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 header UI update in Patient details page #9377

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from

Conversation

Mahendar0701
Copy link
Contributor

@Mahendar0701 Mahendar0701 commented Dec 11, 2024

Proposed Changes

@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

  • New Features

    • Updated localization for improved clarity and corrected spelling errors.
    • Introduced new keys for unassigning volunteers and indicating successful volunteer updates.
    • Enhanced patient information display with new sections for facility, treating doctor, assigned doctor, and assigned volunteer.
    • Added new visual variants for badges, including primary, alert, and danger.
  • Bug Fixes

    • Corrected spelling of "Immediately" in localization.
  • Refactor

    • Streamlined rendering logic in the PatientHome component.
    • Refactored AuthorizedButton component to change export method.
  • Style

    • Updated visual representation of patient information using Badge components and tooltips.
    • Minor textual adjustment in the EmergencyContact component comment.

@Mahendar0701 Mahendar0701 requested a review from a team as a code owner December 11, 2024 11:41
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

This pull request encompasses updates to localization, UI components, and patient-related interfaces. The changes include modifying the English localization file with spelling corrections and new keys, updating the Badge component with new variants, refactoring the AuthorizedButton component's export method, and enhancing the PatientHome and Demography components to improve data display and retrieval. The modifications focus on improving user interface clarity, fixing minor linguistic errors, and streamlining component implementations.

Changes

File Change Summary
public/locale/en.json - Updated "patient_details" text
- Corrected spelling of "prescription_frequency_stat"
- Added new keys "unassign" and "volunteer_update"
src/components/Patient/PatientDetailsTab/Demography.tsx - Modified state data retrieval from patientData.state to patientData?.state_object?.name
- Minor comment update
src/components/Patient/PatientHome.tsx - Replaced Chip with Badge components
- Added new patient information sections
- Updated button and layout styling
src/components/ui/badge.tsx - Added new badge variants: primary, alert, danger, custom
- Imported VariantProps
src/components/Common/AuthorizedButton.tsx - Changed button import source
- Modified export to default export

Assessment against linked issues

Objective Addressed Explanation
Update Patient Header
Correct state value in demography tab
Correct colors of transfer labels No explicit color changes observed

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad
  • nihal467

Poem

🐰 A rabbit's tale of code so bright,
Locales polished, components light,
Badges gleam and buttons dance,
Patient details now enhance!
Code refactored with bunny 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 Dec 11, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 9059f4d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676abc3e1a47f400081326f2
😎 Deploy Preview https://deploy-preview-9377--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: 1

🧹 Outside diff range and nitpick comments (1)
src/components/Patient/PatientHome.tsx (1)

279-309: Consider memoizing the skills formatting logic

The skills formatting and tooltip rendering logic could benefit from memoization to prevent unnecessary re-renders, especially for large skill sets.

+ const formattedSkills = useMemo(() => formatSkills(skillsQuery.data?.results), 
+   [skillsQuery.data?.results]);

- {!!skillsQuery.data?.results?.length &&
-   formatSkills(skillsQuery.data?.results)}
+ {!!skillsQuery.data?.results?.length && formattedSkills}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e89530d and 38bcda5.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/components/Patient/PatientDetailsTab/Demography.tsx (1 hunks)
  • src/components/Patient/PatientHome.tsx (1 hunks)
🔇 Additional comments (4)
src/components/Patient/PatientDetailsTab/Demography.tsx (1)

229-229: LGTM: Safe state value access implementation

The change to use state_object?.name with optional chaining is a safer way to access the state value and fixes the incorrect state value issue mentioned in the PR objectives.

src/components/Patient/PatientHome.tsx (2)

268-269: LGTM: Clean layout structure

The flex layout with proper gap spacing provides a responsive and well-organized structure for the patient header.


350-432: LGTM: Comprehensive status indicators

The status chips section effectively displays all relevant patient statuses with appropriate visual indicators and conditions.

public/locale/en.json (1)

1119-1119: LGTM: Improved text clarity

The text change from "Patient Details" to "Details of Patient" provides better clarity in the UI.

