# 洗腎護照聊天室 API 文件 1.0 ###### tags: `API` :::info server: ::: :::danger 注意事項: 1. 依照 identify_key 不同需初始化某些變數 * identify_key 為 0 的使用者 * chatroom_page_index = 0 * identify_key 為 1 的使用者 * send_to = 0 2. 修正洗腎護照登入畫面同意書的日期區間 ::: ## 留言板入口畫面 :::warning **==GET== /app_api/chatroom_page** 概述:使用者從個案搜尋頁面點選聊天室按鈕所連結之頁面,會根據登入身分有所不同 * Parameters * user_id <font color=#FF0000>(必填)</font> * chatroom_page_index <font color=#FF0000>(若使用者 identify_key 為 0 則必填,值為 0 or 1)</font> * dialysis_room_id <font color=#FF0000>(若使用者 identify_key 為 1 或 chatroom_page_index = 1 時必填)</font> 使用情境: 1. 使用者 identify_key 為 0,讀取洗腎室未讀訊息列表 * user_id: 1 * chatroom_page_index: 0 * dialysis_room_id: (空白字串,"") 2. 使用者 identify_key 為 0,選擇洗腎室未讀訊息列表中的某一洗腎室,回傳聊天紀錄中與該洗腎室有關之病人未讀訊息列表 * user_id: 1 * chatroom_page_index: 1 * dialysis_room_id: 11 (該洗腎室) 3. 使用者 identify_key 為 1, * user_id: 2 * chatroom_page_index: 1 * dialysis_room_id: 11 (登入時會拿到) * Responses | status | message | result | | ------ | ------- | ------ | | 200 | admin chatroom_page 0 成功 </br> admin chatroom_page 1 成功 </br> clinic chatroom_page 成功 | (見下表) | | 405 | 不支援所請求的方法 | [] | | 500 | 資料庫連接錯誤 </br> 資料庫取值錯誤 | [] | | input | | ----- | | user_1: 1 </br> chatroom_page_index: 0 </br> dialysis_room_id: | ```python= { "status": 200, "message": "admin chatroom_page 0 成功", "result": [ { "dialysis_room_id": 11, "dialysis_room_name": "花蓮慈濟醫院", "unread_count_total": "4" }, { "dialysis_room_id": 10, "dialysis_room_name": "花蓮嘉恩診所", "unread_count_total": "3" }, ... ``` | input | | ----- | | user_1: 1 </br> chatroom_page_index: 1 </br> dialysis_room_id: 11 | ```python= { "status": 200, "message": "get_chatroom 成功", "result": [ { "patient_id": 44, "name": "許愛月", "unread_count": 2 }, { "patient_id": 45, "name": "林豐南", "unread_count": 2 } ] } ``` | input | | ----- | | user_1: 2 </br> chatroom_page_index: 1 (don't care) </br> dialysis_room_id: 11 | ```python= { "status": 200, "message": "get_chatroom 成功", "result": [ { "patient_id": 44, "name": "許愛月", "unread_count": 3 }, { "patient_id": 45, "name": "林豐南", "unread_count": 0 } ] } ``` ::: ## 留言板訊息內容 :::warning **==GET== /app_api/get_chatroom** 概述:已有 user_id, dialysis_room_id, patient_id,呼叫此 API 回傳聊天室訊息內容(未讀訊息、歷史訊息) <font color=#FF0000>注意 1: 此 API 會重置後端資料庫中該使用者在該留言板中 unread 計數,所以以同樣參數呼叫此 API 或許不會得到相同結果,因為已讀了某些訊息</font> <font color=#FF0000>注意 2: 第一次被進入的留言板呼叫此 api 會得到result = []</font> * Parameters * user_id <font color=#FF0000>(必填)</font> * patient_id <font color=#FF0000>(必填)</font> * dialysis_room <font color=#FF0000>(必填)</font> * messages_per_page <font color=#FF0000>(用以獲取歷史訊息時必填)</font> * offset_id <font color=#FF0000>(用以獲取歷史訊息時必填)</font> 使用情境 1. 進入留言板 * user_id = 1 * patient_id = 44 * dialysis_room = 11 * messages_per_page = * offset_id = 2. 已在留言版頁面,想要獲取更多歷史訊息 * user_id = 1 * patient_id = 44 * dialysis_room = 11 * messages_per_page = n (想從 id 為 m 之訊息再往前取 n 筆) * offset_id = m (從 id 為 m 之訊息往前取) * Responses | status | message | result | | ------ | ------- | ------ | | 200 | get_chatroom 成功 | (見下表) | | 405 | 不支援所請求的方法 | [] | | 500 | 資料庫連接錯誤 </br> 資料庫取值錯誤 | [] | | input | | ----- | | user_id = 1 </br> patient_id = 44 </br> dialysis_room = 11 </br> messages_per_page = </br> offset_id = | ```python= { "status": 200, "message": "get_chatroom 成功", "result": [ { "id": 1, "user_id": 2, "account": "clinic", "patient_id": 44, "send_from": 11, "send_to": 0, "content": "傳送訊息測試 user id 2", "created_at": "2023-01-12T10:37:21", "reply_to_id": null, "reply_to_text": null, "identify_key": 1, "unit": "花蓮慈濟醫院" "read": 1 }, { "id": 2, "user_id": 2, "account": "clinic", "patient_id": 44, "send_from": 11, "send_to": 0, "content": "傳送訊息測試 user id 2", "created_at": "2023-01-12T10:37:28", "reply_to_id": null, "reply_to_text": null, "identify_key": 1, "unit": "花蓮慈濟醫院" "read": 1 }, ... ``` | input | 備註 | | ----- | --- | | user_id = 1 </br> patient_id = 44 </br> dialysis_room = 11 </br> messages_per_page = 5 </br> offset_id = 6 | 因為 offset_id = 6 所以收到之資料 id 皆應小於 6 ```python= { "status": 200, "message": "get_chatroom 成功", "result": [ { "id": 1, "user_id": 2, "account": "clinic", "patient_id": 44, "send_from": 11, "send_to": 0, "content": "傳送訊息測試 user id 2", "created_at": "2023-01-12T10:37:21", "reply_to_id": null, "reply_to_text": null, "identify_key": 1, "unit": "花蓮慈濟醫院" "read": 1 }, { "id": 2, "user_id": 2, "account": "clinic", "patient_id": 44, "send_from": 11, "send_to": 0, "content": "傳送訊息測試 user id 2", "created_at": "2023-01-12T10:37:28", "reply_to_id": null, "reply_to_text": null, "identify_key": 1, "unit": "花蓮慈濟醫院" "read": 1 }, { "id": 5, "user_id": 1, "account": "tzuchi", "patient_id": 44, "send_from": 0, "send_to": 11, "content": "傳送訊息測試 user id 1", "created_at": "2023-01-12T10:38:33", "reply_to_id": null, "reply_to_text": null, "identify_key": 0, "unit": "花蓮慈濟醫院admin" "read": 1 } ] } ``` ::: ## 傳送訊息 :::success **==POST== /app_api/send_message** 概述:插入一則訊息到資料庫,此 API 會回傳該筆訊息 * Request Body (form-data) * user_id <font color=#FF0000>(必填)</font> * patient_id <font color=#FF0000>(必填)</font> * send_to <font color=#FF0000>(若 identify_key = 0 必填為前面選擇之洗腎室編號,若 identify_key = 1 必填為 0)</font> * board_id * content 使用情境 1. admin 使用者對某一留言板傳送一則訊息 * user_id = 1 * patient_id = 46 * send_to = 11 * board_id = * content = '測試訊息1' 2. 非 admin 使用者對某一留言板傳送一則訊息 * user_id = 2 * patient_id = 46 * send_to = 0 * board_id = * content = '測試訊息2' * Response | status | message | result | | ------ | ------- | ------ | | 200 | board POST 成功 | (見下表) | | 405 | 不支援所請求的方法 | [] | | 500 | 資料庫連接錯誤 </br> 資料庫取值錯誤 | [] | | input | 備註 | | ----- | --- | | user_id = 1 </br> patient_id = 46 </br> send_to = 11 </br> board_id = </br> content = '傳送訊息測試 user id 1' | 沒有指定回覆哪則訊息 ```python= { "status": 200, "message": "board POST 成功", "result": { "id": 11, "account": "tzuchi", "content": "傳送訊息測試 user id 1", "reply_to_id": null, "reply_to_text": null, "unit": "花蓮慈濟醫院admin", "identify_key": 0 "read": 1 } } ``` | input | 備註 | | ----- | --- | | user_id = 2 </br> patient_id = 46 </br> send_to = 0 </br> board_id = </br> content = '測試訊息2' | 有指定回覆哪則訊息 | ```python= { "status": 200, "message": "board POST 成功", "result": { "id": 12, "account": "tzuchi", "content": "傳送訊息測試 user id 1", "reply_to_id": 11, "reply_to_text": "傳送訊息測試 user id 1", "unit": "花蓮慈濟醫院admin", "identify_key": 0 } } ``` ::: ## 搜尋病患 :::success **==POST== /app_api/searchroom** 概述:依照給定的洗腎室編號回傳屬於該洗腎室之病人清單 * Parameters * keyword <font color=#FF0000>(必填)</font> * Response | status | data | | ------ | ---- | | 0 | ![](https://i.imgur.com/00rMV65.png) | 1 | 錯誤 | ::: ## 其他參考 ![](https://i.imgur.com/Bm70LSo.png) ![](https://i.imgur.com/nZjDam1.png)