# 其他巨集函數

## OPENURL 開啟外部網址函數

點選按鈕開啟指定網址。

**巨集函數說明**

**函數名稱**：OPENURL

**參數**：

* urlstring ：網址文字，也可使用函數組合成動態連結。

**用法**：

```csharp
OPENURL(urlstring)
```

範例：

{% code overflow="wrap" %}

```csharp
// open UpToDate 網頁資料

OPENURL("https://www.uptodate.com/contents/pain-control-in-the-critically-ill-adult-patient?search=fentany1%20dosing&search_resecult&selectedTitle=2%7E150&sage_type=default&display_rank=1#H144549897")
```

{% endcode %}

<figure><img src="https://1792893123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdwFoogk3W80yJlNR060h%2Fuploads%2FRN7hPsVa1yoyKsveOzmZ%2Fexternal%20link1.jpg?alt=media&#x26;token=4eaddd11-b3aa-4035-800a-094cbfc10e41" alt=""><figcaption><p>小助手表單</p></figcaption></figure>

建議按鈕名稱可設為 " ⮥ "，實際操作如下圖所示。本範例使用 AI 小助手表單為範例

<figure><img src="https://1792893123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdwFoogk3W80yJlNR060h%2Fuploads%2FHXmeztrRoffSbp3Yg8Ar%2Fexternal%20link2.jpg?alt=media&#x26;token=2650d788-6bd0-4ff0-804b-bc8b10b63799" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
OPENURL  函數僅適用結構化2.0視窗。目前在 [門診結構化2.0](https://cgmh-kj.gitbook.io/strucmed/biao-dan-ru-kou/biao-dan-ru-kou-gai-lun/men-zhen)，[檢查報告結構化2.0](https://cgmh-kj.gitbook.io/strucmed/biao-dan-ru-kou/biao-dan-ru-kou-gai-lun/jian-cha-bao-gao)，以及 門住診 [AI小助手](https://cgmh-kj.gitbook.io/strucmed/biao-dan-shi-yong/ai-xiao-zhu-shou-beta) 都可使用。
{% endhint %}

## MACRO 巨集函數

**巨集函數** 是一種可以根據指定的公式計算結果來動態更新特定元素內容的功能。本函數僅能使用在巨集按鈕。這在需要動態展示計算結果或更新頁面內容的場景中特別有用。

**巨集函數說明**

**函數名稱**：`MACRO`

**參數**：

* `id`：需要更新內容的元素標識。
* `formula`：純文字，或是函數公式，會被評估並用作更新內容的值。

**用法**：

```csharp
MACRO(id, formula)
```

## **CUSTOMFUNC 客製化函數**

使用者可在表單選項的 JS Script addon 區塊，自行設計 javascript 函數，然後利用 CUSTOMFUNC() 調用

Javascript 函數範例

```javascript
function checkDrug(){
	console.log('call checkDrug');
    var tracerForExam = [
        { tracer: 'Tc99m PYP', half: '360', exams: ['3-037', '3-050', '3-051'] },
        { tracer: 'Tc99m ECD', half: '360', exams: ['3-001', '3-005'] },
        { tracer: 'Tc99m MDP', half: '360', exams: ['3-060', '3-060A'] },
        { tracer: 'Tc99m DMSA', half: '360', exams: ['3-041'] },
        { tracer: 'Tc99m Phytate', half: '360', exams: ['3-056'] },
        { tracer: 'Tc99m TRODAT-1', half: '360', exams: ['3-007'] },
        { tracer: 'Tc99m ECD', half: '360', exams: ['3-001','3-005'] },
        { tracer: 'Tl-201', half: '4320', exams: ['3-052', '3-065'] },
        { tracer: 'I-131 Caps', half: '11548', exams: ['3-090', '3-016'] },
        { tracer: 'Tc99m', half: '360', exams: ['3-004', '3-005', '3-010', '3-034', '3-036', '3-038', '3-037', '3-050'] },
        { tracer: 'Tc99m MAG3', half: '360', exams: ['3-041'] },
        { tracer: 'I-131 NP59', half: '11548', exams: ['3-040'] },
        { tracer: 'Tc99m DTPA', half: '360', exams: ['3-030', '3-036', '3-038', '3-041', '3-054', '3-055'] },
        { tracer: 'Tc99m MAA', half: '360', exams: ['3-020', '3-054'] },
        { tracer: 'Tc99m Sestamibi', half: '360', exams: ['3-018', '3-052', '3-065'] },
        { tracer: 'Ga-67', half: '4698', exams: ['3-036', '3-061'] }
    ];

	var exam_ids = $('[itemid=38]').text();
	console.log('exam_ids: '+ exam_ids);		
	// Use setTimeout to delay fetching tracer_id by 100ms
	setTimeout(function() {
		var tracer_id = $('[itemid=28]').text();
		console.log('tracer_id: '+ tracer_id );	
		var allowed = false;
		
		// Loop through the tracerForExam array to find the matching tracer
        $.each(tracerForExam, function(index, tracerObj) {
            if (tracerObj.tracer === tracer_id) {
                // Set the value of tf to the corresponding half value
                $('[itemid=39]').text(tracerObj.half).keyup().blur(); 
                
                // Check if the exam_id string contains any of the exams in the tracer's list
                $.each(tracerObj.exams, function(i, exam) {
                    if (exam_ids.includes(exam)) { // Check if the exam_id string contains the current exam
                        allowed = true;
                        return false; // Exit loop once a match is found
                    }
                });
            }
        });
		console.log('allowed: '+ allowed);
		// Display result
		if (allowed) {            
			$('[itemid=40]').text("").keyup(); 
		} else {
			$('[itemid=40]').text(" 藥物錯誤 ").keyup(); 
		}
	}, 500); // Delay for 500ms (0.5 second)
}
```

然後在表單中使用巨集函數調用 CUSTOMFUNC("checkDrug") 呼叫調用。

<figure><img src="https://1792893123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdwFoogk3W80yJlNR060h%2Fuploads%2FQIZZ4LGxaMrSgx0kdvBT%2Fcustomfunc.jpg?alt=media&#x26;token=6c486f60-79ca-40b7-9259-b6dcffc46971" alt=""><figcaption><p>CUSTOMFUNC</p></figcaption></figure>
