This
page
is
part
of
the
FHIR
Specification
v6.0.0-ballot3:
Release
6
Ballot
(3rd
Draft)
(see
Ballot
Notes
).
The
current
version
is
5.0.0
.
For
a
full
list
Continuous
Integration
Build
of
available
versions,
see
FHIR
(will
be
incorrect/inconsistent
at
times).
See
the
Directory
of
published
versions
Responsible
Owner:
FHIR
Infrastructure
Work
Group
|
Standards
Status
:
|
This page defines a FHIR Parameters -based, syntax-agnostic patch mechanism where elements to be manipulated by the patch interaction are described using their FHIRpath names and navigation.
This table documents the FHIR Patch operations that may be used to specify changes to a resource:
| Type | Path | Name | Value | Index | source | destination | Details |
| add | Path at which to add the content | Name of the property to add | Datatype to add at nominated place | The content will be appended to the element identified in the path, using the name specified. Add can used for non-repeating elements as long as they do not already exist | |||
| insert | Path of the collection in which to insert the content | value (Datatype) to add at nominated place | index at which to insert |
The
content
will
be
inserted
into
the
nominated
list
at
the
index
specified
(0
based).
The
index
is
mandatory
and
must
be
equal
or
less
than
the
number
of
elements
in
the
list.
Note:
add
is
easier
than
insert
at
the
end
of
the
list
|
|||
| delete | Path of the element to delete (if found) | Only a single element can be deleted | |||||
| replace | Path of the element to replace | value (Datatype) to replace it with | |||||
| move | Path of the collection in which to move the content | list index to move from | list index to move to | Move an element within a single list |
There are a few base rules that apply for all operations:
resolve()
function
Observation.subject.resolve().identifier
).
resolve()
SHALL
only
be
used
to
refer
to
contained
resource
within
the
resource
being
patched.
Servers
SHALL
NOT
allow
patch
operations
to
alter
other
resources
than
the
nominated
target,
and
SHOULD
return
an
error
if
the
patch
operation
tries
The FHIRPath patch operations are encoded in a Parameters resource as follows:
A profile for this has been defined on the Parameters resource .
| Parameter | Type |
| type | code |
| path | string |
| name | string |
| value | * |
| index | integer |
| source | integer |
| destination | integer |
Here is an example of adding an element:
<Parameters xmlns="http://hl7.org/fhir">
<parameter>
<name value="operation"/>
<part>
<name value="type"/>
<valueCode value="add"/>
</part>
<part>
<name value="path"/>
<valueString value="Patient"/>
</part>
<part>
<name value="name"/>
<valueString value="birthDate"/>
</part>
<part>
<name value="value"/>
<valueDate value="1930-01-01"/>
</part>
</parameter>
</Parameters>
Only
some
named
datatypes
(see
the
list
)
are
allowed
to
be
used
directly
in
parameters.
In
order
to
add
or
insert
other
kinds
of
types
-
including
anonymous
elements
(e.g.
(e.g.,
Observation.component,
Timing.repeat),
the
content
is
defined
by
defining
the
name
as
described
above,
and
instead
of
providing
a
value,
a
set
of
parts
that
are
values
are
provided.
Here
is
an
example:
<Parameters xmlns="http://hl7.org/fhir">
<parameter>
<name value="operation"/>
<part>
<name value="type"/>
<valueCode value="add"/>
</part>
<part>
<name value="path"/>
<valueString value="Patient"/>
</part>
<part>
<name value="name"/>
<valueString value="contact"/>
</part>
<part>
<name value="value"/>
<part>
<name value="name"/>
<valueHumanName>
<text value="a name"/>
</valueHumanName>
</part>
</part>
</parameter>
</Parameters>
This pattern repeats as deep as necessary.
Note that for elements with a choice of data types, the FHIRPath name in the name of the parameter does not include the data type suffix (per the rules in the FHIRPath Specification), but the parameter value does. Here's an example:
{
"resourceType": "Parameters",
"parameter": [{
"name": "operation",
"part": [{
"name": "type",
"valueCode": "add"
}, {
"name": "path",
"valueString": "Specimen"
}, {
"name": "name",
"valueString": "processing"
}, {
"name": "value",
"part": [{
"name": "description",
"valueString": "testProcessing"
}, {
"name": "time",
"valueDateTime": "2021-08-18T11:32:55.6462761+02:00"
}]
}]
}
]
}
An example of adding an extension:
<Parameters xmlns="http://hl7.org/fhir">
<parameter>
<name value="operation"/>
<part>
<name value="type"/>
<valueString value="add"/>
</part>
<part>
<name value="path"/>
<valueString value="Specimen"/>
</part>
<part>
<name value="name"/>
<valueString value="processing"/>
</part>
<part>
<name value="value" />
<part>
<name value="description" />
<valueString value="test" />
</part>
<part>
<name value="time" />
<valueDateTime value="2021-08-13T07:44:38.342+00:00" />
</part>
<part>
<name value="extension" />
<part>
<name value="url" />
<valueUri value="http://example.org/fhir/DeviceExtension" />
</part>
<part>
<name value="value" />
<valueReference>
<reference reference="Device/1">
</valueReference>
</part>
</part>
</part>
</parameter>
</Parameters>
Applied to an empty Specimen, this would produce:
<Specimen xmlns="http://hl7.org/fhir">
<status value="available"/>
<processing>
<extension url="http://example.org/fhir/DeviceExtension">
<valueReference>
<reference reference="Device/1">
</valueReference>
</extension>
<description value="test"/>
<timeDateTime value="2021-08-13T07:44:38.342+00:00"/>
</processing>
</Specimen>
There
is
a
set
of
test
cases
for
implementers
in
the
fhir-test-cases
repository.
Note
that
the
path
parameter
value
is
a
FHIRPath
expression,
and
not
a
simple
path.
For
example,
in
the
following
patch
operation,
the
path
parameter
value
is
a
FHIRPath
expression
that
selects
the
period
element
of
the
identifier
element
with
a
use
value
of
official
.
{
"resourceType": "Parameters",
"parameter": [
{
"name": "operation",
"part": [
{
"name": "type",
"valueCode": "add"
},
{
"name": "path",
"valueString": "Patient.identifier.where(use = 'official').period"
},
{
"name": "name",
"valueString": "end"
},
{
"name": "value",
"valueDate": "2021-12-01"
}
]
}
]
}
There
is
a
set
of
test
cases
for
implementers
in
the
fhir-test-cases
repository.