-
Notifications
You must be signed in to change notification settings - Fork 553
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
base: develop
Are you sure you want to change the base?
Fix: Medicine Section Bugs #10613
Conversation
WalkthroughThis 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
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
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this 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
📒 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:
- Added proper loading state feedback
- Correctly passing medications data to MedicationsTable
- 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 toMedicationsTable
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:
- Check both active and stopped medications.
- 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.
There was a problem hiding this 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
📒 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
andencounterId
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 andpatientId
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.
One thing more 😅 |
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
New Features
Style