From 3aec19e351c9ecff0750da17c31471d120534188 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Fri, 31 May 2024 15:05:02 +0530 Subject: [PATCH] #1381 - minor fixes --- .../src/service/customDashboard/ReportCardService.js | 8 +++++--- .../src/service/query/RealmQueryService.js | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/openchs-android/src/service/customDashboard/ReportCardService.js b/packages/openchs-android/src/service/customDashboard/ReportCardService.js index bf1e8b489..d065fc1b3 100644 --- a/packages/openchs-android/src/service/customDashboard/ReportCardService.js +++ b/packages/openchs-android/src/service/customDashboard/ReportCardService.js @@ -72,8 +72,10 @@ class ReportCardService extends BaseService { ]); const standardReportCardTypeName = reportCard.standardReportCardType.name; const resultFunc = typeToMethodMap.get(standardReportCardTypeName); - const programEncounterCriteria = RealmQueryService.programEncounterCriteria(reportCard.subjectTypes, reportCard.programs, reportCard.encounterTypes); - const generalEncounterCriteria = RealmQueryService.generalEncounterCriteria(reportCard.subjectTypes, reportCard.encounterTypes); + + const programEncounterCriteria = RealmQueryService.programEncounterCriteria(reportCard.standardReportCardInputSubjectTypes, + reportCard.standardReportCardInputPrograms, reportCard.standardReportCardInputEncounterTypes); + const generalEncounterCriteria = RealmQueryService.generalEncounterCriteria(reportCard.standardReportCardInputSubjectTypes, reportCard.standardReportCardInputEncounterTypes); const result = standardReportCardTypeName === StandardReportCardType.type.Total ? resultFunc(undefined, reportFilters) : resultFunc(new Date(), reportFilters, programEncounterCriteria, generalEncounterCriteria); const sortedResult = standardReportCardTypeName === StandardReportCardType.type.Total ? result : _.orderBy(result, ({visitInfo}) => visitInfo.sortingBy, 'desc'); return {status: standardReportCardTypeName, result: sortedResult}; @@ -149,7 +151,7 @@ class ReportCardService extends BaseService { */ getPlainUUIDFromCompositeReportCardUUID(reportCardUUID) { return reportCardUUID && (typeof reportCardUUID === 'string' || reportCardUUID instanceof String) - ? reportCardUUID.substring(0, reportCardUUID.indexOf('#')) : null; + ? reportCardUUID.substring(0, reportCardUUID.indexOf('#')) : null; } } diff --git a/packages/openchs-android/src/service/query/RealmQueryService.js b/packages/openchs-android/src/service/query/RealmQueryService.js index 7accb4be5..c032d47bc 100644 --- a/packages/openchs-android/src/service/query/RealmQueryService.js +++ b/packages/openchs-android/src/service/query/RealmQueryService.js @@ -35,15 +35,15 @@ class RealmQueryService { } static programEncounterCriteria(subjectTypes, programs, encounterTypes) { - const subjectTypeQuery = subjectTypes.length > 0 ? `programEnrolment.individual.subjectType.uuid IN ["${subjectTypes.join('", "')}"]` : ""; - const programQuery = programs.length > 0 ? `programEnrolment.program.uuid IN ["${programs.join('", "')}"]` : ""; - const encounterTypeQuery = encounterTypes.length > 0 ? `encounterType.uuid IN ["${encounterTypes.join('", "')}"]` : ""; + const subjectTypeQuery = RealmQueryService.orKeyValueQuery("programEnrolment.individual.subjectType.uuid", subjectTypes.map((x) => x.uuid)); + const programQuery = RealmQueryService.orKeyValueQuery("programEnrolment.program.uuid", programs.map((x) => x.uuid)); + const encounterTypeQuery = RealmQueryService.orKeyValueQuery("encounterType.uuid", encounterTypes.map((x) => x.uuid)); return RealmQueryService.andQuery([subjectTypeQuery, programQuery, encounterTypeQuery]); } static generalEncounterCriteria(subjectTypes, encounterTypes) { - const subjectTypeQuery = subjectTypes.length > 0 ? `individual.subjectType.uuid IN ["${subjectTypes.join('", "')}"]` : ""; - const encounterTypeQuery = encounterTypes.length > 0 ? `encounterType.uuid IN ["${encounterTypes.join('", "')}"]` : ""; + const subjectTypeQuery = RealmQueryService.orKeyValueQuery("individual.subjectType.uuid", subjectTypes.map((x) => x.uuid)); + const encounterTypeQuery = RealmQueryService.orKeyValueQuery("encounterType.uuid", encounterTypes.map((x) => x.uuid)); return RealmQueryService.andQuery([subjectTypeQuery, encounterTypeQuery]); } }