use of org.openmrs.Order in project openmrs-core by openmrs.
the class EncounterServiceTest method unvoidEncounter_shouldCascadeUnvoidToOrders.
/**
* @see EncounterService#unvoidEncounter(Encounter)
*/
@Test
public void unvoidEncounter_shouldCascadeUnvoidToOrders() {
EncounterService encounterService = Context.getEncounterService();
// get a voided encounter that has some voided obs
Encounter encounter = encounterService.getEncounter(2);
encounterService.unvoidEncounter(encounter);
Order order = Context.getOrderService().getOrder(2);
assertFalse(order.getVoided());
assertNull(order.getVoidReason());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class PatientDataVoidHandlerTest method handle_shouldVoidTheOrdersEncountersAndObservationsAssociatedWithThePatient.
/**
* @see PatientDataVoidHandler#handle(Patient,User,Date,String)
*/
@Test
public void handle_shouldVoidTheOrdersEncountersAndObservationsAssociatedWithThePatient() {
Patient patient = Context.getPatientService().getPatient(7);
Assert.assertFalse(patient.getVoided());
List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient);
List<Obs> observations = Context.getObsService().getObservationsByPerson(patient);
List<Order> orders = Context.getOrderService().getAllOrdersByPatient(patient);
// we should have some unvoided encounters, obs and orders for the test to be concrete
assertTrue(CollectionUtils.isNotEmpty(encounters));
assertTrue(CollectionUtils.isNotEmpty(observations));
assertTrue(CollectionUtils.isNotEmpty(orders));
// check that fields to be set by the handler are initially null
for (Encounter encounter : encounters) {
assertNull(encounter.getDateVoided());
assertNull(encounter.getVoidedBy());
assertNull(encounter.getVoidReason());
}
for (Obs obs : observations) {
assertNull(obs.getDateVoided());
assertNull(obs.getVoidedBy());
assertNull(obs.getVoidReason());
}
for (Order order : orders) {
assertNull(order.getDateVoided());
assertNull(order.getVoidedBy());
assertNull(order.getVoidReason());
}
new PatientDataVoidHandler().handle(patient, new User(1), new Date(), "voidReason");
// all encounters void related fields should have been set
for (Encounter encounter : encounters) {
assertTrue(encounter.getVoided());
assertNotNull(encounter.getDateVoided());
assertNotNull(encounter.getVoidedBy());
assertNotNull(encounter.getVoidReason());
}
// all obs void related fields should have been set
for (Obs obs : observations) {
assertTrue(obs.getVoided());
assertNotNull(obs.getDateVoided());
assertNotNull(obs.getVoidedBy());
assertNotNull(obs.getVoidReason());
}
// all order void related fields should have been set
for (Order order : orders) {
assertTrue(order.getVoided());
assertNotNull(order.getDateVoided());
assertNotNull(order.getVoidedBy());
assertNotNull(order.getVoidReason());
}
// refresh the lists and check that all encounters, obs and orders were voided
encounters = Context.getEncounterService().getEncountersByPatient(patient);
observations = Context.getObsService().getObservationsByPerson(patient);
assertTrue(CollectionUtils.isEmpty(encounters));
assertTrue(CollectionUtils.isEmpty(observations));
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class PatientServiceTest method hasActiveOrderOfType.
private boolean hasActiveOrderOfType(Patient patient, String orderTypeName) {
OrderType drugOrder = Context.getOrderService().getOrderTypeByName(orderTypeName);
List<Order> preferredPatientOrders = Context.getOrderService().getAllOrdersByPatient(patient).stream().filter(Order::isActive).filter(order -> Objects.equals(drugOrder, order.getOrderType())).collect(Collectors.toList());
return !preferredPatientOrders.isEmpty();
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class ImmutableEntityInterceptorTest method onFlushDirty_shouldPassIfAnEntityHasChangesForAnAllowedMutableProperty.
/**
* @see ImmutableEntityInterceptor#onFlushDirty(Object, java.io.Serializable, Object[],
* Object[], String[], org.hibernate.type.Type[])
*/
@Test
public void onFlushDirty_shouldPassIfAnEntityHasChangesForAnAllowedMutableProperty() {
String[] propertyNames = new String[] { SomeImmutableEntityInterceptor.MUTABLE_FIELD_NAME };
String[] previousState = new String[] { "old" };
String[] currentState = new String[] { "new" };
new SomeImmutableEntityInterceptor().onFlushDirty(new Order(), null, currentState, previousState, propertyNames, null);
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class PatientDataUnvoidHandlerTest method handle_shouldNotUnvoidTheOrdersAndEncountersThatNeverGotVoidedWithThePatient.
/**
* @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
*/
@Test
public void handle_shouldNotUnvoidTheOrdersAndEncountersThatNeverGotVoidedWithThePatient() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-otherEncounters.xml");
Patient patient = Context.getPatientService().getPatient(7);
EncounterService es = Context.getEncounterService();
OrderService os = Context.getOrderService();
Encounter testEncounter = es.getEncountersByPatient(patient).get(0);
// santy checks
assertFalse(testEncounter.getVoided());
assertNull(testEncounter.getDateVoided());
assertNull(testEncounter.getVoidedBy());
assertNull(testEncounter.getVoidReason());
// void one of the encounter orders be voided at a different time for testing purposes
assertFalse(testEncounter.getOrders().isEmpty());
Order testOrder = testEncounter.getOrders().iterator().next();
assertFalse(testOrder.getVoided());
Context.getOrderService().voidOrder(testOrder, "testing");
assertTrue(testOrder.getVoided());
TestUtil.waitForClockTick();
// void one of the unvoided encounters for testing purposes
es.voidEncounter(testEncounter, "random reason");
assertTrue(testEncounter.getVoided());
assertTrue(testOrder.getVoided());
List<Patient> patients = new ArrayList<>();
patients.add(patient);
// wait a bit so that the patient isn't voided on the same millisecond
TestUtil.waitForClockTick();
// now void the patient for testing purposes
patient = Context.getPatientService().voidPatient(patient, "Void Reason");
assertTrue(patient.getVoided());
new PatientDataUnvoidHandler().handle(patient, patient.getVoidedBy(), patient.getDateVoided(), null);
// the encounter that was initially voided separately should still be voided
testEncounter = es.getEncounter(testEncounter.getId());
assertTrue(testEncounter.getVoided());
assertNotNull(testEncounter.getDateVoided());
assertNotNull(testEncounter.getVoidedBy());
assertNotNull(testEncounter.getVoidReason());
// the order that was initially voided separately should still be voided
assertTrue(testOrder.getVoided());
assertNotNull(testOrder.getDateVoided());
assertNotNull(testOrder.getVoidedBy());
assertNotNull(testOrder.getVoidReason());
}
Aggregations