use of org.openmrs.Order in project openmrs-core by openmrs.
the class PatientDataUnvoidHandler method handle.
@Override
public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) {
// can't be unvoiding a patient that doesn't exist in the database
if (patient.getId() != null) {
// unvoid all the encounter that got voided as a result of the patient getting voided
EncounterService es = Context.getEncounterService();
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
if (CollectionUtils.isNotEmpty(encounters)) {
for (Encounter encounter : encounters) {
if (encounter.getVoided() && encounter.getDateVoided().equals(origParentVoidedDate) && encounter.getVoidedBy().equals(originalVoidingUser)) {
es.unvoidEncounter(encounter);
}
}
}
// unvoid all the orders that got voided as a result of the patient getting voided
OrderService os = Context.getOrderService();
List<Order> orders = os.getAllOrdersByPatient(patient);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (order.getVoided() && order.getDateVoided().equals(origParentVoidedDate) && order.getVoidedBy().equals(originalVoidingUser)) {
os.unvoidOrder(order);
}
}
}
CohortService cs = Context.getCohortService();
cs.notifyPatientUnvoided(patient, originalVoidingUser, origParentVoidedDate);
}
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class EncounterServiceTest method transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient.
/**
* @see EncounterService#transferEncounter(Encounter,Patient)
*/
@Test
public void transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient() {
executeDataSet(TRANSFER_ENC_DATA_XML);
Patient targetPatient = Context.getPatientService().getPatient(201);
// encounter has 2 obs which are connected with the same order
Encounter sourceEncounter = Context.getEncounterService().getEncounter(201);
Assert.assertEquals(2, sourceEncounter.getOrders().size());
Assert.assertEquals(2, sourceEncounter.getObs().size());
// transfer
Encounter transferredEncounter = Context.getEncounterService().transferEncounter(sourceEncounter, targetPatient);
List<Order> transferredOrders = new ArrayList<>(transferredEncounter.getOrders());
List<Obs> transferredObservations = new ArrayList<>(transferredEncounter.getObs());
// check if transferredEncounter is newly created encounter
Assert.assertNotEquals(sourceEncounter.getId(), transferredEncounter.getId());
Assert.assertEquals(targetPatient, transferredEncounter.getPatient());
// check order
Assert.assertEquals(0, transferredOrders.size());
// check obs
Assert.assertEquals(2, transferredObservations.size());
Assert.assertEquals(targetPatient, transferredObservations.get(0).getPerson());
Assert.assertEquals(targetPatient, transferredObservations.get(1).getPerson());
Assert.assertNull(transferredObservations.get(0).getOrder());
Assert.assertNull(transferredObservations.get(1).getOrder());
// check if form is transferred
Assert.assertNotNull(transferredEncounter.getForm());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldCascadePatientToOrdersInTheEncounter.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldCascadePatientToOrdersInTheEncounter() {
Encounter enc = Context.getEncounterService().getEncounter(15);
Order existing = enc.getOrders().iterator().next();
// for some reason the xml for the existing encounter has already given
// this order a different patient than the encounter that it's contained
// in, but let's verify that:
Assert.assertNotSame(enc.getPatient().getId(), existing.getPatient().getId());
Context.getEncounterService().saveEncounter(enc);
Assert.assertEquals(enc.getPatient().getId(), existing.getPatient().getId());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class EncounterServiceTest method voidEncounter_shouldCascadeToOrders.
/**
* @see EncounterService#voidEncounter(Encounter,String)
*/
@Test
public void voidEncounter_shouldCascadeToOrders() {
EncounterService encounterService = Context.getEncounterService();
// get a nonvoided encounter that has some obs
Encounter encounter = encounterService.getEncounter(1);
encounterService.voidEncounter(encounter, "Just Testing");
Order order = Context.getOrderService().getOrder(1);
assertTrue(order.getVoided());
assertEquals("Just Testing", order.getVoidReason());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class EncounterServiceTest method shouldSaveMultipleOrderGroupsIfDifferentOrdersHaveDifferentOrderGroups.
@Test
public void shouldSaveMultipleOrderGroupsIfDifferentOrdersHaveDifferentOrderGroups() {
executeDataSet(ORDER_SET);
Encounter encounter = new Encounter();
encounter.setPatient(Context.getPatientService().getPatient(3));
encounter.setEncounterType(Context.getEncounterService().getEncounterType(1));
encounter.setEncounterDatetime(new Date());
Context.getEncounterService().saveEncounter(encounter);
Integer encounterId = Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getId();
// Created a new OrderGroup
OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
OrderGroup orderGroup = new OrderGroup();
orderGroup.setOrderSet(orderSet);
orderGroup.setPatient(encounter.getPatient());
orderGroup.setEncounter(Context.getEncounterService().getEncounter(encounterId));
// Created a new OrderGroup
OrderGroup orderGroup2 = new OrderGroup();
orderGroup2.setEncounter(Context.getEncounterService().getEncounter(encounterId));
orderGroup2.setPatient(encounter.getPatient());
// Added this OrderGroup to two new orders
Order newOrder1 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
Order newOrder2 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
Order newOrder3 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1002).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup2).build();
Order newOrder4 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).build();
Order newOrder5 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup2).build();
// Add these orders to the Encounter
encounter.addOrder(newOrder1);
encounter.addOrder(newOrder2);
encounter.addOrder(newOrder3);
encounter.addOrder(newOrder4);
encounter.addOrder(newOrder5);
Context.getEncounterService().saveEncounter(encounter);
Context.flushSession();
List<Order> orders = new ArrayList<>(Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getOrders());
HashMap<Integer, OrderGroup> orderGroups = new HashMap<>();
for (Order order : orders) {
if (order.getOrderGroup() != null) {
orderGroups.put(order.getOrderGroup().getId(), order.getOrderGroup());
}
}
assertEquals("Two New Order Groups Get Saved", 2, orderGroups.size());
}
Aggregations