# HIS資料查詢 API

## HIS函數參數

```csharp
// Some code
public class StrucWebApiInput
{
    public string CHTNO { get; set; }
    public string OPDCSN { get; set; }
    public string USERIDNO { get; set; } // 身份證字號
    public DateTime TimeStamp { get; set; }
    public List<KeyValuePair<string, string>> Functions { get; set; }
}
public class StrucWebApiOutput
{
    public int Code { get; set; }
    public string Message { get; set; }
    public DateTime TimeStamp { get; set; }
    public List<FunctionValue> FunctionSets { get; set; }

    public StrucWebApiOutput()
    {
        FunctionSets = new List<FunctionValue>();
    }
}
public class FunctionValue
{
    public int Code { get; set; }
    public string Message { get; set; }
    public string Key { get; set; }
    public string Value { get; set; }
}
```

## 輸入參數

* CHTNO:病歷號&#x20;
* OPDCSN:門診號/住院號
* USERIDNO: 身份證字號, 判定是否有權限取得VIP特權病患的門急診病歷，沒有傳無法回傳特權病歷內容。
* TimeStamp:時間戳記
* Functions:
  * Key: 辨識用ID&#x20;
  * Value: [對應字串](#dui-ying-zi-chuan-shui-ming)

### 對應字串說明

應對字串以符號 " . "  區隔類別、搜尋條件、取值條件 ，可用類別如下:

* LABDATA:&#x20;
  * 搜尋條件:
    * InDays:幾日內的資料&#x20;
    * InDr:特定醫師開立&#x20;
    * InName:開立項目名稱(ex:WBC、Creatinine)；可用逗號,同時搜尋多個項目&#x20;
    * InItem:開立代碼(ex:72-001、72-505)；可用逗號,同時搜尋多個項目
    * InAbnormal:異常值(H,L，未填則包含所有異常)
  * 取值條件，限定一個
    * GetValueByName:取得特定項目名稱的數值(ex:WBC、Creatinine)&#x20;
    * GetDateByName:取得特定項目的日期(ex:WBC、Creatinine)&#x20;
    * GetAllString:將所有搜尋到的項目以文字格式回傳&#x20;
    * GetLatestString:將搜尋到的項目中，日期為最近日期的項目以文字格式回傳

### 對應字串範例

```
// Functions.Value
LABDATA.InDays(30).InDr(2517).InItem(72-001).InName(WBC,RBC).GetValueByName(WBC)
```

Sample query string:

```json
// Some query string
{
  "CHTNO": "500",
  "OPDCSN": "",
  "USERIDNO":"",   // 傳入參數新增USERIDNO(身份證字號)，判定是否有權限取得VIP病患的門急診病歷
  "TimeStamp": "",
  "Functions": [
    {
      "1": "LABDATA.InDays(180).GetValueByName(PCO2)"
    },
    {
      "2": "LABDATA.InDays(30).InItem(72-333).GetDateByName()"
    },
    {
      "3": "LABDATA.InDays(30).InItem(72-333).GetValueByName(Creatinine)"
    }
  ]
}
```

Sample c# code

```csharp
// Some code
void StructureFormWebApi()
{
    StrucWebApiInput input = new StrucWebApiInput()
    {
        CHTNO = "4007873",
        OPDCSN = "",
        USERIDNO = "",   // 傳入參數新增USERIDNO(身份證字號)，判定是否有權限取得VIP病患的門急診病歷
        TimeStamp = DateTime.Now,
        Functions = new List<KeyValuePair<string, string>>()
        {
            new KeyValuePair<string, string>("1", @"LABDATA.InDays(180).GetValueByName(PCO2)"),
            new KeyValuePair<string, string>("2", @"LABDATA.InDays(30).InItem(72-333).GetDateByName()"),
            new KeyValuePair<string, string>("3", @"LABDATA.InDays(30).InItem(72-333).GetValueByName(Creatinine)")
        }

    };
    string inputString = JsonConvert.SerializeObject(input);
    WebClient webClient1 = new WebClient();
    webClient1.Headers.Add("Content-Type", "application/json");
    webClient1.Encoding = Encoding.UTF8;
    var result = webClient1.UploadString(@"http://10.30.111.79:45678/api/StrucFunction/FetchData1", inputString);
    var res = JsonConvert.DeserializeObject<StrucWebApiOutput>(result);   
}
```

## 輸出參數

* Code:結果代碼
* Message:結果訊息&#x20;
* TimeStamp:時間戳記&#x20;
* FunctionSets:回傳清單(FunctionValue結構)&#x20;
  * FunctionValue:&#x20;
  * Code:結果代碼&#x20;
  * Message:結果訊息&#x20;
  * Key:對應輸入參數的Key值&#x20;
  * Value:結果值

### Sameple result 值

```json
// Some result 
{
  "Code": 0,
  "Message": "API呼叫成功",
  "TimeStamp": "2024-01-08T16:48:47+08:00",
  "FunctionSets": [
    {
      "Code": 0,
      "Message": "呼叫成功，SQL回傳對應資料",
      "Key": "1",
      "Value": "    38.4"
    },
    {
      "Code": 0,
      "Message": "呼叫成功，SQL回傳對應資料",
      "Key": "2",
      "Value": "20231220"
    },
    {
      "Code": 0,
      "Message": "呼叫成功，SQL回傳對應資料",
      "Key": "3",
      "Value": "1.06"
    }
  ]
}
```
