Skip to content

[ENG-882] Gate empty-state Create Encounter button by can_create_encounter permission - #16640

Open
rithviknishad wants to merge 1 commit into
developfrom
rithviknishad/fix-encounter-history-permission-gate
Open

[ENG-882] Gate empty-state Create Encounter button by can_create_encounter permission#16640
rithviknishad wants to merge 1 commit into
developfrom
rithviknishad/fix-encounter-history-permission-gate

Conversation

@rithviknishad

@rithviknishad rithviknishad commented Aug 5, 2026

Copy link
Copy Markdown
Member

ENG-882

Problem

The empty-state "Create Encounter" button in EncounterHistory.tsx rendered unconditionally. The other 3 encounter creation entry points check can_create_encounter before render:

  • Patient home page
  • Appointment "Start Consultation"
  • Appointment "Create Planned Encounter"

Fix

Destructure canCreateEncounter from getPermissions (same helper the other entry points use) and gate the button render on it.

Test

  • Verified tsc --noEmit shows no new errors for the changed file.
  • Manual review: button now only renders when patientData.permissions grants can_create_encounter.

Closes #16638

Summary by CodeRabbit

  • Bug Fixes
    • The create-encounter action is now shown only to users with permission to create encounters.
    • Encounter history viewing remains available as before.

… permission

The empty-state "Create Encounter" button in EncounterHistory.tsx was
rendered unconditionally, unlike the other 3 encounter creation entry
points (Patient home, Appointment "Start Consultation", Appointment
"Create Planned Encounter"), which all check can_create_encounter.

Fixes #16638

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 71011e8096d1
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

EncounterHistory now retrieves canCreateEncounter and uses it to control the empty-state create-encounter action. Patient viewing behavior remains unchanged.

Changes

Encounter history permissions

Layer / File(s) Summary
Permission-gated create action
src/components/Patient/PatientDetailsTab/EncounterHistory.tsx
EncounterHistory retrieves canCreateEncounter and renders the empty-state create-encounter form only when the permission is enabled.

Possibly related PRs

Suggested reviewers: amjithtitus09, jacobjeevan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change gates the EncounterHistory Create Encounter button with can_create_encounter, which satisfies issue #16638.
Out of Scope Changes check ✅ Passed The changes are limited to permission-gating the specified EncounterHistory action and do not include unrelated work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes gating the empty-state Create Encounter button by the can_create_encounter permission.
Description check ✅ Passed The description clearly states the problem, fix, affected entry points, test verification, and linked issue.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rithviknishad/fix-encounter-history-permission-gate

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.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3420df6
Status: ✅  Deploy successful!
Preview URL: https://0cc80d80.care-preview-a7w.pages.dev
Branch Preview URL: https://rithviknishad-fix-encounter.care-preview-a7w.pages.dev

View logs

Copilot AI 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.

Pull request overview

This PR aligns the patient encounter history empty-state UI with the rest of the app’s permission model by hiding the “Create Encounter” call-to-action unless the user has can_create_encounter.

Changes:

  • Destructures canCreateEncounter from getPermissions() in EncounterHistory.tsx.
  • Conditionally renders the empty-state CreateEncounterForm trigger only when canCreateEncounter is true.

@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: 2

🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx`:
- Around line 82-95: Add regression tests around the EncounterHistory
create-action rendering, covering both canCreateEncounter states: assert the
create button and ShortcutBadge with actionId "create-encounter" are present
when enabled, and both are absent when disabled.
- Around line 82-95: Update the description rendered alongside the
CreateEncounterForm in EncounterHistory so the canCreateEncounter=false branch
does not instruct users to create an encounter; either omit that description or
use a non-actionable localized message. Keep the true and false branches as
separate t() calls so both translation keys remain detectable by the i18n
cleanup script.
🪄 Autofix

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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 23ffd60a-e554-4c9d-ad5e-f94728d50131

📥 Commits

Reviewing files that changed from the base of the PR and between 26e1f50 and 3420df6.

📒 Files selected for processing (1)
  • src/components/Patient/PatientDetailsTab/EncounterHistory.tsx

Comment on lines +82 to +95
canCreateEncounter ? (
<CreateEncounterForm
facilityId={facilityId}
patientId={patientId}
patientName={patientData.name}
trigger={
<Button>
<PlusIcon />
{t("create_encounter")}
<ShortcutBadge actionId="create-encounter" />
</Button>
}
/>
) : undefined

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.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for both permission states.

Test that the create button and create-encounter shortcut render with canCreateEncounter enabled and are absent when it is disabled.

🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx` around lines
82 - 95, Add regression tests around the EncounterHistory create-action
rendering, covering both canCreateEncounter states: assert the create button and
ShortcutBadge with actionId "create-encounter" are present when enabled, and
both are absent when disabled.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a non-actionable description when creation is not allowed.

When canCreateEncounter is false, action is undefined, but Line 79 still tells the user to create an encounter. Use a separate localized description for this branch, or omit the description.

Proposed fix
-                    description={t("create_a_new_encounter_to_get_started")}
+                    description={
+                      canCreateEncounter
+                        ? t("create_a_new_encounter_to_get_started")
+                        : t("no_permission_to_create_encounter")
+                    }

Based on learnings, keep each conditional branch as a separate t() call so the i18n cleanup script can detect both keys.

🤖 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/components/Patient/PatientDetailsTab/EncounterHistory.tsx` around lines
82 - 95, Update the description rendered alongside the CreateEncounterForm in
EncounterHistory so the canCreateEncounter=false branch does not instruct users
to create an encounter; either omit that description or use a non-actionable
localized message. Keep the true and false branches as separate t() calls so
both translation keys remain detectable by the i18n cleanup script.

Source: Learnings

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

Metric Count
Total Tests 337
✅ Passed 337
❌ Failed 0
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #10625

@amjithtitus09 amjithtitus09 added reviewed reviewed by a core member needs peer review and removed needs review labels Aug 6, 2026
@rithviknishad
rithviknishad requested review from gigincg and removed request for gigincg August 8, 2026 04:48
@rithviknishad rithviknishad changed the title 💊 Gate empty-state Create Encounter button by can_create_encounter permission [ENG-882] Gate empty-state Create Encounter button by can_create_encounter permission Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EncounterHistory empty-state "Create Encounter" button is not permission-gated

6 participants