Skip to content

Role Mapping Not Saving When Updating Multiple Roles (Registrar/Nurse/Counsellor) - #162

Merged
vishwab1 merged 5 commits into
release-3.8.4from
vb/rolenoteedit
Sep 11, 2026
Merged

Role Mapping Not Saving When Updating Multiple Roles (Registrar/Nurse/Counsellor)#162
vishwab1 merged 5 commits into
release-3.8.4from
vb/rolenoteedit

Conversation

@vishwab1

Copy link
Copy Markdown
Member

📋 Description

JIRA ID: PSMRI/Admin-API#148

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

vishwab1 and others added 5 commits September 4, 2026 12:48
existingRoleIDs (from group.roles) and newRoleIDs (from roleIDs_duringEdit)
were compared with plain Array.includes() with no type coercion. When one
source returns roleID as a numeric string and the other as a number, an
already-existing role fails the match and gets bucketed into both
rolesToAdd and rolesToRemove, firing simultaneous create+delete calls that
race each other and can silently drop a role (e.g. Counsellor) on update.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rolesToAdd previously fired one SaveWorkLocationMapping POST per role
in parallel via forkJoin. The backend treats a create as the sole
active role for the user+serviceline+block scope, so separate parallel
creates raced each other and only the last commit stayed active -
dropping roles added alongside others (reproduced with StopTB
Counsellor + Nurse, where Nurse's row was born already deleted).

Batch all rolesToAdd into one call instead, with every new role in the
previleges[0].ID array - the same shape already used when two roles
are added together via Create New Mapping, which works correctly.
Location fields (incl. StopTB's nikshayTUID/nikshayFacilityID) are
per-group, not per-role, so batching does not change what is sent for
them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- newly-added roles (e.g. Nurse + Counsellor) must go out in a single
  SaveWorkLocationMapping call, not one per role
- an existing roleID stored as a numeric string must be treated as
  equal to the same roleID selected as a number, so it is kept
  in-place rather than spuriously added and removed at once

Regression coverage for the StopTB Counsellor/Nurse role-dropping bug
fixed in the previous two commits.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…HWC/FLW

Two related changes to updateGroupedWorkLocation()'s edit flow, both
scoped to make the Select Role checkboxes behave as the single source
of truth: checked = active, unchecked = soft-deleted, and re-checking a
previously-removed role reactivates it rather than piling up duplicates.

1. Stop TB rows are now grouped by user+TU (Nikshay block), same as
   HWC/FLW already are, so multiple roles for one user+location show as
   one row with multiple role chips instead of a separate row per role.
   This also removes the risk of an edit on one role's row reaching into
   an unrelated sibling row's role, since everything for that
   user+location is already one group.

2. A role in rolesToAdd that has an old soft-deleted row (group.roles
   keeps deleted entries; only existingRoleIDs filters them out) is now
   reactivated in place via the same {uSRMappingID, deleted:false} call
   the existing Activate button already uses, with its location/role
   fields refreshed to the current edit form — instead of always
   creating a brand-new duplicate row. Only roles with no prior row at
   all go through the batched create path added in the previous fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 60baac16-ad85-4cf1-94f4-dec424e31531

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@vishwab1
vishwab1 merged commit 9a1829f into release-3.8.4 Sep 11, 2026
4 checks passed
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