Skip to content

[ENG-601] feat: allow planned encounters (w/ future start date) to transition to cancelled/discontinued/entered in error#16476

Open
Jacobjeevan wants to merge 6 commits into
developfrom
ENG-601-planned
Open

[ENG-601] feat: allow planned encounters (w/ future start date) to transition to cancelled/discontinued/entered in error#16476
Jacobjeevan wants to merge 6 commits into
developfrom
ENG-601-planned

Conversation

@Jacobjeevan

@Jacobjeevan Jacobjeevan commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

  • ENG-601
  • Do not set end date for encounters if start date in future (currently UI would only allow future dates for planned encounters)

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

Summary of changes

  • Bug Fixes
    • Improved normalization of encounter end dates when the encounter status changes.
    • End dates are now auto-populated only when missing, with special handling for cancelled and error states when the start date is in the future.
    • For other statuses, end dates remain cleared to prevent stale or incorrect values.

@Jacobjeevan Jacobjeevan requested review from a team and Copilot June 24, 2026 07:22
@netlify

netlify Bot commented Jun 24, 2026

Copy link
Copy Markdown

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 2313ed5
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6a3d0c5405660c000890b278
😎 Deploy Preview https://deploy-preview-16476.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

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 Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

EncounterQuestion now checks whether encounter.period.start is in the future before syncing encounter.period.end from encounter.status. For future starts, it clears an existing end value; otherwise, it sets the end value when missing.

Changes

Encounter period.end synchronization

Layer / File(s) Summary
Status split for missing period.end
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx
The effect now populates a missing period.end only for DISCHARGED, DISCONTINUED, and COMPLETED after checking whether the start date is in the future.
Future-start handling for cancelled statuses
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx
CANCELLED and ENTERED_IN_ERROR now set period.end only when it is missing and the start date is not in the future, and clear an existing end when the start date is in the future.

Possibly related PRs

  • ohcnetwork/care_fe#16311: Adds related encounter timing coverage for future-date behavior in the Create Encounter flow.

Suggested labels

Tested

Suggested reviewers

  • rithviknishad
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: planned encounters with future start dates can transition to error/cancel/discontinue states.
Description check ✅ Passed The description matches the template well with Proposed Changes, tagging, and a merge checklist, though the issue reference is implicit.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-601-planned

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


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

@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds special-case handling in the encounter status useEffect so that cancelling or marking as "entered in error" a planned encounter (one with a future period.start) no longer stamps an end date — a transition the backend would reject.

  • CANCELLED and ENTERED_IN_ERROR now check whether period.start is in the future; if so, they clear any existing end date rather than setting a new one.
  • DISCONTINUED was inadvertently left in the "always stamp end date" group alongside DISCHARGED/COMPLETED, contradicting the PR's stated intent and the code's own inline comment ("if start is in the future, BE will reject it").
  • The useEffect dependency array still lists only [encounter.status], a pre-existing stale-closure issue flagged in prior review rounds.

Confidence Score: 3/5

The change partially achieves its goal but leaves DISCONTINUED broken for future-start encounters.

Discontinuing a planned encounter still causes the effect to stamp an end date before the future start, which the backend will reject. The fix is moving DISCONTINUED into the correct branch.

src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx — status grouping in the useEffect at line 141.

Important Files Changed

Filename Overview
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Adds future-start-date aware end-date normalization for CANCELLED/ENTERED_IN_ERROR, but incorrectly leaves DISCONTINUED in the "always set end date" group, which breaks the stated goal of allowing planned encounters to be discontinued.

Reviews (6): Last reviewed commit: "chore: copilot suggestion" | Re-trigger Greptile

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

Adjusts encounter period handling so that planned encounters (often with future period.start) can be transitioned into terminal “non-completion” statuses (cancelled/discontinued/entered-in-error) without auto-setting an end time that would precede the start time.

Changes:

  • Auto-populates period.end only for discharged/completed encounters (when missing).
  • Special-cases cancelled/discontinued/entered_in_error so period.end is not set for planned encounters (and is cleared if present).
Comments suppressed due to low confidence (1)

src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx:171

  • The planned-encounter exception is keyed off encounterData?.status, which is the server-loaded status. If the user sets the status to planned in this form and then switches to cancelled/discontinued/entered_in_error, this block will treat it as non-planned and will set period.end to now, recreating the invalid end < start scenario the PR is trying to avoid. Also, encounterData isn’t in the effect deps, so relying on it here is brittle.

Consider keying this behavior off the encounter timing (future start) instead of the initial server status.

      if (encounterData?.status === EncounterStatus.PLANNED) {
        if (encounter.period.end) {
          handleUpdateEncounter({
            period: {
              ...encounter.period,
              end: undefined,
            },
          });
        }
      } else if (!encounter.period.end) {
        handleUpdateEncounter({
          period: {
            ...encounter.period,
            end: new Date().toISOString(),
          },
        });
      }

@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

