0

我正在尝试通过 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。

有任何想法吗?

4

1 回答 1

0

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 对象的包装器。

于 2021-12-24T21:56:18.427 回答