ca.uhn.hl7v2.validation.ValidationContext Java Examples
The following examples show how to use
ca.uhn.hl7v2.validation.ValidationContext.
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: 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 #2
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); }
Example #3
Source File: HL7MLLPInput.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public Result execute( Result previousResult, int nr ) { Result result = previousResult; try { String serverName = environmentSubstitute( server ); int portNumber = Integer.parseInt( environmentSubstitute( port ) ); String messageVariable = environmentSubstitute( messageVariableName ); String messageTypeVariable = environmentSubstitute( messageTypeVariableName ); String versionVariable = environmentSubstitute( versionVariableName ); MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource( serverName, portNumber ); if ( entry.getJobListener() != null ) { parentJob.addJobListener( entry.getJobListener() ); } MLLPTransport transport = entry.getTransport(); // Get the next value... // synchronized ( transport ) { Transportable transportable = transport.doReceive(); String message = transportable.getMessage(); logDetailed( "Received message: " + message ); parentJob.setVariable( messageVariable, message ); // Parse the message and extract the control ID. // Parser parser = new GenericParser(); ValidationContext validationContext = new NoValidation(); parser.setValidationContext( validationContext ); Message msg = parser.parse( message ); Structure structure = msg.get( "MSH" ); String messageType = null; String version = msg.getVersion(); if ( structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v21.segment.MSH) structure ).getMESSAGETYPE().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v22.segment.MSH) structure ).getMessageType().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v23.segment.MSH) structure ).getMessageType().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v231.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v24.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v25.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v251.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v26.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else { logError( "This job entry does not support the HL7 dialect used. Found MSH class: " + structure.getClass().getName() ); } if ( !Utils.isEmpty( messageTypeVariable ) ) { parentJob.setVariable( messageTypeVariable, messageType ); } if ( !Utils.isEmpty( versionVariable ) ) { parentJob.setVariable( versionVariable, version ); } } // All went well.. // result.setNrErrors( 0 ); result.setResult( true ); } catch ( Exception e ) { log.logError( BaseMessages.getString( PKG, "HL7MLLPInput.Exception.UnexpectedError" ), e ); result.setNrErrors( 1 ); result.setResult( false ); } return result; }