Search in sources :

Example 81 with Order

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());
    }
}
Also used : Order(org.openmrs.Order) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) User(org.openmrs.User) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 82 with Order

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;
}
Also used : Order(org.openmrs.Order) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 83 with Order

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"));
}
Also used : RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Date(java.util.Date) OrderContext(org.openmrs.api.OrderContext) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 84 with Order

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"));
}
Also used : RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) Date(java.util.Date) OrderContext(org.openmrs.api.OrderContext) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 85 with Order

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);*/
}
Also used : RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) Order(org.openmrs.Order) PersonName(org.openmrs.PersonName) Visit(org.openmrs.Visit) Calendar(java.util.Calendar) RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) SimpleDateFormat(java.text.SimpleDateFormat) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9