@Test public void evaluate_shouldCalculateEligibilityTrigger() throws Exception { Concept diagnosisDate = Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS); Concept cd4 = Dictionary.getConcept(Dictionary.CD4_COUNT); Concept whoStage = Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE); TestUtils.saveObs(TestUtils.getPatient(6), diagnosisDate, TestUtils.date(2008, 05, 27), TestUtils.date(2010, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(6), cd4, 300.0, TestUtils.date(2009, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(7), cd4, 900.0, TestUtils.date(1979, 8, 25)); TestUtils.saveObs(TestUtils.getPatient(7), cd4, 300.0, TestUtils.date(2009, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(8), whoStage, Dictionary.getConcept(Dictionary.WHO_STAGE_3_PEDS), TestUtils.date(2009, 1, 1)); List<Integer> cohort = Arrays.asList(6, 7, 8, 999); CalculationResultMap resultMap = new EligibleForArtTriggerCalculation().evaluate(cohort, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Obs patient6Trigger = (Obs) resultMap.get(6).getValue(); Assert.assertEquals(diagnosisDate, patient6Trigger.getConcept()); Assert.assertEquals(TestUtils.date(2008, 05, 27), patient6Trigger.getValueDate()); Obs patient7Trigger = (Obs) resultMap.get(7).getValue(); Assert.assertEquals(cd4, patient7Trigger.getConcept()); Assert.assertEquals(TestUtils.date(1979, 8, 25), patient7Trigger.getObsDatetime()); Obs patient8Trigger = (Obs) resultMap.get(8).getValue(); Assert.assertEquals(whoStage, patient8Trigger.getConcept()); Assert.assertEquals(TestUtils.date(2009, 1, 1), patient8Trigger.getObsDatetime()); Assert.assertNull(resultMap.get(999)); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { CalculationResultMap confirmedPositives = Calculations.allObs(Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), cohort, context); CalculationResultMap whoStages = Calculations.allObs(Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE), cohort, context); CalculationResultMap cdCounts = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_COUNT), cohort, context); CalculationResultMap cdPercents = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { List<Obs> confirmedPosObss = CalculationUtils.extractResultValues((ListResult) confirmedPositives.get(ptId)); List<Obs> whoStageObss = CalculationUtils.extractResultValues((ListResult) whoStages.get(ptId)); List<Obs> cdCountObss = CalculationUtils.extractResultValues((ListResult) cdCounts.get(ptId)); List<Obs> cdPercentObss = CalculationUtils.extractResultValues((ListResult) cdPercents.get(ptId)); List<Obs> allObss = new ArrayList<Obs>(); allObss.addAll(confirmedPosObss); allObss.addAll(whoStageObss); allObss.addAll(cdCountObss); allObss.addAll(cdPercentObss); List<Obs> allTriggerObss = extractTriggers(allObss); Obs eligibilityTriggerObs = findEarliestTrigger(allTriggerObss); ret.put(ptId, eligibilityTriggerObs != null ? new ObsResult(eligibilityTriggerObs, this) : null); } return ret; }
EligibleForArtTriggerCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { CalculationResultMap confirmedPositives = Calculations.allObs(Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), cohort, context); CalculationResultMap whoStages = Calculations.allObs(Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE), cohort, context); CalculationResultMap cdCounts = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_COUNT), cohort, context); CalculationResultMap cdPercents = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { List<Obs> confirmedPosObss = CalculationUtils.extractResultValues((ListResult) confirmedPositives.get(ptId)); List<Obs> whoStageObss = CalculationUtils.extractResultValues((ListResult) whoStages.get(ptId)); List<Obs> cdCountObss = CalculationUtils.extractResultValues((ListResult) cdCounts.get(ptId)); List<Obs> cdPercentObss = CalculationUtils.extractResultValues((ListResult) cdPercents.get(ptId)); List<Obs> allObss = new ArrayList<Obs>(); allObss.addAll(confirmedPosObss); allObss.addAll(whoStageObss); allObss.addAll(cdCountObss); allObss.addAll(cdPercentObss); List<Obs> allTriggerObss = extractTriggers(allObss); Obs eligibilityTriggerObs = findEarliestTrigger(allTriggerObss); ret.put(ptId, eligibilityTriggerObs != null ? new ObsResult(eligibilityTriggerObs, this) : null); } return ret; } }
EligibleForArtTriggerCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { CalculationResultMap confirmedPositives = Calculations.allObs(Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), cohort, context); CalculationResultMap whoStages = Calculations.allObs(Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE), cohort, context); CalculationResultMap cdCounts = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_COUNT), cohort, context); CalculationResultMap cdPercents = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { List<Obs> confirmedPosObss = CalculationUtils.extractResultValues((ListResult) confirmedPositives.get(ptId)); List<Obs> whoStageObss = CalculationUtils.extractResultValues((ListResult) whoStages.get(ptId)); List<Obs> cdCountObss = CalculationUtils.extractResultValues((ListResult) cdCounts.get(ptId)); List<Obs> cdPercentObss = CalculationUtils.extractResultValues((ListResult) cdPercents.get(ptId)); List<Obs> allObss = new ArrayList<Obs>(); allObss.addAll(confirmedPosObss); allObss.addAll(whoStageObss); allObss.addAll(cdCountObss); allObss.addAll(cdPercentObss); List<Obs> allTriggerObss = extractTriggers(allObss); Obs eligibilityTriggerObs = findEarliestTrigger(allTriggerObss); ret.put(ptId, eligibilityTriggerObs != null ? new ObsResult(eligibilityTriggerObs, this) : null); } return ret; }  }
EligibleForArtTriggerCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { CalculationResultMap confirmedPositives = Calculations.allObs(Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), cohort, context); CalculationResultMap whoStages = Calculations.allObs(Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE), cohort, context); CalculationResultMap cdCounts = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_COUNT), cohort, context); CalculationResultMap cdPercents = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { List<Obs> confirmedPosObss = CalculationUtils.extractResultValues((ListResult) confirmedPositives.get(ptId)); List<Obs> whoStageObss = CalculationUtils.extractResultValues((ListResult) whoStages.get(ptId)); List<Obs> cdCountObss = CalculationUtils.extractResultValues((ListResult) cdCounts.get(ptId)); List<Obs> cdPercentObss = CalculationUtils.extractResultValues((ListResult) cdPercents.get(ptId)); List<Obs> allObss = new ArrayList<Obs>(); allObss.addAll(confirmedPosObss); allObss.addAll(whoStageObss); allObss.addAll(cdCountObss); allObss.addAll(cdPercentObss); List<Obs> allTriggerObss = extractTriggers(allObss); Obs eligibilityTriggerObs = findEarliestTrigger(allTriggerObss); ret.put(ptId, eligibilityTriggerObs != null ? new ObsResult(eligibilityTriggerObs, this) : null); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
	                                     PatientCalculationContext context); }
EligibleForArtTriggerCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { CalculationResultMap confirmedPositives = Calculations.allObs(Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), cohort, context); CalculationResultMap whoStages = Calculations.allObs(Dictionary.getConcept(Dictionary.CURRENT_WHO_STAGE), cohort, context); CalculationResultMap cdCounts = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_COUNT), cohort, context); CalculationResultMap cdPercents = Calculations.allObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { List<Obs> confirmedPosObss = CalculationUtils.extractResultValues((ListResult) confirmedPositives.get(ptId)); List<Obs> whoStageObss = CalculationUtils.extractResultValues((ListResult) whoStages.get(ptId)); List<Obs> cdCountObss = CalculationUtils.extractResultValues((ListResult) cdCounts.get(ptId)); List<Obs> cdPercentObss = CalculationUtils.extractResultValues((ListResult) cdPercents.get(ptId)); List<Obs> allObss = new ArrayList<Obs>(); allObss.addAll(confirmedPosObss); allObss.addAll(whoStageObss); allObss.addAll(cdCountObss); allObss.addAll(cdPercentObss); List<Obs> allTriggerObss = extractTriggers(allObss); Obs eligibilityTriggerObs = findEarliestTrigger(allTriggerObss); ret.put(ptId, eligibilityTriggerObs != null ? new ObsResult(eligibilityTriggerObs, this) : null); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
	                                     PatientCalculationContext context);  }