Search in sources :

Example 1 with XCN

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

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

the class ORUR01Handler method getEnterer.

private User getEnterer(ORC orc) throws HL7Exception {
    XCN hl7Enterer = orc.getEnteredBy(0);
    Integer entererId = Context.getHL7Service().resolveUserId(hl7Enterer);
    if (entererId == null) {
        throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedEnterer"));
    }
    User enterer = new User();
    enterer.setUserId(entererId);
    return enterer;
}
Also used : XCN(ca.uhn.hl7v2.model.v25.datatype.XCN) User(org.openmrs.User) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 3 with XCN

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

the class ORUR01Handler method getProvider.

private Provider getProvider(PV1 pv1) throws HL7Exception {
    XCN hl7Provider = pv1.getAttendingDoctor(0);
    Provider provider = null;
    String id = hl7Provider.getIDNumber().getValue();
    String assignAuth = hl7Provider.getAssigningAuthority().getUniversalID().getValue();
    String type = hl7Provider.getAssigningAuthority().getUniversalIDType().getValue();
    String errorMessage;
    if (StringUtils.hasText(id)) {
        String specificErrorMsg = "";
        if (OpenmrsUtil.nullSafeEquals("L", type)) {
            if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_ID.equalsIgnoreCase(assignAuth)) {
                try {
                    provider = Context.getProviderService().getProvider(Integer.valueOf(id));
                } catch (NumberFormatException e) {
                // ignore
                }
                specificErrorMsg = "with provider Id";
            } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER.equalsIgnoreCase(assignAuth)) {
                provider = Context.getProviderService().getProviderByIdentifier(id);
                specificErrorMsg = "with provider identifier";
            } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID.equalsIgnoreCase(assignAuth)) {
                provider = Context.getProviderService().getProviderByUuid(id);
                specificErrorMsg = "with provider uuid";
            }
        } else {
            try {
                Person person = Context.getPersonService().getPerson(Integer.valueOf(id));
                Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
                if (!providers.isEmpty()) {
                    provider = providers.iterator().next();
                }
            } catch (NumberFormatException e) {
            // ignore
            }
            specificErrorMsg = "associated to a person with person id";
        }
        errorMessage = "Could not resolve provider " + specificErrorMsg + ":" + id;
    } else {
        errorMessage = "No unique identifier was found for the provider";
    }
    if (provider == null) {
        throw new HL7Exception(errorMessage);
    }
    return provider;
}
Also used : XCN(ca.uhn.hl7v2.model.v25.datatype.XCN) HL7Exception(ca.uhn.hl7v2.HL7Exception) Person(org.openmrs.Person) Provider(org.openmrs.Provider)

Example 4 with XCN

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

the class HL7ServiceImpl method resolveUserId.

/**
 * @param xcn HL7 component of data type XCN (extended composite ID number and name for persons)
 *            (see HL7 2.5 manual Ch.2A.86)
 * @return Internal ID # of the specified user, or null if that user can't be found or is
 *         ambiguous
 */
@Override
@Transactional(readOnly = true)
public Integer resolveUserId(XCN xcn) throws HL7Exception {
    String idNumber = xcn.getIDNumber().getValue();
    String familyName = xcn.getFamilyName().getSurname().getValue();
    String givenName = xcn.getGivenName().getValue();
    if (idNumber != null && idNumber.length() > 0) {
        try {
            Integer userId = Integer.valueOf(idNumber);
            User user = Context.getUserService().getUser(userId);
            return user.getUserId();
        } catch (Exception e) {
            log.error("Invalid user ID '" + idNumber + "'", e);
            return null;
        }
    } else {
        try {
            List<User> users = Context.getUserService().getUsersByName(givenName, familyName, true);
            if (users.size() == 1) {
                return users.get(0).getUserId();
            } else if (users.size() > 1) {
                // Return null if that user ambiguous
                log.error(getFindingUserErrorMessage(idNumber, familyName, givenName) + ": Found " + users.size() + " ambiguous users.");
                return null;
            } else {
                // legacy behavior is looking up by username
                StringBuilder username = new StringBuilder();
                if (familyName != null) {
                    username.append(familyName);
                }
                if (givenName != null) {
                    if (username.length() > 0) {
                        // separate names with a space
                        username.append(" ");
                    }
                    username.append(givenName);
                }
                User user = Context.getUserService().getUserByUsername(username.toString());
                if (user == null) {
                    log.error(getFindingUserErrorMessage(idNumber, familyName, givenName) + ": User not found");
                    return null;
                }
                return user.getUserId();
            }
        } catch (Exception e) {
            log.error(getFindingUserErrorMessage(idNumber, familyName, givenName), e);
            return null;
        }
    }
}
Also used : User(org.openmrs.User) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with XCN

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

Aggregations

HL7Exception (ca.uhn.hl7v2.HL7Exception)5 XCN (ca.uhn.hl7v2.model.v25.datatype.XCN)5 Message (ca.uhn.hl7v2.model.Message)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)3 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)3 Test (org.junit.Test)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)2 EncodingNotSupportedException (ca.uhn.hl7v2.parser.EncodingNotSupportedException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Person (org.openmrs.Person)2 User (org.openmrs.User)2 APIException (org.openmrs.api.APIException)2 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)2 DAOException (org.openmrs.api.db.DAOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CX (ca.uhn.hl7v2.model.v26.datatype.CX)1 XCN (ca.uhn.hl7v2.model.v26.datatype.XCN)1