-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prep]: Initial prep monthly report (#1626)
* prep: Initial prep monthly report * Add prep monthly report patient list * WIP * Reset variables & rm dead code * Delete src/app/hiv-care-lib/prep-report/monthly/prep-monthly-base/prep-monthly-base.component.css * Delete src/app/hiv-care-lib/prep-report/monthly/prep-monthly-patient-list/prep-monthly-report-patient-list.component.css --------- Co-authored-by: Drizzentic <[email protected]>
- Loading branch information
1 parent
513fe01
commit 66cd364
Showing
20 changed files
with
995 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "none", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/app/data-analytics-dashboard/hiv/prep-report/prep-monthly-report.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Router, ActivatedRoute } from '@angular/router'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Location } from '@angular/common'; | ||
import { take } from 'rxjs/operators'; | ||
import * as rison from 'rison-node'; | ||
import * as Moment from 'moment'; | ||
|
||
import { DataAnalyticsDashboardService } from '../../services/data-analytics-dashboard.services'; | ||
import { PrepMonthlyReportBaseComponent } from 'src/app/hiv-care-lib/prep-report/monthly/prep-monthly-base/prep-monthly-base.component'; | ||
import { PrepMonthlyResourceService } from 'src/app/etl-api/prep-monthly-resource.service'; | ||
|
||
@Component({ | ||
selector: 'prep-monthly-report-base', | ||
templateUrl: | ||
'./../../../hiv-care-lib/prep-report/monthly/prep-monthly-base/prep-monthly-base.component.html' | ||
}) | ||
export class PrepMonthlyReportComponent | ||
extends PrepMonthlyReportBaseComponent | ||
implements OnInit { | ||
public enabledControls = 'monthControl,locationControl'; | ||
|
||
constructor( | ||
public router: Router, | ||
public route: ActivatedRoute, | ||
public prepMonthlyResourceService: PrepMonthlyResourceService, | ||
private dataAnalyticsDashboardService: DataAnalyticsDashboardService, | ||
private location: Location | ||
) { | ||
super(router, route, prepMonthlyResourceService); | ||
} | ||
|
||
public ngOnInit() { | ||
this.loadReportParamsFromUrl(); | ||
} | ||
|
||
public generateReport() { | ||
this.setSelectedLocation(); | ||
this.storeParamsInUrl(); | ||
|
||
if (Array.isArray(this._locationUuids) && this._locationUuids.length > 0) { | ||
this.params = { | ||
locationUuids: this.getSelectedLocations(this._locationUuids), | ||
month: Moment(this._month).endOf('month').format('YYYY-MM-DD') | ||
}; | ||
super.getPrepMonthlyAggReport(this.params); | ||
super.showDraftReportAlert(this._month); | ||
} else { | ||
this.errorMessage = 'Locations are required!'; | ||
} | ||
} | ||
|
||
public storeParamsInUrl() { | ||
const state = { | ||
locationUuids: this.getSelectedLocations(this._locationUuids), | ||
month: Moment(this._month).endOf('month').format('YYYY-MM-DD') | ||
}; | ||
const stateUrl = rison.encode(state); | ||
const path = this.router.parseUrl(this.location.path()); | ||
path.queryParams = { | ||
state: stateUrl | ||
}; | ||
|
||
this.location.replaceState(path.toString()); | ||
} | ||
|
||
public loadReportParamsFromUrl() { | ||
const path = this.router.parseUrl(this.location.path()); | ||
|
||
if (path.queryParams['state']) { | ||
const state = rison.decode(path.queryParams['state']); | ||
this.month = state.month; | ||
this.locationUuids = state.locations; | ||
} | ||
|
||
if (path.queryParams['state']) { | ||
this.generateReport(); | ||
} | ||
} | ||
|
||
public setSelectedLocation() { | ||
this.dataAnalyticsDashboardService | ||
.getSelectedLocations() | ||
.pipe(take(1)) | ||
.subscribe((data) => { | ||
if (data) { | ||
this.locationUuids = data.locations; | ||
} | ||
}); | ||
} | ||
|
||
private getSelectedLocations(locationUuids: Array<any>): string { | ||
return locationUuids.map((location) => location.value).join(','); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { routes } from '../clinic-dashboard/clinic-dashboard.routes'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ClinicDashboardComponent } from '../clinic-dashboard/clinic-dashboard.component'; | ||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
import { AppSettingsService } from '../app-settings/app-settings.service'; | ||
import { LocalStorageService } from '../utils/local-storage.service'; | ||
import { PrepMonthlyResourceService } from './prep-monthly-resource.service'; | ||
|
||
describe('PrepMonthlyResourceService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
PrepMonthlyResourceService, | ||
AppSettingsService, | ||
LocalStorageService | ||
], | ||
declarations: [ClinicDashboardComponent], | ||
imports: [ | ||
RouterTestingModule.withRoutes(routes), | ||
HttpClientTestingModule | ||
], | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA] | ||
}); | ||
}); | ||
|
||
it('should be created', inject( | ||
[PrepMonthlyResourceService], | ||
(service: PrepMonthlyResourceService) => { | ||
expect(service).toBeTruthy(); | ||
} | ||
)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AppSettingsService } from '../app-settings/app-settings.service'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PrepMonthlyResourceService { | ||
public get url(): string { | ||
return this.appSettingsService.getEtlRestbaseurl().trim(); | ||
} | ||
constructor( | ||
public http: HttpClient, | ||
public appSettingsService: AppSettingsService | ||
) {} | ||
public getPrepMonthlyAggReport(params: any): Observable<any> { | ||
// tslint:disable-next-line: max-line-length | ||
return this.http | ||
.get( | ||
`${this.url}prep-monthly-report?endDate=${params.month}&locationUuids=${params.locationUuids}` | ||
) | ||
.pipe( | ||
catchError((err: any) => { | ||
const error: any = err; | ||
const errorObj = { | ||
error: error.status, | ||
message: error.statusText | ||
}; | ||
return Observable.of(errorObj); | ||
}), | ||
map((response: Response) => { | ||
return response; | ||
}) | ||
); | ||
} | ||
public getPrepMonthlyPatientList(params: any): Observable<any> { | ||
// tslint:disable-next-line: max-line-length | ||
return this.http | ||
.get( | ||
`${this.url}prep-monthly-report-patient-list?&endDate=${params.month}&locationUuids=${params.locationUuids}&indicators=${params.indicators}` | ||
) | ||
.pipe( | ||
catchError((err: any) => { | ||
const error: any = err; | ||
const errorObj = { | ||
error: error.status, | ||
message: error.statusText | ||
}; | ||
return Observable.of(errorObj); | ||
}), | ||
map((response: Response) => { | ||
return response; | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
53 changes: 53 additions & 0 deletions
53
src/app/hiv-care-lib/prep-report/monthly/prep-monthly-base/prep-monthly-base.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<h4 class="component-title text-success"> | ||
<span class="fa fa-table"></span>PrEP Monthly Report | ||
</h4> | ||
|
||
<div class="loader" *ngIf="isLoading"> | ||
<span><i class="fa fa-spinner fa-spin"></i>Loading...</span> | ||
</div> | ||
|
||
<p-tabView> | ||
<div> | ||
<p-tabPanel header="Monthly" leftIcon="fa-calendar-o"> | ||
<report-filters | ||
[enabledControls]="enabledControls" | ||
[monthString]="_month" | ||
(onMonthChange)="onMonthChange($event)" | ||
[reportName]="reportName" | ||
(generateReport)="generateReport()" | ||
> | ||
</report-filters> | ||
</p-tabPanel> | ||
</div> | ||
</p-tabView> | ||
|
||
<div class="alert alert-danger fade in" *ngIf="showInfoMessage"> | ||
<a href="#" class="close" data-dismiss="alert">×</a> | ||
<h4 *ngIf="!statusError"> | ||
<strong><span class="glyphicon glyphicon-warning-sign"></span> </strong> An | ||
error occurred while trying to load the report. Please try again. | ||
</h4> | ||
<p> | ||
<small>{{ errorMessage }}</small> | ||
</p> | ||
</div> | ||
<div *ngIf="!isReleased" class="alert alert-warning"> | ||
<strong>Viewing a Draft Version of the Report for the chosen month. </strong> | ||
This report is likely to change without warning. | ||
</div> | ||
<div> | ||
<p-tabView> | ||
<p-tabPanel | ||
header="Report View" | ||
leftIcon="fa-file-pdf-o" | ||
[selected]="currentViewBelow === 'pdf'" | ||
> | ||
<app-prep-monthly-report-view | ||
[SummaryData]="prepReportSummaryData" | ||
[sectionDefs]="columnDefs" | ||
(indicatorSelected)="indicatorSelected($event)" | ||
[reportDetails]="params" | ||
></app-prep-monthly-report-view> | ||
</p-tabPanel> | ||
</p-tabView> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
...pp/hiv-care-lib/prep-report/monthly/prep-monthly-base/prep-monthly-base.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { PrepMonthlyReportBaseComponent } from './prep-monthly-base.component'; | ||
|
||
describe('PrepMonthlyReportBaseComponent', () => { | ||
let component: PrepMonthlyReportBaseComponent; | ||
let fixture: ComponentFixture<PrepMonthlyReportBaseComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [PrepMonthlyReportBaseComponent] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PrepMonthlyReportBaseComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.