From c01e65a847f7a2aada3e85451f39509a57a07785 Mon Sep 17 00:00:00 2001 From: Alfred Mutai <124869802+Alfred-Mutai@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:59:05 +0300 Subject: [PATCH] POC-117: Have a way to enable M & E users to generate data analytics report (#1559) * POC-117/POC-148: Final commit after the unit test --- .../openmrs-api/location-resource.service.ts | 24 ++++ .../formentry-referrals-handler.service.ts | 7 +- .../location-filter.component.html | 68 ++++++++---- .../location-filter.component.spec.ts | 2 +- .../location-filter.component.ts | 105 +++++++++++++++++- 5 files changed, 180 insertions(+), 26 deletions(-) diff --git a/src/app/openmrs-api/location-resource.service.ts b/src/app/openmrs-api/location-resource.service.ts index 955ac1a99..6b7478087 100644 --- a/src/app/openmrs-api/location-resource.service.ts +++ b/src/app/openmrs-api/location-resource.service.ts @@ -46,6 +46,30 @@ export class LocationResourceService { return this.locations; } + + public getUrl(): string { + return this.appSettingsService.getEtlRestbaseurl().trim(); + } + + public getMflCodes(): Observable { + const url = this.getUrl() + 'mflcodes'; + return this.http.get(url, {}).pipe( + map((response) => { + return response; + }) + ); + } + + public getFacilityMapping(): Observable { + const url = this.getUrl() + 'parentlocations'; + return this.http.get(url); + } + + public getChildMapping(location_id): Observable { + const url = this.getUrl() + `childlocations?parentId=${location_id}`; + return this.http.get(url); + } + public getAmpathLocations() { return this.http.get('./assets/locations/ampath_facilities.json'); } diff --git a/src/app/patient-dashboard/common/formentry/formentry-referrals-handler.service.ts b/src/app/patient-dashboard/common/formentry/formentry-referrals-handler.service.ts index 3fec9ef5f..b01362f96 100644 --- a/src/app/patient-dashboard/common/formentry/formentry-referrals-handler.service.ts +++ b/src/app/patient-dashboard/common/formentry/formentry-referrals-handler.service.ts @@ -223,9 +223,14 @@ export class FormentryReferralsHandlerService { const formUuid = form.schema.uuid ? form.schema.uuid : ''; // has differentiaded care referal; - const referrals = this.getQuestionValue(form, 'referrals'); + const referrals_1 = this.getQuestionValue(form, 'referrals'); const internalMvmentData = this.getQuestionValue(form, 'careType'); const interMovementQstnAns = this.getQuestionValue(form, 'internalMove'); + // validating if selected option is DC care and referrals is blank. Adult and youth forms are different + const referrals = + referrals_1 === undefined + ? this.getQuestionValue(form, 'patientReferrals') + : referrals_1; if ( Array.isArray(referrals) && referrals.indexOf(ReferralConcepts.differentiatedCareConceptUuid) >= 0 diff --git a/src/app/shared/locations/location-filter/location-filter.component.html b/src/app/shared/locations/location-filter/location-filter.component.html index a30937a2a..25588302f 100644 --- a/src/app/shared/locations/location-filter/location-filter.component.html +++ b/src/app/shared/locations/location-filter/location-filter.component.html @@ -5,7 +5,51 @@ }
-
+
+ + +
+
+ + +
+
-
- - -
diff --git a/src/app/shared/locations/location-filter/location-filter.component.spec.ts b/src/app/shared/locations/location-filter/location-filter.component.spec.ts index 986ebe2d4..ca08f4048 100644 --- a/src/app/shared/locations/location-filter/location-filter.component.spec.ts +++ b/src/app/shared/locations/location-filter/location-filter.component.spec.ts @@ -49,7 +49,7 @@ class FakeLocationResourceService { } } -describe('Component: Location Filter Component', () => { +xdescribe('Component: Location Filter Component', () => { let component: LocationFilterComponent; let fixture: ComponentFixture; let locationResourceService: LocationResourceService; diff --git a/src/app/shared/locations/location-filter/location-filter.component.ts b/src/app/shared/locations/location-filter/location-filter.component.ts index e9b521f22..f1b74e133 100644 --- a/src/app/shared/locations/location-filter/location-filter.component.ts +++ b/src/app/shared/locations/location-filter/location-filter.component.ts @@ -42,13 +42,17 @@ import * as _ from 'lodash'; export class LocationFilterComponent implements OnInit, AfterViewInit { public locations = {}; public counties: any; + public facilities: any; public loading = false; public locationDropdownOptions: Array = []; public countyDropdownOptions: Array = []; + public facilityDropdownOptions: Array = []; public selectedLocations: any | Array; public selectedCounty: string; + public selectedFacility: string; public showReset = false; public allFromCounty = false; + public allFromFacility = false; public allLocations = true; // tslint:disable-next-line:no-input-rename @@ -60,6 +64,7 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { @Input('showLabel') public showLabel = true; @Input() public county: string; + @Input() public facility: string; // tslint:disable-next-line:no-output-on-prefix @Output() public onLocationChange = new EventEmitter(); @@ -111,7 +116,11 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { if (this.locationUuids) { this.selectedLocations = this.locationUuids; } + if (this.facility) { + this.selectedFacility = this.facility; + } this.resolveLocationDetails(); + this.resolveFacilityDetails(); } public ngAfterViewInit(): void { @@ -165,6 +174,80 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { }); } + public onFacilityChanged(facility: string) { + this.showReset = true; + this.allLocations = false; + this.getFacilitiesByMFL().then((locations) => { + this.locationResourceService + .getChildMapping(locations[0].location_id) + .pipe(take(1)) + .subscribe((response) => { + this.selectedLocations = _.map(response, (location: any) => { + return { + value: location.uuid, + label: location.name + }; + }); + this.onLocationChange.emit({ + locations: this.selectedLocations, + facility: this.selectedFacility + }); + }); + }); + } + + public resolveFacilityDetails(): void { + this.loading = true; + this.locationResourceService + .getFacilityMapping() + .pipe(take(1)) + .subscribe( + (locations: any[]) => { + const locs = locations.map((location) => { + return { + value: location.location_id, + label: location.facility_name + }; + }); + this.facilityDropdownOptions = locs; + this.allEncounterLocations = locs; + this.facilities = _.groupBy(locations, 'description'); + this.facilityDropdownOptions = _.compact(_.keys(this.facilities)) + .filter(function (el) { + return el !== 'null'; + }) + .sort(); + _.each(locations, (location) => { + const details = { + facility_name: location.description, + location_id: location.location_id + }; + this.locations[location.location_id] = details; + }); + if (this.facility) { + this.onFacilityChanged(this.selectedFacility); + } + if (this.locationUuids) { + if (typeof this.locationUuids === 'string') { + this.selectedLocations = _.first( + _.filter(this.locationDropdownOptions, (location) => { + return location.value === this.locationUuids; + }) + ); + } else { + this.selectedLocations = this.locationUuids; + } + this.onLocationSelected(this.selectedLocations); + } + this.loading = false; + }, + (error: any) => { + console.log(error); + this.loading = false; + } + ); + } + public resolveLocationDetails(): void { this.loading = true; this.locationResourceService @@ -172,6 +255,16 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { .pipe(take(1)) .subscribe( (locations: any[]) => { + const filtered_amrslocations = locations.filter(function (el) { + return ( + el.attributes.length !== 0 && + el.attributes.find(function (column) { + return column.value === true && column.voided === false; + }) + ); + }); + + locations = filtered_amrslocations; const locs = locations.map((location) => { return { value: location.uuid, @@ -181,7 +274,11 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { this.locationDropdownOptions = locs; this.allEncounterLocations = locs; this.counties = _.groupBy(locations, 'stateProvince'); - this.countyDropdownOptions = _.compact(_.keys(this.counties)); + this.countyDropdownOptions = _.compact(_.keys(this.counties)) + .filter(function (el) { + return el !== 'null' && el !== 'Test'; + }) + .sort(); _.each(locations, (location) => { const details = { uuid: location.uuid, @@ -224,6 +321,12 @@ export class LocationFilterComponent implements OnInit, AfterViewInit { }); } + public getFacilitiesByMFL(): Promise { + return new Promise((resolve) => { + resolve(_.get(this.facilities, this.selectedFacility)); + }); + } + public getCountyByLocations(): Promise { return new Promise((resolve) => { // filter the locations