@Test public void evaluate2_shouldDetermineWhetherPatientsAreNotOnArt() throws Exception { List<Integer> ptIds = Arrays.asList(2, 999); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(ptIds, new NotOnArtCalculation()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).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);  }