/// <param name="message">a parsed message to validate (note that MSH-9-1 and MSH-9-2 must be valued) /// </param> /// <returns> true if the message is OK /// </returns> /// <throws> HL7Exception if there is at least one error and this validator is set to fail on errors </throws> public virtual bool validate(Message message) { Terser t = new Terser(message); MessageRule[] rules = myContext.getMessageRules(message.Version, t.Get("MSH-9-1"), t.Get("MSH-9-2")); ValidationException toThrow = null; bool result = true; for (int i = 0; i < rules.Length; i++) { ValidationException[] ex = rules[i].test(message); for (int j = 0; j < ex.Length; j++) { result = false; ourLog.error("Invalid message", ex[j]); if (failOnError && toThrow == null) { toThrow = ex[j]; } } } if (toThrow != null) { throw new HL7Exception("Invalid message", toThrow); } return result; }
/// <param name="message">a parsed message to validate (note that MSH-9-1 and MSH-9-2 must be valued) /// </param> /// <returns> true if the message is OK /// </returns> /// <throws> HL7Exception if there is at least one error and this validator is set to fail on errors </throws> public virtual bool validate(Message message) { Terser t = new Terser(message); MessageRule[] rules = myContext.getMessageRules(message.Version, t.Get("MSH-9-1"), t.Get("MSH-9-2")); ValidationException toThrow = null; bool result = true; for (int i = 0; i < rules.Length; i++) { ValidationException[] ex = rules[i].test(message); for (int j = 0; j < ex.Length; j++) { result = false; ourLog.error("Invalid message", ex[j]); if (failOnError && toThrow == null) { toThrow = ex[j]; } } } if (toThrow != null) { throw new HL7Exception("Invalid message", toThrow); } return(result); }
/// <summary> Formats a Message object into an html table object using the given /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> public Table buildTable(Message source) { //get encoding characters ... Segment msh = (Segment)source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) { throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); } char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) { fieldSep = fieldSepString[0]; } System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... Table tbl = new Table(); encode((Group)source, en, tbl); return(tbl); }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding ("VB"). /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> protected internal override System.String doEncode(Message source) { //get encoding characters ... Segment msh = (Segment)source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) { throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); } char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) { fieldSep = fieldSepString[0]; } System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); if (encCharString == null) { throw new HL7Exception("Can't encode message: MSH-2 (encoding characters) is missing"); } if (encCharString.Length != 4) { throw new HL7Exception("Encoding characters '" + encCharString + "' invalid -- must be 4 characters", HL7Exception.DATA_TYPE_ERROR); } EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... return(encode((Group)source, en)); }