/// <summary> <p>Returns a minimal amount of data from a message string, including only the /// data needed to send a response to the remote system. This includes the /// following fields: /// <ul><li>field separator</li> /// <li>encoding characters</li> /// <li>processing ID</li> /// <li>message control ID</li></ul> /// This method is intended for use when there is an error parsing a message, /// (so the Message object is unavailable) but an error message must be sent /// back to the remote system including some of the information in the inbound /// message. This method parses only that required information, hopefully /// avoiding the condition that caused the original error. The other /// fields in the returned MSH segment are empty.</p> /// </summary> public override ISegment GetCriticalResponseData(System.String message) { //try to get MSH segment int locStartMSH = message.IndexOf("MSH"); if (locStartMSH < 0) { throw new HL7Exception("Couldn't find MSH segment in message: " + message, HL7Exception.SEGMENT_SEQUENCE_ERROR); } int locEndMSH = message.IndexOf('\r', locStartMSH + 1); if (locEndMSH < 0) { locEndMSH = message.Length; } System.String mshString = message.Substring(locStartMSH, (locEndMSH) - (locStartMSH)); //find out what the field separator is char fieldSep = mshString[3]; //get field array System.String[] fields = Split(mshString, System.Convert.ToString(fieldSep)); ISegment msh = null; try { //parse required fields System.String encChars = fields[1]; char compSep = encChars[0]; System.String messControlID = fields[9]; System.String[] procIDComps = Split(fields[10], System.Convert.ToString(compSep)); //fill MSH segment System.String version = "2.4"; //default try { version = this.GetVersion(message); } catch (System.Exception) { /* use the default */ } msh = ParserBase.MakeControlMSH(version, Factory); Terser.Set(msh, 1, 0, 1, 1, System.Convert.ToString(fieldSep)); Terser.Set(msh, 2, 0, 1, 1, encChars); Terser.Set(msh, 10, 0, 1, 1, messControlID); Terser.Set(msh, 11, 0, 1, 1, procIDComps[0]); } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); throw new HL7Exception("Can't parse critical fields from MSH segment (" + e.GetType().FullName + ": " + e.Message + "): " + mshString, HL7Exception.REQUIRED_FIELD_MISSING); } return(msh); }
/// <summary> /// <p>Returns a minimal amount of data from a message string, including only the data needed to /// send a response to the remote system. This includes the following fields: /// <ul><li>field separator</li> /// <li>encoding characters</li> /// <li>processing ID</li> /// <li>message control ID</li></ul> /// This method is intended for use when there is an error parsing a message, (so the Message /// object is unavailable) but an error message must be sent back to the remote system including /// some of the information in the inbound message. This method parses only that required /// information, hopefully avoiding the condition that caused the original error.</p> /// </summary> /// /// <param name="message"> a String that contains an HL7 message. </param> /// /// <returns> The critical response data. </returns> public override ISegment GetCriticalResponseData(System.String message) { System.String version = this.GetVersion(message); ISegment criticalData = ParserBase.MakeControlMSH(version, this.Factory); Terser.Set(criticalData, 1, 0, 1, 1, this.ParseLeaf(message, "MSH.1", 0)); Terser.Set(criticalData, 2, 0, 1, 1, this.ParseLeaf(message, "MSH.2", 0)); Terser.Set(criticalData, 10, 0, 1, 1, this.ParseLeaf(message, "MSH.10", 0)); System.String procID = this.ParseLeaf(message, "MSH.11", 0); if (procID == null || procID.Length == 0) { procID = this.ParseLeaf(message, "PT.1", message.IndexOf("MSH.11")); //this field is a composite in later versions } Terser.Set(criticalData, 11, 0, 1, 1, procID); return(criticalData); }