Java Code Examples for ca.uhn.hl7v2.model.Message

The following are top voted examples for showing how to use ca.uhn.hl7v2.model.Message. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: HL7Receiver   File: PSQLReader.java   Source Code and License 6 votes vote down vote up
@Override
public Message next() throws IOException, HL7Exception {
    Message ret = null;

    while (psqlReaderNextmsg != null && ret == null) {
        Message nextMsg = psqlReaderNextmsg;
        readNextPsqlMessage();

        if (skipMessages) {
            Terser nextMsgTerser = new Terser(nextMsg);
            String currMSH10 = nextMsgTerser.get("/MSH-10");
            if (lastSuccessSendMsgId.compareTo(currMSH10) == 0) {
                LOG.info("Skip message (for the last time):" + currMSH10);
                skipMessages = false;
            } else {
                LOG.info("Skip message:" + currMSH10);
            }
        } else {
            ret = nextMsg;
        }
    }

    return ret;
}
 
Example 2
Project: HL7Receiver   File: HAPIReader.java   Source Code and License 6 votes vote down vote up
@Override
public Message next() throws HL7Exception {
    Message ret = null;

    while (hapiIter.hasNext() && ret == null) {
        Message nextMsg = hapiIter.next();
        if (skipMessages) {
            Terser nextMsgTerser = new Terser(nextMsg);
            String currMSH10 = nextMsgTerser.get("/MSH-10");
            if (lastSuccessSendMsgId.compareTo(currMSH10) == 0) {
                LOG.info("Skip message (for the last time):" + currMSH10);
                skipMessages = false;
            } else {
                LOG.info("Skip message:" + currMSH10);
            }
        } else {
            ret = nextMsg;
        }
    }

    return ret;
}
 
Example 3
Project: hapi-spring-integration   File: HL7v24InboundMessageServiceImpl.java   Source Code and License 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a HAPI v2.4 message");
    ADT_A01 adtMsg = (ADT_A01) hapiMsg;
    MSH msh = adtMsg.getMSH();

    XPN[] xpns = adtMsg.getPID().getPatientName();

    for (XPN xpn : xpns) {
        System.out.println(xpn.toString());
    }
    return null;
}
 
Example 4
Project: hapi-spring-integration   File: HL7v23InboundMessageServiceImpl.java   Source Code and License 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a HAPI 2.3 message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;

    PID pID = adtMsg.getPID();

    XPN xpn[] = pID.getPatientName();

    System.out.println(xpn[0].getGivenName().toString() + " " + xpn[0].getFamilyName().toString());
    return null;
}
 
Example 5
Project: hapi-spring-integration   File: HL7v25InboundMessageServiceImpl.java   Source Code and License 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a v25 HAPI message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();


    XPN[] xpns = adtMsg.getPID().getPatientName();

    for (XPN xpn : xpns ) {
        System.out.println(xpn.toString());
    }
    return null;
}
 
Example 6
Project: product-ei   File: SampleApp.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

    String encodedMessage = new PipeParser().encode(theIn);
    System.out.println("Received message:\n" + encodedMessage + "\n\n");

    // Now we need to generate a message to return. This will generally be an ACK message.
    Segment msh = (Segment) theIn.get("MSH");
    Message retVal;
    try {
        // This method takes in the MSH segment of an incoming message, and generates an
        // appropriate ACK
        retVal = DefaultApplication.makeACK(msh);
    } catch (IOException e) {
        throw new HL7Exception(e);
    }

    return retVal;
}
 
Example 7
Project: Camel   File: HL7MLLPNettyEncoder.java   Source Code and License 6 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, Object message, ByteBuf byteBuf) 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());
    }
    byteBuf.writeByte(config.getStartByte());
    byteBuf.writeBytes(body);
    byteBuf.writeByte(config.getEndByte1());
    byteBuf.writeByte(config.getEndByte2());
}
 
Example 8
Project: Camel   File: TerserLanguage.java   Source Code and License 6 votes vote down vote up
public static Expression terser(final String expression) {
    ObjectHelper.notNull(expression, "expression");
    return new ExpressionAdapter() {

        @Override
        public Object evaluate(Exchange exchange) {
            Message message = exchange.getIn().getBody(Message.class);
            try {
                return new Terser(message).get(expression.trim());
            } catch (HL7Exception e) {
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }
        }

        @Override
        public String toString() {
            return "terser(" + expression + ")";
        }

    };
}
 
