/// <summary> /// Formats a <see cref="IMessage"/> object into an HL7 message string using the given encoding. /// </summary> /// <param name="source">An <see cref="IMessage"/> object from which to construct an encoded message string.</param> /// <param name="encodingChars">Encoding characters to be used.</param> /// <returns>The encoded message.</returns> /// <exception cref="HL7Exception">Thrown if the data fields in the message do not permit encoding (e.g. required fields are null).</exception> /// <exception cref="EncodingNotSupportedException">Thrown if the requested encoding is not supported by this parser.</exception> public static string Encode(ISegment source, EncodingCharacters encodingChars) { var result = new StringBuilder(); result.Append(source.GetStructureName()); result.Append(encodingChars.FieldSeparator); // start at field 2 for MSH segment because field 1 is the field delimiter var startAt = 1; if (IsDelimDefSegment(source.GetStructureName())) { startAt = 2; } // loop through fields; for every field delimit any repetitions and add field delimiter after ... var numFields = source.NumFields(); for (var i = startAt; i <= numFields; i++) { try { var reps = source.GetField(i); for (var j = 0; j < reps.Length; j++) { var fieldText = Encode(reps[j], encodingChars); // if this is MSH-2, then it shouldn't be escaped, so un-escape it again if (IsDelimDefSegment(source.GetStructureName()) && i == 2) { fieldText = Escape.UnescapeText(fieldText, encodingChars); } result.Append(fieldText); if (j < reps.Length - 1) { result.Append(encodingChars.RepetitionSeparator); } } } catch (HL7Exception e) { Log.Error("Error while encoding segment: ", e); } result.Append(encodingChars.FieldSeparator); } // strip trailing delimiters ... return(StripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator)); }
public static IMessage MakeACK(ISegment inboundHeader, string ackCode) { if (!inboundHeader.GetStructureName().Equals("MSH")) { throw new NHapi.Base.HL7Exception( "Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")"); } // Find the HL7 version of the inbound message: // string version = null; try { version = Terser.Get(inboundHeader, 12, 0, 1, 1); } catch (NHapi.Base.HL7Exception) { // I'm not happy to proceed if we can't identify the inbound // message version. throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1"); } IMessage ackMessage = new ACK(); // Create a Terser instance for the outbound message (the ACK). Terser terser = new Terser(ackMessage); // Populate outbound MSH fields using data from inbound message ISegment outHeader = (ISegment)terser.getSegment("MSH"); DeepCopy.copy(inboundHeader, outHeader); // Now set the message type, HL7 version number, acknowledgement code // and message control ID fields: string sendingApp = terser.Get("/MSH-3"); string sendingEnv = terser.Get("/MSH-4"); terser.Set("/MSH-3", CommunicationName); terser.Set("/MSH-4", EnvironmentIdentifier); terser.Set("/MSH-5", sendingApp); terser.Set("/MSH-6", sendingEnv); terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh")); terser.Set("/MSH-9", "ACK"); terser.Set("/MSH-12", version); terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode); terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1)); return(ackMessage); }
/// <summary> /// Adds a method to check equality between to segment objects /// </summary> /// <param name="a">First segment</param> /// <param name="b">Second segment</param> /// <returns>True if the segments are equal</returns> public static bool IsEqual(this ISegment a, ISegment b) { bool result = true; string structName = a.GetStructureName(); if (structName != b.GetStructureName()) { result = false; } else { PipeParser p = new PipeParser(); string aMessage = p.Encode(a.Message); string bMessage = p.Encode(b.Message); int aIndex = aMessage.IndexOf(structName); int bIndex = bMessage.IndexOf(structName); if (aIndex == -1 || bIndex == -1) { result = false; } if (result) { string aStruct = aMessage.Substring(aIndex, aMessage.IndexOf("\r", aIndex) - aIndex); string bStruct = bMessage.Substring(bIndex, bMessage.IndexOf("\r", bIndex) - bIndex); result = (string.Compare(aStruct, bStruct) == 0); } } return(result); }
/// <summary> Populates the given error segment with information from this Exception.</summary> // TODO: this is out of sync with hapi see // https://github.com/hapifhir/hapi-hl7v2/blob/809516e3f4851d7cd97573efb6dedf24959a1063/hapi-base/src/main/java/ca/uhn/hl7v2/AbstractHL7Exception.java#L134 public virtual void populate(ISegment errorSegment) { //make sure it's an ERR if (!errorSegment.GetStructureName().Equals("ERR")) { throw new HL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName); } var rep = errorSegment.GetField(1).Length; //append after existing reps if (SegmentName != null) { Terser.Set(errorSegment, 1, rep, 1, 1, SegmentName); } if (SegmentRepetition >= 0) { Terser.Set(errorSegment, 1, rep, 2, 1, Convert.ToString(SegmentRepetition)); } if (FieldPosition >= 0) { Terser.Set(errorSegment, 1, rep, 3, 1, Convert.ToString(FieldPosition)); } Terser.Set(errorSegment, 1, rep, 4, 1, Convert.ToString(ErrorCode)); // this replaces the need to connect to the database Terser.Set(errorSegment, 1, rep, 4, 2, ErrorCode.GetName()); Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357"); Terser.Set(errorSegment, 1, rep, 4, 5, Message); }
public static IMessage MakeACK(ISegment inboundHeader, string ackCode) { if (!inboundHeader.GetStructureName().Equals("MSH")) throw new NHapi.Base.HL7Exception( "Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")"); // Find the HL7 version of the inbound message: // string version = null; try { version = Terser.Get(inboundHeader, 12, 0, 1, 1); } catch (NHapi.Base.HL7Exception) { // I'm not happy to proceed if we can't identify the inbound // message version. throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1"); } IMessage ackMessage = new ACK(); // Create a Terser instance for the outbound message (the ACK). Terser terser = new Terser(ackMessage); // Populate outbound MSH fields using data from inbound message ISegment outHeader = (ISegment)terser.getSegment("MSH"); DeepCopy.copy(inboundHeader, outHeader); // Now set the message type, HL7 version number, acknowledgement code // and message control ID fields: string sendingApp = terser.Get("/MSH-3"); string sendingEnv = terser.Get("/MSH-4"); terser.Set("/MSH-3", CommunicationName); terser.Set("/MSH-4", EnvironmentIdentifier); terser.Set("/MSH-5", sendingApp); terser.Set("/MSH-6", sendingEnv); terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh")); terser.Set("/MSH-9", "ACK"); terser.Set("/MSH-12", version); terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode); terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1)); return ackMessage; }
private static void SetObx2Fallback(IPrimitive obx2, ISegment segment, ParserOptions parserOptions) { if (obx2.Value == null) { if (!(parserOptions.DefaultObx2Type is null)) { Log.Debug($"setting default {segment.GetStructureName()}-{2} type to {parserOptions.DefaultObx2Type}"); obx2.Value = parserOptions.DefaultObx2Type; } } }
/// <summary> Sets the string value of the field specified. See class docs for location spec syntax.</summary> public virtual void Set(System.String spec, System.String value_Renamed) { SupportClass.Tokenizer tok = new SupportClass.Tokenizer(spec, "-", false); ISegment segment = getSegment(tok.NextToken()); int[] ind = getIndices(spec); if (log.DebugEnabled) { log.Debug("Setting " + spec + " seg: " + segment.GetStructureName() + " ind: " + ind[0] + " " + ind[1] + " " + ind[2] + " " + ind[3]); } Set(segment, ind[0], ind[1], ind[2], ind[3], value_Renamed); }
public static void MakeACK(ISegment inboundHeader, string ackCode, IMessage ackMessage, string errorMessage) { if (!inboundHeader.GetStructureName().Equals("MSH")) { throw new NHapi.Base.HL7Exception("Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")"); } // Find the HL7 version of the inbound message: string version = null; try { version = Terser.Get(inboundHeader, 12, 0, 1, 1); } catch (NHapi.Base.HL7Exception) { // I'm not happy to proceed if we can't identify the inbound // message version. throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1"); } // Create a Terser instance for the outbound message (the ACK). Terser terser = new Terser(ackMessage); // Populate outbound MSH fields using data from inbound message ISegment outHeader = (ISegment)terser.getSegment("MSH"); DeepCopy.copy(inboundHeader, outHeader); // Now set the message type, HL7 version number, acknowledgement code // and message control ID fields: string sendingApp = terser.Get("/MSH-3"); string sendingEnv = terser.Get("/MSH-4"); // Make sure you fill the MSH-3 and MSH-4 with the correct values // for you application, preferably with configuration terser.Set("/MSH-3", "HL7Client"); terser.Set("/MSH-4", "EnvironmentIdentifier"); terser.Set("/MSH-5", sendingApp); terser.Set("/MSH-6", sendingEnv); terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh")); terser.Set("/MSH-9", "ACK"); terser.Set("/MSH-12", version); terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode); terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1)); // Set error message if (errorMessage != null) { terser.Set("/ERR-7", errorMessage); } }
/// <summary> Populates the given error segment with information from this Exception.</summary> public virtual void populate(ISegment errorSegment) { //make sure it's an ERR if (!errorSegment.GetStructureName().Equals("ERR")) { throw new HL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName); } int rep = errorSegment.GetField(1).Length; //append after existing reps if (SegmentName != null) { Terser.Set(errorSegment, 1, rep, 1, 1, SegmentName); } if (SegmentRepetition >= 0) { Terser.Set(errorSegment, 1, rep, 2, 1, Convert.ToString(SegmentRepetition)); } if (FieldPosition >= 0) { Terser.Set(errorSegment, 1, rep, 3, 1, Convert.ToString(FieldPosition)); } Terser.Set(errorSegment, 1, rep, 4, 1, Convert.ToString(errCode)); Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357"); Terser.Set(errorSegment, 1, rep, 4, 5, Message); //try to get error condition text try { String desc = TableRepository.Instance.getDescription(357, Convert.ToString(errCode)); Terser.Set(errorSegment, 1, rep, 4, 2, desc); } catch (LookupException e) { ourLog.Debug("Warning: LookupException getting error condition text (are we connected to a TableRepository?)", e); } catch (InvalidOperationException e) { ourLog.Debug("Warning: InvalidOperationException getting error condition text (are we connected to a TableRepository? Is a valid ConnectionString configured?)", e); } }
/// <summary> Populates the given Segment object with data from the given XML Element. </summary> /// <summary> for the given Segment, or if there is an error while setting individual field /// values. </summary> /// /// <param name="segmentObject"> The segment object. </param> /// <param name="segmentElement"> Element describing the segment. </param> public virtual void Parse(ISegment segmentObject, System.Xml.XmlElement segmentElement) { SupportClass.HashSetSupport done = new SupportClass.HashSetSupport(); // for (int i = 1; i <= segmentObject.NumFields(); i++) { // String elementName = makeElementName(segmentObject, i); // done.add(elementName); // parseReps(segmentObject, segmentElement, elementName, i); // } System.Xml.XmlNodeList all = segmentElement.ChildNodes; for (int i = 0; i < all.Count; i++) { System.String elementName = all.Item(i).Name; if (System.Convert.ToInt16(all.Item(i).NodeType) == (short)System.Xml.XmlNodeType.Element && !done.Contains(elementName)) { done.Add(elementName); int index = elementName.IndexOf('.'); if (index >= 0 && elementName.Length > index) { //properly formatted element System.String fieldNumString = elementName.Substring(index + 1); int fieldNum = System.Int32.Parse(fieldNumString); this.ParseReps(segmentObject, segmentElement, elementName, fieldNum); } else { log.Debug( "Child of segment " + segmentObject.GetStructureName() + " doesn't look like a field: " + elementName); } } } //set data type of OBX-5 if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(segmentObject, this.Factory); } }
/// <summary> Populates the given Segment object with data from the given XML Element.</summary> /// <throws> HL7Exception if the XML Element does not have the correct name and structure. </throws> /// <summary> for the given Segment, or if there is an error while setting individual field values. /// </summary> public virtual void Parse(ISegment segmentObject, XmlElement segmentElement, ParserOptions parserOptions) { parserOptions = parserOptions ?? DefaultParserOptions; var done = new SupportClass.HashSetSupport(); // for (int i = 1; i <= segmentObject.NumFields(); i++) { // String elementName = makeElementName(segmentObject, i); // done.add(elementName); // parseReps(segmentObject, segmentElement, elementName, i); // } var all = segmentElement.ChildNodes; for (var i = 0; i < all.Count; i++) { var elementName = all.Item(i).Name; if (Convert.ToInt16(all.Item(i).NodeType) == (short)XmlNodeType.Element && !done.Contains(elementName)) { done.Add(elementName); var index = elementName.IndexOf('.'); if (index >= 0 && elementName.Length > index) { // properly formatted element var fieldNumString = elementName.Substring(index + 1); var fieldNum = int.Parse(fieldNumString); ParseReps(segmentObject, segmentElement, elementName, fieldNum); } else { Log.Debug("Child of segment " + segmentObject.GetStructureName() + " doesn't look like a field: " + elementName); } } } // set data type of OBX-5 if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0) { Varies.FixOBX5(segmentObject, Factory, parserOptions); } }
public static String Encode(ISegment source, EncodingCharacters encodingChars) { StringBuilder result = new StringBuilder(); result.Append(source.GetStructureName()); result.Append(encodingChars.FieldSeparator); //start at field 2 for MSH segment because field 1 is the field delimiter int startAt = 1; if (IsDelimDefSegment(source.GetStructureName())) startAt = 2; //loop through fields; for every field delimit any repetitions and add field delimiter after ... int numFields = source.NumFields(); for (int i = startAt; i <= numFields; i++) { try { IType[] reps = source.GetField(i); for (int j = 0; j < reps.Length; j++) { String fieldText = Encode(reps[j], encodingChars); //if this is MSH-2, then it shouldn't be escaped, so unescape it again if (IsDelimDefSegment(source.GetStructureName()) && i == 2) fieldText = Escape.unescape(fieldText, encodingChars); result.Append(fieldText); if (j < reps.Length - 1) result.Append(encodingChars.RepetitionSeparator); } } catch (HL7Exception e) { log.Error("Error while encoding segment: ", e); } result.Append(encodingChars.FieldSeparator); } //strip trailing delimiters ... return StripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator); }
/// <summary> /// Returns the expected XML element name for the given child of the given Segment. /// </summary> private string MakeElementName(ISegment s, int child) { return($"{s.GetStructureName()}.{child}"); }
/// <summary> Parses a segment string and populates the given Segment object. Unexpected fields are /// added as Varies' at the end of the segment. /// /// </summary> /// <throws> HL7Exception if the given string does not contain the </throws> /// <summary> given segment or if the string is not encoded properly /// </summary> public virtual void Parse(ISegment destination, System.String segment, EncodingCharacters encodingChars) { int fieldOffset = 0; if (IsDelimDefSegment(destination.GetStructureName())) { fieldOffset = 1; //set field 1 to fourth character of string Terser.Set(destination, 1, 0, 1, 1, System.Convert.ToString(encodingChars.FieldSeparator)); } System.String[] fields = Split(segment, System.Convert.ToString(encodingChars.FieldSeparator)); //destination.setName(fields[0]); for (int i = 1; i < fields.Length; i++) { System.String[] reps = Split(fields[i], System.Convert.ToString(encodingChars.RepetitionSeparator)); if (log.DebugEnabled) { log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator); } //MSH-2 will get split incorrectly so we have to fudge it ... bool isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2; if (isMSH2) { reps = new System.String[1]; reps[0] = fields[i]; } for (int j = 0; j < reps.Length; j++) { try { System.Text.StringBuilder statusMessage = new System.Text.StringBuilder("Parsing field "); statusMessage.Append(i + fieldOffset); statusMessage.Append(" repetition "); statusMessage.Append(j); log.Debug(statusMessage.ToString()); //parse(destination.GetField(i + fieldOffset, j), reps[j], encodingChars, false); IType field = destination.GetField(i + fieldOffset, j); if (isMSH2) { Terser.getPrimitive(field, 1, 1).Value = reps[j]; } else { Parse(field, reps[j], encodingChars); } } catch (HL7Exception e) { //set the field location and throw again ... e.FieldPosition = i; e.SegmentRepetition = MessageIterator.getIndex(destination.ParentStructure, destination).rep; e.SegmentName = destination.GetStructureName(); throw e; } } } //set data type of OBX-5 if (destination.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(destination, Factory); } }
/// <summary> /// Parses a segment string and populates the given Segment object. /// <para> /// Unexpected fields are added as Varies' at the end of the segment. /// </para> /// </summary> /// <param name="destination">Segment to parse the segment string into.</param> /// <param name="segment">Encoded segment.</param> /// <param name="encodingChars">Encoding characters to be used.</param> /// <param name="repetition">The repetition number of this segment within its group.</param> /// <param name="parserOptions">Contains configuration that will be applied when parsing.</param> /// <exception cref="HL7Exception"> /// If the given string does not contain the given segment or if the string is not encoded properly. /// </exception> public virtual void Parse(ISegment destination, string segment, EncodingCharacters encodingChars, int repetition, ParserOptions parserOptions) { parserOptions = parserOptions ?? DefaultParserOptions; var fieldOffset = 0; if (IsDelimDefSegment(destination.GetStructureName())) { fieldOffset = 1; // set field 1 to fourth character of string Terser.Set(destination, 1, 0, 1, 1, Convert.ToString(encodingChars.FieldSeparator)); } var fields = Split(segment, Convert.ToString(encodingChars.FieldSeparator)); for (var i = 1; i < fields.Length; i++) { var reps = Split(fields[i], Convert.ToString(encodingChars.RepetitionSeparator)); if (Log.DebugEnabled) { Log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator); } // MSH-2 will get split incorrectly so we have to fudge it ... var isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2; if (isMSH2) { reps = new string[1]; reps[0] = fields[i]; } for (var j = 0; j < reps.Length; j++) { try { var statusMessage = $"Parsing field {i + fieldOffset} repetition {j}"; Log.Debug(statusMessage); var field = destination.GetField(i + fieldOffset, j); if (isMSH2) { Terser.GetPrimitive(field, 1, 1).Value = reps[j]; } else { Parse(field, reps[j], encodingChars); } } catch (HL7Exception e) { // set the field location and throw again ... e.FieldPosition = i; if (repetition > 1) { e.SegmentRepetition = repetition; } e.SegmentName = destination.GetStructureName(); throw; } } } // set data type of OBX-5 if (destination.GetType().FullName.IndexOf("OBX") >= 0) { Varies.FixOBX5(destination, Factory, parserOptions); } }
/// <summary> Populates the given Segment object with data from the given XML Element.</summary> /// <throws> HL7Exception if the XML Element does not have the correct name and structure </throws> /// <summary> for the given Segment, or if there is an error while setting individual field values. /// </summary> public virtual void Parse(ISegment segmentObject, XmlElement segmentElement) { SupportClass.HashSetSupport done = new SupportClass.HashSetSupport(); // for (int i = 1; i <= segmentObject.NumFields(); i++) { // String elementName = makeElementName(segmentObject, i); // done.add(elementName); // parseReps(segmentObject, segmentElement, elementName, i); // } XmlNodeList all = segmentElement.ChildNodes; for (int i = 0; i < all.Count; i++) { String elementName = all.Item(i).Name; if (Convert.ToInt16(all.Item(i).NodeType) == (short) XmlNodeType.Element && !done.Contains(elementName)) { done.Add(elementName); int index = elementName.IndexOf('.'); if (index >= 0 && elementName.Length > index) { //properly formatted element String fieldNumString = elementName.Substring(index + 1); int fieldNum = Int32.Parse(fieldNumString); ParseReps(segmentObject, segmentElement, elementName, fieldNum); } else { log.Debug("Child of segment " + segmentObject.GetStructureName() + " doesn't look like a field: " + elementName); } } } //set data type of OBX-5 if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(segmentObject, Factory); } }
/// <summary> Returns the expected XML element name for the given child of a message constituent /// of the given class (the class should be a Composite or Segment class). /// </summary> /*private String makeElementName(Class c, int child) { * String longClassName = c.getName(); * String shortClassName = longClassName.substring(longClassName.lastIndexOf('.') + 1, longClassName.length()); * if (shortClassName.startsWith("Valid")) { * shortClassName = shortClassName.substring(5, shortClassName.length()); * } * return shortClassName + "." + child; * }*/ /// <summary>Returns the expected XML element name for the given child of the given Segment </summary> private String MakeElementName(ISegment s, int child) { return(s.GetStructureName() + "." + child); }
/// <summary> Returns the expected XML element name for the given child of a message constituent /// of the given class (the class should be a Composite or Segment class). /// </summary> /*private String makeElementName(Class c, int child) { String longClassName = c.getName(); String shortClassName = longClassName.substring(longClassName.lastIndexOf('.') + 1, longClassName.length()); if (shortClassName.startsWith("Valid")) { shortClassName = shortClassName.substring(5, shortClassName.length()); } return shortClassName + "." + child; }*/ /// <summary>Returns the expected XML element name for the given child of the given Segment </summary> private String MakeElementName(ISegment s, int child) { return s.GetStructureName() + "." + child; }
/// <summary> Parses a segment string and populates the given Segment object. Unexpected fields are /// added as Varies' at the end of the segment. /// /// </summary> /// <throws> HL7Exception if the given string does not contain the </throws> /// <summary> given segment or if the string is not encoded properly /// </summary> public virtual void Parse(ISegment destination, String segment, EncodingCharacters encodingChars) { int fieldOffset = 0; if (IsDelimDefSegment(destination.GetStructureName())) { fieldOffset = 1; //set field 1 to fourth character of string Terser.Set(destination, 1, 0, 1, 1, Convert.ToString(encodingChars.FieldSeparator)); } String[] fields = Split(segment, Convert.ToString(encodingChars.FieldSeparator)); for (int i = 1; i < fields.Length; i++) { String[] reps = Split(fields[i], Convert.ToString(encodingChars.RepetitionSeparator)); if (log.DebugEnabled) { log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator); } //MSH-2 will get split incorrectly so we have to fudge it ... bool isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2; if (isMSH2) { reps = new String[1]; reps[0] = fields[i]; } for (int j = 0; j < reps.Length; j++) { try { StringBuilder statusMessage = new StringBuilder("Parsing field "); statusMessage.Append(i + fieldOffset); statusMessage.Append(" repetition "); statusMessage.Append(j); log.Debug(statusMessage.ToString()); IType field = destination.GetField(i + fieldOffset, j); if (isMSH2) { Terser.getPrimitive(field, 1, 1).Value = reps[j]; } else { Parse(field, reps[j], encodingChars); } } catch (HL7Exception e) { //set the field location and throw again ... e.FieldPosition = i + fieldOffset; e.SegmentRepetition = MessageIterator.getIndex(destination.ParentStructure, destination).rep; e.SegmentName = destination.GetStructureName(); throw; } } } //set data type of OBX-5 if (destination.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(destination, Factory); } }
/// <summary> Populates the given error segment with information from this Exception.</summary> public virtual void populate(ISegment errorSegment) { //make sure it's an ERR if (!errorSegment.GetStructureName().Equals("ERR")) throw new HL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName); int rep = errorSegment.GetField(1).Length; //append after existing reps if (this.SegmentName != null) Terser.Set(errorSegment, 1, rep, 1, 1, this.SegmentName); if (this.SegmentRepetition >= 0) Terser.Set(errorSegment, 1, rep, 2, 1, System.Convert.ToString(this.SegmentRepetition)); if (this.FieldPosition >= 0) Terser.Set(errorSegment, 1, rep, 3, 1, System.Convert.ToString(this.FieldPosition)); Terser.Set(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode)); Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357"); Terser.Set(errorSegment, 1, rep, 4, 5, this.Message); //try to get error condition text try { System.String desc = TableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode)); Terser.Set(errorSegment, 1, rep, 4, 2, desc); } catch (LookupException e) { ourLog.Debug("Warning: LookupException getting error condition text (are we connected to a TableRepository?)", e); } }