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

Confirm Alert for Patient Registration #10205

Merged

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Jan 27, 2025

Proposed Changes

  • Fixes Ask Confirmation Before Navigating Away from Patient Registration Page When State is Dirty #10203
    • Show alert is form is dirty and user navigates away (except for submit buttons) for patient registration in both logged in and otp flows
    • Also exception for duplicate patient flow
  • Fix for duplicate flow: Duplicate dialog is triggered if user goes to the registration form with existing number. If user then confirms duplicate record, they are redirected back to PatientIndex, however currently phone number isn't auto entered into the field

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Release Notes

  • New Features

    • Added navigation prompt to alert users about unsaved changes in patient registration forms.
    • Implemented query parameter handling for managing phone number in patient search functionality.
  • Improvements

    • Enhanced patient registration form layout for better organization.
    • Refined logic for displaying duplicate patient alerts.
  • Technical Updates

    • Updated patient registration mutation to track creation status.

The changes focus on improving user experience and form interaction in patient-related workflows.

@Jacobjeevan Jacobjeevan requested a review from a team as a code owner January 27, 2025 08:30
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces improvements to patient registration and patient index components across multiple files. Key changes include the addition of a navigation prompt to prevent unintended data loss when navigating away from a dirty form, and modifications to how phone number query parameters are handled. The changes focus on enhancing user experience by providing better form state management and preserving user input across page navigation.

Changes

File Change Summary
src/components/Patient/PatientIndex.tsx Introduced useQueryParams to manage phoneNumber state from URL query parameters. Replaced setPhoneNumber with setPhoneNumberQuery.
src/components/Patient/PatientRegistration.tsx Added useNavigationPrompt hook, refactored duplicate patient dialog logic into a constant, adjusted layout of nationality and geo-organization fields.
src/pages/PublicAppointments/PatientRegistration.tsx Added useNavigationPrompt hook, updated createPatient mutation to include isPending status for better control flow.

Assessment against linked issues

Objective Addressed Explanation
Ask Confirmation Before Navigating Away [#10203]
Provide Options to Stay or Leave [#10203]

Possibly related PRs

Suggested labels

P1

Suggested reviewers

  • rithviknishad
  • nihal467

Poem

🐰 A rabbit's tale of forms so bright,
Where data dances with delight,
No changes lost, no worries near,
Navigation prompt brings user cheer!
Code hops along, with grace and might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 27, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 7062ba7
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67976da3ffafe00008ee7294
😎 Deploy Preview https://deploy-preview-10205--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/Patient/PatientRegistration.tsx (1)

Line range hint 694-719: Consider using consistent grid layout.

The nationality field is placed in a single-column grid while other form fields maintain a two-column layout. This might affect the visual consistency of the form.

Consider using the same two-column grid layout:

-<div className="grid grid-cols-1 gap-4">
+<div className="grid grid-cols-2 gap-4">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dad3637 and b8e1b9d.

📒 Files selected for processing (3)
  • src/components/Patient/PatientIndex.tsx (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (5 hunks)
  • src/pages/PublicAppointments/PatientRegistration.tsx (3 hunks)
🔇 Additional comments (6)
src/components/Patient/PatientIndex.tsx (1)

2-2: LGTM! Phone number auto-fill implementation looks good.

The implementation correctly retrieves the phone number from query parameters and initializes the state, addressing the requirement to auto-fill the phone number field upon redirection from duplicate patient flow.

Also applies to: 42-43

src/pages/PublicAppointments/PatientRegistration.tsx (2)

3-3: LGTM! Navigation prompt implementation looks good.

The implementation correctly tracks the form state and patient creation status to show the confirmation alert when needed.

Also applies to: 168-168


214-219: Verify the timeline for tanstack router migration.

The TODO comment suggests switching to tanstack router's useBlocker hook. This would provide a more robust solution for navigation blocking.

Run the following script to check if there's an existing issue or PR for the router migration:

src/components/Patient/PatientRegistration.tsx (3)

303-308: LGTM! Improved readability with showDuplicate constant.

The implementation correctly consolidates the conditions for displaying the duplicate dialog into a single, readable constant.


309-318: LGTM! Navigation prompt implementation looks good.

The implementation correctly handles the form state, patient creation/update status, and duplicate dialog state to show the confirmation alert when needed.


Line range hint 720-773: LGTM! Conditional rendering looks good.

The implementation correctly:

  1. Uses the two-column grid layout for geo-organization field
  2. Conditionally renders the field based on nationality
  3. Uses the showDuplicate constant for duplicate dialog rendering

@nihal467
Copy link
Member

image

  • blank form also throws this error, since it is a relevant prefill and expect behavior, LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Patient/PatientIndex.tsx (2)

42-43: Good use of query params for persistent state!

Using URL query parameters for the phone number state is a good choice here as it:

  1. Enables auto-filling the phone number after duplicate patient redirection
  2. Makes the search state shareable and bookmarkable
  3. Preserves the state across page refreshes

This addresses the PR objective of fixing the duplicate patient flow.


95-97: Consider improving phone number validation.

The current validation logic has some potential issues:

  1. The hard-coded length check of 13 characters might not work for all phone number formats
  2. The validation logic is duplicated (parsePhoneNumber is used later in the query)

Consider using the existing parsePhoneNumber utility for consistent validation:

  setPhoneNumberQuery({
-   phone_number: value.length >= 13 || value === "" ? value : "",
+   phone_number: parsePhoneNumber(value) || value === "" ? value : "",
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8e1b9d and 7062ba7.

📒 Files selected for processing (1)
  • src/components/Patient/PatientIndex.tsx (3 hunks)
🔇 Additional comments (1)
src/components/Patient/PatientIndex.tsx (1)

2-2: LGTM!

The addition of useQueryParams from 'raviger' aligns with the implementation of query parameter-based state management.

@rithviknishad rithviknishad merged commit 6834157 into ohcnetwork:develop Jan 28, 2025
20 checks passed
Copy link

@Jacobjeevan Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

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.

Ask Confirmation Before Navigating Away from Patient Registration Page When State is Dirty
3 participants