捆绑 FHIR 资源 - AWS HealthLake

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

捆绑 FHIR 资源

FHIR Bundle 是存放 FHIR 资源集合的容器。 AWS HealthLake AWS HealthLake 支持两种具有不同行为的捆绑包:batchtransaction

  • 对于 “批处理” 捆绑包,将单独处理和记录捆绑包中包含的每个 FHIR 资源。每项资源操作都独立于其他资源进行处理。

  • 对于 “事务” 捆绑包,捆绑包中包含的所有 FHIR 资源都将作为原子操作进行处理。操作中的所有资源都必须成功,否则不提交和存储捆绑包中的任何资源更新。

您可以捆绑相同或不同类型的 FHIR 资源,它们可以包含本章中定义的其他 FHIR 交互组合(例如createreadupdatedelete、和search)。有关更多信息,请参阅 FHIR R4 文档中的资源包

Batch 和 Transaction 类型捆绑包之间的主要区别:

批处理
  • 可以单独成功或失败的独立操作

  • 即使某些操作失败,处理也会继续

  • 不能保证执行顺序

  • 非常适合可以接受部分成功的批量操作

事务
  • 保证原子性-要么全部成功,要么全部失败

  • 保持本地引用(捆绑包内)资源的引用完整性

  • 按指定顺序处理的操作

  • 如果任何操作失败,则完全失败

用例示例:

  • Batch:上传多份无关的患者记录

  • 交易:创建具有相关观察结果和条件的患者,所有人必须共同成功

注意

两者都使用 Bundle 资源类型,但在 “类型” 字段中有所不同:

{ "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. 使用收集到的 HealthLakeregion和值为请求构造一个 URL datastoreId。请在 URL 中指定 FHIR 资源类型。要查看以下示例中的整个 URL 路径,请滚动到 “复制” 按钮。

    POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/
  3. 为请求构造一个 JSON 正文,将每个 HTTP 动词指定为method元素的一部分。以下示例使用与Bundle资源的batch类型交互来创建新的PatientMedication资源。所有必填部分都有相应的注释。出于本过程的目的,请将文件另存为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数据类型的 SMART on FHIR 授权示例。

    { "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 瞄准镜

    服务器返回一个响应,其中显示Patient了作为Bundle批处理类型请求的结果而创建的和Medication资源。

以捆绑包 PUTs 为条件

AWS HealthLake 支持使用以下查询参数在捆绑包内进行有条件更新:

  • _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. 使用收集到的 HealthLakeregion和值为请求构造一个 URL datastoreId。将 FHIR 资源类型Bundle作为网址的一部分。要查看以下示例中的整个 URL 路径,请滚动到 “复制” 按钮。

    POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Bundle
  3. 为请求构建 JSON 正文,指定要组合在一起的 FHIR 资源。以下示例将两个Patient资源分组在一起 HealthLake。出于本过程的目的,请将文件另存为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 文档类型使用带有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数据类型的 SMART on FHIR 授权示例。

    { "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 标头来配置资源的验证级别。将为捆绑包中的所有创建和更新请求设置此验证级别。 AWS HealthLake 目前支持以下验证级别:

  • strict:根据资源的配置文件元素对资源进行验证,如果不存在配置文件,则根据R4规格进行验证。这是的默认验证级别 AWS HealthLake。

  • structure-only:根据 R4 对资源进行验证,忽略任何引用的配置文件。

  • minimal:资源经过最低限度的验证,忽略了某些 R4 规则。未通过所需的结构检查的资源 search/analytics 将进行更新,以包括审计警告。

尽管搜索索引需要验证失败,但与最低验证级别捆绑在一起的资源仍可能会被提取到数据存储中。在这种情况下,资源将更新为包含特定于 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 规范提取的数据可能无法按预期进行搜索。