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

Fix: Discharge patient showing live #9415

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

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Dec 14, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Screenshot

Screenshot 2024-12-15 at 7 12 36 PM

Merge Checklist

  • 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

Summary by CodeRabbit

  • New Features

    • Introduced a new section in the ConsultationCard to display patient status with a visual indicator.
  • Bug Fixes

    • Enhanced layout organization in the ConsultationCard for improved clarity.
  • Refactor

    • Removed the patient status display from the Demography component, adjusting the layout accordingly while maintaining core functionalities.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner December 14, 2024 08:22
Copy link
Contributor

coderabbitai bot commented Dec 14, 2024

Walkthrough

The pull request focuses on modifying how patient status is displayed across two components: ConsultationCard.tsx and Demography.tsx. In ConsultationCard.tsx, a new Chip component is introduced to show patient status as "LIVE" or "DISCHARGED" based on the discharge_date attribute. Conversely, in Demography.tsx, the patient status display section has been completely removed, which may address an issue with inconsistent status representation.

Changes

File Change Summary
src/components/Facility/ConsultationCard.tsx Added patient status Chip component with "LIVE" or "DISCHARGED" status. Restructured layout for better organization.
src/components/Patient/PatientDetailsTab/Demography.tsx Removed patient status display section. Adjusted layout but retained core functionality.

Assessment against linked issues

