/// <summary> /// Searches the specified file /// </summary> /// <param name="f">The file to search</param> /// <returns>A list of messages that match search query</returns> private List <string> SearchFile(string f) { try { List <string> msgList = new List <string>(); FileInfo fi = new FileInfo(f); StreamReader sr = new StreamReader(fi.FullName); string contents = sr.ReadToEnd(); sr.Close(); string[] msgs = contents.Split(new string[] { "MSH|" }, StringSplitOptions.RemoveEmptyEntries); foreach (string msg in msgs) { string m = "MSH|" + msg; HL7Lib.Base.Message message = new HL7Lib.Base.Message(m); if (SearchMessage(message)) { msgList.Add(message.DisplayString); } } return(msgList); } catch (Exception ex) { Log.LogException(ex).ShowDialog(); return(new List <string>()); } }
/// <summary> /// Calculates the stat chart values on the selected message components. /// </summary> /// <returns>The list of GraphItems to display in the chart.</returns> private List <GraphItems> ProcessStatChartItems() { try { List <GraphItems> gItems = new List <GraphItems>(); foreach (string m in Messages) { HL7Lib.Base.Message msg = new HL7Lib.Base.Message(m); List <HL7Lib.Base.Component> coms = msg.GetByID(componentID); if (coms != null && coms.Count == 1) { GraphItems gi = GraphItems.GetGraphItem(gItems, coms[0].Value); if (gi != null) { gItems.Remove(gi); int count = gi.Count + 1; gi = new GraphItems(coms[0].Value, count); gItems.Add(gi); } else { gi = new GraphItems(coms[0].Value, 1); gItems.Add(gi); } } } return(gItems); } catch (Exception ex) { Log.Instance.LogException(ex).Report(); return(new List <GraphItems>()); } }
/// <summary> /// Calculates the stat chart values on the Message Date/Time component of the MSH segment for Daily Traffic Stats. /// </summary> /// <returns>The list of GraphItems to display in the chart.</returns> private List <GraphItems> ProcessDailyStatChartItems() { try { int d1 = 0; int d2 = 0; int d3 = 0; int d4 = 0; int d5 = 0; int d6 = 0; int d7 = 0; List <GraphItems> gItems = new List <GraphItems>(); foreach (string m in Messages) { HL7Lib.Base.Message msg = new HL7Lib.Base.Message(m); List <HL7Lib.Base.Component> coms = msg.GetByID(componentID); if (coms != null && coms.Count == 1) { Nullable <DateTime> d = coms[0].Value.FromHL7Date(); if (d != null) { switch (d.Value.DayOfWeek) { case DayOfWeek.Sunday: d1++; break; case DayOfWeek.Monday: d2++; break; case DayOfWeek.Tuesday: d3++; break; case DayOfWeek.Wednesday: d4++; break; case DayOfWeek.Thursday: d5++; break; case DayOfWeek.Friday: d6++; break; case DayOfWeek.Saturday: d7++; break; } } } } gItems.Add(new GraphItems("Sunday", d1)); gItems.Add(new GraphItems("Monday", d2)); gItems.Add(new GraphItems("Tuesday", d3)); gItems.Add(new GraphItems("Wednesday", d4)); gItems.Add(new GraphItems("Thursday", d5)); gItems.Add(new GraphItems("Friday", d6)); gItems.Add(new GraphItems("Saturday", d7)); return(gItems); } catch (Exception ex) { Log.Instance.LogException(ex).Report(); return(new List <GraphItems>()); } }
/// <summary> /// LoadReport Method: Loads the specified report with the values in a list of messages /// </summary> /// <param name="ReportName">The report to load</param> /// <param name="Messages">The list of Messages to use in the report</param> public void LoadReport(string ReportName, List <string> Messages) { Columns = new List <ReportColumn>(); Items = new List <List <string> >(); if (Directory.Exists(Path.Combine(Application.StartupPath, "Reports"))) { if (File.Exists(Path.Combine(Path.Combine(Application.StartupPath, "Reports"), ReportName + ".xml"))) { XmlTextReader xtr = new XmlTextReader(Path.Combine(Path.Combine(Application.StartupPath, "Reports"), ReportName + ".xml")); xtr.Read(); XmlDocument xDoc = new XmlDocument(); xDoc.Load(xtr); XmlNodeList nodes = xDoc.SelectNodes("Report/Column"); foreach (XmlNode node in nodes) { ReportColumn rc = new ReportColumn(); rc.Name = node.InnerText.Replace("-", "").Replace(".", ""); rc.Header = node.InnerText; if (!Columns.Contains(rc)) { Columns.Add(rc); } } xtr.Close(); foreach (string m in Messages) { List <string> itemList = new List <string>(); HL7Lib.Base.Message msg = new HL7Lib.Base.Message(m); foreach (Segment s in msg.Segments) { foreach (Field f in s.Fields) { foreach (Component c in f.Components) { if (!String.IsNullOrEmpty(GetColumn(c.ID))) { itemList.Add(c.Value); } } } } Items.Add(itemList); } } } }
/// <summary> /// Searches the message using the search query. /// </summary> /// <param name="m">The message to search</param> /// <returns>Returns true if the message matches the search query</returns> private bool SearchMessage(HL7Lib.Base.Message m) { try { bool returnValue = false; foreach (string item in txtSearchTerms.Text.Split('|')) { bool allMatched = false; List <SearchTerm> searchTerms = SearchTerm.GetSearchTerms(item.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)); foreach (SearchTerm st in searchTerms) { HL7Lib.Base.Component c = m.GetByID(st.ID, st.Value.ToUpper()); if (!String.IsNullOrEmpty(c.ID)) { allMatched = true; } else { allMatched = false; break; } } if (allMatched) { returnValue = true; break; } } return(returnValue); } catch (Exception ex) { Log.LogException(ex).ShowDialog(); return(false); } }
/// <summary> /// Calculates the stat chart values on the Message Date/Time component of the MSH segment for Hourly Traffic Stats. /// </summary> /// <returns>The list of GraphItems to display in the chart.</returns> private List <GraphItems> ProcessHourlyStatChartItems() { try { int h0 = 0; int h1 = 0; int h2 = 0; int h3 = 0; int h4 = 0; int h5 = 0; int h6 = 0; int h7 = 0; int h8 = 0; int h9 = 0; int h10 = 0; int h11 = 0; int h12 = 0; int h13 = 0; int h14 = 0; int h15 = 0; int h16 = 0; int h17 = 0; int h18 = 0; int h19 = 0; int h20 = 0; int h21 = 0; int h22 = 0; int h23 = 0; List <GraphItems> gItems = new List <GraphItems>(); foreach (string m in Messages) { HL7Lib.Base.Message msg = new HL7Lib.Base.Message(m); List <HL7Lib.Base.Component> coms = msg.GetByID(componentID); if (coms != null && coms.Count == 1) { Nullable <DateTime> d = coms[0].Value.FromHL7Date(); if (d != null) { switch (d.Value.ToString("HH")) { case "00": h0++; break; case "01": h1++; break; case "02": h2++; break; case "03": h3++; break; case "04": h4++; break; case "05": h5++; break; case "06": h6++; break; case "07": h7++; break; case "08": h8++; break; case "09": h9++; break; case "10": h10++; break; case "11": h11++; break; case "12": h12++; break; case "13": h13++; break; case "14": h14++; break; case "15": h15++; break; case "16": h16++; break; case "17": h17++; break; case "18": h18++; break; case "19": h19++; break; case "20": h20++; break; case "21": h21++; break; case "22": h22++; break; case "23": h23++; break; } } } } gItems.Add(new GraphItems("01", h1)); gItems.Add(new GraphItems("02", h2)); gItems.Add(new GraphItems("03", h3)); gItems.Add(new GraphItems("04", h4)); gItems.Add(new GraphItems("05", h5)); gItems.Add(new GraphItems("06", h6)); gItems.Add(new GraphItems("07", h7)); gItems.Add(new GraphItems("08", h8)); gItems.Add(new GraphItems("09", h9)); gItems.Add(new GraphItems("10", h10)); gItems.Add(new GraphItems("11", h11)); gItems.Add(new GraphItems("12", h12)); gItems.Add(new GraphItems("13", h13)); gItems.Add(new GraphItems("14", h14)); gItems.Add(new GraphItems("15", h15)); gItems.Add(new GraphItems("16", h16)); gItems.Add(new GraphItems("17", h17)); gItems.Add(new GraphItems("18", h18)); gItems.Add(new GraphItems("19", h19)); gItems.Add(new GraphItems("20", h20)); gItems.Add(new GraphItems("21", h21)); gItems.Add(new GraphItems("22", h22)); gItems.Add(new GraphItems("23", h23)); gItems.Add(new GraphItems("00", h0)); return(gItems); } catch (Exception ex) { Log.Instance.LogException(ex).Report(); return(new List <GraphItems>()); } }