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 files #9787

Merged
Merged

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Jan 6, 2025

Proposed Changes

  • Fixes Patient Files #9776
  • BE PR
  • Most of the change is just moving existing code from EncounterFiles to Files (and minor modifications to make it usable for patients as well).
  • Didn't remove the sidebar link for patient files as it would be empty right now

@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

Summary by CodeRabbit

  • Localization

    • Added multiple new translation keys for English localization.
    • Enhanced support for patient management, user interactions, and form labels.
  • New Features

    • Introduced a new FilesTab component for file management.
    • Added patient files tab to patient details interface.
    • Implemented dynamic gender type selection in user creation form.
  • Improvements

    • Updated error messages and UI labels to support internationalization.
    • Simplified encounter and patient file management components.
    • Improved file retrieval and display functionality.
    • Enhanced error handling and user feedback during the file upload process.
    • Added quick actions and active encounters sections in the UI.
    • Integrated file management capabilities into the encounters tab.

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces significant enhancements to file management and localization across multiple components. Key changes include the creation of a reusable FilesTab component for managing both patient and encounter files, the addition of a PatientFilesTab to the patient details interface, and the expansion of localization support with new translation keys. These modifications aim to improve the flexibility of the user interface, enhance internationalization, and streamline file management functionalities.

Changes

File Change Summary
public/locale/en.json Added 10 new localization keys for patient management, encounters, and user interactions
src/components/Files/FilesTab.tsx New component for file management with support for uploads, filtering, and interactions
src/components/Patient/PatientDetailsTab/PatientFiles.tsx Added PatientFilesTab component to integrate files view for patients
src/components/Patient/PatientDetailsTab/index.tsx Imported PatientFilesTab and added a new route for patient files
src/components/Patient/PatientHome.tsx Updated patient not found message to use translation
src/components/Users/CreateUserForm.tsx Updated gender field to use dynamic gender types and added translation support
src/hooks/useFileManager.tsx Minor update to query key for file retrieval
src/pages/Encounters/tabs/EncounterFilesTab.tsx Refactored to use new FilesTab component
src/pages/Patients/VerifyPatient.tsx Added internationalization support

Assessment against linked issues

Objective Addressed Explanation
Reuse Encounter Files Created FilesTab component for both patient and encounter files
Remove Nav Link for Patient Files Unclear from the provided changes
Modify Files Component View Based on Permissions Requires backend permission verification
Add Pagination to Files Pagination support appears to be implemented in FilesTab

Possibly related PRs

Suggested reviewers

  • rithviknishad

Poem

🐰 Files hopping, tabs so bright,
Translations dancing left and right,
Components reused with coding might,
Patient records now shine so light,
A rabbit's code, a pure delight! 🌈


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 Jan 6, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit a937ecc
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/678542a6d936440008bf6442
😎 Deploy Preview https://deploy-preview-9787--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.

@Jacobjeevan Jacobjeevan marked this pull request as ready for review January 6, 2025 11:46
@Jacobjeevan Jacobjeevan requested a review from a team as a code owner January 6, 2025 11:46
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

🧹 Nitpick comments (5)
src/components/Users/models.tsx (1)

61-64: Consider adding field-level documentation for better clarity.

Defining a dedicated UserPermissions type is an excellent step towards more explicit data modeling. To further enhance clarity, consider adding short comments or JSDoc lines indicating the intended use of each field (name, slug, context). This will help future contributors quickly understand these properties.

src/components/Files/FilesTab.tsx (3)

107-108: Remove or clarify commented-out code.

These lines referencing file_category are commented out. If they're no longer needed, removing them would keep the code cleaner. Otherwise, consider explaining why it's temporarily commented out.

