@Test public void evaluate_shouldReturnHivPatientsNotScreenedForTb() throws Exception { // Get HIV Program and TB screening encounter type Program hivProgram = MetadataUtils.getProgram(Metadata.HIV_PROGRAM); EncounterType screeningEncType = MetadataUtils.getEncounterType(Metadata.TB_SCREENING_ENCOUNTER_TYPE); // Enroll patients #6 and #7 PatientService ps = Context.getPatientService(); TestUtils.enrollInProgram(ps.getPatient(6), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(ps.getPatient(7), hivProgram, TestUtils.date(2011, 1, 1)); // Screen patient #6 for TB a year later TestUtils.saveEncounter(ps.getPatient(6), screeningEncType, TestUtils.date(2012, 1, 1)); Context.flushSession(); List<Integer> cohort = Arrays.asList(6, 7, 8); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class) .evaluate(cohort, new NeverScreenedForTbCalculation()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertNull(resultMap.get(8)); // not in HIV program }
/** * @see * org.openmrs.module.kenyaemr.calculation.library.hiv.MissedAppointmentsOrDefaultedCalculation#evaluate(java.util.Collection, * java.util.Map, org.openmrs.calculation.patient.PatientCalculationContext) * @verifies determine whether patients have a Missed appointments or defaulted */ @Test public void evaluate_shouldDetermineWhetherPatientsWhoMissedAppointmentsOrDefaulted() throws Exception { // Get HIV Program Program hivProgram = MetadataUtils.getProgram(Metadata.HIV_PROGRAM); // Enroll patients #6, #7, #8 in the HIV Program PatientService ps = Context.getPatientService(); for (int i = 6; i <= 8; ++i) { TestUtils.enrollInProgram(ps.getPatient(i), hivProgram, TestUtils.date(2011, 1, 1)); } // Give patient #7 a return visit obs of 10 days ago Concept returnVisit = Context.getConceptService().getConcept(5096); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -10); TestUtils.saveObs( Context.getPatientService().getPatient(7), returnVisit, calendar.getTime(), calendar.getTime()); // Give patient #8 a return visit obs of 10 days in the future calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 10); TestUtils.saveObs( Context.getPatientService().getPatient(8), returnVisit, calendar.getTime(), calendar.getTime()); Context.flushSession(); List<Integer> ptIds = Arrays.asList(6, 7, 8, 9); CalculationResultMap resultMap = new MissedAppointmentsOrDefaultedCalculation() .evaluate( ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse( (Boolean) resultMap.get(6).getValue()); // patient in HIV program but no return visit obs Assert.assertTrue((Boolean) resultMap.get(7).getValue()); // patient has missed visit Assert.assertFalse( (Boolean) resultMap.get(8).getValue()); // patient has future return visit date Assert.assertFalse((Boolean) resultMap.get(9).getValue()); // patient not in HIV Program }