Search in sources :

Example 41 with Order

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

the class ObsServiceTest method saveObs_shouldAllowSettingPropertiesOnObs.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldAllowSettingPropertiesOnObs() {
    ObsService obsService = Context.getObsService();
    Order order = null;
    Concept concept = Context.getConceptService().getConcept(3);
    Patient patient = new Patient(2);
    Encounter encounter = new Encounter(3);
    Date datetime = new Date();
    Location location = new Location(1);
    Integer valueGroupId = 7;
    Date valueDatetime = new Date();
    Concept valueCoded = new Concept(3);
    Double valueNumeric = 2.0;
    String valueModifier = "cc";
    String valueText = "value text2";
    String comment = "commenting2";
    Obs obs = new Obs();
    obs.setOrder(order);
    obs.setConcept(concept);
    obs.setPerson(patient);
    obs.setEncounter(encounter);
    obs.setObsDatetime(datetime);
    obs.setLocation(location);
    obs.setValueGroupId(valueGroupId);
    obs.setValueDatetime(valueDatetime);
    obs.setValueCoded(valueCoded);
    obs.setValueNumeric(valueNumeric);
    obs.setValueModifier(valueModifier);
    obs.setValueText(valueText);
    obs.setComment(comment);
    Obs saved = obsService.saveObs(obs, null);
    assertEquals(order, saved.getOrder());
    assertEquals(patient, saved.getPerson());
    assertEquals(comment, saved.getComment());
    assertEquals(concept, saved.getConcept());
    assertEquals(encounter, saved.getEncounter());
    assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime());
    assertEquals(location, saved.getLocation());
    assertEquals(valueGroupId, saved.getValueGroupId());
    assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime());
    assertEquals(valueCoded, saved.getValueCoded());
    assertEquals(valueNumeric, saved.getValueNumeric());
    assertEquals(valueModifier, saved.getValueModifier());
    assertEquals(valueText, saved.getValueText());
}
Also used : Order(org.openmrs.Order) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 42 with Order

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

the class OrderServiceTest method getActiveOrders_shouldReturnActiveOrdersAsOfTheSpecifiedDate.

/**
 * @throws ParseException
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldReturnActiveOrdersAsOfTheSpecifiedDate() throws ParseException {
    Patient patient = Context.getPatientService().getPatient(2);
    List<Order> orders = orderService.getAllOrdersByPatient(patient);
    assertEquals(12, orders.size());
    Date asOfDate = Context.getDateFormat().parse("10/12/2007");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(2, orders.size());
    // DC
    assertFalse(orders.contains(orderService.getOrder(22)));
    // DC
    assertFalse(orders.contains(orderService.getOrder(44)));
    // voided
    assertFalse(orders.contains(orderService.getOrder(8)));
    Order[] expectedOrders = { orderService.getOrder(9) };
    asOfDate = Context.getDateTimeFormat().parse("10/12/2007 00:01:00");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(1, orders.size());
    assertThat(orders, hasItems(expectedOrders));
    Order[] expectedOrders1 = { orderService.getOrder(3), orderService.getOrder(4), orderService.getOrder(222) };
    asOfDate = Context.getDateFormat().parse("10/04/2008");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(3, orders.size());
    assertThat(orders, hasItems(expectedOrders1));
    asOfDate = Context.getDateTimeFormat().parse("10/04/2008 00:01:00");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(2, orders.size());
    Order[] expectedOrders2 = { orderService.getOrder(222), orderService.getOrder(3) };
    assertThat(orders, hasItems(expectedOrders2));
    Order[] expectedOrders3 = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(6) };
    asOfDate = Context.getDateTimeFormat().parse("26/09/2008 09:24:10");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(5, orders.size());
    assertThat(orders, hasItems(expectedOrders3));
    asOfDate = Context.getDateTimeFormat().parse("26/09/2008 09:25:10");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(4, orders.size());
    Order[] expectedOrders4 = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) };
    assertThat(orders, hasItems(expectedOrders4));
    asOfDate = Context.getDateFormat().parse("04/12/2008");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(5, orders.size());
    Order[] expectedOrders5 = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) };
    assertThat(orders, hasItems(expectedOrders5));
    asOfDate = Context.getDateFormat().parse("06/12/2008");
    orders = orderService.getActiveOrders(patient, null, null, asOfDate);
    assertEquals(5, orders.size());
    assertThat(orders, hasItems(expectedOrders5));
}
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 43 with Order

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

the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatient.

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

Example 44 with Order

use of org.openmrs.Order 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 45 with Order

use of org.openmrs.Order 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)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9