Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FHIRPath Patch support #3084

Open
FlixCoder opened this issue Oct 19, 2023 · 1 comment
Open

Add FHIRPath Patch support #3084

FlixCoder opened this issue Oct 19, 2023 · 1 comment

Comments

@FlixCoder
Copy link

Hi!

I am making a PATCH request to a Patient with the following body:

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "operation",
      "part": [
        {
          "name": "type",
          "valueCode": "add"
        },
        {
          "name": "path",
          "valueString": "Patient"
        },
        {
          "name": "name",
          "valueString": "birthDate"
        },
        {
          "name": "value",
          "valueDate": "2021-02-01"
        }
      ]
    },
    {
      "name": "operation",
      "part": [
        {
          "name": "type",
          "valueCode": "delete"
        },
        {
          "name": "path",
          "valueString": "Patient.active"
        }
      ]
    },
    {
      "name": "operation",
      "part": [
        {
          "name": "type",
          "valueCode": "replace"
        },
        {
          "name": "path",
          "valueString": "Patient.gender"
        },
        {
          "name": "value",
          "valueCode": "female"
        }
      ]
    },
    {
      "name": "operation",
      "part": [
        {
          "name": "type",
          "valueCode": "insert"
        },
        {
          "name": "path",
          "valueString": "Patient.name"
        },
        {
          "name": "index",
          "valueInteger": 0
        },
        {
          "name": "value",
          "valueHumanName": {
            "family": "Family"
          }
        }
      ]
    }
  ]
}

The Patient resource can be either empty or look as follows:

{
	"resourceType": "Patient",
	"active": false,
	"name": [
		{
			"family": "Test"
		}
	],
	"gender": "male",
	"id": "0e302b42-d9a8-468d-a5c0-dea6ade9811b",
	"meta": {
		"versionId": "16779e39-7164-4e0a-a4d8-8d00aab42426",
		"lastUpdated": "2023-10-19T17:03:05.835Z"
	}
}

Medplum returns the following OperationOutcome:

{
	"resourceType": "OperationOutcome",
	"issue": [
		{
			"severity": "error",
			"code": "invalid",
			"details": {
				"text": "patch.map is not a function"
			}
		}
	],
	"extension": [
		{
			"url": "https://medplum.com/fhir/StructureDefinition/tracing",
			"extension": [
				{
					"url": "requestId",
					"valueUuid": "57c13314-f51c-4c01-af65-be10fe2dd1bc"
				},
				{
					"url": "traceId",
					"valueUuid": "5d99bbf5-5e24-4696-8e0b-ff245f0cdbd6"
				}
			]
		}
	]
}

Could you tell me what is going wrong? Is this a bug?

The same request works with the HAPI FHIR server, so I assume the request is correct, but please tell me if it is actually incorrect.

Thank you!

@codyebberson
Copy link
Member

codyebberson commented Oct 20, 2023

Hi @FlixCoder - thanks for submitting.

It looks like your request uses "FHIRPatch Operations", which we currently do not support.

According to the FHIR spec, PATCH includes 3 different patch formats:

https://hl7.org/fhir/r4/http.html#patch

The body of a PATCH operation SHALL be either:

  • a JSON Patch document with a content type of application/json-patch+json
  • an XML Patch document with a content type of application/xml-patch+xml
  • a FHIRPath Patch parameters resource with FHIR Content Type

The Medplum FHIR server currently only supports JSONPatch input.

Here is your request converted into JSONPatch:

[
  {
    "op": "add",
    "path": "/birthDate",
    "value": "2021-02-01"
  },
  {
    "op": "remove",
    "path": "/active"
  },
  {
    "op": "replace",
    "path": "/gender",
    "value": "female"
  },
  {
    "op": "add",
    "path": "/name/0",
    "value": {
      "family": "Family"
    }
  }
]

Let me investigate how hard it would be to add the "FHIRPath Patch" support.

@reshmakh reshmakh added this to the Milestone Quality milestone Oct 25, 2023
@codyebberson codyebberson changed the title PATCH returns "patch.map is not a function" Add FHIRPath Patch support Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants