Search in sources :

Example 16 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project openmrs-core by openmrs.

the class ORUR01Handler method createEncounter.

/**
 * This method does not call the database to create the encounter row. The encounter is only
 * created after all obs have been attached to it Creates an encounter pojo to be attached
 * later. This method does not create an encounterId
 *
 * @param msh
 * @param patient
 * @param pv1
 * @param orc
 * @return
 * @throws HL7Exception
 */
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
    // the encounter we will return
    Encounter encounter;
    // look for the encounter id in PV1-19
    CX visitNumber = pv1.getVisitNumber();
    Integer encounterId = null;
    try {
        encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
    } catch (NumberFormatException e) {
    // pass
    }
    // the database
    if (encounterId != null) {
        encounter = Context.getEncounterService().getEncounter(encounterId);
    } else {
        // if no encounter_id was passed in, this is a new
        // encounter, create the object
        encounter = new Encounter();
        Date encounterDate = getEncounterDate(pv1);
        Provider provider = getProvider(pv1);
        Location location = getLocation(pv1);
        Form form = getForm(msh);
        EncounterType encounterType = getEncounterType(msh, form);
        User enterer = getEnterer(orc);
        // Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
        encounter.setEncounterDatetime(encounterDate);
        if (unknownRole == null) {
            unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
        }
        encounter.setProvider(unknownRole, provider);
        encounter.setPatient(patient);
        encounter.setLocation(location);
        encounter.setForm(form);
        encounter.setEncounterType(encounterType);
        encounter.setCreator(enterer);
        encounter.setDateCreated(new Date());
    }
    return encounter;
}
Also used : User(org.openmrs.User) CX(ca.uhn.hl7v2.model.v25.datatype.CX) Form(org.openmrs.Form) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Provider(org.openmrs.Provider) Location(org.openmrs.Location)

Example 17 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project openmrs-core by openmrs.

the class ORUR01Handler method getForm.

/**
 * needs to find a Form based on information in MSH-21. example: 16^AMRS.ELD.FORMID
 *
 * @param msh
 * @return
 * @should pass if return value is null when uuid and id is null
 * @should pass if return value is not null when uuid or id is not null
 * @throws HL7Exception
 */
public Form getForm(MSH msh) throws HL7Exception {
    String uuid = null;
    String id = null;
    for (EI identifier : msh.getMessageProfileIdentifier()) {
        if (identifier != null && identifier.getNamespaceID() != null) {
            String identifierType = identifier.getNamespaceID().getValue();
            if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_UUID)) {
                uuid = identifier.getEntityIdentifier().getValue();
            } else if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_ID)) {
                id = identifier.getEntityIdentifier().getValue();
            } else {
                log.warn("Form identifier type of " + identifierType + " unknown to ORU R01 processor.");
            }
        }
    }
    Form form = null;
    if (uuid == null && id == null) {
        return form;
    }
    // prefer uuid over id
    if (uuid != null) {
        form = Context.getFormService().getFormByUuid(uuid);
    }
    // if uuid did not work ...
    if (id != null) {
        try {
            Integer formId = Integer.parseInt(id);
            form = Context.getFormService().getForm(formId);
        } catch (NumberFormatException e) {
            throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.parseFormId"), e);
        }
    }
    return form;
}
Also used : EI(ca.uhn.hl7v2.model.v25.datatype.EI) Form(org.openmrs.Form) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 18 with MSH

use of ca.uhn.hl7v2.model.v24.segment.MSH in project openmrs-core by openmrs.

the class ADTA28Handler method processADT_A28.

private Message processADT_A28(ADT_A05 adt) throws HL7Exception {
    // validate HL7 version
    validate(adt);
    // extract segments for convenient use below
    MSH msh = getMSH(adt);
    PID pid = getPID(adt);
    // Obtain message control id (unique ID for message from sending
    // application). Eventually avoid replaying the same message.
    String messageControlId = msh.getMessageControlID().getValue();
    log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);
    // Add creator of the patient to application
    String sendingApp = msh.getSendingApplication().getComponent(0).toString();
    log.debug("SendingApplication = " + sendingApp);
    // Search for the patient
    Integer patientId = findPatientId(pid);
    // Create new patient if the patient id doesn't exist yet
    if (patientId == null) {
        log.info("Creating new patient in response to ADT_A28 " + messageControlId);
        Patient patient = createPatient(pid, sendingApp);
        if (patient == null) {
            throw new HL7Exception("Couldn't create Patient object from PID");
        }
        Context.getPatientService().savePatient(patient);
    } else {
        log.info("Ignoring ADT_A28 message because patient (" + patientId + ") already exists.");
    }
    return adt;
}
Also used : MSH(ca.uhn.hl7v2.model.v25.segment.MSH) HL7Exception(ca.uhn.hl7v2.HL7Exception) Patient(org.openmrs.Patient) PID(ca.uhn.hl7v2.model.v25.segment.PID)

Example 19 with MSH

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

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

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