use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSaveARevisedOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldSaveARevisedOrder() {
Order originalOrder = orderService.getOrder(111);
assertTrue(originalOrder.isActive());
final Patient patient = originalOrder.getPatient();
List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null);
final int originalOrderCount = originalActiveOrders.size();
assertTrue(originalActiveOrders.contains(originalOrder));
Order revisedOrder = originalOrder.cloneForRevision();
revisedOrder.setEncounter(encounterService.getEncounter(5));
revisedOrder.setInstructions("Take after a meal");
revisedOrder.setDateActivated(new Date());
revisedOrder.setOrderer(providerService.getProvider(1));
revisedOrder.setEncounter(encounterService.getEncounter(3));
orderService.saveOrder(revisedOrder, null);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(originalOrderCount, activeOrders.size());
assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1));
assertFalse(originalOrder.isActive());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists() {
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
// sanity check that we have an active order for the same concept
TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
assertTrue(duplicateOrder.isActive());
assertEquals(cd4Count, duplicateOrder.getConcept());
Order order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(duplicateOrder.getCareSetting());
Order savedOrder = orderService.saveOrder(order, null);
assertNotNull(orderService.getOrder(savedOrder.getOrderId()));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting() {
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
final CareSetting inpatient = orderService.getCareSetting(2);
assertNotEquals(inpatient, duplicateOrder.getCareSetting());
assertTrue(duplicateOrder.isActive());
assertEquals(cd4Count, duplicateOrder.getConcept());
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(inpatient);
orderService.saveOrder(order, null);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(++initialActiveOrderCount, activeOrders.size());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method getOrders_shouldFailIfCareSettingIsNull.
/**
* @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting,
* org.openmrs.OrderType, boolean)
*/
@Test
public void getOrders_shouldFailIfCareSettingIsNull() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("CareSetting is required");
orderService.getOrders(new Patient(), null, null, false);
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method getOrderHistoryByConcept_shouldReturnEmptyListForConceptWithoutOrders.
/**
* @see OrderService#getOrderHistoryByConcept(Patient, Concept)
*/
@Test
public void getOrderHistoryByConcept_shouldReturnEmptyListForConceptWithoutOrders() {
Concept concept = Context.getConceptService().getConcept(21);
Patient patient = Context.getPatientService().getPatient(2);
List<Order> orders = orderService.getOrderHistoryByConcept(patient, concept);
Assert.assertEquals(0, orders.size());
}
Aggregations