DataMutations and Relationships

I have created a relationship in a DHIS2 custom app - using this datamutation format:

> const mutationRelationships = {
    resource: 'relationships',
    type: 'create',
    data: ({ trackedEntityInstance, eventID, type }) => ({
        relationshipType: type,
        from: {
            event: {
                event: eventID,
            },
        },
        to: {
            trackedEntityInstance: {
                trackedEntityInstance: trackedEntityInstance,
            },
        },        
    }),
};

The relationship does create correctly - however when reviewing I am getting a strange output via the API - /api/relationships/lYCmgpI5UHe - output is coming back ill formed and looking like this :

While odd this is fine - as I just need to access the relationships via the events - /api/events/Uqn71FfIPYk - i get the following output:
image

All good - the primary issue comes now in if i need to delete this relationship. By using the data mutation -
const mutation = {resource: 'relationships', type: 'delete', id: id, }

This does delete the relationship - as in " /api/relationships/lYCmgpI5UHe" - however the relationship associated with the entity still exists even though the relationship is deleted. How can this relationship detail be removed from the Event using a mutation - tried multiple options but not succeeded.

Any advice will be appreciated.

TIA

Hi @matthew_deas

What version is the DHIS2 instance you’re using for testing and development?

The events API endpoint is a deprecated endpoint so it’d be better to test using the newer endpoints.

What about the endpoint /api/tracker/trackedEntities/b3LugZn1Vic do you still see it there?

Thanks!

Hi @Gassim - thanks so much for the reply.

Will test with the new endpoints format to see if I can get the correct responses out - this is using version 2.39.4.1.

I created a new relationship - and checked the endpath you provided - nowhere in that is the relationship mentioned - however I should be able to get it via

/api/tracker/relationships?event=JW708OHzDhU

On deleting of the relationship however - when I go via this endpoint:

/api/tracker/relationships/JW708OHzDhU

I get this

{
"httpStatus": "Not Found",
"httpStatusCode": 404,
"status": "ERROR",
"message": "Relationship not found for uid: MKTRPwk69qv"
}

However on rerunning the prior endpoint /api/tracker/relationships?event=JW708OHzDhU I am still seeing the relationship:

{
   "page": 1,
   "pageSize": 50,
    "instances": [
      {
          "relationship": "MKTRPwk69qv",
          "relationshipType": "ZBUwOGosqI0",
           "from": {
                   "event": {
                            "event": "JW708OHzDhU"
                   }
            },
            "to": {
                  "trackedEntity": {
                       "trackedEntity": "YgmsJybEfA3"
                    }
             }
     }
     ]
}

The only workaround I can do on this - is to run the relationships?event and then do a follow up query if the relationship ID is still valud - but that seems like a lot of processing for this.

1 Like

Maybe this has to do with “soft deleted” data or cache? :thinking: Are you able to see the relationship on the frontend? Are there any cases when the deletion isn’t successful yet received a success response?

I’m wondering if this is the case when deleting using the frontend as well? If so then either there’s a reason for that or it’s a bug.

Thanks!

No - relationship is not visible on the frontend - works accurately. Even on manual deletion same process applies - relationship is not found when searching on

/api/tracker/relationships/Y1OChur9PcA
OUTPUT:
{
"httpStatus": "Not Found",
"httpStatusCode": 404,
"status": "ERROR",
"message": "Relationship not found for uid: Y1OChur9PcA"
}

However it is still there on the following:

/api/tracker/relationships?event=z26ch8SRRtM
OUTPUT:
{
"page": 1,
"pageSize": 50,
"instances": [
                    {
                      "relationship": "Y1OChur9PcA",
                      "relationshipType": "ZBUwOGosqI0",
                      "from": {
                               "event": {
                                      "event": "z26ch8SRRtM"
                                }
                       },
                      "to": {
                         "trackedEntity": {
                         "trackedEntity": "AsPAun7ryJe"
                          }
                       }
                    }
                  ]
}

1 Like

Okay, I think it’s fair to create a bug issue for this. Would you like to create a Jira bug issue on Projects - Jira? Please share the ticket here for follow up and so others can choose to comment or watch [receive notifications on updates to the ticket]…

Thanks!

I’m unsure whether this is a case of needing to create a new ticket - this just needs to be worked on - checked Jira and found this - and I’m experiencing the same issue. While the link is still there and I can see it - now the biggest issue is I cannot relink TEI’s to Events.

https://dhis2.atlassian.net/browse/DHIS2-16162

This is basically the same issue. I’m going to have to perform a workaround until this is resolved.

1 Like

We created a bug issue and I have seen AL-Gassim’s comments. No traction. We are now seeing an issue where the creation of relationships simply fails. We cannot discern a particular pattern for when this happens, but it is affecting some of our users. We are trying to diagnose if these issues are related as best we can. We are using the same version as Matthew, 2.39.4.1

Matthew were you able to find a workaround?

Hi @MELB - apologies for the delayed reply.

I did a workaround by storing the relationship essentially in the DataElements of the relevant program stages - its not pretty but it does the job and as I am implementing a custom frontend it isnt too problematic.

1 Like