@Test public void evaluate_shouldDetermineWhetherPatientsAreNotOnArt() throws Exception { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); EncounterType enrollmentEncounterType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT); Form enrollmentForm = MetadataUtils.existing(Form.class, MchMetadata._Form.MCHMS_ENROLLMENT); TestUtils.enrollInProgram(TestUtils.getPatient(2), mchmsProgram, new Date()); for (int i = 6; i <= 8; i++) { TestUtils.enrollInProgram(TestUtils.getPatient(i), mchmsProgram, new Date()); } Concept hivStatus = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept lmp = Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD); Concept artUse = Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY); Calendar tenWeeksAgo = Calendar.getInstance(); tenWeeksAgo.add(Calendar.DATE, -70); Calendar twentyWeeksAgo = Calendar.getInstance(); twentyWeeksAgo.add(Calendar.DATE, -140); Obs[] encounterObss2 = {TestUtils.saveObs(TestUtils.getPatient(2), hivStatus, Dictionary.getConcept(Dictionary.NEGATIVE), new Date()), TestUtils.saveObs(TestUtils.getPatient(2), lmp, twentyWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(TestUtils.getPatient(2), enrollmentEncounterType,enrollmentForm, new Date(), encounterObss2); TestUtils.saveObs(TestUtils.getPatient(2), artUse, Dictionary.getConcept(Dictionary.NOT_APPLICABLE), new Date()); Obs[] encounterObss6 = {TestUtils.saveObs(TestUtils.getPatient(6), hivStatus, Dictionary.getConcept(Dictionary.POSITIVE), new Date()), TestUtils.saveObs(TestUtils.getPatient(6), lmp, tenWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(TestUtils.getPatient(6), enrollmentEncounterType,enrollmentForm, new Date(), encounterObss6); TestUtils.saveObs(TestUtils.getPatient(6), artUse, Dictionary.getConcept(Dictionary.NOT_APPLICABLE), new Date()); Obs[] encounterObss7 = {TestUtils.saveObs(TestUtils.getPatient(7), hivStatus, Dictionary.getConcept(Dictionary.POSITIVE), new Date()), TestUtils.saveObs(TestUtils.getPatient(7), lmp, twentyWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(TestUtils.getPatient(7), enrollmentEncounterType,enrollmentForm, new Date(), encounterObss7); TestUtils.saveObs(TestUtils.getPatient(7), artUse, Dictionary.getConcept(Dictionary.NOT_APPLICABLE), new Date()); Obs[] encounterObss8 = {TestUtils.saveObs(TestUtils.getPatient(8), hivStatus, Dictionary.getConcept(Dictionary.POSITIVE), new Date()), TestUtils.saveObs(TestUtils.getPatient(8), lmp, twentyWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(TestUtils.getPatient(8), enrollmentEncounterType,enrollmentForm, new Date(), encounterObss8); TestUtils.saveObs(TestUtils.getPatient(8), artUse, Dictionary.getConcept(Dictionary.MOTHER_ON_PROPHYLAXIS), new Date()); Context.flushSession(); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(ptIds, new NotOnArtCalculation()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inMchmsProgram = Filters.inProgram(mchmsProgram, alive, context); CalculationResultMap lastHivStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap artStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY), inMchmsProgram, context); CalculationResultMap lmpObss = Calculations.firstObs(Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD), inMchmsProgram, context); Set<Integer> onART = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> eligibleForArt = CalculationUtils.patientsThatPass(calculate(new EligibleForArtCalculation(), cohort, context)); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean notOnArt = false; if (inMchmsProgram.contains(ptId) && !(onART.contains(ptId)) && !(eligibleForArt.contains(ptId))) { Concept lastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastHivStatusObss, ptId); Concept lastArtStatus = EmrCalculationUtils.codedObsResultForPatient(artStatusObss, ptId); Date lastLmpDate = EmrCalculationUtils.datetimeObsResultForPatient(lmpObss, ptId); boolean hivPositive = false; boolean onArt = false; if (lastHivStatus != null) { hivPositive = lastHivStatus.equals(Dictionary.getConcept(Dictionary.POSITIVE)); if (lastArtStatus != null) { onArt = !lastArtStatus.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE)); } } notOnArt = hivPositive && gestationIsGreaterThan14Weeks(lastLmpDate) && !onArt; } ret.put(ptId, new BooleanResult(notOnArt, this, context)); } return ret; }
NotOnArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inMchmsProgram = Filters.inProgram(mchmsProgram, alive, context); CalculationResultMap lastHivStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap artStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY), inMchmsProgram, context); CalculationResultMap lmpObss = Calculations.firstObs(Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD), inMchmsProgram, context); Set<Integer> onART = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> eligibleForArt = CalculationUtils.patientsThatPass(calculate(new EligibleForArtCalculation(), cohort, context)); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean notOnArt = false; if (inMchmsProgram.contains(ptId) && !(onART.contains(ptId)) && !(eligibleForArt.contains(ptId))) { Concept lastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastHivStatusObss, ptId); Concept lastArtStatus = EmrCalculationUtils.codedObsResultForPatient(artStatusObss, ptId); Date lastLmpDate = EmrCalculationUtils.datetimeObsResultForPatient(lmpObss, ptId); boolean hivPositive = false; boolean onArt = false; if (lastHivStatus != null) { hivPositive = lastHivStatus.equals(Dictionary.getConcept(Dictionary.POSITIVE)); if (lastArtStatus != null) { onArt = !lastArtStatus.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE)); } } notOnArt = hivPositive && gestationIsGreaterThan14Weeks(lastLmpDate) && !onArt; } ret.put(ptId, new BooleanResult(notOnArt, this, context)); } return ret; } }
NotOnArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inMchmsProgram = Filters.inProgram(mchmsProgram, alive, context); CalculationResultMap lastHivStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap artStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY), inMchmsProgram, context); CalculationResultMap lmpObss = Calculations.firstObs(Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD), inMchmsProgram, context); Set<Integer> onART = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> eligibleForArt = CalculationUtils.patientsThatPass(calculate(new EligibleForArtCalculation(), cohort, context)); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean notOnArt = false; if (inMchmsProgram.contains(ptId) && !(onART.contains(ptId)) && !(eligibleForArt.contains(ptId))) { Concept lastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastHivStatusObss, ptId); Concept lastArtStatus = EmrCalculationUtils.codedObsResultForPatient(artStatusObss, ptId); Date lastLmpDate = EmrCalculationUtils.datetimeObsResultForPatient(lmpObss, ptId); boolean hivPositive = false; boolean onArt = false; if (lastHivStatus != null) { hivPositive = lastHivStatus.equals(Dictionary.getConcept(Dictionary.POSITIVE)); if (lastArtStatus != null) { onArt = !lastArtStatus.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE)); } } notOnArt = hivPositive && gestationIsGreaterThan14Weeks(lastLmpDate) && !onArt; } ret.put(ptId, new BooleanResult(notOnArt, this, context)); } return ret; }  }
NotOnArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inMchmsProgram = Filters.inProgram(mchmsProgram, alive, context); CalculationResultMap lastHivStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap artStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY), inMchmsProgram, context); CalculationResultMap lmpObss = Calculations.firstObs(Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD), inMchmsProgram, context); Set<Integer> onART = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> eligibleForArt = CalculationUtils.patientsThatPass(calculate(new EligibleForArtCalculation(), cohort, context)); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean notOnArt = false; if (inMchmsProgram.contains(ptId) && !(onART.contains(ptId)) && !(eligibleForArt.contains(ptId))) { Concept lastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastHivStatusObss, ptId); Concept lastArtStatus = EmrCalculationUtils.codedObsResultForPatient(artStatusObss, ptId); Date lastLmpDate = EmrCalculationUtils.datetimeObsResultForPatient(lmpObss, ptId); boolean hivPositive = false; boolean onArt = false; if (lastHivStatus != null) { hivPositive = lastHivStatus.equals(Dictionary.getConcept(Dictionary.POSITIVE)); if (lastArtStatus != null) { onArt = !lastArtStatus.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE)); } } notOnArt = hivPositive && gestationIsGreaterThan14Weeks(lastLmpDate) && !onArt; } ret.put(ptId, new BooleanResult(notOnArt, this, context)); } return ret; }  @Override String getFlagMessage(); @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
NotOnArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inMchmsProgram = Filters.inProgram(mchmsProgram, alive, context); CalculationResultMap lastHivStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap artStatusObss = Calculations.lastObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY), inMchmsProgram, context); CalculationResultMap lmpObss = Calculations.firstObs(Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD), inMchmsProgram, context); Set<Integer> onART = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> eligibleForArt = CalculationUtils.patientsThatPass(calculate(new EligibleForArtCalculation(), cohort, context)); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean notOnArt = false; if (inMchmsProgram.contains(ptId) && !(onART.contains(ptId)) && !(eligibleForArt.contains(ptId))) { Concept lastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastHivStatusObss, ptId); Concept lastArtStatus = EmrCalculationUtils.codedObsResultForPatient(artStatusObss, ptId); Date lastLmpDate = EmrCalculationUtils.datetimeObsResultForPatient(lmpObss, ptId); boolean hivPositive = false; boolean onArt = false; if (lastHivStatus != null) { hivPositive = lastHivStatus.equals(Dictionary.getConcept(Dictionary.POSITIVE)); if (lastArtStatus != null) { onArt = !lastArtStatus.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE)); } } notOnArt = hivPositive && gestationIsGreaterThan14Weeks(lastLmpDate) && !onArt; } ret.put(ptId, new BooleanResult(notOnArt, this, context)); } return ret; }  @Override String getFlagMessage(); @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }