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

Error with Json Patch #2342

Closed
evance-mose opened this issue Nov 28, 2023 · 3 comments · Fixed by #2370
Closed

Error with Json Patch #2342

evance-mose opened this issue Nov 28, 2023 · 3 comments · Fixed by #2370
Assignees
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue type:bug Something isn't working

Comments

@evance-mose
Copy link

evance-mose commented Nov 28, 2023

Describe the bug
Right now, we have a problem adding multiple activities to the CarePlan. The issue lies in the Json Patch. It's giving us the same path for each activity in the patch file. When the changes are merged, the system compares them based on the path in this file .associateBy { it.optString("op") to it.optString("path") }. This causes it to pick only one activity that's being updated, resulting in the server returning a CarePlan with just one added activity.

After investigating the Json Patch further, it seems there are problems with it, causing it to return the wrong patch. json-patch

Component
Fhir Engine

To Reproduce
Steps to reproduce the behavior:

  1. Open an existing CarePlan in app (already in sync with server)
  2. Update it to add 2 or more Task activities to the CarePlan, to generate LocalChange for the CarePlan
  3. Sync to server, only the last task activity in the Careplan gets synced

Additional context
Patch File - LocalChange payload

[
  {
    "op": "replace",
    "path": "/activity/6/detail/status",
    "value": "in-progress"
  },
  {
    "op": "add",
    "path": "/activity/-",
    "value": {
      "outcomeReference": [
        {
          "reference": "Task/4f26da79-4571-4442-911a-c3a707e3e662",
          "display": "Viral Load Collection"
        }
      ],
      "detail": {
        "kind": "Task",
        "code": {
          "coding": [
            {
              "system": "https://d-tree.org/",
              "code": "art-client-viral-load-collection"
            }
          ]
        },
        "status": "in-progress",
        "scheduledPeriod": {
          "start": "2023-11-15T11:45:40+02:00",
          "end": "2023-12-14T11:10:34.227+03:00"
        },
        "performer": [
          {
            "reference": "Practitioner/311015",
            "display": "John Doe"
          }
        ],
        "description": "Viral Load Collection"
      }
    }
  },
  {
    "op": "add",
    "path": "/activity/-",
    "value": {
      "outcomeReference": [
        {
          "reference": "Task/6f6e6672-ef2d-4e57-9854-0a04cd0fb001",
          "display": "Index Case Testing"
        }
      ],
      "detail": {
        "kind": "Task",
        "code": {
          "coding": [
            {
              "system": "https://d-tree.org/",
              "code": "art-client-index-case-testing"
            }
          ]
        },
        "status": "in-progress",
        "scheduledPeriod": {
          "start": "2023-11-15T11:45:40+02:00",
          "end": "2023-12-14T11:10:34.227+03:00"
        },
        "performer": [
          {
            "reference": "Practitioner/311015",
            "display": "John Doe"
          }
        ],
        "description": "Index Case Testing"
      }
    }
  }
]

Local CarePlan.
local-careplan.json

Remote CarePlan
remote-careplan.json

Would you like to work on the issue?
yes, @LZRS and @evance-mose

cc @KhumboLihonga

@aditya-07 aditya-07 added effort:medium Medium effort - 3 to 5 days P1 High priority issue labels Nov 29, 2023
@omarismail94 omarismail94 self-assigned this Nov 29, 2023
@kelvin-ngure
Copy link

kelvin-ngure commented Dec 11, 2023

This issue is also causing household members to disappear when syncing.

The same line of code @evance-mose pointed out causes add patch operations performed on the same Group.member resource to disappear. This is because having the key of the hashmap be a non unique value (i.e the op) causes the overwrite

@aditya-07
Copy link
Contributor

@evance-mose @omarismail94 Is anyone working on this?

@omarismail94
Copy link
Contributor

I've created PR#2370 as a fix. @kelvin-ngure @evance-mose can you cherry-pick the commit and see if that resolves the issue?

@fredhersch fredhersch moved this from New to PR under Review in Android FHIR SDK Feb 7, 2024
@fredhersch fredhersch assigned jingtang10 and unassigned omarismail94 Feb 7, 2024
@fredhersch fredhersch added the type:bug Something isn't working label Feb 7, 2024
@github-project-automation github-project-automation bot moved this from PR under Review to Complete in Android FHIR SDK Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue type:bug Something isn't working
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

6 participants