/// <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 Segment getCriticalResponseData(System.String message) { //try to get MSH segment int locStartMSH = message.IndexOf("MSH"); if (locStartMSH < 0) { throw new NuGenHL7Exception("Couldn't find MSH segment in message: " + message, NuGenHL7Exception.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)); Segment 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 = NuGenParser.makeControlMSH(version, Factory); Terser.set_Renamed(msh, 1, 0, 1, 1, System.Convert.ToString(fieldSep)); Terser.set_Renamed(msh, 2, 0, 1, 1, encChars); Terser.set_Renamed(msh, 10, 0, 1, 1, messControlID); Terser.set_Renamed(msh, 11, 0, 1, 1, procIDComps[0]); Terser.set_Renamed(msh, 12, 0, 1, 1, version); } catch (System.Exception e) { throw new NuGenHL7Exception("Can't parse critical fields from MSH segment (" + e.GetType().FullName + ": " + e.Message + "): " + mshString, NuGenHL7Exception.REQUIRED_FIELD_MISSING, e); } 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> public override Segment getCriticalResponseData(System.String message) { System.String version = getVersion(message); Segment criticalData = NuGenParser.makeControlMSH(version, Factory); Terser.set_Renamed(criticalData, 1, 0, 1, 1, parseLeaf(message, "MSH.1", 0)); Terser.set_Renamed(criticalData, 2, 0, 1, 1, parseLeaf(message, "MSH.2", 0)); Terser.set_Renamed(criticalData, 10, 0, 1, 1, parseLeaf(message, "MSH.10", 0)); System.String procID = parseLeaf(message, "MSH.11", 0); if (procID == null || procID.Length == 0) { procID = parseLeaf(message, "PT.1", message.IndexOf("MSH.11")); //this field is a composite in later versions } Terser.set_Renamed(criticalData, 11, 0, 1, 1, procID); return(criticalData); }