# FHIR 資訊互通常見錯誤 ## 什麼是FHIR/FHIR Resources? 介紹及範例相關Link(解讀範例):https://hackmd.io/@VirtualHospitalaaa/B14SUqyXi ![image](https://hackmd.io/_uploads/H1IhY8aYa.png) ## 簡易上傳及調閱 FHIR 網頁介紹 練習網頁及原始程式碼: 提供 Post、Get、Update 網頁,上傳資料到 HAPI server [練習網頁](https://mos2718.github.io/F24/list.html)【Web】 [Source code download](https://github.com/mos2718/F24)【Github】 # 錯誤清單 ## 前端系統常見錯誤 ### 1. 呼叫錯的 API;CRUD API 的語法 error 以下是一個範例,假設您應該將FHIR資料上傳到<font color="#f00"> /api/patients </font> 但誤用了<font color="#f00"> /api/patien</font>: ```typescript= POST /api/patien Content-Type: application/fhir+json Authorization: Bearer your_access_token { "resourceType": "Patient", "id": "example", "name": [ { "family": "Doe", "given": ["John"] } ], "gender": "male", "birthDate": "1990-01-01" } ``` 伺服器可能回應如下: ``` HTTP/1.1 404 Not Found Content-Type: application/json { "error": "not_found", "error_description": "The requested API endpoint '/api/patien' was not found." } ``` 解決辦法:檢查您的API請求的端點路徑是否正確。確保您正在呼叫正確的API端點,以及端點的拼寫和格式是否與伺服器的預期相符。 ### 2. 格式有誤: XML 或 JSON data 不對 ```typescript= POST /api/patients Content-Type: application/fhir+json Authorization: Bearer your_access_token { "resourceType": "Patient", "id": "example", "name": "John Doe", // 這裡應該是一個名字對象的陣列 "gender": "male", "birthDate": "1990-01-01" } ``` 伺服器可能回應如下: ``` HTTP/1.1 400 Bad Request Content-Type: application/json { "error": "bad_request", "error_description": "Invalid JSON data. The 'name' field should be an array of name objects." } ``` 解決辦法:檢查您的JSON資料,確保其結構與FHIR標準相符。根據回應中的錯誤信息,更新您的JSON資料以符合FHIR的規範。在這個例子中,您需要將name字段更改為包含名字對象的陣列,以滿足FHIR的要求。 ### 3. 使用 FHIR 標準不支援的欄位 -- 上傳後不會回應錯誤訊息, 但 server 不會儲存此欄位 ```typescript= POST /api/patients Content-Type: application/fhir+json Authorization: Bearer your_access_token { "resourceType": "Patient", "id": "example", "name": [ { "family": "Doe", "given": ["John"] } ], "gender": "male", "birthDate": "1990-01-01", "customField": "Some value" // FHIR標準中不存在的自定義欄位 } ``` 伺服器可能回應如下: ``` HTTP/1.1 422 Unprocessable Entity Content-Type: application/json { "error": "unprocessable_entity", "error_description": "Invalid resource. The field 'customField' is not supported by the FHIR standard." } ``` 解決辦法:檢查您的JSON資料,確保只包含FHIR標準所支援的欄位。根據回應中的錯誤信息,移除或更改任何FHIR標準不支援的欄位,以使您的資料符合FHIR規範。这确保了您的資料能夠被伺服器正確解析和處理。 ### 4. 參考的 resource 不存在 以下是一個範例,其中患者資料參考了一個不存在的醫生: ```typescript= POST /api/patients Content-Type: application/fhir+json Authorization: Bearer your_access_token { "resourceType": "Patient", "id": "example", "name": [ { "family": "Doe", "given": ["John"] } ], "gender": "male", "birthDate": "1990-01-01", "generalPractitioner": [ { "reference": "Practitioner/example-doctor" // 參考了一個不存在的醫生 } ] } ``` 伺服器可能回應如下: ``` HTTP/1.1 422 Unprocessable Entity Content-Type: application/json { "error": "unprocessable_entity", "error_description": "Invalid resource. The referenced 'Practitioner/example-doctor' does not exist." } ``` 解決辦法:根據回應中的錯誤信息,檢查您的參考,確保它指向了存在的 resource。 ### 5.產生端及調閱端 採用之欄位規格及編碼不一致 * 發生原因: 無一致的規格,或對規格認知不一致 * 解決方式: -- 基於應用情境,確立 resource 包含那些欄位,及其採用的編碼 -- 進行嚴謹之聯測與驗證 以下是一個範例,其中患者資料的性別在生成端使用字符串編碼,但在調閱端使用了編碼的系統: * 產生端(生成端)JSON 資料: ```typescript= POST /api/patients Content-Type: application/fhir+json Authorization: Bearer your_access_token { "resourceType": "Patient", "id": "example", "name": [ { "family": "Doe", "given": ["John"] } ], "gender": "male" // 產生端使用字符串編碼 } ``` * 調閱端(查詢端)JSON 資料 ```typescript= GET /api/patients/example Accept: application/fhir+json { "resourceType": "Patient", "id": "example", "name": [ { "family": "Doe", "given": ["John"] } ], "gender": { "coding": [ { "system": "http://hl7.org/fhir/administrative-gender", "code": "M", "display": "Male" } ], "text": "Male" // 調閱端使用編碼的系統 } } ``` 在這個例子中,產生端使用了簡單的字符串 "male" 來表示性別,而調閱端使用了編碼的系統 "http://hl7.org/fhir/administrative-gender" 和相應的編碼 "M" 來表示性別。 解決辦法:需要協調並確保產生端和調閱端在使用FHIR資源時採用相同的欄位規格和編碼標準。可以參考FHIR標準文檔,以確保兩端使用的欄位和編碼是一致的。 ## 其他錯誤 1.使用者操作錯誤 2.網路不通或無權限、伺服器端有問題 ## 網頁回傳之錯誤狀態碼 1.權限不足 (Unauthorized): 錯誤可能存在位置:Root URL 錯誤信息: HTTP 401 Unauthorized。 解決方法: 確保您的請求包含正確的授權標頭,檢查您是否具有上傳數據的權限。 2.無效的資料格式 (Unsupported Media Type): 錯誤信息: HTTP 415 Unsupported Media Type。 解決方法: 檢查您的請求標頭,確保Content-Type標頭正確指定為FHIR支持的格式,例如application/fhir+json或application/fhir+xml。 3.資料格式錯誤 (Invalid Resource Format): 錯誤信息: HTTP 400 Bad Request,可能伴隨有具體的錯誤信息。 解決方法: 檢查您上傳的FHIR資料是否符合FHIR規範,特別是檢查是否存在必需的元素,以及元素的數據類型是否正確。 4.資料一致性錯誤 (Validation Error): 錯誤信息: HTTP 422 Unprocessable Entity,伴隨有具體的驗證錯誤信息。 解決方法: 根據伺服器返回的錯誤信息,調整您的FHIR資料以符合驗證規則。 5.伺服器內部錯誤 (Internal Server Error): 錯誤信息: HTTP 500 Internal Server Error。 解決方法: 聯繫伺服器管理員,檢查伺服器端是否存在問題。同時,檢查您的請求是否正確,避免引起伺服器錯誤。 6.資源衝突 (Resource Conflict): 錯誤信息: HTTP 409 Conflict。 解決方法: 確認您上傳的資源是否已存在,如果是,可能需要使用更新或其他方式處理衝突。