FHIR Chat · PATCH a List · hapi

Stream: hapi

Topic: PATCH a List


view this post on Zulip Michael Sauer (Mar 17 2021 at 18:37):

I like to manage a List of Patients in a List-Ressource.

To add a Patient I use:

[
   { "op": "add", "path": "/entry/0", "value":
      {
         "item":
         {
            "reference": "Patient?identifier=urn:oid:1.2.276.0.76.3.1.139.100.2|40137998"
         }
      }
    }
]

That works fine. The operation add an entry like the following to the list:

       {
            "item": {
                "reference": "Patient/24d7329b-67a9-4855-965d-dd8a849b9f30"
            }
        }

Now I want to remove this entry, and thought that this should work:

[{ "op": "remove", "path": "/entry/", "value":{"item":{"reference": "Patient?identifier=urn:oid:1.2.276.0.76.3.1.139.100.2|40137998"}}}]

or maybe:

[{ "op": "remove", "path": "/entry/", "value":{"item":{"reference": "Patient/24d7329b-67a9-4855-965d-dd8a849b9f30"}}}]

But I got this error using SMILE CDR:

{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "no such path in target JSON document"
        }
    ]
}

Any idea, what I can do to remove an entry from the list?
Thank's for helping!

Michael

view this post on Zulip Dexter (Mar 18 2021 at 06:47):

I think it should be "path": "/entry/0" when removing the item, and you don't need the value key.

It should just be,

[
    {
        "op": "remove",
        "path": "/entry/0"
    }
]

Here's the JSON Patch RFC with the relevant examples

view this post on Zulip Dexter (Mar 18 2021 at 07:01):

Hi, just saw your message in the other thread. Are you trying to check the element before removing it?

view this post on Zulip Michael Sauer (Mar 19 2021 at 07:11):

I know which patient I want to remove, but I don‘t know the index. The list can be very long - so I don‘t want to transfer the complete list to the client. I thought that I can use the reference value to find the entry and remove it.

view this post on Zulip Michael Sauer (Mar 19 2021 at 07:15):

Do you think it is possible to do this using FHIR-Patch?

view this post on Zulip Dexter (Mar 19 2021 at 11:33):

I'm not sure, but what I've resorted to doing is make a GET, then modify the payload as you see fit, and PATCH with a test and replace to ensure I'm PATCHing the same data that I have

Something like this

[
    {
        "op": "test",
        "path": "/meta/VersionId",
        "value": "1"
    },
    {
        "op": "replace",
        "path": "path-to-data",
        "value": { ... }
    },
    {
        "op": "replace",
        "path": "",
        "value": { this replaces the whole object from the root }
    },
    // more things
]

view this post on Zulip Dexter (Mar 19 2021 at 11:38):

In your case, it'd be

// Get the data, get the version,
// check the list and find the index of the element to delete
[
    {
        "op": "test",
        "path": "/meta/VersionId",
        "value": "version-you-got-above"
    },
    {
        "op": "delete",
        "path": "path-to-data/index",
    },
]

On a sidenote, I think we both asked the question in the wrong stream. Not sure, maybe someone can let us know


Last updated: Apr 12 2022 at 19:14 UTC