@Test
  public void testEvaluate() throws Exception {
    EncounterEvaluationContext context = new EncounterEvaluationContext();
    context.setBaseEncounters(new EncounterIdSet(encounter.getId()));

    EvaluatedEncounterData result =
        encounterDataService.evaluate(new AuditInfoEncounterDataDefinition(), context);
    assertThat(result.getData().size(), is(1));
    AuditInfo auditInfo = (AuditInfo) result.getData().get(encounter.getId());
    assertThat(auditInfo.getCreator(), is(encounter.getCreator()));
    assertThat(auditInfo.getDateCreated(), is(encounter.getDateCreated()));
    assertThat(auditInfo.getChangedBy(), is(encounter.getChangedBy()));
    assertThat(auditInfo.getDateChanged(), is(encounter.getDateChanged()));
    assertThat(auditInfo.getVoided(), is(encounter.getVoided()));
    assertThat(auditInfo.getVoidedBy(), is(encounter.getVoidedBy()));
    assertThat(auditInfo.getDateVoided(), is(encounter.getDateVoided()));
    assertThat(auditInfo.getVoidReason(), is(encounter.getVoidReason()));
  }
  /**
   * @see org.openmrs.api.EncounterService#voidEncounter(org.openmrs.Encounter, java.lang.String)
   */
  public Encounter voidEncounter(Encounter encounter, String reason) {

    // if authenticated user is not supposed to edit encounter of certain type
    if (!canEditEncounter(encounter, null)) {
      throw new APIException(
          String.format(
              "Privilege %s required to void encounters of this type",
              encounter.getEncounterType().getEditPrivilege()));
    }

    if (reason == null) {
      throw new IllegalArgumentException("The argument 'reason' is required and so cannot be null");
    }

    ObsService os = Context.getObsService();
    for (Obs o : encounter.getObsAtTopLevel(false)) {
      if (!o.isVoided()) {
        os.voidObs(o, reason);
      }
    }

    OrderService orderService = Context.getOrderService();
    for (Order o : encounter.getOrders()) {
      if (!o.isVoided()) {
        orderService.voidOrder(o, reason);
      }
    }

    encounter.setVoided(true);
    encounter.setVoidedBy(Context.getAuthenticatedUser());
    // we expect the dateVoided to be already set by AOP logic at this point unless this method was
    // called within the API,
    // this ensures that original ParentVoidedDate and the dateVoided of associated objects will
    // always match for the
    // unvoid handler to work
    if (encounter.getDateVoided() == null) {
      encounter.setDateVoided(new Date());
    }
    encounter.setVoidReason(reason);
    Context.getEncounterService().saveEncounter(encounter);
    return encounter;
  }