檢查報告整合範例
example using strucform2 (CefSharp) package using async function call
using CefSharp.Web;
using Newtonsoft.Json;
using strucform2;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;
using WindowsInput.Native;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
private StrucForm strucForm1; // Declare as a member of Form1
private ListView listViewPatients;
private Button buttonCloseStrucForms;
private Button button1stLine;
private Button buttonTemplateForm;
private Button buttonTemplateText;
private Button buttonSaveDoc;
private Button buttonLoadDoc;
private Button buttonResetDoc;
private Panel Report;
private ContextMenuStrip textContextMenu;
public Form1()
{
InitializeComponent();
InitializeListView(); // Initialize the list view
this.ClientSize = new Size(1050, 750);
}
private void InitializeListView()
{
listViewPatients = new ListView
{
Location = new Point(10, 50),
Size = new Size(1000, 690),
View = View.Details,
FullRowSelect = true
};
listViewPatients.Columns.Add("病歷號", 100);
listViewPatients.Columns.Add("姓名", 150);
listViewPatients.Columns.Add("年齡", 50);
listViewPatients.Columns.Add("性別", 50);
listViewPatients.Columns.Add("收件號", 150);
listViewPatients.Columns.Add("影像號", 150);
listViewPatients.Columns.Add("存檔狀態", 50);
// Add mock data to the ListView
var patients = GetMockPatients();
foreach (var patient in patients)
{
var listItem = new ListViewItem(patient.Chtno);
listItem.SubItems.Add(patient.Name);
listItem.SubItems.Add(patient.Age.ToString());
listItem.SubItems.Add(patient.Gender);
listItem.SubItems.Add(patient.Opdno);
listItem.SubItems.Add(patient.Pacsno);
listItem.SubItems.Add(patient.Status);
listViewPatients.Items.Add(listItem);
}
listViewPatients.DoubleClick += ListViewPatients_DoubleClick;
this.Controls.Add(listViewPatients);
}
private List<Patient> GetMockPatients()
{
return new List<Patient>
{
new Patient { Chtno = "500", Pacsno = "20230916000000", Opdno = "20230916000000", Name = "林小明", Age = 80, Gender = "女", Status = "暫存" },
new Patient { Chtno = "501", Pacsno = "20230916000001", Opdno = "20230916000001", Name = "王大同", Age = 65, Gender = "男", Status = "" },
new Patient { Chtno = "502", Pacsno = "20230916000002", Opdno = "20230916000002", Name = "陳麗麗", Age = 72, Gender = "女", Status = "暫存" },
new Patient { Chtno = "503", Pacsno = "20230916000003", Opdno = "20230916000003", Name = "張三", Age = 55, Gender = "男", Status = "暫存" },
};
}
private async void ListViewPatients_DoubleClick(object sender, EventArgs e)
{
if (listViewPatients.SelectedItems.Count > 0)
{
string chtno = listViewPatients.SelectedItems[0].Text;
Patient patient = GetMockPatients().Find(p => p.Chtno == chtno);
await AddReport(patient);
}
}
private async Task AddReport(Patient patient)
{
InitializeReportView(patient);
// Hide the patient list
listViewPatients.Visible = false;
Report.Visible = true;
var _DocAutoLoad = (patient.Status == "暫存");
// 設定 Configuration 初始化 subject 欄位
strucForm1.Configuration = new StructureConfiguration
{
DocAutoLoad = _DocAutoLoad, // 依照 HIS 存檔狀態,決定是否自動載入上次暫存報告內容
Preview = false, // 設定起始畫面為病歷預覽或編輯模式,預設 false 為編輯模式
UserID = "OL5", // 設定使用者代號
UserName = patient.Name, // 設定使用者姓名
Chtno = patient.Chtno, // 設定病歷號
Opdno = patient.Opdno, // 設定收件號
Pacsno = patient.Pacsno, // 設定影像號(AI 推論使用)
DeptNo = "33F0", // 部門代號
DocTypeID = "65fff9a8-da57-4e97-bed6-1a234667e8ef", // 設定 HIS 病歷欄位ID (例如 HIS 檢查報告),請填寫代表該文件種類的字典ID
DocTypeName = "Exam Report", // 設定放大視窗標題
BaselinePreset = "exam", // 設定結構化控制項種類 (OPD, IPD, exam, ER)
BaselineFormID = "f93afc97-9403-4613-bd67-2f683d805234", // 設定起始表單編號 (同門診空白純文字表單)
SubpanelFormID = "7011725e-81f5-421f-8caf-337c6f2f7a21", // 設定子頁面起始助手表單編號 (同門診小助手表單)
EnableParentTemplateShortcut = true, // 啟動切換表單功能列
EnableChildTemplateShortcut = true, // 啟動子表單切換功能列
F2Fix = true, // 固定切換表單功能列
Scutsource = new List<string> { "usr", "sub", "dpt", "sys" }, // 顯示個人,次專,專科,以及體系
Scutgroup = new List<string> { "檢查" }, // 只顯示檢查表單,範例 { "門", "急", "住", "檢查", "手術" }
showCharCount = false, // 設定是否顯示純文字字數計數
showSubpanel = false // 預設是否展開子頁面
};
// 結構化表單生成
await strucForm1.InitAsync();
// 設定右鍵選單
strucForm1.RightClickOccurred += (sender, args) =>
{
Point mouseLocation = args.MouseLocation;
textContextMenu.Show(strucForm1, mouseLocation);
};
}
private void InitializeReportView(Patient patient)
{
// Setup Report
Report = new Panel()
{
Location = new Point(5, 40),
Size = new Size(1020, 710),
Visible = false
};
this.Controls.Add(Report);
// setup content panel for strucForm1
Panel contentPanel = new Panel
{
Dock = DockStyle.Fill
};
Report.Controls.Add(contentPanel);
strucForm1 = new StrucForm();
strucForm1.Dock = DockStyle.Fill;
contentPanel.Controls.Add(strucForm1);
InitializeButton(patient);
InitializeContextMenu();
}
private void InitializeButton(Patient patient)
{
// Create a separate panel for buttons, docked at the bottom
Panel buttonPanel = new Panel
{
Dock = DockStyle.Bottom,
Height = 100 // Height for the button panel
};
Report.Controls.Add(buttonPanel);
// Setup button to close StrucForms
buttonCloseStrucForms = new Button
{
Text = "待檢病患",
Location = new Point(10, 10), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonCloseStrucForms.Click += (sender, e) => RemoveReportView();
buttonPanel.Controls.Add(buttonCloseStrucForms); // Add to buttonPanel
// Setup button to insert first line
button1stLine = new Button
{
Text = "將文字插入第一行",
Location = new Point(210, 10), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
button1stLine.Click += (sender, e) => add1stLine();
buttonPanel.Controls.Add(button1stLine); // Add to buttonPanel
// Setup button to insert template form
buttonTemplateForm = new Button
{
Text = "插入表單",
Location = new Point(410, 10), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonTemplateForm.Click += (sender, e) => addTemplateForm();
buttonPanel.Controls.Add(buttonTemplateForm); // Add to buttonPanel
// Setup button to insert template text
buttonTemplateText = new Button
{
Text = "插入範本文字",
Location = new Point(610, 10), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonTemplateText.Click += (sender, e) => addTemplateText();
buttonPanel.Controls.Add(buttonTemplateText); // Add to buttonPanel
// Setup button to SaveDoc
buttonSaveDoc = new Button
{
Text = "暫存",
Location = new Point(10, 50), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonSaveDoc.Click += (sender, e) => SaveDoc(patient);
buttonPanel.Controls.Add(buttonSaveDoc); // Add to buttonPanel
// Setup button to LoadDoc
buttonLoadDoc = new Button
{
Text = "取出暫存",
Location = new Point(210, 50), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonLoadDoc.Click += (sender, e) => LoadDoc();
buttonPanel.Controls.Add(buttonLoadDoc); // Add to buttonPanel
// Setup button to ResetDoc
buttonResetDoc = new Button
{
Text = "清空文字區塊",
Location = new Point(410, 50), // Adjusted location within the buttonPanel
Size = new Size(150, 30)
};
buttonResetDoc.Click += (sender, e) => ResetForm();
buttonPanel.Controls.Add(buttonResetDoc); // Add to buttonPanel
}
private void InitializeContextMenu()
{
textContextMenu = new ContextMenuStrip();
ToolStripMenuItem copyMenuItem = new ToolStripMenuItem("Copy", null, CopyText);
ToolStripMenuItem pasteMenuItem = new ToolStripMenuItem("Paste", null, PasteText);
ToolStripMenuItem cutMenuItem = new ToolStripMenuItem("Cut", null, CutText);
ToolStripMenuItem undoMenuItem = new ToolStripMenuItem("Undo", null, UndoText);
textContextMenu.Items.AddRange(new ToolStripItem[] { copyMenuItem, pasteMenuItem, cutMenuItem, undoMenuItem });
}
private void RemoveReportView()
{
// remove strucForm1 from Report
if (strucForm1 != null)
{
if (strucForm1.IsEnlarged)
{
strucForm1.RestoreToOriginalParent();
}
Report.Controls.Remove(strucForm1);
}
// remove Report
Report.Dispose();
// Show the patient list and hide report Report
listViewPatients.Visible = true;
Report.Visible = false;
}
// 與結構化控件互動範例
private void add1stLine()
{
strucForm1.InsertTemplate("more text at first line\n", 0);
}
private void addTemplateForm()
{
strucForm1.InsertTemplate("##7d53bbe6-9895-48a9-aa7b-d0b66b843d03##");
}
private void addTemplateText()
{
strucForm1.InsertTemplate("insert template text");
}
private async void SaveDoc(Patient patient)
{
await strucForm1.SaveDocAsync();
string jsonString = await strucForm1.GetJsonTextAsync();
Console.WriteLine("GetJsonTextAsync: " + jsonString);
// 將 JSON 字串轉換為 Dictionary<string, string>
Dictionary<string, string> jsonData = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
// 根據不同的鍵將資料賦值到變數中
string allText = jsonData.ContainsKey("all") ? jsonData["all"] : string.Empty;
string report = jsonData.ContainsKey("Report") ? jsonData["Report"] : string.Empty;
string impression = jsonData.ContainsKey("Impression") ? jsonData["Impression"] : string.Empty;
string comment = jsonData.ContainsKey("Comment") ? jsonData["Comment"] : string.Empty;
string note = jsonData.ContainsKey("note") ? jsonData["note"] : string.Empty;
Console.WriteLine("====Saved " + patient.Chtno +
"\n====All Text: =====\n" + allText +
"\n====Report: ====\n" + report +
"\n====Impression: ====\n" + impression +
"\n====Comment: ====\n" + comment +
"\n====note: ====\n" + note);
}
private async void LoadDoc()
{
await strucForm1.LoadDocAsync();
}
private void ResetForm()
{
strucForm1.ResetFreeTextForm();
}
private void CopyText(object sender, EventArgs e)
{
var inputSimulator = new InputSimulator();
inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
}
private void PasteText(object sender, EventArgs e)
{
var inputSimulator = new InputSimulator();
inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
}
private void CutText(object sender, EventArgs e)
{
var inputSimulator = new InputSimulator();
inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_X);
}
private void UndoText(object sender, EventArgs e)
{
var inputSimulator = new InputSimulator();
inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_Z);
}
}
public class Patient
{
public string Chtno { get; set; }
public string Opdno { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Pacsno { get; set; }
public string Gender { get; set; }
public string Status { get; set; }
}
}
範例說明
Last updated