/** Setup each test */
  @Before
  public void setup() throws Exception {
    commonMetadata.install();

    VisitType outpatient = MetadataUtils.getVisitType(CommonMetadata._VisitType.OUTPATIENT);

    // Patient #7 has two visits on 1-Jan-2012 (from 9am to 10am and another from 11am to 12pm)
    TestUtils.saveVisit(
        TestUtils.getPatient(7),
        outpatient,
        TestUtils.date(2012, 1, 1, 9, 0, 0),
        TestUtils.date(2012, 1, 1, 10, 0, 0));
    TestUtils.saveVisit(
        TestUtils.getPatient(7),
        outpatient,
        TestUtils.date(2012, 1, 1, 11, 0, 0),
        TestUtils.date(2012, 1, 1, 12, 0, 0));

    // Patient #8 has visit on 2-Jan-2012
    TestUtils.saveVisit(
        TestUtils.getPatient(8),
        outpatient,
        TestUtils.date(2012, 1, 2, 9, 0, 0),
        TestUtils.date(2012, 1, 2, 10, 0, 0));
  }
  /** @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));
  }