@Test public void evaluate_shouldDetermineWhetherCoupleIsDiscordant1() throws Exception { Program mchmsProgram = MetadataUtils.existing(Program.class, MchMetadata._Program.MCHMS); EncounterType enrollmentEncounterType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT); Form enrollmentForm = MetadataUtils.existing(Form.class, MchMetadata._Form.MCHMS_ENROLLMENT); Date enrollmentDate = TestUtils.date(2012, 1, 1); TestUtils.enrollInProgram(TestUtils.getPatient(2), mchmsProgram, enrollmentDate); for (int i = 6; i <= 8; i++) { TestUtils.enrollInProgram(TestUtils.getPatient(i), mchmsProgram, enrollmentDate); } Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); Concept patientHivTestDateConcept = Dictionary.getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS); Concept partnerHivTestDateConcept = Dictionary.getConcept(Dictionary.DATE_OF_PARTNER_HIV_DIAGNOSIS); { Patient patient = TestUtils.getPatient(6); Obs[] enrollmentEncounterObs = {TestUtils.saveObs(patient, partnerHivStatusConcept, Dictionary.getConcept(Dictionary.UNKNOWN), enrollmentDate)}; TestUtils.saveEncounter(patient, enrollmentEncounterType, enrollmentForm, enrollmentDate, enrollmentEncounterObs); TestUtils.saveObs(patient, partnerHivTestDateConcept, enrollmentDate, enrollmentDate); } { Patient patient = TestUtils.getPatient(7); Obs[] enrollmentEncounterObs = {TestUtils.saveObs(patient, patientHivStatusConcept, Dictionary.getConcept(Dictionary.NEGATIVE), enrollmentDate)}; TestUtils.saveEncounter(patient, enrollmentEncounterType, enrollmentForm, enrollmentDate, enrollmentEncounterObs); TestUtils.saveObs(patient, partnerHivStatusConcept, Dictionary.getConcept(Dictionary.NEGATIVE), enrollmentDate); TestUtils.saveObs(patient, patientHivTestDateConcept, enrollmentDate, enrollmentDate); TestUtils.saveObs(patient, partnerHivTestDateConcept, enrollmentDate, enrollmentDate); } { Patient patient = TestUtils.getPatient(8); Obs[] enrollmentEncounterObs = {TestUtils.saveObs(patient, patientHivStatusConcept, Dictionary.getConcept(Dictionary.NEGATIVE), enrollmentDate)}; TestUtils.saveEncounter(patient, enrollmentEncounterType, enrollmentForm, enrollmentDate, enrollmentEncounterObs); TestUtils.saveObs(patient, partnerHivStatusConcept, Dictionary.getConcept(Dictionary.POSITIVE), enrollmentDate); TestUtils.saveObs(patient, patientHivTestDateConcept, enrollmentDate, enrollmentDate); TestUtils.saveObs(patient, partnerHivTestDateConcept, enrollmentDate, enrollmentDate); } Context.flushSession(); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8); Map<String, Object> parameters = new HashMap<String, Object>(); CalculationResultMap resultMap = new DiscordantCoupleCalculation().evaluate(ptIds, parameters, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertFalse((Boolean) resultMap.get(7).getValue()); Assert.assertTrue((Boolean) resultMap.get(8).getValue()); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, 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); Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); CalculationResultMap lastPatientHivStatusObss = Calculations.lastObs(patientHivStatusConcept, inMchmsProgram, context); CalculationResultMap lastPartnerHivTestDateObss = Calculations.lastObs(partnerHivStatusConcept, inMchmsProgram, context); CalculationResultMap resultMap = new CalculationResultMap(); for (Integer ptId : cohort) { Concept patientLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPatientHivStatusObss, ptId); Concept partnerLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPartnerHivTestDateObss, ptId); boolean qualified = false; if (patientLastHivStatus != null && partnerLastHivStatus != null) { Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); if ((patientLastHivStatus.equals(positive) || patientLastHivStatus.equals(negative)) && (partnerLastHivStatus.equals(positive) || partnerLastHivStatus.equals(negative))) { qualified = !patientLastHivStatus.equals(partnerLastHivStatus); } } resultMap.put(ptId, new BooleanResult(qualified, this, context)); } return resultMap; }
DiscordantCoupleCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, 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); Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); CalculationResultMap lastPatientHivStatusObss = Calculations.lastObs(patientHivStatusConcept, inMchmsProgram, context); CalculationResultMap lastPartnerHivTestDateObss = Calculations.lastObs(partnerHivStatusConcept, inMchmsProgram, context); CalculationResultMap resultMap = new CalculationResultMap(); for (Integer ptId : cohort) { Concept patientLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPatientHivStatusObss, ptId); Concept partnerLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPartnerHivTestDateObss, ptId); boolean qualified = false; if (patientLastHivStatus != null && partnerLastHivStatus != null) { Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); if ((patientLastHivStatus.equals(positive) || patientLastHivStatus.equals(negative)) && (partnerLastHivStatus.equals(positive) || partnerLastHivStatus.equals(negative))) { qualified = !patientLastHivStatus.equals(partnerLastHivStatus); } } resultMap.put(ptId, new BooleanResult(qualified, this, context)); } return resultMap; } }
DiscordantCoupleCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, 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); Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); CalculationResultMap lastPatientHivStatusObss = Calculations.lastObs(patientHivStatusConcept, inMchmsProgram, context); CalculationResultMap lastPartnerHivTestDateObss = Calculations.lastObs(partnerHivStatusConcept, inMchmsProgram, context); CalculationResultMap resultMap = new CalculationResultMap(); for (Integer ptId : cohort) { Concept patientLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPatientHivStatusObss, ptId); Concept partnerLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPartnerHivTestDateObss, ptId); boolean qualified = false; if (patientLastHivStatus != null && partnerLastHivStatus != null) { Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); if ((patientLastHivStatus.equals(positive) || patientLastHivStatus.equals(negative)) && (partnerLastHivStatus.equals(positive) || partnerLastHivStatus.equals(negative))) { qualified = !patientLastHivStatus.equals(partnerLastHivStatus); } } resultMap.put(ptId, new BooleanResult(qualified, this, context)); } return resultMap; }  }
DiscordantCoupleCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, 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); Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); CalculationResultMap lastPatientHivStatusObss = Calculations.lastObs(patientHivStatusConcept, inMchmsProgram, context); CalculationResultMap lastPartnerHivTestDateObss = Calculations.lastObs(partnerHivStatusConcept, inMchmsProgram, context); CalculationResultMap resultMap = new CalculationResultMap(); for (Integer ptId : cohort) { Concept patientLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPatientHivStatusObss, ptId); Concept partnerLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPartnerHivTestDateObss, ptId); boolean qualified = false; if (patientLastHivStatus != null && partnerLastHivStatus != null) { Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); if ((patientLastHivStatus.equals(positive) || patientLastHivStatus.equals(negative)) && (partnerLastHivStatus.equals(positive) || partnerLastHivStatus.equals(negative))) { qualified = !patientLastHivStatus.equals(partnerLastHivStatus); } } resultMap.put(ptId, new BooleanResult(qualified, this, context)); } return resultMap; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, PatientCalculationContext context); }
DiscordantCoupleCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, 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); Concept patientHivStatusConcept = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept partnerHivStatusConcept = Dictionary.getConcept(Dictionary.PARTNER_HIV_STATUS); CalculationResultMap lastPatientHivStatusObss = Calculations.lastObs(patientHivStatusConcept, inMchmsProgram, context); CalculationResultMap lastPartnerHivTestDateObss = Calculations.lastObs(partnerHivStatusConcept, inMchmsProgram, context); CalculationResultMap resultMap = new CalculationResultMap(); for (Integer ptId : cohort) { Concept patientLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPatientHivStatusObss, ptId); Concept partnerLastHivStatus = EmrCalculationUtils.codedObsResultForPatient(lastPartnerHivTestDateObss, ptId); boolean qualified = false; if (patientLastHivStatus != null && partnerLastHivStatus != null) { Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); if ((patientLastHivStatus.equals(positive) || patientLastHivStatus.equals(negative)) && (partnerLastHivStatus.equals(positive) || partnerLastHivStatus.equals(negative))) { qualified = !patientLastHivStatus.equals(partnerLastHivStatus); } } resultMap.put(ptId, new BooleanResult(qualified, this, context)); } return resultMap; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, PatientCalculationContext context);  }