@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()));
  }
  @RequestMapping(method = RequestMethod.POST)
  public void savePatientInfo(
      @RequestParam("patientId") Integer patientId,
      @RequestParam(value = "encounterId", required = false) Integer encounterId,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ParseException, IOException {

    Map<String, String> parameters = RegistrationWebUtils.optimizeParameters(request);

    // get patient
    Patient patient = Context.getPatientService().getPatient(patientId);

    /*
     * SAVE ENCOUNTER
     */
    Encounter encounter = null;
    if (encounterId != null) {
      encounter = Context.getEncounterService().getEncounter(encounterId);
    } else {
      encounter = RegistrationWebUtils.createEncounter(patient, true);

      // create OPD obs
      Concept opdWardConcept =
          Context.getConceptService().getConcept(RegistrationConstants.CONCEPT_NAME_OPD_WARD);
      Concept selectedOPDConcept =
          Context.getConceptService()
              .getConcept(
                  Integer.parseInt(
                      parameters.get(RegistrationConstants.FORM_FIELD_PATIENT_OPD_WARD)));
      Obs opd = new Obs();
      opd.setConcept(opdWardConcept);
      opd.setValueCoded(selectedOPDConcept);
      encounter.addObs(opd);

      // send patient to opd room/bloodbank

      // harsh 5/10/2012 changed the way to get blood bank concept->shifted hardcoded dependency
      // from id to name
      //			Concept bloodbankConcept = Context.getConceptService().getConcept(
      //			    GlobalPropertyUtil.getInteger(RegistrationConstants.PROPERTY_BLOODBANK_CONCEPT_ID,
      // 6425));
      String bloodBankWardName =
          GlobalPropertyUtil.getString(
              RegistrationConstants.PROPERTY_BLOODBANK_OPDWARD_NAME, "Blood Bank Room");

      // ghanshyam 03-sept-2013 Bug #394 [Blood bank]queue
      String socn = new String(selectedOPDConcept.getName().toString());
      String substringofsocn = socn.substring(0, 15);

      if (!substringofsocn.equalsIgnoreCase(bloodBankWardName)) {
        RegistrationWebUtils.sendPatientToOPDQueue(patient, selectedOPDConcept, true);
      } else {
        OrderType orderType = null;
        String orderTypeName =
            Context.getAdministrationService().getGlobalProperty("bloodbank.orderTypeName");
        orderType = OrderUtil.getOrderTypeByName(orderTypeName);

        Order order = new Order();
        order.setConcept(selectedOPDConcept);
        order.setCreator(Context.getAuthenticatedUser());
        order.setDateCreated(new Date());
        order.setOrderer(Context.getAuthenticatedUser());
        order.setPatient(patient);
        order.setStartDate(new Date());
        order.setAccessionNumber("0");
        order.setOrderType(orderType);
        order.setEncounter(encounter);
        encounter.addOrder(order);
      }
    }

    // create temporary attributes
    for (String name : parameters.keySet()) {
      if ((name.contains(".attribute.")) && (!StringUtils.isBlank(parameters.get(name)))) {
        String[] parts = name.split("\\.");
        String idText = parts[parts.length - 1];
        Integer id = Integer.parseInt(idText);
        Concept tempCatConcept = Context.getConceptService().getConceptByName("TEMPORARY CATEGORY");

        Concept temporaryAttributeConcept =
            Context.getConceptService().getConcept(tempCatConcept.getConceptId());
        Obs temporaryAttribute = new Obs();
        temporaryAttribute.setConcept(temporaryAttributeConcept);
        logger.info("concept: " + temporaryAttributeConcept);
        logger.info("value: " + parameters.get(name));
        temporaryAttribute.setValueAsString(parameters.get(name));
        encounter.addObs(temporaryAttribute);
      }
    }

    // save encounter
    Context.getEncounterService().saveEncounter(encounter);
    logger.info(
        String.format(
            "Save encounter for the visit of patient [encounterId=%s, patientId=%s]",
            encounter.getId(), patient.getId()));

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.print("success");
  }