Search in sources :

Example 26 with Patient

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()));
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 27 with Patient

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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 28 with Patient

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));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 29 with Patient

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);
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 30 with Patient

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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28