接口描述
用于在同一个
Bundle 事务中一次性提交多个彼此关联的资源。该方式适合将患者及其关联的检验、就诊、诊断等资源统一写入,确保这些资源在同一次提交中被整体处理。在已知资源标识的情况下,可以使用客户端自定义 ID,并在资源之间直接通过这些 ID 建立引用关系。
输入参数
参数名称 | 类型 | 是否必填 | 说明 |
HTTP Method | String | 是 | 固定为 POST。 |
URL | String | 是 | Bundle 提交地址,格式为 [baseUrl]。 |
Authorization | String | 是 | 身份认证令牌,格式为 Bearer <AccessToken>,AccessToken 通过 调用方式 中的 GetAccessToken 接口获取(实例控制台场景可通过 GetWebAccessToken 接口获取)。 |
Content-Type | String | 是 | 请求体 MIME 类型,示例为 application/fhir+json。 |
Request Body | JSON Object | 是 | 包含多个关联资源的事务 Bundle。 |
请求体主要字段说明:
字段 | 类型 | 是否必填 | 说明 |
resourceType | String | 是 | 固定为 Bundle。 |
type | String | 否 | Bundle 类型,指定事务处理方式。取值如下: transaction:事务模式,所有条目作为整体提交,任一条目失败则全部回滚。 batch:批处理模式,各条目独立处理,互不影响,详见 FHIR BundleType。 未指定时服务端默认按 transaction 模式处理。 |
entry | Array | 是 | 多个资源条目。 |
entry[].fullUrl | String | 否 | 资源在 Bundle 中的唯一标识。 |
entry[].resource.id | String | 否 | 客户端指定资源 ID。使用客户端自定义 ID 时,需配合 entry[].request.method 为 PUT、entry[].request.url 为 [resourceType]/[id],服务端将以此 ID 创建或更新资源;若不指定,由服务端自动生成。 |
entry[].resource.subject.reference | String | 否 | 对其他资源的引用。 |
entry[].request.method | String | 是 | 条目请求方法。 |
entry[].request.url | String | 是 | 条目目标资源路径。 |
输出参数
接口调用成功后,通常返回 HTTP 状态码
200 OK 或 201 Created,并在响应头中包含内容类型及请求追踪信息,响应体一般为处理结果 Bundle,包含各资源条目的执行状态。响应头示例说明:
参数名称 | 类型 | 说明 |
Status Code | Integer | 成功时返回 200 OK 或 201 Created。 |
Content-Type | String | 响应体 MIME 类型,通常为 application/fhir+json。 |
x-request-id | String | 请求追踪 ID。 |
响应体主要字段说明:
字段 | 类型 | 说明 |
resourceType | String | 返回资源类型,通常为 Bundle。 |
id | String | Bundle 的唯一标识,由服务端生成。 |
type | String | 响应 Bundle 类型,事务响应为 transaction-response,批处理响应为 batch-response。 |
link | Array | Bundle 关联链接列表。 |
link[].relation | String | 链接关系类型,如 self 表示当前请求自身。 |
link[].url | String | 链接地址。 |
entry | Array | 各资源条目的执行结果。 |
entry[].response.status | String | 条目执行状态。 |
entry[].response.location | String | 资源位置或版本地址。 |
entry[].response.etag | String | 资源版本标识。 |
示例
请求示例
POST /INSTANCE_ID/fhir HTTP/1.1Host: HOSTNAMEAuthorization: Bearer YOUR_ACCESS_TOKENContent-Type: application/fhir+json
{"resourceType": "Bundle","type": "transaction","entry": [{"fullUrl": "Patient/PTA","resource": {"resourceType": "Patient","id": "PTA","identifier": [{"system": "http://acme.org/mrns","value": "013872"}],"name": [{"family": "Simpson","given": ["Homer"]}],"gender": "male"},"request": {"method": "PUT","url": "Patient/PTA"}},{"fullUrl": "Condition/CD1","resource": {"resourceType": "Condition","id": "CD1","clinicalStatus": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-clinical","code": "active"}]},"verificationStatus": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-ver-status","code": "confirmed"}]},"category": [{"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-category","code": "problem-list-item","display": "Problem List Item"}]}],"code": {"coding": [{"system": "http://snomed.info/sct","code": "59621000","display": "Essential hypertension"}]},"subject": {"reference": "Patient/PTA"}},"request": {"method": "PUT","url": "Condition/CD1"}},{"fullUrl": "Condition/CD2","resource": {"resourceType": "Condition","id": "CD2","clinicalStatus": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-clinical","code": "active"}]},"verificationStatus": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-ver-status","code": "confirmed"}]},"category": [{"coding": [{"system": "http://terminology.hl7.org/CodeSystem/condition-category","code": "problem-list-item","display": "Problem List Item"}]}],"code": {"coding": [{"system": "http://snomed.info/sct","code": "44054006","display": "Type 2 diabetes mellitus"}]},"subject": {"reference": "Patient/PTA"}},"request": {"method": "PUT","url": "Condition/CD2"}}]}
响应示例
HTTP/1.1 200 OKContent-Type: application/fhir+jsonx-request-id: <REQUEST_ID>
{"resourceType": "Bundle","id": "b67e4a2f-3c5d-4e8a-9f01-7a2b3c4d5e6f","type": "transaction-response","link": [{"relation": "self","url": "https://HOSTNAME/INSTANCE_ID/fhir"}],"entry": [{"response": {"status": "201 Created","location": "Patient/PTA/_history/1","etag": "1"}},{"response": {"status": "201 Created","location": "Condition/CD1/_history/1","etag": "1"}},{"response": {"status": "201 Created","location": "Condition/CD2/_history/1","etag": "1"}}]}
错误码
错误码 | 说明 |
400 Bad Request | Bundle 中资源关联关系或请求格式错误 |
401 Unauthorized | 未认证,缺少有效身份凭证 |
403 Forbidden | 已认证但无执行 Bundle 操作的权限 |
409 Conflict | 资源 ID 或引用关系冲突 |
422 Unprocessable Entity | Bundle 语法正确,但未通过业务或规则校验 |
500 Internal Server Error | 服务端内部处理异常 |