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

BUG: Patient form is accepting wrong dates in date field #10361

Open
Tanuj1718 opened this issue Feb 2, 2025 · 5 comments · May be fixed by #10415
Open

BUG: Patient form is accepting wrong dates in date field #10361

Tanuj1718 opened this issue Feb 2, 2025 · 5 comments · May be fixed by #10415
Assignees

Comments

@Tanuj1718
Copy link
Contributor

Describe the bug
We can write any value(decimal, >12) manually in months box of DOB (Date of Birth).

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://care.ohc.network/facility/9557da74-f0a0-44dd-9152-ef02be5767d2/patient/create?
  2. Fill the details and write some random value on DOB section , especially on months.
  3. Create Patient
  4. See error , patient is created.

Expected behavior
When user type wrong values manually in DOB, it show show error message. Although it is creating patient with default month (december) when wrong value is entered, but it should show proper error message.

Screenshots

InShot_20250202_111116534.mp4

Desktop (please complete the following information):

  • OS: MacOS
@Tanuj1718
Copy link
Contributor Author

@bodhish @rithviknishad If it gets approved, please assign it to me.

@Tanuj1718
Copy link
Contributor Author

@rithviknishad I think it is a state management issue as when I am continuously changing values, it is showing anonymous behavior. Sometimes the wrong value is getting replaced by the random values between 1-31 for days and 1-12 for months. There may be some other issue also which I am missing. I am working on it.

@github-actions github-actions bot added needs-triage question Further information is requested labels Feb 3, 2025
@nihal467 nihal467 removed question Further information is requested needs-triage labels Feb 4, 2025
@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Feb 4, 2025

@rithviknishad I think it is a state management issue as when I am continuously changing values, it is showing anonymous behavior. Sometimes the wrong value is getting replaced by the random values between 1-31 for days and 1-12 for months. There may be some other issue also which I am missing. I am working on it.

date-field is expecting user to type in 2 digit values for month (handleMonthChange doesn't change anything if there's only one digit).

To fix this, you can modify the logic in handleMonthChange to pad newMonth before the conditional checks. Also given that form doesn't allow submission when month > 12 (barring the padding issue above), I don't think any additional error handling is needed.

Edit: handleMonthChange is also the reason why you are able to submit the form after going back and entering 122 in the month column (month isn't changed within form value, instead submitted with previous value).

Edit: The auto focus to next cell causes an issue here, hmm let me see.

@Tanuj1718
Copy link
Contributor Author

@rithviknishad I think it is a state management issue as when I am continuously changing values, it is showing anonymous behavior. Sometimes the wrong value is getting replaced by the random values between 1-31 for days and 1-12 for months. There may be some other issue also which I am missing. I am working on it.

date-field is expecting user to type in 2 digit values for month (handleMonthChange doesn't change anything if there's only one digit).

To fix this, you can modify the logic in handleMonthChange to pad newMonth before the conditional checks. Also given that form doesn't allow submission when month > 12 (barring the padding issue above), I don't think any additional error handling is needed.

Edit: handleMonthChange is also the reason why you are able to submit the form after going back and entering 122 in the month column (month isn't changed within form value, instead submitted with previous value).

Edit: The auto focus to next cell causes an issue here, hmm let me see.

I have also tried onFocus and onInput event handlers to clear the values but it is not working.

@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Feb 4, 2025

@rithviknishad I think it is a state management issue as when I am continuously changing values, it is showing anonymous behavior. Sometimes the wrong value is getting replaced by the random values between 1-31 for days and 1-12 for months. There may be some other issue also which I am missing. I am working on it.

date-field is expecting user to type in 2 digit values for month (handleMonthChange doesn't change anything if there's only one digit).
To fix this, you can modify the logic in handleMonthChange to pad newMonth before the conditional checks. Also given that form doesn't allow submission when month > 12 (barring the padding issue above), I don't think any additional error handling is needed.
Edit: handleMonthChange is also the reason why you are able to submit the form after going back and entering 122 in the month column (month isn't changed within form value, instead submitted with previous value).
Edit: The auto focus to next cell causes an issue here, hmm let me see.

I have also tried onFocus and onInput event handlers to clear the values but it is not working.

You pad the field with an onBlur handler (do the same for day as well) and remove the focus behavior in handleDayChange and handleMonthChange.

   const handleMonthBlur = () => {
    if (month.length === 1 && parseInt(month) >= 1 && parseInt(month) <= 9) {
      const paddedMonth = month.padStart(2, "0");
      setMonth(paddedMonth);
      if (isValidDate(year, paddedMonth, day) && onChange) {
        const updatedDate = new Date(
          parseInt(year),
          parseInt(paddedMonth) - 1,
          parseInt(day),
        );
        onChange(updatedDate);
      }
    }
  };

@Tanuj1718 Tanuj1718 linked a pull request Feb 5, 2025 that will close this issue
6 tasks
@Tanuj1718 Tanuj1718 changed the title No proper error handling in DOB section of Patient BUG: Patient form is accepting wrong dates in date field Feb 6, 2025
@Jacobjeevan Jacobjeevan added this to Care Feb 7, 2025
@github-project-automation github-project-automation bot moved this to Triage in Care Feb 7, 2025
@Jacobjeevan Jacobjeevan moved this from Triage to Review required in Care Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review required
Development

Successfully merging a pull request may close this issue.

3 participants