Repository navigation
Conversation
There was a problem hiding this comment.
Analytics SQL Review — users linked to government facilities (ENG-1198)
Ask: count of users linked to government facilities as of 31 Mar 2025, 31 Mar 2026, 30 Jun 2026 and 30 Sep 2026.
Delivery: one row with four cumulative columns. The structure is good: deleted = FALSE is applied on every table and COUNT(DISTINCT) avoids fan-out. The lint report shows no parse or template findings. The three comments below are what I'd settle before this goes on a dashboard.
- The government filter
facility_type < 2999includes private hospitals, hostels, hotels, COVID centres and similar types, so the numbers are likely inflated (inline comment). - Using
date_joinedas the "linked as of" date, and the "active" wording with nois_activefilter, need confirming (inline comment). - Hygiene:
_kcimplies a deployment-specific query, but nothing is hardcoded for one. Confirm that suffix is intended.
Verdict: not yet safe to publish. The numbers are probably overstated until the facility-type filter is fixed.
Generated by Analytics SQL Reviewer for #172 · auto · 19.2 AIC · ⊞ 5.3K
| ON f.id = fo.facility_id | ||
| AND f.deleted = FALSE | ||
| WHERE fou.deleted = FALSE | ||
| AND f.facility_type < 2999; |
There was a problem hiding this comment.
[Critical, unless intended] facility_type < 2999 is not a government filter.
In care/facility/models/facility.py the FACILITY_TYPES below 2999 include non-government types: 2 Private Hospital, 3 Other, 1 Educational Inst, 4/5/6 Hostel/Hotel/Lodge, 10 Private Labs, 900 Co-operative hospitals, 910 Autonomous, and the 1010–1600 COVID centres. Government types are 9 (Govt Labs) and 800–870 (PHC, FHC, CHC, Taluk, Women & Child, District, Govt Medical College). This predicate will overcount.
Suggested fix, to confirm with the ticket owner:
AND (f.facility_type = 9 OR f.facility_type BETWEEN 800 AND 870)Whatever list you settle on, state it in Notes, because the ticket doesn't define "government". If < 2999 is a deliberate convention, say so in Notes with the reason.
|
|
||
| ```sql | ||
| SELECT | ||
| COUNT(DISTINCT fou.user_id) FILTER (WHERE u.date_joined < DATE '2025-04-01') AS users_until_31_mar_2025, |
There was a problem hiding this comment.
[Medium, question] "Linked as of date X" is approximated by users_user.date_joined.
A user created before 31 Mar 2025 but linked to a facility later is counted in the 2025 column, while one who was unlinked since then is missed. The Notes mention this, but the ticket asks for users linked as of each date. If emr_facilityorganizationuser.created_date is the right "linked on" timestamp, fou.created_date < DATE '...' matches the ask more closely. Please confirm which is intended.
The query also doesn't filter u.is_active, although the header says "active users". Either add AND u.is_active or drop "active" from the description.
No description provided.