Conversation
There was a problem hiding this comment.
Pull request overview
Adds new query documentation for reporting counts of completed MLSP questionnaire visits by facility, scoped to an organization, in the Care/Operations documentation set.
Changes:
- Introduces a new markdown doc describing purpose, parameters, and SQL for “MLSP Visits Count by Facility”
- Provides a CTE-based query to count completed questionnaire responses (questionnaire_id = 69) grouped by facility
- Adds notes about hardcoded IDs and parameter expectations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
Care/Operations/mlsp_visits_count_by_facility_kc.md:73
- The Notes currently say
organization_idis required and the query won’t run without it, but the actualexternal_id = {{organization_id}}predicate is commented out. This makes the documentation inaccurate, and it also meansorg_idcan return multiple rows which can multiply encounters and inflate counts unless the filter is enabled.
- **Hardcoded IDs:**
- `questionnaire_id = 69` — the MLSP questionnaire. Update if the questionnaire id changes.
- **`organization_id` is required** (no `[[...]]` wrapper) — the query will not run without a value.
- Results are ordered by visit count descending, then alphabetically by facility name for ties.
Care/Operations/mlsp_visits_count_by_facility_kc.md:39
- The Purpose says results are scoped to “living patients”, but the query never filters out deceased patients. Other KC queries do this via
emr_patient.deceased_datetime IS NULL, so counts here may include deceased patients unless you add an explicit patient filter (or update the Purpose text).
FROM emr_encounter
INNER JOIN facility_facility
ON facility_facility.id = emr_encounter.facility_id
AND facility_facility.deleted = false
INNER JOIN org_id
Care/Operations/mlsp_visits_count_by_facility_kc.md:65
- The Notes say results are ordered by visit count descending (with facility name tie-break), but the SQL currently orders only by
facility_facility.name, so the output won’t match the documentation.
GROUP BY facility_facility.name
ORDER BY facility_facility.name;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (5)
Care/Operations/mlsp_visits_count_by_facility_kc.md:8
- The Purpose claims the query is scoped to “living patients within a specified organization”, but the SQL does not join to
emr_patient(so it can’t filter living/deleted patients) and the organization filter is currently commented out. Update the Purpose text so it matches what the query actually does (or implement the missing filters).
Counts completed responses to the MLSP questionnaire (`questionnaire_id = 69`) per facility, scoped to living patients within a specified organization.
Care/Operations/mlsp_visits_count_by_facility_kc.md:14
organization_idis described as scoping results viaemr_organization.external_id, but the corresponding SQL predicate is commented out (see theorg_idCTE). Either make the predicate active or document this parameter as optional/disabled so the docs match the query.
| `organization_id` | TEXT | Organization external ID to scope patients (matched against `emr_organization.external_id`) | `'org-uuid-1234'` |
Care/Operations/mlsp_visits_count_by_facility_kc.md:72
- This note states
organization_idis required, but the query will currently run without it because theorganization_idpredicate in theorg_idCTE is commented out. Adjust this note so it reflects the current query behavior.
- **`organization_id` is required** (no `[[...]]` wrapper) — the query will not run without a value.
Care/Operations/mlsp_visits_count_by_facility_kc.md:40
filtered_encountersdoesn’t filter out deleted encounters, which means deleted encounters can flow into thevisitsCTE and only get removed later in the final join. Addingemr_encounter.deleted = falseearlier avoids unnecessary work and reduces the chance of accidental reuse offiltered_encounterswithout the later safeguard.
WHERE emr_encounter.status NOT IN ('entered_in_error', 'cancelled')
),
Care/Operations/mlsp_visits_count_by_facility_kc.md:65
- The Notes say results are ordered by visit count descending (then facility name), but the SQL currently orders only by facility name. Update the ORDER BY to match the documented behavior (or adjust the note).
ORDER BY facility_facility.name;
No description provided.