綁定 FHIR 資源 - AWS HealthLake

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

綁定 FHIR 資源

FHIR Bundle是 中 FHIR 資源集合的容器 AWS HealthLake。 AWS HealthLake 支援兩種具有不同行為的套件: batchtransaction

  • 對於「批次」套件,套件中包含的每個 FHIR 資源都會個別處理和記錄。每個資源操作都會獨立於其他資源處理。

  • 對於「交易」套件,套件中包含的所有 FHIR 資源都會處理為原子操作。操作中的所有資源都必須成功,否則套件中的資源更新都不會遞交和儲存。

您可以綁定相同或不同類型的 FHIR 資源,而且它們可以包含本章所定義的其他 FHIR 互動 (例如 createreaddeleteupdatesearch) 的混合。如需詳細資訊,請參閱 FHIR R4 文件中的資源套件

批次與交易類型套件之間的主要差異:

Batch
  • 可個別成功或失敗的獨立操作

  • 即使某些操作失敗,仍會繼續處理

  • 不保證執行順序

  • 適用於可接受部分成功的大量操作

交易
  • 原子保證 - 全部成功或全部失敗

  • 維護本機參考 (套件內) 資源的參考完整性

  • 依指定的順序處理的操作

  • 如果任何操作失敗,則完全失敗

範例使用案例:

  • 批次:上傳多個不相關的病患記錄

  • 交易:建立具有相關觀察和條件的患者,其中所有必須一起成功

注意

兩者都使用套件資源類型,但在「類型」欄位中不同:

{ "resourceType": "Bundle", "type": "transaction", "entry": [ { "fullUrl": "urn:uuid:4f6a30fb-cd3c-4ab6-8757-532101f72065", "resource": { "resourceType": "Patient", "id": "new-patient", "active": true, "name": [ { "family": "Johnson", "given": [ "Sarah" ] } ], "gender": "female", "birthDate": "1985-08-12", "telecom": [ { "system": "phone", "value": "555-123-4567", "use": "home" } ] }, "request": { "method": "POST", "url": "Patient" } }, { "fullUrl": "urn:uuid:7f83f473-d8cc-4a8d-86d3-9d9876a3248b", "resource": { "resourceType": "Observation", "id": "blood-pressure", "status": "final", "code": { "coding": [ { "system": "http://loinc.org", "code": "85354-9", "display": "Blood pressure panel" } ], "text": "Blood pressure panel" }, "subject": { "reference": "urn:uuid:4f6a30fb-cd3c-4ab6-8757-532101f72065" }, "effectiveDateTime": "2023-10-15T09:30:00Z", "component": [ { "code": { "coding": [ { "system": "http://loinc.org", "code": "8480-6", "display": "Systolic blood pressure" } ] }, "valueQuantity": { "value": 120, "unit": "mmHg", "system": "http://unitsofmeasure.org", "code": "mm[Hg]" } }, { "code": { "coding": [ { "system": "http://loinc.org", "code": "8462-4", "display": "Diastolic blood pressure" } ] }, "valueQuantity": { "value": 80, "unit": "mmHg", "system": "http://unitsofmeasure.org", "code": "mm[Hg]" } } ] }, "request": { "method": "POST", "url": "Observation" } }, { "resource": { "resourceType": "Appointment", "id": "appointment-123", "status": "booked", "description": "Annual physical examination", "start": "2023-11-15T09:00:00Z", "end": "2023-11-15T09:30:00Z", "participant": [ { "actor": { "reference": "urn:uuid:4f6a30fb-cd3c-4ab6-8757-532101f72065" }, "status": "accepted" } ] }, "request": { "method": "PUT", "url": "Appointment/appointment-123" } }, { "request": { "method": "DELETE", "url": "MedicationRequest/med-request-456" } } ] }

將 FHIR 資源綁定為獨立實體

