Skip to content

Commit

Permalink
#1382 - unselect programs and encounters based on which parent has be…
Browse files Browse the repository at this point in the history
…en unselected in the filters. fixed BaseService find by all uuid. refactored custom filter service so that it can be reused. removed wrong use of state at the service level for individuals. used CustomFilterService in scheduled report card type.
  • Loading branch information
petmongrels committed Jun 13, 2024
1 parent 1656939 commit bc8bd16
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 240 deletions.
40 changes: 40 additions & 0 deletions packages/openchs-android/src/model/DashboardReportFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Objects has been used in place of arrays to allow for flexibility in contract in the future.

import _ from "lodash";
import {CustomFilter} from "openchs-models";

export class DashboardReportFilter {
type;
dataType;
groupSubjectTypeFilter;
observationBasedFilter;
filterValue;

static getAddressFilter(reportFilters) {
if (_.isNil(reportFilters)) return null;
return _.find(reportFilters, (x: DashboardReportFilter) => x.type === CustomFilter.type.Address);
}

static getGenderFilterValues(reportFilters = []) {
const genderFilter = _.find(reportFilters, (x: DashboardReportFilter) => x.type === CustomFilter.type.Gender);
if (_.isNil(genderFilter)) return [];
return genderFilter.filterValue;
}

getScope() {
return _.get(this.observationBasedFilter, "scope");
}

getConceptUUID() {
return _.get(this.observationBasedFilter, "concept.uuid");
}

getScopeParameters() {
if (_.isNil(this.observationBasedFilter)) return null;

return {
programUUIDs: Object.keys(this.observationBasedFilter.programs),
encounterTypeUUIDs: Object.keys(this.observationBasedFilter.encounterTypes)
};
}
}
17 changes: 0 additions & 17 deletions packages/openchs-android/src/model/DashboardReportFilters.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/openchs-android/src/model/FormMetaDataSelection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

class FormMetaDataSelection {
subjectTypes;
programs;
Expand All @@ -16,6 +18,17 @@ class FormMetaDataSelection {
static createNew() {
return new FormMetaDataSelection([], [], []);
}

updateSubjectTypes(selectedSubjectTypes, programsForSubjectTypes, encounterTypesForSubjectTypesAndPrograms) {
this.subjectTypes = selectedSubjectTypes;
this.programs = _.intersectionBy(this.programs, programsForSubjectTypes, "uuid");
this.encounterTypes = _.intersectionBy(this.encounterTypes, encounterTypesForSubjectTypesAndPrograms, "uuid");
}

updatePrograms(selectedPrograms, encounterTypesForSubjectTypesAndPrograms) {
this.programs = selectedPrograms;
this.encounterTypes = _.intersectionBy(this.encounterTypes, encounterTypesForSubjectTypesAndPrograms, "uuid");
}
}

export default FormMetaDataSelection;
4 changes: 3 additions & 1 deletion packages/openchs-android/src/service/BaseService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import _ from "lodash";
import General from "../utility/General";
import RealmQueryService from "./query/RealmQueryService";

/*
All methods with entity/entities in their name are to be used for disconnected objects. The ones without these terms are for connected objects.
Expand Down Expand Up @@ -43,7 +44,8 @@ class BaseService {
}

findAllByUUID(uuids, entityType) {
return this.findAllByKey("uuid", uuids, entityType.schema.name);
if (uuids.length === 0) return [];
return this.findAllByCriteria(RealmQueryService.orKeyValueQuery("uuid", uuids), entityType.schema.name).map(_.identity);
}

findAllByKey(keyName, value, schemaName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class CustomDashboardCacheService extends BaseService {
encounterTypes: selectedFilterValues[filterUuid].encounterTypes.map(x => x.uuid)
};
} else if (dataTypeDetails.has(dashboardFilterConfig.getInputDataType()) &&
dataTypeDetails.get(dashboardFilterConfig.getInputDataType()).isArray &&
!_.isEmpty(selectedFilterValues[filterUuid])) {
dataTypeDetails.get(dashboardFilterConfig.getInputDataType()).isArray &&
!_.isEmpty(selectedFilterValues[filterUuid])) {
serialisedSelectedValues[filterUuid] = selectedFilterValues[filterUuid].map(x => x.uuid);
} else if (dataTypeDetails.has(dashboardFilterConfig.getInputDataType())) {
serialisedSelectedValues[filterUuid] = _.get(selectedFilterValues[filterUuid], "uuid");
Expand All @@ -116,10 +116,6 @@ class CustomDashboardCacheService extends BaseService {
dashboardCache.selectedValuesJSON = JSON.stringify(serialisedSelectedValues);
this.saveOrUpdate(dashboardCache);
}

resetCache(dashboardUUID) {
return CustomDashboardCache.createEmptyInstance();
}
}

export default CustomDashboardCacheService;
Loading

0 comments on commit bc8bd16

Please sign in to comment.