fix(medications): TAMOC-395: Fix 'Missing FROM clause' error in Patients Ongoing Medications table (hotfix 2.48)#9260
Conversation
…ongoing-prescriptions endpoint to not throw error
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical database query error affecting the display of patient ongoing medications. The primary goal was to fix a 'Missing FROM clause' error that arose from complex Sequelize Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a "Missing FROM clause" error that occurred when fetching paginated ongoing prescriptions with specific filters. The core of the fix, setting subQuery: false in the Sequelize query, is a well-targeted solution to prevent problematic subquery generation. The refactoring of the query logic for filtering sensitive medications and handling facility-specific data is also a good improvement. I appreciate the comprehensive set of unit tests added, which cover various scenarios including permissions and edge cases, significantly increasing confidence in the fix. I have one minor suggestion to improve the robustness of integer parsing.
| const parsedPage = isNil(page) ? undefined : parseInt(page) || 0; | ||
| const parsedRowsPerPage = isNil(rowsPerPage) ? undefined : parseInt(rowsPerPage) || 10; |
There was a problem hiding this comment.
It's a good practice to always specify the radix (the base in mathematical numeral systems) for the parseInt function. This prevents unexpected behavior, especially with strings that could be misinterpreted as octal or hexadecimal numbers. While modern JavaScript engines default to base 10, being explicit improves code clarity and robustness across different environments.
| const parsedPage = isNil(page) ? undefined : parseInt(page) || 0; | |
| const parsedRowsPerPage = isNil(rowsPerPage) ? undefined : parseInt(rowsPerPage) || 10; | |
| const parsedPage = isNil(page) ? undefined : parseInt(page, 10) || 0; | |
| const parsedRowsPerPage = isNil(rowsPerPage) ? undefined : parseInt(rowsPerPage, 10) || 10; |
Changes
There was a fair bit of finagling to get cursor to do the right thing here, tbf its a pretty awkward issue. Sequelize kept moving parts of the nested
includeinto an inner subquery to ensure it fetched the right number of records, but there were missing join clauses.I think I've got it working right now, and added a bunch of unit tests to confirm
Deploys
Tests
Review Hero
Remember to...