Skip to content

Commit

Permalink
#1185 - fixed signature to allow calling without any filter from MyDa…
Browse files Browse the repository at this point in the history
…shboardActions
  • Loading branch information
petmongrels committed Nov 17, 2023
1 parent 0fd8ab6 commit 1acd050
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -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
}));
Expand All @@ -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]));
}
}

Expand Down
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/openchs-android/src/GlobalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions packages/openchs-android/src/service/IndividualService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}`));
Expand Down

0 comments on commit 1acd050

Please sign in to comment.