Search in sources :

Example 11 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExists.

/**
 * @see OrderService#saveOrder(Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExists() {
    final Patient patient = patientService.getPatient(2);
    final Concept triomuneThirty = conceptService.getConcept(792);
    // sanity check that we have an active order for the same concept
    DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(3);
    assertTrue(duplicateOrder.isActive());
    assertEquals(triomuneThirty, duplicateOrder.getConcept());
    DrugOrder drugOrder = new DrugOrder();
    drugOrder.setPatient(patient);
    drugOrder.setCareSetting(orderService.getCareSetting(1));
    drugOrder.setConcept(triomuneThirty);
    drugOrder.setEncounter(encounterService.getEncounter(6));
    drugOrder.setOrderer(providerService.getProvider(1));
    drugOrder.setCareSetting(duplicateOrder.getCareSetting());
    drugOrder.setDrug(duplicateOrder.getDrug());
    drugOrder.setDose(duplicateOrder.getDose());
    drugOrder.setDoseUnits(duplicateOrder.getDoseUnits());
    drugOrder.setRoute(duplicateOrder.getRoute());
    drugOrder.setFrequency(duplicateOrder.getFrequency());
    drugOrder.setQuantity(duplicateOrder.getQuantity());
    drugOrder.setQuantityUnits(duplicateOrder.getQuantityUnits());
    drugOrder.setNumRefills(duplicateOrder.getNumRefills());
    expectedException.expect(AmbiguousOrderException.class);
    expectedException.expectMessage("Order.cannot.have.more.than.one");
    orderService.saveOrder(drugOrder, null);
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 12 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldSetConceptForDrugOrdersIfNull.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetConceptForDrugOrdersIfNull() {
    Patient patient = patientService.getPatient(7);
    CareSetting careSetting = orderService.getCareSetting(2);
    OrderType orderType = orderService.getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = encounterService.getEncounter(3);
    order.setEncounter(encounter);
    order.setPatient(patient);
    order.setDrug(conceptService.getDrug(2));
    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");
    orderService.saveOrder(order, null);
    assertNotNull(order.getOrderId());
}
Also used : DrugOrder(org.openmrs.DrugOrder) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 13 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheDCOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheDCOrder() {
    final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(5);
    assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
    // create a different test drug
    Drug discontinuationOrderDrug = new Drug();
    discontinuationOrderDrug.setConcept(orderToDiscontinue.getConcept());
    discontinuationOrderDrug = conceptService.saveDrug(discontinuationOrderDrug);
    assertNotEquals(discontinuationOrderDrug, orderToDiscontinue.getDrug());
    assertNotNull(orderToDiscontinue.getDrug());
    DrugOrder order = orderToDiscontinue.cloneForRevision();
    order.setDateActivated(new Date());
    order.setOrderer(providerService.getProvider(1));
    order.setEncounter(encounterService.getEncounter(6));
    order.setDrug(discontinuationOrderDrug);
    order.setOrderReasonNonCoded("Discontinue this");
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
    orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Drug(org.openmrs.Drug) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 14 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheRevisedOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheRevisedOrder() {
    final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(5);
    // create a different test drug
    Drug discontinuationOrderDrug = new Drug();
    discontinuationOrderDrug.setConcept(orderToDiscontinue.getConcept());
    discontinuationOrderDrug = conceptService.saveDrug(discontinuationOrderDrug);
    assertNotEquals(discontinuationOrderDrug, orderToDiscontinue.getDrug());
    assertNotNull(orderToDiscontinue.getDrug());
    DrugOrder order = orderToDiscontinue.cloneForRevision();
    order.setDateActivated(new Date());
    order.setOrderer(providerService.getProvider(1));
    order.setEncounter(encounterService.getEncounter(6));
    order.setDrug(discontinuationOrderDrug);
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
    orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Drug(org.openmrs.Drug) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 15 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug.

/**
 * @see OrderServiceImpl#discontinueExistingOrdersIfNecessary()
 */
@Test(expected = AmbiguousOrderException.class)
public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-ambiguousDrugOrders.xml");
    DrugOrder order = new DrugOrder();
    order.setAction(Order.Action.DISCONTINUE);
    order.setOrderReasonNonCoded("Discontinue this");
    order.setDrug(conceptService.getDrug(3));
    order.setEncounter(encounterService.getEncounter(7));
    order.setPatient(patientService.getPatient(9));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order = (DrugOrder) orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

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