Search in sources :

Example 31 with IS

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

the class ORUR01HandlerTest method parseObs_shouldAddCommentsToAnObservationGroup.

/**
 * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String)
 */
@Test
public void parseObs_shouldAddCommentsToAnObservationGroup() 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|||23^FOOD CONSTRUCT^99DCT\r" + "NTE|1|L|This is a comment\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206\r" + "NTE|1|L|This should not be considered :-)";
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals("This is a comment", 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 32 with IS

use of ca.uhn.hl7v2.model.v25.datatype.IS 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 33 with IS

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

the class ADTA28Handler method createPatient.

// Create a new patient when this patient doesn't exist in the database
private Patient createPatient(PID pid, String creatorName) throws HL7Exception {
    Patient patient = new Patient();
    // Try to use the specified username as the creator
    User creator = Context.getUserService().getUserByUsername(creatorName);
    if (creator != null) {
        patient.setCreator(creator);
    }
    // Create all patient identifiers specified in the message
    // Copied code from resolvePatientId() in HL7ServiceImpl.java
    CX[] idList = pid.getPatientIdentifierList();
    if (idList == null || idList.length < 1) {
        throw new HL7Exception("Missing patient identifier in PID segment");
    }
    List<PatientIdentifier> goodIdentifiers = new ArrayList<>();
    for (CX id : idList) {
        String assigningAuthority = id.getAssigningAuthority().getNamespaceID().getValue();
        String hl7PatientId = id.getIDNumber().getValue();
        log.debug("identifier has id=" + hl7PatientId + " assigningAuthority=" + assigningAuthority);
        if (assigningAuthority != null && assigningAuthority.length() > 0) {
            try {
                PatientIdentifierType pit = Context.getPatientService().getPatientIdentifierTypeByName(assigningAuthority);
                if (pit == null) {
                    log.warn("Can't find PatientIdentifierType named '" + assigningAuthority + "'");
                    // skip identifiers with unknown type
                    continue;
                }
                PatientIdentifier pi = new PatientIdentifier();
                if (creator != null) {
                    pi.setCreator(creator);
                }
                pi.setIdentifierType(pit);
                pi.setIdentifier(hl7PatientId);
                // Get default location
                Location location = Context.getLocationService().getDefaultLocation();
                if (location == null) {
                    throw new HL7Exception("Cannot find default location");
                }
                pi.setLocation(location);
                try {
                    PatientIdentifierValidator.validateIdentifier(pi);
                    goodIdentifiers.add(pi);
                } catch (PatientIdentifierException ex) {
                    log.warn("Patient identifier in PID is invalid: " + pi, ex);
                }
            } catch (Exception e) {
                log.error("Uncaught error parsing/creating patient identifier '" + hl7PatientId + "' for assigning authority '" + assigningAuthority + "'", e);
            }
        } else {
            log.error("PID contains identifier with no assigning authority");
            continue;
        }
    }
    if (goodIdentifiers.isEmpty()) {
        throw new HL7Exception("PID segment has no recognizable patient identifiers.");
    }
    patient.addIdentifiers(goodIdentifiers);
    // Extract patient name from the message
    XPN patientNameX = pid.getPatientName(0);
    if (patientNameX == null) {
        throw new HL7Exception("Missing patient name in the PID segment");
    }
    // Patient name
    PersonName name = new PersonName();
    name.setFamilyName(patientNameX.getFamilyName().getSurname().getValue());
    name.setGivenName(patientNameX.getGivenName().getValue());
    name.setMiddleName(patientNameX.getSecondAndFurtherGivenNamesOrInitialsThereof().getValue());
    if (creator != null) {
        name.setCreator(creator);
    }
    patient.addName(name);
    // Gender (checks for null, but not for 'M' or 'F')
    String gender = pid.getAdministrativeSex().getValue();
    if (gender == null) {
        throw new HL7Exception("Missing gender in the PID segment");
    }
    gender = gender.toUpperCase();
    if (!OpenmrsConstants.GENDER().containsKey(gender)) {
        throw new HL7Exception("Unrecognized gender: " + gender);
    }
    patient.setGender(gender);
    // Date of Birth
    TS dateOfBirth = pid.getDateTimeOfBirth();
    if (dateOfBirth == null || dateOfBirth.getTime() == null || dateOfBirth.getTime().getValue() == null) {
        throw new HL7Exception("Missing birth date in the PID segment");
    }
    patient.setBirthdate(tsToDate(dateOfBirth));
    // Estimated birthdate?
    ID precisionTemp = dateOfBirth.getDegreeOfPrecision();
    if (precisionTemp != null && precisionTemp.getValue() != null) {
        String precision = precisionTemp.getValue().toUpperCase();
        log.debug("The birthdate is estimated: " + precision);
        if ("Y".equals(precision) || "L".equals(precision)) {
            patient.setBirthdateEstimated(true);
        }
    }
    return patient;
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) HL7Exception(ca.uhn.hl7v2.HL7Exception) PatientIdentifierException(org.openmrs.api.PatientIdentifierException) ApplicationException(ca.uhn.hl7v2.app.ApplicationException) CX(ca.uhn.hl7v2.model.v25.datatype.CX) XPN(ca.uhn.hl7v2.model.v25.datatype.XPN) HL7Exception(ca.uhn.hl7v2.HL7Exception) PID(ca.uhn.hl7v2.model.v25.segment.PID) ID(ca.uhn.hl7v2.model.v25.datatype.ID) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifierException(org.openmrs.api.PatientIdentifierException) Location(org.openmrs.Location) TS(ca.uhn.hl7v2.model.v25.datatype.TS)

Example 34 with IS

use of ca.uhn.hl7v2.model.v25.datatype.IS in project quickstarts by jboss-switchyard.

the class CamelServiceRoute method configure.

/**
 * The Camel route is configured via this method.  The from endpoint is required to be a SwitchYard service.
 */
public void configure() {
    DataFormat hl7 = new HL7DataFormat();
    from("switchyard://HL7Route").unmarshal(hl7).process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            String body = exchange.getIn().getBody(String.class);
            PipeParser pipeParser = new PipeParser();
            try {
                // Parse the HL7 message
                ca.uhn.hl7v2.model.Message message = pipeParser.parse(body);
                if (message instanceof QRY_A19) {
                    // Print out some details from the QRD
                    QRD qrd = (QRD) message.get("QRD");
                    System.out.println("Query Date/Time : " + qrd.getQueryDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Query Format Code : " + qrd.getQueryFormatCode().getValue());
                    System.out.println("Query Priority : " + qrd.getQueryPriority().getValue());
                    System.out.println("Query ID : " + qrd.getQueryID().getValue());
                    System.out.println("Deferred Response Type : " + qrd.getDeferredResponseType().getValue());
                    System.out.println("Deferred Response Date/Time : " + qrd.getDeferredResponseDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Quantity Limited Request : " + qrd.getQuantityLimitedRequest().getQuantity().getValue());
                    System.out.println("Query Results Level : " + qrd.getQueryResultsLevel().getValue());
                    qrd.getQueryID();
                }
            } catch (Exception e) {
                throw e;
            }
            SwitchYardMessage out = new SwitchYardMessage();
            out.setBody(body);
            exchange.setOut(out);
        }
    });
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Processor(org.apache.camel.Processor) PipeParser(ca.uhn.hl7v2.parser.PipeParser) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) Exchange(org.apache.camel.Exchange) DataFormat(org.apache.camel.spi.DataFormat) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) QRY_A19(ca.uhn.hl7v2.model.v24.message.QRY_A19)

Aggregations

Message (ca.uhn.hl7v2.model.Message)21 Test (org.junit.Test)16 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)15 Patient (org.openmrs.Patient)13 HL7Exception (ca.uhn.hl7v2.HL7Exception)12 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)10 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)8 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)7 IOException (java.io.IOException)7 Concept (org.openmrs.Concept)7 Obs (org.openmrs.Obs)7 Person (org.openmrs.Person)7 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)6 EncodingNotSupportedException (ca.uhn.hl7v2.parser.EncodingNotSupportedException)5 FileNotFoundException (java.io.FileNotFoundException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 RelationshipType (org.openmrs.RelationshipType)5 ObsService (org.openmrs.api.ObsService)5