Skip to content

Conversation

@hrazasalman
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • New Report Added: A new SQL report, sensitive-medication-dispensed-summary.sql, has been introduced to summarize dispensed sensitive medications.
  • Reporting Functionality: The report aggregates the total quantity of each sensitive medication dispensed, providing a summary view.
  • Flexible Filtering: Users can filter the report by facility ID, specific medication ID, and a date range (from and to dates) using dynamic parameters.
  • Localization Support: Column headers in the report are set up for localization using a translate_label function, ensuring adaptability for different languages.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +1 to +29
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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:

  1. Storing parameter values in variables: This avoids repeated calls to the parameter macro, which is more efficient during dbt compilation.
  2. Simplifying filter logic: Using (parameter is null or column = parameter) is more concise and readable than a CASE statement, 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

Copy link
Contributor

@gagank16 gagank16 left a 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?

@hrazasalman
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants