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); }
public synchronized PipeParser getPipeParser() { if (pipeParser == null) { pipeParser = new PipeParser(this); } return pipeParser; }
final HL7Message message; try { final Message hapiMessage = parser.parse(hl7Text); message = new HapiMessage(hapiMessage); } catch (final Exception e) {
/** * {@inheritDoc} */ protected Message doParseForSpecificPackage(String message, String version, String packageName) throws HL7Exception { // try to instantiate a message object of the right class MessageStructure structure = getStructure(message); Message m = instantiateMessageInASpecificPackage(structure.messageStructure, version, structure.explicitlyDefined, packageName); parse(m, message); return m; }
/** * {@inheritDoc } */ @Override public String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception { return encode(type, encodingCharacters, getParserConfiguration(), null); }
PipeParser parser = new PipeParser(); IMessage hl7Message = parser.Parse(hl7); IStructure msa = hl7Message.GetStructure("MSA"); IType ackCode = ((ISegment)msa).GetField(1)[0]; MessageBox.Show(((AbstractPrimitive)ackCode).Value);
/** * {@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. MSH msh = (MSH)theIn.get("MSH"); ACK retVal; try { // This method takes in the MSH segment of an incoming message, and generates an // appropriate ACK retVal = (ACK)DefaultApplication.makeACK(msh); } catch (IOException e) { throw new HL7Exception(e); } return retVal; }
@Override public void parse(Message message, String string) throws HL7Exception { if (message instanceof AbstractSuperMessage && message.getName() == null) { String structure = getStructure(string).messageStructure; ((AbstractSuperMessage) message).setName(structure); IStructureDefinition structureDef = getStructureDefinition(message); MessageIterator messageIter = new MessageIterator(message, structureDef, "MSH", true); String[] segments = split(string, SEGMENT_DELIMITER); segments[i] = stripLeadingWhitespace(segments[i]); if (messageIter.hasNext()) { Segment next = (Segment) messageIter.next(); parse(next, segments[i], getEncodingChars(string), repNum); applySuperStructureName(message);
PipeParser parser = new PipeParser(); parser.setValidationContext(defaultValidation); parser.parse(validMessage); System.out.println("Successfully parsed valid message"); } catch (HL7Exception e) { parser.parse(invalidMessage); parser.setValidationContext(noValidation); parser.parse(invalidMessage); System.out.println("Successfully parsed invalid message"); } catch (HL7Exception e) { + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||"; try { Message parsedMessage = parser.parse(invalidMessage); System.out.println(new PipeParser().encode(parsedMessage));
PipeParser pipeParser = new PipeParser(); Message message = pipeParser.parse(ackMessageString);
if (isDelimDefSegment(source.getName())) startAt = 2; Type[] reps = source.getField(i); for (int j = 0; j < reps.length; j++) { String fieldText = encode(reps[j], encodingChars, parserConfig, nextFieldTerserPath); if (isDelimDefSegment(source.getName()) && i == 2) fieldText = parserConfig.getEscaping().unescape(fieldText, encodingChars); result.append(fieldText); String retVal = stripExtraDelimiters(result.toString(), fieldSeparator); int offset = isDelimDefSegment(source.getName()) ? 1 : 0; while (forceUpToFieldNum > 0 && (countInstancesOf(retVal, fieldSeparator) + offset) < forceUpToFieldNum) { retVal = retVal + fieldSeparator;
if (isDelimDefSegment(destination.getName())) { fieldOffset = 1; String[] fields = split(segment, String.valueOf(encodingChars.getFieldSeparator())); String[] reps = split(fields[i], String.valueOf(encodingChars.getRepetitionSeparator())); boolean isMSH2 = isDelimDefSegment(destination.getName()) && i + fieldOffset == 2; if (isMSH2) { reps = new String[1]; Terser.getPrimitive(field, 1, 1).setValue(reps[j]); } else { parse(field, reps[j], encodingChars); FixFieldDataType.fixOBX5(destination, getFactory(), getHapiContext().getParserConfiguration()); FixFieldDataType.fixMFE4(destination, getFactory(), getHapiContext().getParserConfiguration());
/** * Formats a Message object into an HL7 message string using this parser's * default encoding ("VB"). * * @throws HL7Exception * if the data fields in the message do not permit encoding * (e.g. required fields are null) */ protected String doEncode(Message source) throws HL7Exception { // get encoding characters ... Segment msh = (Segment) source.get("MSH"); String fieldSepString = Terser.get(msh, 1, 0, 1, 1); if (fieldSepString == null) throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); char fieldSep = '|'; if (fieldSepString.length() > 0) fieldSep = fieldSepString.charAt(0); EncodingCharacters en = getValidEncodingCharacters(fieldSep, msh); // pass down to group encoding method which will operate recursively on // children ... return encode(source, en, getParserConfiguration(), ""); }
/** * Formats a Message object into an HL7 message string using the given * encoding. * * @throws HL7Exception * if the data fields in the message do not permit encoding * (e.g. required fields are null) * @throws EncodingNotSupportedException * if the requested encoding is not supported by this parser. */ protected String doEncode(Message source, String encoding) throws HL7Exception { if (!this.supportsEncoding(encoding)) throw new EncodingNotSupportedException("This parser does not support the " + encoding + " encoding"); return encode(source); }
/** * Parses a message string and returns the corresponding Message object. * Unexpected segments added at the end of their group. * * @throws HL7Exception * if the message is not correctly formatted. * @throws EncodingNotSupportedException * if the message encoded is not supported by this parser. */ protected Message doParse(String message, String version) throws HL7Exception { // try to instantiate a message object of the right class MessageStructure structure = getStructure(message); Message m = instantiateMessage(structure.messageStructure, version, structure.explicitlyDefined); m.setParser(this); parse(m, message); return m; }
PipeParser pp = new PipeParser(); ca.uhn.hl7v2.parser.XMLParser xp = new DefaultXMLParser(); System.out.println("Encoding: " + pp.getEncoding(messString)); if (pp.getEncoding(messString) != null) { inParser = pp; outParser = xp;
theStringBuilder.append(new PipeParser().doEncode(nextSegment, EncodingCharacters.getInstance(getMessage()))); theStringBuilder.append(lineSeparator);
for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.append(encodePrimitive(p, parserConfig.getEscaping(), encodingChars)); comp.append(encodingChars.getSubcomponentSeparator()); field.append(stripExtraDelimiters(comp.toString(), encodingChars.getSubcomponentSeparator())); field.append(encodingChars.getComponentSeparator()); String retVal = stripExtraDelimiters(field.toString(), componentSeparator); while (forceUpToFieldNum > 0 && (countInstancesOf(retVal, componentSeparator) + 1) < forceUpToFieldNum) { retVal = retVal + componentSeparator;
retVal = createStructureDefinition(theMessage, previousLeaf, theMessage.getName()); } else { Message message = ReflectionUtil.instantiateMessage(clazz, getFactory()); Holder<StructureDefinition> previousLeaf = new Holder<StructureDefinition>(); retVal = createStructureDefinition(message, previousLeaf, theMessage.getName());
/** * @param theContext the set of validation rules to be applied to messages parsed or encoded by * this parser (defaults to ValidationContextFactory.DefaultValidation) * * @deprecated use a dedicated {@link HapiContext} and set its ValidationContext property */ public void setValidationContext(ValidationContext theContext) { super.setValidationContext(theContext); // These parsers are not yet initialized when this is called during the Parser constructor if (xmlParser != null) { pipeParser.setValidationContext(theContext); xmlParser.setValidationContext(theContext); } }