/** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
  @Test
  @Verifies(
      value = "should return a Date with current date, but time of 00:00:00:00, for 'today'",
      method = "translateDatetimeParam(String,String)")
  public void translateDatetimeParam_shouldReturnDateForToday() throws Exception {

    Date testDate = HtmlFormEntryUtil.translateDatetimeParam("today", null);
    Assert.assertTrue(
        HtmlFormEntryUtil.translateDatetimeParam("today", null) instanceof java.util.Date);

    java.util.Calendar referenceCalendar = Calendar.getInstance();
    referenceCalendar.setTime(new java.util.Date());
    java.util.Calendar testCal = Calendar.getInstance();
    testCal.setTime(testDate);
    // date matches today?
    Assert.assertEquals(
        referenceCalendar.get(java.util.Calendar.YEAR), testCal.get(java.util.Calendar.YEAR));
    Assert.assertEquals(
        referenceCalendar.get(java.util.Calendar.DAY_OF_YEAR),
        testCal.get(java.util.Calendar.DAY_OF_YEAR));

    // check the time fields are zeroed out
    Assert.assertEquals(0, testCal.get(java.util.Calendar.HOUR));
    Assert.assertEquals(0, testCal.get(java.util.Calendar.MINUTE));
    Assert.assertEquals(0, testCal.get(java.util.Calendar.SECOND));
  }
  @Test
  @Verifies(
      value = "should return program enrollment after specified date",
      method = "getClosestFutureProgramEnrollment(Patient,Program,Date)")
  public void shouldReturnPatientProgramWithEnrollmentAfterSpecifiedDate() throws Exception {
    // load this data set so that we get the additional patient program created in this data case
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));

    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(2);
    Program program = pws.getProgram(1);

    Calendar cal = Calendar.getInstance();
    cal.set(2001, 6, 31);
    Date date = cal.getTime();

    PatientProgram pp = HtmlFormEntryUtil.getClosestFutureProgramEnrollment(patient, program, date);
    Assert.assertEquals("32296060-03aa-102d-b0e3-001ec94a0cc5", pp.getUuid());

    // now, if we roll the date back a year earlier, it should get the earlier of the two programs
    // for this patient
    cal.set(2000, 6, 31);
    date = cal.getTime();

    pp = HtmlFormEntryUtil.getClosestFutureProgramEnrollment(patient, program, date);
    Assert.assertEquals("32596060-03aa-102d-b0e3-001ec94a0cc5", pp.getUuid());
  }
 @Test
 @Verifies(value = "shoud return true valid uuid format", method = "isValidUuidFormat(String)")
 public void isValidUuidFormat_shouldReturnTrueIfNotValidUuidFormat() throws Exception {
   Assert.assertTrue(
       HtmlFormEntryUtil.isValidUuidFormat(
           "1000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); // 36 characters
   Assert.assertTrue(
       HtmlFormEntryUtil.isValidUuidFormat(
           "1000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); // 38 characters
 }
 /** @see FormSubmissionControllerAction#handleSubmission(FormEntrySession, HttpServletRequest) */
 @Override
 public void handleSubmission(FormEntrySession session, HttpServletRequest submission) {
   if (dateWidget != null) {
     Date date = (Date) dateWidget.getValue(session.getContext(), submission);
     if (session.getSubmissionActions().getCurrentEncounter().getEncounterDatetime() != null
         && !session
             .getSubmissionActions()
             .getCurrentEncounter()
             .getEncounterDatetime()
             .equals(date)) {
       session
           .getContext()
           .setPreviousEncounterDate(
               new Date(
                   session
                       .getSubmissionActions()
                       .getCurrentEncounter()
                       .getEncounterDatetime()
                       .getTime()));
     }
     session.getSubmissionActions().getCurrentEncounter().setEncounterDatetime(date);
   }
   if (timeWidget != null) {
     Date time = (Date) timeWidget.getValue(session.getContext(), submission);
     Encounter e = session.getSubmissionActions().getCurrentEncounter();
     Date dateAndTime = HtmlFormEntryUtil.combineDateAndTime(e.getEncounterDatetime(), time);
     e.setEncounterDatetime(dateAndTime);
   }
   if (providerWidget != null) {
     Object value = providerWidget.getValue(session.getContext(), submission);
     Person person = (Person) convertValueToProvider(value);
     session.getSubmissionActions().getCurrentEncounter().setProvider(person);
   }
   if (locationWidget != null) {
     Object value = locationWidget.getValue(session.getContext(), submission);
     Location location =
         (Location) HtmlFormEntryUtil.convertToType(value.toString().trim(), Location.class);
     session.getSubmissionActions().getCurrentEncounter().setLocation(location);
   }
   if (encounterTypeWidget != null) {
     EncounterType encounterType =
         (EncounterType) encounterTypeWidget.getValue(session.getContext(), submission);
     session.getSubmissionActions().getCurrentEncounter().setEncounterType(encounterType);
   }
   if (voidWidget != null) {
     if ("true".equals(voidWidget.getValue(session.getContext(), submission))) {
       session.setVoidEncounter(true);
     } else if ("false".equals(voidWidget.getValue(session.getContext(), submission))) {
       // nothing..  the session.voidEncounter property will be false, and the encounter will be
       // un-voided if already voided
       // otherwise, nothing will happen.  99% of the time the encounter won't be voided to begin
       // with.
     }
   }
 }
 @Test
 @Verifies(
     value = "shoud return false if not valid uuid format",
     method = "isValidUuidFormat(String)")
 public void isValidUuidFormat_shouldReturnFalseIfNotValidUuidFormat() throws Exception {
   Assert.assertFalse(HtmlFormEntryUtil.isValidUuidFormat("afasdfasd")); // less than 36 characters
   Assert.assertFalse(
       HtmlFormEntryUtil.isValidUuidFormat(
           "012345678901234567890123456789012345678")); // more than 38 characters
   Assert.assertFalse(
       HtmlFormEntryUtil.isValidUuidFormat(
           "1000AAAAAA AAAAAAAAA AAAAAAAAAA AAAA")); // includes whitespace
 }
  /** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
  @Test
  @Verifies(
      value = "should  return a Date object with current date and time for 'now'",
      method = "translateDatetimeParam(String,String)")
  public void translateDatetimeParam_shouldReturnDateForNow() throws Exception {
    Date referenceDate = new Date();
    Date testDate = HtmlFormEntryUtil.translateDatetimeParam("now", null);

    Assert.assertNotNull(testDate);
    Assert.assertTrue(
        HtmlFormEntryUtil.translateDatetimeParam("now", null) instanceof java.util.Date);
    // some millis elapsed between Date() calls - allow it a 1000 ms buffer
    Assert.assertEquals(referenceDate.getTime() / 1000, testDate.getTime() / 1000);
  }
  @Test
  @Verifies(
      value = "should return encounter with all child objects voided according to schema",
      method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterVoided() throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));

    // add a bunch of obs...
    TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); // matches

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);

    // this is going to test out the voided state of the obs in the encounter after processing:
    Assert.assertTrue(e.isVoided());
  }
 /**
  * @see {@link HtmlFormEntryUtil#getConcept(String)} tests a uuid that is in invalid format (less
  *     than 36 characters)
  */
 @Test
 @Verifies(value = "should not find a concept with invalid uuid", method = "getConcept(String)")
 public void getConcept_shouldNotFindAConceptWithInvalidUuid() throws Exception {
   // concept from HtmlFormEntryTest-data.xml
   String id = "1000";
   Assert.assertNull(HtmlFormEntryUtil.getConcept(id));
 }
 /**
  * @see {@link HtmlFormEntryUtil#getConcept(String)} tests a uuid that is 36 characters long but
  *     has no dashes
  */
 @Test
 @Verifies(value = "should find a concept by its uuid", method = "getConcept(String)")
 public void getConcept_shouldFindAConceptWithNonStandardUuid() throws Exception {
   // concept from HtmlFormEntryTest-data.xml
   String id = "1000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
   Assert.assertEquals(id, HtmlFormEntryUtil.getConcept(id).getUuid());
 }
 /** @see {@link HtmlFormEntryUtil#getConcept(String)} this is the uuid test */
 @Test
 @Verifies(value = "should find a concept by its uuid", method = "getConcept(String)")
 public void getConcept_shouldFindAConceptByItsUuid() throws Exception {
   // the uuid from standardTestDataset
   String id = "0cbe2ed3-cd5f-4f46-9459-26127c9265ab";
   Assert.assertEquals(id, HtmlFormEntryUtil.getConcept(id).getUuid());
 }
 /** @see {@link HtmlFormEntryUtil#getPerson(String)} this is the uuid test */
 @Test
 @Verifies(value = "should find a person by uuid", method = "getPerson(String)")
 public void getPerson_shouldFindAPersonByUuid() throws Exception {
   Assert.assertEquals(
       "Hornblower",
       HtmlFormEntryUtil.getPerson("da7f524f-27ce-4bb2-86d6-6d1d05312bd5").getFamilyName());
 }
 /** @see {@link HtmlFormEntryUtil#getProgram(String)} this is the name test */
 @Test
 @Verifies(value = "should find a program by its name", method = "getProgram(String)")
 public void getProgram_shouldFindAProgramByItsName() throws Exception {
   Assert.assertEquals(
       "71779c39-d289-4dfe-91b5-e7cfaa27c78b",
       HtmlFormEntryUtil.getProgram("MDR-TB PROGRAM").getUuid());
 }
    /**
     *
     * Generate the header row for the csv file.
     *
     * @param form
     * @param extraCols
     * @return
     * @throws Exception
     */
    public static String generateColumnHeadersFromHtmlForm(HtmlForm form, List<String> extraCols, StringBuffer sb, List<PatientIdentifierType> pitList) throws Exception {
        FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), form, null); // session gets a null HttpSession
        session.getHtmlToDisplay();
        HtmlFormSchema hfs = session.getContext().getSchema();

        sb.append(DEFAULT_QUOTE).append("ENCOUNTER_ID").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR)
        .append(DEFAULT_QUOTE).append("ENCOUNTER_DATE").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR)
        .append(DEFAULT_QUOTE).append("ENCOUNTER_LOCATION").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR)
        .append(DEFAULT_QUOTE).append("ENCOUNTER_PROVIDER").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR)
        .append(DEFAULT_QUOTE).append("INTERNAL_PATIENT_ID").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR);
        int index = 1;
        for (PatientIdentifierType pit :  pitList){
            sb.append(DEFAULT_QUOTE).append(pit.getName()).append(DEFAULT_QUOTE);
            if (index < pitList.size())
                sb.append(DEFAULT_COLUMN_SEPARATOR);
            index ++;
        }

        Set<HtmlFormField> fields = hfs.getAllFields();

        for (HtmlFormField hfsec : fields) {
            sb = generateColumnHeadersFromHtmlFormHelper(hfsec, extraCols, sb);
        }

        session = null;
        sb.append(DEFAULT_LINE_SEPARATOR);
        return sb.toString();
    }
 /**
  * Gets provider id and obtains the Provider from it
  *
  * @param value - provider id
  * @return the Provider object of corresponding id
  */
 private Object convertValueToProvider(Object value) {
   String val = (String) value;
   if (StringUtils.hasText(val)) {
     return HtmlFormEntryUtil.convertToType(val.trim(), Person.class);
   }
   return null;
 }
 /** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
 @Test
 @Verifies(
     value = "should return null if format is null and value not in [ null, 'now', 'today' ]",
     method = "translateDatetimeParam(String,String)")
 public void translateDatetimeParam_shouldReturnNullForNullFormat() throws Exception {
   Assert.assertNull(HtmlFormEntryUtil.translateDatetimeParam("1990-01-02-13-59", null));
 }
 /** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
 @Test
 @Verifies(
     value = "should return null for null value",
     method = "translateDatetimeParam(String,String)")
 public void translateDatetimeParam_shouldReturnNullForNullValue() throws Exception {
   Assert.assertNull(HtmlFormEntryUtil.translateDatetimeParam(null, "yyyy-MM-dd-HH-mm"));
 }
 /** @see {@link HtmlFormEntryUtil#getConcept(String)} mapping test */
 @Test
 @Verifies(value = "should find a concept by its mapping", method = "getConcept(String)")
 public void getConcept_shouldFindAConceptByItsMapping() throws Exception {
   String id = "XYZ:HT";
   Concept cpt = HtmlFormEntryUtil.getConcept(id);
   Assert.assertEquals("XYZ", cpt.getConceptMappings().iterator().next().getSource().getName());
   Assert.assertEquals("HT", cpt.getConceptMappings().iterator().next().getSourceCode());
 }
 /** @see {@link HtmlFormEntryUtil#getState(String,Program)} */
 @Test
 @Verifies(
     value = "should return the workflow with the matching id",
     method = "getWorkflow(String)")
 public void getWorkflow_shouldReturnTheWorkflowWithTheMatchingId() throws Exception {
   Assert.assertEquals(
       "84f0effa-dd73-46cb-b931-7cd6be6c5f81", HtmlFormEntryUtil.getWorkflow("1").getUuid());
 }
 /** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
 @Test(expected = java.lang.IllegalArgumentException.class)
 @Verifies(
     value = "should fail if date parsing fails",
     method = "translateDatetimeParam(String,String)")
 public void translateDatetimeParam_shouldFailForBadDateFormat() throws Exception {
   HtmlFormEntryUtil.translateDatetimeParam(
       "1990-01-02-13-59", "a bogus date format that will throw an error");
 }
 /** @see {@link HtmlFormEntryUtil#getPatientIdentifierType(String)} id test */
 @Test
 @Verifies(
     value = "should find a patient identifier type by its Id",
     method = "getPatientIdentifierType(String)")
 public void getPatientIdentifierType_shouldFindAPatientIdentifierTypeByItsId() throws Exception {
   Assert.assertEquals(
       "OpenMRS Identification Number", HtmlFormEntryUtil.getPatientIdentifierType("1").getName());
 }
  /** @see {@link HtmlFormEntryUtil#getLocation(String)} */
  @Test
  @Verifies(value = "should return null otherwise", method = "getLocation(String)")
  public void getLocation_shouldReturnNullOtherwise() throws Exception {
    String id = null;
    Assert.assertNull(HtmlFormEntryUtil.getLocation(id));

    id = "";
    Assert.assertNull(HtmlFormEntryUtil.getLocation(id));

    id = "100000"; // not exist in the standardTestData
    Assert.assertNull(HtmlFormEntryUtil.getLocation(id));

    id = "ASDFASDFEAF"; // random string
    Assert.assertNull(HtmlFormEntryUtil.getLocation(id));

    id = "-"; // uuid style
    Assert.assertNull(HtmlFormEntryUtil.getLocation(id));
  }
 /** @see {@link HtmlFormEntryUtil#isEnrolledInProgram(Patient,Program,Date)} */
 @Test
 @Verifies(
     value = "should return false if the patient is not enrolled in the program",
     method = "isEnrolledInProgram(Patient,Program,Date)")
 public void isEnrolledInProgram_shouldReturnFalseIfThePatientIsNotEnrolledInTheProgram()
     throws Exception {
   Patient patient = Context.getPatientService().getPatient(6);
   Program program = Context.getProgramWorkflowService().getProgram(1);
   Assert.assertFalse(HtmlFormEntryUtil.isEnrolledInProgramOnDate(patient, program, new Date()));
 }
 /** @see {@link HtmlFormEntryUtil#getState(String,Program)} */
 @Test
 @Verifies(
     value = "should return the state with the matching id",
     method = "getState(String,Program)")
 public void getStateProgram_shouldReturnTheStateWithTheMatchingId() throws Exception {
   Assert.assertEquals(
       "92584cdc-6a20-4c84-a659-e035e45d36b0",
       HtmlFormEntryUtil.getState("1", Context.getProgramWorkflowService().getProgram(1))
           .getUuid());
 }
 /** @see {@link HtmlFormEntryUtil#getPatientIdentifierType(String)} this is the name test */
 @Test
 @Verifies(
     value = "should find a program by its name",
     method = "getPatientIdentifierType(String)")
 public void getPatientIdentifierType_shouldFindAPatientIdentifierTypeByItsName()
     throws Exception {
   Assert.assertEquals(
       "1a339fe9-38bc-4ab3-b180-320988c0b968",
       HtmlFormEntryUtil.getPatientIdentifierType("OpenMRS Identification Number").getUuid());
 }
  @Test
  @Verifies(
      value = "should return encounter with all child objects voided according to schema",
      method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderCorrectly() throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 1, 5000, date); // a matching obs

    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setStartDate(new Date());
    e.addOrder(dor);

    Context.getEncounterService().saveEncounter(e);

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));

    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, "test void reason");

    // this is going to test out the voided state of the obs in the encounter after processing:
    // order was matched, so order was voided, and because that's the only thing in the encounter,
    // encounter was voided too.
    Assert.assertTrue(e.isVoided());
    Assert.assertTrue(e.getVoidReason().equals("test void reason"));
    for (Order o : e.getOrders()) {
      Assert.assertTrue(o.isVoided());
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
    for (Obs o : e.getAllObs(true)) {
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
  }
  @Test
  @Verifies(value = "should delete encounter correctly", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldDeleteEncounter() throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 3, 5000, date); // adding an un-matched, voided Obs
    for (Obs o : e.getAllObs(true)) {
      o.setVoided(true);
      o.setVoidedBy(Context.getUserService().getUser(1));
      o.setVoidReason("blah");
      o.setDateVoided(new Date());
    }

    // and adding a voided drug order
    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setVoided(true);
    dor.setVoidedBy(Context.getUserService().getUser(1));
    dor.setVoidReason("blah");
    dor.setDateVoided(new Date());
    dor.setStartDate(new Date());
    e.addOrder(dor);

    Context.getEncounterService().saveEncounter(e);

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));

    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);

    // encounter had no non-voided objects, should be voided
    Assert.assertTrue(e.isVoided());
  }
 /** @see {@link HtmlFormEntryUtil#isEnrolledInProgram(Patient,Program,Date)} */
 @Test
 @Verifies(
     value = "should return true if the patient is enrolled in the program at the specified date",
     method = "isEnrolledInProgram(Patient,Program,Date)")
 public void
     isEnrolledInProgram_shouldReturnTrueIfThePatientIsEnrolledInTheProgramAtTheSpecifiedDate()
         throws Exception {
   Patient patient = Context.getPatientService().getPatient(2);
   Program program = Context.getProgramWorkflowService().getProgram(1);
   Assert.assertTrue(HtmlFormEntryUtil.isEnrolledInProgramOnDate(patient, program, new Date()));
 }
 /** @see {@link HtmlFormEntryUtil#translateDatetimeParam(String,String)} */
 @Test(expected = java.lang.IllegalArgumentException.class)
 @Verifies(
     value = "should return null if format is null and value not in [ null, 'now', 'today' ]",
     method = "translateDatetimeParam(String,String)")
 public void translateDatetimeParam_shouldReturnNullForInvalidDate() throws Exception {
   // java.text.SimpleDateFormat parses invalid numerical dates without
   // error, e.g. 9999-99-99-99-99-99 is parsed to Mon Jun 11 04:40:39 EDT
   // 10007
   // Text strings are unparseable, however.
   HtmlFormEntryUtil.translateDatetimeParam("c'est ne pas une date", "yyyy-MM-dd-HH-mm");
 }
  @Test
  @Verifies(
      value = "should return encounter with all child objects voided according to schema",
      method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderAndObsCorrectly()
      throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 3, 5000, date); // adding an un-matched Obs

    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setStartDate(new Date());
    e.addOrder(dor);

    Context.getEncounterService().saveEncounter(e);

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));

    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);

    // order was matched, obs was not, so order should be voided, obs not, encounter not.
    Assert.assertTrue(!e.isVoided());
    for (Order o : e.getOrders()) {
      Assert.assertTrue(o.isVoided());
    }
    for (Obs o : e.getObs()) {
      Assert.assertTrue(!o.isVoided());
    }
  }
 @Test
 @Verifies(
     value = "should return null if no program enrollment after specified date",
     method = "getClosestFutureProgramEnrollment(Patient,Program,Date)")
 public void
     getClosestFutureProgramEnrollment_shouldReturnNullIfNoProgramEnrollmentAfterSpecifiedDate()
         throws Exception {
   ProgramWorkflowService pws = Context.getProgramWorkflowService();
   Patient patient = Context.getPatientService().getPatient(2);
   Program program = pws.getProgram(1);
   Assert.assertNull(
       HtmlFormEntryUtil.getClosestFutureProgramEnrollment(patient, program, new Date()));
 }