Event duplicated by uid

I’ve imported events with the api (post on /api/events) with “pre assigned uid” in the “event” field
It’s a technique that worked great on my previous tracker import (the events gets updated and not duplicated)

But here it’s a “simple program” without registration.
It’s super strange, it seems that I managed to create 2 events with the same uuid

now this api call : /api/events?fields=event&program=c9j4wleJAcU

returns

{
  "pager": {
    "page": 1,
    "pageSize": 50,
    "isLastPage": false
  },
  "events": [
    {
      "event": "NNsTgSQHnfw",
      "created": "2023-09-29T00:00:00.000"
    },
    {
      "event": "NNsTgSQHnfw",
      "created": "2023-09-29T00:00:00.000"
    },

when looking in the program_stage_instance it looks unique…

in the things I noticed, I have a note…

    {
      "event": "NNsTgSQHnfw",
      "created": "2023-09-29T00:00:00.000",
      "notes": [
        {
          "lastUpdated": "2023-09-29T00:00:00.000",
          "note": "rL5Wm24NP4a",
          "storedDate": "2023-09-29T00:00:00.000",
          "storedBy": "s_mestach",
          "value": "imported "
        }
      ]
    },
    {
      "event": "NNsTgSQHnfw",
      "created": "2023-09-29T00:00:00.000",
      "notes": [
        {
          "lastUpdated": "2023-09-29T00:00:00.000",
          "note": "CMXnuLQ5yPU",
          "storedDate": "2023-09-29T00:00:00.000",
          "storedBy": "s_mestach",
          "value": "imported "
        }
      ]
    },

So I assume there’s a kind of “duplication” for each note instead of having an array of notes.

1 Like

Hi @Stephan_Mestach

The id of the note is not preassigned so maybe that’s why it looks unique.

But aren’t we here dealing with two different events except that somehow they’ve got the same id during import?

What version of dhis2 are you using? If you are using DHIS2 version 2.36 and above, would it be possible to test using api endpoint /api/tracker/events instead of the deprecated /api/events endpoint? (see the updates here in this docs please: Tracker - DHIS2 Documentation)

If the /api/tracker/events endpoint still doesn’t work, would you share the steps to reproduce this on any of the play.dhis2.org instances?

Thanks!

indeed the note I forgot to pre assigned an id, in the meantime I removed the note.

steps to reproduce on play

  1. install the app “DHIS2 Taskr” DHIS 2 Demo - Sierra Leone
  2. create a new recipe in the app with the + button : DHIS 2 Demo - Sierra Leone
  3. paste the content below
    3.1 the recipe create 2 events (with a preassigned id ohAH6BXIMad) with a note (without pre assigned id)
    3.2 then fetch the events for that program
  4. run the recipe
  5. you will see that the event are not “duplicated” in the programstageinstance but are in the /api/events
    DHIS 2 Demo - Sierra Leone
    same for /api/tracker/events DHIS 2 Demo - Sierra Leone
    note that this happen even if you don’t ask for the notes field
const api = await dhis2.api();

const eventId = "ohAH6BXIMad";

const event = {
  programStage: "dBwrot7S420",
  programType: "WITHOUT_REGISTRATION",
  orgUnit: "DiszpKrYNg8",
  program: "lxAQ7Zs9VYR",
  event: eventId,
  status: "COMPLETED",
  orgUnitName: "Ngelehun CHC",
  eventDate: "2023-04-07T00:00:00.000",
  deleted: false,
  dataValues: [
    {
      dataElement: "vANAXwtLwcT",
      value: "9"
    },
    {
      dataElement: "sWoqcoByYmD",
      value: "false"
    }
  ],
  notes: [{ value: "imported " }]
};

await api.post("events", { ...event, notes: [{ value: "imported 1" }] });

await api.post("events", { ...event, notes: [{ value: "imported 2" }] });

const ou = await api.get("events", {
  program: "lxAQ7Zs9VYR",
  fields: ":all,notes",
  paging: false
});

return ou.events.filter(e => e.event == eventId);

the problem is more that the list returned
is

   [  
     { event: "ohAH6BXIMad" , notes: [ { value: "imported 1"}] },
     { event: "ohAH6BXIMad" , notes: [ { value: "imported 2"}] }
   ]

instead of

   [  
     { event: "ohAH6BXIMad" , notes: [ { value: "imported 1"}, { value: "imported 2"}] }
   ]

there’s probably a join on notes but no “grouping” of the object/event by uid.
the problem is not the “import” but the payload returned by /api/events query when an event has more than 1 note.