Search in sources :

Example 21 with OBR

use of ca.uhn.hl7v2.model.v26.segment.OBR in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processNK1_shouldFailIfTheCodingSystemIsNot99REL.

/**
 * @see ORUR01Handler#processNK1(Patient,NK1)
 */
@Test(expected = HL7Exception.class)
public void processNK1_shouldFailIfTheCodingSystemIsNot99REL() throws Exception {
    // process a message with an invalid coding system
    // the patient that is the focus of
    Patient patient = new Patient(3);
    // this hl7 message
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^ACKFOO||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
    ORUR01Handler oruHandler = new ORUR01Handler();
    Message hl7message = parser.parse(hl7String);
    ORU_R01 oru = (ORU_R01) hl7message;
    List<NK1> nk1List = oruHandler.getNK1List(oru);
    for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1);
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) NK1(ca.uhn.hl7v2.model.v25.segment.NK1) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with OBR

use of ca.uhn.hl7v2.model.v26.segment.OBR in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldUnderstandFormUuidIfPresent.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldUnderstandFormUuidIfPresent() throws Exception {
    // save original encounter count
    List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(new Patient(3));
    Integer originalEncounters = encounters.size();
    // process message
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||d9218f76-6c39-45f4-8efa-4c5c6c199f50^AMRS.ELD.FORMUUID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714";
    Message hl7message = parser.parse(hl7String);
    router.processMessage(hl7message);
    // make sure an encounter was added
    encounters = Context.getEncounterService().getEncountersByPatient(new Patient(3));
    Assert.assertEquals(originalEncounters + 1, encounters.size());
    // get last encounter
    Encounter enc = encounters.get(encounters.size() - 1);
    // check the form uuid
    Form form = enc.getForm();
    Assert.assertEquals("d9218f76-6c39-45f4-8efa-4c5c6c199f50", form.getUuid());
}
Also used : Message(ca.uhn.hl7v2.model.Message) Form(org.openmrs.Form) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with OBR

use of ca.uhn.hl7v2.model.v26.segment.OBR in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldSetValueAsBooleanForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsBoolean.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldSetValueAsBooleanForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsBoolean() throws Exception {
    GlobalProperty trueConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_TRUE_CONCEPT, "7", "Concept id of the concept defining the TRUE boolean concept");
    GlobalProperty falseConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FALSE_CONCEPT, "8", "Concept id of the concept defining the TRUE boolean concept");
    Context.getAdministrationService().saveGlobalProperty(trueConceptGlobalProperty);
    Context.getAdministrationService().saveGlobalProperty(falseConceptGlobalProperty);
    ObsService os = Context.getObsService();
    Assert.assertNull(os.getObs(17));
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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|18^FOOD ASSISTANCE^99DCT||0|||||||||20080206";
    // the expected question for the obs in the hl7 message has to be
    // Boolean
    Assert.assertEquals("Boolean", Context.getConceptService().getConcept(18).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && !newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals(false, newObservation.getValueBoolean());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) ObsService(org.openmrs.api.ObsService) Person(org.openmrs.Person) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with OBR

use of ca.uhn.hl7v2.model.v26.segment.OBR in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldAppendToAnExistingEncounter.

/**
 * If an hl7 message contains a "visit number" pv1-19 value, then assume its an encounter_id and
 * that information in the hl7 message should be appended to that encounter.
 *
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldAppendToAnExistingEncounter() throws Exception {
    // there should be an encounter with encounter_id == 3 for this test
    // to append to
    assertNotNull(Context.getEncounterService().getEncounter(3));
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080902151831||ORU^R01|yow3LEP6bycnLfoPyI31|P|2.5|1||||||||3^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Indakasi^Testarius^Ambote||\r" + "PV1||O|1||||1^Super User (1-8)||||||||||||3|||||||||||||||||||||||||20080831|||||||V\r" + "ORC|RE||||||||20080902150000|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|10^CD4 COUNT^99DCT||250|||||||||20080831";
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    Patient patient = new Patient(7);
    Concept question = new Concept(10);
    // check that the CD4 count obs in the hl7 message was appended to the
    // encounter with encounter_id == 3 and _not_ put into a new encounter
    // that has encounter_id == (autoincremented value)
    List<Obs> obsForPatient = Context.getObsService().getObservationsByPersonAndConcept(patient, question);
    // there should be 1 obs now for
    assertEquals(1, obsForPatient.size());
    // this patient
    assertEquals(3, obsForPatient.get(0).getEncounter().getId().intValue());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with OBR

use of ca.uhn.hl7v2.model.v26.segment.OBR in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processORU_R01_shouldProcessMultipleNK1Segments.

/**
 * @see ORUR01Handler#processORU_R01(ORU_R01)
 */
@Test
public void processORU_R01_shouldProcessMultipleNK1Segments() throws Exception {
    PersonService personService = Context.getPersonService();
    // the patient that is the focus of
    Patient patient = new Patient(3);
    // this hl7 message
    // the patient that is related to
    Patient relative = new Patient(2);
    // patientA
    // create a relationship in the database
    Relationship newRel = new Relationship();
    newRel.setRelationshipType(new RelationshipType(3));
    newRel.setPersonA(relative);
    newRel.setPersonB(patient);
    personService.saveRelationship(newRel);
    // verify relationship exists
    Assert.assertEquals(1, personService.getRelationships(relative, patient, new RelationshipType(3)).size());
    // process a new message with multiple NK1 segments
    // this one defines patientB as patientA's Sibling and Patient
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170333||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|2A^Sibling^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "NK1|2|Jones^Jane^Lee^^RN|1B^Patient^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
    Message hl7message = parser.parse(hl7String);
    router.processMessage(hl7message);
    // verify existing relationship
    List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3));
    Assert.assertTrue("existing relationship was not retained", !rels.isEmpty() && rels.size() == 1);
    // verify first new relationship
    rels = personService.getRelationships(patient, relative, new RelationshipType(2));
    Assert.assertTrue("first new relationship was not created", !rels.isEmpty() && rels.size() == 1);
    // verify second new relationship
    rels = personService.getRelationships(patient, relative, new RelationshipType(1));
    Assert.assertTrue("second new relationship was not created", !rels.isEmpty() && rels.size() == 1);
}
Also used : Message(ca.uhn.hl7v2.model.Message) PersonService(org.openmrs.api.PersonService) Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) 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 Concept (org.openmrs.Concept)14 Obs (org.openmrs.Obs)14 Person (org.openmrs.Person)14 ObsService (org.openmrs.api.ObsService)11 Encounter (org.openmrs.Encounter)9 CX (ca.uhn.hl7v2.model.v25.datatype.CX)5 Form (org.openmrs.Form)5 RelationshipType (org.openmrs.RelationshipType)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)4 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)4 PV1 (ca.uhn.hl7v2.model.v25.segment.PV1)4 Date (java.util.Date)4 Provider (org.openmrs.Provider)4