@Test public void evaluate_shouldCalculateWhoStageAtArtStart() throws Exception { Concept whoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); Concept whoStage1Adults = Dictionary.getConcept(Dictionary.WHO_STAGE_1_ADULT); Concept whoStage2Adults = Dictionary.getConcept(Dictionary.WHO_STAGE_2_ADULT); Concept whoStageUnknown = Dictionary.getConcept(Dictionary.UNKNOWN); Concept stavudine = Dictionary.getConcept(Dictionary.STAVUDINE); TestUtils.saveObs(TestUtils.getPatient(2), whoStage, whoStage1Adults, TestUtils.date(2007, 12, 25)); TestUtils.saveObs(TestUtils.getPatient(6), whoStage, whoStage1Adults, TestUtils.date(2012, 1, 1)); TestUtils.saveDrugOrder(TestUtils.getPatient(6), stavudine, TestUtils.date(2012, 1, 8), null); TestUtils.saveObs(TestUtils.getPatient(7), whoStage, whoStage1Adults, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(7), whoStage, whoStageUnknown, TestUtils.date(2012, 1, 3)); TestUtils.saveDrugOrder(TestUtils.getPatient(7), stavudine, TestUtils.date(2012, 1, 8), null); TestUtils.saveObs(TestUtils.getPatient(8), whoStage, whoStage1Adults, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(8), whoStage, whoStage2Adults, TestUtils.date(2012, 1, 15)); TestUtils.saveDrugOrder(TestUtils.getPatient(8), stavudine, TestUtils.date(2012, 1, 8), null); Context.flushSession(); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8, 999); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(ptIds, new WhoStageAtArtStartCalculation()); Assert.assertEquals(1, resultMap.get(2).getValue()); Assert.assertEquals(1, resultMap.get(6).getValue()); Assert.assertNull(resultMap.get(7)); Assert.assertEquals(1, resultMap.get(8).getValue()); Assert.assertNull(resultMap.get(999)); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept currentWhoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context); CalculationResultMap whoStageObss = Calculations.allObs(currentWhoStage, cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { SimpleResult result = null; Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult whoStageObssResult = (ListResult) whoStageObss.get(ptId); if (artStartDate != null && whoStageObssResult != null && !whoStageObssResult.isEmpty()) { List<Obs> whoStages = CalculationUtils.extractResultValues(whoStageObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(whoStages, artStartDate); if (lastBeforeArtStart != null) { Integer whoStage = EmrUtils.whoStage(lastBeforeArtStart.getValueCoded()); if (whoStage != null) { result = new SimpleResult(whoStage, this); } } } ret.put(ptId, result); } return ret; }
WhoStageAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept currentWhoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context); CalculationResultMap whoStageObss = Calculations.allObs(currentWhoStage, cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { SimpleResult result = null; Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult whoStageObssResult = (ListResult) whoStageObss.get(ptId); if (artStartDate != null && whoStageObssResult != null && !whoStageObssResult.isEmpty()) { List<Obs> whoStages = CalculationUtils.extractResultValues(whoStageObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(whoStages, artStartDate); if (lastBeforeArtStart != null) { Integer whoStage = EmrUtils.whoStage(lastBeforeArtStart.getValueCoded()); if (whoStage != null) { result = new SimpleResult(whoStage, this); } } } ret.put(ptId, result); } return ret; } }
WhoStageAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept currentWhoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context); CalculationResultMap whoStageObss = Calculations.allObs(currentWhoStage, cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { SimpleResult result = null; Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult whoStageObssResult = (ListResult) whoStageObss.get(ptId); if (artStartDate != null && whoStageObssResult != null && !whoStageObssResult.isEmpty()) { List<Obs> whoStages = CalculationUtils.extractResultValues(whoStageObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(whoStages, artStartDate); if (lastBeforeArtStart != null) { Integer whoStage = EmrUtils.whoStage(lastBeforeArtStart.getValueCoded()); if (whoStage != null) { result = new SimpleResult(whoStage, this); } } } ret.put(ptId, result); } return ret; }  }
WhoStageAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept currentWhoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context); CalculationResultMap whoStageObss = Calculations.allObs(currentWhoStage, cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { SimpleResult result = null; Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult whoStageObssResult = (ListResult) whoStageObss.get(ptId); if (artStartDate != null && whoStageObssResult != null && !whoStageObssResult.isEmpty()) { List<Obs> whoStages = CalculationUtils.extractResultValues(whoStageObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(whoStages, artStartDate); if (lastBeforeArtStart != null) { Integer whoStage = EmrUtils.whoStage(lastBeforeArtStart.getValueCoded()); if (whoStage != null) { result = new SimpleResult(whoStage, this); } } } ret.put(ptId, result); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
WhoStageAtArtStartCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept currentWhoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context); CalculationResultMap whoStageObss = Calculations.allObs(currentWhoStage, cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { SimpleResult result = null; Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId); ListResult whoStageObssResult = (ListResult) whoStageObss.get(ptId); if (artStartDate != null && whoStageObssResult != null && !whoStageObssResult.isEmpty()) { List<Obs> whoStages = CalculationUtils.extractResultValues(whoStageObssResult); Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(whoStages, artStartDate); if (lastBeforeArtStart != null) { Integer whoStage = EmrUtils.whoStage(lastBeforeArtStart.getValueCoded()); if (whoStage != null) { result = new SimpleResult(whoStage, this); } } } ret.put(ptId, result); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }