Search in sources :

Example 16 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldSetOrderTypeOfDrugOrderToDrugOrderIfNotSetAndConceptNotMapped.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderTypeOfDrugOrderToDrugOrderIfNotSetAndConceptNotMapped() {
    Drug drug = conceptService.getDrug(2);
    Concept unmappedConcept = conceptService.getConcept(113);
    Assert.assertNull(orderService.getOrderTypeByConcept(unmappedConcept));
    drug.setConcept(unmappedConcept);
    DrugOrder drugOrder = new DrugOrder();
    Encounter encounter = encounterService.getEncounter(3);
    drugOrder.setEncounter(encounter);
    drugOrder.setPatient(patientService.getPatient(7));
    drugOrder.setCareSetting(orderService.getCareSetting(1));
    drugOrder.setOrderer(Context.getProviderService().getProvider(1));
    drugOrder.setDateActivated(encounter.getEncounterDatetime());
    drugOrder.setDrug(drug);
    drugOrder.setDosingType(SimpleDosingInstructions.class);
    drugOrder.setDose(300.0);
    drugOrder.setDoseUnits(conceptService.getConcept(50));
    drugOrder.setQuantity(20.0);
    drugOrder.setQuantityUnits(conceptService.getConcept(51));
    drugOrder.setFrequency(orderService.getOrderFrequency(3));
    drugOrder.setRoute(conceptService.getConcept(22));
    drugOrder.setNumRefills(10);
    drugOrder.setOrderType(null);
    orderService.saveOrder(drugOrder, null);
    Assert.assertNotNull(drugOrder.getOrderType());
    Assert.assertEquals(orderService.getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID), drugOrder.getOrderType());
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 17 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept.

/**
 * @see DrugOrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept() {
    Concept concept = Context.getConceptService().getConcept(3);
    assertThat(concept, not(isIn(Context.getOrderService().getDrugDispensingUnits())));
    DrugOrder order = new DrugOrder();
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDuration(5);
    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("quantityUnits"));
}
Also used : Concept(org.openmrs.Concept) 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 18 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet.

@Test
public void saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet() {
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    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.assertTrue(errors.hasFieldErrors());
    assertEquals("DrugOrder.error.drugIsRequired", errors.getFieldError("drug").getCode());
}
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 19 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldNotValidateACustomDosingTypeAgainstAnyOtherDosingTypeValidation.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldNotValidateACustomDosingTypeAgainstAnyOtherDosingTypeValidation() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(CustomDosingInstructions.class);
    order.setDosingInstructions(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors("dosingInstructions"));
}
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 20 with DrugOrder

use of org.openmrs.DrugOrder 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)

Aggregations

DrugOrder (org.openmrs.DrugOrder)68 Test (org.junit.Test)64 OrderUtilTest (org.openmrs.order.OrderUtilTest)64 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)64 BindException (org.springframework.validation.BindException)38 Errors (org.springframework.validation.Errors)38 Patient (org.openmrs.Patient)22 Date (java.util.Date)18 Encounter (org.openmrs.Encounter)17 Concept (org.openmrs.Concept)12 CareSetting (org.openmrs.CareSetting)11 Order (org.openmrs.Order)11 OrderType (org.openmrs.OrderType)11 TestOrder (org.openmrs.TestOrder)11 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 Drug (org.openmrs.Drug)7 GlobalProperty (org.openmrs.GlobalProperty)7 Calendar (java.util.Calendar)5 SimpleDateFormat (java.text.SimpleDateFormat)1 Ignore (org.junit.Ignore)1