use of org.openmrs.Patient 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.Patient 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.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatientAndCareSetting.
/**
* @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
* org.openmrs.CareSetting, java.util.Date)
*/
@Test
public void getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatientAndCareSetting() {
Patient patient = patientService.getPatient(2);
CareSetting careSetting = orderService.getCareSetting(1);
List<Order> orders = orderService.getActiveOrders(patient, null, careSetting, null);
assertEquals(4, orders.size());
Order[] expectedOrders = { orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) };
assertThat(orders, hasItems(expectedOrders));
}
use of org.openmrs.Patient 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);
}
use of org.openmrs.Patient 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());
}
Aggregations