將 FHIR 資源綁定為獨立實體

  1. 收集 HealthLake regiondatastoreId 值。如需詳細資訊,請參閱取得資料存放區屬性

  2. 使用 HealthLake region和 的收集值來建構請求的 URLdatastoreId請勿在 URL 中指定 FHIR 資源類型。若要在下列範例中檢視整個 URL 路徑,請捲動至複製按鈕。

    POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/
  3. 為請求建構 JSON 內文,將每個 HTTP 動詞指定為method元素的一部分。下列範例使用與 Bundle 資源的batch類型互動來建立新的 Medication Patient和資源。所有必要區段都會據此加上註解。為了此程序的目的,請將檔案儲存為 batch-independent.json

    { "resourceType": "Bundle", "id": "bundle-batch", "meta": { "lastUpdated": "2014-08-18T01:43:30Z" }, "type": "batch", "entry": [ { "resource": { "resourceType": "Patient", "meta": { "lastUpdated": "2022-06-03T17:53:36.724Z" }, "text": { "status": "generated", "div": "Some narrative" }, "active": true, "name": [ { "use": "official", "family": "Jackson", "given": [ "Mateo", "James" ] } ], "gender": "male", "birthDate": "1974-12-25" }, "request": { "method": "POST", "url": "Patient" } }, { "resource": { "resourceType": "Medication", "id": "med0310", "contained": [ { "resourceType": "Substance", "id": "sub03", "code": { "coding": [ { "system": "http://snomed.info/sct", "code": "55452001", "display": "Oxycodone (substance)" } ] } } ], "code": { "coding": [ { "system": "http://snomed.info/sct", "code": "430127000", "display": "Oral Form Oxycodone (product)" } ] }, "form": { "coding": [ { "system": "http://snomed.info/sct", "code": "385055001", "display": "Tablet dose form (qualifier value)" } ] }, "ingredient": [ { "itemReference": { "reference": "#sub03" }, "strength": { "numerator": { "value": 5, "system": "http://unitsofmeasure.org", "code": "mg" }, "denominator": { "value": 1, "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" } } } ] }, "request": { "method": "POST", "url": "Medication" } } ] }
  4. 傳送 請求。FHIR Bundle批次類型使用具有AWS 簽章第 4 版或 FHIR 授權上的 SMART 的POST請求。下列程式碼範例使用curl命令列工具進行示範。

    SigV4

    SigV4 授權

    curl --request POST \ 'https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/' \ --aws-sigv4 'aws:amz:region:healthlake' \ --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \ --header "x-amz-security-token:$AWS_SESSION_TOKEN" \ --header 'Accept: application/json' \ --data @batch-type.json
    SMART on FHIR

    IdentityProviderConfiguration 資料類型的 FHIR 上的 SMART 授權範例。

    { "AuthorizationStrategy": "SMART_ON_FHIR", "FineGrainedAuthorizationEnabled": true, "IdpLambdaArn": "arn:aws:lambda:your-region:your-account-id:function:your-lambda-name", "Metadata": "{\"issuer\":\"https://ehr.example.com\", \"jwks_uri\":\"https://ehr.example.com/.well-known/jwks.json\",\"authorization_endpoint\":\"https://ehr.example.com/auth/authorize\",\"token_endpoint\":\"https://ehr.token.com/auth/token\",\"token_endpoint_auth_methods_supported\":[\"client_secret_basic\",\"foo\"],\"grant_types_supported\":[\"client_credential\",\"foo\"],\"registration_endpoint\":\"https://ehr.example.com/auth/register\",\"scopes_supported\":[\"openId\",\"profile\",\"launch\"],\"response_types_supported\":[\"code\"],\"management_endpoint\":\"https://ehr.example.com/user/manage\",\"introspection_endpoint\":\"https://ehr.example.com/user/introspect\",\"revocation_endpoint\":\"https://ehr.example.com/user/revoke\",\"code_challenge_methods_supported\":[\"S256\"],\"capabilities\":[\"launch-ehr\",\"sso-openid-connect\",\"client-public\",\"permission-v2\"]}" }

    發起人可以在授權 lambda 中指派許可。如需詳細資訊,請參閱OAuth 2.0 範圍

    伺服器會傳回回應,顯示因Bundle批次類型請求而建立的 Medication Patient和資源。

套件中的條件式 PUTs

