Patch
Updating a part of your resource
All examples can be run in Postman. Here's a web view of these examples.
​​
​
​
In most Operations in FHIR, you manipulate a resource as a whole (create, update, delete operations). But sometimes you want to update specific data elements in a resource and do not care about the rest. In other words, you need an element/attribute level operation.
With the patch operation, you can update a part of a resource by sending a declarative description of operations that should be performed on an existing resource. To describe these operations in Aidbox, you can use different notations (methods):

Patch Method

You can specify a patch method by the content-type header or by the _method parameter.
method
parameter
header
json-patch
json-patch
application/json-patch+json
merge-patch
merge-patch
application/merge-patch+json
If the method is not specified, Aidbox will try to guess it by the following algorithm:
  • if the payload is an array β€” json-patch
  • else merge-patch

Operation Description

patch
[base-url]/:resourceType/:id
Patch Operation

Example

You can exercise this tutorial using REST Console β€” just copy/paste queries into your console!
Let's suppose we've created a Patient resource with the id pt-1
1
POST /Patient
2
​
3
resourceType: Patient
4
id: pt-1
5
active: true
6
name:
7
- given: ['John']
8
family: Doe
9
use: official
10
- given: ['Johny']
11
family: Doe
12
telecom:
13
- system: phone
14
value: '(03) 5555 6473'
15
use: work
16
rank: 1
17
birthDate: '1979-01-01'
18
​
19
# 200
20
​
21
id: pt-1
22
resourceType: Patient
23
name:
24
- use: official
25
given:
26
- John
27
family: Doe
28
- given:
29
- Johny
30
family: Doe
31
active: true
32
telecom:
33
- use: work
34
rank: 1
35
value: "(03) 5555 6473"
36
system: phone
37
birthDate: '1979-01-01'
Copied!
You can copy/paste this request into REST Console of Aidbox.Cloud.

Merge Patch

Let's say we want to switch an active flag to false and remove telecom:
1
PATCH /Patient/pt-1?_method=merge-patch
2
​
3
active: false
4
telecom: null
5
​
6
# 200
7
​
8
id: pt-1
9
resourceType: Patient
10
name:
11
- use: official
12
given:
13
- John
14
family: Doe
15
- given:
16
- Johny
17
family: Doe
18
active: false
19
birthDate: '1979-01-01'
Copied!

JSON Patch

With JSON patch, we can do more sophisticated transformations β€” change the first given name, delete the second name, and change the active attribute value to true:
1
PATCH /Patient/pt-1
2
​
3
- op: replace
4
path: '/name/0/given/0'
5
value: Nikolai
6
- op: remove
7
path: '/name/1'
8
- op: replace
9
path: '/active'
10
value: true
11
12
# 200
13
​
14
# response 200
15
​
16
id: pt-1
17
resourceType: Patient
18
name:
19
- use: official
20
given:
21
- Nikolai
22
family: Doe
23
active: true
24
birthDate: '1979-01-01'
Copied!
​
Last modified 1yr ago