Search in sources :

Example 61 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldFailDiscontinueNonCodedDrugOrderIfOrderableOfPreviousAndNewOrderDontMatch.

@Test
public void saveOrder_shouldFailDiscontinueNonCodedDrugOrderIfOrderableOfPreviousAndNewOrderDontMatch() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
    DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
    DrugOrder drugOrder = previousOrder.cloneForDiscontinuing();
    drugOrder.setDrugNonCoded("non coded drug citrigine");
    drugOrder.setPreviousOrder(previousOrder);
    drugOrder.setDateActivated(new Date());
    drugOrder.setOrderer(providerService.getProvider(1));
    drugOrder.setEncounter(encounterService.getEncounter(6));
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
    orderService.saveOrder(drugOrder, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 62 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldThrowAmbiguousOrderExceptionIfAnActiveDrugOrderForTheSameDrugFormulationExists.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldThrowAmbiguousOrderExceptionIfAnActiveDrugOrderForTheSameDrugFormulationExists() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml");
    final Patient patient = patientService.getPatient(2);
    // sanity check that we have an active order for the same concept
    DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000);
    assertTrue(existingOrder.isActive());
    // New Drug order
    DrugOrder order = new DrugOrder();
    order.setPatient(patient);
    order.setDrug(existingOrder.getDrug());
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(existingOrder.getCareSetting());
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDosingInstructions("2 for 5 days");
    order.setQuantity(10.0);
    order.setQuantityUnits(conceptService.getConcept(51));
    order.setNumRefills(2);
    expectedException.expect(AmbiguousOrderException.class);
    expectedException.expectMessage("Order.cannot.have.more.than.one");
    orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 63 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldFailIfDrugNonCodedInPreviousDrugOrderDoesNotMatchThatOfTheRevisedDrugOrder.

@Test
public void saveOrder_shouldFailIfDrugNonCodedInPreviousDrugOrderDoesNotMatchThatOfTheRevisedDrugOrder() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
    DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
    DrugOrder order = previousOrder.cloneForRevision();
    String drugNonCodedParacetemol = "non coded aspirin";
    order.setDateActivated(new Date());
    order.setOrderer(providerService.getProvider(1));
    order.setEncounter(encounterService.getEncounter(6));
    assertFalse(previousOrder.getDrugNonCoded().equals(drugNonCodedParacetemol));
    order.setDrugNonCoded(drugNonCodedParacetemol);
    order.setPreviousOrder(previousOrder);
    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) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 64 with DrugOrder

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

the class OrderServiceTest method saveRetrospectiveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExistsAtOrderDateActivated.

@Test
public void saveRetrospectiveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExistsAtOrderDateActivated() throws ParseException {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-ordersWithAutoExpireDate.xml");
    Date newOrderDateActivated = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2008-11-19 13:00:10");
    final Patient patient = patientService.getPatient(12);
    final Concept orderConcept = conceptService.getConcept(88);
    // sanity check that we have an active order for the same concept
    DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(202);
    assertTrue(duplicateOrder.isActive(newOrderDateActivated));
    assertEquals(orderConcept, duplicateOrder.getConcept());
    DrugOrder order = new DrugOrder();
    order.setPatient(patient);
    order.setConcept(orderConcept);
    order.setEncounter(encounterService.getEncounter(17));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(duplicateOrder.getCareSetting());
    order.setDateActivated(newOrderDateActivated);
    order.setDrug(duplicateOrder.getDrug());
    order.setDose(duplicateOrder.getDose());
    order.setDoseUnits(duplicateOrder.getDoseUnits());
    order.setRoute(duplicateOrder.getRoute());
    order.setFrequency(duplicateOrder.getFrequency());
    order.setQuantity(duplicateOrder.getQuantity());
    order.setQuantityUnits(duplicateOrder.getQuantityUnits());
    order.setNumRefills(duplicateOrder.getNumRefills());
    expectedException.expect(AmbiguousOrderException.class);
    expectedException.expectMessage("Order.cannot.have.more.than.one");
    orderService.saveRetrospectiveOrder(order, null);
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 65 with DrugOrder

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

the class OrderServiceTest method saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndDrugOfTheDCOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndDrugOfTheDCOrder() {
    final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(444);
    assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
    DrugOrder order = new DrugOrder();
    order.setDrug(orderToDiscontinue.getDrug());
    order.setOrderType(orderService.getOrderTypeByName("Drug order"));
    order.setAction(Order.Action.DISCONTINUE);
    order.setOrderReasonNonCoded("Discontinue this");
    order.setPatient(orderToDiscontinue.getPatient());
    order.setConcept(orderToDiscontinue.getConcept());
    order.setOrderer(orderToDiscontinue.getOrderer());
    order.setCareSetting(orderToDiscontinue.getCareSetting());
    order.setEncounter(encounterService.getEncounter(6));
    order.setDateActivated(new Date());
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDose(orderToDiscontinue.getDose());
    order.setDoseUnits(orderToDiscontinue.getDoseUnits());
    order.setRoute(orderToDiscontinue.getRoute());
    order.setFrequency(orderToDiscontinue.getFrequency());
    order.setQuantity(orderToDiscontinue.getQuantity());
    order.setQuantityUnits(orderToDiscontinue.getQuantityUnits());
    order.setNumRefills(orderToDiscontinue.getNumRefills());
    orderService.saveOrder(order, null);
    Assert.assertNotNull("previous order should be discontinued", orderToDiscontinue.getDateStopped());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Date(java.util.Date) 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