/** @see {@link DrugOrderValidator#validate(Object,Errors)} */
  @Test
  @Verifies(
      value = "should pass validation if all fields are correct",
      method = "validate(Object,Errors)")
  public void validate_shouldPassValidationIfAllFieldsAreCorrect() throws Exception {
    DrugOrder order = new DrugOrder();
    Encounter encounter = new Encounter();
    Patient patient = Context.getPatientService().getPatient(2);
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDosingType(DrugOrder.DosingType.FREE_TEXT);
    order.setInstructions("Instructions");
    order.setDosingInstructions("Test Instruction");
    order.setPatient(patient);
    encounter.setPatient(patient);
    order.setEncounter(encounter);
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
    order.setStartDate(cal.getTime());
    order.setAutoExpireDate(new Date());
    order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order"));
    order.setDrug(Context.getConceptService().getDrug(3));
    order.setCareSetting(Context.getOrderService().getCareSetting(1));
    order.setQuantity(2.00);
    order.setQuantityUnits(Context.getConceptService().getConcept(51));
    order.setNumRefills(10);

    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasErrors());
  }
 /**
  * @verifies fail validation if quantityUnits is null when quantity is present
  * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
  */
 @Test
 public void validate_shouldFailValidationIfQuantityUnitsIsNullWhenQuantityIsPresent()
     throws Exception {
   DrugOrder order = new DrugOrder();
   order.setDosingType(DrugOrder.DosingType.FREE_TEXT);
   order.setQuantity(20.0);
   order.setQuantityUnits(null);
   Errors errors = new BindException(order, "order");
   new DrugOrderValidator().validate(order, errors);
   Assert.assertTrue(errors.hasFieldErrors("quantityUnits"));
 }
  /**
   * @see DrugOrderValidator#validate(Object,Errors)
   * @verifies fail validation if doseUnits is not a dose unit concept
   */
  @Test
  public void validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept() throws Exception {
    Concept concept = Context.getConceptService().getConcept(3);
    assertThat(concept, not(isIn(Context.getOrderService().getDrugDosingUnits())));

    DrugOrder order = new DrugOrder();
    order.setDosingType(DrugOrder.DosingType.FREE_TEXT);
    order.setDuration(5.0);
    order.setDurationUnits(concept);
    order.setDose(1.0);
    order.setDoseUnits(concept);
    order.setQuantity(30.0);
    order.setQuantityUnits(concept);

    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
  }
  /**
   * @verifies fail if route is not a valid concept
   * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
   */
  @Test
  public void validate_shouldFailIfRouteIsNotAValidConcept() throws Exception {
    Concept concept = Context.getConceptService().getConcept(3);
    assertThat(concept, not(isIn(Context.getOrderService().getDrugRoutes())));

    DrugOrder order = new DrugOrder();
    order.setDosingType(DrugOrder.DosingType.FREE_TEXT);
    order.setDuration(5.0);
    order.setDurationUnits(concept);
    order.setDose(1.0);
    order.setDoseUnits(concept);
    order.setQuantity(30.0);
    order.setQuantityUnits(concept);
    order.setRoute(concept);

    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("route"));
    Assert.assertEquals(
        "DrugOrder.error.routeNotAmongAllowedConcepts", errors.getFieldError("route").getCode());
  }