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

Patient Registration form refactor #9854

Merged
merged 67 commits into from
Jan 13, 2025
Merged

Patient Registration form refactor #9854

merged 67 commits into from
Jan 13, 2025

Conversation

khavinshankar
Copy link
Member

@khavinshankar khavinshankar commented Jan 9, 2025

  • Refactored PatientRegistration component to use react hook form
  • Added a couple of plugin hooks
  • Exposed core envs to global scope

Summary by CodeRabbit

Release Notes

  • Localization

    • Added multiple new validation messages and prompts for improved user guidance in forms.
  • Patient Registration

    • Enhanced patient registration form with improved validation using Zod and react-hook-form.
    • Simplified form layout and structure for better user experience.
  • Plugin System

    • Integrated new plugin component for patient actions in the PatientHome, PatientInfoCard, and other components.
    • Removed outdated plugin component from the EncounterContext.
  • Configuration

    • Improved handling of environment variables and expanded shared dependencies in build configuration.

khavinshankar and others added 30 commits January 8, 2025 23:48
…updating related components. Refactor organization level retrieval to use metadata for improved localization. Remove deprecated organization levels constant and clean up unused code in various components.
- Introduced a new PermissionContext to manage user permissions and super admin status across the application.
- Updated AppRouter to utilize PermissionProvider for managing permissions.
- Changed UserModel to store permissions as strings instead of objects.
- Refactored OrganizationFacilities and OrganizationPatients components to use updated permission checks and organization identifiers.
- Enhanced OrganizationLayout to conditionally render navigation items based on user permissions.

This commit improves the permission management system and ensures consistent handling of user permissions throughout the application.
- Introduced a new `searchPostFix` prop in `ValueSetSelect` to allow appending a suffix to the search query.
- Updated `MedicationRequestQuestion` and `MedicationStatementQuestion` components to utilize the `searchPostFix` prop with a default value of " clinical drug".
- This change enhances search functionality by providing more context in search queries.
Bumps [@tanstack/react-query-devtools](https://github.com/TanStack/query/tree/HEAD/packages/react-query-devtools) from 5.62.11 to 5.62.15.
- [Release notes](https://github.com/TanStack/query/releases)
- [Commits](https://github.com/TanStack/query/commits/HEAD/packages/react-query-devtools)

---
updated-dependencies:
- dependency-name: "@tanstack/react-query-devtools"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bodhisha Thomas <[email protected]>
Co-authored-by: Bodhish Thomas <[email protected]>
* Enhance encounter data handling by adding encounterId prop across multiple components

- Added `encounterId` prop to `ObservationChart`, `ObservationHistoryTable`, `ObservationsList`, `QuestionnaireResponsesList`, and `StructuredResponseView` components to improve data fetching and display related to specific encounters.
- Updated query parameters in API calls to include `encounterId` for better data context.
- Refactored `EncounterPlotsTab` and `EncounterUpdatesTab` to pass the new `encounterId` prop, ensuring consistent data handling across the application.

This change improves the overall functionality and user experience by ensuring that encounter-specific data is accurately retrieved and displayed.

* fix: disable encounter create button during save to prevent multiple submissions #9794
…anizationSelector labels

- Removed unused state and commented-out code in PatientHome for improved readability.
- Enhanced patient data display by updating the last updated and created by fields to use `updated_by` instead of `modified_by`.
- Updated date formatting functions to ensure consistent display of patient and encounter dates.
- Changed labels in FacilityOrganizationSelector from "Organization" to "Select Department" and adjusted related text for clarity.

These changes streamline the codebase and improve user interface clarity.
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: 2

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

261-262: Avoid type casting with proper typing

The type casting of geo_organization could be avoided by properly typing the API response.

Consider updating the PatientModel type to include the correct type for geo_organization.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1998e9 and 18e8454.

📒 Files selected for processing (1)
  • src/components/Patient/PatientRegistration.tsx (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (3)
src/components/Patient/PatientRegistration.tsx (3)

150-157: ⚠️ Potential issue

Set default value for same_address checkbox

According to the PR objectives, the "Use this address for permanent address" checkbox should be selected by default.

Apply this diff:

    defaultValues: {
      nationality: "India",
      phone_number: phone_number || "+91",
      emergency_phone_number: "+91",
      age_or_dob: "dob",
      same_phone_number: false,
-     same_address: true,
+     same_address: true, // Set to true by default as per requirements
    },

Likely invalid or redundant comment.


250-265: 🛠️ Refactor suggestion

Add form to useEffect dependencies

The useEffect hook depends on patientQuery.data, but it should also include form in its dependency array to ensure that form.reset has the latest reference.

Apply this diff:

-  }, [patientQuery.data]); // eslint-disable-line react-hooks/exhaustive-deps
+  }, [patientQuery.data, form]); // eslint-disable-line react-hooks/exhaustive-deps

