Skip to content

Commit

Permalink
#1280 - run probable query in realm before filtering in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Jan 30, 2024
1 parent b4b613e commit 8336134
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 6 additions & 8 deletions packages/openchs-android/src/service/CallService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ class CallService extends BaseService {
const userSettings = this.getService(UserInfoService).getUserSettings();
const isCallMaskNeeded = _.get(userSettings, "enableCallMasking", false);

if(isCallMaskNeeded) {
if (isCallMaskNeeded) {
this.connectCall(number, maskedCallResponseCb);
}
else {
} else {
immediateCallCb();
}
}
Expand All @@ -33,15 +32,14 @@ class CallService extends BaseService {
.then(({success, message}) => {
if (success) {
maskedCallResponseCb("Requested for masked call. Expect a call on your number.");
}
else {
} else {
maskedCallResponseCb(`Cannot perform masked call at this time. ${message}`);
}
})
.catch(error => {
maskedCallResponseCb("Cannot perform masked call at this time. (Internet connection unavailable/System error)")
}
);
maskedCallResponseCb("Cannot perform masked call at this time. (Internet connection unavailable/System error)")
}
);
}
}

Expand Down
12 changes: 8 additions & 4 deletions packages/openchs-android/src/service/IndividualService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Privilege,
ProgramEncounter,
ProgramEnrolment
} from "avni-models";
} from "openchs-models";
import _ from 'lodash';
import moment from 'moment';
import MediaQueueService from "./MediaQueueService";
Expand All @@ -22,7 +22,7 @@ import PrivilegeService from "./PrivilegeService";
import EntityApprovalStatusService from "./EntityApprovalStatusService";
import GroupSubjectService from "./GroupSubjectService";
import OrganisationConfigService from './OrganisationConfigService';
import {getUnderlyingRealmCollection} from "openchs-models";
import {getUnderlyingRealmCollection, KeyValue} from "openchs-models";
import RealmQueryService from "./query/RealmQueryService";
import {DashboardReportFilter} from "../model/DashboardReportFilters";

Expand Down Expand Up @@ -701,8 +701,12 @@ class IndividualService extends BaseService {
}

findAllWithMobileNumber(mobileNumber) {
return this.getAllNonVoided()
.filter(ind => _.toString(ind.getMobileNumber()).slice(-10) === _.toString(mobileNumber).slice(-10));
const toMatchMobileNumber = _.toString(mobileNumber).slice(-10);
const probableSubjects = this.getAllNonVoided()
.filtered(`(observations.concept.keyValues.key = "${KeyValue.PrimaryContactKey}" or observations.concept.keyValues.key = "${KeyValue.ContactNumberKey}") and (observations.valueJSON CONTAINS "${toMatchMobileNumber}")`);
return probableSubjects.filter((subject) => {
return _.toString(subject.getMobileNumber()).slice(-10) === toMatchMobileNumber;
});
}

getAllBySubjectType(subjectType) {
Expand Down

0 comments on commit 8336134

Please sign in to comment.