Skip to content

Add documentation for counting users linked to government facilities - #172

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

sonzsara wants to merge 1 commit into
mainfrom
ENG-1198

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 — 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 < 2999 includes private hospitals, hostels, hotels, COVID centres and similar types, so the numbers are likely inflated (inline comment).
  • Using date_joined as the "linked as of" date, and the "active" wording with no is_active filter, need confirming (inline comment).
  • Hygiene: _kc implies 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

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