Skip to content

Add MLSP Visits Count by Facility query documentation - #132

Open
sonzsara wants to merge 3 commits into
mainfrom
ENG-756
Open

Add MLSP Visits Count by Facility query documentation#132
sonzsara wants to merge 3 commits into
mainfrom
ENG-756

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI 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.

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.

Comment thread Care/Operations/mlsp_visits_count_by_facility_kc.md

Copilot AI 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.

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_id is required and the query won’t run without it, but the actual external_id = {{organization_id}} predicate is commented out. This makes the documentation inaccurate, and it also means org_id can 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;

Copilot AI 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.

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_id is described as scoping results via emr_organization.external_id, but the corresponding SQL predicate is commented out (see the org_id CTE). 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_id is required, but the query will currently run without it because the organization_id predicate in the org_id CTE 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_encounters doesn’t filter out deleted encounters, which means deleted encounters can flow into the visits CTE and only get removed later in the final join. Adding emr_encounter.deleted = false earlier avoids unnecessary work and reduces the chance of accidental reuse of filtered_encounters without 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;

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.

2 participants