ca.uhn.hl7v2.parser.PipeParser Java Examples
The following examples show how to use
ca.uhn.hl7v2.parser.PipeParser.
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_ORU_R01.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Adds a ORU_R01 observation result * * @param oru * @param patient * @param labItem * @param labwert * @param initial * @return */ private String addResultInternal(final ORU_R01 oru, final HL7Patient patient, final HL7LaborItem labItem, final HL7LaborWert labwert, int orderObservationIndex) throws DataTypeException, HL7Exception{ // Observation ORU_R01_ORDER_OBSERVATION orderObservation = (ORU_R01_ORDER_OBSERVATION) oru.getPATIENT_RESULT().getORDER_OBSERVATION( orderObservationIndex); fillOBR(orderObservation.getOBR(), orderObservationIndex, labItem); fillOBX(orderObservation.getOBSERVATION().getOBX(), patient, labItem, labwert); if (labwert.getKommentar() != null && labwert.getKommentar().length() > 0) { fillNTE(orderObservation.getNTE(), labwert); } // Now, let's encode the message and look at the output Parser parser = new PipeParser(); return parser.encode(oru); }
Example #2
Source File: HL7_ORU_R01.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Creates an ORU_R01 message * * @param patient * @param labItem * @param labwert * * @return */ public String createText(final HL7Patient patient, final HL7LaborItem labItem, final HL7LaborWert labwert) throws DataTypeException, HL7Exception{ ORU_R01 oru = new ORU_R01(); // Message fillMSH(oru.getMSH(), "ORU", "R01", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$ this.uniqueProcessingID, patient); //$NON-NLS-1$ //$NON-NLS-2$ // Patient PID pid = oru.getPATIENT_RESULT().getPATIENT().getPID(); fillPID(pid, patient); ORU_R01_ORDER_OBSERVATION orderObservation = oru.getPATIENT_RESULT().getORDER_OBSERVATION(); fillORC(orderObservation.getORC(), "RE", null); //$NON-NLS-1$ addResultInternal(oru, patient, labItem, labwert, 0); // Now, let's encode the message and look at the output Parser parser = new PipeParser(); return parser.encode(oru); }
Example #3
Source File: HL7_OML_O21.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Creates an OMG_O19 message * * @param patient * @param kostentraeger * @param rechnungsempfaenger * @param auftragsNummer * @param plan * Abrechnungssystem (MV, UVG, VVG, KVG, usw) * @param beginDate * @param vnr * Versicherungs-, Fall- oder Unfallnr * @return */ public String createText(final HL7Patient patient, final HL7Kostentraeger rechnungsempfaenger, final HL7Kostentraeger kostentraeger, final String plan, final Date beginDate, final String fallNr, final long auftragsNummer) throws DataTypeException, HL7Exception{ OML_O21 omg = new OML_O21(); fillMSH(omg.getMSH(), "OML", "O21", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$ this.uniqueProcessingID, patient); //$NON-NLS-1$ //$NON-NLS-2$ fillPID(omg.getPATIENT().getPID(), patient); fillNK1(omg.getPATIENT().getNK1(), rechnungsempfaenger); fillPV1(omg.getPATIENT().getPATIENT_VISIT().getPV1(), patient, beginDate); fillIN1(omg.getPATIENT().getINSURANCE().getIN1(), patient, kostentraeger, plan, fallNr); fillORC(omg.getORDER().getORC(), "1", auftragsNummer); //$NON-NLS-1$ // Now, let's encode the message and look at the output Parser parser = new PipeParser(); return parser.encode(omg); }
Example #4
Source File: SampleApp.java From product-ei with Apache License 2.0 | 6 votes |
/** * {@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 #5
Source File: HL7_ORU_R01.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Reads an ORU_R01 HL7 file * * @param text * ISO-8559-1 String * @param readWithValidation * True for parsing with validation, False for parsing without validation * @return The ORU_R01 message * @throws HL7Exception */ public ORU_R01 read(String text, boolean readWithValidation) throws HL7Exception{ Parser p = new PipeParser(); if (readWithValidation) { p.setValidationContext(new ElexisValidation()); } else { p.setValidationContext(new NoValidation()); } Message hl7Msg = p.parse(text); if (hl7Msg instanceof ORU_R01) { return (ORU_R01) hl7Msg; } else { addError( MessageFormat.format(Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName())); } return null; }
Example #6
Source File: XdsRegistryImpl.java From openxds with Apache License 2.0 | 6 votes |
/** * Starts a PIX Registry Server to accept PIX Feed messages. * * @return <code>true</code> if the initialization is successful; * otherwise <code>false</code>. */ private boolean initPixRegistry() { boolean isSuccess = false; try { LowerLayerProtocol llp = LowerLayerProtocol.makeLLP(); // The transport protocol pixServer = new HL7Server(pixRegistryConnection, llp, new PipeParser()); Application pixFeed = new PixFeedHandler(this); //Admission of in-patient into a facility pixServer.registerApplication("ADT", "A01", pixFeed); //Registration of an out-patient for a visit of the facility pixServer.registerApplication("ADT", "A04", pixFeed); //Pre-admission of an in-patient pixServer.registerApplication("ADT", "A05", pixFeed); //Update patient information pixServer.registerApplication("ADT", "A08", pixFeed); //Merge patients pixServer.registerApplication("ADT", "A40", pixFeed); //now start the Pix Registry Server pixServer.start(); isSuccess = true; }catch(Exception e) { log.fatal("Failed to start the PIX Registry server", e); } return isSuccess; }
Example #7
Source File: XdsTest.java From openxds with Apache License 2.0 | 6 votes |
protected void createPatient(String patientId) throws Exception { if (!validatePatient) return ; patientId = patientId.replace("&", "&"); //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 #8
Source File: MergePatientTest.java From openxds with Apache License 2.0 | 5 votes |
private void SendPIX(String msg) throws Exception { 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 #9
Source File: HL7_ORU_R01.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * Reads an ORU_R01 HL7 file * * @param text * ISO-8559-1 String * @return * @throws HL7Exception */ public ORU_R01 read(String text) throws HL7Exception{ Parser p = new PipeParser(); p.setValidationContext(new ElexisValidation()); Message hl7Msg = p.parse(text); if (hl7Msg instanceof ORU_R01) { return (ORU_R01) hl7Msg; } else { addError(MessageFormat.format( Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName())); //$NON-NLS-1$ } return null; }
Example #10
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 #11
Source File: HapiField.java From nifi with Apache License 2.0 | 5 votes |
public HapiField(final Type type) { this.value = PipeParser.encode(type, EncodingCharacters.defaultInstance()); final List<HL7Component> componentList = new ArrayList<>(); if (type instanceof Composite) { final Composite composite = (Composite) type; for (final Type component : composite.getComponents()) { componentList.add(new HapiField(component)); } } final ExtraComponents extra = type.getExtraComponents(); if (extra != null && extra.numComponents() > 0) { final String singleFieldValue; if (type instanceof Primitive) { singleFieldValue = ((Primitive) type).getValue(); } else { singleFieldValue = this.value; } componentList.add(new SingleValueField(singleFieldValue)); for (int i = 0; i < extra.numComponents(); i++) { componentList.add(new HapiField(extra.getComponent(i))); } } this.components = Collections.unmodifiableList(componentList); }
Example #12
Source File: HapiField.java From localization_nifi with Apache License 2.0 | 5 votes |
public HapiField(final Type type) { this.value = PipeParser.encode(type, EncodingCharacters.defaultInstance()); final List<HL7Component> componentList = new ArrayList<>(); if (type instanceof Composite) { final Composite composite = (Composite) type; for (final Type component : composite.getComponents()) { componentList.add(new HapiField(component)); } } final ExtraComponents extra = type.getExtraComponents(); if (extra != null && extra.numComponents() > 0) { final String singleFieldValue; if (type instanceof Primitive) { singleFieldValue = ((Primitive) type).getValue(); } else { singleFieldValue = this.value; } componentList.add(new SingleValueField(singleFieldValue)); for (int i = 0; i < extra.numComponents(); i++) { final Varies varies = extra.getComponent(i); componentList.add(new HapiField(varies)); } } this.components = Collections.unmodifiableList(componentList); }
Example #13
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 #14
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 #15
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 #16
Source File: HL7InboundTestSender.java From product-ei with Apache License 2.0 | 4 votes |
public Message getOULMessage() throws HL7Exception { PipeParser parser = new PipeParser(); return parser.parse(OULMessage); }
Example #17
Source File: HL7Server.java From product-ei with Apache License 2.0 | 4 votes |
public HL7Server(int port) { LowerLayerProtocol llp = LowerLayerProtocol.makeLLP(); // The transport // protocol PipeParser parser = new PipeParser(); server = new SimpleServer(port, llp, parser); }
Example #18
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 #19
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}); }