/** @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#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#isEnrolledInProgram(Patient,Program,Date)} */
  @Test
  @Verifies(
      value = "should return false if the program was completed",
      method = "isEnrolledInProgram(Patient,Program,Date)")
  public void isEnrolledInProgram_shouldReturnFalseIfTheProgramWasCompleted() throws Exception {
    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(2);

    // for test purposes, lets set a program as complete
    PatientProgram pp = pws.getPatientProgram(1);
    Assert.assertSame(patient, pp.getPatient());
    pp.setDateCompleted(new Date());
    Thread.sleep(100);
    pws.savePatientProgram(pp);

    Assert.assertFalse(
        HtmlFormEntryUtil.isEnrolledInProgramOnDate(patient, pws.getProgram(1), new Date()));
  }
  /** @see {@link HtmlFormEntryUtil#isEnrolledInProgram(Patient,Program,Date)} */
  @Test
  @Verifies(
      value =
          "should return false if the date is before the existing patient program enrollment date",
      method = "isEnrolledInProgram(Patient,Program,Date)")
  public void
      isEnrolledInProgram_shouldReturnFalseIfTheDateIsBeforeTheExistingPatientProgramEnrollmentDateIgnoringTimeFields()
          throws Exception { // 2008-08-01 00:00:00.0
    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(2);
    Program program = pws.getProgram(1);
    PatientProgram pp = pws.getPatientProgram(1);

    Calendar cal = Calendar.getInstance();
    cal.set(2008, 6, 31);
    Date newEnrollmentDate = cal.getTime();
    Assert.assertTrue(newEnrollmentDate.before(pp.getDateEnrolled())); // sanity check
    Assert.assertFalse(
        HtmlFormEntryUtil.isEnrolledInProgramOnDate(patient, program, newEnrollmentDate));
  }