🤖 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/Questionnaire/QuestionTypes/EncounterQuestion.tsx`:
- Around line 155-165: The transition logic in EncounterQuestion.tsx is using
the persisted encounterData.status snapshot instead of the previous local
status, which can cause period.end to be cleared and then re-added when
reopening the same record. Update the status-change detection in the
EncounterQuestion component to compare against a previous status stored with
useRef, and only clear period.end for true PLANNED-to-terminal-status
transitions in the handleUpdateEncounter flow.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cf709796-2cf8-43b0-892e-003b9c5633d1

📥 Commits

Reviewing files that changed from the base of the PR and between 6921efb and f8ca7df.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Outdated
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

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

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

Run: #9782

@nihal467 nihal467 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Image
  • when we update the planned encounter with future date to some other status such as "on hold" , "in progress" and then mark them as "enterred in error" , "cancelled" , its throwing the error which was earlier mentioned

@Jacobjeevan

Copy link
Copy Markdown
Contributor Author
Image
* when we update the planned encounter with future date to some other status such as "on hold" , "in progress" and then mark them as "enterred in error" , "cancelled" , its throwing the error which was earlier mentioned

🤔 Changed to check if start date is in future instead 👍

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (1)

137-173: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Effect misses period.start in dependencies, so the future-start rule can be skipped.

Line 173 only depends on encounter.status, but this effect’s decision also uses encounter.period.start (and encounter.period.end). If status is changed first and start is later moved to a future date, period.end won’t be re-synced.

Suggested fix
-  }, [encounter.status]);
+  }, [encounter.status, encounter.period.start, encounter.period.end]);
🤖 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/Questionnaire/QuestionTypes/EncounterQuestion.tsx` around
lines 137 - 173, The useEffect in EncounterQuestion is only keyed on
encounter.status, but it also reads encounter.period.start and
encounter.period.end, so the future-start/end synchronization can become stale
when those fields change. Update the dependency list for this effect to include
the period fields it relies on, especially encounter.period.start and
encounter.period.end, so the logic that calls handleUpdateEncounter always
re-runs when the encounter timing changes.
🤖 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.

Outside diff comments:
In `@src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx`:
- Around line 137-173: The useEffect in EncounterQuestion is only keyed on
encounter.status, but it also reads encounter.period.start and
encounter.period.end, so the future-start/end synchronization can become stale
when those fields change. Update the dependency list for this effect to include
the period fields it relies on, especially encounter.period.start and
encounter.period.end, so the logic that calls handleUpdateEncounter always
re-runs when the encounter timing changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: df74125a-9428-46e1-97cd-ebece23de6a7

📥 Commits

Reviewing files that changed from the base of the PR and between f8ca7df and dbb62a4.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 24, 2026

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2313ed5
Status: ✅  Deploy successful!
Preview URL: https://c9bcedb8.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-601-planned.care-preview-a7w.pages.dev

View logs

Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Outdated
Copilot AI review requested due to automatic review settings June 24, 2026 10:34

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Outdated
Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Outdated
Copilot AI review requested due to automatic review settings June 25, 2026 10:42

@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

🤖 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/Questionnaire/QuestionTypes/EncounterQuestion.tsx`:
- Around line 141-157: The EncounterQuestion status handling currently treats
EncounterStatus.DISCONTINUED the same as discharged/completed in the branch that
always sets period.end, which bypasses the new future-start guard. Update the
conditional logic in EncounterQuestion so DISCONTINUED follows the same
restriction path as the other future-start planned encounter transitions, and
only set period.end in the branch that is meant for statuses that are allowed to
auto-close; use the EncounterStatus checks and handleUpdateEncounter flow in
this component to keep the behavior consistent.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: be00cedc-a06c-4b61-8ee9-fa87893d44ac

📥 Commits

Reviewing files that changed from the base of the PR and between 95641fe and 4b0b8e7.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx Outdated
Comment thread src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

@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.

♻️ Duplicate comments (1)
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (1)

141-157: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

DISCONTINUED still skips the future-start rule (Line 143).

EncounterStatus.DISCONTINUED is in the always-set-end branch, so future-start planned encounters transitioned to discontinued still get period.end, which contradicts the PR behavior for discontinued/cancelled/entered-in-error.

Suggested fix
     if (
       encounter.status === EncounterStatus.DISCHARGED ||
-      encounter.status === EncounterStatus.DISCONTINUED ||
       encounter.status === EncounterStatus.COMPLETED
     ) {
       // Always set end date — if start is in the future, BE will reject it
       if (!encounter.period.end) {
         handleUpdateEncounter({
@@
     } else if (
+      encounter.status === EncounterStatus.DISCONTINUED ||
       encounter.status === EncounterStatus.CANCELLED ||
       encounter.status === EncounterStatus.ENTERED_IN_ERROR
     ) {
🤖 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/Questionnaire/QuestionTypes/EncounterQuestion.tsx` around
lines 141 - 157, `EncounterQuestion` is treating `EncounterStatus.DISCONTINUED`
like discharged/completed and always setting `period.end`, which bypasses the
future-start handling expected for discontinued encounters. Update the status
branching in the encounter update logic so the `DISCONTINUED` path follows the
same rule as `CANCELLED` and `ENTERED_IN_ERROR`, and only auto-populates
`period.end` for the statuses that should always receive an end date. Keep the
fix in the conditional block that checks `encounter.status` and uses
`handleUpdateEncounter`.
🤖 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.

Duplicate comments:
In `@src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx`:
- Around line 141-157: `EncounterQuestion` is treating
`EncounterStatus.DISCONTINUED` like discharged/completed and always setting
`period.end`, which bypasses the future-start handling expected for discontinued
encounters. Update the status branching in the encounter update logic so the
`DISCONTINUED` path follows the same rule as `CANCELLED` and `ENTERED_IN_ERROR`,
and only auto-populates `period.end` for the statuses that should always receive
an end date. Keep the fix in the conditional block that checks
`encounter.status` and uses `handleUpdateEncounter`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ff0e6ecf-ba8c-403e-a9fa-98781f2acb21

📥 Commits

Reviewing files that changed from the base of the PR and between 4b0b8e7 and 2313ed5.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants