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); }
throw new HL7Exception(Context.getMessageSourceService().getMessage( "ORUR01.error.improperlyFormattedOBX", new Object[] { PipeParser.encode(obx, new EncodingCharacters('|', "^~\\&")) }, null), HL7Exception.DATA_TYPE_ERROR, errorInHL7Queue);
/** * Returns the datatype and attempts to pipe-encode it. For example, a string implementation * might return "ST[Value^Value2]". This is only intended for logging/debugging purposes. */ static String toString(Type theType) { StringBuilder b = new StringBuilder(); b.append(theType.getClass().getSimpleName()); b.append("["); b.append(PipeParser.encode(theType, EncodingCharacters.defaultInstance())); b.append("]"); return b.toString(); }
/** * Returns the datatype and attempts to pipe-encode it. For example, a string implementation * might return "ST[Value^Value2]". This is only intended for logging/debugging purposes. */ static String toString(Type theType) { StringBuilder b = new StringBuilder(); b.append(theType.getClass().getSimpleName()); b.append("["); b.append(PipeParser.encode(theType, EncodingCharacters.defaultInstance())); b.append("]"); return b.toString(); }
/** * {@inheritDoc } */ @Override public String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception { return encode(type, encodingCharacters, getParserConfiguration(), null); }
/** * {@inheritDoc } */ @Override public String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception { return encode(type, encodingCharacters, getParserConfiguration(), null); }
/** * {@inheritDoc } */ @Override public String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception { return encode(structure, encodingCharacters, getParserConfiguration(), null); }
/** * {@inheritDoc } */ @Override public String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception { return encode(structure, encodingCharacters, getParserConfiguration(), null); }
/** * Tests whether the given type falls within a maximum length. * * @return null of OK, an HL7Exception otherwise */ public HL7Exception testLength(Type type, int maxLength) { HL7Exception e = null; String encoded = PipeParser.encode(type, this.enc); if (encoded.length() > maxLength) { e = new ProfileNotFollowedException("Length of " + encoded.length() + " exceeds maximum of " + maxLength); } return e; }
/** * Tests whether the given type falls within a maximum length. * * @return null of OK, an HL7Exception otherwise */ public HL7Exception testLength(Type type, int maxLength) { HL7Exception e = null; String encoded = PipeParser.encode(type, this.enc); if (encoded.length() > maxLength) { e = new ProfileNotFollowedException("Length of " + encoded.length() + " exceeds maximum of " + maxLength); } return e; }
/** * 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); }
/** * 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); }
/** * Returns given segment serialized as a pipe-encoded string. * * @param source segment to be encoded * @param encodingChars encoding characters to be used * @return encoded group */ public static String encode(Segment source, EncodingCharacters encodingChars) { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), null); }
/** * Returns given segment serialized as a pipe-encoded string. * * @param source segment to be encoded * @param encodingChars encoding characters to be used * @return encoded group */ public static String encode(Segment source, EncodingCharacters encodingChars) { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), null); }
/** * Encodes the given Type, using the given encoding characters. It is * assumed that the Type represents a complete field rather than a * component. * * @param source type to be encoded * @param encodingChars encoding characters to be used * @return encoded type */ public static String encode(Type source, EncodingCharacters encodingChars) { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), null); }
/** * Encodes the given Type, using the given encoding characters. It is * assumed that the Type represents a complete field rather than a * component. * * @param source type to be encoded * @param encodingChars encoding characters to be used * @return encoded type */ public static String encode(Type source, EncodingCharacters encodingChars) { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), null); }
/** * Returns given group serialized as a pipe-encoded string - this method is * called by encode(Message source, String encoding). * * @param source group to be encoded * @param encodingChars encoding characters to be used * @throws HL7Exception if an error occurred while encoding * @return encoded group */ public static String encode(Group source, EncodingCharacters encodingChars) throws HL7Exception { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), ""); }
/** * Returns given group serialized as a pipe-encoded string - this method is * called by encode(Message source, String encoding). * * @param source group to be encoded * @param encodingChars encoding characters to be used * @throws HL7Exception if an error occurred while encoding * @return encoded group */ public static String encode(Group source, EncodingCharacters encodingChars) throws HL7Exception { return encode(source, encodingChars, source.getMessage().getParser().getParserConfiguration(), ""); }
/** * {@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; }
/** * Tests a Type against the corresponding section of a profile. * * @param encoded optional encoded form of type (if you want to specify this -- if null, default * pipe-encoded form is used to check length and constant val) */ public List<HL7Exception> testType(Type type, AbstractComponent<?> profile, String encoded, String profileID) { List<HL7Exception> exList = new ArrayList<HL7Exception>(); if (encoded == null) encoded = PipeParser.encode(type, this.enc); testUsage(encoded, profile.getUsage(), profile.getName(), exList); if (!profile.getUsage().equals("X")) { checkDataType(profile.getDatatype(), type, exList); checkLength(profile.getLength(), profile.getName(), encoded, exList); checkConstantValue(profile.getConstantValue(), encoded, exList); testTypeAgainstTable(type, profile, profileID, exList); } return exList; }