From be5958bd06c9daf2997015c747e0f860dda9d239 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 25 May 2026 13:23:23 +0530 Subject: [PATCH 1/3] Add booked-in, checked-in, fulfilled, and in consultation reports for Arike facility --- Care/Operations/booked_in_report_arike.md | 67 +++++++++++++++++++ Care/Operations/checkedin_report_arike.md | 67 +++++++++++++++++++ Care/Operations/fulfilled_report_arike.md | 67 +++++++++++++++++++ .../Operations/inconsultation_report_arike.md | 67 +++++++++++++++++++ 4 files changed, 268 insertions(+) create mode 100644 Care/Operations/booked_in_report_arike.md create mode 100644 Care/Operations/checkedin_report_arike.md create mode 100644 Care/Operations/fulfilled_report_arike.md create mode 100644 Care/Operations/inconsultation_report_arike.md diff --git a/Care/Operations/booked_in_report_arike.md b/Care/Operations/booked_in_report_arike.md new file mode 100644 index 0000000..0334e01 --- /dev/null +++ b/Care/Operations/booked_in_report_arike.md @@ -0,0 +1,67 @@ + +# Booked-In Report - Arike + +> List of upcoming/booked appointments at the Arike facility with patient, practitioner and booking-staff details + +## Purpose + +Operational report for the Arike team showing every appointment currently in the `booked` state at facility (Arike). For each booking it includes: + +- Patient demographics (name, phone, gender, year of birth, ADM ID, deceased flag). +- The practitioner the booking is with. +- The slot's start datetime. +- The staff member who created the booking. + + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +WITH bookings AS ( + SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + u.first_name AS staff_first_name, + TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased + FROM emr_tokenbooking tb + JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id + JOIN emr_schedulableresource sr ON ts.resource_id = sr.id + JOIN users_user u ON tb.booked_by_id = u.id + JOIN users_user pr ON sr.user_id = pr.id + JOIN emr_patient p ON tb.patient_id = p.id + LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 + WHERE sr.facility_id = 2 + AND tb.status = 'booked' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] +) + +SELECT * FROM bookings +ORDER BY patient_name; +``` + + +## Notes + +- **Hardcoded values:** + - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. + - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. +- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- Results are ordered alphabetically by `patient_name`. + +*Last updated: 2026-05-25* + +```` diff --git a/Care/Operations/checkedin_report_arike.md b/Care/Operations/checkedin_report_arike.md new file mode 100644 index 0000000..e97eceb --- /dev/null +++ b/Care/Operations/checkedin_report_arike.md @@ -0,0 +1,67 @@ + +# Booked-In Report - Arike + +> List of checked_in appointments at the Arike facility with patient, practitioner and booking-staff details + +## Purpose + +Operational report for the Arike team showing every appointment currently in the `checked_in` state at facility (Arike). For each booking it includes: + +- Patient demographics (name, phone, gender, year of birth, ADM ID, deceased flag). +- The practitioner the booking is with. +- The slot's start datetime. +- The staff member who created the booking. + + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +WITH bookings AS ( + SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + u.first_name AS staff_first_name, + TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased + FROM emr_tokenbooking tb + JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id + JOIN emr_schedulableresource sr ON ts.resource_id = sr.id + JOIN users_user u ON tb.booked_by_id = u.id + JOIN users_user pr ON sr.user_id = pr.id + JOIN emr_patient p ON tb.patient_id = p.id + LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 + WHERE sr.facility_id = 2 + AND tb.status = 'checked_in' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] +) + +SELECT * FROM bookings +ORDER BY patient_name; +``` + + +## Notes + +- **Hardcoded values:** + - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. + - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. +- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- Results are ordered alphabetically by `patient_name`. + +*Last updated: 2026-05-25* + +```` diff --git a/Care/Operations/fulfilled_report_arike.md b/Care/Operations/fulfilled_report_arike.md new file mode 100644 index 0000000..1f1fd62 --- /dev/null +++ b/Care/Operations/fulfilled_report_arike.md @@ -0,0 +1,67 @@ + +# Booked-In Report - Arike + +> List of fulfilled appointments at the Arike facility with patient, practitioner and booking-staff details + +## Purpose + +Operational report for the Arike team showing every appointment currently in the `fulfilled` state at facility (Arike). For each booking it includes: + +- Patient demographics (name, phone, gender, year of birth, ADM ID, deceased flag). +- The practitioner the booking is with. +- The slot's start datetime. +- The staff member who created the booking. + + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +WITH bookings AS ( + SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + u.first_name AS staff_first_name, + TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased + FROM emr_tokenbooking tb + JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id + JOIN emr_schedulableresource sr ON ts.resource_id = sr.id + JOIN users_user u ON tb.booked_by_id = u.id + JOIN users_user pr ON sr.user_id = pr.id + JOIN emr_patient p ON tb.patient_id = p.id + LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 + WHERE sr.facility_id = 2 + AND tb.status = 'fulfilled' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] +) + +SELECT * FROM bookings +ORDER BY patient_name; +``` + + +## Notes + +- **Hardcoded values:** + - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. + - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. +- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- Results are ordered alphabetically by `patient_name`. + +*Last updated: 2026-05-25* + +```` diff --git a/Care/Operations/inconsultation_report_arike.md b/Care/Operations/inconsultation_report_arike.md new file mode 100644 index 0000000..d30118d --- /dev/null +++ b/Care/Operations/inconsultation_report_arike.md @@ -0,0 +1,67 @@ + +# Booked-In Report - Arike + +> List of in consultation appointments at the Arike facility with patient, practitioner and booking-staff details + +## Purpose + +Operational report for the Arike team showing every appointment currently in the `in_consultation` state at facility (Arike). For each booking it includes: + +- Patient demographics (name, phone, gender, year of birth, ADM ID, deceased flag). +- The practitioner the booking is with. +- The slot's start datetime. +- The staff member who created the booking. + + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +WITH bookings AS ( + SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + u.first_name AS staff_first_name, + TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased + FROM emr_tokenbooking tb + JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id + JOIN emr_schedulableresource sr ON ts.resource_id = sr.id + JOIN users_user u ON tb.booked_by_id = u.id + JOIN users_user pr ON sr.user_id = pr.id + JOIN emr_patient p ON tb.patient_id = p.id + LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 + WHERE sr.facility_id = 2 + AND tb.status = 'in_consultation' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] +) + +SELECT * FROM bookings +ORDER BY patient_name; +``` + + +## Notes + +- **Hardcoded values:** + - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. + - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. +- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- Results are ordered alphabetically by `patient_name`. + +*Last updated: 2026-05-25* + +```` From e5d4ed92709f89f5469c0cfa523e120f6358ea5b Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 2 Jun 2026 16:16:05 +0530 Subject: [PATCH 2/3] Update Arike reports to standardize date parameter and improve practitioner name formatting --- Care/Operations/booked_in_report_arike.md | 10 +++++----- Care/Operations/checkedin_report_arike.md | 12 ++++++------ Care/Operations/fulfilled_report_arike.md | 12 ++++++------ Care/Operations/inconsultation_report_arike.md | 12 ++++++------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Care/Operations/booked_in_report_arike.md b/Care/Operations/booked_in_report_arike.md index 0334e01..4953733 100644 --- a/Care/Operations/booked_in_report_arike.md +++ b/Care/Operations/booked_in_report_arike.md @@ -17,7 +17,7 @@ Operational report for the Arike team showing every appointment currently in th | Parameter | Type | Description | Example | |-----------|------|-------------|---------| -| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | | `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | --- @@ -34,7 +34,7 @@ WITH bookings AS ( p.year_of_birth, ts.start_datetime AS init_date, u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased FROM emr_tokenbooking tb JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id @@ -45,7 +45,7 @@ WITH bookings AS ( LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 WHERE sr.facility_id = 2 AND tb.status = 'booked' - --[[AND {{created_date}}]] + --[[AND {{date}}]] --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] ) @@ -59,9 +59,9 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* -```` + diff --git a/Care/Operations/checkedin_report_arike.md b/Care/Operations/checkedin_report_arike.md index e97eceb..569584d 100644 --- a/Care/Operations/checkedin_report_arike.md +++ b/Care/Operations/checkedin_report_arike.md @@ -1,5 +1,5 @@ -# Booked-In Report - Arike +# Checked-In Report - Arike > List of checked_in appointments at the Arike facility with patient, practitioner and booking-staff details @@ -17,7 +17,7 @@ Operational report for the Arike team showing every appointment currently in th | Parameter | Type | Description | Example | |-----------|------|-------------|---------| -| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | | `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | --- @@ -34,7 +34,7 @@ WITH bookings AS ( p.year_of_birth, ts.start_datetime AS init_date, u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased FROM emr_tokenbooking tb JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id @@ -45,7 +45,7 @@ WITH bookings AS ( LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 WHERE sr.facility_id = 2 AND tb.status = 'checked_in' - --[[AND {{created_date}}]] + --[[AND {{date}}]] --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] ) @@ -59,9 +59,9 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* -```` + diff --git a/Care/Operations/fulfilled_report_arike.md b/Care/Operations/fulfilled_report_arike.md index 1f1fd62..14f71d0 100644 --- a/Care/Operations/fulfilled_report_arike.md +++ b/Care/Operations/fulfilled_report_arike.md @@ -1,5 +1,5 @@ -# Booked-In Report - Arike +# fulfilled Report - Arike > List of fulfilled appointments at the Arike facility with patient, practitioner and booking-staff details @@ -17,7 +17,7 @@ Operational report for the Arike team showing every appointment currently in th | Parameter | Type | Description | Example | |-----------|------|-------------|---------| -| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | | `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | --- @@ -34,7 +34,7 @@ WITH bookings AS ( p.year_of_birth, ts.start_datetime AS init_date, u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased FROM emr_tokenbooking tb JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id @@ -45,7 +45,7 @@ WITH bookings AS ( LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 WHERE sr.facility_id = 2 AND tb.status = 'fulfilled' - --[[AND {{created_date}}]] + --[[AND {{date}}]] --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] ) @@ -59,9 +59,9 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* -```` + diff --git a/Care/Operations/inconsultation_report_arike.md b/Care/Operations/inconsultation_report_arike.md index d30118d..677b819 100644 --- a/Care/Operations/inconsultation_report_arike.md +++ b/Care/Operations/inconsultation_report_arike.md @@ -1,5 +1,5 @@ -# Booked-In Report - Arike +# In consultation Report - Arike > List of in consultation appointments at the Arike facility with patient, practitioner and booking-staff details @@ -17,7 +17,7 @@ Operational report for the Arike team showing every appointment currently in th | Parameter | Type | Description | Example | |-----------|------|-------------|---------| -| `created_date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | +| `date` | DATE / range | Metabase date filter on the booking (see Notes for which column it binds to) | `'2026-05-25'` | | `practitioner` | TEXT | Filter by the practitioner's full name (`first_name + last_name`, trimmed) | `'Dr Asha Menon'` | --- @@ -34,7 +34,7 @@ WITH bookings AS ( p.year_of_birth, ts.start_datetime AS init_date, u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) AS practitioner, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased FROM emr_tokenbooking tb JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id @@ -45,7 +45,7 @@ WITH bookings AS ( LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 WHERE sr.facility_id = 2 AND tb.status = 'in_consultation' - --[[AND {{created_date}}]] + --[[AND {{date}}]] --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] ) @@ -59,9 +59,9 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{created_date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* -```` + From 02258ba4d0f0de9167da2f16b52959f7b4363b94 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 2 Jun 2026 16:36:17 +0530 Subject: [PATCH 3/3] Update SQL queries in Arike reports to simplify structure --- Care/Operations/booked_in_report_arike.md | 52 +++++++++---------- Care/Operations/checkedin_report_arike.md | 52 +++++++++---------- Care/Operations/fulfilled_report_arike.md | 52 +++++++++---------- .../Operations/inconsultation_report_arike.md | 52 +++++++++---------- 4 files changed, 104 insertions(+), 104 deletions(-) diff --git a/Care/Operations/booked_in_report_arike.md b/Care/Operations/booked_in_report_arike.md index 4953733..18d42cb 100644 --- a/Care/Operations/booked_in_report_arike.md +++ b/Care/Operations/booked_in_report_arike.md @@ -25,31 +25,31 @@ Operational report for the Arike team showing every appointment currently in th ## Query ```sql -WITH bookings AS ( - SELECT - p.name AS patient_name, - p.phone_number, - p.gender, - pi.value AS adm, - p.year_of_birth, - ts.start_datetime AS init_date, - u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, - CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased - FROM emr_tokenbooking tb - JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id - JOIN emr_schedulableresource sr ON ts.resource_id = sr.id - JOIN users_user u ON tb.booked_by_id = u.id - JOIN users_user pr ON sr.user_id = pr.id - JOIN emr_patient p ON tb.patient_id = p.id - LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 - WHERE sr.facility_id = 2 - AND tb.status = 'booked' - --[[AND {{date}}]] - --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] -) - -SELECT * FROM bookings +SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased +FROM emr_tokenbooking tb +JOIN emr_tokenslot ts + ON tb.token_slot_id = ts.id +JOIN emr_schedulableresource sr + ON ts.resource_id = sr.id +JOIN users_user pr + ON sr.user_id = pr.id +JOIN emr_patient p + ON tb.patient_id = p.id +LEFT JOIN emr_patientidentifier pi + ON p.id = pi.patient_id + AND pi.config_id = 2 +WHERE sr.facility_id = 2 + AND tb.status = 'booked' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]] ORDER BY patient_name; ``` @@ -59,7 +59,7 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* diff --git a/Care/Operations/checkedin_report_arike.md b/Care/Operations/checkedin_report_arike.md index 569584d..07a1f5d 100644 --- a/Care/Operations/checkedin_report_arike.md +++ b/Care/Operations/checkedin_report_arike.md @@ -25,31 +25,31 @@ Operational report for the Arike team showing every appointment currently in th ## Query ```sql -WITH bookings AS ( - SELECT - p.name AS patient_name, - p.phone_number, - p.gender, - pi.value AS adm, - p.year_of_birth, - ts.start_datetime AS init_date, - u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, - CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased - FROM emr_tokenbooking tb - JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id - JOIN emr_schedulableresource sr ON ts.resource_id = sr.id - JOIN users_user u ON tb.booked_by_id = u.id - JOIN users_user pr ON sr.user_id = pr.id - JOIN emr_patient p ON tb.patient_id = p.id - LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 - WHERE sr.facility_id = 2 - AND tb.status = 'checked_in' - --[[AND {{date}}]] - --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] -) - -SELECT * FROM bookings +SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased +FROM emr_tokenbooking tb +JOIN emr_tokenslot ts + ON tb.token_slot_id = ts.id +JOIN emr_schedulableresource sr + ON ts.resource_id = sr.id +JOIN users_user pr + ON sr.user_id = pr.id +JOIN emr_patient p + ON tb.patient_id = p.id +LEFT JOIN emr_patientidentifier pi + ON p.id = pi.patient_id + AND pi.config_id = 2 +WHERE sr.facility_id = 2 + AND tb.status = 'checked_in' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]] ORDER BY patient_name; ``` @@ -59,7 +59,7 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* diff --git a/Care/Operations/fulfilled_report_arike.md b/Care/Operations/fulfilled_report_arike.md index 14f71d0..a18906a 100644 --- a/Care/Operations/fulfilled_report_arike.md +++ b/Care/Operations/fulfilled_report_arike.md @@ -25,31 +25,31 @@ Operational report for the Arike team showing every appointment currently in th ## Query ```sql -WITH bookings AS ( - SELECT - p.name AS patient_name, - p.phone_number, - p.gender, - pi.value AS adm, - p.year_of_birth, - ts.start_datetime AS init_date, - u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, - CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased - FROM emr_tokenbooking tb - JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id - JOIN emr_schedulableresource sr ON ts.resource_id = sr.id - JOIN users_user u ON tb.booked_by_id = u.id - JOIN users_user pr ON sr.user_id = pr.id - JOIN emr_patient p ON tb.patient_id = p.id - LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 - WHERE sr.facility_id = 2 - AND tb.status = 'fulfilled' - --[[AND {{date}}]] - --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] -) - -SELECT * FROM bookings +SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased +FROM emr_tokenbooking tb +JOIN emr_tokenslot ts + ON tb.token_slot_id = ts.id +JOIN emr_schedulableresource sr + ON ts.resource_id = sr.id +JOIN users_user pr + ON sr.user_id = pr.id +JOIN emr_patient p + ON tb.patient_id = p.id +LEFT JOIN emr_patientidentifier pi + ON p.id = pi.patient_id + AND pi.config_id = 2 +WHERE sr.facility_id = 2 + AND tb.status = 'fulfilled' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]] ORDER BY patient_name; ``` @@ -59,7 +59,7 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25* diff --git a/Care/Operations/inconsultation_report_arike.md b/Care/Operations/inconsultation_report_arike.md index 677b819..b71e26e 100644 --- a/Care/Operations/inconsultation_report_arike.md +++ b/Care/Operations/inconsultation_report_arike.md @@ -25,31 +25,31 @@ Operational report for the Arike team showing every appointment currently in th ## Query ```sql -WITH bookings AS ( - SELECT - p.name AS patient_name, - p.phone_number, - p.gender, - pi.value AS adm, - p.year_of_birth, - ts.start_datetime AS init_date, - u.first_name AS staff_first_name, - TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, - CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased - FROM emr_tokenbooking tb - JOIN emr_tokenslot ts ON tb.token_slot_id = ts.id - JOIN emr_schedulableresource sr ON ts.resource_id = sr.id - JOIN users_user u ON tb.booked_by_id = u.id - JOIN users_user pr ON sr.user_id = pr.id - JOIN emr_patient p ON tb.patient_id = p.id - LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 2 - WHERE sr.facility_id = 2 - AND tb.status = 'in_consultation' - --[[AND {{date}}]] - --[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]] -) - -SELECT * FROM bookings +SELECT + p.name AS patient_name, + p.phone_number, + p.gender, + pi.value AS adm, + p.year_of_birth, + ts.start_datetime AS init_date, + TRIM(pr.first_name || ' ' || pr.last_name) AS practitioner, + CASE WHEN p.deceased_datetime IS NULL THEN 'No' ELSE 'Yes' END AS deceased +FROM emr_tokenbooking tb +JOIN emr_tokenslot ts + ON tb.token_slot_id = ts.id +JOIN emr_schedulableresource sr + ON ts.resource_id = sr.id +JOIN users_user pr + ON sr.user_id = pr.id +JOIN emr_patient p + ON tb.patient_id = p.id +LEFT JOIN emr_patientidentifier pi + ON p.id = pi.patient_id + AND pi.config_id = 2 +WHERE sr.facility_id = 2 + AND tb.status = 'in_consultation' + --[[AND {{created_date}}]] + --[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]] ORDER BY patient_name; ``` @@ -59,7 +59,7 @@ ORDER BY patient_name; - **Hardcoded values:** - `sr.facility_id = 2` — the Arike facility ID. Update if pointing to a different facility. - `pi.config_id = 2` — the identifier config representing the Arike ADM ID. Update if the config ID changes. -- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || COALESCE(pr.last_name, '')) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. +- **Metabase filters** — `[[AND {{date}}]]` is a field filter (bind it to the column you want to filter on in the Metabase UI, typically `ts.start_datetime`), and `[[AND TRIM(pr.first_name || ' ' || pr.last_name) = {{practitioner}}]]` filters by the same expression used to render the `practitioner` column so the value matches what users see. - Results are ordered alphabetically by `patient_name`. *Last updated: 2026-05-25*