use of org.openmrs.Order in project openmrs-core by openmrs.
the class PatientDataUnvoidHandlerTest method handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient.
/**
* @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
*/
@Test
public void handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient() {
Patient patient = Context.getPatientService().getPatient(7);
patient = Context.getPatientService().voidPatient(patient, "Void Reason");
assertTrue(patient.getVoided());
EncounterService es = Context.getEncounterService();
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
assertTrue(CollectionUtils.isNotEmpty(encounters));
// all encounters void related fields should be null
for (Encounter encounter : encounters) {
assertTrue(encounter.getVoided());
assertNotNull(encounter.getDateVoided());
assertNotNull(encounter.getVoidedBy());
assertNotNull(encounter.getVoidReason());
}
OrderService os = Context.getOrderService();
List<Order> orders = os.getAllOrdersByPatient(patient);
assertFalse(orders.isEmpty());
// all order void related fields should be null
for (Order order : orders) {
assertTrue(order.getVoided());
assertNotNull(order.getDateVoided());
assertNotNull(order.getVoidedBy());
assertNotNull(order.getVoidReason());
}
User user = Context.getUserService().getUser(1);
new PatientDataUnvoidHandler().handle(patient, user, patient.getDateVoided(), null);
// check that the voided related fields were set null
for (Encounter encounter : encounters) {
assertFalse(encounter.getVoided());
assertNull(encounter.getDateVoided());
assertNull(encounter.getVoidedBy());
assertNull(encounter.getVoidReason());
}
for (Order order : orders) {
assertFalse(order.getVoided());
assertNull(order.getDateVoided());
assertNull(order.getVoidedBy());
assertNull(order.getVoidReason());
}
}
use of org.openmrs.Order in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjects method parseOrders.
public List<SimpleObject> parseOrders() {
List<SimpleObject> orders = new ArrayList<SimpleObject>();
// hacky reflection to allow core 1.9 compatibility, which doesn't support order.orderNumber
Method getOrderNumber = null;
for (Method m : new Order().getClass().getMethods()) {
if (m.getName().equals("getOrderNumber")) {
getOrderNumber = m;
break;
}
}
for (Order order : encounter.getOrders()) {
try {
orders.add(SimpleObject.create("concept", uiUtils.format(order.getConcept()), "orderNumber", // prior to 1.10 we display accession number, 1.10+ we display order number
uiUtils.format(getOrderNumber != null ? getOrderNumber.invoke(order) : order.getAccessionNumber())));
}// fail softly for now
catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return orders;
}
use of org.openmrs.Order in project openmrs-module-mirebalais by PIH.
the class RadiologyOrderNumberGeneratorComponentTest method shouldGenerateStandardOrderNumber.
@Test
public void shouldGenerateStandardOrderNumber() {
// new test order
Order order = new TestOrder();
order.setEncounter(encounterService.getEncounter(6));
order.setPatient(patientService.getPatient(7));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderType(orderService.getOrderType(2));
order.setEncounter(encounterService.getEncounter(3));
order.setDateActivated(new Date());
OrderContext orderContext = new OrderContext();
order = orderService.saveOrder(order, orderContext);
// the GP "order.nextOrderNumberSeed" is set to 1 in the standard test dataset
assertThat(order.getOrderNumber(), is("ORD-1"));
}
use of org.openmrs.Order in project openmrs-module-mirebalais by PIH.
the class RadiologyOrderNumberGeneratorComponentTest method shouldGenerateRadiologyOrderNumber.
@Test
public void shouldGenerateRadiologyOrderNumber() {
// new test order
Order order = new RadiologyOrder();
order.setEncounter(encounterService.getEncounter(6));
order.setPatient(patientService.getPatient(7));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderType(orderService.getOrderType(1001));
order.setEncounter(encounterService.getEncounter(3));
order.setDateActivated(new Date());
OrderContext orderContext = new OrderContext();
orderContext.setOrderType(orderService.getOrderType(1001));
order = orderService.saveOrder(order, orderContext);
assertThat(order.getOrderNumber(), is("0000000125"));
}
use of org.openmrs.Order in project openmrs-module-mirebalais by PIH.
the class MirthIT method testMirthChannelIntegration.
@Test
@DirtiesContext
public void testMirthChannelIntegration() throws Exception {
authenticate();
// if the test patient already exists, delete it and any existing orders
if (patientService.getPatients("2ADMMN").size() > 0) {
Patient patient = patientService.getPatients("2ADMMN").get(0);
for (Order order : orderService.getAllOrdersByPatient(patient)) {
orderService.purgeOrder(order);
}
for (Encounter encounter : encounterService.getEncountersByPatient(patient)) {
encounterService.purgeEncounter(encounter);
}
for (Visit visit : visitService.getVisitsByPatient(patient)) {
visitService.purgeVisit(visit);
}
patientService.purgePatient(patient);
}
// TODO: eventually we should make sure all the necessary fields are included here
// first create and save a patient
Patient patient = new Patient();
patient.setGender("M");
Calendar birthdate = Calendar.getInstance();
birthdate.set(2000, 2, 23);
patient.setBirthdate(birthdate.getTime());
PersonName name = new PersonName();
name.setFamilyName("Test Patient");
name.setGivenName("Mirth Integration");
patient.addName(name);
PatientIdentifier identifier = new PatientIdentifier();
identifier.setIdentifierType(emrApiProperties.getPrimaryIdentifierType());
identifier.setIdentifier("2ADMMN");
identifier.setPreferred(true);
identifier.setLocation(locationService.getLocation("Unknown Location"));
patient.addIdentifier(identifier);
// save the patient
patientService.savePatient(patient);
/**
* Commenting this out because we are not currently sending ADT information to APCS
* String result = listenForResults();
*
* System.out.println(result);
*
* // make sure the appropriate message has been delivered
* TestUtils.assertContains("MSH|^~\\&|||||||ADT^A01||P|2.3", result);
* TestUtils.assertContains("PID|||2ADMMN||Test Patient^Mirth Integration||200003230000|M", result);
*
* // now resave the patient and verify that a patient updated message is sent
* // save the patient to trigger an update event
* patientService.savePatient(patient);
*
* result = listenForResults();
*
* System.out.println(result);
*
* TestUtils.assertContains("MSH|^~\\&|||||||ADT^A08||P|2.3", result);
* TestUtils.assertContains("PID|||2ADMMN||Test Patient^Mirth Integration||200003230000|M", result);
*/
// TODO: eventually we should make sure all the necessary fields are concluded here
// TODO: specifically: sending facility, device location, universal service id, universal service id text, and modality
// ensure that there is a visit for the patient (so that the encounter visit handlers doesn't bomb)
adtService.ensureActiveVisit(patient, locationService.getLocation("Mirebalais Hospital"));
// now create and save the order for this patient
RadiologyOrder order = new RadiologyOrder();
order.setOrderType(orderService.getOrderTypeByUuid(administrationService.getGlobalProperty(RadiologyConstants.GP_RADIOLOGY_TEST_ORDER_TYPE)));
order.setPatient(patient);
// chest x-ray, one view
order.setConcept(conceptService.getConceptByUuid("fc6de1c0-1a36-11e2-a310-aa00f871a3e1"));
order.setAccessionNumber("ACCESSION NUMBER");
order.setDateActivated(new SimpleDateFormat("MM-dd-yyyy").parse("09-09-2012"));
order.setUrgency(Order.Urgency.STAT);
order.setClinicalHistory("Patient fell off horse");
order.setExamLocation(locationService.getLocation("Mirebalais Hospital"));
Encounter encounter = new Encounter();
encounter.setPatient(patient);
encounter.setEncounterDatetime(new Date());
encounter.setLocation(locationService.getLocation("Mirebalais Hospital"));
encounter.setEncounterType(encounterService.getEncounterType(1));
encounter.addOrder(order);
encounter.addProvider(emrApiProperties.getOrderingProviderEncounterRole(), Context.getProviderService().getProvider(1));
encounterService.saveEncounter(encounter);
// TODO: I've changed the configuration so that this sends the message directly to the PACS test server
// TODO: since we aren't getting messages send back from PACS yet, there is no good way to test this
/*String result = listenForResults();
TestUtils.assertContains("MSH|^~\\&||Mirebalais|||||ORM^O01||P|2.3", result);
TestUtils.assertContains("PID|||2ADMMN||Test Patient^Mirth Integration||200003230000|M", result);
TestUtils.assertContains("PV1|||Mirebalais Hospital|||||^User^Super", result);
TestUtils.assertContains("ORC|NW", result);
TestUtils
.assertContains(
"OBR|||ACCESSION NUMBER|36554-4^X-ray of chest, 1 view|||||||||||||||CR||||||||^^^^^STAT||||^Patient fell off horse|||||201209090000",
result);*/
}
Aggregations