diff --git a/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js b/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js index bcf39fd92..cd1985e8d 100644 --- a/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js +++ b/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js @@ -44,15 +44,11 @@ import TestEncounterFactory from "../test/model/txn/TestEncounterFactory"; import TestEncounterTypeFactory from "../test/model/TestEncounterTypeFactory"; import moment from "moment"; -function getCount(reportCardService, card, reportFilters) { - return reportCardService.getReportCardCount(card, reportFilters).primaryValue +function getCount(test, card, reportFilters) { + return test.reportCardService.getReportCardCount(card, reportFilters).primaryValue } class ReportCardServiceIntegrationTest extends BaseIntegrationTest { - approvedCard; - subjectType; - addressLevel2; - setup() { super.setup(); this.executeInWrite((db) => { @@ -79,7 +75,8 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest { const approvalStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({})); const pendingStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({status: ApprovalStatus.statuses.Pending})); const subjectId = General.randomUUID(); - const encounterId = General.randomUUID(); + const encounterId1 = General.randomUUID(); + const encounterId2 = General.randomUUID(); const subjectEAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({ entityType: EntityApprovalStatus.entityType.Subject, @@ -89,7 +86,7 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest { })); const encEAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({ entityType: EntityApprovalStatus.entityType.Encounter, - entityUUID: encounterId, + entityUUID: encounterId1, entityTypeUuid: encounterType.uuid, approvalStatus: pendingStatus })); @@ -102,38 +99,57 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest { approvalStatuses: [subjectEAS] })); - db.create(Encounter, TestEncounterFactory.create({ - uuid: encounterId, + subject.addEncounter(db.create(Encounter, TestEncounterFactory.create({ + uuid: encounterId1, earliestVisitDateTime: moment().add(-2, "day").toDate(), maxVisitDateTime: moment().add(2, "day").toDate(), encounterType: encounterType, approvalStatuses: [encEAS], subject: subject - })); + }))); + + subject.addEncounter(db.create(Encounter, TestEncounterFactory.create({ + uuid: encounterId2, + earliestVisitDateTime: moment().add(-10, "day").toDate(), + maxVisitDateTime: moment().add(-5, "day").toDate(), + encounterType: encounterType, + approvalStatuses: [], + subject: subject + }))); const approvedCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.Approved})); const scheduledVisitsCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.ScheduledVisits})); - this.approvedCard = db.create(ReportCard, TestReportCardFactory.create({name: "a", standardReportCardType: approvedCardType})); - this.scheduledVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "b", standardReportCardType: scheduledVisitsCardType})); + const overdueVisitsCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.OverdueVisits})); + this.approvedCard = db.create(ReportCard, TestReportCardFactory.create({name: "approvedCard", standardReportCardType: approvedCardType})); + this.scheduledVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "scheduledVisitsCard", standardReportCardType: scheduledVisitsCardType})); + this.overdueVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "overdueVisitsCard", standardReportCardType: overdueVisitsCardType})); }); + + this.reportCardService = this.getService(ReportCardService); + this.addressSelected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel]}); + this.address2Selected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel2]}); + this.twoAddressSelected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel, this.addressLevel2]}); } getResultForApprovalCardsType() { - const reportCardService = this.getService(ReportCardService); - assert.equal(1, getCount(reportCardService, this.approvedCard, [])); - let filterValues = [TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel]})]; - assert.equal(1, getCount(reportCardService, this.approvedCard, filterValues)); - filterValues = [TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel2]})]; - assert.equal(0, getCount(reportCardService, this.approvedCard, filterValues)); - filterValues = [TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel, this.addressLevel2]})]; - assert.equal(1, getCount(reportCardService, this.approvedCard, filterValues)); + assert.equal(1, getCount(this, this.approvedCard, [])); + assert.equal(1, getCount(this, this.approvedCard, [this.addressSelected])); + assert.equal(0, getCount(this, this.approvedCard, [this.address2Selected])); + assert.equal(1, getCount(this, this.approvedCard, [this.twoAddressSelected])); + } + + getCountForDefaultCardsType_forScheduledVisits() { + assert.equal(1, getCount(this, this.scheduledVisitsCard, [])); + assert.equal(1, getCount(this, this.scheduledVisitsCard, [this.addressSelected])); + assert.equal(0, getCount(this, this.scheduledVisitsCard, [this.address2Selected])); + assert.equal(1, getCount(this, this.scheduledVisitsCard, [this.twoAddressSelected])); } - getCountForDefaultCardsType() { - const reportCardService = this.getService(ReportCardService); - assert.equal(1, getCount(reportCardService, this.scheduledVisitsCard, [])); - assert.equal(1, getCount(reportCardService, this.scheduledVisitsCard, [TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel]})])); - assert.equal(0, getCount(reportCardService, this.scheduledVisitsCard, [TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.addressLevel2]})])); + getCountForDefaultCardsType_forOverdueVisits() { + assert.equal(1, getCount(this, this.overdueVisitsCard, [])); + assert.equal(1, getCount(this, this.overdueVisitsCard, [this.addressSelected])); + assert.equal(0, getCount(this, this.overdueVisitsCard, [this.address2Selected])); + assert.equal(1, getCount(this, this.overdueVisitsCard, [this.twoAddressSelected])); } } diff --git a/packages/openchs-android/package-lock.json b/packages/openchs-android/package-lock.json index a4be8d02f..d0d29c5e4 100644 --- a/packages/openchs-android/package-lock.json +++ b/packages/openchs-android/package-lock.json @@ -33,7 +33,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.88", + "openchs-models": "1.30.90", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", @@ -16431,9 +16431,9 @@ } }, "node_modules/openchs-models": { - "version": "1.30.88", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.88.tgz", - "integrity": "sha512-ZHiQuPGyz+f7cf+jSQCti3wnGTIz53oZxI3rLMJ4H/IRMnfVQBeN14wtNlUE0UXkoItVqimL7fVog2q4apbY/g==", + "version": "1.30.90", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.90.tgz", + "integrity": "sha512-IpAPJxCZX49GukXeafWoOHu/3tQ7TQ1GZJTfufAyrSN3MiMCMjWMMYWxVYtJdLf1YPwSghce1Ky3l65vX0A9Jw==", "peerDependencies": { "lodash": "*", "moment": "*" @@ -35131,9 +35131,9 @@ } }, "openchs-models": { - "version": "1.30.88", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.88.tgz", - "integrity": "sha512-ZHiQuPGyz+f7cf+jSQCti3wnGTIz53oZxI3rLMJ4H/IRMnfVQBeN14wtNlUE0UXkoItVqimL7fVog2q4apbY/g==" + "version": "1.30.90", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.90.tgz", + "integrity": "sha512-IpAPJxCZX49GukXeafWoOHu/3tQ7TQ1GZJTfufAyrSN3MiMCMjWMMYWxVYtJdLf1YPwSghce1Ky3l65vX0A9Jw==" }, "opencollective-postinstall": { "version": "2.0.3", diff --git a/packages/openchs-android/package.json b/packages/openchs-android/package.json index 3d8edb011..d347d70e5 100644 --- a/packages/openchs-android/package.json +++ b/packages/openchs-android/package.json @@ -57,7 +57,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.89", + "openchs-models": "1.30.90", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", diff --git a/packages/openchs-android/src/GlobalContext.js b/packages/openchs-android/src/GlobalContext.js index 596c52352..0c01d849f 100644 --- a/packages/openchs-android/src/GlobalContext.js +++ b/packages/openchs-android/src/GlobalContext.js @@ -27,7 +27,6 @@ class GlobalContext { async initialiseGlobalContext(appStore, realmFactory) { this.db = await realmFactory.createRealm(); - this.db.setLogQueries(true); this.beanRegistry.init(this.db); this.reduxStore = appStore.create(this.beanRegistry.beansMap); this.beanRegistry.setReduxStore(this.reduxStore); diff --git a/packages/openchs-android/src/action/mydashboard/MyDashboardActions.js b/packages/openchs-android/src/action/mydashboard/MyDashboardActions.js index 8eb154352..33fd09d30 100644 --- a/packages/openchs-android/src/action/mydashboard/MyDashboardActions.js +++ b/packages/openchs-android/src/action/mydashboard/MyDashboardActions.js @@ -98,10 +98,10 @@ class MyDashboardActions { dueChecklist ] = state.returnEmpty ? [[], [], [], [], [], [], [],[]] : (fetchFromDB ? [ MyDashboardActions.commonIndividuals(individualService.allScheduledVisitsIn(state.date.value, [], encountersFilters, generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter), state.individualUUIDs), - MyDashboardActions.commonIndividuals(individualService.allOverdueVisitsIn(state.date.value, encountersFilters, generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter), state.individualUUIDs), - MyDashboardActions.commonIndividuals(individualService.recentlyCompletedVisitsIn(state.date.value, encountersFilters, generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter), state.individualUUIDs), - MyDashboardActions.commonIndividuals(individualService.recentlyRegistered(state.date.value, individualFilters, state.selectedPrograms, getApplicableEncounterTypes(state)), state.individualUUIDs), - MyDashboardActions.commonIndividuals(individualService.recentlyEnrolled(state.date.value, enrolmentFilters), state.individualUUIDs), + MyDashboardActions.commonIndividuals(individualService.allOverdueVisitsIn(state.date.value, [], encountersFilters, generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter), state.individualUUIDs), + MyDashboardActions.commonIndividuals(individualService.recentlyCompletedVisitsIn(state.date.value, [], encountersFilters, generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter), state.individualUUIDs), + MyDashboardActions.commonIndividuals(individualService.recentlyRegistered(state.date.value, [], individualFilters, state.selectedPrograms, getApplicableEncounterTypes(state)), state.individualUUIDs), + MyDashboardActions.commonIndividuals(individualService.recentlyEnrolled(state.date.value, [], enrolmentFilters), state.individualUUIDs), MyDashboardActions.commonIndividuals(individualService.allInWithFilters(state.date.value, individualFilters, state.selectedPrograms, getApplicableEncounterTypes(state)), state.individualUUIDs, true), MyDashboardActions.commonIndividuals(dueChecklistWithChecklistItem.individual, state.individualUUIDs) ] @@ -194,9 +194,9 @@ class MyDashboardActions { const queryGeneralEncounter = MyDashboardActions.shouldQueryGeneralEncounter(state); let allIndividuals; if (listType === "recentlyCompletedRegistration" || listType === "total") - allIndividuals = methodMap.get(listType)(state.date.value, filters, state.selectedPrograms, getApplicableEncounterTypes(state)); + allIndividuals = methodMap.get(listType)(state.date.value, [], filters, state.selectedPrograms, getApplicableEncounterTypes(state)); else if (listType === "dueChecklist") { - allIndividuals = methodMap.get(listType)(state.date.value, state.dueChecklistFilter) + allIndividuals = methodMap.get(listType)(state.date.value, [], state.dueChecklistFilter) } else allIndividuals = methodMap.get(listType)(state.date.value, filters, state.generalEncountersFilters, queryProgramEncounter, queryGeneralEncounter); diff --git a/packages/openchs-android/src/service/IndividualService.js b/packages/openchs-android/src/service/IndividualService.js index e98bca682..9eaaf6884 100644 --- a/packages/openchs-android/src/service/IndividualService.js +++ b/packages/openchs-android/src/service/IndividualService.js @@ -289,7 +289,7 @@ class IndividualService extends BaseService { return this.withScheduledVisits(program, addressLevel, encounterType).length; } - allOverdueVisitsIn(date, programEncounterCriteria, encounterCriteria, queryProgramEncounter = true, queryGeneralEncounter = true) { + allOverdueVisitsIn(date, reportFilters, programEncounterCriteria, encounterCriteria, queryProgramEncounter = true, queryGeneralEncounter = true) { const privilegeService = this.getService(PrivilegeService); const performProgramVisitCriteria = `privilege.name = '${Privilege.privilegeName.performVisit}' AND privilege.entityType = '${Privilege.privilegeEntityType.encounter}'`; const allowedProgramEncounterTypeUuidsForPerformVisit = privilegeService.allowedEntityTypeUUIDListForCriteria(performProgramVisitCriteria, 'programEncounterTypeUuid'); @@ -395,7 +395,7 @@ class IndividualService extends BaseService { .map(_.identity); } - recentlyCompletedVisitsIn(date, programEncounterCriteria, encounterCriteria, queryProgramEncounter = true, queryGeneralEncounter = true) { + recentlyCompletedVisitsIn(date, reportFilters, programEncounterCriteria, encounterCriteria, queryProgramEncounter = true, queryGeneralEncounter = true) { let fromDate = moment(date).subtract(1, 'day').startOf('day').toDate(); let tillDate = moment(date).endOf('day').toDate(); const programEncounters = queryProgramEncounter ? this.db.objects(ProgramEncounter.schema.name) @@ -449,7 +449,7 @@ class IndividualService extends BaseService { .map(_.identity); } - recentlyRegistered(date, addressQuery, programs = [], encounterTypes = []) { + recentlyRegistered(date, reportFilters, addressQuery, programs = [], encounterTypes = []) { let fromDate = moment(date).subtract(1, 'day').startOf('day').toDate(); let tillDate = moment(date).endOf('day').toDate(); let individuals = this.db.objects(Individual.schema.name) @@ -484,7 +484,7 @@ class IndividualService extends BaseService { .map(_.identity); } - recentlyEnrolled(date, queryAdditions) { + recentlyEnrolled(date, reportFilters, queryAdditions) { let fromDate = moment(date).subtract(1, 'day').startOf('day').toDate(); let tillDate = moment(date).endOf('day').toDate(); return [...this.db.objects(ProgramEnrolment.schema.name) @@ -535,10 +535,10 @@ class IndividualService extends BaseService { if (!this.showDueChecklistOnDashboard) { return {individual: [], checklistItemNames: []} } - return this.dueChecklists(date, queryAdditions); + return this.dueChecklists(date, [], queryAdditions); } - dueChecklists = (date, queryAdditions) => { + dueChecklists = (date, reportFilters, queryAdditions) => { const childEnrolments = this.db.objects(ProgramEnrolment.schema.name) .filtered('voided = false ' + 'AND individual.voided = false ' + 'AND program.name = $0', 'Child') .filtered((_.isEmpty(queryAdditions) ? 'uuid != null' : `${queryAdditions}`));