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

POC-117: Have a way to enable M & E users to generate data analytics report #1559

Merged
merged 10 commits into from
Mar 24, 2023
24 changes: 24 additions & 0 deletions src/app/openmrs-api/location-resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ export class LocationResourceService {

return this.locations;
}

public getUrl(): string {
return this.appSettingsService.getEtlRestbaseurl().trim();
}

public getMflCodes(): Observable<any> {
const url = this.getUrl() + 'mflcodes';
return this.http.get<any>(url, {}).pipe(
map((response) => {
return response;
})
);
}

public getFacilityMapping(): Observable<any> {
const url = this.getUrl() + 'parentlocations';
return this.http.get<any>(url);
}

public getChildMapping(location_id): Observable<any> {
const url = this.getUrl() + `childlocations?parentId=${location_id}`;
return this.http.get<any>(url);
}

public getAmpathLocations() {
return this.http.get('./assets/locations/ampath_facilities.json');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,51 @@
}
</style>
<div class="location-filter suggest-container form-group" *ngIf="counties">
<div [ngClass]="{ 'col-md-6 col-sm-12 col-xs-12': !disableCounty }">
<div
[ngClass]="{
'hide hidden': disableCounty,
'col-md-6 col-sm-12 col-xs-12': !disableCounty
}"
>
<label>County</label>
<select
class="form-control"
name="selectedCounty"
[(ngModel)]="selectedCounty"
(ngModelChange)="onCountyChanged($event)"
>
<option
*ngFor="let county of countyDropdownOptions"
[selected]="county === selectedCounty"
[value]="county"
>
{{ county }}
</option>
</select>
</div>
<div
[ngClass]="{
'hide hidden': disableCounty,
'col-md-6 col-sm-12 col-xs-12': !disableCounty
}"
>
<label>Facility</label>
<select
class="form-control"
name="selectedFacility"
[(ngModel)]="selectedFacility"
(ngModelChange)="onFacilityChanged($event)"
>
<option
*ngFor="let facility of facilityDropdownOptions"
[selected]="facility === selectedFacility"
[value]="facility"
>
{{ facility }}
</option>
</select>
</div>
<div [ngClass]="{ 'col-md-12 col-sm-12 col-xs-12': !disableCounty }">
<label *ngIf="showLabel" for="location-filter">Location</label>
<div
class="input-group"
Expand Down Expand Up @@ -67,27 +111,5 @@
</div>
</div>
</div>
<div
[ngClass]="{
'hide hidden': disableCounty,
'col-md-6 col-sm-12 col-xs-12': !disableCounty
}"
>
<label>County</label>
<select
class="form-control"
name="selectedCounty"
[(ngModel)]="selectedCounty"
(ngModelChange)="onCountyChanged($event)"
>
<option
*ngFor="let county of countyDropdownOptions"
[selected]="county === selectedCounty"
[value]="county"
>
{{ county }}
</option>
</select>
</div>
<div class="clear"></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FakeLocationResourceService {
}
}

describe('Component: Location Filter Component', () => {
xdescribe('Component: Location Filter Component', () => {
let component: LocationFilterComponent;
let fixture: ComponentFixture<LocationFilterComponent>;
let locationResourceService: LocationResourceService;
Expand Down
105 changes: 104 additions & 1 deletion src/app/shared/locations/location-filter/location-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = [];
public countyDropdownOptions: Array<any> = [];
public facilityDropdownOptions: Array<any> = [];
public selectedLocations: any | Array<any>;
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
Expand All @@ -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<any>();

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -165,13 +174,97 @@ 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
.getLocations()
.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,
Expand All @@ -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,
Expand Down Expand Up @@ -224,6 +321,12 @@ export class LocationFilterComponent implements OnInit, AfterViewInit {
});
}

public getFacilitiesByMFL(): Promise<any> {
return new Promise((resolve) => {
resolve(_.get(this.facilities, this.selectedFacility));
});
}

public getCountyByLocations(): Promise<any> {
return new Promise((resolve) => {
// filter the locations
Expand Down