コード例 #1
0
 public static bool TryParse(string line, ChoHL7Configuration configuration, out ChoHL7Message rec, out string errMsg)
 {
     rec    = null;
     errMsg = null;
     try
     {
         rec = Parse(line, configuration);
         return(true);
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
         return(false);
     }
 }
コード例 #2
0
 protected T GetValueAt <T>(int index)
 {
     if (Field != null && index < Field.Components.Count)
     {
         if (typeof(ChoHL7AbstractField).IsAssignableFrom(typeof(T)))
         {
             return(ChoHL7Message.CreateElementInstance <T>(Field.Configuration, Field.Components[index].ToNString(), Field.Configuration));
         }
         else
         {
             return(Field.Components[index].ToNString().CastTo <T>());
         }
     }
     else
     {
         return(default(T));
     }
 }
コード例 #3
0
        private static ChoHL7Message CreateInstance(ChoHL7Configuration configuration)
        {
            ChoHL7MessageType mt      = configuration.MessageType;
            ChoHL7Version     version = configuration.Version;

            ChoHL7Message msg = null;

            string messageTypeName = "ChoETL.HL7.Model.{0}.{1}".FormatString(version.ToString(), mt.ToString());

            if (!ChoHL7MessageCache.Instance.HL7MessageDict.ContainsKey(messageTypeName))
            {
                throw new ChoHL7Exception("Can't find '{0}' HL7 Message type.".FormatString(messageTypeName));
            }

            msg             = CreateInstance(ChoHL7MessageCache.Instance.HL7MessageDict[messageTypeName]) as ChoHL7Message;
            msg.Version     = version;
            msg.MessageType = mt;
            return(msg);
        }
コード例 #4
0
ファイル: ChoHL7Segment.cs プロジェクト: lanicon/ChoETL.HL7
 protected T[] GetValuesAt <T>(int index)
 {
     if (index < Fields.Count)
     {
         if (typeof(ChoHL7AbstractField).IsAssignableFrom(typeof(T)))
         {
             List <T> list = new List <T>();
             foreach (var field in Fields[index])
             {
                 list.Add(ChoHL7Message.CreateElementInstance <T>(Configuration, field));
             }
             return(list.ToArray());
         }
         else
         {
             return new T[] { }
         };
     }
     else
     {
         return new T[] { }
     };
 }
コード例 #5
0
 protected T GetDefaultValue <T>()
 {
     return(ChoHL7Message.CreateElementInstance <T>(Field.Configuration, Field.Value, Field.Configuration));
 }
コード例 #6
0
        static void Main(string[] args)
        {
            ChoETLFrxBootstrap.TraceLevel = System.Diagnostics.TraceLevel.Error;
            ChoETLFramework.Initialize();

            dynamic hl7Message = ChoHL7Message.Parse("Sample1.csv", new ChoHL7Configuration()
            {
                Comments = new string[] { ";" }
            });

            Console.WriteLine($"Version: {hl7Message.Version}");
            Console.WriteLine($"Name: {hl7Message.GetType().FullName}");
            Console.WriteLine($"MessageType: {hl7Message.MessageType}");
            Console.WriteLine($"IsValid: {hl7Message.IsValid}");
            Console.WriteLine($"Error Line No: {hl7Message.ErrorLineNo}");
            Console.WriteLine($"Error Line: {hl7Message.ErrorLine}");
            Console.WriteLine($"Err: {hl7Message.ErrorMsg}");
            Console.WriteLine($"Err Detail: {hl7Message.ErrorDetail}");

            return;

            MSH msh = hl7Message.MSH;

            Console.WriteLine("*** Encoding Chars: " + msh.MessageType);
            //Console.WriteLine("*** PatientID: " + hl7Message.ORU_R01_RESULTS_GROUP[0]);
            //foreach (var s in hl7Message.MSH)
            Console.WriteLine(hl7Message.MSH);
            Console.WriteLine(hl7Message.EVN);
            return;

            foreach (var g in hl7Message.ORU_R01_RESULTS_GROUP)
            {
                foreach (var g1 in g.ORU_R01_PATIENT_GROUP)
                {
                    Console.WriteLine(g1.PID.PatientID);
                    Console.WriteLine(g1.PID.PatientExternalID);

                    foreach (var pi in g1.PID.PatientInternalID)
                    {
                        Console.WriteLine(pi);
                    }
                    foreach (var pi in g1.PID.PatientName)
                    {
                        Console.WriteLine(pi);
                    }

                    Console.WriteLine(g1.PID.DateOfBirth);
                    Console.WriteLine(g1.PID.Sex);
                }
                //Console.WriteLine(g1.PID.PatientID);
            }
            //Console.WriteLine(hl7Message.ToString());
            //var hl7Message = new ChoHL7Message(ChoHL7Version.v2_3);
            //var hl7MSHSegment = new ChoHL7Segment("MSH");
            //hl7MSHSegment.Fields.Add(new ChoHL7Field("1"));

            //hl7Message.Segments.Add(hl7MSHSegment);
            //Console.WriteLine(hl7Message.ToString());

            //using (var p = new ChoHL7Reader("sample1.csv"))
            //{
            //    foreach (var r in p)
            //        Console.WriteLine(r);
            //}
        }
コード例 #7
0
        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);
        }