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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Laboratory Service Requests with Their Charge Items - SSMM

> Distinct laboratory service requests mapped to their linked charge items

## Purpose

Lists each laboratory service request together with the charge item linked through the service request external id.

## Parameters

| Parameter | Type | Description | Example |
|-----------|------|-------------|---------|
| *(none)* | - | Query runs as a static report with fixed filters | - |

---

## Query

```sql
SELECT DISTINCT
emr_servicerequest.title AS service_title,
emr_servicerequest.category AS service_category,
Comment thread
sonzsara marked this conversation as resolved.
emr_chargeitem.title AS charge_item_title
FROM emr_servicerequest
JOIN emr_chargeitem
ON emr_chargeitem.service_resource = 'service_request'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[High] emr_chargeitem.status is not filtered.

ChargeItem has its own status field (see care/emr/models/charge_item.py) independent of the service request's status. The query excludes entered_in_error on emr_servicerequest but not on emr_chargeitem — a charge item entered in error (or voided/cancelled) will still show up here as if it were a valid charge tied to the lab request. Add AND emr_chargeitem.status != 'entered_in_error' (and any other terminal status this report should exclude) alongside the existing service-request filter.

Also, neither table filters deleted = FALSE. It's rarely set, but it's free and matches repo convention — worth adding on both tables.

AND emr_chargeitem.service_resource_id = emr_servicerequest.external_id::text
WHERE emr_servicerequest.status != 'entered_in_error'
AND emr_servicerequest.category = 'laboratory'
ORDER BY emr_servicerequest.category, emr_servicerequest.title;
```

## Notes

- **Lab-only filter:** `emr_servicerequest.category = 'laboratory'` limits the output to laboratory requests.
- Results are sorted by service category and service title.

*Last updated: 2026-08-31*
Loading