Search in sources :

Example 11 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project camel by apache.

the class HL7RouteTest method createADT01Message.

private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();
    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");
    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);
    return adt;
}
Also used : MSH(ca.uhn.hl7v2.model.v24.segment.MSH) PID(ca.uhn.hl7v2.model.v24.segment.PID) ADT_A01(ca.uhn.hl7v2.model.v24.message.ADT_A01)

Example 12 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project camel by apache.

the class HL7XmlDataFormatTest method testUnmarshalOkXml.

@Test
public void testUnmarshalOkXml() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    mock.expectedMessageCount(1);
    String body = createHL7AsString();
    Message msg = hl7.getParser().parse(body);
    String xml = hl7.getParser().encode(msg, "XML");
    assertTrue(xml.contains("<ORM_O01"));
    template.sendBody("direct:unmarshalOkXml", xml);
    assertMockEndpointsSatisfied();
    Message received = mock.getReceivedExchanges().get(0).getIn().getMandatoryBody(Message.class);
    assertEquals("O01", new Terser(received).get("MSH-9-2"));
}
Also used : Message(ca.uhn.hl7v2.model.Message) Terser(ca.uhn.hl7v2.util.Terser) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 13 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project pentaho-kettle by pentaho.

the class HL7MLLPInput method execute.

public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    try {
        String serverName = environmentSubstitute(server);
        int portNumber = Integer.parseInt(environmentSubstitute(port));
        String messageVariable = environmentSubstitute(messageVariableName);
        String messageTypeVariable = environmentSubstitute(messageTypeVariableName);
        String versionVariable = environmentSubstitute(versionVariableName);
        MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
        if (entry.getJobListener() != null) {
            parentJob.addJobListener(entry.getJobListener());
        }
        MLLPTransport transport = entry.getTransport();
        // 
        synchronized (transport) {
            Transportable transportable = transport.doReceive();
            String message = transportable.getMessage();
            logDetailed("Received message: " + message);
            parentJob.setVariable(messageVariable, message);
            // Parse the message and extract the control ID.
            // 
            Parser parser = new GenericParser();
            ValidationContext validationContext = new NoValidation();
            parser.setValidationContext(validationContext);
            Message msg = parser.parse(message);
            Structure structure = msg.get("MSH");
            String messageType = null;
            String version = msg.getVersion();
            if (structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v21.segment.MSH) structure).getMESSAGETYPE().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v22.segment.MSH) structure).getMessageType().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v23.segment.MSH) structure).getMessageType().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v231.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v24.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v25.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v251.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v26.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else {
                logError("This job entry does not support the HL7 dialect used. Found MSH class: " + structure.getClass().getName());
            }
            if (!Utils.isEmpty(messageTypeVariable)) {
                parentJob.setVariable(messageTypeVariable, messageType);
            }
            if (!Utils.isEmpty(versionVariable)) {
                parentJob.setVariable(versionVariable, version);
            }
        }
        // All went well..
        // 
        result.setNrErrors(0);
        result.setResult(true);
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
        result.setNrErrors(1);
        result.setResult(false);
    }
    return result;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Result(org.pentaho.di.core.Result) MLLPSocketCacheEntry(org.pentaho.di.trans.steps.hl7input.common.MLLPSocketCacheEntry) Structure(ca.uhn.hl7v2.model.Structure) Transportable(ca.uhn.hl7v2.protocol.Transportable) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation)

Example 14 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project streamsx.health by IBMStreams.

the class AdtToModelMapper method messageToModel.

