/// <summary> /// Background Worker Do Work Event: fills in the filled fields list view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void bgw_DoWork(object sender, DoWorkEventArgs e) { try { UpdateFormCursor(Cursors.WaitCursor); List <FilledFields> fieldList = FilledFields.Calculate(msgs); foreach (FilledFields ff in fieldList) { ListViewItem lvi = new ListViewItem(ff.ID); lvi.SubItems.Add(ff.Name); lvi.SubItems.Add(ff.MinLength.ToString()); lvi.SubItems.Add(ff.AvergeLength.ToString()); lvi.SubItems.Add(ff.MaxLength.ToString()); AddListViewItems(lvi); } UpdateFormCursor(Cursors.Default); } catch (Exception ex) { Log.LogException(ex).ShowDialog(); } }
/// <summary> /// Calculates the filled in fields/components in the selected message. /// </summary> /// <param name="Messages">The message to check</param> /// <returns>A list of FilledFields with calculation logic for each object</returns> public static List <FilledFields> Calculate(List <string> Messages) { Dictionary <string, List <int> > fieldList = new Dictionary <string, List <int> >(); List <FilledFields> fieldItems = new List <FilledFields>(); foreach (string m in Messages) { HL7Lib.Base.Message msg = new Message(m); foreach (Segment s in msg.Segments) { foreach (Field f in s.Fields) { foreach (Component c in f.Components) { if (!String.IsNullOrEmpty(c.Value)) { string n = ""; if (String.IsNullOrEmpty(c.Name)) { n = c.ID + "+++|+++" + f.Name; } else { n = c.ID + "+++|+++" + f.Name + "-|-" + c.Name; } if (fieldList.ContainsKey(n)) { List <int> outLengths = new List <int>(); if (fieldList.TryGetValue(n, out outLengths)) { fieldList.Remove(n); outLengths.Add(c.Value.Length); fieldList.Add(n, outLengths); } } else { List <int> lengths = new List <int>(); lengths.Add(c.Value.Length); fieldList.Add(n, lengths); } } } } } } foreach (KeyValuePair <string, List <int> > kvp in fieldList) { FilledFields ff = new FilledFields(); ff.ID = kvp.Key.Split(new string[] { "+++|+++" }, StringSplitOptions.None).GetValue(0).ToString(); ff.Name = kvp.Key.Split(new string[] { "+++|+++" }, StringSplitOptions.None).GetValue(1).ToString(); ff.MinLength = kvp.Value.Min(); ff.MaxLength = kvp.Value.Max(); ff.AvergeLength = kvp.Value.Sum() / kvp.Value.Count; if (ff.Name != "Segment Name") { fieldItems.Add(ff); } } return(fieldItems); }