Skip to content

Fix the issue in Linking Care Context for V3#51

Merged
vanitha1822 merged 3 commits into
mainfrom
nd/vs/m2v3
Jun 25, 2026
Merged

Fix the issue in Linking Care Context for V3#51
vanitha1822 merged 3 commits into
mainfrom
nd/vs/m2v3

Conversation

@vanitha1822

@vanitha1822 vanitha1822 commented Jun 24, 2026

Copy link
Copy Markdown
Member

📋 Description

JIRA ID:

AMM-2290


✅ Type of Change

  • 🛠 Refactor (change that is neither a fix nor a new feature)

Summary by CodeRabbit

  • New Features

    • Updated health ID linking to use a direct care-context linking flow.
    • Added support for generating a link token and completing the link from the modal.
  • Bug Fixes

    • Removed the OTP entry and verification steps from the health ID modal.
    • Simplified the action button flow so linking can proceed without the previous OTP process.

@vanitha1822 vanitha1822 self-assigned this Jun 24, 2026
@vanitha1822 vanitha1822 requested a review from snehar-nd June 24, 2026 07:56
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR removes the OTP-based care-context mapping flow (generateOtpForMapping, verifyOtp, resendOtp, the OTP form, and related state) from HealthIdDisplayModalComponent. It replaces that flow with a token-based linkCareContextV3() method that calls two new RegistrarService HTTP POST endpoints, and updates the template accordingly.

Changes

Care-Context V3 Linking Flow

Layer / File(s) Summary
New RegistrarService HTTP methods
src/registrar/services/registrar.service.ts
Adds generateLinkTokenForCareContext(reqObj) and linkCareContextV3(reqObj) as public POST methods targeting their respective environment endpoints.
Remove OTP state/methods; implement linkCareContextV3()
src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts
Removes FormGroup/FormBuilder import, OTP fields, FormBuilder constructor injection, createOtpGenerationForm(), and the full OTP method block. Adds linkCareContextV3() which reads from SessionStorageService, generates a link token, calls the V3 link endpoint, and updates progress-bar and alert state.
Template: remove OTP gating and wire new button
src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html
Strips enablehealthIdOTPForm from *ngIf guards on the header, secondary table, and mapping section. Changes the mapping button to call linkCareContextV3() with a linkCareContext label. Removes the entire OTP entry form section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clearly related to the main change: fixing the V3 care context linking flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts (1)

182-299: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Refactor linkCareContextV3 below the cognitive-complexity threshold.

SonarCloud flags this method at 17 where 15 is allowed. Extract token/link request building and response/error handling into helpers, or flatten the nested subscriptions so this PR does not fail the quality gate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts`
around lines 182 - 299, The linkCareContextV3 method is too complex and needs to
be split up to meet the cognitive-complexity limit. Extract the token request
creation, link request creation, and the success/error handling for
generateLinkTokenForCareContext and linkCareContextV3 into separate helper
methods, or flatten the nested subscribe flow in
health-id-display-modal.component.ts while keeping the same behavior and alerts.
Use the existing linkCareContextV3 and related request/response symbols to
locate the logic and reduce branching in the main method.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html`:
- Around line 292-295: The link action in health-id-display-modal.component.html
remains clickable while linkCareContextV3() is already running, which can
trigger duplicate token generation and repeated care-context link requests.
Update the button’s disabled condition to also reflect the in-flight state
tracked by showProgressBar (or the equivalent loading flag used by
linkCareContextV3), so it stays disabled until the request completes. Keep the
existing selectedHealthID checks and use the linkCareContextV3 method and
showProgressBar state as the key references when wiring the guard.

---

Nitpick comments:
In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts`:
- Around line 182-299: The linkCareContextV3 method is too complex and needs to
be split up to meet the cognitive-complexity limit. Extract the token request
creation, link request creation, and the success/error handling for
generateLinkTokenForCareContext and linkCareContextV3 into separate helper
methods, or flatten the nested subscribe flow in
health-id-display-modal.component.ts while keeping the same behavior and alerts.
Use the existing linkCareContextV3 and related request/response symbols to
locate the logic and reduce branching in the main method.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f59fa767-624d-453f-92ea-1316adafb61e

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6fe40 and 4677d34.

📒 Files selected for processing (3)
  • src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html
  • src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.ts
  • src/registrar/services/registrar.service.ts

Comment on lines +292 to 295
(click)="linkCareContextV3()"
[disabled]="
selectedHealthID === undefined || selectedHealthID === null
"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Disable linking while the request is already in flight.

linkCareContextV3() sets showProgressBar, but this button stays enabled, so double-clicks can generate multiple tokens and send duplicate care-context link POSTs.

Proposed fix
-          (click)="linkCareContextV3()"
+          (click)="!showProgressBar && linkCareContextV3()"
           [disabled]="
-            selectedHealthID === undefined || selectedHealthID === null
+            selectedHealthID === undefined || selectedHealthID === null || showProgressBar
           "
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(click)="linkCareContextV3()"
[disabled]="
selectedHealthID === undefined || selectedHealthID === null
"
(click)="!showProgressBar && linkCareContextV3()"
[disabled]="
selectedHealthID === undefined || selectedHealthID === null || showProgressBar
"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/registrar/abha-components/health-id-display-modal/health-id-display-modal.component.html`
around lines 292 - 295, The link action in
health-id-display-modal.component.html remains clickable while
linkCareContextV3() is already running, which can trigger duplicate token
generation and repeated care-context link requests. Update the button’s disabled
condition to also reflect the in-flight state tracked by showProgressBar (or the
equivalent loading flag used by linkCareContextV3), so it stays disabled until
the request completes. Keep the existing selectedHealthID checks and use the
linkCareContextV3 method and showProgressBar state as the key references when
wiring the guard.

@vanitha1822 vanitha1822 merged commit 43e854c into main Jun 25, 2026
6 of 7 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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