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

Script to import and reassign CHAs with multiple CHP Areas #241

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kennsippell
Copy link
Member

@kennsippell kennsippell commented Jan 17, 2025

Script used for Digital Payment task https://app.clickup.com/t/1278154/CHT-13271 to create one account per CHA in Nairobi and Migori.

Here is the input for Nairobi for once the instance is back up.

Progress toward #185
Progress toward #70

cc @eljhkrr as FYI

@kennsippell
Copy link
Member Author

@freddieptf This was used to create CHA users in Nairobi this week. Would you kindly review at your convenience?

* Unit tests passing for reassignment

* Refactor to single "import-cha-users" script

* Update place contacts

* Round of testing
@kennsippell
Copy link
Member Author

@freddieptf I've updated this scripts to also support CSV-based bulk reassignment of CHUs. It's quite rough.

The script does the following:

  1. Accepts the standard minimal format for CHA replacement
  2. Downloads all primary contacts for all CHUs
  3. Attempts a string-match by primary contact's name and subcounty
  4. If no match is found, it prompts the user if these CHA accounts shoheuld be created
  5. If match is found, it "reassigns" the CHU to all user accounts associated with the primary contact's place

I considered three approaches for this broadly, focusing on the question "how do you know the username of the CHA who is the recipient of the CHU"

  1. Get the user to put the username directly into the CSV. I cons I saw are that it required a different CSV format, and is a bit harder for users. But I maybe I wish I had in the end.
  2. Lookup the user based on the "fullname" attribute in the users table. The cons I saw here are that it is difficult to group-by subcounty, there is no API endpoint to get users by role, the fullname of the user isn't always accurate or highly visible.
  3. Do a fetch of all primary contacts of CHUs. The cons of this is that it is expensive, and the result is ambiguous: if we are looking for the username of "Tom" and we find two of him and then look up usernames for those two places - there could be 10 users? I did this and updated all.

Imlementation notes:

  • I've created this as a script because I'm unclear how well this work will align with the UI work you're leading Support for having multiple places assigned to a user #185
  • Some aspects which seem very likely to be needed or unavoidable, I've built into UMT
  • If you plan to use an approach like this, a crux will be getting the primary contact information for string comparison. We dont fetch it now and if we ever did this for CHP-level areas, it'd be slow.

@kennsippell kennsippell changed the title Script to create CHAs with multiple CHP Areas Script to import and reassign CHAs with multiple CHP Areas Feb 1, 2025
function groupByKey(place: Place) {
const subcounty = place.resolvedHierarchy[1]?.name.formatted;
const contactName = place.contact.name;
return `${contactName}@${subcounty}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a higher chance of the CHA's phone number being more unique than their name

@freddieptf
Copy link
Collaborator

Downloads all primary contacts for all CHUs
Attempts a string-match by primary contact's name and subcounty

Is this necessary for re-assignments? if it's re-assigning then I'm assuming the CHA already exists in some CHU? Couldn't we just use the CHU which is unique and get the primary contact/user from there?

@kennsippell
Copy link
Member Author

kennsippell commented Feb 8, 2025

Is this necessary for re-assignments?

I gave three options for how to approach this in the text above. Sounds like you are proposing a fourth option here? The inputs you are imagining are something like:

  1. "For the CHA who manages X CHU"
  2. "They should now also manage Y CHU"

As mentioned above, I took the approach I did because it allows for the same template that exists today (supporting new CHAs, reassigning, replacing, etc all in one template). If you have opinions about the best approach, I am all ears. Or I am available to discuss. Personally, I feel if we are going to support a different template for replacement then we should prompt for the username directly rather than a 2nd CHU.

@kennsippell
Copy link
Member Author

CHA today had problems with their account because the contact_id on the user was deleted. Need to update this script to avoid that.

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

Successfully merging this pull request may close these issues.

2 participants