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: Medicine Section Bugs #10613

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

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 14, 2025

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

    • Added a "Back" button on the print view to allow easy return to the previous screen.
    • Introduced a loading indicator on the prescription printing page to enhance user feedback during data retrieval.
  • Style

    • Updated medication notifications by replacing the phrase "No active medications" with a more general "No Medications" message.
    • Refined how empty states are handled in medication displays for clearer, more accurate information.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request updates the application's medication-related messaging and flow. The localization file is modified by removing the "no_active_medications" key and adding a more general "no_medications" key. The PrintPreview component now offers navigation via a new "Back" button using a history hook. The empty state logic in the AdministrationTab and medication table components is refined to check both active and stopped medications. Additionally, the medication data handling is optimized through memoization, optional property support, and a loading state in the PrintPrescription component.

Changes

Files Change Summary
public/locale/en.json Removed "no_active_medications": "No active medications" and added "no_medications": "No Medications" to update localization messaging.
src/CAREUI/misc/PrintPreview.tsx Added import for useAppHistory and introduced a "Back" button that calls the goBack function.
src/components/Medicine/MedicationAdministration/AdministrationTab.tsx Updated condition to display EmptyState only when both activeMedications.results and stoppedMedications.results are empty; changed message key to "no_medications".
src/components/Medicine/MedicationRequestTable/index.tsx, src/components/Medicine/MedicationsTable.tsx, src/pages/Encounters/PrintPrescription.tsx Enhanced medication data flow: modified imports (using useMemo and navigate), updated state management, introduced optional medication props, renamed variables to avoid conflicts, and added a loading state for medication fetching in PrintPrescription.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PrintPreview
    participant HistoryHook

    User->>PrintPreview: Click "Back" button
    PrintPreview->>HistoryHook: Call goBack()
    HistoryHook-->>PrintPreview: Navigate to previous page
Loading
sequenceDiagram
    participant User
    participant PrintPrescription
    participant MedicationAPI
    participant Loading
    participant MedicationsTable

    User->>PrintPrescription: Open PrintPrescription page
    PrintPrescription->>MedicationAPI: Fetch medication data
    MedicationAPI-->>PrintPrescription: Return data (or indicate loading)
    alt Data is loading
        PrintPrescription->>Loading: Render Loading component
    else Data loaded
        PrintPrescription->>MedicationsTable: Pass medication data
        MedicationsTable-->>User: Display medication list
    end
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a hopping bunny in the code,
Skipping through updates on each mode.
Keys changed with a gentle touch,
Back buttons and states mean so much.
Meds now clear in every byte,
Hoppin' along—oh what a 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 Feb 14, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d809699
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67b0e621e61fb50008350637
😎 Deploy Preview https://deploy-preview-10613.preview.ohc.network
📱 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.

@AdityaJ2305 AdityaJ2305 marked this pull request as ready for review February 15, 2025 18:56
@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 15, 2025 18:56
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/Medicine/MedicationsTable.tsx (1)

54-61: Consider simplifying the query enabled condition.

The current condition enabled: isPrintPreview && !medications && !!patientId might be too restrictive. Consider separating the concerns:

-    enabled: isPrintPreview && !medications && !!patientId,
+    enabled: !medications && !!patientId,
src/components/Medicine/MedicationRequestTable/index.tsx (1)

175-180: Simplify the disabled condition.

The array spread operation for checking length is unnecessary.

-    disabled={
-      [
-        ...(activeMedications?.results || []),
-        ...(stoppedMedications?.results || []),
-      ].length == 0
-    }
+    disabled={
+      !(activeMedications?.results?.length || stoppedMedications?.results?.length)
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21ecdf5 and d20664d.

📒 Files selected for processing (7)
  • public/locale/en.json (1 hunks)
  • src/CAREUI/misc/PrintPreview.tsx (2 hunks)
  • src/components/Medicine/MedicationAdministration/AdministrationTab.tsx (1 hunks)
  • src/components/Medicine/MedicationRequestTable/index.tsx (4 hunks)
  • src/components/Medicine/MedicationsTable.tsx (3 hunks)
  • src/components/Patient/TreatmentSummary.tsx (1 hunks)
  • src/pages/Encounters/PrintPrescription.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (9)
src/CAREUI/misc/PrintPreview.tsx (1)

17-17: LGTM! Good UX improvement.

Adding a back button with proper icon and translation improves navigation, following good UX practices for print preview pages.

Also applies to: 30-30, 36-39

src/components/Medicine/MedicationsTable.tsx (2)

39-44: LGTM! Props interface is well-designed.

The optional props with clear types improve component reusability.


71-74: LGTM! Clean conditional rendering logic.

The displayedMedications logic cleanly handles both print preview and regular modes.

src/pages/Encounters/PrintPrescription.tsx (1)

34-43: LGTM! Improved loading state handling.

Good improvements:

  1. Added proper loading state feedback
  2. Correctly passing medications data to MedicationsTable
  3. Setting isPrintPreview flag appropriately

Also applies to: 128-131

src/components/Medicine/MedicationRequestTable/index.tsx (2)

95-104: LGTM! Good performance optimization.

Using useMemo for the medications array prevents unnecessary recalculations.


199-202: LGTM! Improved empty state handling.

The empty state logic now correctly checks both active and stopped medications.

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

220-220: LGTM!

The addition of isPrintPreview prop to MedicationsTable aligns with the print preview functionality improvements.

src/components/Medicine/MedicationAdministration/AdministrationTab.tsx (1)

621-628: LGTM!

The empty state logic has been improved to:

  1. Check both active and stopped medications.
  2. Use a more appropriate message that applies to both cases.
public/locale/en.json (1)

1423-1423: LGTM!

The new localization key provides a more general message that works for all empty medication states.

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/pages/Encounters/PrintPrescription.tsx (1)

43-44: Consider adding error handling for the medications query.

While loading state is handled, there's no explicit error handling for the medications query.

+ const { data: medications, isLoading: medicationLoading, error: medicationError } = useQuery({
   queryKey: ["medication_requests", patientId],
   queryFn: query(medicationRequestApi.list, {
     pathParams: { patientId },
     queryParams: { encounter: encounterId, limit: 50, offset: 0 },
   }),
   enabled: !!patientId,
 });

+ if (medicationError) {
+   return (
+     <div className="flex h-[200px] items-center justify-center rounded-lg border-2 border-dashed p-4 text-red-500">
+       {t("error_loading_medications")}
+     </div>
+   );
+ }

 if (medicationLoading) return <Loading />;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d20664d and d809699.

📒 Files selected for processing (3)
  • src/components/Medicine/MedicationRequestTable/index.tsx (4 hunks)
  • src/components/Medicine/MedicationsTable.tsx (3 hunks)
  • src/pages/Encounters/PrintPrescription.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Medicine/MedicationRequestTable/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (5)
src/components/Medicine/MedicationsTable.tsx (3)

39-43: LGTM! Props interface changes improve component flexibility.

The changes to MedicationsTableProps make the component more versatile by:

  • Making patientId and encounterId optional
  • Adding an optional medications prop for direct data passing

52-59: LGTM! Query optimization prevents unnecessary API calls.

The query is now conditionally executed based on props:

  • Only runs when medications prop is not provided and patientId exists
  • Prevents redundant API calls when data is passed directly

69-71: LGTM! Clear and concise data source selection logic.

The displayedMedications logic elegantly handles both data sources:

  • Uses provided medications prop if available
  • Falls back to query results if no direct data is provided
src/pages/Encounters/PrintPrescription.tsx (2)

34-41: LGTM! Improved loading state handling for medications.

The query now properly tracks loading state, enabling better UX during data fetching.


128-128: LGTM! Proper usage of updated MedicationsTable component.

The component now correctly passes medications data directly, aligning with the updated MedicationsTable interface.

@AdityaJ2305
Copy link
Contributor Author

AdityaJ2305 commented Feb 15, 2025

One thing more 😅
I observed in AdministrationTab.tsx we are using refetch from UseQuery . Let's not use that instead use invalidate query like we are doing all over other places in codebase. LMK ?

@github-actions github-actions bot added needs-triage question Further information is requested labels Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show/Hide Toggle for Stopped Prescriptions Not Working
2 participants