public void controller( @FragmentParam("patient") Patient patient, FragmentModel model, UiUtils ui, @SpringBean CoreContext emr) { String[] page1FormUuids = {Metadata.FAMILY_HISTORY_FORM, Metadata.HIV_PROGRAM_ENROLLMENT_FORM}; List<SimpleObject> page1AvailableForms = new ArrayList<SimpleObject>(); List<Encounter> page1Encounters = new ArrayList<Encounter>(); for (String page1FormUuid : page1FormUuids) { Form page1Form = MetadataUtils.getForm(page1FormUuid); List<Encounter> formEncounters = getPatientEncounterByForm(patient, page1Form); if (formEncounters.size() == 0) { page1AvailableForms.add(ui.simplifyObject(page1Form)); } else { page1Encounters.addAll(formEncounters); } } Form moh257VisitForm = MetadataUtils.getForm(Metadata.MOH_257_VISIT_SUMMARY_FORM); List<Encounter> moh257VisitSummaryEncounters = getPatientEncounterByForm(patient, moh257VisitForm); model.addAttribute("page1AvailableForms", page1AvailableForms); model.addAttribute("page1Encounters", page1Encounters); model.addAttribute("page2Form", moh257VisitForm); model.addAttribute("page2Encounters", moh257VisitSummaryEncounters); Concept masterSet = emr.getRegimenManager().getMasterSetConcept("ARV"); RegimenChangeHistory arvHistory = RegimenChangeHistory.forPatient(patient, masterSet); model.addAttribute("arvHistory", arvHistory); }
/** @see EmrVisitAssignmentHandler#getAutoCreateVisitType(org.openmrs.Encounter) */ @Test public void getAutoCreateVisitType_shouldReturnAutoCreateVisitTypeIfSpecified() { VisitType outpatient = MetadataUtils.getVisitType(CommonMetadata._VisitType.OUTPATIENT); // Check form that doesn't specify one Encounter hivAddendum = new Encounter(); hivAddendum.setForm(MetadataUtils.getForm(HivMetadata._Form.CLINICAL_ENCOUNTER_HIV_ADDENDUM)); Assert.assertThat( EmrVisitAssignmentHandler.getAutoCreateVisitType(hivAddendum), is(nullValue())); // Check form that does specify one Encounter moh257 = new Encounter(); moh257.setForm(MetadataUtils.getForm(HivMetadata._Form.MOH_257_VISIT_SUMMARY)); Assert.assertThat(EmrVisitAssignmentHandler.getAutoCreateVisitType(moh257), is(outpatient)); }
/** @see EmrVisitAssignmentHandler#checkLocations(org.openmrs.Visit, org.openmrs.Encounter) */ @Test public void checkLocations() { Patient patient = TestUtils.getPatient(7); Form moh257 = MetadataUtils.getForm(HivMetadata._Form.MOH_257_VISIT_SUMMARY); VisitType outpatient = MetadataUtils.getVisitType(CommonMetadata._VisitType.OUTPATIENT); // Save regular visit on Jan 1st at no specific location Visit visit0 = TestUtils.saveVisit(patient, outpatient, TestUtils.date(2012, 1, 1), null); // Save regular visit on Jan 1st at location #2 Visit visit1 = TestUtils.saveVisit(patient, outpatient, TestUtils.date(2012, 1, 1), null); visit1.setLocation(Context.getLocationService().getLocation(1)); // Save regular visit on Jan 1st at location #2 Visit visit2 = TestUtils.saveVisit(patient, outpatient, TestUtils.date(2012, 1, 1), null); visit2.setLocation(Context.getLocationService().getLocation(2)); // Save MOH257 for that day (will default to location #1) Encounter encounter = TestUtils.saveEncounter(patient, moh257, TestUtils.date(2012, 1, 1)); Assert.assertThat(EmrVisitAssignmentHandler.checkLocations(visit0, encounter), is(true)); Assert.assertThat(EmrVisitAssignmentHandler.checkLocations(visit1, encounter), is(true)); Assert.assertThat(EmrVisitAssignmentHandler.checkLocations(visit2, encounter), is(false)); }