---
# System prepended metadata

title: 個案統計

---

## 收案狀態
Attribute | Description | IsRequired| Remark
-|-|-|-
id | number | true | Primary Key
caseId | number | true | 個案管理Id
acceptDate | number | true | 收案日期
caseTypeId | number | true | 收案別Id
caseTypeName | String | false | 收案別名稱
caseStatusId | number | true | 收案狀態Id
caseStatusName | String | false | 收案狀態名稱
closeDate | timestamp | false | 結案日期
createdAt | timestamp | true | 建立時間(timestamp)
updatedAt | timestamp | false | 修改時間(timestamp)
### 查詢列表
```url=
GET /case/$caseId/acceptRecords
```
<!-- Query Params:
|  欄位 | 型態  | 預設   | 說明  | 
|---|---|---|---|---|
| page | number |1| 當前頁數|
| pageSize | number |10| 每頁結果數量，-1 為顯示所有|
| sort | string | createdAt | 排序欄位
| desc | boolean | false | 是否倒序排列？ -->

Response (成功):
```json=
{
    "success": true,
    "totoal": 20,
    "data": [
        {
            "id": 40,
            "caseId": 2212,
            "acceptDate": 1591001165037,
            "updateDate": 1591001165037,
            "caseTypeId": 5,
            "caseTypeName": "高血壓",
            "caseStatusId": 10,
            "caseStatusName": "前期",
            "closeDate": null,
            "createdAt": 1592901981763,
            "updatedAt": 1592901981763
        },
        {
            "id": 41,
            "caseId": 2212,
            "acceptDate": 1591087571247,
            "updateDate": 1591087571247,
            "caseTypeId": 6,
            "caseTypeName": "慢性肝炎",
            "caseStatusId": 14,
            "caseStatusName": "B肝",
            "closeDate": null,
            "createdAt": 1592901981763,
            "updatedAt": 1592901981763
        }
    ]
}
```

### 查詢
Request:
```url=
Get /case/acceptRecords/$id
```

Response:
```json=
{
  "success": true,
  "data": [
    {
      "id": 84,
      "caseStatusId": 17,
      "caseStatusName": "第一階段",
      "receiveDate": "1591001544687"
    }
  ]
}
```

### 新增
Request:
```url=
POST /case/acceptRecords
```
Payload：
```json=
{
    "caseId":2212,
    "receiveDate":1591001544687,
    "caseTypeId":7,
    "caseStatusId":17,
}
```
Response (成功):
```json=
{
    "success": true,
    "data": {
        "caseId": 2212,
        "createdAt": 1592902358334
    }
}
```

### 修改
Request:
```url=
PATCH /case/acceptRecords/$id
```
Payload：
```json=
{
    "caseTypeId":7,
    "caseStatusId":18,
    "receiveDate":1592902786440,
    "closeDate":null
}
```
Response (成功):
```json=
{
    "success": true,
    "data": {
        "caseId": 2212,
        "createdAt": 1592902786606
    }
}
```

# 個案統計
# 個案GIS地圖
* 依照國別/縣市/區域統計/收案別/收案狀態，分類個案數量成統計表
* 以下id/代碼都是暫時示意使用，真實情況會以縣市區圖資資料作為標準
* 區域界線請查另外一隻API # [國別/縣市/區域GIS界線經緯度](https://hackmd.io/VDSyv1RGTFaYO0RQgIOcbQ?view#%E5%9C%8B%E5%88%A5%E7%B8%A3%E5%B8%82%E5%8D%80%E5%9F%9FGIS%E7%95%8C%E7%B7%9A%E7%B6%93%E7%B7%AF%E5%BA%A6)

Query Params:
|  欄位 | 型態  | 預設   | 說明  | 
|---|---|---|---|---|
| country | number | TW | 國別 (必填)
| city | number |Id (台北)| 區域(縣市) (非必填)
| caseType | String | null | 收案別 (非必填)
| caseStatus | String | null | 收案狀態 (非必填)
```url=
GET /case/statistics
```

Attribute | Description | IsRequired| Remark
-|-|-|-
id | number | true | Primary Key (regionId)
countryCode | String | true | 國別代碼(city code)
cityCode | String | true | 縣市代碼(city code)
regionCode | String | true | 區域代碼(region code)
caseType | Object Array | true | 收案別
- id | number | true | 收案別Id
- name | String | true | 收案別名稱
- caseStatus | Object array | true | 收案狀態
- - id | number | true | 收案狀態Id
- - name | String | true | 收案狀態名稱
- - count | number | true | 數量


Response (成功):
```json=
{
    "success": true,
    "totoal": 20,
    "data": [
        {
            "id": 1, // regionId
            "countryCode": "TW",
            "cityCode": "Taipei",
            "regionCode": "Beitou", //北投
            "caseType": [
                {
                    "id": 1,
                    "name": "高血壓"
                    "caseStatus": [
                        {
                            "id": 1,
                            "name": "第一期",
                            "count": 5
                        },
                        ...
                    ]
                },
                ...
            ]
        }, {
            "id": 2, // regionId
            "countryCode": "TW",
            "cityCode": "Taipei",
            "regionCode": "Shilin", //士林
            "caseType": [
                {
                    "id": 2,
                    "name": "ECKD"
                    "caseStatus": [
                        {
                            "id": 5,
                            "name": "前期",
                            "count": 16
                        },
                        ...
                    ]
                },
                ...
            ]
        },
        ...
    ]
}
```

### 匯入個案
* 需要後端替換成Id欄位如下
*   1. cityName、regionName (Common Data)
*   2. managingOrganization (Organization)
*   3. nationality (Common Data)
*   4. caseTypeList
* 家族疾病史一律視為<span style="color:red">非個案</span>案例
Request:
```url=
POST /case/import
```
Payload：
```json=
{
    "cases": [
        {
            "username": "E111222333",
            "name": "王二文",
            "userNumber": "V100121201",
            "birthDate": "1990-12-21", 
            "departmentName": "MR0S",
            "height": 175, 
            "gender": "male",
            "telecomEmail": "XXX@gmail.com",
            "telecomSubEmail": null,
            "telecomPhone": "07-2225555#123",
            "address": "五甲三路101號",
            "cityName": "高雄市",
            "regionName": "鳳山區",
            "managingOrganization": "高雄榮民總醫院",
            "nationality": "台灣",
            "diseaseHistory": [ //個人罹病史
                { "date": 2019, "description": "高血壓"  },
                    ...
            ],
            "surgeryHistory": [ //個人開刀史
                { "date": 2019, "description": "脊椎側彎"  },
                    ...
            ],
            "familyHistory": [ //家族疾病史
                { 
                    "username": "A123456789",
                    "name": "王大明",
                    "birthDate": "1966-01-01",
                    "title": "哥哥",
                    "liveWithFamily": false,
                    "diseaseHistory": "心臟病、皮膚病",
                },
                ...
            ],
            "caseTypeList": [ //收案別、收案狀態
                {
                    "receiveDate": 1583991833330,
                    "caseType": "高血壓",
                    "caseStatus": "第一期"
                }
            ],
            "active": true
        },
        ...
    ]
}
```
Response (成功):
```json=
{
    "success": true,
    "total": 60
}
```
Response (失敗):
```json=
{
    "success": false,
    "details": [
        {
            "rowNo": 101,
            "msg": "非法的收案別"
        },
        ....
    ]
}
```







