use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldNotChangeTheAutoExpireDateIfItHasATimeComponent.
/**
* @throws ParseException
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldNotChangeTheAutoExpireDateIfItHasATimeComponent() throws ParseException {
Order order = new TestOrder();
order.setPatient(patientService.getPatient(2));
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(conceptService.getConcept(5089));
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setDateActivated(new Date());
DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
order.setDateActivated(dateformat.parse("14/08/2014 10:00:00"));
Date autoExpireDate = dateformat.parse("18/08/2014 10:00:00");
order.setAutoExpireDate(autoExpireDate);
orderService.saveOrder(order, null);
assertEquals(autoExpireDate, order.getAutoExpireDate());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method discontinueOrder_shouldFailForADiscontinuationOrder.
/**
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
* org.openmrs.Provider, org.openmrs.Encounter)
*/
@Test
public void discontinueOrder_shouldFailForADiscontinuationOrder() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinuedOrder.xml");
Order discontinuationOrder = orderService.getOrder(26);
assertEquals(Action.DISCONTINUE, discontinuationOrder.getAction());
Encounter encounter = encounterService.getEncounter(3);
expectedException.expect(CannotStopDiscontinuationOrderException.class);
expectedException.expectMessage(mss.getMessage("Order.action.cannot.discontinue"));
orderService.discontinueOrder(discontinuationOrder, "Test if I can discontinue this", null, null, encounter);
}
use of org.openmrs.Order 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());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method unvoidOrder_shouldFailForAReviseOrderIfThePreviousOrderIsInactive.
/**
* @throws InterruptedException
* @see OrderService#unvoidOrder(org.openmrs.Order)
*/
@Test
public void unvoidOrder_shouldFailForAReviseOrderIfThePreviousOrderIsInactive() throws InterruptedException {
Order order = orderService.getOrder(111);
assertEquals(Action.REVISE, order.getAction());
Order previousOrder = order.getPreviousOrder();
assertNotNull(previousOrder.getDateStopped());
assertFalse(order.getVoided());
// void the DC order for testing purposes so we can unvoid it later
orderService.voidOrder(order, "None");
assertTrue(order.getVoided());
assertNull(previousOrder.getDateStopped());
// stop the order with a different REVISE order
Order revise = previousOrder.cloneForRevision();
revise.setOrderer(order.getOrderer());
revise.setEncounter(order.getEncounter());
orderService.saveOrder(revise, null);
Thread.sleep(10);
expectedException.expect(CannotUnvoidOrderException.class);
expectedException.expectMessage(mss.getMessage("Order.action.cannot.unvoid", new Object[] { "revision" }, null));
orderService.unvoidOrder(order);
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate.
/**
* @see OrderService#discontinueOrder(Order,String,Date,Provider,Encounter)
*/
@Test
public void discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate() {
Order order = new Order();
order.setAction(Action.NEW);
order.setPatient(Context.getPatientService().getPatient(7));
order.setConcept(Context.getConceptService().getConcept(5497));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderer(orderService.getOrder(1).getOrderer());
order.setEncounter(encounterService.getEncounter(3));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(17));
order.setDateActivated(new Date());
order.setScheduledDate(DateUtils.addMonths(new Date(), 2));
order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
order = orderService.saveOrder(order, null);
assertTrue(OrderUtilTest.isActiveOrder(order, null));
assertFalse(order.isStarted());
Encounter encounter = encounterService.getEncounter(3);
Provider orderer = providerService.getProvider(1);
Date discontinueDate = new Date();
String discontinueReasonNonCoded = "Test if I can discontinue this";
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, orderer, encounter);
Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Assert.assertNotNull(discontinueOrder.getId());
Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
Assert.assertEquals(discontinueOrder.getOrderReasonNonCoded(), discontinueReasonNonCoded);
Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
Aggregations