Skip to content

Commit

Permalink
#1416 - use the same approach as used elsewhere subjects registered a…
Browse files Browse the repository at this point in the history
…t = "all selected and descendants of lowest selected ones"
  • Loading branch information
petmongrels committed Jun 6, 2024
1 parent 0f781a7 commit 91a3241
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _ from "lodash";
import FormMappingService from "../../service/FormMappingService";
import {ArrayUtil} from "openchs-models";
import AddressLevelState from '../common/AddressLevelsState';
import General from "../../utility/General";

class FiltersActions {

Expand Down Expand Up @@ -64,10 +65,8 @@ class FiltersActions {
addressLevelState: action.addressLevelState
};
const addressLevelService = beans.get(AddressLevelService);
const lowestSelectedAddressLevels = action.addressLevelState.lowestSelectedAddresses;
const lowestAddressLevels = lowestSelectedAddressLevels
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent)), []);
newState.locationSearchCriteria.toggleLowestAddresses(lowestAddressLevels);
const toMatchAddresses = [...action.addressLevelState.selectedAddresses].concat(addressLevelService.getAllDescendants(action.addressLevelState.selectedAddresses));
newState.locationSearchCriteria.toggleLowestAddresses(toMatchAddresses);
return newState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {firebaseEvents, logEvent} from "../../utility/Analytics";
import RealmQueryService from "../../service/query/RealmQueryService";
import SubjectTypeService from "../../service/SubjectTypeService";
import {DashboardCacheFilter} from "openchs-models";
import General from "../../utility/General";

function getApplicableEncounterTypes(holder) {
return _.isEmpty(holder.selectedGeneralEncounterTypes) ? holder.selectedEncounterTypes : holder.selectedGeneralEncounterTypes;
Expand Down
10 changes: 9 additions & 1 deletion packages/openchs-android/src/service/AddressLevelService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Service from '../framework/bean/Service';
import {AddressLevel} from 'avni-models';
import {AddressLevel} from 'openchs-models';
import BaseAddressLevelService from "./BaseAddressLevelService";
import _ from "lodash";

@Service("addressLevelService")
class AddressLevelService extends BaseAddressLevelService {
Expand All @@ -11,6 +12,13 @@ class AddressLevelService extends BaseAddressLevelService {
getSchema() {
return AddressLevel.schema.name;
}

getAllDescendants(addresses) {
const addressLevelService = this;
return addresses
.filter(location => location.level === _.get(_.minBy(addresses, 'level'), 'level'))
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent)), []);
}
}

export default AddressLevelService;
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ class IndividualSearchCriteria {
this.allowedSubjectUUIDs = subjectUUIDs;
}

toggleLowestAddress(lowestAddress) {
if (BaseEntity.collectionHasEntity(this.lowestAddressLevels, lowestAddress))
BaseEntity.removeFromCollection(this.lowestAddressLevels, lowestAddress);
else
this.lowestAddressLevels.push(lowestAddress);
}

toggleLowestAddresses(lowestAddresses) {
this.lowestAddressLevels = lowestAddresses;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ class DashboardFilterService extends BaseService {
} else {
const addressLevelService = this.getService(AddressLevelService);
const addressFilterValues = [...filterValue.selectedAddresses];
const descendants = filterValue.selectedAddresses
.filter(location => location.level === _.get(_.minBy(filterValue.selectedAddresses, 'level'), 'level'))
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent)), []);

const descendants = addressLevelService.getAllDescendants(filterValue.selectedAddresses);
ruleInput.filterValue = addressFilterValues.concat(descendants
.map(addressLevel => _.pick(addressLevel, ['uuid', 'name', 'level', 'type', 'parentUuid'])));
General.logDebug('DashboardFilterService', `Effective address filters: ${JSON.stringify(_.countBy(ruleInput.filterValue, "type"))}`);
Expand Down

0 comments on commit 91a3241

Please sign in to comment.