ca.uhn.hl7v2.HapiContext Java Examples
The following examples show how to use
ca.uhn.hl7v2.HapiContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HL7_ADT_A08.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Creates an ORU_R01 message * * @param patient * @param consultation * @param labItem * @param labwert * * @return */ public String createText(final HL7Patient patient, HL7Konsultation consultation) throws DataTypeException, HL7Exception{ ADT_A08 adt = new ADT_A08(); // Message fillMSH(adt.getMSH(), "ADT", "A08", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$ "8859/1", patient); //$NON-NLS-1$ //$NON-NLS-2$ fillEVN(adt.getEVN()); // Patient fillPID(adt.getPID(), patient); // Patient Visit fillPV1(adt.getPV1(), consultation); // Now, let's encode the message and look at the output HapiContext context = new DefaultHapiContext(); Parser parser = context.getPipeParser(); return parser.encode(adt); }
Example #2
Source File: TestHL7Query.java From localization_nifi with Apache License 2.0 | 5 votes |
private HL7Message createMessage(final File file) throws HL7Exception, IOException { final byte[] bytes = Files.readAllBytes(file.toPath()); final String msgText = new String(bytes, "UTF-8"); final HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext(ValidationContextFactory.noValidation()); final PipeParser parser = hapiContext.getPipeParser(); final Message message = parser.parse(msgText); return new HapiMessage(message); }
Example #3
Source File: HL7InboundTestSender.java From product-ei with Apache License 2.0 | 5 votes |
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 #4
Source File: HL7InboundTestSender.java From product-ei with Apache License 2.0 | 5 votes |
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 #5
Source File: TestHL7Query.java From nifi with Apache License 2.0 | 5 votes |
private HL7Message createMessage(final String msgText) throws HL7Exception, IOException { final HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext(ValidationContextFactory.noValidation()); final PipeParser parser = hapiContext.getPipeParser(); final Message message = parser.parse(msgText); return new HapiMessage(message); }
Example #6
Source File: HL7IntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("resource") public void testMarshalUnmarshal() throws Exception { final String msg = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r"; final HL7DataFormat format = new HL7DataFormat(); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .marshal(format) .unmarshal(format) .to("mock:result"); } }); camelctx.start(); try { HapiContext context = new DefaultHapiContext(); Parser p = context.getGenericParser(); Message hapimsg = p.parse(msg); ProducerTemplate producer = camelctx.createProducerTemplate(); Message result = (Message) producer.requestBody("direct:start", hapimsg); Assert.assertEquals(hapimsg.toString(), result.toString()); } finally { camelctx.close(); } }
Example #7
Source File: RouteHL7.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).evaluateAttributeExpressions(flowFile).getValue()); final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, new InputStreamCallback() { @Override public void process(final InputStream in) throws IOException { StreamUtils.fillBuffer(in, buffer); } }); @SuppressWarnings("resource") final HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext((ca.uhn.hl7v2.validation.ValidationContext) ValidationContextFactory.noValidation()); final PipeParser parser = hapiContext.getPipeParser(); final String hl7Text = new String(buffer, charset); final HL7Message message; try { final Message hapiMessage = parser.parse(hl7Text); message = new HapiMessage(hapiMessage); } catch (final Exception e) { getLogger().error("Failed to parse {} as HL7 due to {}; routing to failure", new Object[]{flowFile, e}); session.transfer(flowFile, REL_FAILURE); return; } final Set<String> matchingRels = new HashSet<>(); final Map<Relationship, HL7Query> queryMap = queries; for (final Map.Entry<Relationship, HL7Query> entry : queryMap.entrySet()) { final Relationship relationship = entry.getKey(); final HL7Query query = entry.getValue(); final QueryResult result = query.evaluate(message); if (result.isMatch()) { FlowFile clone = session.clone(flowFile); clone = session.putAttribute(clone, "RouteHL7.Route", relationship.getName()); session.transfer(clone, relationship); session.getProvenanceReporter().route(clone, relationship); matchingRels.add(relationship.getName()); } } session.transfer(flowFile, REL_ORIGINAL); getLogger().info("Routed a copy of {} to {} relationships: {}", new Object[]{flowFile, matchingRels.size(), matchingRels}); }
Example #8
Source File: ExtractHL7Attributes.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).evaluateAttributeExpressions(flowFile).getValue()); final Boolean useSegmentNames = context.getProperty(USE_SEGMENT_NAMES).asBoolean(); final Boolean parseSegmentFields = context.getProperty(PARSE_SEGMENT_FIELDS).asBoolean(); final Boolean skipValidation = context.getProperty(SKIP_VALIDATION).asBoolean(); final String inputVersion = context.getProperty(HL7_INPUT_VERSION).getValue(); final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, new InputStreamCallback() { @Override public void process(final InputStream in) throws IOException { StreamUtils.fillBuffer(in, buffer); } }); @SuppressWarnings("resource") final HapiContext hapiContext = new DefaultHapiContext(); if (!inputVersion.equals("autodetect")) { hapiContext.setModelClassFactory(new CanonicalModelClassFactory(inputVersion)); } if (skipValidation) { hapiContext.setValidationContext((ValidationContext) ValidationContextFactory.noValidation()); } final PipeParser parser = hapiContext.getPipeParser(); final String hl7Text = new String(buffer, charset); try { final Message message = parser.parse(hl7Text); final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields); flowFile = session.putAllAttributes(flowFile, attributes); getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes}); } catch (final HL7Exception e) { getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e}); session.transfer(flowFile, REL_FAILURE); return; } session.transfer(flowFile, REL_SUCCESS); }
Example #9
Source File: RouteHL7.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).evaluateAttributeExpressions(flowFile).getValue()); final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, new InputStreamCallback() { @Override public void process(final InputStream in) throws IOException { StreamUtils.fillBuffer(in, buffer); } }); @SuppressWarnings("resource") final HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext((ca.uhn.hl7v2.validation.ValidationContext) ValidationContextFactory.noValidation()); final PipeParser parser = hapiContext.getPipeParser(); final String hl7Text = new String(buffer, charset); final HL7Message message; try { final Message hapiMessage = parser.parse(hl7Text); message = new HapiMessage(hapiMessage); } catch (final Exception e) { getLogger().error("Failed to parse {} as HL7 due to {}; routing to failure", new Object[]{flowFile, e}); session.transfer(flowFile, REL_FAILURE); return; } final Set<String> matchingRels = new HashSet<>(); final Map<Relationship, HL7Query> queryMap = queries; for (final Map.Entry<Relationship, HL7Query> entry : queryMap.entrySet()) { final Relationship relationship = entry.getKey(); final HL7Query query = entry.getValue(); final QueryResult result = query.evaluate(message); if (result.isMatch()) { FlowFile clone = session.clone(flowFile); clone = session.putAttribute(clone, "RouteHL7.Route", relationship.getName()); session.transfer(clone, relationship); session.getProvenanceReporter().route(clone, relationship); matchingRels.add(relationship.getName()); } } session.transfer(flowFile, REL_ORIGINAL); getLogger().info("Routed a copy of {} to {} relationships: {}", new Object[]{flowFile, matchingRels.size(), matchingRels}); }
Example #10
Source File: ExtractHL7Attributes.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).evaluateAttributeExpressions(flowFile).getValue()); final Boolean useSegmentNames = context.getProperty(USE_SEGMENT_NAMES).asBoolean(); final Boolean parseSegmentFields = context.getProperty(PARSE_SEGMENT_FIELDS).asBoolean(); final Boolean skipValidation = context.getProperty(SKIP_VALIDATION).asBoolean(); final String inputVersion = context.getProperty(HL7_INPUT_VERSION).getValue(); final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, new InputStreamCallback() { @Override public void process(final InputStream in) throws IOException { StreamUtils.fillBuffer(in, buffer); } }); @SuppressWarnings("resource") final HapiContext hapiContext = new DefaultHapiContext(); if (!inputVersion.equals("autodetect")) { hapiContext.setModelClassFactory(new CanonicalModelClassFactory(inputVersion)); } if (skipValidation) { hapiContext.setValidationContext((ValidationContext) ValidationContextFactory.noValidation()); } final PipeParser parser = hapiContext.getPipeParser(); final String hl7Text = new String(buffer, charset); try { final Message message = parser.parse(hl7Text); final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields); flowFile = session.putAllAttributes(flowFile, attributes); getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes}); } catch (final HL7Exception e) { getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e}); session.transfer(flowFile, REL_FAILURE); return; } session.transfer(flowFile, REL_SUCCESS); }