# 主要參數說明

## 公共方法及其描述

**`StrucForm`** 是一個自定義的 UserControl，集成了 WebView2 元件，用於顯示和互動 HTML 內容。它支持各種任務的異步和同步操作，包括初始化、加載和保存文檔、設置文本和處理事件。

| 異步                                                                 | 同步                                                     | 說明                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Task\<bool> **InitAsync**()                                        | bool **Init**()                                        | <p>使用特定模板或基線配置初始化表單。<br><strong>Return</strong>: true=成功，false=失敗</p>                                                                                                                                                                                                                                                                                                             |
| Task\<bool> **RequiredDoneAsync**()                                | bool **RequiredDone**()                                | <p>檢查表單 <strong>必填欄位</strong> 是否已完成。<br><strong>Return</strong>: true=成功，false=失敗</p>                                                                                                                                                                                                                                                                                             |
| Task\<bool> **ResetFreeTextFormAsync**()                           | bool **ResetFreeTextForm**()                           | <p>重置自由文本表單。<br><strong>Return</strong>: true=成功，false=失敗</p>                                                                                                                                                                                                                                                                                                                     |
| Task\<bool> **InsertTemplateAsync**(string text, int? cpos = null) | bool **InsertTemplate**(string text, int? cpos = null) | <p>在指定位置  cpos 插入模板文本或表單 ##<code>sheetID</code>##。<br><strong>Return</strong>: true=成功，false=失敗</p>                                                                                                                                                                                                                                                                               |
| Task\<string> **GetTextAsync**()                                   | string **GetText**()                                   | <p>從 WebView2 獲取文本內容。<br><strong>Return:</strong> string=成功，empty=失敗<br>回傳範例:<br>'\[comment:]\r\nThis is a comment section.\r\n\[report:]\r\nHere is the report content.\r\n\[impression:]\r\nImpression text here.'</p>                                                                                                                                                          |
| Task\<string> **GetJsonTextAsync**()                               | string **GetJsonText**()                               | <p>從 WebView2 獲取含 heading 的文本內容。<strong>eturn:</strong> string=成功，empty=失敗<br>回傳範例: <br>"{ 'all': '\[comment:]\r\nThis is a comment section.\r\n\[report:]\r\nHere is the report content.\r\n\[impression:]\r\nImpression text here.', 'comment': 'This is a comment section.\r\n', 'report': 'Here is the report content.\r\n', 'impression': 'Impression text here.\r\n' }"</p> |
| Task **ShowDialogAsync**(StructureConfiguration config)            |                                                        | 彈出結構化視窗使用                                                                                                                                                                                                                                                                                                                                                                         |
| Task\<bool> **SetTextAsyn**c(string value)                         | bool **SetText**(string value)                         | <p>在 WebView2 中設置文本內容。<br><strong>Return:</strong> string=成功，empty=失敗</p>                                                                                                                                                                                                                                                                                                         |
| Task\<bool> **SaveDocAsync**()                                     | bool **SaveDoc**()                                     | <p>保存表單文檔。<br><strong>Return:</strong> string=成功，empty=失敗</p>                                                                                                                                                                                                                                                                                                                     |
| Task\<bool> **LoadDocAsync**()                                     | bool **LoadDoc**()                                     | <p>加載表單文檔。<br><strong>Return:</strong> string=成功，empty=失敗</p>                                                                                                                                                                                                                                                                                                                     |
|                                                                    | void **MoveToNewWindow**()                             | 將 StrucForm 移動到新視窗。                                                                                                                                                                                                                                                                                                                                                               |
|                                                                    | void **RestoreToOriginalParent**()                     | 將 StrucForm 恢復到原始父控制項。                                                                                                                                                                                                                                                                                                                                                            |
|                                                                    | void **SendMessage**(string messageType, object data)  | 向 WebView2 元件發送消息。                                                                                                                                                                                                                                                                                                                                                                |

## Properties 屬性&#x20;

