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()));
}
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());
}
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());
}
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));
}
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));
}
Aggregations