private Encounter buildEncounter(
     EncounterType encounterType,
     Patient patient,
     Location location,
     Form form,
     Date when,
     List<Obs> obsToCreate,
     List<Order> ordersToCreate) {
   Encounter encounter = new Encounter();
   encounter.setPatient(patient);
   encounter.setEncounterType(encounterType);
   encounter.setLocation(location);
   encounter.setForm(form);
   encounter.setEncounterDatetime(when);
   if (obsToCreate != null) {
     for (Obs obs : obsToCreate) {
       obs.setObsDatetime(new Date());
       encounter.addObs(obs);
     }
   }
   if (ordersToCreate != null) {
     for (Order order : ordersToCreate) {
       encounter.addOrder(order);
     }
   }
   return encounter;
 }
  /** @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));
  }