1. **Configuration**
   * **Type**: `StructureConfiguration`
   * **Description**: Gets or sets the configuration for the control.
   * ```json
     public class StructureConfiguration
     {
         // 必填使用者資料    
         public string UserID { get; set; } = "OL5"; // 使用者代號
         public string Idno { get; set; } = "A123456789"; // 身分證字號 (用來確認管制病歷權限)
         public string UserName { get; set; } = "none"; // 使用者姓名
         
         // 必填病人資料
         public string Chtno { get; set; } = "500"; // 必填設定病歷號
         public string Opdno { get; set; } = "20240401"; // 必填設定收件號
         public string DeptNo { get; set; } = "none"; // 必填病人收件作業部門代號四碼 33F0  (非使用者部門)  
         
         // 必填起始表單 BaselineJson, BaselineFormID 擇一填寫
         public string BaselineJson { get; set; } // 優先以內建 JSON 文件 設定作為起始表單
         public string BaselineFormID { get; set; } = "f93afc97-9403-4613-bd67-2f683d805234";  // 資料庫表單，預設純文字表單
         
         // 選填

         // 病人資料    
         public string Pacsno { get; set; } = "20240400001";   // 選填設定影像號(AI 推論使用)
         
         // 表單綁定 HIS 病歷欄位資料
         public string DocTypeID { get; set; } = "none";   // 設定 HIS 病歷欄位ID (例如 HIS 檢查報告, OPD SOAP)，請填寫代表該文件種類的字典ID
         public string DocTypeName { get; set; } = "DocTypeName";  // 設定放大視窗標題 SOAP，檢查報告
         public string BaselinePreset { get; set; } = "opd";   // HIS 作業種類設定 (opd, ipd, exam, er)        
      
         // 表單其他設定
         public string SubpanelFormID { get; set; } = "7011725e-81f5-421f-8caf-337c6f2f7a21"; // 設定子頁面起始助手表單編號 (預設門診小助手表單 7011725e-81f5-421f-8caf-337c6f2f7a21)
         public int LimitDictVal { get; set; } = 4000; // HIS 欄位字元數 byte 上限 (中文2 byte)
         public List<string> Scutsource { get; set; } = new List<string> { "usr", "sub", "dpt", "sys" }; // 顯示個人，次專，科部，或體系表單
         public List<string> Scutgroup { get; set; } = new List<string> { "門", "急", "住", "檢查", "手術" }; // 設定 "門", "急", "住", "檢查", "手術" 專用的快捷表單       
         public string DocDitto { get; set; } = "";  // 設定依 doctorID or deptNo 自動載入最近一次紀錄: DocDitto 預設 "" 不 ditto
         public bool DocAutoLoad { get; set; } = false;  // 設定是否載入本診次(opdno) 暫存報告內容
         public bool DocOverwrite { get; set; } = false;  // 是否自動複寫同 opdno 文件，預設 false ，使用者可另存新檔
         public bool ShortcutAutoSave { get; set; } = true; // 範本自動儲存
         public string Font { get; set; } = "system-ui, sans-serif, Microsoft Sans Serif";    
         public int FontSize { get; set; } = 16;  // 僅門診 opd 作業適用
         public string FontWeight { get; set; } = "bold";  // 僅門診 opd 作業適用
         public bool Preview { get; set; } = false;  // 設定起始畫面為病歷預覽或編輯模式，預設 false 為編輯模式
         public string URLRoot { get; set; } = "https://cghasp.cgmh.org.tw/structure/"; // 結構化 API 網址
         public string URLtemplate { get; set; } = "https://lvaiw.cgmf.org.tw/struc/"; // template API 網址
         public bool EnableParentTemplateShortcut { get; set; } = false;  // 啟動切換表單功能列
         public bool EnableChildTemplateShortcut { get; set; } = true;    // 啟動子表單切換功能列
         public bool F2Fix { get; set; } = false;   // 固定切換表單功能列
         public bool showCharCount { get; set; } = true;   // 設定是否顯示純文字字數計數
         public bool showSubpanel { get; set; } = false;  // 設定是否預設展開子頁面
         public bool Debug { get; set; } = true;  // 是否允許 Ctrl+D 顯示除錯視窗
         public int OnlineCheckTimer { get; set; } = 5; // time interval for online check (sec)
         public string OPDtext { get; set; } = "";  // init() 控件啟動後，自動插入 OPDtext 到OPD 段落輸入框中  20241123

     }
     ```
2. **IsEnlarged**
   * **Type**: `bool`
   * **Description**: Indicates if the control is currently enlarged. 檢查是否有開啟放大視窗，有的話 strucForm.dispose() 前請先 strucForm.RestoreToOriginalParent()
3. **IsOnline**
   * **Type**: `bool`
   * **Description**: Indicates if the control is currently online.

## Events 事件

### `RightClickOccurred` 事件

#### **定義**

`RightClickOccurred` 是一個自訂事件，用於通知外部訂閱者在 `StrucForm` 控件中發生滑鼠右鍵點擊操作時的詳細資訊。

#### **宣告**

```csharp
public event EventHandler<RightClickEventArgs> RightClickOccurred;
```

此事件的參數使用了 `RightClickEventArgs` 類別，它繼承自 `EventArgs`，並包含右鍵點擊的具體滑鼠位置資訊。使用方式及範例請參見 [事件及範例](https://cgmh-kj.gitbook.io/strucmed/his-jiao-huan-zheng-he-gui-ge/shi-jian-ji-fan-li#rightclickoccurred-shi-jian)。

### `OnDataSaved` 事件

`OnDataSaved` 是一個公開的事件，允許外部物件訂閱並在資料成功儲存時被觸發。這個事件使用了 C# 的標準 `EventHandler<T>`，其中泛型參數為 `string`，代表所傳遞的資料內容（例如儲存的 JSON 資料）。使用方式及範例請參見 [事件及範例](https://cgmh-kj.gitbook.io/strucmed/his-jiao-huan-zheng-he-gui-ge/shi-jian-ji-fan-li#ondatasaved-shi-jian)。

#### 宣告方式

```csharp
public event EventHandler<string> OnDataSaved;
```
