Search in sources :

Example 1 with ORU_R01

use of ca.uhn.hl7v2.model.v25.message.ORU_R01 in project streamsx.health by IBMStreams.

the class ObxToSplMapper method messageToModel.

@SuppressWarnings("unchecked")
public <T> Iterable<T> messageToModel(Message message) {
    ArrayList<Observation> observations = new ArrayList<Observation>();
    if (message instanceof ORU_R01) {
        ORU_R01 oruMsg = (ORU_R01) message;
        String obxTs = "";
        String obxLocation = "";
        String sendingApp = "";
        String sendingFacility = "";
        try {
            MSH msh = oruMsg.getMSH();
            sendingApp = msh.getSendingApplication().encode();
            sendingFacility = msh.getSendingFacility().encode();
            List<ORU_R01_PATIENT_RESULT> patient_RESULTAll = ((ORU_R01) message).getPATIENT_RESULTAll();
            for (ORU_R01_PATIENT_RESULT result : patient_RESULTAll) {
                ORU_R01_ORDER_OBSERVATION order_OBSERVATION = result.getORDER_OBSERVATION();
                OBR obr = order_OBSERVATION.getOBR();
                DTM ts = obr.getObservationDateTime();
                obxTs = ts.getValue();
                ORU_R01_PATIENT patient = result.getPATIENT();
                ORU_R01_VISIT visit = patient.getVISIT();
                PL location = visit.getPV1().getAssignedPatientLocation();
                obxLocation = location.encode();
                List<ORU_R01_OBSERVATION> observationAll = order_OBSERVATION.getOBSERVATIONAll();
                for (ORU_R01_OBSERVATION oru_R01_OBSERVATION : observationAll) {
                    parseOBX(observations, obxTs, obxLocation, oru_R01_OBSERVATION.getOBX(), sendingApp, sendingFacility);
                }
            }
        } catch (HL7Exception e) {
            if (TRACE.isDebugEnabled())
                TRACE.log(TraceLevel.WARN, e);
        }
        try {
            OBR obr = (OBR) oruMsg.get("OBR");
            DTM ts = obr.getObservationDateTime();
            obxTs = ts.getValue();
            Structure tmp = oruMsg.get("PV1");
            if (tmp != null) {
                PV1 pv1 = (PV1) tmp;
                PL location = pv1.getAssignedPatientLocation();
                obxLocation = location.encode();
            }
            Structure[] structures = oruMsg.getAll("OBX");
            for (Structure structure : structures) {
                parseOBX(observations, obxTs, obxLocation, (OBX) structure, sendingApp, sendingFacility);
            }
        } catch (HL7Exception e) {
            if (TRACE.isDebugEnabled())
                TRACE.log(TraceLevel.WARN, e);
        }
    }
    return (Iterable<T>) observations;
}
Also used : ORU_R01_OBSERVATION(ca.uhn.hl7v2.model.v26.group.ORU_R01_OBSERVATION) MSH(ca.uhn.hl7v2.model.v26.segment.MSH) ORU_R01_PATIENT_RESULT(ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT_RESULT) ORU_R01_VISIT(ca.uhn.hl7v2.model.v26.group.ORU_R01_VISIT) ArrayList(java.util.ArrayList) PV1(ca.uhn.hl7v2.model.v26.segment.PV1) ORU_R01_ORDER_OBSERVATION(ca.uhn.hl7v2.model.v26.group.ORU_R01_ORDER_OBSERVATION) ORU_R01_PATIENT(ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT) ORU_R01(ca.uhn.hl7v2.model.v26.message.ORU_R01) Observation(com.ibm.streamsx.health.hapi.model.Observation) HL7Exception(ca.uhn.hl7v2.HL7Exception) DTM(ca.uhn.hl7v2.model.v26.datatype.DTM) PL(ca.uhn.hl7v2.model.v26.datatype.PL) Structure(ca.uhn.hl7v2.model.Structure) OBR(ca.uhn.hl7v2.model.v26.segment.OBR)

Example 2 with ORU_R01

use of ca.uhn.hl7v2.model.v25.message.ORU_R01 in project openmrs-core by openmrs.

the class ORUR01Handler method processMessage.

/**
 * Processes an ORU R01 event message
 *
 * @should create encounter and obs from hl7 message
 * @should create basic concept proposal
 * @should create concept proposal and with obs alongside
 * @should not create problem list observation with concept proposals
 * @should append to an existing encounter
 * @should create obs group for OBRs
 * @should create obs valueCodedName
 * @should fail on empty concept proposals
 * @should fail on empty concept answers
 * @should set value_Coded matching a boolean concept for obs if the answer is 0 or 1 and
 *         Question datatype is coded
 * @should set value as boolean for obs if the answer is 0 or 1 and Question datatype is Boolean
 * @should set value_Numeric for obs if Question datatype is Numeric and the answer is either 0
 *         or 1
 * @should set value_Numeric for obs if Question datatype is Numeric
 * @should fail if question datatype is coded and a boolean is not a valid answer
 * @should fail if question datatype is neither Boolean nor numeric nor coded
 * @should create an encounter and find the provider by identifier
 * @should create an encounter and find the provider by personId
 * @should create an encounter and find the provider by uuid
 * @should create an encounter and find the provider by providerId
 * @should fail if the provider name type code is not specified and is not a personId
 * @should understand form uuid if present
 * @should prefer form uuid over id if both are present
 * @should prefer form id if uuid is not found
 * @should set complex data for obs with complex concepts
 */
