This wiki has undergone a migration to Confluence found Here
FHIR Patch Examples
Contents
- 1 Adding an attribute to a non-list object
- 2 Adding an attribute to a list object identified by index
- 3 Adding an attribute to a list object identified by predicate
- 4 Adding a simple non-list object
- 5 Adding a complex non-list object
- 6 Appending a simple object to a list
- 7 Appending a complex object to a list
- 8 Prepending a simple object to a list
- 9 Prepending a complex object to a list
- 10 Inserting a simple object into a list by index (xml pos="before")
- 11 Inserting a simple object into a list by index (xml pos="after")
- 12 Inserting an simple object into a list by predicate (xml pos="before")
- 13 Inserting an simple object into a list by predicate (xml pos="after")
- 14 Inserting a complex object into a list by index (xml pos="before")
- 15 Inserting a complex object into a list by index (xml pos="after")
- 16 Replacing an attribute on a non-list object
- 17 Replacing an attribute on a list object selected by index
- 18 Replacing an attribute on a list object selected by predicate
- 19 Replacing a non-list object
- 20 Replacing an object in a list selected by index
- 21 Replacing an object in a list selected by predicate
- 22 Replacing all entries in a list with a single object
- 23 Removing an attribute on a non-list object
- 24 Removing an attribute on a list object selected by index
- 25 Removing an attribute on a list object selected by predicate
- 26 Removing a non-list object
- 27 Removing a list object selected by index
- 28 Removing a list object selected by predicate
- 29 Removing an entire list
Adding an attribute to a non-list object
<diff><add sel="Patient/gender" type="@id">patient-1-gender-1</add></diff> [{"op":"add", "path":"/_gender/id", "value":"patient-1-gender-1"}]
Adding an attribute to a list object identified by index
<diff><add sel="Patient/identifier[1]" type="@id">identifier-1</add>/diff> [{"op":"add", "path":"/identifier/0/id", "value":"identifier-1"}]</code
Adding an attribute to a list object identified by predicate
<diff><add sel="Patient/identifier[use/@value='usual']" type="@id">identifier-1</add></diff>
n/a for json
Adding a simple non-list object
<diff><add sel="Patient/managingOrganization"><display value="Massachusetts General Hospital"/></add>/diff> [{"op":"add", "path":"/managingOrganization/display", "value":"Massachusetts General Hospital"}]
Adding a complex non-list object
<diff><add sel="Patient"><animal><species><text value="human"/><coding><system value="http://hl7.org/fhir/animal-species"/><code value="1234-5"/><display value="human"/></coding></species></animal></add>/diff> [{"op":"add", "path":"/animal", "value":{"species":{"text":"human", "coding":[{"system":"http://hl7.org/fhir/animal-species", "code":"1234-5", "display":"human"}]}}}]
Appending a simple object to a list
<diff><add sel="Patient/name[1]"><given value="Matt"/></add>/diff> [{"op":"add", "path":"/name/0/given/-", "value":"Matt"}]
Appending a complex object to a list
<diff><add sel="Patient"><name><use value="old"/><family value="Hutz"/><given value="Lionel"/><given value="J"/><suffix value="JD"/><suffix value="Esq."/><period><end value="1997-08-02"/></period></name></add>/diff> [{ "op":"add", "path":"/name/-", "value":{"use":"old", "family":["Hutz"], "given":["Lionel","J"], "suffix":["JD","Esq."], "period":{"end":"1997-08-02"}} }]
Prepending a simple object to a list
<diff><add sel="Patient/name[1]" pos="prepend"><given value="John"/></add>/diff> [{"op":"add", "path":"/name/0/given/0", "value":"John" }]
Prepending a complex object to a list
<diff><add sel="Patient" pos="prepend"><name><use value="nickname"/><given value="Pedro"/></name></add>/diff> [{"op":"add", "path":"/name/0", "value":{"use":"nickname", "given":["Pedro"]} }]
Inserting a simple object into a list by index (xml pos="before")
<diff><add sel="Patient/name[1]/given[1]" pos="before"><given value="Matthew"/></add>/diff> [{"op":"add", "path":"/name/0/given/0", "value":"Matthew"}]
Inserting a simple object into a list by index (xml pos="after")
<diff><add sel="Patient/name[1]/given[1]" pos="after"><given value="Matthew"/></add>/diff> [{"op":"add", "path":"/name/0/given/1", "value":"Matthew"}]
Inserting an simple object into a list by predicate (xml pos="before")
<diff><add sel="Patient/name[1]/given[@value='James']" pos="before"><given value="Michael"/></add></diff>
n/a for json
Inserting an simple object into a list by predicate (xml pos="after")
<diff><add sel="Patient/name[1]/given[@value='James']" pos="after"><given value="Michael"/></add></diff>
n/a for json
Inserting a complex object into a list by index (xml pos="before")
<diff><add sel="Patient/name[2]" pos="before"><name><use value="old"/><family value="Hutz"/><given value="Lionel"/><given value="J"/><suffix value="JD"/><suffix value="Esq."/><period><end value="1997-08-02"/></period></name></add>/diff> [{ "op":"add", "path":"/name/1", "value":{"use":"old", "family":["Hutz"], "given":["Lionel","J"], "suffix":["JD","Esq."], "period":{"end":"1997-08-02"}} }]
Inserting a complex object into a list by index (xml pos="after")
<diff><add sel="Patient/name[1]" pos="after"><name><use value="old"/><family value="Hutz"/><given value="Lionel"/><given value="J"/><suffix value="JD"/><suffix value="Esq."/><period><end value="1997-08-02"/></period></name></add>/diff> [{ "op":"add", "path":"/name/1", "value":{"use":"old", "family":["Hutz"], "given":["Lionel","J"], "suffix":["JD","Esq."], "period":{"end":"1997-08-02"}} }]
Replacing an attribute on a non-list object
<diff><replace sel="Patient/birthDate/@value">1984-10-11</replace>/diff> [{ "op":"replace", "path":"/birthDate", "value":"1984-10-11" }]
Replacing an attribute on a list object selected by index
<diff><replace sel="Patient/name[1]/given[1]/@value">Petey</replace>/diff> [{ "op":"replace", "path":"name/0/given/0", "value":"Petey" }]
Replacing an attribute on a list object selected by predicate
<diff><replace sel="Patient/name[1]/given[@value='Peter']/@value">Pedro</replace></diff>
n/a for json
Replacing a non-list object
<diff><replace sel="Patient/managingOrganization"><managingOrganization><reference value="Organization/536"/><display value="MGH"/></managingOrganization></replace>/diff> [{ "op":"replace", "path":"/managingOrganization", "value":{"reference":"Organization/536", "display":"MGH"} }]
Replacing an object in a list selected by index
<diff><replace sel="Patient/name[2]"><name><use value="usual"/><given value="Jimmy"/></name></replace>/diff> [{ "op":"replace", "path":"/name/1", "value":{"use":"usual", "given":["Jimmy"]} }]
Replacing an object in a list selected by predicate
<diff><replace sel="Patient/name[use/@value='official']/given[@value='Peter']"><given value="Pierre"/></replace></diff>
n/a for json
Replacing all entries in a list with a single object
<diff><replace sel="Patient/name"><name><use value="official"/><family value="Johnson"/><given value="Eric"/><given value="Middle"/></name></replace>/diff> [{ "op":"replace", "path":"/name", "value":[{"use":"official", "family":["Johnson"], "given":["Eric", "Middle"]}] }]
Removing an attribute on a non-list object
<diff><remove sel="Patient/name[1]/use/@value"/>/diff> [{ "op":"remove", "path":"/name/0/use" }]
Removing an attribute on a list object selected by index
<diff><remove sel="Patient/birthDate/extension[1]/@url"/>/diff> [{ "op":"remove", "path":"/birthDate/extension/0/url" }]
Removing an attribute on a list object selected by predicate
<diff><remove sel="Patient/name[use/@value='official']/given[@value='James']/@value"/></diff>
n/a for json
Removing a non-list object
<diff><remove sel="Patient/managingOrganization"/>/diff> [{ "op":"remove", "path":"/managingOrganization" }]
Removing a list object selected by index
<diff><remove sel="Patient/name[1]"/>/diff> [{ "op":"remove", "path":"/name/0" }]
Removing a list object selected by predicate
<diff><remove sel="Patient/name[use/@value='usual']"/></diff>
n/a for json
Removing an entire list
<diff><remove sel="Patient/name"/>/diff> [{ "op":"remove", "path":"/name" }]