Search in sources :

Example 6 with XCN

use of ca.uhn.hl7v2.model.v26.datatype.XCN in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveUserId_shouldReturnNullForAmbiguousUsersUsingFirstAndLastNameGivenUserIDIsNull.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveUserId(ca.uhn.hl7v2.model.v25.datatype.XCN)
 */
@Test
public void resolveUserId_shouldReturnNullForAmbiguousUsersUsingFirstAndLastNameGivenUserIDIsNull() 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" + "PV1||O|99999^0^0^0&Unknown&0||||^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|^User^Super\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);
    // userId should be null since there exist two ambiguous users that has givename=Super and lastname=User.
    Integer userId = hl7service.resolveUserId(xcn);
    Assert.assertNull(userId);
}
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 7 with XCN

use of ca.uhn.hl7v2.model.v26.datatype.XCN in project openmrs-core by openmrs.

the class HL7ServiceTest method resolveUserId_shouldReturnUserUsingFirstAndLastNameGivenUserIDIsNull.

/**
 * @throws HL7Exception
 * @see HL7Service#resolveUserId(ca.uhn.hl7v2.model.v25.datatype.XCN)
 */
@Test
public void resolveUserId_shouldReturnUserUsingFirstAndLastNameGivenUserIDIsNull() 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|^Otterbourg^Bruno\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(501));
}
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 8 with XCN

use of ca.uhn.hl7v2.model.v26.datatype.XCN in project openmrs-core by openmrs.

the class HL7ServiceImpl method resolvePersonId.

/**
 * @see org.openmrs.hl7.HL7Service#resolvePersonId(ca.uhn.hl7v2.model.v25.datatype.XCN)
 */
@Override
@Transactional(readOnly = true)
public Integer resolvePersonId(XCN xcn) throws HL7Exception {
    String idNumber = xcn.getIDNumber().getValue();
    String familyName = xcn.getFamilyName().getSurname().getValue();
    String givenName = xcn.getGivenName().getValue();
    if (idNumber != null && idNumber.length() > 0) {
        try {
            Person person = Context.getPersonService().getPerson(Integer.valueOf(idNumber));
            return person.getPersonId();
        } catch (Exception e) {
            log.error("Invalid person ID '" + idNumber + "'", e);
            return null;
        }
    } else {
        List<Person> persons = Context.getPersonService().getPeople(givenName + " " + familyName, null);
        if (persons.size() == 1) {
            return persons.get(0).getPersonId();
        } else if (persons.isEmpty()) {
            log.error("Couldn't find a person named " + givenName + " " + familyName);
            return null;
        } else {
            log.error("Found more than one person named " + givenName + " " + familyName);
            return null;
        }
    }
}
Also used : Person(org.openmrs.Person) URISyntaxException(java.net.URISyntaxException) DAOException(org.openmrs.api.db.DAOException) FileNotFoundException(java.io.FileNotFoundException) APIException(org.openmrs.api.APIException) HL7Exception(ca.uhn.hl7v2.HL7Exception) EncodingNotSupportedException(ca.uhn.hl7v2.parser.EncodingNotSupportedException) IOException(java.io.IOException) PatientIdentifierException(org.openmrs.api.PatientIdentifierException) ApplicationException(ca.uhn.hl7v2.app.ApplicationException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

HL7Exception (ca.uhn.hl7v2.HL7Exception)5 XCN (ca.uhn.hl7v2.model.v25.datatype.XCN)5 Message (ca.uhn.hl7v2.model.Message)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)3 ORC (ca.uhn.hl7v2.model.v25.segment.ORC)3 Test (org.junit.Test)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)2 EncodingNotSupportedException (ca.uhn.hl7v2.parser.EncodingNotSupportedException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Person (org.openmrs.Person)2 User (org.openmrs.User)2 APIException (org.openmrs.api.APIException)2 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)2 DAOException (org.openmrs.api.db.DAOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CX (ca.uhn.hl7v2.model.v26.datatype.CX)1 XCN (ca.uhn.hl7v2.model.v26.datatype.XCN)1