Search in sources :

Example 21 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting() {
    // sanity check that we have an active order
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder activeOrder = new TestOrder();
    activeOrder.setPatient(patient);
    activeOrder.setConcept(cd4Count);
    activeOrder.setEncounter(encounterService.getEncounter(6));
    activeOrder.setOrderer(providerService.getProvider(1));
    activeOrder.setCareSetting(orderService.getCareSetting(2));
    activeOrder.setDateActivated(new Date());
    activeOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
    orderService.saveOrder(activeOrder, null);
    // New Drug order in future for same concept
    TestOrder secondOrder = new TestOrder();
    secondOrder.setPatient(activeOrder.getPatient());
    secondOrder.setConcept(activeOrder.getConcept());
    secondOrder.setEncounter(encounterService.getEncounter(6));
    secondOrder.setOrderer(providerService.getProvider(1));
    secondOrder.setCareSetting(activeOrder.getCareSetting());
    secondOrder.setDateActivated(new Date());
    secondOrder.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 1));
    secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    orderService.saveOrder(secondOrder, null);
    // Revise Second Order to have scheduled date not overlapping with active order
    TestOrder revision = secondOrder.cloneForRevision();
    revision.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 2));
    revision.setEncounter(encounterService.getEncounter(6));
    revision.setOrderer(providerService.getProvider(1));
    Order savedRevisionOrder = orderService.saveOrder(revision, null);
    assertNotNull(orderService.getOrder(savedRevisionOrder.getOrderId()));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) Date(java.util.Date) Ignore(org.junit.Ignore) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 22 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldPassForRevisionOrderIfAnActiveTestOrderForTheSameConceptAndCareSettingsExists.

/**
 *           settings exists
 * @see OrderService#saveOrder(Order, OrderContext)
 */
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldPassForRevisionOrderIfAnActiveTestOrderForTheSameConceptAndCareSettingsExists() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder activeOrder = new TestOrder();
    activeOrder.setPatient(patient);
    activeOrder.setConcept(cd4Count);
    activeOrder.setEncounter(encounterService.getEncounter(6));
    activeOrder.setOrderer(providerService.getProvider(1));
    activeOrder.setCareSetting(orderService.getCareSetting(2));
    activeOrder.setDateActivated(new Date());
    activeOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
    orderService.saveOrder(activeOrder, null);
    // New order in future for same concept
    TestOrder secondOrder = new TestOrder();
    secondOrder.setPatient(activeOrder.getPatient());
    secondOrder.setConcept(activeOrder.getConcept());
    secondOrder.setEncounter(encounterService.getEncounter(6));
    secondOrder.setOrderer(providerService.getProvider(1));
    secondOrder.setCareSetting(activeOrder.getCareSetting());
    secondOrder.setDateActivated(new Date());
    secondOrder.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 1));
    secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    orderService.saveOrder(secondOrder, null);
    // Revise second order to have scheduled date overlapping with active order
    TestOrder revision = secondOrder.cloneForRevision();
    revision.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStartDate(), 2));
    revision.setEncounter(encounterService.getEncounter(6));
    revision.setOrderer(providerService.getProvider(1));
    Order savedSecondOrder = orderService.saveOrder(revision, null);
    assertNotNull(orderService.getOrder(savedSecondOrder.getOrderId()));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) Date(java.util.Date) Ignore(org.junit.Ignore) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 23 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class OrderServiceTest method getOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified.

/**
 * @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting,
 *      org.openmrs.OrderType, boolean)
 */
@Test
public void getOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrders.xml");
    Patient patient = patientService.getPatient(2);
    OrderType testOrderType = orderService.getOrderType(2);
    CareSetting outPatient = orderService.getCareSetting(1);
    List<Order> orders = orderService.getOrders(patient, outPatient, testOrderType, false);
    assertEquals(7, orders.size());
    Order[] expectedOrder1 = { orderService.getOrder(6), orderService.getOrder(7), orderService.getOrder(9), orderService.getOrder(101), orderService.getOrder(102), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder1));
    OrderType labTestOrderType = orderService.getOrderType(7);
    orders = orderService.getOrders(patient, outPatient, labTestOrderType, false);
    assertEquals(3, orderService.getOrders(patient, outPatient, labTestOrderType, false).size());
    Order[] expectedOrder2 = { orderService.getOrder(101), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder2));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 24 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class OrderServiceTest method getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrders.xml");
    Patient patient = Context.getPatientService().getPatient(2);
    OrderType testOrderType = orderService.getOrderType(2);
    List<Order> orders = orderService.getActiveOrders(patient, testOrderType, null, null);
    assertEquals(5, orders.size());
    Order[] expectedOrder1 = { orderService.getOrder(7), orderService.getOrder(101), orderService.getOrder(102), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder1));
    OrderType labTestOrderType = orderService.getOrderType(7);
    orders = orderService.getActiveOrders(patient, labTestOrderType, null, null);
    assertEquals(3, orders.size());
    Order[] expectedOrder2 = { orderService.getOrder(101), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder2));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 25 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient() {
    Patient patient = patientService.getPatient(2);
    List<Order> orders = orderService.getActiveOrders(patient, orderService.getOrderType(1), null, null);
    assertEquals(4, orders.size());
    Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) };
    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) 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