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

wf2 - map latest answer to sex from encounter to TEI #38

Open
aleksa-krolls opened this issue Sep 30, 2024 · 8 comments
Open

wf2 - map latest answer to sex from encounter to TEI #38

aleksa-krolls opened this issue Sep 30, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@aleksa-krolls
Copy link
Member

aleksa-krolls commented Sep 30, 2024

Background, context, and business value

Sometimes sex is specified on an OMRS form/encounter in a later consultation. If answered, we will need to map this answer for sex from the encounter to the trackedEntityInstance record.

The specific request, in as few words as possible

If either the mhpss baseline form (encounter id: 6a3e1e0e-dd13-3465-b8f5-ee2d42691fe5) or mhgap baseline form (encounter id: 82db23a1-4eb1-3f3c-bb65-b7ebfe95b19b) have sex specified, then map this value to the dhis2 TEI record.

  • Check the mhpss baseline encounter first --> and map answer if the sex concept is found.
  • If not found, then check the mhgap baseline encounter --> and map answer if the sex concept is found.
  • If an answer for sex is found in neither encounter, then no action required.

See example code snippet below. If either encounter contains an obs[x] where concept.uuid = 'ec42d68d-3e23-43de-b8c5-a03bb538e7c7', then map the obs[x].uuid answer using the optionsMap --> to dhis2 attribute: qptKDiv9uPl

"obs": [
 {
                    "uuid": "87d4e635-fdf4-447a-9a79-1bf89dde9344",
                    "display": "Sexe: Unknown",
                    "concept": {
                        "uuid": "ec42d68d-3e23-43de-b8c5-a03bb538e7c7",
                        "display": "Sexe",

Workflow

wf2 --> I think you'll need to update step 6-create-events to add a step to update the parent TEI again if an answer for sex is found in either of the 2 encounters.

Your mapping will look something like this...

attribute: 'qptKDiv9uPl',
value: genderOptions[patient.person.gender],

Output

qptKDiv9uPl is the only attribute you'll need to update for this TEI, so your final payload will probably look like this...

program: 'w9MSPn5oSqp',
orgUnit: 'OPjuJMZFLop',
trackedEntityType: 'cHlzCA2MuEF',
 attributes: [
          {
            attribute: 'qptKDiv9uPl', //gender
            value: optionMap[encounter.latestAnswerSex],
          },
          {
            attribute: 'AYbfTPYMNJH', //OpenMRS Patient UID to use to upsert TEI
            value: patient.uuid,
          },

Testing guidance

Try running wf2 with this cursor to get patient {"lastRunDateTime": "2024-09-30T07:00:00.000Z"} to test this with.

Toggl

MSF 2024

@aleksa-krolls aleksa-krolls added the enhancement New feature or request label Sep 30, 2024
@aleksa-krolls
Copy link
Member Author

@mtuchi this is a tricky one... I suggest we pair on it later today

@aleksa-krolls
Copy link
Member Author

aleksa-krolls commented Oct 1, 2024

hey @mtuchi for this one...

  1. Gist updated and new link added to staging --> add dhis2 option codes for sex
  2. See "sex" diagram in LucidChart for what we discussed
  3. If you use the cursor 2024-09-29, then you will find some patients like Anna (uid: 716e3fce-5483-4cce-99e9-cd2fae999a67) where a different gender is specified in the encounter than on her patient record.

@mtuchi
Copy link
Collaborator

mtuchi commented Oct 2, 2024

I need fresh eyes on this one, I think get-encounters step need to start before upsert-teis step i just need to figure out the mapping

@aleksa-krolls
Copy link
Member Author

@mtuchi as discussed...

  • let's add this step at the end so it can be turned on/off in future projects
  • let's update TEIs in bulk using the TEI id
  • only update TEIs in this step if the patient has an encounter where sex is specified. (FYI I added another test patient Yudi that has 1 encounter where gender is not specified, so therefore he would be excluded from this update step)
    Image

@mtuchi
Copy link
Collaborator

mtuchi commented Oct 3, 2024

Hiya @aleksa-krolls i have added the update-teis step in the wf2. See #44. I have tested locally running only the update-teis step because create-events step is throwing some errors and i can't seem to figure out the issue. See error ⬇

// TEI: Wn43LPkTyjv
 "conflicts": [
   {
      "object": "G0hLyxqgcO7",
      "value": "value_not_true_only"
   }
 ],

@mtuchi
Copy link
Collaborator

mtuchi commented Oct 3, 2024

Hiya @aleksa-krolls i have tested locally the whole workflow for lastRunDateTime: "2024-09-30" and it ran successfully and updated one trackedEntity. I have commented out G0hLyxqgcO7 because it was causing an error when creating an event, please help troubleshoot that. Otherwise the PR #44 is ready review

aleksa-krolls added a commit that referenced this issue Oct 3, 2024
* update gist url

* add gender updated mappings and update TEIs to address #38 

* update lastRunDateTime

* add update-teis step

* commented out G0hLyxqgcO7

* add log when creating an event

* update optionsMap gist link

latest optionSets

---------

Co-authored-by: Aleksa Krolls <[email protected]>
@aleksa-krolls
Copy link
Member Author

hey @mtuchi this is generally looking pretty good, but per the logs I'm wondering if we're mapping more encounters than we need to. Can you please check out my comments (yellow post-its) in this "sex" diagram and lmk if we need to make any other changes?

Also fyi there is a known issue with some of the OMRS sex options missing from the optionMap... I am working with the client to resolve this.

@mtuchi
Copy link
Collaborator

mtuchi commented Oct 4, 2024

@aleksa-krolls i have found the issue and worked on a fix, See my PR #46. You can merge and test again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants