@Test public void evaluate_shouldCalculatePregnancyStatusAtArtStart() throws Exception { Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept no = Dictionary.getConcept(Dictionary.NO); Concept stavudine = Dictionary.getConcept(Dictionary.STAVUDINE); TestUtils.getPatient(2).setGender("F"); TestUtils.getPatient(6).setGender("F"); TestUtils.saveObs(TestUtils.getPatient(2), pregnancyStatus, yes, TestUtils.date(2007, 12, 25)); TestUtils.saveObs(TestUtils.getPatient(6), pregnancyStatus, yes, TestUtils.date(2012, 1, 1)); TestUtils.saveDrugOrder(TestUtils.getPatient(6), stavudine, TestUtils.date(2012, 1, 8), null); TestUtils.saveObs(TestUtils.getPatient(7), pregnancyStatus, yes, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(7), pregnancyStatus, no, TestUtils.date(2012, 1, 3)); TestUtils.saveDrugOrder(TestUtils.getPatient(7), stavudine, TestUtils.date(2012, 1, 8), null); TestUtils.saveObs(TestUtils.getPatient(8), pregnancyStatus, yes, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(8), pregnancyStatus, no, TestUtils.date(2012, 1, 15)); TestUtils.saveDrugOrder(TestUtils.getPatient(8), stavudine, TestUtils.date(2012, 1, 8), null); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8, 999); CalculationResultMap resultMap = new PregnantAtArtStartCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertTrue((Boolean) resultMap.get(2).getValue()); Assert.assertTrue((Boolean) resultMap.get(6).getValue()); Assert.assertFalse((Boolean) resultMap.get(7).getValue()); Assert.assertTrue((Boolean) resultMap.get(8).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Set<Integer> female = Filters.female(cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), female, context); CalculationResultMap pregnancyObss = Calculations.allObs(pregnancyStatus, female, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (female.contains(ptId)) { Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult pregObssResult = (ListResult) pregnancyObss.get(ptId); if (artStartDate != null && pregObssResult != null && !pregObssResult.isEmpty()) { List<Obs> pregnancyStatuses = CalculationUtils.extractResultValues(pregObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(pregnancyStatuses, artStartDate); if (lastBeforeArtStart != null && lastBeforeArtStart.getValueCoded().equals(yes)) { result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }
PregnantAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Set<Integer> female = Filters.female(cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), female, context); CalculationResultMap pregnancyObss = Calculations.allObs(pregnancyStatus, female, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (female.contains(ptId)) { Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult pregObssResult = (ListResult) pregnancyObss.get(ptId); if (artStartDate != null && pregObssResult != null && !pregObssResult.isEmpty()) { List<Obs> pregnancyStatuses = CalculationUtils.extractResultValues(pregObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(pregnancyStatuses, artStartDate); if (lastBeforeArtStart != null && lastBeforeArtStart.getValueCoded().equals(yes)) { result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; } }
PregnantAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Set<Integer> female = Filters.female(cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), female, context); CalculationResultMap pregnancyObss = Calculations.allObs(pregnancyStatus, female, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (female.contains(ptId)) { Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult pregObssResult = (ListResult) pregnancyObss.get(ptId); if (artStartDate != null && pregObssResult != null && !pregObssResult.isEmpty()) { List<Obs> pregnancyStatuses = CalculationUtils.extractResultValues(pregObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(pregnancyStatuses, artStartDate); if (lastBeforeArtStart != null && lastBeforeArtStart.getValueCoded().equals(yes)) { result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  }
PregnantAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Set<Integer> female = Filters.female(cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), female, context); CalculationResultMap pregnancyObss = Calculations.allObs(pregnancyStatus, female, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (female.contains(ptId)) { Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult pregObssResult = (ListResult) pregnancyObss.get(ptId); if (artStartDate != null && pregObssResult != null && !pregObssResult.isEmpty()) { List<Obs> pregnancyStatuses = CalculationUtils.extractResultValues(pregObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(pregnancyStatuses, artStartDate); if (lastBeforeArtStart != null && lastBeforeArtStart.getValueCoded().equals(yes)) { result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
PregnantAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Set<Integer> female = Filters.female(cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept pregnancyStatus = Dictionary.getConcept(Dictionary.PREGNANCY_STATUS); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), female, context); CalculationResultMap pregnancyObss = Calculations.allObs(pregnancyStatus, female, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (female.contains(ptId)) { Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult pregObssResult = (ListResult) pregnancyObss.get(ptId); if (artStartDate != null && pregObssResult != null && !pregObssResult.isEmpty()) { List<Obs> pregnancyStatuses = CalculationUtils.extractResultValues(pregObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(pregnancyStatuses, artStartDate); if (lastBeforeArtStart != null && lastBeforeArtStart.getValueCoded().equals(yes)) { result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }