Skip to content

Commit 0f50b78

Browse files
committed
Add Nursing Care Report with Patient Tags documentation and SQL query
1 parent d855ba4 commit 0f50b78

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
# Nursing Care Report with Patient Tags
3+
4+
> Nursing care questionnaire responses with patient tags for zone and place-of-care
5+
6+
## Purpose
7+
8+
Lists nursing-care questionnaire responses (`questionnaire_id = 17`) alongside patient identity (name, phone, gender, ADM identifier) and two patient tags
9+
10+
## Parameters
11+
12+
| Parameter | Type | Description | Example |
13+
|-----------|------|-------------|---------|
14+
| `visit_date` | DATE / range | Metabase date filter (typically bound to `emr_questionnaireresponse.created_date`) | `'2026-06-01'` |
15+
| `patient_name` | TEXT | Metabase text filter (typically bound to `emr_patient.name`) | `'John Doe'` |
16+
| `zone_filter` | TEXT | Filter by resolved zone tag display (exact match) | `'Zone A'` |
17+
| `place_of_care` | TEXT | Filter by resolved place-of-care tag display (exact match) | `'Home'` |
18+
19+
---
20+
21+
## Query
22+
23+
```sql
24+
WITH forms AS (
25+
SELECT
26+
emr_questionnaire.title AS form_name,
27+
emr_patient.name AS patient_name,
28+
emr_patient.phone_number,
29+
emr_patient.gender,
30+
emr_patientidentifier.value AS adm,
31+
COALESCE(
32+
(SELECT emr_tagconfig.display
33+
FROM unnest(emr_patient.instance_tags) AS tag_id
34+
JOIN emr_tagconfig ON emr_tagconfig.id = tag_id
35+
WHERE emr_tagconfig.parent_id = 55
36+
LIMIT 1),
37+
'unassigned'
38+
) AS zone,
39+
COALESCE(
40+
(SELECT emr_tagconfig.display
41+
FROM unnest(emr_patient.instance_tags) AS tag_id
42+
JOIN emr_tagconfig ON emr_tagconfig.id = tag_id
43+
WHERE emr_tagconfig.parent_id = 71
44+
LIMIT 1),
45+
'unassigned'
46+
) AS place_of_care,
47+
emr_questionnaireresponse.created_date AS date
48+
FROM emr_questionnaireresponse
49+
JOIN emr_questionnaire
50+
ON emr_questionnaireresponse.questionnaire_id = emr_questionnaire.id
51+
JOIN emr_patient
52+
ON emr_questionnaireresponse.patient_id = emr_patient.id
53+
LEFT JOIN emr_patientidentifier
54+
ON emr_patient.id = emr_patientidentifier.patient_id
55+
AND emr_patientidentifier.config_id = 2
56+
WHERE emr_questionnaire.id = 17
57+
--[[AND {{visit_date}}]]
58+
--[[AND {{patient_name}}]]
59+
)
60+
SELECT *
61+
FROM forms
62+
WHERE 1=1
63+
--[[AND zone = {{zone_filter}}]]
64+
--[[AND place_of_care = {{place_of_care}}]]
65+
ORDER BY patient_name;
66+
```
67+
68+
## Notes
69+
70+
- **Hardcoded IDs:**
71+
- `emr_questionnaire.id = 17` — the nursing-care questionnaire at Arike. Update if the questionnaire id changes.
72+
- `emr_patientidentifier.config_id = 2` — the ADM identifier configuration at Arike.
73+
- `parent_id = 55` — parent tag for **zone**.
74+
- `parent_id = 71` — parent tag for **place of care**.
75+
Update any of these if the underlying configuration changes.
76+
- **Metabase filters:**
77+
- `[[AND {{visit_date}}]]` — field filter, bind to `emr_questionnaireresponse.created_date`.
78+
- `[[AND {{patient_name}}]]` — text filter, bind to `emr_patient.name`.
79+
- `[[AND zone = {{zone_filter}}]]` and `[[AND place_of_care = {{place_of_care}}]]` — exact-match filters applied on the resolved tag columns
80+
- Results are ordered alphabetically by patient name.
81+
82+
*Last updated: 2026-07-07*

0 commit comments

Comments
 (0)