Likely invalid or redundant comment.


497-510: 🛠️ Refactor suggestion

Add validation for date of birth fields

The date input fields lack validation for valid dates (e.g., preventing invalid dates like February 30th).

Apply this diff to add validation:

                              <Input
                                type="number"
                                placeholder="DD"
+                               min={1}
+                               max={31}
                                {...field}
                                value={
-                                 form.watch("date_of_birth")?.split("-")[2]
+                                 form.watch("date_of_birth")?.split("-")?.[2] || ""
                                }
                                onChange={(e) => {
+                                 const day = Number(e.target.value);
+                                 if (day < 1 || day > 31) return;
                                  form.setValue(
                                    "date_of_birth",
                                    `${form.watch("date_of_birth")?.split("-")?.[0] || ""}-${form.watch("date_of_birth")?.split("-")?.[1] || ""}-${e.target.value}`,
                                  )
                                }}

Apply similar validation for month (1-12) and year inputs.

Likely invalid or redundant comment.

Comment on lines +89 to +91
phone_number: z
.string()
.regex(/^\+\d{12}$/, t("phone_number_must_be_10_digits")),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix phone number validation to match requirements

The regex pattern /^\+\d{12}$/ requires exactly 12 digits after the '+' sign, but according to the PR objectives, phone numbers should be limited to 10 digits.

Apply this diff to fix the validation:

-            .regex(/^\+\d{12}$/, t("phone_number_must_be_10_digits")),
+            .regex(/^\+\d{10}$/, t("phone_number_must_be_10_digits")),

Make the same change for emergency_phone_number validation as well.

Also applies to: 93-95

Comment on lines +335 to +348
<Input
{...field}
maxLength={13}
onChange={(e) => {
form.setValue("phone_number", e.target.value);
if (form.watch("same_phone_number")) {
form.setValue(
"emergency_phone_number",
e.target.value,
);
}
}}
data-cy="patient-phone-input"
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve phone number input validation

The phone number input should validate the format as the user types and prevent invalid characters.

Apply this diff:

                      <Input
                        {...field}
                        maxLength={13}
+                       pattern="[+][0-9]+"
                        onChange={(e) => {
+                         const value = e.target.value.replace(/[^+0-9]/g, '');
-                         form.setValue("phone_number", e.target.value);
+                         form.setValue("phone_number", value);
                          if (form.watch("same_phone_number")) {
                            form.setValue(
                              "emergency_phone_number",
-                             e.target.value,
+                             value,
                            );
                          }
                        }}
+                       inputMode="numeric"
                        data-cy="patient-phone-input"
                      />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Input
{...field}
maxLength={13}
onChange={(e) => {
form.setValue("phone_number", e.target.value);
if (form.watch("same_phone_number")) {
form.setValue(
"emergency_phone_number",
e.target.value,
);
}
}}
data-cy="patient-phone-input"
/>
<Input
{...field}
maxLength={13}
pattern="[+][0-9]+"
onChange={(e) => {
const value = e.target.value.replace(/[^+0-9]/g, '');
form.setValue("phone_number", value);
if (form.watch("same_phone_number")) {
form.setValue(
"emergency_phone_number",
value,
);
}
}}
inputMode="numeric"
data-cy="patient-phone-input"
/>

@nihal467
Copy link
Member

nihal467 commented Jan 13, 2025

image

the update patients page is not pre-filling, patients state,district, etc... from the dropdown, can you fix it, it exist in develop also

@nihal467
Copy link
Member

LGTM

@nihal467 nihal467 merged commit b8c1ed2 into develop Jan 13, 2025
24 checks passed
@nihal467 nihal467 deleted the abdm_micro_fe branch January 13, 2025 10:24
Copy link

@khavinshankar 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.