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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

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
    • Improved the patient registration form by adding real-time feedback for the year of birth input. Users now receive an immediate error alert for invalid entries and see their calculated age displayed when a valid year is provided, making the registration process more interactive and user-friendly.

…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

Walkthrough

The changes modify the PatientRegistration component to include conditional rendering for the year_of_birth input. When a value is provided, the component checks if it is less than or equal to zero and displays an error message ("Invalid age" in red) if true. If the value is valid (greater than zero), it calculates the age using the current year minus the year_of_birth and displays the result with a violet text prefix of the translated "year_of_birth". No modifications were made to the public or exported entities.

Changes

File Change Summary
src/.../PatientRegistration.tsx Added a conditional block to validate the year_of_birth input. Displays an error for non-positive values and shows the computed age for valid inputs.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant PR as PatientRegistration Component
    participant Sys as System

    U->>PR: Enter year_of_birth value
    alt year_of_birth ≤ 0
        PR->>U: Render "Invalid age" (red text)
    else year_of_birth > 0
        PR->>Sys: Calculate age (currentYear - year_of_birth)
        Sys-->>PR: Return computed age
        PR->>U: Display age with translated "year_of_birth" prefix (violet text)
    end
Loading

Possibly related PRs

Suggested labels

tested, needs review

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I’m a hopping coder rabbit, full of cheer,
Tweaking year_of_birth with logic so clear.
Red for error, violet for the true,
My little changes dance anew.
Hop along in code, let insights appear! 🐇
Happy coding from the burrow near!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 Feb 25, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 65c396c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67bdbcd98d12a10008a5f04b
😎 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

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65c396c
Status: ✅  Deploy successful!
Preview URL: https://6e2172a5.care-fe.pages.dev
Branch Preview URL: https://bodhish-fix-patient-registra.care-fe.pages.dev

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 #4950

Run Properties:  status check passed Passed #4950  •  git commit 65c396c17f: 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 #4950
Run duration 07m 11s
Commit git commit 65c396c17f: 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 11
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
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.

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