@SuppressWarnings("unchecked")
public <T> Iterable<T> messageToModel(Message message) {
    ArrayList<ADTEvent> adtEvents = new ArrayList<ADTEvent>();
    if (message instanceof ADT_AXX) {
        ADT_AXX superMsg = (ADT_AXX) message;
        MessageInfo msg = new MessageInfo();
        Patient patient = new Patient();
        try {
            MSH header = superMsg.getMSH();
            msg.setSendingApp(header.getSendingApplication().encode());
            msg.setSendingFacility(header.getSendingFacility().encode());
            msg.setReceivingApp(header.getReceivingApplication().encode());
            msg.setReceivingFacility(header.getReceivingFacility().encode());
            msg.setMessageTs(header.getDateTimeOfMessage().encode());
            msg.setMessageType(header.getMessageType().encode());
            PID pid = superMsg.getPID();
            patient.setId(pid.getPatientID().encode());
            XPN[] patientNames = pid.getPatientName();
            for (XPN name : patientNames) {
                if (patient.getName().equals(IInjestServicesConstants.EMPTYSTR)) {
                    patient.setName(getPatientFullName(name));
                } else {
                    patient.addAlternateName(getPatientFullName(name));
                }
            }
            patient.setGender(pid.getAdministrativeSex().encode());
            patient.setDateOfBirth(pid.getDateTimeOfBirth().encode());
            CX[] ids = pid.getAlternatePatientIDPID();
            if (ids.length > 0) {
                for (CX cx : ids) {
                    patient.addAlternativeId(cx.encode());
                }
            }
            EventDetails evt = new EventDetails();
            EVN evn = superMsg.getEVN();
            evt.setEventType(evn.getEventTypeCode().encode());
            evt.setEventTs(evn.getEvn6_EventOccurred().encode());
            evt.setRecordTs(evn.getEvn2_RecordedDateTime().encode());
            PV1 pv1 = superMsg.getPV1();
            PatientVisit patientVisit = new PatientVisit();
            patientVisit.setPatientClass(pv1.getPatientClass().encode());
            patientVisit.setLocation(pv1.getAssignedPatientLocation().encode());
            patientVisit.setPriorLocation(pv1.getPriorPatientLocation().encode());
            patientVisit.setVisitNumber(pv1.getVisitNumber().encode());
            patient.setStatus(pv1.getBedStatus().encode());
            XCN[] doctors = pv1.getAttendingDoctor();
            for (XCN xcn : doctors) {
                String id = xcn.getIDNumber().encode();
                String name = xcn.getFamilyName().encode() + " " + xcn.getGivenName().encode();
                Clinician clinician = new Clinician();
                clinician.setId(id);
                clinician.setName(name);
                patientVisit.addAttendingDoctor(clinician);
            }
            doctors = pv1.getConsultingDoctor();
            for (XCN xcn : doctors) {
                String id = xcn.getIDNumber().encode();
                String name = xcn.getFamilyName().encode() + " " + xcn.getGivenName().encode();
                Clinician clinician = new Clinician();
                clinician.setId(id);
                clinician.setName(name);
                patientVisit.addConsultingDoctor(clinician);
            }
            ADTEvent adtEvent = new ADTEvent();
            adtEvent.setEvt(evt);
            adtEvent.setPatient(patient);
            adtEvent.setMsg(msg);
            adtEvent.setPv(patientVisit);
            adtEvents.add(adtEvent);
        } catch (HL7Exception e) {
            TRACE.error("Unable to parse HL7 message", e);
        }
    }
    return (Iterable<T>) adtEvents;
}
Also used : PatientVisit(com.ibm.streamsx.health.ingest.types.model.PatientVisit) XCN(ca.uhn.hl7v2.model.v26.datatype.XCN) MSH(ca.uhn.hl7v2.model.v26.segment.MSH) ADTEvent(com.ibm.streamsx.health.ingest.types.model.ADTEvent) ArrayList(java.util.ArrayList) Patient(com.ibm.streamsx.health.ingest.types.model.Patient) PID(ca.uhn.hl7v2.model.v26.segment.PID) PV1(ca.uhn.hl7v2.model.v26.segment.PV1) MessageInfo(com.ibm.streamsx.health.ingest.types.model.MessageInfo) EventDetails(com.ibm.streamsx.health.ingest.types.model.EventDetails) Clinician(com.ibm.streamsx.health.ingest.types.model.Clinician) CX(ca.uhn.hl7v2.model.v26.datatype.CX) XPN(ca.uhn.hl7v2.model.v26.datatype.XPN) HL7Exception(ca.uhn.hl7v2.HL7Exception) ADT_AXX(ca.uhn.hl7v2.model.v26.message.ADT_AXX) EVN(ca.uhn.hl7v2.model.v26.segment.EVN)

Example 15 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH 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)

Aggregations

Message (ca.uhn.hl7v2.model.Message)68 Test (org.junit.Test)64 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)60 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)29 Patient (org.openmrs.Patient)23 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)22 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 MSH (ca.uhn.hl7v2.model.v24.segment.MSH)14 Person (org.openmrs.Person)14 Concept (org.openmrs.Concept)13 Obs (org.openmrs.Obs)13 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)12 ObsService (org.openmrs.api.ObsService)11 ADR_A19 (ca.uhn.hl7v2.model.v24.message.ADR_A19)10 MSA (ca.uhn.hl7v2.model.v24.segment.MSA)10 Encounter (org.openmrs.Encounter)10 Form (org.openmrs.Form)7 HL7Exception (ca.uhn.hl7v2.HL7Exception)6 CX (ca.uhn.hl7v2.model.v25.datatype.CX)6 ArrayList (java.util.ArrayList)5