Skip to content

Commit

Permalink
feat: Add export button to PatientOverview.vue and integrate XLSX lib…
Browse files Browse the repository at this point in the history
…rary

This commit adds an export button to the PatientOverview.vue component, allowing users to export patient data as an Excel file. The XLSX library is imported and used to generate the Excel file based on the patient data. The exported file is named "patient_data_<current_date>.xlsx".

Code changes:
- Added an export button to the PatientOverview.vue component
- Imported the XLSX library
- Implemented the exportAsExcel method to prepare and export patient data as an Excel file

Closes: #11
  • Loading branch information
berntpopp committed Sep 14, 2024
1 parent 9ccaa2c commit b4b3f76
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
106 changes: 105 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"vue": "^3.4.37",
"vue-chartjs": "^5.3.1",
"vuetify": "^3.7.0-beta.1",
"webfontloader": "^1.6.28"
"webfontloader": "^1.6.28",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.2",
Expand Down
46 changes: 46 additions & 0 deletions src/components/PatientOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<v-card outlined class="pa-2">
<v-card-title>
<span>Overview</span>
<!-- Add export button -->
<v-btn
small
density="compact"
icon @click="exportAsExcel"
aria-label="Export as Excel"
style="margin-left: 16px;"
>
<v-icon>mdi-file-excel</v-icon>
<v-tooltip activator="parent" location="bottom">
Export as Excel
</v-tooltip>
</v-btn>
</v-card-title>
<v-card-text>
<v-table dense>
Expand All @@ -26,6 +39,9 @@
</template>

<script>
// Import the XLSX library
import * as XLSX from 'xlsx';
export default {
props: {
patient: {
Expand All @@ -47,5 +63,35 @@ export default {
}),
},
},
methods: {
exportAsExcel() {
// Prepare data for Excel export
const data = [
{
'Patient ID': this.patient.patientId,
Age: this.patient.age,
Height: this.patient.height,
'Mayo Class': this.patient.mayoClass,
'PROPKD Score': this.patient.propkdScore,
},
];
// Create a new workbook and worksheet
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(data);
// Append the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, 'Patient Data');
// Export the workbook as an Excel file
XLSX.writeFile(wb, `patient_data_${new Date().toISOString()}.xlsx`);
},
},
};
</script>

<style scoped>
.ml-auto {
margin-left: auto;
}
</style>

0 comments on commit b4b3f76

Please sign in to comment.