我正在嘗試通過 Ruby 客戶端從 FHIR 存盤中獲取患者,但它始終回傳 null。
通過 CURL 查詢時我成功了。這是我正在運行的 CURL 命令(完整路徑已編輯):
curl -X GET \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID"
這將回傳正確的 FHIR 患者資源。
我的 Ruby 代碼如下所示:
require 'google/apis/healthcare_v1'
require 'googleauth'
service = Google::Apis::HealthcareV1::CloudHealthcareService.new
scope = 'https://www.googleapis.com/auth/cloud-platform'
service.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('REDACTED'),
scope: scope
)
service.authorization.fetch_access_token!
project_id = REDACTED
location = REDACTED
dataset_id = REDACTED
fhir_store_id = REDACTED
resource_type = 'Patient'
patient_id = REDACTED
name = "projects/#{project_id}/locations/#{location}/datasets/#{dataset_id}/fhirStores/#{fhir_store_id}/fhir/Patient/#{patient_id}"
response = service.read_project_location_dataset_fhir_store_fhir(name)
puts response.to_json
我沒有收到任何身份驗證錯誤。CURL 示例回傳適當的結果,而 Ruby 客戶端示例回傳 null。
有任何想法嗎?
uj5u.com熱心網友回復:
Ruby 庫會自動嘗試將回應決議為 JSON。由于來自 Healthcare API(或任何 FHIR 服務器)的回應是Content-Type: application/fhir json,因此 Ruby 庫無法識別它,它只是nil為決議的回應回傳。
我通過使用skip_deserializationAPI 呼叫的選項 ( docs )使其作業,因此您應該嘗試
require 'json'
name = "projects/#{project_id}/locations/#{location}/datasets/#{dataset_id}/fhirStores/#{fhir_store_id}/fhir/Patient/#{patient_id}"
response = service.read_project_location_dataset_fhir_store_fhir(name, options: {
skip_deserialization: true,
})
patient = JSON.parse(response)
無論如何,您實際上必須自己決議回應,因為這些呼叫的 Ruby 回應型別是Google::Apis::HealthcareV1::HttpBody,它本質上只是原始 JSON 物件的包裝器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/396596.html
標籤:红宝石 谷歌 API 客户端 google-healthcare-api
