/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableNode) { int pos = 0; int suffixPos = -1; while (pos < tableNode.Text.Length && pos >= 0) { pos = tableNode.Text.IndexOf(HraTagText, pos); if (pos >= 0) { suffixPos = tableNode.Text.IndexOf(HraTagSuffix, pos); if (pos >= 0 && suffixPos > pos) { string tag = tableNode.Text.Substring(pos, suffixPos + HraTagSuffix.Length - pos); string sql = tableNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); DataTable theData = BCDB2.Instance.getDataTable(sql); string dataVal = ""; if (theData.Rows.Count > 0 && theData.Columns.Count > 0) { dataVal = theData.Rows[0][0].ToString(); } tableNode.Text = tableNode.Text.Replace(tag, dataVal); } } } }
/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableNode) { if (proband != null) { int pos = 0; int suffixPos = -1; while (pos < tableNode.Text.Length && pos >= 0) { pos = tableNode.Text.IndexOf(HraTagText, pos); if (pos >= 0) { suffixPos = tableNode.Text.IndexOf(HraTagSuffix, pos); if (pos >= 0 && suffixPos > pos) { string tag = tableNode.Text.Substring(pos, suffixPos + HraTagSuffix.Length - pos); string args = tableNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); string[] parts = args.Split(splitChars); int rule = -1; if (parts.Length > 0) { int.TryParse(parts[0], out rule); } bool bullets = false; if (parts.Length>1) { bool.TryParse(parts[1], out bullets); } string prefix = "<p>"; string suffix = "</p>"; if (bullets) { prefix = "<li>"; suffix = "</li>"; } if (rule > 0) { ParameterCollection pc = new ParameterCollection(); pc.Add("ruleID", rule); pc.Add("apptID", proband.apptid); string value = ""; using (SqlDataReader reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_getParagraphsByRule", pc)) { while (reader.Read()) { if (reader.IsDBNull(0) == false) value += (prefix + reader.GetValue(0).ToString() + suffix); } } tableNode.Text = tableNode.Text.Replace(tag, value); } } } } } }
public FreeTextNodeAdaptor(HtmlNodeFactory factory, AP.HtmlTextNode node) : base(node) { if (node.ParentNode != null) { throw new InvalidOperationException(); } _factory = factory; }
private void BuildTableFromResults(HtmlTextNode makeTableNode, DataTable theData) { HtmlNode firstRow = FindFirstRow(makeTableNode); HtmlNode firstlist = FindFirstList(makeTableNode); if (theData == null) { firstlist.ParentNode.RemoveChild(firstlist); return; } if (theData.Rows.Count==0) { firstlist.ParentNode.RemoveChild(firstlist); return; } for (int i = 0; i < theData.Rows.Count; i++) { HtmlNode newRow; HtmlTextNode newText = null; if (i == 0) newRow = firstRow; else { newRow = makeTableNode.OwnerDocument.CreateElement("li"); foreach (HtmlAttribute ha in firstRow.Attributes) { newRow.Attributes.Add(ha); } } string acc = ""; for (int j = 0; j < theData.Columns.Count; j++) { acc += (theData.Rows[i][j].ToString()) + " "; } acc = acc.Trim(); if (i == 0) { newText = makeTableNode; newText.Text = acc; } else { newText = makeTableNode.OwnerDocument.CreateTextNode(acc); newText.Text = acc; newRow.AppendChild(newText); firstRow.ParentNode.AppendChild(newRow); } } }
public override void ProcessTableCellByIndex(int row, int column, HtmlNode tableCellNode, HtmlTextNode cellTextNode) { if (column == 0) { tableCellNode.Attributes.Remove("align"); tableCellNode.Attributes.Add(tableCellNode.OwnerDocument.CreateAttribute("align", "right")); } else { tableCellNode.Attributes.Remove("align"); tableCellNode.Attributes.Add(tableCellNode.OwnerDocument.CreateAttribute("align", "left")); cellTextNode.Text = "<b>" + cellTextNode.Text + "</b>"; } }
/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableNode) { int pos = 0; int suffixPos = -1; while (pos < tableNode.Text.Length && pos >= 0) { pos = tableNode.Text.IndexOf(HraTagText, pos); if (pos >= 0) { suffixPos = tableNode.Text.IndexOf(HraTagSuffix, pos); if (pos >= 0 && suffixPos > pos) { string tag = tableNode.Text.Substring(pos, suffixPos + HraTagSuffix.Length - pos); string args = tableNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); int templateId = -1; int.TryParse(args, out templateId); string value = ""; if (templateId > 0) { DocumentTemplate dt = new DocumentTemplate(); dt.documentTemplateID = templateId; dt.SetPatient(proband); dt.BackgroundLoadWork(); dt.OpenHTML(); dt.UseDocArgs = UseDocArgs; dt.ProcessDocument(); value = dt.htmlText; HtmlNode body = dt.FindNodeByName(dt.doc.DocumentNode, "body"); StripNonInsertNodes(body); if (body != null) { value = body.InnerHtml; } tableNode.Text = tableNode.Text.Replace(tag, value); } } } } }
/**********************************************************************/ private void PerformPedigreeReplacement(HtmlTextNode pedigreeNode) { int pos = pedigreeNode.Text.IndexOf(HraTagText, 0); int suffixPos = pedigreeNode.Text.IndexOf(HraTagSuffix); if (suffixPos > pos) { string args = pedigreeNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); string[] parts = args.Split(splitChars); if (parts.Length == 2) { int.TryParse(parts[0], out width); int.TryParse(parts[1], out height); } PedigreeGenerator pg = new PedigreeGenerator(width, height,proband); Bitmap bmp; if (proband != null) { bmp = pg.GeneratePedigreeImage(proband); } else { bmp = pg.GeneratePedigreeImage(); } System.IO.MemoryStream stream = new System.IO.MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); var base64Data = Convert.ToBase64String(stream.ToArray()); HtmlNode newPedNode = pedigreeNode.OwnerDocument.CreateElement("img"); newPedNode.Attributes.Add(pedigreeNode.OwnerDocument.CreateAttribute("src", "data:image/png;base64," + base64Data)); newPedNode.Attributes.Add(pedigreeNode.OwnerDocument.CreateAttribute("style", "width:" + bmp.Width + "px; height:" + bmp.Height + "px")); pedigreeNode.ParentNode.ReplaceChild(newPedNode, pedigreeNode); } }
/**********************************************************************/ private void PerformRiskChartReplacement(HtmlTextNode riskChartNode) { int pos = riskChartNode.Text.IndexOf(HraTagText, 0); int suffixPos = riskChartNode.Text.IndexOf(HraTagSuffix); if (suffixPos > pos) { if (proband.HasBreastCancer() || proband.gender.ToLower().StartsWith("m")) { riskChartNode.ParentNode.RemoveChild(riskChartNode); } else { string args = riskChartNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); string[] parts = args.Split(splitChars); if (parts.Length == 2) { int.TryParse(parts[0], out width); int.TryParse(parts[1], out height); } RiskChartGenerator rcg = new RiskChartGenerator(width, height, proband); Bitmap bmp = rcg.GenerateRiskChartImage(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); var base64Data = Convert.ToBase64String(stream.ToArray()); HtmlNode newRCNode = riskChartNode.OwnerDocument.CreateElement("img"); newRCNode.Attributes.Add(riskChartNode.OwnerDocument.CreateAttribute("src", "data:image/png;base64," + base64Data)); newRCNode.Attributes.Add(riskChartNode.OwnerDocument.CreateAttribute("style", "width:" + bmp.Width + "px; height:" + bmp.Height + "px")); riskChartNode.ParentNode.ReplaceChild(newRCNode, riskChartNode); } } }
public HtmlTextNodeAdapter(AP.HtmlTextNode node) : base(node) { }
/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableNode) { int pos = tableNode.Text.IndexOf(HraTagText, 0); int suffixPos = tableNode.Text.IndexOf(HraTagSuffix); if (suffixPos > pos) { string sql = tableNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); DataTable theData = BCDB2.Instance.getDataTable(sql); BuildTableFromResults(tableNode, theData); } }
public static IHtmlTextNode AsTextNode(this AP.HtmlTextNode node) { return(new HtmlTextNodeAdapter(node)); }
public virtual void ProcessTableCellByIndex(int row, int column, HtmlNode tableCellNode, HtmlTextNode cellTextNode) { }
public void HandleText(HtmlTextNode node) { if (IsTag (node.Text)) node.Text = ""; char[] ch = HttpUtility.HtmlDecode (node.Text).ToCharArray (); int start = 0; int length = ch.Length; textElementIdx++; if (flush) { FlushBlock (); flush = false; } if (inIgnorableElement != 0) { return; } char c; bool startWhitespace = false; bool endWhitespace = false; if (length == 0) { return; } int end = start + length; for (int i = start; i < end; i++) { if (IsWhiteSpace (ch [i])) { ch [i] = ' '; } } while (start < end) { c = ch [start]; if (c == ' ') { startWhitespace = true; start++; length--; } else { break; } } while (length > 0) { c = ch [start + length - 1]; if (c == ' ') { endWhitespace = true; length--; } else { break; } } if (length == 0) { if (startWhitespace || endWhitespace) { if (!sbLastWasWhitespace) { textBuilder.Append (' '); tokenBuilder.Append (' '); } sbLastWasWhitespace = true; } else { sbLastWasWhitespace = false; } lastEvent = NBoilerpipeContentHandler.Event.WHITESPACE; return; } if (startWhitespace) { if (!sbLastWasWhitespace) { textBuilder.Append (' '); tokenBuilder.Append (' '); } } if (blockTagLevel == -1) { blockTagLevel = tagLevel; } textBuilder.Append (ch, start, length); tokenBuilder.Append (ch, start, length); if (endWhitespace) { textBuilder.Append (' '); tokenBuilder.Append (' '); } sbLastWasWhitespace = endWhitespace; lastEvent = NBoilerpipeContentHandler.Event.CHARACTERS; currentContainedTextElements.Add (textElementIdx); }
private void BuildTableFromResults(HtmlTextNode makeTableNode, DataTable theData) { HtmlNode firstColumn = FindFirstColumn(makeTableNode); HtmlNode firstRow = FindFirstRow(makeTableNode); HtmlNode firsttable = FindFirstTable(makeTableNode); if (theData == null) { firsttable.ParentNode.RemoveChild(firsttable); return; } if (theData.Rows.Count==0) { firsttable.ParentNode.RemoveChild(firsttable); return; } for (int i = 0; i < theData.Rows.Count; i++) { HtmlNode newRow; if (i == 0) newRow = firstRow; else { newRow = makeTableNode.OwnerDocument.CreateElement("tr"); foreach(HtmlAttribute ha in firstRow.Attributes) { newRow.Attributes.Add(ha); } } for (int j = 0; j < theData.Columns.Count; j++) { HtmlNode newCell = null; HtmlTextNode newText = null; if (!(i == 0 && j == 0)) { newCell = makeTableNode.OwnerDocument.CreateElement("td"); foreach (HtmlAttribute ha in firstColumn.Attributes) { newCell.Attributes.Add(ha); } newText = makeTableNode.OwnerDocument.CreateTextNode(theData.Rows[i][j].ToString()); if (string.IsNullOrEmpty(newText.InnerHtml)) newText.InnerHtml = " "; newCell.AppendChild(newText); newRow.AppendChild(newCell); } else { newCell = firstColumn; newText = makeTableNode; newText.Text = theData.Rows[i][j].ToString(); } ProcessTableCellByIndex(i, j, newCell, newText); } if (i != 0) firstRow.ParentNode.AppendChild(newRow); } }
/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableNode) { int pos = 0; int suffixPos = -1; while (pos < tableNode.Text.Length && pos >= 0) { pos = tableNode.Text.IndexOf(HraTagText, pos); if (pos >= 0) { suffixPos = tableNode.Text.IndexOf(HraTagSuffix, pos); if (pos >= 0 && suffixPos > pos) { string tag = tableNode.Text.Substring(pos, suffixPos + HraTagSuffix.Length - pos); string relid = tableNode.Text.Substring(pos + HraTagText.Length, suffixPos - pos - HraTagText.Length); int r; if (int.TryParse(relid,out r)) { tableNode.Text = GetAreaProvidersByRelId(r); } } } } }
public static void VisitNode(HtmlTextNode textNode) { textNode.Text = textNode.Text.Trim(); }
/**********************************************************************/ private void GetDataAndReplaceTag(HtmlTextNode tableColumnNode) { string val = ""; MatchCollection matches = tagRegEx.Matches(tableColumnNode.Text); foreach (Match m in matches) { string formated = m.Value.Replace("[", "").Replace("]", ""); string[] parts = formated.Split(splitters); if (parts.Length == 2) { using (SqlConnection connection = new SqlConnection(BCDB2.Instance.getConnectionString())) { connection.Open(); SqlCommand cmdProcedure = new SqlCommand("sp_getPatientDataValue", connection); cmdProcedure.CommandType = CommandType.StoredProcedure; //SqlCommand command = new SqlCommand(sql, connection); cmdProcedure.Parameters.Add("@apptID", SqlDbType.NVarChar); if (proband == null) { cmdProcedure.Parameters["@apptID"].Value = SessionManager.Instance.GetActivePatient().apptid;//da.apptid; } else { cmdProcedure.Parameters["@apptID"].Value = proband.apptid;//da.apptid; } cmdProcedure.Parameters.Add("@tableName", SqlDbType.NVarChar); cmdProcedure.Parameters["@tableName"].Value = parts[0]; cmdProcedure.Parameters.Add("@columnName", SqlDbType.NVarChar); cmdProcedure.Parameters["@columnName"].Value = parts[1]; try { SqlDataReader reader = cmdProcedure.ExecuteReader(CommandBehavior.CloseConnection); if (reader != null) { while (reader.Read()) { if (reader.IsDBNull(0) == false) val = reader.GetValue(0).ToString(); } } } catch (Exception e) { Logger.Instance.WriteToLog(e.ToString()); } } tableColumnNode.Text = tableColumnNode.Text.Replace(m.Value, val); } } //PerformTagReplacement(tableColumnNode, val); }