Batch/Transaction
Do multiple operations in one call

Introduction

Transaction interaction allows performing several interactions using one http request. There are two types of transaction interaction (type is specified by field type): batch and transaction. The first one just executes requests one by one, the second one does the same, but roll backs all changes if any request fails.
1
POST [base]
Copied!
The body of such request contains one resource of type Bundle, which contains field entry with an array of interactions, for example (taken from Getting Started with SPA tutorial):
1
POST /
2
​Accept: text/yaml
3
Content-Type: text/yaml
4
5
type: transaction
6
entry:
7
- resource:
8
id: admin
9
email: "[email protected]" # Change this value
10
password: "password" # Change this value
11
request:
12
method: POST
13
url: "/User"
14
15
- resource:
16
id: SPA
17
redirect_uri: http://localhost:4200
18
request:
19
method: POST
20
url: "/Client"
21
22
- resource:
23
engine: json-schema
24
schema:
25
type: object
26
required:
27
- user
28
request:
29
method: POST
30
url: "/AccessPolicy"
Copied!
Each element of the entry array contains a resource field (body of the request) and a request field (request line in terms of the HTTP request).
1
resource: # not needed for DELETE and GET
2
# resource here
3
4
fullUrl: "something-here" # needed if you want to refer
5
# the resource inside bundle
6
request:
7
method: POST # POST/GET/PUT/DELETE
8
url: "/ResourceType" # request url
Copied!

Processing rules and Conditional refs

Transaction interaction is processed in the order provided in a bundle, each interaction is executed one by one. It differs from the FHIR transaction processing rules.
For type: batch references to resources inside a bundle won't be resolved.
For type: transaction before processing interactions, all references in a resource will attempt to resolve. In this example ProcedureRequest will refer to a newly created patient:
1
POST /
2
Accept: text/yaml
3
Content-Type: text/yaml
4
5
type: transaction
6
entry:
7
- resource:
8
resourceType: Patient
9
fullUrl: urn:uuid:<uuid-here>
10
request:
11
method: POST
12
url: "/Patient?_identifier=mrn:123"
13
14
- resource:
15
resourceType: Encounter
16
status: proposal
17
subject:
18
uri: urn:uuid:<uuid-here>
19
request:
20
method: POST
21
url: "/Encounter"
22
Copied!
You can provide a full Url with value like "urn:<uuid-here>" and reference to the resource created by such interaction using ref: {uri: "urn:<uuid-here>"}. Those references are temporary and will be translated to valid Aidbox references when interaction entry is processed by a server.
You SHALL NOT refer resource, which is created later using conditional operations!

Multiple resources with the same id

If you have multiple entries with the same resource id, aidbox will execute them one by one and thus you are able to create a resource with a history in within a single transaction:
1
POST /
2
Accept: text/yaml
3
Content-Type: text/yaml
4
5
resourceType: Bundle
6
type: transaction
7
entry:
8
- request: {method: PUT, url: 'Patient/pt-1'}
9
resource: {birthDate: '2021-01-01'}
10
- request: {method: PUT, url: 'Patient/pt-1'}
11
resource: {birthDate: '2021-01-02'}
12
- request: {method: PUT, url: 'Patient/pt-1'}
13
resource: {birthDate: '2021-01-03'}
Copied!
Request
Response
1
GET /Patient/pt-1
2
Accept: text/yaml
Copied!
1
{birthDate: '2021-01-03', id: pt-1, resourceType: Patient}
Copied!
1
GET /Patient/pt-1/_history
2
Accept: text/yaml
3
Content-Type: text/yaml
4
5
resourceType: Bundle
6
type: history
7
total: 3
8
entry:
9
- resource: {birthDate: '2021-01-03', id: pt-1, resourceType: Patient}
10
- resource: {birthDate: '2021-01-02', id: pt-1, resourceType: Patient}
11
- resource: {birthDate: '2021-01-01', id: pt-1, resourceType: Patient}
Copied!