EmrVisitAssignmentHandler extends BaseEncounterVisitHandler implements ExistingEncounterVisitHandler { protected static VisitType getAutoCreateVisitType(Encounter encounter) { if (encounter.getForm() != null) { FormManager formManager = CoreContext.getInstance().getManager(FormManager.class); FormDescriptor fd = formManager.getFormDescriptor(encounter.getForm()); if (fd != null && fd.getAutoCreateVisitTypeUuid() != null) { return MetadataUtils.existing(VisitType.class, fd.getAutoCreateVisitTypeUuid()); } } return null; }  @Override String getDisplayName(Locale locale); @Override void beforeCreateEncounter(Encounter encounter); @Override void beforeEditEncounter(Encounter encounter);  }
@Test public void getAutoCreateVisitType_shouldReturnAutoCreateVisitTypeIfSpecified() { VisitType outpatient = MetadataUtils.existing(VisitType.class, CommonMetadata._VisitType.OUTPATIENT); Encounter hivAddendum = new Encounter(); hivAddendum.setForm(MetadataUtils.existing(Form.class, HivMetadata._Form.CLINICAL_ENCOUNTER_HIV_ADDENDUM)); Assert.assertThat(EmrVisitAssignmentHandler.getAutoCreateVisitType(hivAddendum), is(nullValue())); Encounter moh257 = new Encounter(); moh257.setForm(MetadataUtils.existing(Form.class, HivMetadata._Form.MOH_257_VISIT_SUMMARY)); Assert.assertThat(EmrVisitAssignmentHandler.getAutoCreateVisitType(moh257), is(outpatient)); }