Skip to content

Commit 97e1e3d

Browse files
committed
Add request and response examples for patch with metahistory
1 parent 18ba2d2 commit 97e1e3d

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

articles/healthcare-apis/fhir/fhir-versioning-policy-and-history-management.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ If the versioning policy is set to either `versioned` or `version-update`, metad
7676
- `_meta-history=false` The `_meta-history` parameter can be configured to `false`. This means that the resource version is incremented, a new version is created, but the old version is not saved as a historical record. The lastUpdated timestamp is also still updated to reflect the change. This configuration can be used to help reduce data storage when making metadata-only updates.
7777

7878

79-
### Example with `_meta-history=false` with PUT
79+
### Example of `_meta-history=false` with PUT
8080
To demonstrate the use of the `_meta-history` parameter with PUT, follow this example:
8181
1. Create a resource:
8282
`PUT <fhir server>/Patient/test-patient`
@@ -127,11 +127,85 @@ To demonstrate the use of the `_meta-history` parameter with PUT, follow this ex
127127
]
128128
}
129129
```
130-
5. This will increment resource version and create a new version 3, but the old version 2 will not be saved as a historical record. To see this, run: `GET <fhir server>/Patient/test-patient/_history`. Two versions should be returned, versions 1 and 3. Please note that `_meta-history=false` query parameter only affects metadata-only changes made using PUT. Using the query parameter to make metadata updates along with other non-metadata field value changes will increment the resource version and save the old version as a historical record.
130+
5. This will increment resource version and create a new version 3, but the old version 2 will not be saved as a historical record. To see this, run: `GET <fhir server>/Patient/test-patient/_history`. Two versions should be returned, versions 1 and 3. Please note that `_meta-history=false` query parameter only affects metadata-only changes made using PUT or PATCH. Using the query parameter to make metadata updates along with other non-metadata field value changes will increment the resource version and save the old version as a historical record.
131131

132132

133+
### Example of `_meta-history=false` with PATCH
134+
To demonstrate the use of the `_meta-history` parameter with PATCH, follow this example:
135+
136+
1. Create a resource:
137+
`PUT <fhir server>/Patient/test-patient`
138+
```
139+
{
140+
"id": "test-patient",
141+
"resourceType": "Patient",
142+
"name": [
143+
{
144+
"family": "Doe",
145+
"given": [ "John" ]
146+
}
147+
]
148+
}
149+
```
150+
2. Create a new version of the resource with `PUT <fhir server>/Patient/test-patient`. This will have version 2.
151+
```
152+
{
153+
"id": "test-patient",
154+
"resourceType": "Patient",
155+
"meta": {
156+
"tag": [
157+
{
158+
"system": "test",
159+
"code": "test"
160+
}
161+
]
162+
},
163+
"name": [
164+
{
165+
"family": "Doe",
166+
"given": [ "Jane" ]
167+
}
168+
]
169+
}
170+
```
171+
3. Run: `GET <fhir server>/Patient/test-patient/_history`. Two versions should be returned, versions 1 and 2.
172+
4. Use PATCH to make a metadata-only update with `_meta-history=false` query parameter. The example uses PATCH to update only the Patient.meta.tag.system value. More information about PATCH [here](rest-api-capabilities.md#patch-and-conditional-patch).
173+
174+
Using PATCH with FHIRPath patch:
175+
`PATCH <fhir server>/Patient/test-patient?_meta-history=false`
176+
`Content-type: application/fhir+json`
133177

134178

179+
```
180+
181+
{
182+
"resourceType": "Parameters",
183+
"parameter": [
184+
{
185+
"name": "operation",
186+
"part": [
187+
{ "name": "type", "valueCode": "replace" },
188+
{ "name": "path", "valueString": "Patient.meta.tag[0].system" },
189+
{ "name": "value", "valueUri": "test2" }
190+
]
191+
}
192+
]
193+
}
194+
```
195+
196+
Using PATCH with JSON Patch:
197+
`PATCH <fhir server>/Patient/test-patient?_meta-history=false`
198+
`Content-type: application/json-patch+json`
199+
```
200+
[
201+
{
202+
"op": "replace",
203+
"path": "/meta/tag/0/system",
204+
"value": "test2"
205+
}
206+
]
207+
```
208+
5. This will increment resource version and create a new version 3, but the old version 2 will not be saved as a historical record. To see this, run: `GET <fhir server>/Patient/test-patient/_history`. Two versions should be returned, versions 1 and 3. Please note that `_meta-history=false` query parameter only affects metadata-only changes made using PUT or PATCH. Using the query parameter to make metadata updates along with other non-metadata field value changes will increment the resource version and save the old version as a historical record.
135209

136210
## Next steps
137211

articles/healthcare-apis/fhir/rest-api-capabilities.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ For more information on history and version management visit [FHIR versioning po
9191
Patch is a valuable RESTful operation when you need to update only a portion of the FHIR resource. Using patch allows you to specify the element that you want to update in the resource without having to update the entire record. FHIR defines three ways to patch resources: JSON Patch, XML Patch, and FHIRPath Patch. The FHIR service supports JSON Patch and FHIRPath Patch, along with Conditional JSON Patch and Conditional FHIRPath Patch (which allows you to patch a resource based on a search criteria instead of a resource ID).
9292
For examples, refer to the [FHIRPath Patch REST file](https://github.com/microsoft/fhir-server/blob/main/docs/rest/FhirPatchRequests.http) and the [JSON Patch REST file](https://github.com/microsoft/fhir-server/blob/main/docs/rest/JsonPatchRequests.http). For more information, see [HL7 documentation for patch operations with FHIR](https://www.hl7.org/fhir/http.html#patch).
9393

94+
95+
9496
> [!NOTE]
9597
> When using `PATCH` against STU3, and if you are requesting a History bundle, the patched resource's `Bundle.entry.request.method` is mapped to `PUT`. This is because STU3 doesn't contain a definition for the `PATCH` verb in the [HTTPVerb value set](http://hl7.org/fhir/STU3/valueset-http-verb.html).
9698
@@ -179,6 +181,13 @@ Content-Type: `application/json`
179181
}
180182
```
181183

184+
#### Patch with `_meta-history` parameter
185+
The FHIR service supports the `_meta-history` query parameter with both `PUT` and `PATCH` operations. This parameter allows you to control whether metadata-only changes to a resource create a new historical version of the resource or not. By default, any change to a resource, including metadata-only changes, creates a new version and saves the previous version as a historical record. When you set the `_meta-history` parameter to `false`, metadata-only changes do not create a new version, and the previous version is not saved as a historical record. This feature is useful for scenarios where frequent metadata updates are made, and you want to avoid cluttering the resource history with numerous versions that only differ in metadata. For more information and examples, see [FHIR versioning policy and history management](fhir-versioning-policy-and-history-management.md#metadata-only-updates-and-versioning).
186+
187+
`PATCH <fhir server>/Patient/test-patient?_meta-history=false`
188+
189+
190+
182191
## Troubleshooting
183192

184193
**Can I delete multiple patient observations or all patient resources in a single API call?**

0 commit comments

Comments
 (0)