Add support for FHIR PATCH operations


I have been looking into the Add support for FHIR PATCH operations in the openmrs fhir2 module. Its unfortunate that this project has not been chosen for gsoc 2023 but nevertheless i thought i should share my findings and maybe when its matured enough to be taken on next time, we have a starter pack and maybe get more input on the project from the community.

Patch Requests explanation
  • PATCH requests essentially comprise of instructions on how to modify a resource or resources. Patch requests can be used to avoid sending a whole document when only a part has changed and this is where it basically differs with the PUT request.

  • Patch Request formats include the following JSON PATCH, XML PATCH which have to be implemented within the openmrs fhir2 module and in addition to those, the FHIR PATCH has to be included aswell as a way of ensuring that when slight changes are made to the Json document, the entire document does not have to be sent.

  • The Patch operations used within the above mentioned patch formats are add, replace, move, copy, test, remove.

We can get the necessary parameters for the patch operation from the HAPI framework and then pass those parameters along to the FhirService interface which is depended on by the resource providers. The interface can then be implemented within BaseFhirService class.

@ibacher advised that Supporting FHIRPath Patch is the most complicated part of the project because there’s no stand-alone library for it and the incoming format is a little FHIR-specific. Though he thinks there’s some stuff in HAPI we can use for inspiration.

For both JSON Patch and XML Patch, we can probably rely on existing libraries, e.g., like zjsonpatch, in which case the code we need needs to:

  1. Detect the incoming format
  2. Load the existing resource in the appropriate format
  3. Apply the patch

More Resources

/cc: @ibacher @dkayiwa @mozzy @kdaud