Search in sources :

Example 61 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfNumberOfRefillsIsNullForOutpatientCareSetting.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfNumberOfRefillsIsNullForOutpatientCareSetting() {
    DrugOrder OutpatientOrder = new DrugOrder();
    OutpatientOrder.setCareSetting(Context.getOrderService().getCareSetting(1));
    OutpatientOrder.setNumRefills(null);
    Errors OutpatientOrderErrors = new BindException(OutpatientOrder, "order");
    new DrugOrderValidator().validate(OutpatientOrder, OutpatientOrderErrors);
    Assert.assertTrue(OutpatientOrderErrors.hasFieldErrors("numRefills"));
    DrugOrder inPatientOrder = new DrugOrder();
    inPatientOrder.setCareSetting(Context.getOrderService().getCareSetting(2));
    inPatientOrder.setNumRefills(null);
    Errors InpatientOrderErrors = new BindException(inPatientOrder, "order");
    new DrugOrderValidator().validate(inPatientOrder, InpatientOrderErrors);
    Assert.assertFalse(InpatientOrderErrors.hasFieldErrors("numRefills"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 62 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldPassIfConceptIsNullAndDrugIsSet.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassIfConceptIsNullAndDrugIsSet() {
    DrugOrder order = new DrugOrder();
    order.setPatient(Context.getPatientService().getPatient(7));
    order.setCareSetting(Context.getOrderService().getCareSetting(2));
    order.setEncounter(Context.getEncounterService().getEncounter(3));
    order.setOrderer(Context.getProviderService().getProvider(1));
    Drug drug = Context.getConceptService().getDrug(3);
    order.setDrug(drug);
    order.setConcept(null);
    FreeTextDosingInstructions di = new FreeTextDosingInstructions();
    di.setInstructions("testing");
    di.setDosingInstructions(order);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Drug(org.openmrs.Drug) FreeTextDosingInstructions(org.openmrs.FreeTextDosingInstructions) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 63 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfFrequencyIsNullForSimpleDosingInstructionsDosingType.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfFrequencyIsNullForSimpleDosingInstructionsDosingType() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(SimpleDosingInstructions.class);
    order.setFrequency(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("frequency"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 64 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse.

/**
 * @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
 */
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 65 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept.

/**
 * @see DrugOrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept() {
    DrugOrder order = new DrugOrder();
    Drug drug = Context.getConceptService().getDrug(3);
    Concept concept = Context.getConceptService().getConcept(792);
    order.setDrug(drug);
    // the actual concept which matches with drug is "88"
    order.setConcept(concept);
    Assert.assertNotEquals(drug.getConcept(), concept);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("concept"));
    Assert.assertTrue(errors.hasFieldErrors("drug"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

BindException (org.springframework.validation.BindException)458 Test (org.junit.Test)402 Errors (org.springframework.validation.Errors)387 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)384 Date (java.util.Date)61 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Patient (org.openmrs.Patient)40 Calendar (java.util.Calendar)30 Concept (org.openmrs.Concept)26 Encounter (org.openmrs.Encounter)25 TestOrder (org.openmrs.TestOrder)23 OrderType (org.openmrs.OrderType)22 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 Visit (org.openmrs.Visit)19 PatientProgram (org.openmrs.PatientProgram)18 PatientIdentifierType (org.openmrs.PatientIdentifierType)17 Drug (org.openmrs.Drug)15