Skip to content

Add Active IP Patients Bed Occupancy Report - SSMM with SQL query and notes - #178

Open
sonzsara wants to merge 1 commit into
mainfrom
ENG-1296
Open

sonzsara wants to merge 1 commit into
mainfrom
ENG-1296

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 — SSMM active IP patients bed occupancy report

Ticket (ENG-1296, "Tally bed occupancy reports in all dashboards"): description and comments are empty, so I can't confirm the requirement. The title says tally across all dashboards, but this PR adds a single SSMM-only patient-level list (one row per occupied bed), not a count/tally. Is a row-level census what was wanted, and is "all dashboards" meant to include the other deployments (_pallium, _kc)? Please add the ask to the ticket.

SQL: Parse is clean (lint: 0 findings). Joins and the JSONB care-team expansion look sound, with no fan-out on beds. Two things could make the list incomplete or stale: NULL handling in NOT IN and missing patient/encounter status guards (see inline comments). Magic IDs (300, 19, 44, config 21) are documented in Notes, and the doc otherwise matches the query. Placement and filename follow convention.

Verdict: Numbers are probably fine for a live census, but resolve the NULL/staleness points and confirm the ticket intent before publishing to the dashboard.

Generated by Analytics SQL Reviewer for #178 · auto · 20.3 AIC · ⊞ 5.3K


## Parameters

No paramters.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typo: "paramters" → "parameters" (or follow TEMPLATE.md's wording for no-parameter queries).

AND fl.form = 'bd'
AND fl.current_encounter_id IS NOT NULL
AND fl.root_location_id != 300
AND emr_encounter.encounter_class = 'imp'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Status/deletion guards are thin for a patient list: emr_patient.deleted isn't filtered, and the encounter status isn't checked (Notes admit this). Since current_encounter_id can go stale if a bed isn't released, consider AND emr_patient.deleted = FALSE and excluding ended statuses (e.g. emr_encounter.status NOT IN ('completed','cancelled','entered_in_error','discontinued') — please verify the values against care/emr/models/encounter.py). Also check whether emr_patientidentifier has a deleted column that should be filtered in the join on line 34 to avoid duplicated rows.

AND fl.current_encounter_id IS NOT NULL
AND fl.root_location_id != 300
AND emr_encounter.encounter_class = 'imp'
AND fl.parent_id NOT IN (19, 44)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fl.parent_id NOT IN (19, 44) evaluates to NULL (row dropped) when a bed has parent_id IS NULL, so any bed sitting directly under no parent silently disappears from the census. If that can't happen in SSMM, fine; otherwise use AND (fl.parent_id IS NULL OR fl.parent_id NOT IN (19, 44)). Same applies to root_location_id != 300 if root_location_id can be NULL.

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