Search in sources :

Example 76 with PID

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

the class ORUR01HandlerTest method processMessage_shouldCreateEncounterAndObsFromHl7Message.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldCreateEncounterAndObsFromHl7Message() throws Exception {
    ObsService obsService = Context.getObsService();
    String hl7string = "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 hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    Patient patient = new Patient(3);
    // check for an encounter
    List<Encounter> encForPatient3 = Context.getEncounterService().getEncountersByPatient(patient);
    assertNotNull(encForPatient3);
    assertTrue("There should be an encounter created", encForPatient3.size() == 1);
    // check for any obs
    List<Obs> obsForPatient3 = obsService.getObservationsByPerson(patient);
    assertNotNull(obsForPatient3);
    assertTrue("There should be some obs created for #3", obsForPatient3.size() > 0);
    // check for the return visit date obs
    Concept returnVisitDateConcept = new Concept(5096);
    Calendar cal = Calendar.getInstance();
    cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0);
    Date returnVisitDate = cal.getTime();
    List<Obs> returnVisitDateObsForPatient3 = obsService.getObservationsByPersonAndConcept(patient, returnVisitDateConcept);
    assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size());
    Obs firstObs = (Obs) returnVisitDateObsForPatient3.toArray()[0];
    cal.setTime(firstObs.getValueDatetime());
    Date firstObsValueDatetime = cal.getTime();
    assertEquals("The date should be the 29th", returnVisitDate.toString(), firstObsValueDatetime.toString());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ObsService(org.openmrs.api.ObsService) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 77 with PID

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

the class ORUR01HandlerTest method processMessage_shouldFailIfQuestionDatatypeIsCodedAndABooleanIsNotAValidAnswer.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test(expected = ApplicationException.class)
public void processMessage_shouldFailIfQuestionDatatypeIsCodedAndABooleanIsNotAValidAnswer() 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);
    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|2|NM|4^CIVIL STATUS^99DCT||1|||||||||20080206";
    Assert.assertEquals("Coded", Context.getConceptService().getConcept(4).getDatatype().getName());
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
}
Also used : Message(ca.uhn.hl7v2.model.Message) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 78 with PID

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

the class ORUR01HandlerTest method processMessage_shouldNotCreateProblemListObservationWithConceptProposals.

/**
 * Tests that a ConceptProposal row can be written by the processor
 *
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldNotCreateProblemListObservationWithConceptProposals() throws Exception {
    ObsService obsService = Context.getObsService();
    ConceptService conceptService = Context.getConceptService();
    EncounterService encService = Context.getEncounterService();
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080630094800||ORU^R01|kgWdFt0SVwwClOfJm3pe|P|2.5|1||||||||15^AMRS.ELD.FORMID\r" + "PID|||3^^^^~d3811480^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20080208|||||||V\r" + "ORC|RE||||||||20080208000000|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBR|1|||1284^PROBLEM LIST^99DCT\r" + "OBX|1|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^SEVERO DOLOR DE CABEZA^99DCT|||||||||20080208";
    Message hl7message = parser.parse(hl7String);
    router.processMessage(hl7message);
    Patient patient = new Patient(3);
    // check for any obs
    assertEquals("There should not be any obs created for #3", 0, obsService.getObservationsByPerson(patient).size());
    // check for a new encounter
    assertEquals("There should be 1 new encounter created for #3", 1, encService.getEncountersByPatient(patient).size());
    // check for the proposed concept
    List<ConceptProposal> proposedConcepts = conceptService.getConceptProposals("SEVERO DOLOR DE CABEZA");
    assertEquals("There should be a proposed concept by this name", 1, proposedConcepts.size());
    assertEquals(encService.getEncountersByPatient(patient).get(0), proposedConcepts.get(0).getEncounter());
}
Also used : Message(ca.uhn.hl7v2.model.Message) ConceptProposal(org.openmrs.ConceptProposal) Patient(org.openmrs.Patient) ObsService(org.openmrs.api.ObsService) ConceptService(org.openmrs.api.ConceptService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 79 with PID

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

the class ORUR01HandlerTest method parseObs_shouldAddMultipleCommentsForAnObservationAsOneComment.

/**
 * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String)
 */
@Test
public void parseObs_shouldAddMultipleCommentsForAnObservationAsOneComment() throws Exception {
    ObsService os = Context.getObsService();
    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|5497^CD4, BY FACS^99DCT||1|||||||||20080206\r" + "NTE|1|L|This is a comment\r" + "NTE|2|L|that spans two lines\r" + "OBX|2|NM|5497^CD4, BY FACS^99DCT||2|||||||||20080206";
    // the expected question for the obs in the hl7 message has to be
    // numeric
    Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    // get the new observation with a not-null comment; not interested in
    // the other one
    Obs newObservation = null;
    int thisIndex = 0;
    while (newObservation == null && thisIndex < newList.size()) {
        Obs newObs = newList.get(thisIndex++);
        if (!oldList.contains(newObs) && !newObs.isObsGrouping() && newObs.getComment() != null)
            newObservation = newObs;
    }
    Assert.assertEquals("This is a comment that spans two lines", newObservation.getComment());
}
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) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 80 with PID

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

the class ORUR01HandlerTest method processMessage_shouldCreateBasicConceptProposal.

/**
 * Should create a concept proposal because of the key string in the message
 *
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldCreateBasicConceptProposal() throws Exception {
    // remember initial occurrence of proposal's text in the model
    int initialOccurrences = Context.getConceptService().getConceptProposals("PELVIC MASS").size();
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080924022306||ORU^R01|Z185fTD0YozQ5kvQZD7i|P|2.5|1||||||||3^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Joe^S^Mith||\r" + "PV1||O|1^Unknown Module 2||||1^Joe (1-1)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080219085345|1^Joe\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|18|DT|5096^RETURN VISIT DATE^99DCT||20080506|||||||||20080212\r" + "OBR|19|||1284^PROBLEM LIST^99DCT\r" + "OBX|1|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^PELVIC MASS^99DCT|||||||||20080212";
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    // make sure that the proposal was added
    Assert.assertEquals("Processing of the HL7 message did not result in the new proposal being added to the model", initialOccurrences + 1, Context.getConceptService().getConceptProposals("PELVIC MASS").size());
}
Also used : Message(ca.uhn.hl7v2.model.Message) 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 Patient (org.openmrs.Patient)26 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)22 Person (org.openmrs.Person)16 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 MSH (ca.uhn.hl7v2.model.v24.segment.MSH)14 Concept (org.openmrs.Concept)13 Obs (org.openmrs.Obs)13 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 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)10 Encounter (org.openmrs.Encounter)9 ADT_A01 (ca.uhn.hl7v2.model.v24.message.ADT_A01)8 PID (ca.uhn.hl7v2.model.v24.segment.PID)8 CX (ca.uhn.hl7v2.model.v25.datatype.CX)8 HL7Exception (ca.uhn.hl7v2.HL7Exception)7