/**
  * @verifies fail validation if doseUnits is null for SIMPLE dosingType
  * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
  */
 @Test
 public void validate_shouldFailValidationIfDoseUnitsIsNullForSIMPLEDosingType() throws Exception {
   DrugOrder order = new DrugOrder();
   order.setDosingType(DrugOrder.DosingType.SIMPLE);
   order.setDoseUnits(null);
   Errors errors = new BindException(order, "order");
   new DrugOrderValidator().validate(order, errors);
   Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
 }
 /**
  * @verifies fail validation if doseUnits is null when dose is present
  * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
  */
 @Test
 public void validate_shouldFailValidationIfDoseUnitsIsNullWhenDoseIsPresent() throws Exception {
   DrugOrder order = new DrugOrder();
   order.setDosingType(DrugOrder.DosingType.FREE_TEXT);
   order.setDose(20.0);
   order.setDoseUnits(null);
   Errors errors = new BindException(order, "order");
   new DrugOrderValidator().validate(order, errors);
   Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
 }
 private DrugOrder createValidDrugOrder() {
   DrugOrder drugOrder = new DrugOrder();
   drugOrder.setDose(10.0);
   drugOrder.setDoseUnits(createConceptWithName("ml"));
   drugOrder.setRoute(createConceptWithName("IV"));
   OrderFrequency frequency = new OrderFrequency();
   frequency.setConcept(createConceptWithName("Twice a day"));
   drugOrder.setFrequency(frequency);
   return drugOrder;
 }
  /**
   * @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());
  }