Search in sources :

Example 41 with Patient

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

Example 42 with Patient

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()));
}
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) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 43 with Patient

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());
}
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) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 44 with Patient

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

Example 45 with Patient

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());
}
Also used : Concept(org.openmrs.Concept) 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