/** * Encodes the given Type, using the given encoding characters. * It is assumed that the Type represents a complete field rather than a component. */ public static String encode(Type source, EncodingCharacters encodingChars) { StringBuffer field = new StringBuffer(); for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuffer comp = new StringBuffer(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.append(encodePrimitive(p, encodingChars)); comp.append(encodingChars.getSubcomponentSeparator()); } field.append(stripExtraDelimiters(comp.toString(), encodingChars.getSubcomponentSeparator())); field.append(encodingChars.getComponentSeparator()); } return stripExtraDelimiters(field.toString(), encodingChars.getComponentSeparator()); //return encode(source, encodingChars, false); }
/** * Encodes the given Type, using the given encoding characters. * It is assumed that the Type represents a complete field rather than a component. */ public static String encode(Type source, EncodingCharacters encodingChars) { StringBuffer field = new StringBuffer(); for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuffer comp = new StringBuffer(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.append(encodePrimitive(p, encodingChars)); comp.append(encodingChars.getSubcomponentSeparator()); } field.append(stripExtraDelimiters(comp.toString(), encodingChars.getSubcomponentSeparator())); field.append(encodingChars.getComponentSeparator()); } return stripExtraDelimiters(field.toString(), encodingChars.getComponentSeparator()); //return encode(source, encodingChars, false); }
public char delim(int level) { if(level == 0) return m_encodingChars.getFieldSeparator(); else if(level == 1) return m_encodingChars.getRepetitionSeparator(); else if(level == 2) return m_encodingChars.getComponentSeparator(); else if(level == 3) return m_encodingChars.getSubcomponentSeparator(); else if(level == 4) return m_encodingChars.getTruncationCharacter(); else throw new java.lang.Error(); }
public char delim(int level) { if(level == 0) return m_encodingChars.getFieldSeparator(); else if(level == 1) return m_encodingChars.getRepetitionSeparator(); else if(level == 2) return m_encodingChars.getComponentSeparator(); else if(level == 3) return m_encodingChars.getSubcomponentSeparator(); else if(level == 4) return m_encodingChars.getTruncationCharacter(); else throw new java.lang.Error(); }
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());
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());
EncLookup(EncodingCharacters ec) { characters[0] = ec.getFieldSeparator(); characters[1] = ec.getComponentSeparator(); characters[2] = ec.getSubcomponentSeparator(); characters[3] = ec.getRepetitionSeparator(); characters[4] = ec.getEscapeCharacter(); characters[5] = ec.getTruncationCharacter(); characters[6] = '\r'; char[] codes = {'F', 'S', 'T', 'R', 'E', 'L'}; for (int i = 0; i < codes.length; i++) { StringBuilder seq = new StringBuilder(); seq.append(ec.getEscapeCharacter()); seq.append(codes[i]); seq.append(ec.getEscapeCharacter()); encodings[i] = seq.toString(); } // Escaping of truncation # is not implemented yet. It may only be escaped if it is the first character that // exceeds the conformance length of the component (ch 2.5.5.2). As of now, this information is not // available at this place. encodings[5] = "#"; encodings[6] = "\\X000d\\"; } }
EncLookup(EncodingCharacters ec) { characters[0] = ec.getFieldSeparator(); characters[1] = ec.getComponentSeparator(); characters[2] = ec.getSubcomponentSeparator(); characters[3] = ec.getRepetitionSeparator(); characters[4] = ec.getEscapeCharacter(); characters[5] = ec.getTruncationCharacter(); characters[6] = '\r'; char[] codes = {'F', 'S', 'T', 'R', 'E', 'L'}; for (int i = 0; i < codes.length; i++) { StringBuilder seq = new StringBuilder(); seq.append(ec.getEscapeCharacter()); seq.append(codes[i]); seq.append(ec.getEscapeCharacter()); encodings[i] = seq.toString(); } // Escaping of truncation # is not implemented yet. It may only be escaped if it is the first character that // exceeds the conformance length of the component (ch 2.5.5.2). As of now, this information is not // available at this place. encodings[5] = "#"; encodings[6] = "\\X000d\\"; } }
/** * Fills a field with values from an unparsed string representing the field. * @param destinationField the field Type * @param data the field string (including all components and subcomponents; not including field delimiters) * @param encodingCharacters the encoding characters used in the message */ public void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception { String[] components = split(data, String.valueOf(encodingCharacters.getComponentSeparator())); for (int i = 0; i < components.length; i++) { String[] subcomponents = split(components[i], String.valueOf(encodingCharacters.getSubcomponentSeparator())); for (int j = 0; j < subcomponents.length; j++) { String val = subcomponents[j]; if (val != null) { val = Escape.unescape(val, encodingCharacters); } Terser.getPrimitive(destinationField, i+1, j+1).setValue(val); } } }
/** * Fills a field with values from an unparsed string representing the field. * @param destinationField the field Type * @param data the field string (including all components and subcomponents; not including field delimiters) * @param encodingCharacters the encoding characters used in the message */ public void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception { String[] components = split(data, String.valueOf(encodingCharacters.getComponentSeparator())); for (int i = 0; i < components.length; i++) { String[] subcomponents = split(components[i], String.valueOf(encodingCharacters.getSubcomponentSeparator())); for (int j = 0; j < subcomponents.length; j++) { String val = subcomponents[j]; if (val != null) { val = Escape.unescape(val, encodingCharacters); } Terser.getPrimitive(destinationField, i+1, j+1).setValue(val); } } }
/** @see java.lang.Object#hashCode */ public int hashCode() { return 7 * (int) this.getComponentSeparator() * (int) this.getEscapeCharacter() * (int) this.getFieldSeparator() * (int) this.getRepetitionSeparator() * (int) this.getSubcomponentSeparator() * (int) this.getTruncationCharacter(); }
/** @see java.lang.Object#hashCode */ public int hashCode() { return 7 * (int) this.getComponentSeparator() * (int) this.getEscapeCharacter() * (int) this.getFieldSeparator() * (int) this.getRepetitionSeparator() * (int) this.getSubcomponentSeparator() * (int) this.getTruncationCharacter(); }
/** @see java.lang.Object#equals */ public boolean equals(Object o) { if (o instanceof EncodingCharacters) { EncodingCharacters other = (EncodingCharacters) o; return (this.getFieldSeparator() == other.getFieldSeparator() && this.getComponentSeparator() == other.getComponentSeparator() && this.getEscapeCharacter() == other.getEscapeCharacter() && this.getRepetitionSeparator() == other.getRepetitionSeparator() && this.getSubcomponentSeparator() == other.getSubcomponentSeparator() && this.getTruncationCharacter() == other.getTruncationCharacter()); } else { return false; } }
/** @see java.lang.Object#equals */ public boolean equals(Object o) { if (o instanceof EncodingCharacters) { EncodingCharacters other = (EncodingCharacters) o; return (this.getFieldSeparator() == other.getFieldSeparator() && this.getComponentSeparator() == other.getComponentSeparator() && this.getEscapeCharacter() == other.getEscapeCharacter() && this.getRepetitionSeparator() == other.getRepetitionSeparator() && this.getSubcomponentSeparator() == other.getSubcomponentSeparator() && this.getTruncationCharacter() == other.getTruncationCharacter()); } else { return false; } }
/** * Fills a field with values from an unparsed string representing the field. * * @param destinationField * the field Type * @param data * the field string (including all components and subcomponents; * not including field delimiters) * @param encodingCharacters * the encoding characters used in the message */ @Override public void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception { String[] components = split(data, String.valueOf(encodingCharacters.getComponentSeparator())); for (int i = 0; i < components.length; i++) { String[] subcomponents = split(components[i], String.valueOf(encodingCharacters.getSubcomponentSeparator())); for (int j = 0; j < subcomponents.length; j++) { String val = subcomponents[j]; if (val != null) { val = getParserConfiguration().getEscaping().unescape(val, encodingCharacters); } Terser.getPrimitive(destinationField, i + 1, j + 1).setValue(val); } } }
/** * Fills a field with values from an unparsed string representing the field. * * @param destinationField * the field Type * @param data * the field string (including all components and subcomponents; * not including field delimiters) * @param encodingCharacters * the encoding characters used in the message */ @Override public void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception { String[] components = split(data, String.valueOf(encodingCharacters.getComponentSeparator())); for (int i = 0; i < components.length; i++) { String[] subcomponents = split(components[i], String.valueOf(encodingCharacters.getSubcomponentSeparator())); for (int j = 0; j < subcomponents.length; j++) { String val = subcomponents[j]; if (val != null) { val = getParserConfiguration().getEscaping().unescape(val, encodingCharacters); } Terser.getPrimitive(destinationField, i + 1, j + 1).setValue(val); } } }
char subc = encodingCharacters.getSubcomponentSeparator(); char cmpc = encodingCharacters.getComponentSeparator();
/** copies contents of "other" */ public EncodingCharacters(EncodingCharacters other) { this.fieldSep = other.getFieldSeparator(); this.encChars = new char[5]; setComponentSeparator(other.getComponentSeparator()); setRepetitionSeparator(other.getRepetitionSeparator()); setEscapeCharacter(other.getEscapeCharacter()); setSubcomponentSeparator(other.getSubcomponentSeparator()); setTruncationCharacter(other.getTruncationCharacter()); }
/** copies contents of "other" */ public EncodingCharacters(EncodingCharacters other) { this.fieldSep = other.getFieldSeparator(); this.encChars = new char[5]; setComponentSeparator(other.getComponentSeparator()); setRepetitionSeparator(other.getRepetitionSeparator()); setEscapeCharacter(other.getEscapeCharacter()); setSubcomponentSeparator(other.getSubcomponentSeparator()); setTruncationCharacter(other.getTruncationCharacter()); }
char subc = encodingCharacters.getSubcomponentSeparator(); char cmpc = encodingCharacters.getComponentSeparator();