-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1448 - total standard report card type support.
- Loading branch information
1 parent
35a752d
commit f57ce97
Showing
8 changed files
with
156 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/openchs-android/src/service/customDashboard/ReportCardQueryBuilder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import RealmQueryService from "../query/RealmQueryService"; | ||
|
||
class ReportCardQueryBuilder { | ||
static getProgramEncounterCriteria(reportCard) { | ||
const subjectTypeQuery = RealmQueryService.orKeyValueQuery("programEnrolment.individual.subjectType.uuid", reportCard.standardReportCardInputSubjectTypes.map((x) => x.uuid)); | ||
const programQuery = RealmQueryService.orKeyValueQuery("programEnrolment.program.uuid", reportCard.standardReportCardInputPrograms.map((x) => x.uuid)); | ||
const encounterTypeQuery = RealmQueryService.orKeyValueQuery("encounterType.uuid", reportCard.standardReportCardInputEncounterTypes.map((x) => x.uuid)); | ||
return RealmQueryService.andQuery([subjectTypeQuery, programQuery, encounterTypeQuery]); | ||
} | ||
|
||
static getGeneralEncounterCriteria(reportCard) { | ||
const subjectTypeQuery = RealmQueryService.orKeyValueQuery("individual.subjectType.uuid", reportCard.standardReportCardInputSubjectTypes.map((x) => x.uuid)); | ||
const encounterTypeQuery = RealmQueryService.orKeyValueQuery("encounterType.uuid", reportCard.standardReportCardInputEncounterTypes.map((x) => x.uuid)); | ||
return RealmQueryService.andQuery([subjectTypeQuery, encounterTypeQuery]); | ||
} | ||
|
||
static getProgramEnrolmentCriteria(reportCard) { | ||
const subjectTypeQuery = RealmQueryService.orKeyValueQuery("individual.subjectType.uuid", reportCard.standardReportCardInputSubjectTypes.map((x) => x.uuid)); | ||
const programQuery = RealmQueryService.orKeyValueQuery("program.uuid", reportCard.standardReportCardInputPrograms.map((x) => x.uuid)); | ||
return RealmQueryService.andQuery([subjectTypeQuery, programQuery]); | ||
} | ||
|
||
static getSubjectCriteria(reportCard) { | ||
const uptoProgramEncounterCriteria = []; | ||
const uptoGeneralEncounterCriteria = []; | ||
|
||
const subjectCriteria = RealmQueryService.orKeyValueQuery("subjectType.uuid", reportCard.standardReportCardInputSubjectTypes.map((x) => x.uuid)); | ||
if (reportCard.hasInputForSubject() > 0) uptoProgramEncounterCriteria.push(subjectCriteria); | ||
|
||
const programMatch = RealmQueryService.orKeyValueQuery("$enrolment.program.uuid", reportCard.standardReportCardInputPrograms.map((x) => x.uuid)); | ||
const encounterTypeMatch = RealmQueryService.orKeyValueQuery("$encounter.encounterType.uuid", reportCard.standardReportCardInputEncounterTypes.map((x) => x.uuid)); | ||
|
||
const programEnrolmentWithEncounterTypeCriteria = `subquery(enrolments, $enrolment, $enrolment.voided = false and (${programMatch}) and (subquery($enrolment.encounters, $encounter, $encounter.voided = false and (${encounterTypeMatch})).@count > 0)).@count > 0`; | ||
const programEnrolmentWithoutEncounterTypeCriteria = `subquery(enrolments, $enrolment, $enrolment.voided = false and (${programMatch})).@count > 0`; | ||
if (reportCard.hasInputForProgramEncounter()) | ||
uptoProgramEncounterCriteria.push(programEnrolmentWithEncounterTypeCriteria); | ||
else if (reportCard.hasInputForEnrolment()) | ||
uptoProgramEncounterCriteria.push(programEnrolmentWithoutEncounterTypeCriteria); | ||
|
||
if (reportCard.hasInputForGeneralEncounter()) { | ||
uptoGeneralEncounterCriteria.push(subjectCriteria); | ||
uptoGeneralEncounterCriteria.push(`subquery(encounters, $encounter, $encounter.voided = false and (${encounterTypeMatch})).@count > 0`); | ||
} | ||
|
||
return RealmQueryService.orQuery([RealmQueryService.andQuery(uptoProgramEncounterCriteria), RealmQueryService.andQuery(uptoGeneralEncounterCriteria)]); | ||
} | ||
} | ||
|
||
export default ReportCardQueryBuilder; |
Oops, something went wrong.