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

Display year of birth when age is entered in public patient registration page #10808

Merged
merged 3 commits into from
Mar 8, 2025

Conversation

bodhish
Copy link
Member

@bodhish bodhish commented Feb 25, 2025

Fixes #10807

Add year of birth display when age is entered in public patient registration page

  • Add a new div element to display the year of birth when age is entered
  • Update the FormField for age to include the year of birth display
  • Calculate the year of birth based on the entered age and display it
  • Display "Invalid age" message if the calculated year of birth is less than or equal to 0

For more details, open the Copilot Workspace session.

Summary by CodeRabbit

  • New Features

    • Enhanced the patient registration form by replacing the year of birth input with an age field. Users now receive immediate error alerts for invalid age entries, improving the registration process's interactivity and user-friendliness.
    • Added a localized error message for invalid age inputs, enhancing user experience across different languages.
  • Bug Fixes

    • Updated the error message for invalid age inputs to be dynamically translated based on user language settings.

…ion page

Fixes #10807

Add year of birth display when age is entered in public patient registration page

* Add a new `div` element to display the year of birth when age is entered
* Update the `FormField` for age to include the year of birth display
* Calculate the year of birth based on the entered age and display it
* Display "Invalid age" message if the calculated year of birth is less than or equal to 0

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ohcnetwork/care_fe/issues/10807?shareId=XXXX-XXXX-XXXX-XXXX).
@bodhish bodhish requested a review from a team as a code owner February 25, 2025 12:51
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes modify the PatientRegistration component by replacing the year_of_birth field with an age field. The validation logic now checks for a valid age, displaying an error message if the age is less than or equal to zero. The calculation for displaying the year of birth based on age has been updated accordingly. Additionally, the AppointmentPatientRegister type in the utility file has been adjusted to reflect this change.

Changes

File Change Summary
src/pages/PublicAppointments/PatientRegistration.tsx Replaced year_of_birth with age, updated validation logic, adjusted default values, and modified form field registrations accordingly.
src/pages/Patient/Utils.tsx Removed year_of_birth property and added age property in the AppointmentPatientRegister type.
public/locale/en.json Added new entry "invalid_age": "Invalid age" for age validation error message.
src/components/Patient/PatientRegistration.tsx Changed static error message to use translation function t("invalid_age") for localization of the invalid age message.

Possibly related PRs

Suggested reviewers

  • rithviknishad
  • khavinshankar

Poem

