帮你快速理解、总结文档立即下载

基础 Bundle 事务

最近更新时间:2026-07-28 16:18:01

我的收藏

接口描述

用于通过单个 Bundle 请求提交一个或多个 FHIR 交互操作。客户端将多个交互条目封装在 Bundle.entry 中,通过 HTTP POST 提交到服务基地址,由服务端按 Bundle.type 指定的模式进行处理。
在事务模式下,所有条目会作为一个原子事务执行。
在批处理模式下,各条目独立执行。
基础事务 Bundle 的关键元素包括:
Bundle.type:指定处理模式,如 transactionbatch
Bundle.entry:交互条目数组,每个条目代表一次独立 REST 交互。
Bundle.entry.fullUrl:条目的完整 URL 或临时 URI。
Bundle.entry.resource:请求体资源内容。
Bundle.entry.request:请求方法、请求 URL 及其他请求控制信息。

输入参数

参数名称
类型
是否必填
说明
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
处理模式。取值如下:
transaction:事务模式,所有条目作为一个原子事务执行,任一条目失败则整体回滚。
batch:批处理模式,各条目独立执行,互不影响。
未指定时服务端默认按 transaction 模式处理。
entry
Array
交互条目列表。
entry[].fullUrl
String
条目的唯一地址或占位 URI。
entry[].resource
Object
资源内容,适用于创建、更新、删除、补丁等操作。
entry[].request.method
String
条目请求方法,如 POSTPUTDELETEPATCH
entry[].request.url
String
条目对应的目标资源路径。

输出参数

接口调用成功后,通常返回 HTTP 状态码 200 OK201 Created,并在响应头中包含内容类型及请求追踪信息,响应体一般为 Bundle 资源,用于描述各条目执行结果。
响应头示例说明:
参数名称
类型
说明
Status Code
Integer
成功时返回 200 OK201 Created
Location
String
Bundle 响应资源地址,格式为 [baseUrl]/Bundle/[bundleId]
Content-Location
String
Bundle 响应资源当前版本地址。
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
条目处理状态,如201 Created
entry[].response.location
String
资源位置或版本地址。
entry[].response.etag
String
资源版本标识。
entry[].response.lastModified
String
资源最后修改时间。
entry[].response.outcome
Object
操作结果详情,包含 OperationOutcome 资源,描述条目执行的具体结果信息。

示例

请求示例

POST /INSTANCE_ID/fhir HTTP/1.1
Host: HOSTNAME
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/fhir+json
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:850bc2ca-d9ab-467b-9924-0e08d0a6e586",
"resource": {
"resourceType": "Patient",
"identifier": [
{
"system": "https://example.org/mrns",
"value": "8ffd03ee-fb56-441d-a3ef-01cdc9f94d89"
}
],
"name": [
{
"use": "official",
"family": "Trantow673",
"given": [
"Matthew562"
],
"prefix": [
"Mr."
]
}
],
"gender": "male"
},
"request": {
"method": "POST",
"url": "Patient"
}
}
]
}

响应示例

HTTP/1.1 200 OK
Location: https://HOSTNAME/INSTANCE_ID/fhir/Bundle/<BUNDLE_ID>
Content-Location: https://HOSTNAME/INSTANCE_ID/fhir/Bundle/<BUNDLE_ID>
Content-Type: application/fhir+json
x-request-id: <REQUEST_ID>
{
"resourceType": "Bundle",
"id": "<BUNDLE_ID>",
"type": "transaction-response",
"link": [
{
"relation": "self",
"url": "https://HOSTNAME/INSTANCE_ID/fhir"
}
],
"entry": [
{
"response": {
"status": "201 Created",
"location": "Patient/<RESOURCE_ID>/_history/1",
"etag": "1",
"lastModified": "2026-07-09T18:50:33.309+08:00",
"outcome": {
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "information",
"code": "informational",
"details": {
"coding": [
{
"system": "https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code",
"code": "SUCCESSFUL_CREATE",
"display": "Create succeeded."
}
]
},
"diagnostics": "Successfully created resource \\"Patient/<RESOURCE_ID>/_history/1\\". Took 68ms."
}
]
}
}
}
]
}

错误码

常见错误码如下,更多错误码请参见 错误码
错误码
说明
400 Bad Request
Bundle 结构错误,或条目请求格式不合法
401 Unauthorized
未认证,缺少有效身份凭证
403 Forbidden
已认证但无执行 Bundle 操作的权限
404 Not Found
条目中的目标资源路径不存在
422 Unprocessable Entity
Bundle 语法正确,但未通过业务或规则校验
500 Internal Server Error
服务端内部处理异常