public ChoHL7Component(string value = null, ChoHL7Configuration configuration = null) { _configuration = configuration = configuration ?? ChoHL7Configuration.Instance; Value = configuration.Decode(value); }
public static ChoHL7Message ParseText(string inputText, Encoding encoding = null, ChoHL7Configuration configuration = null) { return(Parse(inputText.ToStream(encoding))); }
public static ChoHL7Message Parse(TextReader textReader, ChoHL7Configuration configuration = null) { ChoHL7Message msg = null; configuration = configuration ?? ChoHL7Configuration.Instance; bool _configCheckDone = false; bool?skip = false; string[] commentTokens = configuration.Comments; using (ChoPeekEnumerator <Tuple <long, string> > e = new ChoPeekEnumerator <Tuple <long, string> >( new ChoIndexedEnumerator <string>(textReader.ReadLines(configuration.SegmentSeperator.ToString(), ChoCharEx.NUL, false)).ToEnumerable(), (pair) => { //bool isStateAvail = IsStateAvail(); skip = false; //if (isStateAvail) //{ // if (!IsStateMatches(item)) // { // skip = filterFunc != null ? filterFunc(item) : false; // } // else // skip = true; //} //else // skip = filterFunc != null ? filterFunc(item) : false; if (skip == null) { return(null); } if (configuration.TraceSwitch.TraceVerbose) { //ChoETLFramework.WriteLog(configuration.TraceSwitch.TraceVerbose, Environment.NewLine); if (!skip.Value) { ChoETLFramework.WriteLog(configuration.TraceSwitch.TraceVerbose, "Loading line [{0}]...".FormatString(pair.Item1)); } else { ChoETLFramework.WriteLog(configuration.TraceSwitch.TraceVerbose, "Skipping line [{0}]...".FormatString(pair.Item1)); } } if (skip.Value) { return(skip); } if (pair.Item2.IsNullOrWhiteSpace()) { if (!configuration.IgnoreEmptyLine) { throw new ChoHL7Exception("Empty line found at [{0}] location.".FormatString(pair.Item1)); } else { if (configuration.TraceSwitch.TraceVerbose) { ChoETLFramework.WriteLog(configuration.TraceSwitch.TraceVerbose, "Ignoring empty line found at [{0}].".FormatString(pair.Item1)); } return(true); } } if (commentTokens != null && commentTokens.Length > 0) { foreach (string comment in commentTokens) { if (!pair.Item2.IsNull() && pair.Item2.StartsWith(comment, StringComparison.Ordinal)) //, true, Configuration.Culture)) { if (configuration.TraceSwitch.TraceVerbose) { ChoETLFramework.WriteLog(configuration.TraceSwitch.TraceVerbose, "Comment line found at [{0}]...".FormatString(pair.Item1)); } return(true); } } } if (!_configCheckDone) { configuration.Validate(pair.Item2); msg = CreateInstance(configuration); _configCheckDone = true; } return(false); })) { while (true) { Tuple <long, string> pair = e.Peek; if (pair == null) { break; } try { var segment = ChoHL7Segment.Parse(pair.Item2, pair.Item1, configuration); msg.Segments.Add(segment); } catch (Exception ex) { msg.SetError(ex, pair.Item1, pair.Item2); break; } e.MoveNext(); } } var iter = new ChoPeekEnumerator <ChoHL7Segment>(msg.Segments); try { if (msg.IsValid) { msg.Construct(iter); msg.IsValid = iter.Peek == null; if (iter.Peek != null) { msg.SetError("[Line: {1}]: Unrecognized '{0}' segment found in message.".FormatString(iter.Peek.TargetType, iter.Peek.LineNo)); } } } catch (Exception ex) { msg.SetError(ex); } return(msg); }
public static ChoHL7Message Parse(string filePath, ChoHL7Configuration configuration = null) { configuration = configuration ?? ChoHL7Configuration.Instance; return(Parse(new StreamReader(ChoPath.GetFullPath(filePath), configuration.GetEncoding(filePath), false, configuration.BufferSize), configuration)); }