Source:
<code>public void evaluate_shouldDetermineWhetherPatientsEnrolledLate() throws Exception { Program mchmsProgram = MetadataUtils.getProgram(Metadata.Program.MCHMS); EncounterType enrollmentEncounterType = MetadataUtils.getEncounterType(Metadata.EncounterType.MCHMS_ENROLLMENT); Form enrollmentForm = MetadataUtils.getForm(Metadata.Form.MCHMS_ENROLLMENT); PatientService patientService = Context.getPatientService(); for (int i = 6; i <= 7; i++) { TestUtils.enrollInProgram(patientService.getPatient(i), mchmsProgram, new Date()); } Concept lmp = Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD); Calendar tenWeeksAgo = Calendar.getInstance(); tenWeeksAgo.add(Calendar.DATE, -70); Calendar twentyWeeksAgo = Calendar.getInstance(); twentyWeeksAgo.add(Calendar.DATE, -210); Obs[] encounterObss6 = {TestUtils.saveObs(patientService.getPatient(6), lmp, tenWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(patientService.getPatient(6), enrollmentEncounterType, enrollmentForm, new Date(), encounterObss6); Obs[] encounterObss7 = {TestUtils.saveObs(patientService.getPatient(7), lmp, twentyWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(patientService.getPatient(7), enrollmentEncounterType, enrollmentForm, new Date(), encounterObss7); Context.flushSession(); List<Integer> ptIds = Arrays.asList(6, 7, 999); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(ptIds, new LateEnrollmentCalculation()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); <START> Assert.assertFalse((Boolean) resultMap.get(999).getValue()); END> }</code><technical_language>Patient #999 is voided - reason calculate true. #8 instead example of a patient in MCHMS</technical_language>

Target:
public void evaluate_shouldDetermineWhetherPatientsEnrolledLate() throws Exception { Program mchmsProgram = MetadataUtils.getProgram(Metadata.Program.MCHMS); EncounterType enrollmentEncounterType = MetadataUtils.getEncounterType(Metadata.EncounterType.MCHMS_ENROLLMENT); Form enrollmentForm = MetadataUtils.getForm(Metadata.Form.MCHMS_ENROLLMENT); PatientService patientService = Context.getPatientService(); for (int i = 6; i <= 7; i++) { TestUtils.enrollInProgram(patientService.getPatient(i), mchmsProgram, new Date()); } Concept lmp = Dictionary.getConcept(Dictionary.LAST_MONTHLY_PERIOD); Calendar tenWeeksAgo = Calendar.getInstance(); tenWeeksAgo.add(Calendar.DATE, -70); Calendar twentyWeeksAgo = Calendar.getInstance(); twentyWeeksAgo.add(Calendar.DATE, -210); Obs[] encounterObss6 = {TestUtils.saveObs(patientService.getPatient(6), lmp, tenWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(patientService.getPatient(6), enrollmentEncounterType, enrollmentForm, new Date(), encounterObss6); Obs[] encounterObss7 = {TestUtils.saveObs(patientService.getPatient(7), lmp, twentyWeeksAgo.getTime(), new Date())}; TestUtils.saveEncounter(patientService.getPatient(7), enrollmentEncounterType, enrollmentForm, new Date(), encounterObss7); Context.flushSession(); List<Integer> ptIds = Arrays.asList(6, 7, 2, 999); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(ptIds, new LateEnrollmentCalculation()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }