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

Disabled view files and assign volunteer for discharged patients #9278

Conversation

nithish1018
Copy link
Contributor

@nithish1018 nithish1018 commented Dec 3, 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

    • Enhanced patient file upload and volunteer assignment buttons to be conditionally enabled based on patient discharge status.
  • Bug Fixes

    • Prevented actions on buttons when the patient is inactive, improving user experience and preventing errors.

@nithish1018 nithish1018 requested a review from a team as a code owner December 3, 2024 07:36
Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request focus on the PatientHome component, specifically introducing a new function isPatientDischarged. This function determines if a patient is discharged based on their active status and facility ID. The disabled property for the ButtonV2 components related to uploading patient files and assigning a volunteer has been updated to utilize this function, ensuring these actions are only available for non-discharged patients. The overall structure and functionality of the component remain unchanged.

Changes

File Change Summary
src/components/Patient/PatientHome.tsx Added isPatientDischarged function; updated disabled property for ButtonV2 components.
src/components/Patient/Utils.ts Added isPatientDischarged function to check discharge status of patients.

Assessment against linked issues

Objective Addressed Explanation
Disable the View/Update patient files button for discharged patients (#9277)
Disable the assign to volunteer button for discharged patients (#9310)

Possibly related issues

Possibly related PRs

  • Added dynamic lock icon and strong types #9006: This PR modifies the PatientHome component, which is the same file affected by the main PR. It updates the component's logic and types, potentially impacting how the isPatientDischarged function is utilized within the same context.
  • Remove redundant "Add Consultation" button #9095: This PR also modifies the PatientHome component, specifically removing the isPatientEligibleForNewConsultation function, indicating ongoing changes to the logic and rendering within the same file.

Suggested labels

tested

Suggested reviewers

  • rithviknishad
  • shivankacker

Poem

In the land of patients, where buttons reside,
A change was made, with care and pride.
If a patient is active, the buttons will glow,
But if they're not, they'll simply say no.
So here's to the updates, both clever and bright,
Keeping our system both safe and right! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2762559 and 018ab95.

📒 Files selected for processing (1)
  • src/components/Patient/Utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Patient/Utils.ts

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

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit c39f7f5
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6757c90db5a12800080f492a
😎 Deploy Preview https://deploy-preview-9278--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/Patient/FileUploadPage.tsx (1)

20-22: Consider adding a notification before redirect.

The navigation logic correctly prevents inactive patients from accessing the file upload page. However, consider adding a notification to inform users why they're being redirected.

  if (!patient?.is_active) {
+   Notification.Error({
+     msg: t("cannot_access_files_for_discharged_patient")
+   });
    navigate(`/facility/${facilityId}/patient/${patientId}`);
  }
src/components/Patient/PatientHome.tsx (2)

492-492: Consider adding a tooltip for disabled state.

The button is correctly disabled for inactive patients. However, consider adding a tooltip to explain why the button is disabled.

  disabled={!patientData.is_active}
+ title={!patientData.is_active ? t("button_disabled_discharged_patient") : ""}

511-511: Consider adding a tooltip for disabled state.

The button is correctly disabled for inactive patients. However, consider adding a tooltip to explain why the button is disabled.

  disabled={!patientData.is_active}
+ title={!patientData.is_active ? t("button_disabled_discharged_patient") : ""}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2d9669e and 6a780ff.

📒 Files selected for processing (2)
  • src/components/Patient/FileUploadPage.tsx (2 hunks)
  • src/components/Patient/PatientHome.tsx (2 hunks)

@Jacobjeevan Jacobjeevan added changes required and removed needs testing reviewed reviewed by a core member labels Dec 6, 2024
@Jacobjeevan Jacobjeevan mentioned this pull request Dec 6, 2024
6 tasks
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)

92-98: Move isPatientDischarged to a shared utility file

Based on previous discussions, this logic should be moved to a shared utility file for reuse across components. This would:

  1. Ensure consistent discharge status checks across the application
  2. Follow DRY principles
  3. Make it easier to maintain and update the logic in one place

Consider creating a new utility file (e.g., src/Utils/patient.ts):

export const isPatientDischarged = (
  patientData: PatientModel,
  facilityId?: string
): boolean => {
  return (
    !patientData.is_active ||
    facilityId !== patientData.facility_object?.id?.toString()
  );
};

Then import and use it in this component:

import { isPatientDischarged } from '@/Utils/patient';
// ...
disabled={isPatientDischarged(patientData, facilityId)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce2fb1 and 1b2d627.

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

511-511: LGTM: Button disabled states are correctly implemented

The isPatientDischarged function is properly used to disable both the file upload and volunteer assignment buttons for discharged patients.

Also applies to: 530-530

src/components/Patient/PatientHome.tsx Outdated Show resolved Hide resolved
@Jacobjeevan Jacobjeevan removed their request for review December 6, 2024 05:06
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/Utils.ts (1)

20-29: Add JSDoc documentation for the function

Adding documentation would improve maintainability and help other developers understand the function's purpose and behavior.

Consider adding JSDoc documentation:

+/**
+ * Determines if a patient is considered discharged based on their active status
+ * and facility assignment.
+ * @param patientData - The patient data object
+ * @param facilityId - The current facility ID to check against
+ * @returns true if the patient is discharged or not in the current facility
+ */
 export const isPatientDischarged = (
   patientData: PatientModel,
   facilityId: string | undefined,
 ) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1b2d627 and 2762559.

📒 Files selected for processing (2)
  • src/components/Patient/PatientHome.tsx (3 hunks)
  • src/components/Patient/Utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Patient/PatientHome.tsx
🔇 Additional comments (2)
src/components/Patient/Utils.ts (2)

20-23: 🛠️ Refactor suggestion

Consider handling undefined facilityId explicitly

The function signature allows undefined for facilityId, but the implementation doesn't explicitly handle this case.

Consider this safer implementation:

 export const isPatientDischarged = (
   patientData: PatientModel,
   facilityId: string | undefined,
 ) => {

Likely invalid or redundant comment.


20-29: Verify integration with patient discharge workflow

The function correctly implements the discharge check based on active status and facility ID, but let's verify its integration with the broader patient discharge workflow.

✅ Verification successful

Function is correctly integrated with patient discharge workflow

The verification shows that isPatientDischarged is well-integrated with the patient discharge workflow:

  • It's used in PatientHome.tsx to disable actions when a patient is discharged
  • The function's logic aligns with the broader discharge handling in the codebase:
    • Checks for is_active status matches how it's used throughout the application
    • Facility ID comparison is consistent with other facility checks in the codebase
  • The implementation correctly supports the UI states in PatientHome.tsx and integrates with the discharge-related features
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other discharge-related logic to ensure consistency
echo "Searching for related discharge logic..."
rg -t typescript -t javascript "is_active|discharge" --glob "!{test,__tests__}/*"

# Search for other facility ID comparisons
echo "Searching for similar facility ID checks..."
rg -t typescript -t javascript "facility.*id.*toString" --glob "!{test,__tests__}/*"

Length of output: 428


Script:

#!/bin/bash
# Search for discharge-related logic with correct file extensions
echo "Searching for related discharge logic..."
rg "is_active|discharge" --type-add 'ts:*.{ts,tsx}' -t ts

# Search for facility ID comparisons
echo "Searching for similar facility ID checks..."
rg "facility.*id.*toString" --type-add 'ts:*.{ts,tsx}' -t ts

# Look for usages of isPatientDischarged function
echo "Searching for usages of isPatientDischarged..."
rg "isPatientDischarged" --type-add 'ts:*.{ts,tsx}' -t ts

Length of output: 29722

src/components/Patient/Utils.ts Outdated Show resolved Hide resolved
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

Only encounter related pages needs checks like these. In patient profile page we can simply check by patient.is_active alone.

Comment on lines +27 to +30
const patientFacilityId = patientData.facility_object?.id;
if (!patientFacilityId || !facilityId) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. why do we have to check if facility ID matches?
  2. Shouldn't we instead check if the last_consultation.discharge_date has a value or not?

@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Dec 10, 2024

Only encounter related pages needs checks like these. In patient profile page we can simply check by patient.is_active alone.

Well, for a patient who's readmitted, is_active check alone won't suffice. For example:

Patient A is discharged from Facility A and then readmitted to Facility B. If we don't check for facility Id match, a user in Facility A would see the option to assign volunteer and view file on the discharged patient as enabled.

@rithviknishad

I just saw Nihal's reply here: #9289 (comment). So depends on how we address this.

@nihal467
Copy link
Member

expected behavior has been modified, closing the PR as it's not solving the core issue

@nihal467 nihal467 closed this Dec 10, 2024
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.

Patients Files Upload Page is opening for discharged patients even though the permission is denied
4 participants