Objective Addressed Explanation
Discharged Patient Status Correction [#9289]
Ensure Accurate Patient Status Display [#9289]

Poem

🐰 A rabbit's tale of patient care,
Status chips now dance with flair,
Live or discharged, crystal clear,
No more confusion, have no fear!
Code hops forward, status bright ✨


📜 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 bd240e9 and 9b4111d.

📒 Files selected for processing (1)
  • src/components/Facility/ConsultationCard.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Facility/ConsultationCard.tsx

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 14, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 7abb9fd
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6763897727d4d400082791c9
😎 Deploy Preview https://deploy-preview-9415--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: 0

🧹 Outside diff range and nitpick comments (3)
src/components/Facility/ConsultationCard.tsx (3)

Line range hint 18-22: Consider renaming isLastConsultation prop for clarity

The isLastConsultation prop is being used to determine if a patient is discharged, but its name doesn't clearly convey this purpose. This could lead to confusion and maintenance issues.

Consider renaming it to something more explicit like isDischargedConsultation or adding a JSDoc comment to clarify its purpose:

 interface ConsultationProps {
   itemData: ConsultationModel;
-  isLastConsultation?: boolean;
+  /** Indicates if this consultation resulted in patient discharge */
+  isDischargedConsultation?: boolean;
   refetch: () => void;
 }

57-72: Simplify the layout structure

The current layout uses nested flex containers with translation transforms, which makes it harder to maintain and could cause layout issues across different screen sizes.

Consider simplifying the layout:

-<div className="flex flex-wrap items-center gap-4 mt-4">
-  <div className="flex flex-col gap-1">
+<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4">
+  <div className="flex items-center gap-4">
     <Chip
       size="small"
       variant={itemData.suggestion === "A" ? "alert" : "primary"}
       text={
         itemData.suggestion === "A"
           ? t("ip_encounter")
           : t("op_encounter")
       }
-      className="-translate-y-2"
     />
-    <div className="text-sm">
+    <div className="text-sm whitespace-nowrap">
       {dayjs(itemData.created_date).format("DD/MM/YYYY")}
     </div>
   </div>

83-88: Reconsider the implementation approach for patient status

The current implementation relies on isLastConsultation to determine patient status, but this might not be the most reliable indicator. The itemData.discharge_date would be a more direct and reliable way to determine if a patient is discharged.

Consider these points:

  1. A patient's discharge status should be determined by the presence of discharge_date
  2. The isLastConsultation prop might not always correlate with discharge status
  3. This change should be coordinated with the removal of status display from Demography.tsx to ensure consistent status display across the application
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8963ad and 00fb42b.

📒 Files selected for processing (2)
  • src/components/Facility/ConsultationCard.tsx (2 hunks)
  • src/components/Patient/PatientDetailsTab/Demography.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • src/components/Patient/PatientDetailsTab/Demography.tsx
🔇 Additional comments (1)
src/components/Facility/ConsultationCard.tsx (1)

74-89: ⚠️ Potential issue

Multiple improvements needed in the patient status section

  1. The status text "LIVE" and "DISCHARGED" should use i18n translations
  2. The negative translate value (-translate-y-5) suggests a layout issue
  3. The status logic might be incorrect based on the PR title "Fix: Discharge patient showing live"

Here's the suggested fix:

 {/* Patient Status Section */}
-<div className="flex items-center gap-2 -translate-y-5 ">
+<div className="flex items-center gap-2">
   <div className="text-sm font-normal leading-5">
     {t("patient_status")}
   </div>
   <Chip
     size="medium"
     variant="custom"
     className={
-      !isLastConsultation
+      itemData.discharge_date
         ? "bg-red-100 text-red-800"
         : "bg-blue-100 text-blue-800"
     }
-    text={!isLastConsultation ? "LIVE" : "DISCHARGED"}
+    text={itemData.discharge_date ? t("discharged") : t("live")}
   />
 </div>

Let's verify the discharge status logic across the codebase:

✅ Verification successful

The review comment suggestions are correct and should be implemented

The codebase analysis confirms:

  1. The hardcoded "LIVE" and "DISCHARGED" strings should use translations as they are already available in multiple language files (en.json, kn.json, ta.json, etc.) with keys "live" and "discharged"

  2. The -translate-y-5 appears to be an arbitrary value not used elsewhere in similar contexts, suggesting it's a hacky fix

  3. The logic for determining status should indeed be based on discharge_date as suggested in the review, as this is the consistent pattern used throughout the codebase for determining patient discharge status (seen in multiple components like PatientHome.tsx, PatientInfoCard.tsx, etc.)

The suggested fix in the review comment is the correct approach:

  • Uses proper i18n translations
  • Removes the hacky translation
  • Uses the correct discharge_date based logic which aligns with the rest of the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components that determine patient discharge status
rg -A 5 "discharge_date|isLastConsultation" --type tsx

Length of output: 84


Script:

#!/bin/bash
# Search for discharge status related code with proper file extensions
rg -t ts -t tsx -A 5 "discharge_date|isLastConsultation"

# Also search for translation keys related to patient status
rg -t ts -t tsx -t json "\"live\"|\"discharged\"|\"patient_status\""

Length of output: 179


Script:

#!/bin/bash
# Search for discharge status related code
rg -g "*.{ts,tsx,js,jsx}" "discharge_date|isLastConsultation" -A 5

# Search for translation keys related to patient status
rg -g "*.{ts,tsx,js,jsx,json}" "\"live\"|\"discharged\"|\"patient_status\"" 

Length of output: 44391

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/Patient/PatientDetailsTab/EncounterHistory.tsx (1)

76-79: Consider improving prop documentation

The isLastConsultation prop's behavior is crucial for the discharge status display. Consider adding JSDoc comments to clearly document the expected behavior and its impact on the UI.

+              {/* isLastConsultation: Determines if this consultation is the latest one.
+                 Used to control the display of patient status (LIVE/DISCHARGED) */}
               <ConsultationCard
                 itemData={item}
                 isLastConsultation={
                   item.id !== patientData.last_consultation?.id
                 }
                 refetch={refetch}
               />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 00fb42b and dc2b994.

📒 Files selected for processing (1)
  • src/components/Patient/PatientDetailsTab/EncounterHistory.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Patient/PatientDetailsTab/EncounterHistory.tsx (2)

77-77: Verify null safety handling for last_consultation

The addition of optional chaining (?.) suggests potential null cases. We should ensure proper handling of cases where last_consultation is undefined.

✅ Verification successful

Based on the gathered information, I can now provide the final response:

Optional chaining is correctly implemented for last_consultation

The code is properly handling the optional nature of last_consultation. The interface definition in models.tsx explicitly declares it as optional with last_consultation?: ConsultationModel, and its usage in EncounterHistory.tsx correctly employs optional chaining when accessing the id property. This implementation ensures safe handling of potentially undefined values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for null handling patterns in related files
rg -A 5 "last_consultation" 

# Check TypeScript interface for PatientModel
ast-grep --pattern 'interface PatientModel {
  $$$
  last_consultation?: $_
  $$$
}'

Length of output: 69494


Script:

#!/bin/bash
# Let's check the PatientModel interface definition and its usage
ast-grep --pattern 'interface PatientModel {
  $$$
  last_consultation?: ConsultationModel;
  $$$
}'

# Let's also check how last_consultation is handled in EncounterHistory.tsx
rg -A 3 "last_consultation\?" src/components/Patient/PatientDetailsTab/EncounterHistory.tsx

Length of output: 5913


77-77: ⚠️ Potential issue

The logic inversion appears incorrect and may cause unintended behavior.

The condition has been inverted from checking if this IS the last consultation to checking if this is NOT the last consultation. This seems counterintuitive and might be causing the "Discharge patient showing live" issue.

Let's verify the usage and impact:

Consider reverting the logic:

-item.id !== patientData.last_consultation?.id
+item.id === patientData.last_consultation?.id

@rithviknishad rithviknishad added invalid This doesn't seem right changes required labels Dec 16, 2024
Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

LGTM, minor thing, but can we switch to using size small, so that it matches with IP/OP encounter chip.

@AdityaJ2305
Copy link
Contributor Author

LGTM, minor thing, but can we switch to using size small, so that it matches with IP/OP encounter chip.

Yeah
Done

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

Successfully merging this pull request may close these issues.

Discharged Patient status showing as "live"
4 participants