Skip to content

Add IP Patients Bed Stay Details documentation and SQL query - #173

Open
sonzsara wants to merge 2 commits into
mainfrom
ENG-1236
Open

sonzsara wants to merge 2 commits into
mainfrom
ENG-1236

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Analytics SQL Review — IP patients bed stay report (SSMM)

Ticket ENG-1236: an IP bed stay report with admission date, stay duration, discharge and related details, filterable by date and primary doctor.

Delivery: the query covers the ask. It has admission, discharge, duration and bed/floor columns, plus admission-date, discharge-date and practitioner filters. It excludes entered_in_error and deleted encounters, and the lint report is clean. The magic IDs (config_id = 21, root_location_id = 300) are documented in Notes.

Verdict: not yet safe to publish.

  • The missing facility scope is the main blocker. The query would include IP encounters from other facilities.
  • The bed-selection status question and the doc gaps are smaller, and are in the inline comments.

Generated by Analytics SQL Reviewer for #173 · auto · 22.1 AIC · ⊞ 5.3K

CASE WHEN jsonb_typeof(e.care_team) = 'array' THEN e.care_team -> 0 ->> 'user_id' END
)::int
WHERE e.encounter_class = 'imp'
-- [[AND (e.created_date AT TIME ZONE 'Asia/Kolkata')::date = {{encounter_date}}]]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Low] Non-sargable date filter. (e.created_date AT TIME ZONE 'Asia/Kolkata')::date = {{encounter_date}} wraps the indexed created_date in a function, so the index can't be used. Use a range instead: e.created_date >= ({{encounter_date}}::timestamp AT TIME ZONE 'Asia/Kolkata') AND e.created_date < (({{encounter_date}}::date + 1)::timestamp AT TIME ZONE 'Asia/Kolkata'). The discharge_date filter is JSONB-derived and already unindexed, so only the admission filter benefits.

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.

1 participant