src/components/Patient/PatientHome.tsx Outdated Show resolved Hide resolved
@Mahendar0701 Mahendar0701 changed the title Patient header UI redesign Patient header UI update in Patient details page Dec 11, 2024
Copy link

👋 Hi, @Mahendar0701,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 12, 2024
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

🧹 Outside diff range and nitpick comments (2)
src/components/ui/badge.tsx (1)

37-59: Consider adding aria-label for icon-only scenarios.

The implementation looks good! For better accessibility, consider adding aria-label when the badge contains only icons without text.

-      {startIcon && <CareIcon icon={startIcon} className="mr-1" />}
+      {startIcon && <CareIcon icon={startIcon} className="mr-1" aria-label={startIcon} />}
       <span>{props.children}</span>
-      {endIcon && <CareIcon icon={endIcon} className="ml-1" />}
+      {endIcon && <CareIcon icon={endIcon} className="ml-1" aria-label={endIcon} />}
src/components/Patient/PatientHome.tsx (1)

568-577: Consider consolidating transfer status logic.

The transfer status badge could be simplified using a single conditional render.

-            {patientData.allow_transfer ? (
-              <Badge variant="success" startIcon="l-unlock">
-                {t("transfer_allowed")}
-              </Badge>
-            ) : (
-              <Badge variant="warning" startIcon="l-lock">
-                {t("transfer_blocked")}
-              </Badge>
-            )}
+            <Badge
+              variant={patientData.allow_transfer ? "success" : "warning"}
+              startIcon={patientData.allow_transfer ? "l-unlock" : "l-lock"}
+            >
+              {t(patientData.allow_transfer ? "transfer_allowed" : "transfer_blocked")}
+            </Badge>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 53ec8ad and 86a3597.

📒 Files selected for processing (2)
  • src/components/Patient/PatientHome.tsx (5 hunks)
  • src/components/ui/badge.tsx (3 hunks)
🔇 Additional comments (3)
src/components/ui/badge.tsx (1)

19-26: LGTM! Well-structured variant definitions.

The new variants (alert, danger, success) are properly defined with appropriate color schemes and hover states.

src/components/Patient/PatientHome.tsx (2)

291-434: LGTM! Well-structured patient header layout.

The new layout effectively organizes patient information with clear sections for:

  • Facility details
  • Treating doctor with skills tooltip
  • Assigned doctor with WhatsApp integration
  • Assigned volunteer
  • Status badges with appropriate visual indicators

347-355: ⚠️ Potential issue

Security: Enhance WhatsApp link sanitization.

The current phone number sanitization can be improved for better security.

This was previously flagged in an earlier review. Please implement the suggested phone number sanitization function.

@Mahendar0701
Copy link
Contributor Author

@Jacobjeevan i replaced chip with badge . can you once look into it

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 23, 2024
Copy link

👋 Hi, @Mahendar0701,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@nihal467
Copy link
Member

@Mahendar0701 clear the merge conflict

@Mahendar0701
Copy link
Contributor Author

@Mahendar0701 clear the merge conflict

Resolved

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/PatientHome.tsx (2)

358-366: Initial visit badge usage is consistent.
Using a custom variant for the badge is clear. Possibly consider reusing a standard variant for uniform styling, but not critical.


405-415: Telemedicine and allergy indicators.
Multiple badges in a single row can get cluttered but is still acceptable. The approach is consistent with the rest of the code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c5a558 and cae2c1b.

