use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet.
@Test
public void saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet() throws ParseException {
executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrderAutoExpireDate.xml");
Drug drug = conceptService.getDrug(3000);
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.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(0);
drugOrder.setOrderType(null);
drugOrder.setDateActivated(TestUtil.createDateTime("2014-08-03"));
// 20 days
drugOrder.setDuration(20);
drugOrder.setDurationUnits(conceptService.getConcept(1001));
Order savedOrder = orderService.saveOrder(drugOrder, null);
Order loadedOrder = orderService.getOrder(savedOrder.getId());
Assert.assertEquals(TestUtil.createDateTime("2014-08-22 23:59:59"), loadedOrder.getAutoExpireDate());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndThereIsNoDrugOnThePreviousOrder.
/**
* previous order
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndThereIsNoDrugOnThePreviousOrder() {
DrugOrder orderToDiscontinue = new DrugOrder();
orderToDiscontinue.setAction(Action.NEW);
orderToDiscontinue.setPatient(Context.getPatientService().getPatient(7));
orderToDiscontinue.setConcept(Context.getConceptService().getConcept(5497));
orderToDiscontinue.setCareSetting(orderService.getCareSetting(1));
orderToDiscontinue.setOrderer(orderService.getOrder(1).getOrderer());
orderToDiscontinue.setEncounter(encounterService.getEncounter(3));
orderToDiscontinue.setDateActivated(new Date());
orderToDiscontinue.setScheduledDate(new Date());
orderToDiscontinue.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
orderToDiscontinue.setEncounter(encounterService.getEncounter(3));
orderToDiscontinue.setOrderType(orderService.getOrderType(17));
orderToDiscontinue.setDrug(null);
orderToDiscontinue.setDosingType(FreeTextDosingInstructions.class);
orderToDiscontinue.setDosingInstructions("instructions");
orderToDiscontinue.setOrderer(providerService.getProvider(1));
orderToDiscontinue.setDosingInstructions("2 for 5 days");
orderToDiscontinue.setQuantity(10.0);
orderToDiscontinue.setQuantityUnits(conceptService.getConcept(51));
orderToDiscontinue.setNumRefills(2);
orderService.saveOrder(orderToDiscontinue, null);
assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
DrugOrder order = orderToDiscontinue.cloneForDiscontinuing();
order.setDateActivated(new Date());
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderReasonNonCoded("Discontinue this");
orderService.saveOrder(order, null);
Assert.assertNotNull("previous order should be discontinued", orderToDiscontinue.getDateStopped());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued() {
// We are trying to discontinue order id 111 in standardTestDataset.xml
DrugOrder order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setDrug(conceptService.getDrug(3));
order.setEncounter(encounterService.getEncounter(5));
order.setPatient(Context.getPatientService().getPatient(7));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(1));
order.setDateActivated(new Date());
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(500.0);
order.setDoseUnits(conceptService.getConcept(50));
order.setFrequency(orderService.getOrderFrequency(1));
order.setRoute(conceptService.getConcept(22));
order.setNumRefills(10);
order.setQuantity(20.0);
order.setQuantityUnits(conceptService.getConcept(51));
Order previousOrder = orderService.getOrder(111);
assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
order.setPreviousOrder(previousOrder);
orderService.saveOrder(order, null);
Assert.assertEquals(order.getDateActivated(), order.getAutoExpireDate());
Assert.assertNotNull("previous order should be discontinued", previousOrder.getDateStopped());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml");
final Patient patient = patientService.getPatient(2);
// sanity check that we have an active order
DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000);
assertTrue(existingOrder.isActive());
// New Drug order
DrugOrder order = new DrugOrder();
order.setPatient(patient);
order.setConcept(existingOrder.getConcept());
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(existingOrder.getCareSetting());
order.setDrug(conceptService.getDrug(3001));
order.setDosingType(FreeTextDosingInstructions.class);
order.setDosingInstructions("2 for 5 days");
order.setQuantity(10.0);
order.setQuantityUnits(conceptService.getConcept(51));
order.setNumRefills(2);
Order savedDrugOrder = orderService.saveOrder(order, null);
assertNotNull(orderService.getOrder(savedDrugOrder.getOrderId()));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameDrugFormulationExistsBeyondSchedule.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameDrugFormulationExistsBeyondSchedule() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-DrugOrders.xml");
final Patient patient = patientService.getPatient(2);
DrugOrder existingOrder = (DrugOrder) orderService.getOrder(2000);
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
// 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 10 days");
order.setQuantity(10.0);
order.setQuantityUnits(conceptService.getConcept(51));
order.setNumRefills(2);
order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
order.setScheduledDate(DateUtils.addDays(existingOrder.getDateStopped(), 1));
orderService.saveOrder(order, null);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(++initialActiveOrderCount, activeOrders.size());
}
Aggregations