Search in sources :

Example 21 with IS

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

the class ORUR01HandlerTest method processNK1_shouldCreateAPersonIfTheRelativeIsNotFound.

/**
 * @see ORUR01Handler#processNK1(Patient,NK1)
 */
@Test
public void processNK1_shouldCreateAPersonIfTheRelativeIsNotFound() throws Exception {
    // process a message with an invalid relative identifier
    PersonService personService = Context.getPersonService();
    // 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^99REL||||||||||||F|19751016|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220029^^^UUID^v4\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);
    // find the relative in the database
    Person relative = personService.getPersonByUuid("2178037d-f86b-4f12-8d8b-be3ebc220029");
    Assert.assertNotNull("a new person was not created", relative);
    // see if the relative made it into the relationship properly
    List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3));
    Assert.assertTrue("new relationship was not created", !rels.isEmpty() && rels.size() == 1);
}
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) PersonService(org.openmrs.api.PersonService) Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Patient(org.openmrs.Patient) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with IS

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

the class ORUR01HandlerTest method processNK1_shouldFailIfTheRelationshipIdentifierIsFormattedImproperly.

/**
 * @see ORUR01Handler#processNK1(Patient,NK1)
 */
@Test(expected = HL7Exception.class)
public void processNK1_shouldFailIfTheRelationshipIdentifierIsFormattedImproperly() throws Exception {
    // process a message with an invalid relationship identifier format
    // 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|3C^Parent^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";
    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 23 with IS

use of ca.uhn.hl7v2.model.v25.datatype.IS in project streamsx.health by IBMStreams.

the class HapiMessageHandler method processMessage.

@Override
public Message processMessage(Message theMessage, Map<String, Object> arg1) throws ReceivingApplicationException, HL7Exception {
    server.messageArrived(theMessage);
    Message ack;
    try {
        // Always use the default parser to generate an ack
        // HAPI seems to get into trouble if the ADT_AXX superstructure
        // is used.  
        // Internally, when it tries to generate an ack message
        // the super structure setting in the model class factory causes the ADT_AXX message
        // to get created instead of the ACK getting created.  This is to override the model
        // class factory so that the proper class can be generated.
        theMessage.setParser(ackParser);
        ack = theMessage.generateACK();
        return ack;
    } catch (IOException e) {
        TRACE.log(TraceLevel.ERROR, "Unable to generate ack message", e);
    }
    return theMessage;
}
Also used : Message(ca.uhn.hl7v2.model.Message) IOException(java.io.IOException)

Example 24 with IS

use of ca.uhn.hl7v2.model.v25.datatype.IS in project tdi-studio-se by Talend.

the class HL7Parse method doParse.

/**
     * DOC gcui Comment method "doParse".
     * 
     * @param filePath
     * @return
     */
public List<Message> doParse(String filePath, String startChar, String endChar) {
    List<Message> messageList = new ArrayList<Message>();
    String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
    File file = Path.fromOSString(filePathNoQuotes).toFile();
    if (file.exists()) {
        ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
        try {
            array.setInnerContentFromFile(file);
            TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
            if (startChar != null) {
                talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
            }
            if (endChar != null) {
                talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
            }
            String HL7InputTem = null;
            String messageText = "";
            while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
                Message message = getHL7MessageInput(HL7InputTem);
                messageList.add(message);
                messageText = messageText + HL7InputTem + "\r";
            }
            if (messageText == null || "".equals(messageText)) {
                messageText = new String(array.getInnerContent());
            }
            talendHL7Reader.close();
        } catch (IOException ex) {
            ExceptionHandler.process(ex);
        }
    } else {
        MessageBox message = new MessageBox(new Shell(), SWT.APPLICATION_MODAL | SWT.OK);
        //$NON-NLS-1$
        message.setText("The file is not exist");
        //$NON-NLS-1$
        message.setMessage("Please check the file path and select the file again");
        if (message.open() == SWT.OK) {
            message.getParent().getShell().close();
        }
    }
    return messageList;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) ByteArray(org.talend.core.model.properties.ByteArray) IOException(java.io.IOException) File(java.io.File) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 25 with IS

use of ca.uhn.hl7v2.model.v25.datatype.IS in project camel by apache.

the class HL7MLLPEncoder method encode.

public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    if (message == null) {
        throw new IllegalArgumentException("Message to be encoded is null");
    } else if (message instanceof Exception) {
        // we cannot handle exceptions
        throw (Exception) message;
    }
    byte[] body;
    if (message instanceof Message) {
        body = ((Message) message).encode().getBytes(config.getCharset());
    } else if (message instanceof String) {
        body = ((String) message).getBytes(config.getCharset());
    } else if (message instanceof byte[]) {
        body = (byte[]) message;
    } else {
        throw new IllegalArgumentException("The message to encode is not a supported type: " + message.getClass().getCanonicalName());
    }
    // put the data into the byte buffer
    IoBuffer buf = IoBuffer.allocate(body.length + 3).setAutoExpand(true);
    buf.put((byte) config.getStartByte());
    buf.put(body);
    buf.put((byte) config.getEndByte1());
    buf.put((byte) config.getEndByte2());
    // flip the buffer so we can use it to write to the out stream
    buf.flip();
    LOG.debug("Encoded HL7 from {} to byte stream", message.getClass().getCanonicalName());
    out.write(buf);
}
Also used : Message(ca.uhn.hl7v2.model.Message) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

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