Example 9
Project: Camel   File: HL7MLLPCodecLongTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec").process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    assertEquals(70010, exchange.getIn().getBody(byte[].class).length);
                    MDM_T02 input = (MDM_T02)exchange.getIn().getBody(Message.class);
                    assertEquals("2.5", input.getVersion());
                    MSH msh = input.getMSH();
                    assertEquals("20071129144629", msh.getDateTimeOfMessage().getTime().getValue());
                    exchange.getOut().setBody("some response");
                }
            }).to("mock:result");
        }
    };
}
 
Example 10
Project: Camel   File: HL7MLLPNettyRouteToTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:start")
                .to("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                // because HL7 message contains a bunch of control chars then the logger do not log all of the data
                .log("HL7 message: ${body}")
                .to("mock:result");

            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                });
        }
    };
}
 
Example 11
Project: Camel   File: HL7MLLPNettyRouteToTest.java   Source Code and License 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 12
Project: Camel   File: HL7MLLPCodecStandAndEndBytesTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 13
Project: Camel   File: HL7MLLPCodecStandAndEndBytesTest.java   Source Code and License 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 14
Project: Camel   File: HL7RouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 15
Project: Camel   File: HL7RouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
    assertEquals("PID|||123||Doe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 16
Project: Camel   File: HL7RouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 17
Project: Camel   File: HL7RouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 18
Project: Camel   File: HL7RouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 19
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 20
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4||||||UNICODE UTF-8";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("PID|||123||Döe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 21
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 22
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 23
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Döe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 24
Project: Camel   File: HL7ValidateTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testMarshalWithValidation() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:end");
    mock.expectedMessageCount(0);

    Message message = createADT01Message();
    try {
        template.sendBody("direct:start1", message);
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(HL7Exception.class, e.getCause());
        assertIsInstanceOf(ValidationException.class, e.getCause().getCause());
        System.out.println(e.getCause().getCause().getMessage());
        assertTrue("Should be a validation error message", e.getCause().getCause().getMessage().startsWith("Validation failed:"));
    }

    assertMockEndpointsSatisfied();
}
 
Example 25
Project: Camel   File: HL7MLLPNettyCodecTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 26
Project: Camel   File: HL7MLLPNettyCodecTest.java   Source Code and License 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 27
Project: Camel   File: HL7NettyRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 28
Project: Camel   File: HL7NettyRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
    assertEquals("PID|||123||Doe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 29
Project: Camel   File: HL7NettyRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 30
Project: Camel   File: HL7NettyRouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 31
Project: Camel   File: HL7MLLPNettyCodecStandAndEndBytesTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 32
Project: Camel   File: HL7MLLPNettyCodecStandAndEndBytesTest.java   Source Code and License 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 33
Project: Camel   File: HL7MLLPCodecTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 34
Project: Camel   File: HL7MLLPCodecTest.java   Source Code and License 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 35
Project: Camel   File: HL7ByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 36
Project: Camel   File: HL7ByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4||||||UNICODE UTF-8";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("PID|||123||Döe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 37
Project: Camel   File: HL7ByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 38
Project: Camel   File: HL7ByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 39
Project: Camel   File: HL7ByteArrayRouteTest.java   Source Code and License 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Döe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 40
Project: Camel   File: HL7MLLPNettyCodecLongTest.java   Source Code and License 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder").process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    assertEquals(70010, exchange.getIn().getBody(byte[].class).length);
                    MDM_T02 input = (MDM_T02)exchange.getIn().getBody(Message.class);
                    assertEquals("2.5", input.getVersion());
                    MSH msh = input.getMSH();
                    assertEquals("20071129144629", msh.getDateTimeOfMessage().getTime().getValue());
                    exchange.getOut().setBody("some response");
                }
            }).to("mock:result");
        }
    };
}
 
Example 41
Project: openxds   File: BaseIheActor.java   Source Code and License 6 votes vote down vote up
/**
 * Initiates a <code>MessageStore</code> instance, and log the 
 * initial message, either in-bound message or out-bound message.
 * 
 * @param message the initial message to log
 * @param isInbound whether the message is an in-bound message or out-bound message 
 * @return a <code>MessageStore</code>
 * @throws HL7Exception
 */
public MessageStore initMessageStore(Message message, boolean isInbound) 
throws HL7Exception {
	if (storeLogger == null)
		return null;
	
	MessageStore ret = new MessageStore(); 
	if (message != null) {
		String encodedMessage = HL7Util.encodeMessage(message);
	    if (isInbound)
	    	ret.setInMessage( encodedMessage );
	    else 
	    	ret.setOutMessage( encodedMessage );
	}
    return ret;
}
 