AWS HealthLake 使用以下查詢參數支援 Bundles 中的條件式更新:

  • _id (獨立)

  • _id 搭配下列其中一項:

    • _tag

    • _createdAt

    • _lastUpdated

根據符合提供給現有資源的條件的結果,以下將與指出所採取動作的相關聯結果代碼一起發生:

建立或更新 FHIR 資源時,系統會根據資源 ID 佈建和現有相符項目來處理不同的案例:

  • 一律會建立沒有 IDs的資源 (201)。

  • 會建立具有新 IDs的資源 (201)。

  • 具有現有 IDs的資源會更新相符的資源 (200),或在發生衝突 (409) 或 ID 不相符 (400) 時傳回錯誤。

  • 多個相符的資源會觸發先決條件失敗 (419)。

在包含條件更新的範例套件中,只有在符合條件時,具有 FHIR ID _lastUpdated=lt2025-04-20 的患者資源456才會更新。

{ "resourceType": "Bundle", "id": "bundle-batch", "meta": { "lastUpdated": "2014-08-18T01:43:30Z" }, "type": "batch", "entry": [ { "resource": { "resourceType": "Patient", "id": "476", "meta": { "lastUpdated": "2022-06-03T17:53:36.724Z" }, "active": true, "name": [ { "use": "official", "family": "Jackson", "given": [ "Mateo", "James" ] } ], "gender": "male", "birthDate": "1974-12-25" }, "request": { "method": "PUT", "url": "Patient?_id=476&_lastUpdated=lt2025-04-20" } }, { "resource": { "resourceType": "Medication", "id": "med0310", "contained": [ { "resourceType": "Substance", "id": "sub03", "code": { "coding": [ { "system": "http://snomed.info/sct", "code": "55452001", "display": "Oxycodone (substance)" } ] } } ], "code": { "coding": [ { "system": "http://snomed.info/sct", "code": "430127000", "display": "Oral Form Oxycodone (product)" } ] }, "form": { "coding": [ { "system": "http://snomed.info/sct", "code": "385055001", "display": "Tablet dose form (qualifier value)" } ] }, "ingredient": [ { "itemReference": { "reference": "#sub03" }, "strength": { "numerator": { "value": 5, "system": "http://unitsofmeasure.org", "code": "mg" }, "denominator": { "value": 1, "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" } } } ] }, "request": { "method": "POST", "url": "Medication" } } ] }

將 FHIR 資源綁定為單一實體

