Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5215] Health record export #5264

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/health/health.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<a mat-raised-button color="accent" i18n [routerLink]="['update']" *ngIf="isOwnUser">Update Details</a>
<a mat-raised-button color="accent" i18n [routerLink]="['event', { id: userDetail._id }]">Add Examination</a>
<span *ngIf="userDetail.firstName === undefined"><ng-container i18n>Member login:</ng-container> {{userDetail.name}}</span>
<span class="toolbar-fill"></span>
<a mat-raised-button color="accent" class="margin-lr-3" i18n (click)="exportCSV()" >Export Examination</a>
</mat-toolbar>
<div class="view-container view-full-height">
<div class="profile-container">
Expand Down
14 changes: 13 additions & 1 deletion src/app/health/health.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { takeUntil, switchMap } from 'rxjs/operators';
import { Subject, of } from 'rxjs';
import { CouchService } from '../shared/couchdb.service';
import { conditionAndTreatmentFields } from './health.constants';
import { CsvService } from '../shared/csv.service';
import { DatePipe } from '@angular/common';

@Component({
templateUrl: './health.component.html',
Expand All @@ -35,7 +37,9 @@ export class HealthComponent implements OnInit, AfterViewChecked, OnDestroy {
private router: Router,
private route: ActivatedRoute,
private dialog: MatDialog,
private couchService: CouchService
private couchService: CouchService,
private csvService: CsvService,
private datePipe: DatePipe
) {}

ngOnInit() {
Expand Down Expand Up @@ -112,4 +116,12 @@ export class HealthComponent implements OnInit, AfterViewChecked, OnDestroy {
this.displayedColumns = Object.keys(this.eventTable.data[0]);
}

exportCSV() {
const data = this.eventTable.data.map(h => Object.entries(h).reduce((object, [ key, value ]: [ any, any ]) => {
key = isNaN(key) ? key : (key / 86400 + 25569);
return ({ ...object, [key]: value });
}, {}));
this.csvService.exportCSV({ data, title: 'Health Report' });
}

}
3 changes: 2 additions & 1 deletion src/app/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CommonModule, DatePipe } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';

Expand Down Expand Up @@ -35,6 +35,7 @@ const routes: Routes = [
HealthEventComponent,
HealthEventDialogComponent
],
providers: [ DatePipe ],
entryComponents: [ HealthEventDialogComponent ]
})
export class HealthModule {}