I’m a hopping coder rabbit, full of cheer,
Swapping year_of_birth for age, oh dear!
With checks for the numbers, I’ll keep it all right,
Hopping through changes, coding day and night.
Let’s celebrate progress, with a joyful cheer! 🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28db4e8 and 43e4d7c.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (1 hunks)
  • src/pages/PublicAppointments/PatientRegistration.tsx (6 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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 Feb 25, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 43e4d7c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67cca5f799068d000849dcc9
😎 Deploy Preview https://deploy-preview-10808.preview.ohc.network
📱 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

cloudflare-workers-and-pages bot commented Feb 25, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 43e4d7c
Status:⚡️  Build in progress...

View logs

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 (3)
src/pages/PublicAppointments/PatientRegistration.tsx (3)

365-377: Use translation function for error message text

The error message "Invalid age" is hardcoded in English, while other UI strings in the application use the translation function t(). For consistency and proper internationalization, this text should be translated.

Consider using the translation function for the error message:

-                              <span className="text-red-600">Invalid age</span>
+                              <span className="text-red-600">{t("invalid_age")}</span>

Make sure to add the "invalid_age" key to your translation files.


367-374: Clarify the age calculation logic

The calculation is correct, but there might be confusion in the variable naming. In this form, year_of_birth is actually used to store the user's age input, while the calculated value represents the actual year of birth.

To improve code clarity, you could add a comment explaining this or consider refactoring the variable names in a future update to better reflect their purpose.


365-377: Enhance form reactivity with watch instead of getValues

Using form.getValues() multiple times doesn't automatically re-render when values change during typing. Using form.watch() would make the UI update reactively as the user types.

Consider modifying the code to use watch for better reactivity:

-                        {form.getValues("year_of_birth") && (
+                        {form.watch("year_of_birth") && (
                           <div className="text-sm font-bold">
-                            {Number(form.getValues("year_of_birth")) <= 0 ? (
+                            {Number(form.watch("year_of_birth")) <= 0 ? (
                               <span className="text-red-600">Invalid age</span>
                             ) : (
                               <span className="text-violet-600">
                                 {t("year_of_birth")}:{" "}
                                 {new Date().getFullYear() -
-                                  Number(form.getValues("year_of_birth"))}
+                                  Number(form.watch("year_of_birth"))}
                               </span>
                             )}
                           </div>
                         )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfeda14 and 65c396c.

📒 Files selected for processing (1)
  • src/pages/PublicAppointments/PatientRegistration.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10260
File: src/components/Patient/PatientRegistration.tsx:286-289
Timestamp: 2025-01-28T15:50:07.442Z
Learning: For patient registration in the frontend, either year_of_birth or date_of_birth is required for successful registration. If date_of_birth is not available, year_of_birth must be present.
src/pages/PublicAppointments/PatientRegistration.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10260
File: src/components/Patient/PatientRegistration.tsx:286-289
Timestamp: 2025-01-28T15:50:07.442Z
Learning: For patient registration in the frontend, either year_of_birth or date_of_birth is required for successful registration. If date_of_birth is not available, year_of_birth must be present.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/pages/PublicAppointments/PatientRegistration.tsx (1)

365-377: Implementation successfully meets PR objectives

The added code successfully implements the PR objective to display the year of birth when age is entered. The UI feedback is clear, with proper error handling for invalid ages and a nicely formatted display for valid ages.

Copy link

cypress bot commented Feb 25, 2025

CARE    Run #5054

Run Properties:  status check passed Passed #5054  •  git commit 28db4e8415: Display year of birth when age is entered in public patient registration page
Project CARE
Branch Review bodhish/fix-patient-registration
Run status status check passed Passed #5054
Run duration 07m 21s
Commit git commit 28db4e8415: Display year of birth when age is entered in public patient registration page
Committer Bodhish Thomas
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 12
View all changes introduced in this branch ↗︎

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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

Comment on lines 367 to 375
{Number(form.getValues("year_of_birth")) <= 0 ? (
<span className="text-red-600">Invalid age</span>
) : (
<span className="text-violet-600">
{t("year_of_birth")}:{" "}
{new Date().getFullYear() -
Number(form.getValues("year_of_birth"))}
</span>
)}
Copy link
Preview

Copilot AI Feb 25, 2025

Choose a reason for hiding this comment

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

The validation is checking the raw input value rather than the calculated birth year. Consider computing the birth year as new Date().getFullYear() minus the entered age and then verifying that this value is greater than 0.

Suggested change
{Number(form.getValues("year_of_birth")) <= 0 ? (
<span className="text-red-600">Invalid age</span>
) : (
<span className="text-violet-600">
{t("year_of_birth")}:{" "}
{new Date().getFullYear() -
Number(form.getValues("year_of_birth"))}
</span>
)}
{(() => {
const currentYear = new Date().getFullYear();
const birthYear = currentYear - Number(form.getValues("year_of_birth"));
return birthYear <= 0 ? (
<span className="text-red-600">Invalid age</span>
) : (
<span className="text-violet-600">
{t("year_of_birth")}: {birthYear}
</span>
);
})()}

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@nihal467
Copy link
Member

@bodhish can you look into @gigincg comment

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/pages/Patient/Utils.tsx (1)

1-10: Consider adding validation constraints for the age field.

Since age is now being used instead of year_of_birth, it's important to enforce appropriate validation constraints. This should include:

  1. Ensuring the age is a positive number
  2. Setting a reasonable maximum age limit (e.g., 120 years)
  3. Handling validation errors with appropriate user feedback

If the validation is handled elsewhere, consider adding JSDoc comments to this type to document the expected constraints:

export type AppointmentPatientRegister = {
  name: string;
  gender: string;
  phone_number: string;
  address: string;
  date_of_birth?: Date | string;
+  /** 
+   * Patient's age in years. Must be a positive number.
+   * Used to calculate and display year of birth on the registration form.
+   */
  age?: string;
  geo_organization?: string;
  pincode?: string;
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65c396c and 28db4e8.

📒 Files selected for processing (2)
  • src/pages/Patient/Utils.tsx (1 hunks)
  • src/pages/PublicAppointments/PatientRegistration.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/PublicAppointments/PatientRegistration.tsx
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10260
File: src/components/Patient/PatientRegistration.tsx:286-289
Timestamp: 2025-01-28T15:50:07.442Z
Learning: For patient registration in the frontend, either year_of_birth or date_of_birth is required for successful registration. If date_of_birth is not available, year_of_birth must be present.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/pages/Patient/Utils.tsx (1)

7-7:

❓ Verification inconclusive

Verify backend compatibility with the type change from year_of_birth to age.

This change replaces year_of_birth with age in the AppointmentPatientRegister type. According to previous learnings, either year_of_birth or date_of_birth is required for successful patient registration. Please ensure one of the following:

  1. The backend has been updated to accept age instead of year_of_birth
  2. The frontend calculates year_of_birth from age and includes it in the data sent to the backend
  3. The date_of_birth field is always provided when using age

🏁 Script executed:

#!/bin/bash
# Check how the registration API is called to verify the data being sent
echo "Checking API calls for patient registration..."
rg -A 10 "registerPatient|createPatient|patientRegister" --glob "*.ts*"

# Look for any backend validation related to year_of_birth or age
echo "Checking backend validation requirements..."
rg "year_of_birth|dateOfBirth" --glob "*.ts*" | grep -i "required|validation|error"

Length of output: 4944


Action: Confirm API field compatibility for patient registration

The new change now defines the patient’s birth-related information with an optional age in the type (in src/pages/Patient/Utils.tsx). However, our investigation shows that the registration flow (e.g., in src/components/Patient/PatientRegistration.tsx) still references and uses year_of_birth (both when sending data and when handling responses).

Please verify that one of the following approaches has been fully implemented before merging:

  • Backend Update: The backend now accepts age instead of year_of_birth.
  • Frontend Transformation: The frontend calculates or maps year_of_birth from age (or vice versa) before sending data to the backend.
  • Alternative Field: The process always provides date_of_birth to satisfy registration requirements when using age.

Manually review the API contract and related validations—especially in files such as src/Utils/request/api.tsx and src/components/Patient/PatientRegistration.tsx—to ensure these changes won’t break the patient registration process.

@nihal467
Copy link
Member

nihal467 commented Mar 4, 2025

LGTM

@rithviknishad rithviknishad self-requested a review March 5, 2025 06:49
@Jacobjeevan Jacobjeevan merged commit a8932e4 into develop Mar 8, 2025
9 of 13 checks passed
@Jacobjeevan Jacobjeevan deleted the bodhish/fix-patient-registration branch March 8, 2025 20:19
Copy link

github-actions bot commented Mar 8, 2025

@bodhish 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! 🙌

@Jacobjeevan Jacobjeevan added reviewed reviewed by a core member and removed needs review labels Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewed reviewed by a core member tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display year of birth when age is entered in public patient registration page
6 participants