@Override
public Message processMessage(Message message) throws ApplicationException {
    if (!(message instanceof ORU_R01)) {
        throw new ApplicationException(Context.getMessageSourceService().getMessage("ORUR01.error.invalidMessage"));
    }
    log.debug("Processing ORU_R01 message");
    Message response;
    try {
        ORU_R01 oru = (ORU_R01) message;
        response = processORU_R01(oru);
    } catch (ClassCastException e) {
        log.warn("Error casting " + message.getClass().getName() + " to ORU_R01", e);
        throw new ApplicationException(Context.getMessageSourceService().getMessage("ORUR01.error.invalidMessageType ", new Object[] { message.getClass().getName() }, null), e);
    } catch (HL7Exception e) {
        log.warn("Error while processing ORU_R01 message", e);
        throw new ApplicationException(Context.getMessageSourceService().getMessage("ORUR01.error.WhileProcessing"), e);
    }
    log.debug("Finished processing ORU_R01 message");
    return response;
}
Also used : ApplicationException(ca.uhn.hl7v2.app.ApplicationException) Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 3 with ORU_R01

use of ca.uhn.hl7v2.model.v25.message.ORU_R01 in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveUserId_shouldReturnUserUsingUsername.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveUserId(ca.uhn.hl7v2.model.v25.datatype.XCN)
 */
@Test
public void resolveUserId_shouldReturnUserUsingUsername() throws HL7Exception {
    HL7Service hl7service = Context.getHL7Service();
    // construct a message such that id Number at ORC is null
    Message message = hl7service.parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||1000^^^L^PN||||\r" + "ORC|RE||||||||20080226102537|^butch\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212");
    ORU_R01 oru = (ORU_R01) message;
    ORC orc = oru.getPATIENT_RESULT().getORDER_OBSERVATION().getORC();
    XCN xcn = orc.getEnteredBy(0);
    Integer userId = hl7service.resolveUserId(xcn);
    assertThat(userId, is(502));
}
Also used : ORC(ca.uhn.hl7v2.model.v25.segment.ORC) XCN(ca.uhn.hl7v2.model.v25.datatype.XCN) Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with ORU_R01

use of ca.uhn.hl7v2.model.v25.message.ORU_R01 in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveLocationId_shouldReturnNullIfLocationIdAndNameAreIncorrect.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL)
 */
@Test
public void resolveLocationId_shouldReturnNullIfLocationIdAndNameAreIncorrect() throws HL7Exception {
    executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml");
    HL7Service hl7service = Context.getHL7Service();
    Message message = hl7service.parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||1000^^^L^PN||||\r" + "PV1||O|99999^0^0^0&Unknown&0||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212");
    ORU_R01 oru = (ORU_R01) message;
    PV1 pv1 = oru.getPATIENT_RESULT().getPATIENT().getVISIT().getPV1();
    Assert.assertNotNull("PV1 parsed as null", pv1);
    PL hl7Location = pv1.getAssignedPatientLocation();
    Integer locationId = hl7service.resolveLocationId(hl7Location);
    Assert.assertNull(locationId);
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) PV1(ca.uhn.hl7v2.model.v25.segment.PV1) PL(ca.uhn.hl7v2.model.v25.datatype.PL) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with ORU_R01

use of ca.uhn.hl7v2.model.v25.message.ORU_R01 in project openmrs-core by openmrs.

the class HL7ServiceTest method getUuidFromIdentifiers_shouldFailIfMultipleDifferentUUIDsExistInIdentifiers.

/**
 * @throws HL7Exception
 * @see HL7Service#getUuidFromIdentifiers(null)
 */
@Test(expected = HL7Exception.class)
public void getUuidFromIdentifiers_shouldFailIfMultipleDifferentUUIDsExistInIdentifiers() throws HL7Exception {
    HL7Service hl7service = Context.getHL7Service();
    Message message = hl7service.parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220022^^^UUID^v4~2178037d-f86b-4f12-8d8b-be3ebc220023^^^UUID^v4||||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212");
    ORU_R01 oru = (ORU_R01) message;
    List<NK1> nk1List = new ORUR01Handler().getNK1List(oru);
    CX[] identifiers = nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers();
    hl7service.getUuidFromIdentifiers(identifiers);
    Assert.fail("should have failed");
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORUR01Handler(org.openmrs.hl7.handler.ORUR01Handler) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) NK1(ca.uhn.hl7v2.model.v25.segment.NK1) CX(ca.uhn.hl7v2.model.v25.datatype.CX) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Message (ca.uhn.hl7v2.model.Message)31 Test (org.junit.Test)31 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)31 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)30 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)22 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Patient (org.openmrs.Patient)9 Person (org.openmrs.Person)7 CX (ca.uhn.hl7v2.model.v25.datatype.CX)5 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)4 PV1 (ca.uhn.hl7v2.model.v25.segment.PV1)4 Relationship (org.openmrs.Relationship)4 RelationshipType (org.openmrs.RelationshipType)4 PersonService (org.openmrs.api.PersonService)4 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 PL (ca.uhn.hl7v2.model.v25.datatype.PL)3 XCN (ca.uhn.hl7v2.model.v25.datatype.XCN)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)2 ArrayList (java.util.ArrayList)2 Form (org.openmrs.Form)2