-
Notifications
You must be signed in to change notification settings - Fork 0
Sensitive Medication Summary Report #288
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @hrazasalman, 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 introduces a new SQL-based report designed to provide a summary of sensitive medications that have been dispensed. The report aims to offer insights into medication usage by aggregating quantities and allowing for flexible filtering based on various criteria such as facility, specific medication, and date ranges, enhancing the system's reporting capabilities. Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new SQL report for a sensitive medication summary. The query is functional, but can be improved for readability and performance by reducing redundant macro calls and simplifying the WHERE clause logic. I've suggested a refactoring that defines Jinja variables for parameters at the beginning of the file and uses a more concise filtering logic.
| select | ||
| ep.medication as "{{ translate_label('prescriptionMedication')}}", | ||
| ep.medication_code as "{{ translate_label('prescriptionMedicationCode')}}", | ||
| sum(ep.quantity) as "{{ translate_label('prescriptionQuantity')}}" | ||
| from {{ ref('ds__sensitive_encounter_prescriptions') }} ep | ||
| where is_selected_for_discharge = true | ||
| and | ||
| case | ||
| when {{ parameter('facilityId') }} is null then true | ||
| else ep.facility_id = {{ parameter('facilityId') }} | ||
| end | ||
| and | ||
| case | ||
| when {{ parameter('medicationId') }} is null then true | ||
| else ep.medication_id = {{ parameter('medicationId') }} | ||
| end | ||
| and | ||
| case | ||
| when {{ parameter('fromDate', default_value='2024-01-01', data_type='timestamp') }} is null then true | ||
| else ep.datetime | ||
| >= {{ parameter('fromDate', default_value='2024-01-01', data_type='timestamp') }} | ||
| end | ||
| and | ||
| case | ||
| when {{ parameter('toDate', default_value='2024-01-31', data_type='timestamp') }} is null then true | ||
| else ep.datetime | ||
| <= {{ parameter('toDate', default_value='2024-01-31', data_type='timestamp') }} | ||
| end | ||
| group by ep.medication_id, ep.medication, ep.medication_code No newline at end of file |
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.
The current implementation of the WHERE clause is verbose and inefficient. It calls the parameter macro multiple times for each parameter and uses CASE statements for optional filters. This can be improved by:
- Storing parameter values in variables: This avoids repeated calls to the
parametermacro, which is more efficient during dbt compilation. - Simplifying filter logic: Using
(parameter is null or column = parameter)is more concise and readable than aCASEstatement, and often helps the database query planner.
I've suggested a refactoring of the entire file to apply these improvements.
{%- set facility_id = parameter('facilityId') -%}
{%- set medication_id = parameter('medicationId') -%}
{%- set from_date = parameter('fromDate', default_value='2024-01-01', data_type='timestamp') -%}
{%- set to_date = parameter('toDate', default_value='2024-01-31', data_type='timestamp') -%}
select
ep.medication as "{{ translate_label('prescriptionMedication')}}",
ep.medication_code as "{{ translate_label('prescriptionMedicationCode')}}",
sum(ep.quantity) as "{{ translate_label('prescriptionQuantity')}}"
from {{ ref('ds__sensitive_encounter_prescriptions') }} ep
where is_selected_for_discharge = true
and ({{ facility_id }} is null or ep.facility_id = {{ facility_id }})
and ({{ medication_id }} is null or ep.medication_id = {{ medication_id }})
and ({{ from_date }} is null or ep.datetime >= {{ from_date }})
and ({{ to_date }} is null or ep.datetime <= {{ to_date }})
group by ep.medication_id, ep.medication, ep.medication_code
gagank16
left a comment
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.
Looks good, not sure asking correct question but is this compiled already?
That’s a valid question. I will push it as it is now, cherry-pick it into the lower branches, and compile. |
No description provided.