Repository navigation
Conversation
There was a problem hiding this comment.
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}}]] |
There was a problem hiding this comment.
[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.
No description provided.