Ejemplo n.º 1
0
        private void ProcessDataTypeColumn(HL7SchemaRepository repo, string hl7Version, DataType dt)
        {
            HtmlNode scrapedData = null;

            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Scraping table information for data type {0} version {1}.", dt.Name, hl7Version));
            try
            {
                string       url    = string.Format("http://hl7-definition.caristix.com:9010/Default.aspx?version=HL7%20v{0}&dataType={1}", hl7Version, dt.Name);
                var          Webget = new HtmlWeb();
                HtmlDocument doc    = Webget.Load(url);
                scrapedData = doc.DocumentNode.SelectSingleNode("//table[@id='grdResult']");
            }
            catch (Exception ex)
            {
                _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Failed to scrape DataTypeColumn for version {0} column {1}. ERROR: {2}", hl7Version, dt.Name, ex.Message));
            }

            if (scrapedData != null)
            {
                foreach (HtmlNode node in scrapedData.ChildNodes)
                {
                    if (node.Name == "tr")
                    {
                        bool          isValid   = true;
                        const string  tdPattern = @"<td\b[^>]*?>(?<V>[\s\S]*?)</\s*td>";
                        StringBuilder strNode   = new StringBuilder();
                        foreach (Match match in Regex.Matches(node.InnerHtml, tdPattern, RegexOptions.IgnoreCase))
                        {
                            string value = match.Groups["V"].Value;
                            strNode.Append(value + "|");
                        }

                        if (strNode.Length > 0)
                        {
                            strNode.Remove(strNode.Length - 1, 1);
                            DataTypeColumn newDataTypeColumn = new DataTypeColumn();
                            try
                            {
                                string[] splitData = strNode.ToString().Split('|');

                                newDataTypeColumn.Sequence   = splitData[0].Split('.')[1].Parse <long>();
                                newDataTypeColumn.Length     = splitData[1].Parse <long>();
                                newDataTypeColumn.IsOptional = bool.Parse(splitData[3] == "O" ? "true" : "false");
                                newDataTypeColumn.Name       = splitData[5];
                                newDataTypeColumn.DataType1  = dt;

                                const string aPattern = @"<a\b[^>]*?>(?<V>[\s\S]*?)</\s*a>";
                                foreach (Match match in Regex.Matches(splitData[2], aPattern, RegexOptions.IgnoreCase))
                                {
                                    string value = match.Groups["V"].Value;
                                    newDataTypeColumn.DataType = DataTypeMap(value);
                                }
                            }
                            catch (Exception ex)
                            {
                                _fileLogger.LogMessage(LogMessageType.ERROR, ex.Message);
                                isValid = false;
                            }

                            if (isValid)
                            {
                                repo.AddNew <DataTypeColumn>(newDataTypeColumn);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateSegment(string version, string segment)
        {
            HL7SchemaRepository repo = new HL7SchemaRepository();
            HtmlNodeCollection  scrapedSegmentData = null;

            try
            {
                _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Starting segment {0}, version {1}", segment, version));
                string url    = string.Format("http://hl7-definition.caristix.com:9010/Default.aspx?version=HL7%20v{0}&segment={1}", version, segment);
                var    Webget = new HtmlWeb();
                var    doc    = Webget.Load(url);
                scrapedSegmentData = doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[5]/div[1]/div[3]/table[1]/tr");
            }
            catch (Exception ex)
            {
                _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Failure scraping segment {0}, version {1}. ERROR: {2}", segment, version, ex.Message));
            }

            if (scrapedSegmentData != null)
            {
                foreach (HtmlNode node in scrapedSegmentData)
                {
                    if (node.Name == "tr")
                    {
                        Segment s = new Segment();
                        s.SegmentId = segment;
                        s.Version   = version;
                        bool          isValid   = true;
                        const string  tdPattern = @"<td\b[^>]*?>(?<V>[\s\S]*?)</\s*td>";
                        StringBuilder strNode   = new StringBuilder();
                        foreach (Match match in Regex.Matches(node.InnerHtml, tdPattern, RegexOptions.IgnoreCase))
                        {
                            string value = match.Groups["V"].Value;
                            strNode.Append(value + "|");
                        }

                        if (strNode.Length > 0)
                        {
                            strNode.Remove(strNode.Length - 1, 1);

                            try
                            {
                                string[] splitData = strNode.ToString().Split('|');

                                //0 Sequence string, split on .
                                string[] sequence = splitData[0].Split('.');
                                s.Sequence = long.Parse(sequence[1]);

                                //index 1 = length
                                s.Length = long.Parse(splitData[1]);

                                //index 2 - the type. needs to run agains regex to get
                                const string aPattern = @"<a\b[^>]*?>(?<V>[\s\S]*?)</\s*a>";
                                foreach (Match match in Regex.Matches(splitData[2], aPattern, RegexOptions.IgnoreCase))
                                {
                                    string value = match.Groups["V"].Value;
                                    s.DataType = DataTypeMap(value);
                                }

                                //index 3 optional
                                s.IsRequired = bool.Parse(splitData[3] == "R" ? "true" : "false");

                                //index 4 is repeating
                                s.IsRepeating = bool.Parse(splitData[4] == "*" ? "true" : "false");

                                //index 6 name
                                s.Name = splitData[6];
                            }
                            catch (Exception ex)
                            {
                                _fileLogger.LogMessage(LogMessageType.ERROR, ex.Message);
                                isValid = false;
                            }

                            if (isValid)
                            {
                                repo.AddNew <Segment>(s);
                            }
                        }
                    }
                }
            }
            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Ending segment {0}, version {1}", segment, version));
        }
Ejemplo n.º 3
0
        private void ScrapeDataTypeBy(string hl7Version)
        {
            HtmlNode scrapedData = null;

            try
            {
                string       url    = string.Format("http://hl7-definition.caristix.com:9010/Default.aspx?version=HL7%20v{0}", hl7Version);
                var          Webget = new HtmlWeb();
                HtmlDocument doc    = Webget.Load(url);
                scrapedData = doc.DocumentNode.SelectSingleNode("//select[@id='cbxDataType']");
            }
            catch (Exception ex)
            {
                _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Failed to scrape DataType for version {0}. ERROR: {1}", hl7Version, ex.Message));
            }

            if (scrapedData != null)
            {
                Parallel.ForEach(scrapedData.ChildNodes, option => {
                    if (option.InnerText != "- Choose a data type" & option.InnerText != "\r\n\t" & !string.IsNullOrEmpty(option.InnerText))
                    {
                        bool isValid             = true;
                        HL7SchemaRepository repo = new HL7SchemaRepository();
                        DataType dt = new DataType();

                        try
                        {
                            dt.Name    = option.InnerText;
                            dt.Version = hl7Version;
                        }
                        catch (Exception ex)
                        {
                            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Error creating DataType {0} version {1}. ERROR: {2}", option.InnerText, hl7Version, ex.Message));
                            isValid = false;
                        }

                        if (isValid)
                        {
                            repo.AddNew <DataType>(dt);
                            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Created DataType {0} version {1}", option.InnerText, hl7Version));
                        }

                        repo.Dispose();
                    }
                });

                #region standard for each
                //foreach (HtmlNode option in scrapedData.ChildNodes)
                //{
                //    if (option.InnerText != "- Choose a data type" & option.InnerText != "\r\n\t" & !string.IsNullOrEmpty(option.InnerText))
                //    {
                //        bool isValid = true;
                //        HL7SchemaRepository repo = new HL7SchemaRepository();
                //        DataType dt = new DataType();

                //        try
                //        {
                //            dt.Name = option.InnerText;
                //            dt.Version = hl7Version;
                //        }
                //        catch (Exception ex)
                //        {
                //            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Error creating DataType {0} version {1}. ERROR: {2}", option.InnerText, hl7Version, ex.Message));
                //            isValid = false;
                //        }

                //        if (isValid)
                //        {
                //            repo.AddNew<DataType>(dt);
                //            _fileLogger.LogMessage(LogMessageType.INFO, string.Format("Created DataType {0} version {1}", option.InnerText, hl7Version));
                //        }

                //        repo.Dispose();
                //    }
                //}
                #endregion
            }
        }