Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Care/Operations/laboratory_service_req_by_patient_count_ssmm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Laboratory Service Requests by Patient Count - SSMM

> Number of completed laboratory service requests per patient per day.

## Purpose

Identifies patients with the highest volume of laboratory service requests at SSMM.

## Parameters

*No parameters — the query returns all completed laboratory service requests.*

Comment on lines +10 to +13
---

## Query

```sql
SELECT
DATE(sr.created_date) AS created_date,
p.name AS patient_name,
pi.value AS ssmm_id,
COUNT(*) AS request_count
FROM emr_servicerequest sr
JOIN emr_patient p ON sr.patient_id = p.id
LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 21
WHERE sr.status = 'completed'
AND sr.category = 'laboratory'
GROUP BY DATE(sr.created_date), p.name, pi.value
ORDER BY request_count DESC;
Comment on lines +28 to +30
```


## Notes

- Only service requests with `status = 'completed'` and `category = 'laboratory'` are counted.
- **Hardcoded values:**
- `pi.config_id = 21` — the identifier config representing the SSMM ID. Update if the config ID changes.
- `sr.category = 'laboratory'` — restricts to lab requests; change to widen/narrow the scope (e.g. `'imaging'`).
- Results are ordered by highest `request_count` first, so top lab consumers surface at the top.
- No date filter is applied — the result spans all history. Add a `[[AND {{created_date}}]]` clause if a Metabase date filter is needed.

*Last updated: 2026-05-22*