Example 42
Project: openxds   File: BaseIheActor.java   Source Code and License 6 votes vote down vote up
/**
 * Persists the <code>MessageStore</code> log, and save the return message
 * which could be either in-bound or out-bound.
 * 
 * @param message the last message to save and log
 * @param isInbound whether the message is an in-bound message or out-bound message 
 * @param msgStore the <code>MessageStore</code> instance to hold the log data
 * @throws HL7Exception if the message could not be encoded 
 */
public void saveMessageStore(Message message, boolean isInbound, MessageStore msgStore) 
throws HL7Exception {
	if (msgStore == null || storeLogger == null )
		return;
	
    if (message != null) {
	    String encodedMessage = HL7Util.encodeMessage(message);
	    if (isInbound) 
		    msgStore.setInMessage( encodedMessage );
	    else
	    	msgStore.setOutMessage( encodedMessage );
    }		
    storeLogger.saveLog( msgStore );

}
 
Example 43
Project: openxds   File: XdsTest.java   Source Code and License 6 votes vote down vote up
protected void createPatient(String patientId) throws Exception {
	if (!validatePatient)
		return ;
	
	patientId = patientId.replace("&amp;", "&");
	//If it is a valid patient, then no need to re-create.
	if (isValidPatient(patientId))
		return; 
	
	String msg = "MSH|^~\\&|OTHER_KIOSK|HIMSSSANDIEGO|PAT_IDENTITY_X_REF_MGR_MISYS|ALLSCRIPTS|20090512132906-0300||ADT^A04^ADT_A01|7723510070655179915|P|2.3.1\r" + 
      "EVN||20090512132906-0300\r" +
      "PID|||"+ patientId +"||FARNSWORTH^STEVE||19781208|M|||820 JORIE BLVD^^CHICAGO^IL^60523\r" +
      "PV1||O|";
	PipeParser pipeParser = new PipeParser();
	Message adt = pipeParser.parse(msg);
	ConnectionHub connectionHub = ConnectionHub.getInstance();
	Connection connection = connectionHub.attach(hostName, pixRegistryPort, new PipeParser(), MinLowerLayerProtocol.class);
	Initiator initiator = connection.getInitiator();
	Message response = initiator.sendAndReceive(adt);
	String responseString = pipeParser.encode(response);	        
	System.out.println("Received response:\n" + responseString);
		MSA msa = (MSA)response.get("MSA");
	assertEquals("AA", msa.getAcknowledgementCode().getValue());
}
 
Example 44
Project: AvoinApotti   File: HL7PasProcessor.java   Source Code and License 6 votes vote down vote up
private void getResponseMSH(/*ADR_A19resp*/MSH retMsh,Message msg) throws Exception
{
	ca.uhn.hl7v2.model.v231.segment.MSH msh = (ca.uhn.hl7v2.model.v231.segment.MSH)msg.get("MSH");
	
	SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
	//ca.uhn.hl7v2.model.v231.segment.MSH retMsh = resp.getMSH();
	
	retMsh.getEncodingCharacters().setValue(msh.getEncodingCharacters().getValue());
	retMsh.getFieldSeparator().setValue("|");
	retMsh.getSendingApplication().getNamespaceID().setValue("" + ConfigFlag.HL7.HL7_APPLICATION.getValue());
	retMsh.getSendingFacility().getNamespaceID().setValue("" + ConfigFlag.HL7.HL7_FACILITY.getValue());
	retMsh.getReceivingApplication().getNamespaceID().setValue(msh.getReceivingFacility().getNamespaceID().getValue());
	retMsh.getReceivingFacility().getNamespaceID().setValue(msh.getReceivingFacility().getNamespaceID().getValue());
	
	retMsh.getDateTimeOfMessage().getTimeOfAnEvent().setValue(sf.format(new Date()));		
	retMsh.getSequenceNumber().setValue(msh.getSequenceNumber().getValue());
	retMsh.getMessageControlID().setValue(msh.getMessageControlID().getValue());
	retMsh.getCharacterSet(0).setValue(msh.getCharacterSet(0).getValue());
	retMsh.getProcessingID().getProcessingID().setValue("" + ConfigFlag.HL7.HL7_PROCESSING_ID.getValue());
	retMsh.getVersionID().getVersionID().setValue("2.3.1");
	
}
 
