use of org.openmrs.Encounter 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.Encounter 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.Encounter in project openmrs-core by openmrs.
the class OrderServiceTest method discontinueOrder_shouldPopulateCorrectAttributesOnTheDiscontinueAndDiscontinuedOrders.
/**
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
* org.openmrs.Provider, org.openmrs.Encounter)
*/
@Test
public void discontinueOrder_shouldPopulateCorrectAttributesOnTheDiscontinueAndDiscontinuedOrders() {
Order order = orderService.getOrderByOrderNumber("111");
Encounter encounter = encounterService.getEncounter(3);
Provider orderer = providerService.getProvider(1);
assertTrue(OrderUtilTest.isActiveOrder(order, null));
Date discontinueDate = new Date();
String discontinueReasonNonCoded = "Test if I can discontinue this";
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, orderer, encounter);
Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Assert.assertNotNull(discontinueOrder.getId());
Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
Assert.assertEquals(discontinueOrder.getOrderReasonNonCoded(), discontinueReasonNonCoded);
Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class OrderServiceTest method shouldSaveOrdersWithSortWeightWhenWithinAOrderGroup.
@Test
public void shouldSaveOrdersWithSortWeightWhenWithinAOrderGroup() {
executeDataSet(ORDER_SET);
Encounter encounter = encounterService.getEncounter(3);
OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
OrderGroup orderGroup = new OrderGroup();
orderGroup.setOrderSet(orderSet);
orderGroup.setPatient(encounter.getPatient());
orderGroup.setEncounter(encounter);
Order firstOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
Order secondOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
Order orderWithoutOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).build();
Set<Order> orders = new LinkedHashSet<>();
orders.add(firstOrderWithOrderGroup);
orders.add(secondOrderWithOrderGroup);
orders.add(orderWithoutOrderGroup);
encounter.setOrders(orders);
for (OrderGroup og : encounter.getOrderGroups()) {
if (og.getId() == null) {
Context.getOrderService().saveOrderGroup(og);
}
}
for (Order o : encounter.getOrdersWithoutOrderGroups()) {
if (o.getId() == null) {
Context.getOrderService().saveOrder(o, null);
}
}
Context.flushSession();
OrderGroup savedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
Order savedOrder = Context.getOrderService().getOrderByUuid(orderWithoutOrderGroup.getUuid());
assertEquals("The first order in savedOrderGroup is the same which is sent first in the List", firstOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(0).getUuid());
assertEquals("The second order in savedOrderGroup is the same which is sent second in the List", secondOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(1).getUuid());
assertNull("The order which doesn't belong to an orderGroup has no sortWeight", savedOrder.getSortWeight());
assertThat("The first order has a lower sortWeight than the second", savedOrderGroup.getOrders().get(0).getSortWeight().compareTo(savedOrderGroup.getOrders().get(1).getSortWeight()), is(-1));
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class OrderServiceTest method discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDateWithParamConcept.
/**
* @see OrderService#discontinueOrder(Order,Concept,Date,Provider,Encounter)
*/
@Test
public void discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDateWithParamConcept() {
Order order = new Order();
order.setAction(Action.NEW);
order.setPatient(Context.getPatientService().getPatient(7));
order.setConcept(Context.getConceptService().getConcept(5497));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderer(orderService.getOrder(1).getOrderer());
order.setEncounter(encounterService.getEncounter(3));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(17));
order.setDateActivated(new Date());
order.setScheduledDate(DateUtils.addMonths(new Date(), 2));
order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
order = orderService.saveOrder(order, null);
assertTrue(OrderUtilTest.isActiveOrder(order, null));
assertFalse(order.isStarted());
Encounter encounter = encounterService.getEncounter(3);
Provider orderer = providerService.getProvider(1);
Date discontinueDate = new Date();
Concept concept = Context.getConceptService().getConcept(1);
Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, orderer, encounter);
Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Assert.assertNotNull(discontinueOrder.getId());
Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
Assert.assertEquals(discontinueOrder.getOrderReason(), concept);
Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
Aggregations