📒 Files selected for processing (4)
  • public/locale/en.json (1 hunks)
  • src/components/Common/AuthorizedButton.tsx (2 hunks)
  • src/components/Patient/PatientDetailsTab/Demography.tsx (2 hunks)
  • src/components/Patient/PatientHome.tsx (14 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Patient/PatientDetailsTab/Demography.tsx
  • public/locale/en.json
🔇 Additional comments (22)
src/components/Common/AuthorizedButton.tsx (3)

7-8: Switching to a local Button component is consistent with the app’s design.
The import statement references a local “Button” component instead of a headless UI component, aligning with the unified button styling approach seen across the application.


9-12: Clear and concise default prop usage.
Using a default authorizeFor prop returning true ensures the button is always enabled unless explicitly restricted. This approach keeps the API consistent. No issues found.


23-24: Default export of the component.
Exporting the component as the default export is valid, simplifying imports in other files. No issues found.

src/components/Patient/PatientHome.tsx (19)

9-9: Consistent import for authorized UI elements.
Importing AuthorizedButton from a central location helps maintain consistency. No issues found.


42-42: Introducing Badge for state indicators.
Pulling in the Badge component is aligned with the shift away from chips. No issues found.


210-210: Clear textual representation of patient data.
Displaying patient age, gender, and blood group is straightforward. The usage of fallback " - " for absent blood group is helpful for clarity.


275-285: Facility details block looks good.
Graceful fallback to “-” ensures the UI doesn’t break if facility details are missing. Implementation is fine.


286-316: Properly displaying treating physician details.
The tooltip-based approach for revealing additional physician skills is a good UX choice. Code structure is clear, and the fallback logic is handled gracefully.


318-344: Repeating phone sanitization suggestion.
Consider sanitizing the phone number before appending it to the WhatsApp URL to prevent potential injection or formatting issues.


345-353: Assigned volunteer section is concise and functional.
Straightforward display logic with fallback. No issues found.


367-375: Vaccination badge appropriately highlighted.
The icon plus text approach is a clear representation. Implementation is straightforward.


377-404: Antenatal and postpartum indicators.
Using separate badges for antenatal/postpartum states is logical. The color scheme with pink variants for these statuses is readable. No issues found.


416-422: Location-based badge.
Displaying district and state in a single badge is effective. Implementation is straightforward and uses fallback strings earlier.


Line range hint 429-440: Tab navigation logic is clear.
Conditionally adding an active border for the selected tab helps indicate the current route. Accessibility attributes (aria-selected, role="tab") are also well-used.


470-475: Investigation summary button.
Users can easily navigate to the relevant reports. Good use of an icon for clarity.


Line range hint 491-517: Patient files and volunteer assignment actions.
Volunteer assignment logic is guarded behind authorization checks, which is good for security. Implementation looks sound.


Line range hint 532-570: Transfer toggling mechanism.
The handlePatientTransfer function updates the allow_transfer field properly. This is a good pattern for controlling patient record updates.


560-572: Transfer status badges.
Using a primary badge for allowed and a warning badge for blocked is an effective visual distinction. Logic is straightforward.


604-604: Last discharge reason.
Displays a default dash when no discharge reason is found. Implementation is correct.


638-638: Last updated by section.
Tooltips for both relative and absolute timestamps are helpful. No issues found.


659-659: Created by information.
Similar pattern to “last updated by,” consistent from a UI standpoint.


688-688: Death report generation button.
Provides a clear action for generating a death report if the patient has an “Expired” discharge reason. Straightforward approach.

src/components/Common/AuthorizedButton.tsx Outdated Show resolved Hide resolved
Comment on lines 9 to 12
const AuthorizedButton: React.FC<AuthorizedElementProps & ButtonProps> = ({
authorizeFor = () => true,
...props
}) => {
Copy link
Member

Choose a reason for hiding this comment

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

let's drop the default. If we are going to use AuthorizedButton, then let's mandate the prop. If we are not going to pass the authorizeFor prop, we should be using the normal Button itself.

Suggested change
const AuthorizedButton: React.FC<AuthorizedElementProps & ButtonProps> = ({
authorizeFor = () => true,
...props
}) => {
const AuthorizedButton: React.FC<AuthorizedElementProps & ButtonProps> = (props) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rithviknishad can you once check

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Dec 23, 2024
@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 23, 2024
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/Common/AuthorizedButton.tsx (1)

13-17: Consider enhancing prop validation

While the authorizeFor validation is good, consider adding type checking to ensure the prop is of the correct type when provided.

 if (!authorizeFor) {
   throw new Error(
     "The 'authorizeFor' prop is required for AuthorizedButton.",
   );
 }
+if (typeof authorizeFor !== 'string' && !Array.isArray(authorizeFor)) {
+  throw new Error(
+    "The 'authorizeFor' prop must be a string or an array of strings.",
+  );
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd3e31e and 8ef8b19.

📒 Files selected for processing (1)
  • src/components/Common/AuthorizedButton.tsx (2 hunks)
🔇 Additional comments (4)
src/components/Common/AuthorizedButton.tsx (4)

9-12: LGTM! Clean component declaration with proper type definitions

The component declaration properly combines both ButtonProps and AuthorizedElementProps types, ensuring proper type checking for all props.


Line range hint 18-27: LGTM! Clean implementation with proper prop handling

The component correctly handles authorization logic and properly combines the disabled state with authorization status.


29-29: LGTM! Clean default export

The default export aligns with modern React practices and provides flexibility in importing.


5-5: Verify the Button component styling compatibility

The Button component import has been changed from headlessui to a local UI component. Please ensure that this change maintains consistent styling and behavior across all usage locations.

✅ Verification successful

Let me gather more information about the Button component usage to better understand the impact.


Let me check one more thing to understand the Button component's implementation and its compatibility.


Button component change is compatible and safe

The change from headlessui to the local UI Button component is safe and maintains consistent styling and behavior because:

  1. The local Button component is a well-structured component with proper styling variants and size options
  2. The AuthorizedButton correctly forwards all ButtonProps and handles the disabled state appropriately
  3. The Button component is widely used across the codebase (20+ files) as the standard button implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all files that use AuthorizedButton to verify visual consistency
rg -l "AuthorizedButton" | xargs rg -l "Button.*disabled.*isAuthorized"

Length of output: 114


Script:

#!/bin/bash
# Check the implementation of the local Button component
ast-grep --pattern 'export function Button($$$) { $$$ }' src/components/ui/button.tsx

# Find all usages of AuthorizedButton to understand its implementation
ast-grep --pattern 'const AuthorizedButton = $$$' src/components/Common/AuthorizedButton.tsx

# Find other Button usages in the codebase for consistency
rg "from.*components/ui/button" -A 2

Length of output: 5135


Script:

#!/bin/bash
# Check the Button component's implementation
cat src/components/ui/button.tsx

# Check the AuthorizedButton implementation to see how it uses the Button component
cat src/components/Common/AuthorizedButton.tsx

Length of output: 3398

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/Common/AuthorizedButton.tsx (2)

Line range hint 13-23: Consider extracting button-specific props

While the implementation is clean, spreading all props to the Button component might pass unnecessary props. Consider extracting only ButtonProps:

-const AuthorizedButton: React.FC<AuthorizedButtonProps> = (props) => {
+const AuthorizedButton: React.FC<AuthorizedButtonProps> = ({ authorizeFor, children, ...buttonProps }) => {
   return (
-    <AuthorizedChild authorizeFor={props.authorizeFor}>
+    <AuthorizedChild authorizeFor={authorizeFor}>
       {({ isAuthorized }) => (
-        <Button {...props} disabled={props.disabled || !isAuthorized}>
-          {props.children}
+        <Button {...buttonProps} disabled={buttonProps.disabled || !isAuthorized}>
+          {children}
         </Button>
       )}
     </AuthorizedChild>
   );
 };

25-25: Consider using named export

While default exports work, named exports are generally preferred for better maintainability and refactoring support. However, if this follows your project's conventions, feel free to keep it as is.

-export default AuthorizedButton;
+export { AuthorizedButton };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ef8b19 and 6810996.

📒 Files selected for processing (1)
  • src/components/Common/AuthorizedButton.tsx (2 hunks)
🔇 Additional comments (2)
src/components/Common/AuthorizedButton.tsx (2)

1-7: LGTM! Clean import organization

The imports are well-structured using absolute paths and properly organized by separating external (React) from internal dependencies.


9-11: LGTM! Well-structured type definition

The AuthorizedButtonProps type effectively combines the necessary props while making authorizeFor mandatory, addressing the previous review feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Patient Header and state value in Patient details page
4 participants