Search in sources :

Example 36 with Patient

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

the class ObsServiceTest method saveObs_shouldCreateVeryBasicObsAndAddNewObsId.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldCreateVeryBasicObsAndAddNewObsId() {
    Obs o = new Obs();
    o.setConcept(Context.getConceptService().getConcept(3));
    o.setPerson(new Patient(2));
    o.setEncounter(new Encounter(3));
    o.setObsDatetime(new Date());
    o.setLocation(new Location(1));
    o.setValueNumeric(50d);
    Obs oSaved = Context.getObsService().saveObs(o, null);
    // make sure the returned Obs and the passed in obs
    // now both have primary key obsIds
    assertTrue(oSaved.getObsId().equals(o.getObsId()));
}
Also used : 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 37 with Patient

use of org.openmrs.Patient 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 38 with Patient

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

the class ObsServiceTest method saveObs_shouldCascadeSaveToChildObsGroups.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldCascadeSaveToChildObsGroups() {
    ObsService obsService = Context.getObsService();
    Obs parentObs = new Obs();
    parentObs.setConcept(Context.getConceptService().getConcept(3));
    parentObs.setObsDatetime(new Date());
    parentObs.setPerson(new Patient(2));
    parentObs.setLocation(new Location(1));
    Obs groupMember = new Obs();
    groupMember.setConcept(Context.getConceptService().getConcept(3));
    groupMember.setValueNumeric(1.0);
    groupMember.setObsDatetime(new Date());
    groupMember.setPerson(new Patient(2));
    groupMember.setLocation(new Location(1));
    parentObs.addGroupMember(groupMember);
    obsService.saveObs(parentObs, null);
    // make sure the child obs was saved
    Assert.assertNotNull(groupMember.getObsId());
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 39 with Patient

use of org.openmrs.Patient 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 40 with Patient

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

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