Search in sources :

Example 16 with DT

use of ca.uhn.hl7v2.model.v25.datatype.DT in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationNameIsSpecified.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL)
 */
@Test
public void resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationNameIsSpecified() 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&Test Location&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.assertEquals("Resolved and given locationId shoud be equals", Integer.valueOf(1), 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 17 with DT

use of ca.uhn.hl7v2.model.v25.datatype.DT in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldCreateObsGroupForOBRs.

/**
 * This method checks that obs grouping is happening correctly when processing an ORUR01
 *
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldCreateObsGroupForOBRs() throws Exception {
    ObsService obsService = Context.getObsService();
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226103553||ORU^R01|OD9PWqcD9g0NKn81rvSD|P|2.5|1||||||||66^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John^Doe^||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080205|||||||V\r" + "ORC|RE||||||||20080226103428|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|DT|1592^MISSED RETURNED VISIT DATE^99DCT||20080201|||||||||20080205\r" + "OBR|2|||1726^FOLLOW-UP ACTION^99DCT\r" + "OBX|1|CWE|1558^PATIENT CONTACT METHOD^99DCT|1|1555^PHONE^99DCT|||||||||20080205\r" + "OBX|2|NM|1553^NUMBER OF ATTEMPTS^99DCT|1|1|||||||||20080205\r" + "OBX|3|NM|1554^SUCCESSFUL^99DCT|1|1|||||||||20080205";
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    Patient patient = new Patient(3);
    Context.clearSession();
    // check for any obs
    List<Obs> obsForPatient2 = obsService.getObservationsByPerson(patient);
    assertNotNull(obsForPatient2);
    assertTrue("There should be some obs created for #3", obsForPatient2.size() > 0);
    // check for the missed return visit date obs
    Concept returnVisitDateConcept = new Concept(1592);
    Calendar cal = new GregorianCalendar();
    cal.set(2008, Calendar.FEBRUARY, 1, 0, 0, 0);
    Date returnVisitDate = cal.getTime();
    List<Obs> returnVisitDateObsForPatient2 = obsService.getObservationsByPersonAndConcept(patient, returnVisitDateConcept);
    assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient2.size());
    Obs firstObs = (Obs) returnVisitDateObsForPatient2.toArray()[0];
    cal.setTime(firstObs.getValueDatetime());
    cal.clear(Calendar.HOUR);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);
    assertEquals("The date should be the 1st", returnVisitDate.toString(), cal.getTime().toString());
    // check for the grouped obs
    Concept contactMethod = new Concept(1558);
    Concept phoneContact = Context.getConceptService().getConcept(1555);
    List<Obs> contactMethodObsForPatient2 = obsService.getObservationsByPersonAndConcept(patient, contactMethod);
    assertEquals("There should be a contact method", 1, contactMethodObsForPatient2.size());
    Obs firstContactMethodObs = (Obs) contactMethodObsForPatient2.toArray()[0];
    assertEquals("The contact method should be phone", phoneContact, firstContactMethodObs.getValueCoded());
    // check that there is a group id
    Obs obsGroup = firstContactMethodObs.getObsGroup();
    assertNotNull("Their should be a grouping obs", obsGroup);
    assertNotNull("Their should be an associated encounter", firstContactMethodObs.getEncounter());
    // check that the obs that are grouped have the same group id
    List<Integer> groupedConceptIds = new ArrayList<>();
    groupedConceptIds.add(1558);
    groupedConceptIds.add(1553);
    groupedConceptIds.add(1554);
    // total obs should be 5
    assertEquals(5, obsForPatient2.size());
    int groupedObsCount = 0;
    for (Obs obs : obsForPatient2) {
        if (groupedConceptIds.contains(obs.getConcept().getConceptId())) {
            groupedObsCount += 1;
            assertEquals("All of the parent groups should match", obsGroup, obs.getObsGroup());
        }
    }
    // the number of obs that were grouped
    assertEquals(3, groupedObsCount);
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) ObsService(org.openmrs.api.ObsService) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 18 with DT

use of ca.uhn.hl7v2.model.v25.datatype.DT in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationIdIsSpecified.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL)
 */
@Test
public void resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationIdIsSpecified() 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|1^0^0^0&Test Location&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.assertEquals("Resolved and given locationId shoud be equals", Integer.valueOf(1), 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 19 with DT

use of ca.uhn.hl7v2.model.v25.datatype.DT in project openmrs-core by openmrs.

the class HL7ServiceTest method getPersonFromNK1_shouldReturnAPatientIfValidPatientIdentifiersExist.

/**
 * @throws HL7Exception
 * @see HL7Service#createPersonFromNK1(NK1)
 */
@Test
public void getPersonFromNK1_shouldReturnAPatientIfValidPatientIdentifiersExist() 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|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220029^^^UUID^v4~9-1^^^Test Identifier Type^PT||||\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");
    ORU_R01 oru = (ORU_R01) message;
    List<NK1> nk1List = new ORUR01Handler().getNK1List(oru);
    Person result = hl7service.createPersonFromNK1(nk1List.get(0));
    Assert.assertNotNull("should have returned something", result);
    Assert.assertTrue("should have returned a Patient", result instanceof Patient);
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORUR01Handler(org.openmrs.hl7.handler.ORUR01Handler) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) NK1(ca.uhn.hl7v2.model.v25.segment.NK1) Patient(org.openmrs.Patient) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with DT

use of ca.uhn.hl7v2.model.v25.datatype.DT in project openmrs-core by openmrs.

the class HL7ServiceTest method resolvePersonFromIdentifiers_shouldFindAPersonBasedOnTheInternalPersonID.

/**
 * @throws HL7Exception
 * @see HL7Service#resolvePersonFromIdentifiers(null)
 */
@Test
public void resolvePersonFromIdentifiers_shouldFindAPersonBasedOnTheInternalPersonID() 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|||||||||||||||||2^^^L^PN||||\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");
    ORU_R01 oru = (ORU_R01) message;
    List<NK1> nk1List = new ORUR01Handler().getNK1List(oru);
    Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size());
    Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers());
    Assert.assertNotNull("should have found a person", result);
    Assert.assertEquals("found the wrong person", 2, result.getId().intValue());
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORUR01Handler(org.openmrs.hl7.handler.ORUR01Handler) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) NK1(ca.uhn.hl7v2.model.v25.segment.NK1) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Message (ca.uhn.hl7v2.model.Message)28 Test (org.junit.Test)28 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)28 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)21 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)15 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Person (org.openmrs.Person)6 CX (ca.uhn.hl7v2.model.v25.datatype.CX)5 Concept (org.openmrs.Concept)4 Obs (org.openmrs.Obs)4 Patient (org.openmrs.Patient)4 PL (ca.uhn.hl7v2.model.v25.datatype.PL)3 XCN (ca.uhn.hl7v2.model.v25.datatype.XCN)3 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)3 PV1 (ca.uhn.hl7v2.model.v25.segment.PV1)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 HL7Exception (ca.uhn.hl7v2.HL7Exception)2 GregorianCalendar (java.util.GregorianCalendar)2 Application (ca.uhn.hl7v2.app.Application)1