將 FHIR 資源綁定為單一實體

  1. 收集 HealthLake regiondatastoreId 值。如需詳細資訊,請參閱取得資料存放區屬性

  2. 使用 HealthLake region和 的收集值來建構請求的 URLdatastoreId。在 Bundle URL 中包含 FHIR 資源類型。若要在下列範例中檢視整個 URL 路徑,請捲動至複製按鈕。

    POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Bundle
  3. 為請求建構 JSON 內文,指定要分組的 FHIR 資源。下列範例會將 HealthLake 中的兩個Patient資源分組。基於此程序的目的,請將檔案儲存為 batch-single.json

    { "resourceType": "Bundle", "id": "bundle-minimal", "language": "en-US", "identifier": { "system": "urn:oid:1.2.3.4.5", "value": "28b95815-76ce-457b-b7ae-a972e527db4f" }, "type": "document", "timestamp": "2020-12-11T14:30:00+01:00", "entry": [ { "fullUrl": "urn:uuid:f40b07e3-37e8-48c3-bf1c-ae70fe12dabf", "resource": { "resourceType": "Composition", "id": "f40b07e3-37e8-48c3-bf1c-ae70fe12dabf", "status": "final", "type": { "coding": [ { "system": "http://loinc.org", "code": "60591-5", "display": "Patient summary Document" } ] }, "date": "2020-12-11T14:30:00+01:00", "author": [ { "reference": "urn:uuid:45271f7f-63ab-4946-970f-3daaaa0663ff" } ], "title": "Patient Summary as of December 7, 2020 14:30" } }, { "fullUrl": "urn:uuid:45271f7f-63ab-4946-970f-3daaaa0663ff", "resource": { "resourceType": "Practitioner", "id": "45271f7f-63ab-4946-970f-3daaaa0663ff", "active": true, "name": [ { "family": "Doe", "given": [ "John" ] } ] } } ] }
  4. 傳送 請求。FHIR Bundle 文件類型使用 Signature AWS 第 4 版簽署通訊協定的POST請求。下列程式碼範例使用curl命令列工具進行示範。

    SigV4

    SigV4 授權

    curl --request POST \ 'https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Bundle' \ --aws-sigv4 'aws:amz:region:healthlake' \ --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \ --header "x-amz-security-token:$AWS_SESSION_TOKEN" \ --header 'Accept: application/json' \ --data @document-type.json
    SMART on FHIR

    IdentityProviderConfiguration 資料類型的 FHIR 上的 SMART 授權範例。

    { "AuthorizationStrategy": "SMART_ON_FHIR", "FineGrainedAuthorizationEnabled": true, "IdpLambdaArn": "arn:aws:lambda:your-region:your-account-id:function:your-lambda-name", "Metadata": "{\"issuer\":\"https://ehr.example.com\", \"jwks_uri\":\"https://ehr.example.com/.well-known/jwks.json\",\"authorization_endpoint\":\"https://ehr.example.com/auth/authorize\",\"token_endpoint\":\"https://ehr.token.com/auth/token\",\"token_endpoint_auth_methods_supported\":[\"client_secret_basic\",\"foo\"],\"grant_types_supported\":[\"client_credential\",\"foo\"],\"registration_endpoint\":\"https://ehr.example.com/auth/register\",\"scopes_supported\":[\"openId\",\"profile\",\"launch\"],\"response_types_supported\":[\"code\"],\"management_endpoint\":\"https://ehr.example.com/user/manage\",\"introspection_endpoint\":\"https://ehr.example.com/user/introspect\",\"revocation_endpoint\":\"https://ehr.example.com/user/revoke\",\"code_challenge_methods_supported\":[\"S256\"],\"capabilities\":[\"launch-ehr\",\"sso-openid-connect\",\"client-public\",\"permission-v2\"]}" }

    發起人可以在授權 lambda 中指派許可。如需詳細資訊,請參閱OAuth 2.0 範圍

    伺服器會傳回回應,顯示因Bundle文件類型請求而建立的兩個Patient資源。

設定套件的驗證層級

綁定 FHIR 資源時,您可以選擇指定 x-amzn-healthlake-fhir-validation-level HTTP 標頭來設定資源的驗證層級。此驗證層級將針對 bundle 內的所有建立和更新請求設定。 AWS HealthLake 目前支援下列驗證層級:

  • strict:資源會根據資源的設定檔元素進行驗證,如果沒有設定檔,則為 R4 規格。這是 的預設驗證層級 AWS HealthLake。

  • structure-only:資源會根據 R4 驗證,忽略任何參考的設定檔。

  • minimal:最少驗證資源,忽略某些 R4 規則。搜尋/分析所需的結構檢查失敗的資源將更新為包含稽核警告。

與最低驗證層級綁定的資源可能會擷取到資料存放區,即使搜尋索引所需的驗證失敗。在此情況下,資源將更新為包含 Healthlake 特定的延伸,以記錄上述失敗,而 Bundle 回應中的項目將包含 OperationOutcome 資源,如下所示:

{ "resourceType": "Bundle", "type": "batch-response", "timestamp": "2025-08-25T22:58:48.846287342Z", "entry": [ { "response": { "status": "201", "location": "Patient/195abc49-ba8e-4c8b-95c2-abc88fef7544/_history/1", "etag": "W/\"1\"", "lastModified": "2025-08-25T22:58:48.801245445Z", "outcome": { "resourceType": "OperationOutcome", "issue": [ { "severity": "error", "code": "processing", "details": { "text": "FHIR resource in payload failed FHIR validation rules." }, "diagnostics": "FHIR resource in payload failed FHIR validation rules." } ] } } } ] }

此外,以下 HTTP 回應標頭會包含在「true」的值中:

x-amzn-healthlake-validation-issues : true
注意

請注意,如果出現這些錯誤,根據 R4 規格格式不正確擷取的資料可能無法如預期搜尋。