Search in sources :

Example 1 with ORC

use of ca.uhn.hl7v2.model.v25.segment.ORC 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 2 with ORC

use of ca.uhn.hl7v2.model.v25.segment.ORC 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 ORC

use of ca.uhn.hl7v2.model.v25.segment.ORC 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 ORC

use of ca.uhn.hl7v2.model.v25.segment.ORC 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 ORC

use of ca.uhn.hl7v2.model.v25.segment.ORC in project openmrs-core by openmrs.

the class HL7ServiceTest method processHL7Message_shouldSaveHl7MessageToTheDatabase.

/**
 * @throws HL7Exception
 * @see HL7Service#processHL7Message(Message)
 */
@Test
public void processHL7Message_shouldSaveHl7MessageToTheDatabase() 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" + "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");
    Message result = hl7service.processHL7Message(message);
    Assert.assertNotNull(result);
    Concept returnVisitDateConcept = new Concept(5096);
    Calendar cal = Calendar.getInstance();
    cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0);
    List<Obs> returnVisitDateObsForPatient3 = Context.getObsService().getObservationsByPersonAndConcept(new Patient(3), returnVisitDateConcept);
    assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Message (ca.uhn.hl7v2.model.Message)60 Test (org.junit.Test)60 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)60 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)29 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)22 Patient (org.openmrs.Patient)22 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Person (org.openmrs.Person)14 Concept (org.openmrs.Concept)13 Obs (org.openmrs.Obs)13 ObsService (org.openmrs.api.ObsService)11 Encounter (org.openmrs.Encounter)10 CX (ca.uhn.hl7v2.model.v25.datatype.CX)6 Form (org.openmrs.Form)6 Provider (org.openmrs.Provider)5 XCN (ca.uhn.hl7v2.model.v25.datatype.XCN)4 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)4 PV1 (ca.uhn.hl7v2.model.v25.segment.PV1)4 Date (java.util.Date)4 Relationship (org.openmrs.Relationship)4