Example 45
Project: AvoinApotti   File: A04NasMapper.java   Source Code and License 6 votes vote down vote up
public ImsNasMsg translate(Message msg) throws Exception 
{
	if (conn == null) 
	{
		throw new Exception("Cannot operate without connection to NAS Server.");
	}
	
	PV1 pv1 = (PV1) msg.get(SegName.PV1);
	String tmpVal = pv1.getPatientClass().getValue(); 
	if (tmpVal != null && tmpVal.equalsIgnoreCase("O"))
	{
		NasMapper mapper = HL7NasApplication.getNasMapper("A05");
		if (mapper == null)
		{
			throw new Exception("A04 mapper requires A05 mapper. A05 mapper not found in list of registerd mappers.");			
		}
		mapper.setConnection(conn);
		return mapper.translate(msg);
	}
	else return null; //will just pos ack.

}
 
Example 46
Project: AvoinApotti   File: A34NasMapper.java   Source Code and License 6 votes vote down vote up
public ImsNasMsg translate(Message msg) throws Exception
{
	//WDEV-5010
	if (conn == null) 
	{
		throw new Exception("Cannot operate without connection to NAS Server.");
	}
	MRG mrg = (MRG) msg.get(SegName.MRG);
	
	//EVN
	EVN evn = (EVN) msg.get(SegName.EVN);
	/* field 1 */
	if (!evn.getEventTypeCode().getValue().equalsIgnoreCase("A34"))
	{
		throw new HL7Exception("Unexpected Event Type Code for this message type");
	}
	
	return doMerge(mrg,msg,null);
	
}
 
Example 47
Project: AvoinApotti   File: M01VoMapper.java   Source Code and License 6 votes vote down vote up
public Message processEvent(Message msg, ProviderSystemVo providerSystem) throws HL7Exception
{
	try
	{
		if (isLookupType(msg))
		{
			processLookup(msg,providerSystem);
		}
	}
	catch (Exception ex)
	{
		LOG.error(ex.getMessage(), ex);
		return HL7Utils.buildRejAck(msg.get("MSH"), ex.getClass().getName() + " occurred. " + ex.getMessage(), HL7Errors.APP_INT_ERROR, toConfigItemArray(providerSystem.getConfigItems()));
	}

	Message ack = HL7Utils.buildPosAck(msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems()));
	return ack;	
}
 
Example 48
Project: AvoinApotti   File: A28VoMapper.java   Source Code and License 6 votes vote down vote up
protected Message processPatientUpdate(Message msg, ProviderSystemVo providerSystem, boolean includeNok) throws HL7Exception
{
	try
	{
		Patient patVo = savePatient(msg, providerSystem, includeNok);
		PV1 pv1 = (PV1) msg.get("PV1");
		if (ConfigFlag.HL7.INSTANTIATE_EPISODE_FROM_ADT.getValue())
		{
			createCareSpell(patVo, pv1,providerSystem);
		}
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		return HL7Utils.buildRejAck( msg.get("MSH"), "Exception. " + ex.getMessage(), HL7Errors.APP_INT_ERROR, toConfigItemArray(providerSystem.getConfigItems()));
	}
	

	Message ack = HL7Utils.buildPosAck( msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems()));
	return ack;
}
 
Example 49
Project: switchyard   File: HL7ServiceTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCamelRoute() {
    StringBuilder in = new StringBuilder();
    in.append(LINE_ONE);
    in.append("\r");
    in.append(LINE_TWO);
    
    String result = processMessage.sendInOut(in).getContent(String.class);;
    PipeParser pipeParser = new PipeParser();
    
    try {
        //parse the message string into a Message object 
        Message message = pipeParser.parse(result);
        if (message instanceof QRY_A19) {
            QRD qrd = (QRD) message.get("QRD");
            ST st = qrd.getQueryID();
            Assert.assertTrue(st.getValue().equals("GetPatient"));
        } else {
            Assert.fail("Message not instance of QRY_A19");
        }
        
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    
}
 
Example 50
Project: AvoinApotti   File: M05VoMapper.java   Source Code and License 6 votes vote down vote up
public Message processEvent(Message msg, ProviderSystemVo providerSystem) throws HL7Exception 
{
	
	try
	{
		if (isClinicType(msg))
			processClinic(msg, providerSystem);
		else
			processLocation(msg,providerSystem);
	}
	catch (Exception ex)
	{
		LOG.error(ex.getMessage(), ex);
		return HL7Utils.buildRejAck( msg.get("MSH"), "Exception. " + ex.getMessage(), HL7Errors.APP_INT_ERROR, toConfigItemArray(providerSystem.getConfigItems()));
	}

	Message ack = HL7Utils.buildPosAck( msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems()));
	return ack;
}
 
