@Test public void evaluate() throws Exception { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); TestUtils.enrollInProgram(TestUtils.getPatient(2), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(6), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram, TestUtils.date(2011, 1, 1)); EncounterType type = MetadataUtils.existing(EncounterType.class, HivMetadata._EncounterType.HIV_CONSULTATION); Obs obs = new Obs(); obs.setConcept(Dictionary.getConcept(Dictionary.CIVIL_STATUS)); obs.setObsDatetime(new Date()); obs.setValueCoded(Dictionary.getConcept(Dictionary.MARRIED_MONOGAMOUS)); TestUtils.saveEncounter(TestUtils.getPatient(7), type, new Date(), obs); Concept ctxDispensed = Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED); Concept yes = Dictionary.getConcept(Dictionary.YES); TestUtils.saveObs(TestUtils.getPatient(2), ctxDispensed, yes, TestUtils.date(2011, 1, 1)); Concept medOrders = Dictionary.getConcept(Dictionary.MEDICATION_ORDERS); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); TestUtils.saveObs(TestUtils.getPatient(6), medOrders, dapsone, TestUtils.date(2011, 1, 1)); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8); CalculationResultMap resultMap = new NeverTakenCtxOrDapsoneCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); 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()); }
@SuppressWarnings("unchecked") @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); CalculationResultMap medOrdersObss = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context); CalculationResultMap ctxProphylaxisObss = Calculations.allObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), cohort, context); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpCalculation(), cohort, context)); Date endOfReportingPeriod = DateUtil.getEndOfMonth(DateUtil.adjustDate(DateUtil.getStartOfMonth(context.getNow()), -1, DurationUnit.DAYS)); Date startOfReportingPeriod = DateUtil.adjustDate(DateUtil.adjustDate(endOfReportingPeriod, -3, DurationUnit.MONTHS), -1, DurationUnit.DAYS); CalculationResultMap activePatients = Calculations.allEncounters(null, cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept ctx = Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean neverTakenCtxOrDapsone = false; boolean isActive = false; ListResult listResult = (ListResult) activePatients.get(ptId); List<Encounter> allEncounters = CalculationUtils.extractResultValues(listResult); for(Encounter encounter : allEncounters) { if(encounter.getEncounterDatetime().after(startOfReportingPeriod)) { isActive = true; break; } } if (inHivProgram.contains(ptId) && isActive) { neverTakenCtxOrDapsone = true; ListResult ctxProphylaxis = (ListResult) ctxProphylaxisObss.get(ptId); if (ctxProphylaxis != null) { List<Obs> ctxProphylaxisObsList = CalculationUtils.extractResultValues(ctxProphylaxis); for (Obs ctxProphylaxisObs : ctxProphylaxisObsList) { if (ctxProphylaxisObs.getValueCoded().equals(yes)) { neverTakenCtxOrDapsone = false; break; } } } if (neverTakenCtxOrDapsone) { ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId); if (patientMedOrders != null) { List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders); for (Obs medOrderObs : medOrderObsList) { if (medOrderObs.getValueCoded().equals(dapsone) || medOrderObs.getValueCoded().equals(ctx)) { neverTakenCtxOrDapsone = false; break; } } } } } if(ltfu.contains(ptId)){ neverTakenCtxOrDapsone = false; } ret.put(ptId, new BooleanResult(neverTakenCtxOrDapsone, this)); } return ret; }
NeverTakenCtxOrDapsoneCalculation extends AbstractPatientCalculation { @SuppressWarnings("unchecked") @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); CalculationResultMap medOrdersObss = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context); CalculationResultMap ctxProphylaxisObss = Calculations.allObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), cohort, context); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpCalculation(), cohort, context)); Date endOfReportingPeriod = DateUtil.getEndOfMonth(DateUtil.adjustDate(DateUtil.getStartOfMonth(context.getNow()), -1, DurationUnit.DAYS)); Date startOfReportingPeriod = DateUtil.adjustDate(DateUtil.adjustDate(endOfReportingPeriod, -3, DurationUnit.MONTHS), -1, DurationUnit.DAYS); CalculationResultMap activePatients = Calculations.allEncounters(null, cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept ctx = Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean neverTakenCtxOrDapsone = false; boolean isActive = false; ListResult listResult = (ListResult) activePatients.get(ptId); List<Encounter> allEncounters = CalculationUtils.extractResultValues(listResult); for(Encounter encounter : allEncounters) { if(encounter.getEncounterDatetime().after(startOfReportingPeriod)) { isActive = true; break; } } if (inHivProgram.contains(ptId) && isActive) { neverTakenCtxOrDapsone = true; ListResult ctxProphylaxis = (ListResult) ctxProphylaxisObss.get(ptId); if (ctxProphylaxis != null) { List<Obs> ctxProphylaxisObsList = CalculationUtils.extractResultValues(ctxProphylaxis); for (Obs ctxProphylaxisObs : ctxProphylaxisObsList) { if (ctxProphylaxisObs.getValueCoded().equals(yes)) { neverTakenCtxOrDapsone = false; break; } } } if (neverTakenCtxOrDapsone) { ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId); if (patientMedOrders != null) { List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders); for (Obs medOrderObs : medOrderObsList) { if (medOrderObs.getValueCoded().equals(dapsone) || medOrderObs.getValueCoded().equals(ctx)) { neverTakenCtxOrDapsone = false; break; } } } } } if(ltfu.contains(ptId)){ neverTakenCtxOrDapsone = false; } ret.put(ptId, new BooleanResult(neverTakenCtxOrDapsone, this)); } return ret; } }
NeverTakenCtxOrDapsoneCalculation extends AbstractPatientCalculation { @SuppressWarnings("unchecked") @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); CalculationResultMap medOrdersObss = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context); CalculationResultMap ctxProphylaxisObss = Calculations.allObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), cohort, context); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpCalculation(), cohort, context)); Date endOfReportingPeriod = DateUtil.getEndOfMonth(DateUtil.adjustDate(DateUtil.getStartOfMonth(context.getNow()), -1, DurationUnit.DAYS)); Date startOfReportingPeriod = DateUtil.adjustDate(DateUtil.adjustDate(endOfReportingPeriod, -3, DurationUnit.MONTHS), -1, DurationUnit.DAYS); CalculationResultMap activePatients = Calculations.allEncounters(null, cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept ctx = Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean neverTakenCtxOrDapsone = false; boolean isActive = false; ListResult listResult = (ListResult) activePatients.get(ptId); List<Encounter> allEncounters = CalculationUtils.extractResultValues(listResult); for(Encounter encounter : allEncounters) { if(encounter.getEncounterDatetime().after(startOfReportingPeriod)) { isActive = true; break; } } if (inHivProgram.contains(ptId) && isActive) { neverTakenCtxOrDapsone = true; ListResult ctxProphylaxis = (ListResult) ctxProphylaxisObss.get(ptId); if (ctxProphylaxis != null) { List<Obs> ctxProphylaxisObsList = CalculationUtils.extractResultValues(ctxProphylaxis); for (Obs ctxProphylaxisObs : ctxProphylaxisObsList) { if (ctxProphylaxisObs.getValueCoded().equals(yes)) { neverTakenCtxOrDapsone = false; break; } } } if (neverTakenCtxOrDapsone) { ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId); if (patientMedOrders != null) { List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders); for (Obs medOrderObs : medOrderObsList) { if (medOrderObs.getValueCoded().equals(dapsone) || medOrderObs.getValueCoded().equals(ctx)) { neverTakenCtxOrDapsone = false; break; } } } } } if(ltfu.contains(ptId)){ neverTakenCtxOrDapsone = false; } ret.put(ptId, new BooleanResult(neverTakenCtxOrDapsone, this)); } return ret; }  }
NeverTakenCtxOrDapsoneCalculation extends AbstractPatientCalculation { @SuppressWarnings("unchecked") @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); CalculationResultMap medOrdersObss = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context); CalculationResultMap ctxProphylaxisObss = Calculations.allObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), cohort, context); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpCalculation(), cohort, context)); Date endOfReportingPeriod = DateUtil.getEndOfMonth(DateUtil.adjustDate(DateUtil.getStartOfMonth(context.getNow()), -1, DurationUnit.DAYS)); Date startOfReportingPeriod = DateUtil.adjustDate(DateUtil.adjustDate(endOfReportingPeriod, -3, DurationUnit.MONTHS), -1, DurationUnit.DAYS); CalculationResultMap activePatients = Calculations.allEncounters(null, cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept ctx = Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean neverTakenCtxOrDapsone = false; boolean isActive = false; ListResult listResult = (ListResult) activePatients.get(ptId); List<Encounter> allEncounters = CalculationUtils.extractResultValues(listResult); for(Encounter encounter : allEncounters) { if(encounter.getEncounterDatetime().after(startOfReportingPeriod)) { isActive = true; break; } } if (inHivProgram.contains(ptId) && isActive) { neverTakenCtxOrDapsone = true; ListResult ctxProphylaxis = (ListResult) ctxProphylaxisObss.get(ptId); if (ctxProphylaxis != null) { List<Obs> ctxProphylaxisObsList = CalculationUtils.extractResultValues(ctxProphylaxis); for (Obs ctxProphylaxisObs : ctxProphylaxisObsList) { if (ctxProphylaxisObs.getValueCoded().equals(yes)) { neverTakenCtxOrDapsone = false; break; } } } if (neverTakenCtxOrDapsone) { ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId); if (patientMedOrders != null) { List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders); for (Obs medOrderObs : medOrderObsList) { if (medOrderObs.getValueCoded().equals(dapsone) || medOrderObs.getValueCoded().equals(ctx)) { neverTakenCtxOrDapsone = false; break; } } } } } if(ltfu.contains(ptId)){ neverTakenCtxOrDapsone = false; } ret.put(ptId, new BooleanResult(neverTakenCtxOrDapsone, this)); } return ret; }  @SuppressWarnings("unchecked") @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
NeverTakenCtxOrDapsoneCalculation extends AbstractPatientCalculation { @SuppressWarnings("unchecked") @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); CalculationResultMap medOrdersObss = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context); CalculationResultMap ctxProphylaxisObss = Calculations.allObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), cohort, context); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpCalculation(), cohort, context)); Date endOfReportingPeriod = DateUtil.getEndOfMonth(DateUtil.adjustDate(DateUtil.getStartOfMonth(context.getNow()), -1, DurationUnit.DAYS)); Date startOfReportingPeriod = DateUtil.adjustDate(DateUtil.adjustDate(endOfReportingPeriod, -3, DurationUnit.MONTHS), -1, DurationUnit.DAYS); CalculationResultMap activePatients = Calculations.allEncounters(null, cohort, context); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept ctx = Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean neverTakenCtxOrDapsone = false; boolean isActive = false; ListResult listResult = (ListResult) activePatients.get(ptId); List<Encounter> allEncounters = CalculationUtils.extractResultValues(listResult); for(Encounter encounter : allEncounters) { if(encounter.getEncounterDatetime().after(startOfReportingPeriod)) { isActive = true; break; } } if (inHivProgram.contains(ptId) && isActive) { neverTakenCtxOrDapsone = true; ListResult ctxProphylaxis = (ListResult) ctxProphylaxisObss.get(ptId); if (ctxProphylaxis != null) { List<Obs> ctxProphylaxisObsList = CalculationUtils.extractResultValues(ctxProphylaxis); for (Obs ctxProphylaxisObs : ctxProphylaxisObsList) { if (ctxProphylaxisObs.getValueCoded().equals(yes)) { neverTakenCtxOrDapsone = false; break; } } } if (neverTakenCtxOrDapsone) { ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId); if (patientMedOrders != null) { List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders); for (Obs medOrderObs : medOrderObsList) { if (medOrderObs.getValueCoded().equals(dapsone) || medOrderObs.getValueCoded().equals(ctx)) { neverTakenCtxOrDapsone = false; break; } } } } } if(ltfu.contains(ptId)){ neverTakenCtxOrDapsone = false; } ret.put(ptId, new BooleanResult(neverTakenCtxOrDapsone, this)); } return ret; }  @SuppressWarnings("unchecked") @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }