Search in sources :

Example 1 with PL

use of ca.uhn.hl7v2.model.v26.datatype.PL 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 PL

use of ca.uhn.hl7v2.model.v26.datatype.PL in project openmrs-core by openmrs.

the class HL7ServiceImpl method resolveLocationId.

/**
 * @param pl HL7 component of data type PL (person location) (see Ch 2.A.53)
 * @return internal identifier of the specified location, or null if it is not found or
 *         ambiguous
 */
@Override
@Transactional(readOnly = true)
public Integer resolveLocationId(PL pl) throws HL7Exception {
    // TODO: Get rid of hack that allows first component to be an integer
    // location.location_id
    String pointOfCare = pl.getPointOfCare().getValue();
    String facility = pl.getFacility().getUniversalID().getValue();
    // Care" as an internal openmrs location_id
    try {
        Integer locationId = Integer.valueOf(pointOfCare);
        Location l = Context.getLocationService().getLocation(locationId);
        if (l != null) {
            return l.getLocationId();
        }
    } catch (Exception ex) {
        if (facility == null) {
            // throw an exception
            throw new HL7Exception("Error trying to treat PL.pointOfCare '" + pointOfCare + "' as a location.location_id", ex);
        }
    }
    // Treat the 4th component "Facility" as location.name
    try {
        Location l = Context.getLocationService().getLocation(facility);
        if (l == null) {
            log.debug("Couldn't find a location named '" + facility + "'");
        }
        return l == null ? null : l.getLocationId();
    } catch (Exception ex) {
        log.error("Error trying to treat PL.facility '" + facility + "' as a location.name", ex);
        return null;
    }
}
Also used : HL7Exception(ca.uhn.hl7v2.HL7Exception) URISyntaxException(java.net.URISyntaxException) DAOException(org.openmrs.api.db.DAOException) FileNotFoundException(java.io.FileNotFoundException) APIException(org.openmrs.api.APIException) HL7Exception(ca.uhn.hl7v2.HL7Exception) EncodingNotSupportedException(ca.uhn.hl7v2.parser.EncodingNotSupportedException) IOException(java.io.IOException) PatientIdentifierException(org.openmrs.api.PatientIdentifierException) ApplicationException(ca.uhn.hl7v2.app.ApplicationException) Location(org.openmrs.Location) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PL

use of ca.uhn.hl7v2.model.v26.datatype.PL 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 4 with PL

use of ca.uhn.hl7v2.model.v26.datatype.PL in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationNameIsSpecified.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL)
 */
@Test
public void resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationNameIsSpecified() 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&Test Location&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.assertEquals("Resolved and given locationId shoud be equals", Integer.valueOf(1), 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 PL

use of ca.uhn.hl7v2.model.v26.datatype.PL in project openmrs-core by openmrs.

the class ORUR01Handler method getLocation.

private Location getLocation(PV1 pv1) throws HL7Exception {
    PL hl7Location = pv1.getAssignedPatientLocation();
    Integer locationId = Context.getHL7Service().resolveLocationId(hl7Location);
    if (locationId == null) {
        throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedLocation"));
    }
    return Context.getLocationService().getLocation(locationId);
}
Also used : HL7Exception(ca.uhn.hl7v2.HL7Exception) PL(ca.uhn.hl7v2.model.v25.datatype.PL)

Aggregations

PL (ca.uhn.hl7v2.model.v25.datatype.PL)4 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 Message (ca.uhn.hl7v2.model.Message)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)3 PV1 (ca.uhn.hl7v2.model.v25.segment.PV1)3 Test (org.junit.Test)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)1 Structure (ca.uhn.hl7v2.model.Structure)1 DTM (ca.uhn.hl7v2.model.v26.datatype.DTM)1 PL (ca.uhn.hl7v2.model.v26.datatype.PL)1 ORU_R01_OBSERVATION (ca.uhn.hl7v2.model.v26.group.ORU_R01_OBSERVATION)1 ORU_R01_ORDER_OBSERVATION (ca.uhn.hl7v2.model.v26.group.ORU_R01_ORDER_OBSERVATION)1 ORU_R01_PATIENT (ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT)1 ORU_R01_PATIENT_RESULT (ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT_RESULT)1 ORU_R01_VISIT (ca.uhn.hl7v2.model.v26.group.ORU_R01_VISIT)1 ORU_R01 (ca.uhn.hl7v2.model.v26.message.ORU_R01)1 MSH (ca.uhn.hl7v2.model.v26.segment.MSH)1 OBR (ca.uhn.hl7v2.model.v26.segment.OBR)1 PV1 (ca.uhn.hl7v2.model.v26.segment.PV1)1