Example 51
Project: HL7Receiver   File: DirectoryReader.java   Source Code and License 5 votes vote down vote up
@Override
public Message next() throws IOException {
    Message ret = null;

    while (hasNext() && ret == null) {
        currentFile = fileList.get(fileListPos);
        fileListPos++;
        LOG.info("Next file in list(" + currentFile.getFileName().toString() + "):" + currentFile.toString());

        if (skipMessages) {
            if (lastSuccessSendMsgId.compareTo(currentFile.getFileName().toString()) == 0) {
                LOG.info("Skip message (for the last time):" + currentFile.getFileName().toString());
                skipMessages = false;
            } else {
                LOG.info("Skip message:" + currentFile.getFileName().toString());
            }
        } else {
            FileReader reader = new FileReader(currentFile.toFile());
            Hl7InputStreamMessageIterator hapiIter = new Hl7InputStreamMessageIterator(reader);
            ret = hapiIter.next();
            reader.close();
        }
    }

    return ret;
}
 
Example 52
Project: hapi-spring-integration   File: HL7v21InboundMessageServiceImpl.java   Source Code and License 5 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a v21 HAPI message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();

    PN pn = adtMsg.getPID().getPATIENTNAME();

    System.out.println(pn.toString());
    return null;
}
 
Example 53
Project: hapi-spring-integration   File: HL7v22InboundMessageServiceImpl.java   Source Code and License 5 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a HAPI message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();

    PN pn = adtMsg.getPID().getPatientName();

    System.out.println(pn.toString());
    return null;
}
 
Example 54
Project: hapi-spring-integration   File: HL7v26InboundMessageServiceImpl.java   Source Code and License 5 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a v26 HAPI message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();

    XPN[] xpns = adtMsg.getPID().getPatientName();

    for (XPN xpn : xpns) {
        System.out.println(xpn.toString());
    }        return null;    }
 
Example 55
Project: hapi-spring-integration   File: HL7ParserTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testParseMessage() throws Exception {
    Message hapiMsg = parser.parseMessage(MSG);

    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();

    String msgType = msh.getMessageType().getMessageType().getValue();

    assertEquals("ADT", msgType);
}
 
Example 56
Project: hapi-spring-integration   File: HL7ParserTestv23.java   Source Code and License 5 votes vote down vote up
@Test
public void testParseMessage() throws Exception {
    Message hapiMsg = parser.parseMessage(MSG);

    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();

    String msgType = msh.getMessageType().getMessageType().getValue();

    assertEquals("ADT", msgType);
}
 
Example 57
Project: OSCAR-ConCert   File: EaapsMessageSupport.java   Source Code and License 5 votes vote down vote up
public void init(String hl7Body) throws HL7Exception, EncodingNotSupportedException {
	hl7Body = preProcess(hl7Body);
	Parser parser = new GenericParser();
	parser.setValidationContext(new NoValidation());
	Message m = parser.parse(hl7Body);
	if (!(m instanceof ORU_R01)) {
		throw new HL7Exception("Unsupported message type: " + m.getName() + ". Expected ORU^R01 ver 2.2");
	}
	ORU_R01 message = (ORU_R01) m;
	int commentReps = message.getPATIENT_RESULT().getORDER_OBSERVATION().currentReps("NTE");
	if (commentReps < 2) {
		throw new HL7Exception("Expected at least 2 comments in the NTE field.");
	}
	this.message = message;
}
 
Example 58
Project: product-ei   File: HL7InboundTestSender.java   Source Code and License 5 votes vote down vote up
public String send(String host, int port) throws HL7Exception, IOException, LLPException {
       HapiContext context = new DefaultHapiContext();
       Connection c = context.newClient(host, port, false);
       Initiator initiator = c.getInitiator();

       ADT_A01 msg = new ADT_A01();
       msg.initQuickstart("ADT", "A01", "T");
       Message resp = initiator.sendAndReceive(msg);
       return resp.encode();
}
 
Example 59
Project: product-ei   File: HL7InboundTestSender.java   Source Code and License 5 votes vote down vote up
public String send(String host, int port, Message message) throws HL7Exception, IOException, LLPException {
    HapiContext context = new DefaultHapiContext();
    Connection c = context.newClient(host, port, false);
    Initiator initiator = c.getInitiator();

    Message resp = initiator.sendAndReceive(message);
    return resp.encode();
}
 
Example 60
Project: Camel   File: HL7MLLPEncoder.java   Source Code and License 5 votes vote down vote up
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);
}