97     queryFn: query(routes.viewUpload, {
98       queryParams: {
99         ...
104         ...(qParams.is_archived !== undefined && {
105           is_archived: qParams.is_archived,
106         }),
107-        //file_category: qParams.file_category,
108       },

147-151: Duplicate 'pdf' extension.

You're appending "pdf" twice to the allowed extensions. Consider removing the duplicate entry to keep the list consistent.

147       "pdf",
148       "xls",
149       "xlsx",
150       "ods",
-151       "pdf",

530-540: Remove or justify the commented-out <TabsList> block.

This entire block is commented out. If it's in development, add a TODO or comment explaining its purpose. If obsolete, remove it to maintain readability.

src/pages/Facility/FacilityDetailsPage.tsx (1)

107-108: Use optional chaining for cleaner checks.

Static analysis suggests using optional chaining on tokenData and tokenData.createdAt. This slightly reduces complexity and prevents potential undefined access.

- if (tokenData && tokenData.createdAt && dayjs(tokenData.createdAt).isAfter(dayjs().subtract(14, "minutes"))) {
+ if (tokenData?.createdAt && dayjs(tokenData.createdAt).isAfter(dayjs().subtract(14, "minutes"))) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 107-108: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51ca34f and 58a0c1f.

📒 Files selected for processing (12)
  • public/locale/en.json (17 hunks)
  • src/Routers/AppRouter.tsx (1 hunks)
  • src/components/Files/FilesTab.tsx (1 hunks)
  • src/components/Patient/PatientDetailsTab/PatientFiles.tsx (1 hunks)
  • src/components/Patient/PatientDetailsTab/index.tsx (2 hunks)
  • src/components/Patient/PatientHome.tsx (1 hunks)
  • src/components/Users/CreateUserForm.tsx (17 hunks)
  • src/components/Users/models.tsx (1 hunks)
  • src/hooks/useFileManager.tsx (1 hunks)
  • src/pages/Encounters/tabs/EncounterFilesTab.tsx (1 hunks)
  • src/pages/Facility/FacilityDetailsPage.tsx (1 hunks)
  • src/pages/Patients/VerifyPatient.tsx (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/pages/Encounters/tabs/EncounterFilesTab.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/pages/Facility/FacilityDetailsPage.tsx

[error] 107-108: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (23)
src/Routers/AppRouter.tsx (1)

92-92: Mapping permission objects to slug is a clean approach.

Providing only the slug property to the PermissionProvider helps keep the provider data minimal and focused on permission checks. This is a solid approach, but ensure no other part of the application requires the additional context provided by UserPermissions (like name or context). If needed, you could pass the entire object instead, or maintain a separate store tracking all permission info.

src/components/Files/FilesTab.tsx (1)

1-672: Overall file structure and functionality.

The file organization and approach for handling file uploads, audio playback, and data fetching look comprehensive. The usage of the Tabs, useQuery, and local hooks is well-structured, and the addition of tooltips for long file names is a nice usability touch.

src/components/Patient/PatientDetailsTab/PatientFiles.tsx (1)

5-13: Verify patientData availability.

Ensure that patientData is always defined when rendering this component. If there's a case where patientData.id might be undefined, consider adding a safety check or a loading state.

✅ Verification successful

No additional safety checks needed

The patientData prop is properly typed as required in the PatientProps interface, and the parent component (PatientHome) already implements a null check that prevents rendering when patientData is undefined. The current implementation is safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# This script searches for references to `PatientFilesTab` to confirm that
# `patientData` is always populated before rendering.

rg -A 5 $'PatientFilesTab'

Length of output: 1264


Script:

#!/bin/bash
# Check PatientProps interface and component usage
ast-grep --pattern 'interface PatientProps {
  $$$
}'

# Check parent component rendering
rg -B 5 -A 10 '<PatientFilesTab'

# Check for loading states
rg -A 3 'patientData.*undefined|!patientData|patientData\?'

Length of output: 5255

src/components/Patient/PatientDetailsTab/index.tsx (1)

9-9: New route for patient files looks good.

The addition of PatientFilesTab to patientTabs is straightforward and appears to be implemented properly. No issues found.

Also applies to: 48-51

src/pages/Patients/VerifyPatient.tsx (1)

5-5: Internationalization usage is correct.

Using useTranslation and replacing hardcoded strings with t() calls is well done. This improves maintainability and supports multiple languages seamlessly.

Also applies to: 74-74, 100-100, 103-103, 114-114, 116-116, 136-136, 139-139, 170-170, 173-173, 190-190, 192-192, 211-211, 214-214

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

111-111: Good use of i18n for "patient not found" message.
This localized approach ensures that messages are consistent with the rest of the application’s translation framework.

src/components/Users/CreateUserForm.tsx (15)

78-80: Dynamic gender enum looks good.
Switching from a static enum to GENDER_TYPES.map(gender => gender.id) enables more flexibility and consistency across the app.


160-164: User type field label and placeholder.
Your i18n usage for user type selection is correct. This improves multilingual support.


185-187: Consistent translations for first and last name fields.
Applying t("first_name") and t("last_name") ensures consistency across the UI.

Also applies to: 199-201


214-216: Username label and placeholder localized.
The integration with t("username") is consistent.


229-235: Password field placeholders updated.
The distinct placeholders for password fields enhance clarity for multilingual users.


247-251: Confirm password field label and placeholder.
Good job ensuring both password fields have translated labels and placeholders.


266-266: Email label updated.
This aligns with the overall internationalization approach.


281-281: Phone number fields localized.
The labels for primary and alternative phone numbers reflect i18n best practices.

Also applies to: 295-295


322-324: WhatsApp number label localized.
Resolves the need for multiple languages in phone/WhatsApp settings.


336-336: Date of birth label improvements.
Ensures multilingual support for date fields.


350-350: Gender label and placeholder.
The approach is consistent with the dynamic enum shift above.

Also applies to: 357-357


380-382: Qualification label.
Localizing professional details ensures better user experience across languages.


398-402: Years of experience.
The translation usage is appropriate, verifying consistent user-facing text.


416-419: Medical council registration label.
Completes the i18n coverage for key user form fields.


449-449: Create user button label translated.
Great finishing touch on the form submission button for multilingual support.

src/hooks/useFileManager.tsx (1)

94-94: Verify consistency of updated query key.
Renaming from ${fileType}-files to ${fileType}-file can affect caching. Confirm all references in the codebase are updated to maintain consistent data retrieval and cache invalidation.

✅ Verification successful

Query key change is correct and intentional
The different suffixes (${fileType}-files vs ${fileType}-file) are properly used to distinguish between list and single-item queries, which is a good practice for cache management in React Query.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search references to the old query key and the new one
rg --json '\\$\\{fileType\\}-files' -A 5
rg --json '\\$\\{fileType\\}-file' -A 5

Length of output: 307


Script:

#!/bin/bash
# Search for both singular and plural forms with proper escaping
echo "=== Searching for -files pattern ==="
rg "fileType.*-files" -A 5

echo -e "\n=== Searching for -file pattern ==="
rg "fileType.*-file[^s]" -A 5

Length of output: 1618

public/locale/en.json (1)

313-313: New localized strings added.
These keys (e.g., "active_encounters", "alternative_phone_number", "book_a_new_appointment", "create_encounter", "create_user", "encounter_class", "quick_actions", "quick_actions_description", "start_a_new_clinical_encounter", "start_date", "view_and_manage_patient_encounters", "whatsapp_number_is_same_as_phone_number") reflect expanded internationalization coverage. Make sure to cross-check usage across components and confirm that new strings are displayed correctly.

Also applies to: 366-366, 472-472, 639-639, 653-653, 800-800, 1490-1490, 1491-1491, 1697-1697, 1699-1699, 1883-1883, 1916-1916

src/components/Users/models.tsx Outdated Show resolved Hide resolved
@DonXavierdev
Copy link
Contributor

@Jacobjeevan When i checked deploy preview i saw that the File upload Button is missing here...Or is there any other route for file uploading ??
Before:
Screenshot 2025-01-06 at 8 19 29 PM

After:

Screenshot 2025-01-06 at 8 17 49 PM

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 6, 2025
@Jacobjeevan
Copy link
Contributor Author

@Jacobjeevan When i checked deploy preview i saw that the File upload Button is missing here...Or is there any other route for file uploading ?? Before: Screenshot 2025-01-06 at 8 19 29 PM

After:

Screenshot 2025-01-06 at 8 17 49 PM

It's related to perms; Backend would address that later today :) That should take care of it.

@Jacobjeevan Jacobjeevan added waiting for backend and removed question Further information is requested needs-triage labels Jan 6, 2025
Copy link

github-actions bot commented Jan 6, 2025

👋 Hi, @Jacobjeevan,
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 Jan 6, 2025
@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Jan 8, 2025
@nihal467
Copy link
Member

nihal467 commented Jan 9, 2025

@Jacobjeevan

image

  • Once the patient file upload fails and you close the pop-up, if you try to upload a new file, the pop-up state is not getting reset and still shows the old files.

image

  • when we try to upload a file through netlify deploy preview, its throwing CORS issues @tellmeY18 can you look into it

image

  • broken file uploads are visible in patient files after a hard refresh

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 (3)
public/locale/en.json (3)

1512-1513: Consider consolidating duplicate translations.

There appears to be duplicate translations for the same concept:

  • "quick_actions_description": "Schedule an appointment or create a new encounter"
  • "schedule_an_appointment_or_create_a_new_encounter": "Schedule an appointment or create a new encounter"

Consider using a single key to maintain consistency and ease maintenance.

{
-  "quick_actions_description": "Schedule an appointment or create a new encounter",
+  "quick_actions_description": "@:schedule_an_appointment_or_create_a_new_encounter",
}

Also applies to: 1617-1617


640-640: Consider optimizing encounter-related translations.

There are several related translations that could be consolidated using parameters:

  • "create_a_new_encounter_to_get_started"
  • "create_encounter"
  • "start_a_new_clinical_encounter"

Consider using a parameterized approach to reduce duplication and maintain consistency.

{
+  "encounter_create": {
+    "default": "Create Encounter",
+    "clinical": "Start a new clinical encounter",
+    "get_started": "Create a new encounter to get started"
+  }
}

Also applies to: 645-645, 1720-1720


1939-1939: Consider improving the WhatsApp message formatting.

The current translation could be more professionally formatted.

-  "whatsapp_number_is_same_as_phone_number": "WhatsApp number is same as phone number",
+  "whatsapp_number_is_same_as_phone_number": "WhatsApp number is the same as phone number",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58a0c1f and b922ab6.

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

314-314: LGTM! Core translations for encounters and files.

The translations for "active_encounters" and "files" are clear and concise.

Also applies to: 967-967


803-803: LGTM! Encounter management translations.

The translations for encounter classification and priority are appropriately concise and use standard medical terminology.

Also applies to: 1491-1491


1388-1388: LGTM! Patient management translations.

The translations for patient-related messages are clear and user-friendly:

  • Error message for when a patient is not found
  • Action description for viewing and managing patient encounters

Also applies to: 1906-1906


967-967: Verify completeness of file-related translations.

Since functionality is being moved from EncounterFiles to Files component, please verify that all necessary file-related translations have been added, such as:

  • File upload/download actions
  • File type descriptions
  • File-related error messages
✅ Verification successful

All necessary file-related translations are present

The codebase has comprehensive coverage of file-related translations including:

  • File operations (upload, download, archive)
  • Error messages
  • File categories and states
  • UI labels and descriptions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded strings related to files in the codebase
echo "Searching for potential missing file-related translations..."
rg -i "file" --type ts --type tsx | grep -i "string\|message\|label\|title\|description"

Length of output: 247


Script:

#!/bin/bash
# Check existing file-related translations
echo "Existing file-related translations:"
rg -i "file" public/locale/

# Search for potential hardcoded strings in TypeScript files
echo -e "\nChecking TypeScript files for potential untranslated strings:"
rg -i "['\"](.*file.*)['\"]" --type ts -g '!*.test.ts' -g '!*.spec.ts'

# Search in TSX files using a different approach
echo -e "\nChecking React components for potential untranslated strings:"
find . -name "*.tsx" -type f -exec rg -i "['\"](.*file.*)['\"]" {} \;

Length of output: 35407

@tellmeY18
Copy link
Member

Resolved cors issue ✅

@nihal467

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 9, 2025
Copy link

github-actions bot commented Jan 9, 2025

👋 Hi, @Jacobjeevan,
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

@Jacobjeevan can you clear the merge conflict

@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 11, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 11, 2025
Copy link

👋 Hi, @Jacobjeevan,
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.

@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 11, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 11, 2025
Copy link

👋 Hi, @Jacobjeevan,
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.

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 (4)
src/components/Files/FilesTab.tsx (4)

130-153: Remove duplicate "pdf" extension.

The "pdf" extension appears twice in the allowedExtensions array.

 allowedExtensions: [
   "jpg",
   "jpeg",
   "png",
   "gif",
   "bmp",
   "tiff",
   "mp4",
   "mov",
   "avi",
   "wmv",
   "mp3",
   "wav",
   "ogg",
   "txt",
   "csv",
   "rtf",
   "doc",
   "odt",
   "pdf",
   "xls",
   "xlsx",
   "ods",
-  "pdf",
 ],

531-541: Remove commented-out code.

The commented-out TabsList code should be either removed or implemented if needed. Commented-out code can lead to confusion and maintenance issues.


178-185: Consider moving icons mapping to constants.

The icons mapping could be moved to a constants file or defined outside the component to prevent recreation on each render.

+// In src/common/constants.ts
+export const FILE_TYPE_ICONS: Record<keyof typeof FILE_EXTENSIONS | "UNKNOWN", IconName> = {
+  AUDIO: "l-volume",
+  IMAGE: "l-image",
+  PRESENTATION: "l-presentation-play",
+  VIDEO: "l-video",
+  UNKNOWN: "l-file-medical",
+  DOCUMENT: "l-file-medical",
+};

-const icons: Record<keyof typeof FILE_EXTENSIONS | "UNKNOWN", IconName> = {
-  AUDIO: "l-volume",
-  IMAGE: "l-image",
-  PRESENTATION: "l-presentation-play",
-  VIDEO: "l-video",
-  UNKNOWN: "l-file-medical",
-  DOCUMENT: "l-file-medical",
-};
+const icons = FILE_TYPE_ICONS;

611-613: Improve error handling for multiple file uploads.

Currently, the error is only shown for the first file (index === 0). Consider showing errors for all files that fail validation.

-error={
-  index === 0 && fileUpload.error ? fileUpload.error : undefined
-}
+error={fileUpload.errors?.[index]}

This change requires updating the useFileUpload hook to support multiple error messages.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b7e39a9 and ac531b3.

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

646-691: Add loading state handling for audio files.

The component should show a loading state while fetching the audio file URL.


62-556: Add unit tests for the FilesTab component.

Consider adding unit tests to verify:

  • File upload functionality
  • Permission-based rendering
  • Filter and pagination behavior
  • File type detection and icon mapping

Would you like me to help create unit tests for these components?

@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 13, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 13, 2025
Copy link

👋 Hi, @Jacobjeevan,
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

LGTM

@Jacobjeevan Jacobjeevan removed the merge conflict pull requests with merge conflict label Jan 13, 2025
src/components/Files/FilesTab.tsx Outdated Show resolved Hide resolved
src/components/Files/FilesTab.tsx Outdated Show resolved Hide resolved
src/components/Files/FilesTab.tsx Outdated Show resolved Hide 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 (4)
src/hooks/useFileUpload.tsx (1)

201-209: Consider adding retry logic for failed markUploadComplete.

When markUploadComplete fails, the file is lost even though it was successfully uploaded. Consider adding retry logic or storing the file data for later retry.

 if (markUploadCompleteError) {
+  const retryCount = 3;
+  let retryAttempt = 0;
+  while (retryAttempt < retryCount) {
+    try {
+      await markUploadComplete({
+        data,
+        associating_id: associating_id,
+      });
+      resolve();
+      return;
+    } catch (error) {
+      retryAttempt++;
+      if (retryAttempt === retryCount) {
         toast.error(t("file_error__mark_complete_failed"));
         reject();
+      }
+      await new Promise(r => setTimeout(r, 1000 * retryAttempt));
+    }
+  }
 }
src/components/Files/FilesTab.tsx (3)

533-543: Remove commented code.

Remove the commented TabsList code block if it's no longer needed. If it's for future use, add a TODO comment explaining why it's kept.


178-185: Move file type constants to a separate file.

Consider moving the icons mapping to a separate constants file for better maintainability.

-  const icons: Record<keyof typeof FILE_EXTENSIONS | "UNKNOWN", IconName> = {
-    AUDIO: "l-volume",
-    IMAGE: "l-image",
-    PRESENTATION: "l-presentation-play",
-    VIDEO: "l-video",
-    UNKNOWN: "l-file-medical",
-    DOCUMENT: "l-file-medical",
-  };

Create a new file src/constants/fileIcons.ts:

import { IconName } from "@/CAREUI/icons/CareIcon";
import { FILE_EXTENSIONS } from "@/common/constants";

export const FILE_TYPE_ICONS: Record<keyof typeof FILE_EXTENSIONS | "UNKNOWN", IconName> = {
  AUDIO: "l-volume",
  IMAGE: "l-image",
  PRESENTATION: "l-presentation-play",
  VIDEO: "l-video",
  UNKNOWN: "l-file-medical",
  DOCUMENT: "l-file-medical",
};

573-644: Enhance dialog accessibility.

The FileUploadDialog should have improved accessibility:

  1. Add aria-label to buttons
  2. Add role="dialog" to the dialog
  3. Add descriptive aria-label to the progress bar
 <Dialog
   open={open}
   onOpenChange={onOpenChange}
   aria-labelledby="file-upload-dialog"
+  role="dialog"
 >
   <DialogContent
     className="mb-8 rounded-lg p-5"
     aria-describedby="file-upload"
   >
     // ... other code ...
     <Button
       variant="outline_primary"
       onClick={() => fileUpload.handleFileUpload(associatingId)}
       disabled={fileUpload.uploading}
       className="w-full"
       id="upload_file_button"
+      aria-label={t("upload")}
     >
       <CareIcon icon="l-check" className="mr-1" />
       {t("upload")}
     </Button>
     // ... other code ...
     {!!fileUpload.progress && (
       <Progress 
         value={fileUpload.progress} 
         className="mt-4"
+        aria-label={`Upload progress: ${fileUpload.progress}%`}
       />
     )}
   </DialogContent>
 </Dialog>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44a3397 and a937ecc.

📒 Files selected for processing (5)
  • public/locale/en.json (14 hunks)
  • src/components/Files/FilesTab.tsx (1 hunks)
  • src/components/Patient/PatientHome.tsx (1 hunks)
  • src/hooks/useFileManager.tsx (3 hunks)
  • src/hooks/useFileUpload.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Patient/PatientHome.tsx
  • src/hooks/useFileManager.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/hooks/useFileUpload.tsx

[error] 179-179: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
src/hooks/useFileUpload.tsx (3)

162-181: LGTM! Robust error handling for upload completion.

The implementation properly handles upload completion with error cases and success notifications.

🧰 Tools
🪛 Biome (1.9.4)

[error] 179-179: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 254-288: LGTM! Improved error handling for batch uploads.

The error handling allows the upload process to continue even when some files fail, providing a better user experience.


293-293: LGTM! Error state reset in clearFiles.

Properly resets error state when clearing files to prevent stale error messages.

public/locale/en.json (1)

1019-1019: LGTM! Comprehensive localization coverage.

All required translation keys for file management and encounters are properly added and organized.

Also applies to: 316-316, 673-673, 634-635, 1754-1754

@rithviknishad rithviknishad merged commit 578e1ec into ohcnetwork:develop Jan 13, 2025
17 checks passed
Copy link

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

Successfully merging this pull request may close these issues.

Patient Files
5 participants