From 16114b7f63fc35eee7bc856ce9ebf6ff1272698a Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 16 Dec 2025 19:09:13 +0530 Subject: [PATCH] Add documentation for comfort devices, patient transfers, and nursing services analytics --- Care/Clinical/comfortdevices_kc.md | 101 +++++++++++++++ ...edto_secondary or ngo_comfortdevices_kc.md | 50 ++++++++ ...rrredto_secondary or ngo_patientcare_kc.md | 50 ++++++++ Care/Operations/totaldoctorvisit_kc.md | 52 ++++++++ Care/Operations/totalhomecaredays_kc.md | 69 +++++++++++ Care/Operations/totalnursevisit_kc.md | 66 ++++++++++ .../volunteerlinkagefor bedbound_kc.md | 116 ++++++++++++++++++ 7 files changed, 504 insertions(+) create mode 100644 Care/Clinical/comfortdevices_kc.md create mode 100644 Care/Operations/patientstransferrredto_secondary or ngo_comfortdevices_kc.md create mode 100644 Care/Operations/patientstransferrredto_secondary or ngo_patientcare_kc.md create mode 100644 Care/Operations/totaldoctorvisit_kc.md create mode 100644 Care/Operations/totalhomecaredays_kc.md create mode 100644 Care/Operations/totalnursevisit_kc.md create mode 100644 Care/Operations/volunteerlinkagefor bedbound_kc.md diff --git a/Care/Clinical/comfortdevices_kc.md b/Care/Clinical/comfortdevices_kc.md new file mode 100644 index 0000000..e2e6313 --- /dev/null +++ b/Care/Clinical/comfortdevices_kc.md @@ -0,0 +1,101 @@ +# Comfort Devices + +> Analyze distribution of comfort and assistive devices provided to patients + +## Purpose + +Track and analyze the types and distribution of comfort and assistive devices provided to patients based on nursing care assessments. Helps monitor device provision patterns and support resource allocation. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `visit_date` | DATE | Filter by visit/assessment date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who recorded device (optional) | `Jane Smith` | + +--- + +## Query + +```sql +WITH + nursing_care_questions AS ( + SELECT + emr_questionnaire.id AS questionnaire_id, + emr_questionnaire.slug, + jsonb_array_elements(emr_questionnaire.questions) AS question_block + FROM + emr_questionnaire + WHERE + emr_questionnaire.id IN (3) + ), + nursing_care_qids AS ( + SELECT + questionnaire_id, + slug, + question_block ->> 'id' AS question_id + FROM + nursing_care_questions + WHERE + question_block ->> 'text' = 'Comfort/Assistive Devices' + ), + responses AS ( + SELECT + emr_questionnaireresponse.patient_id, + emr_questionnaireresponse.created_date, + emr_questionnaireresponse.created_by_id, + UPPER( + TRIM( + REPLACE( + COALESCE(val ->> 'value', val -> 'coding' ->> 'display'), + '_', + ' ' + ) + ) + ) AS response_value + FROM + emr_questionnaireresponse + LEFT JOIN users_user ON emr_questionnaireresponse.created_by_id = users_user.id + LEFT JOIN emr_encounter e ON emr_questionnaireresponse.encounter_id = e.id + LEFT JOIN facility_facility ON e.facility_id = facility_facility.id, + jsonb_array_elements(emr_questionnaireresponse.responses) AS resp, + jsonb_array_elements(resp -> 'values') AS val + WHERE + emr_questionnaireresponse.questionnaire_id IN ( + SELECT + questionnaire_id + FROM + nursing_care_qids + ) + AND resp ->> 'question_id' IN ('e8a7b345-fb6a-4b3e-97b2-4e5cfdb7c4f3') + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{visit_date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] + ) +SELECT + response_value AS PROCEDURE, + COUNT(DISTINCT (patient_id, created_date)) AS patient_count +FROM + responses +GROUP BY + response_value +ORDER BY + patient_count DESC; +``` + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- The query uses three CTEs: + - `nursing_care_questions`: Extracts all question blocks from the nursing care questionnaire + - `nursing_care_qids`: Filters to find the specific "Comfort/Assistive Devices" question +- Questionnaire_id = 3 identifies nursing care assessment forms and is instance-specific. +- Question_id `e8a7b345-fb6a-4b3e-97b2-4e5cfdb7c4f3` identifies comfort devices responses and is instance-specific. +- Response values are normalized using UPPER, TRIM, and REPLACE to standardize formatting (spaces replaced with underscores).. +- Facility filter uses `external_id::text` to match facility external identifiers. +- Results are ordered by patient count in descending order (most common device first). +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/patientstransferrredto_secondary or ngo_comfortdevices_kc.md b/Care/Operations/patientstransferrredto_secondary or ngo_comfortdevices_kc.md new file mode 100644 index 0000000..f1bcd20 --- /dev/null +++ b/Care/Operations/patientstransferrredto_secondary or ngo_comfortdevices_kc.md @@ -0,0 +1,50 @@ +# Patients Transferred to Secondary/NGO - Comfort Devices + +> Track the count of comfort device resource requests for patient transfers + +## Purpose + +Monitor and analyze the number of comfort device requests for patients being transferred to secondary care or NGO facilities. Helps track resource allocation and transfer planning for patient care continuity. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `created_date` | DATE | Filter by request creation date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who created request (optional) | `Jane Smith` | + +--- + +## Query + +```sql +SELECT + COUNT(*) +FROM + emr_resourcerequest + JOIN emr_patient ON emr_resourcerequest.related_patient_id = emr_patient.id + JOIN facility_facility ON emr_resourcerequest.origin_facility_id = facility_facility.id + JOIN users_user ON emr_resourcerequest.created_by_id = users_user.id +WHERE + emr_resourcerequest.category = 'comfort_devices' + AND emr_resourcerequest.related_patient_id IS NOT NULL + AND emr_resourcerequest.deleted = FALSE + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{created_date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] +; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- The query counts resource requests of category `'comfort_devices'` from the emr_resourcerequest table. +- Only requests with a valid related_patient_id are included using `emr_resourcerequest.related_patient_id IS NOT NULL`. +- Only non-deleted requests are included using `emr_resourcerequest.deleted = FALSE`. +- Facility filter uses `external_id::text` to match facility external identifiers and filters by origin facility. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/patientstransferrredto_secondary or ngo_patientcare_kc.md b/Care/Operations/patientstransferrredto_secondary or ngo_patientcare_kc.md new file mode 100644 index 0000000..e54204b --- /dev/null +++ b/Care/Operations/patientstransferrredto_secondary or ngo_patientcare_kc.md @@ -0,0 +1,50 @@ +# Patients Transferred to Secondary/NGO - Patient Care + +> Track the count of patient care resource requests for patient transfers + +## Purpose + +Monitor and analyze the number of patient care resource requests for patients being transferred to secondary care or NGO facilities. Helps track care service allocation and transfer planning for patient care continuity. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `created_date` | DATE | Filter by request creation date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who created request (optional) | `Jane Smith` | + +--- + +## Query + +```sql +SELECT + COUNT(*) +FROM + emr_resourcerequest + JOIN emr_patient ON emr_resourcerequest.related_patient_id = emr_patient.id + JOIN facility_facility ON emr_resourcerequest.origin_facility_id = facility_facility.id + JOIN users_user ON emr_resourcerequest.created_by_id = users_user.id +WHERE + emr_resourcerequest.category = 'patient_care' + AND emr_resourcerequest.related_patient_id IS NOT NULL + AND emr_resourcerequest.deleted = FALSE + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{created_date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] +; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- The query counts resource requests of category `'patient_care'` from the emr_resourcerequest table. +- Only requests with a valid related_patient_id are included using `emr_resourcerequest.related_patient_id IS NOT NULL`. +- Only non-deleted requests are included using `emr_resourcerequest.deleted = FALSE`. +- Facility filter uses `external_id::text` to match facility external identifiers and filters by origin facility. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/totaldoctorvisit_kc.md b/Care/Operations/totaldoctorvisit_kc.md new file mode 100644 index 0000000..94cd414 --- /dev/null +++ b/Care/Operations/totaldoctorvisit_kc.md @@ -0,0 +1,52 @@ +# Total Doctor Visit + +> Track the total count of doctor visits recorded in the system + +## Purpose + +Monitor and analyze the total number of visits conducted by doctors based on questionnaire responses. Helps track visit volume with optional filtering by facility, date, and staff member. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `date` | DATE | Filter by visit date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who conducted visit (optional) | `Jane Smith` | + +--- + +## Query + +```sql +SELECT + COUNT(DISTINCT emr_questionnaireresponse.id) AS nurse_visit_count +FROM emr_questionnaireresponse +JOIN emr_questionnaire + ON emr_questionnaire.id = emr_questionnaireresponse.questionnaire_id +JOIN users_user ON + users_user.id = emr_questionnaireresponse.created_by_id +LEFT JOIN emr_encounter + ON emr_encounter.id = emr_questionnaireresponse.encounter_id +LEFT JOIN facility_facility + ON facility_facility.id = emr_encounter.facility_id +WHERE emr_questionnaire.id = 68 + AND emr_questionnaireresponse.deleted = FALSE + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] +; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- The query counts distinct questionnaire responses, where each response represents a visit. +- Questionnaire_id = 68 identifies doctor visit forms and is instance-specific. +- Only non-deleted questionnaire responses are included using `emr_questionnaireresponse.deleted = FALSE`. +- Facility filter uses `external_id::text` to match facility external identifiers. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/totalhomecaredays_kc.md b/Care/Operations/totalhomecaredays_kc.md new file mode 100644 index 0000000..e955f9e --- /dev/null +++ b/Care/Operations/totalhomecaredays_kc.md @@ -0,0 +1,69 @@ +# Total Home Care Days + +> Analyze home care service days by nurse type + +## Purpose + +Track and analyze the number of distinct home care service days by nurse type (Community Nurse, Secondary Nurse, MLSP Nurse). Helps monitor nursing service utilization patterns and resource allocation across different nursing categories over time. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `date` | DATE | Filter by service date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who provided service (optional) | `Jane Smith` | + +--- + +## Query + +```sql +SELECT + nurse_type, + COUNT(DISTINCT created_date) AS homecare_days_count +FROM + ( + SELECT + CASE + WHEN val ->> 'value' = 'Community Nurse' THEN 'Community Nurse' + WHEN val ->> 'value' = 'Secondary Nurse' THEN 'Secondary Nurse' + WHEN val ->> 'value' = 'MLSP Nurse' THEN 'MLSP Nurse' + END AS nurse_type, + DATE (emr_questionnaireresponse.created_date) AS created_date + FROM + emr_questionnaireresponse + JOIN emr_questionnaire ON emr_questionnaire.id = emr_questionnaireresponse.questionnaire_id + LEFT JOIN users_user ON users_user.id = emr_questionnaireresponse.created_by_id + LEFT JOIN emr_encounter ON emr_encounter.id = emr_questionnaireresponse.encounter_id + LEFT JOIN facility_facility ON facility_facility.id = emr_encounter.facility_id + CROSS JOIN LATERAL jsonb_array_elements(emr_questionnaireresponse.responses) AS elem + CROSS JOIN LATERAL jsonb_array_elements(elem -> 'values') AS val + WHERE + emr_questionnaire.id IN (3) + AND emr_questionnaireresponse.deleted = FALSE + AND emr_questionnaireresponse.encounter_id IS NOT NULL + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] + AND elem ->> 'question_id' IN ('d602b9b2-d4cd-43d7-99d3-3d0169095eba') + ) AS nurse_days +GROUP BY + nurse_type; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- Questionnaire_id = 3 identifies nursing service forms and is instance-specific. +- Question_id `d602b9b2-d4cd-43d7-99d3-3d0169095eba` identifies nurse type responses and is instance-specific. +- The `created_date` is converted to DATE type using `DATE()` function to count unique days (not individual timestamps). +- Only non-deleted questionnaire responses are included using `emr_questionnaireresponse.deleted = FALSE`. +- Only responses with a valid encounter_id are included using `emr_questionnaireresponse.encounter_id IS NOT NULL`. +- Three nurse types are recognized: Community Nurse, Secondary Nurse, and MLSP Nurse. +- Facility filter uses `external_id::text` to match facility external identifiers. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/totalnursevisit_kc.md b/Care/Operations/totalnursevisit_kc.md new file mode 100644 index 0000000..15d6aec --- /dev/null +++ b/Care/Operations/totalnursevisit_kc.md @@ -0,0 +1,66 @@ +# Total Nurse Visit + +> Analyze nurse visit distribution by nurse type + +## Purpose + +Track and analyze the distribution of nurse visits by nurse type (Community Nurse, Secondary Nurse, MLSP Nurse). Helps monitor nursing service utilization and resource allocation across different nursing categories. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `date` | DATE | Filter by visit date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who conducted visit (optional) | `Jane Smith` | + +--- + +## Query + +```sql +SELECT + nurse_type, + COUNT(DISTINCT id) AS patient_count +FROM + ( + SELECT + CASE + WHEN val ->> 'value' = 'Community Nurse' THEN 'Community Nurse' + WHEN val ->> 'value' = 'Secondary Nurse' THEN 'Secondary Nurse' + WHEN val ->> 'value' = 'MLSP Nurse' THEN 'MLSP Nurse' + END AS nurse_type, + emr_questionnaireresponse.id + FROM + emr_questionnaireresponse + JOIN emr_questionnaire ON emr_questionnaire.id = emr_questionnaireresponse.questionnaire_id + LEFT JOIN users_user ON users_user.id = emr_questionnaireresponse.created_by_id + LEFT JOIN emr_encounter ON emr_encounter.id = emr_questionnaireresponse.encounter_id + LEFT JOIN facility_facility ON facility_facility.id = emr_encounter.facility_id + CROSS JOIN LATERAL jsonb_array_elements(emr_questionnaireresponse.responses) AS elem + CROSS JOIN LATERAL jsonb_array_elements(elem -> 'values') AS val + WHERE + emr_questionnaire.id = 3 + AND emr_questionnaireresponse.deleted = FALSE + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] + AND elem ->> 'question_id' IN ('d602b9b2-d4cd-43d7-99d3-3d0169095eba') + ) AS nurse_visits +GROUP BY + nurse_type; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- Questionnaire_id = 3 identifies nursing visit forms and is instance-specific. +- Question_id `d602b9b2-d4cd-43d7-99d3-3d0169095eba` identifies nurse type responses and is instance-specific. +- Only non-deleted questionnaire responses are included using `emr_questionnaireresponse.deleted = FALSE`. +- Three nurse types are recognized: Community Nurse, Secondary Nurse, and MLSP Nurse. +- Facility filter uses `external_id::text` to match facility external identifiers. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16* diff --git a/Care/Operations/volunteerlinkagefor bedbound_kc.md b/Care/Operations/volunteerlinkagefor bedbound_kc.md new file mode 100644 index 0000000..67122dc --- /dev/null +++ b/Care/Operations/volunteerlinkagefor bedbound_kc.md @@ -0,0 +1,116 @@ +# Volunteer Linkage for Bedbound + +> Track the count of bedbound patients linked to volunteer support + +## Purpose + +Monitor and analyze the number of bedbound patients who have been linked to volunteer support. Helps track volunteer resource allocation and ensures bedbound patients have appropriate community support. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT | Filter by facility external ID (optional) | `6909ac5e-37b5-4ff7-8311-65610685ed44` | +| `date` | DATE | Filter by assessment date range (optional) | `2025-12-01 TO 2025-12-31` | +| `staff_name` | TEXT | Filter by staff member who recorded assessment (optional) | `Jane Smith` | + +--- + +## Query + +```sql +WITH + all_mobility_entries AS ( + SELECT + emr_questionnaireresponse.patient_id, + emr_questionnaireresponse.questionnaire_id, + emr_questionnaireresponse.created_date, + val ->> 'value' AS mobility_value, + facility_facility.name AS facility_name + FROM + emr_questionnaireresponse + JOIN users_user ON emr_questionnaireresponse.created_by_id = users_user.id + LEFT JOIN emr_encounter ON emr_questionnaireresponse.encounter_id = emr_encounter.id + LEFT JOIN facility_facility ON emr_encounter.facility_id = facility_facility.id + JOIN emr_questionnaire ON emr_questionnaireresponse.questionnaire_id = emr_questionnaire.id + CROSS JOIN LATERAL jsonb_array_elements(emr_questionnaireresponse.responses) AS elem + CROSS JOIN LATERAL jsonb_array_elements(elem -> 'values') AS val + WHERE + emr_questionnaireresponse.questionnaire_id IN (3) + AND elem ->> 'question_id' IN ('a9d443eb-a71c-4288-b285-f4b7310a4f69') + -- [[AND facility_facility.external_id::text = {{facility_id}}]] + -- [[AND {{date}}]] + -- [[AND (users_user.first_name || ' ' || users_user.last_name) = {{staff_name}}]] + ), + latest_per_patient AS ( + SELECT DISTINCT + ON (patient_id) patient_id, + questionnaire_id, + mobility_value, + facility_name, + created_date + FROM + all_mobility_entries + ORDER BY + patient_id, + created_date DESC + ), + all_volunteer_links AS ( + SELECT DISTINCT + emr_patientuser.patient_id + FROM + emr_patientuser + WHERE + emr_patientuser.role_id = 7 + AND emr_patientuser.deleted = FALSE + ), + bedbound_with_linkage AS ( + SELECT + latest_per_patient.patient_id, + CASE + WHEN all_volunteer_links.patient_id IS NOT NULL THEN 'Yes' + ELSE 'No' + END AS volunteer_linkage + FROM + latest_per_patient + LEFT JOIN all_volunteer_links ON latest_per_patient.patient_id = all_volunteer_links.patient_id + WHERE + latest_per_patient.mobility_value ILIKE '%Bedbound%' + ), + counts AS ( + SELECT + SUM( + CASE + WHEN volunteer_linkage = 'Yes' THEN 1 + ELSE 0 + END + ) AS yes_count + FROM + bedbound_with_linkage + ) +SELECT + COALESCE(yes_count, 0) AS yes_count +FROM + counts; +``` + + +## Notes + +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. +- The query uses five CTEs organized for clarity: + - `all_mobility_entries`: Extracts all mobility assessments from questionnaire responses + - `latest_per_patient`: Selects the latest mobility assessment per patient using DISTINCT ON + - `all_volunteer_links`: Identifies patients linked to volunteers (role_id = 7) + - `bedbound_with_linkage`: Joins bedbound patients with volunteer linkage status + - `counts`: Aggregates the final count +- Questionnaire_id = 3 identifies mobility assessment forms and is instance-specific. +- Question_id `a9d443eb-a71c-4288-b285-f4b7310a4f69` identifies mobility status responses and is instance-specific. +- Mobility values are extracted from nested JSONB arrays using two CROSS JOIN LATERAL operations. +- Role_id = 7 identifies volunteer relationships in the emr_patientuser table and is instance-specific. +- Only non-deleted volunteer links are included using `emr_patientuser.deleted = FALSE`. +- Facility filter uses `external_id::text` to match facility external identifiers. +- Ensure all referenced tables and fields exist and are mapped correctly. +- All filters are optional and applied dynamically by Metabase. + +*Last updated: 2025-12-16*