Skip to content

Add lab tests documentation with activity definition, observations and reference ranges - #160

Open
sonzsara wants to merge 2 commits into
mainfrom
ENG-1017
Open

sonzsara wants to merge 2 commits into
mainfrom
ENG-1017

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 10:34
@sonzsara sonzsara changed the title Add lab tests documentation with activity definition, observations and refernce ranges Add lab tests documentation with activity definition, observations and reference ranges Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The observation status filter unintentionally excludes laboratory tests without active observation definitions, and the filename contains a typo.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds an SSMM laboratory-test query documenting linked clinical definitions and reference ranges.

Changes:

  • Adds a static SQL report for laboratory service requests.
  • Includes charge items, specimens, activity definitions, observations, and qualified ranges.
File Description
Care/​Clinical/​lab_test_with_activity_definition_reference_ranges_and_observation_defintion_ssmm.md Documents the laboratory-test reference-range query.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +41 to +46
LEFT JOIN emr_observationdefinition
ON emr_observationdefinition.id = emr_observation.observation_definition_id
WHERE emr_servicerequest.status != 'entered_in_error'
AND emr_chargeitem.status != 'entered_in_error'
AND emr_servicerequest.category = 'laboratory'
AND emr_observationdefinition.status = 'active'
@@ -0,0 +1,56 @@
# Lab Tests with Activity Definition, Reference Ranges and Observation Definition - SSMM

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Analytics SQL Review — SSMM lab test / activity definition / reference range query

Ticket: none could be retrieved for branch ENG-1017 (JIRA returned 404/401 for the review bot's token). I can't verify requirement fidelity; please confirm the ticket is accessible and the branch name matches it. Assumed ask: list lab tests with charge item, specimen, activity and observation definitions and reference ranges for SSMM.

Verdict: not yet safe to publish. The parse is clean (lint: no findings), but:

  • No facility scope despite the _ssmm suffix, and no deleted = FALSE (High).
  • The WHERE emr_observationdefinition.status = 'active' negates the LEFT JOIN (High).
  • DISTINCT over patient-level observation joins hides fan-out and is costly (Medium).
  • Low: filename typo defintion → definition. The doc is otherwise template-conformant and Last updated is set; Notes should document the facility ID once added.

Generated by Analytics SQL Reviewer for #160 · auto · 14.1 AIC · ⊞ 14.3K

WHERE emr_servicerequest.status != 'entered_in_error'
AND emr_chargeitem.status != 'entered_in_error'
AND emr_servicerequest.category = 'laboratory'
AND emr_observationdefinition.status = 'active'

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 – this WHERE predicate turns the LEFT JOIN emr_observationdefinition into an inner join, so tests with no observations/active definition silently disappear (same point as the Copilot review). If tests without an active definition should still be listed, move it into the join:

LEFT JOIN emr_observationdefinition
    ON emr_observationdefinition.id = emr_observation.observation_definition_id
   AND emr_observationdefinition.status = 'active'

If dropping them is intended, use JOIN and say so in Notes. Same applies to emr_chargeitem.status != 'entered_in_error' — fine as an inner join, but consider whitelisting valid statuses.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Addressed: at the head SHA the join is now an explicit inner JOIN emr_observationdefinition, so the status = 'active' predicate no longer silently converts a LEFT JOIN. Note the Purpose still says "each distinct laboratory test", but tests with no observation or active definition are now dropped. Consider one line in Notes saying so.

Generated by Analytics SQL Reviewer for #160 · auto · 19.1 AIC · ⊞ 14.4K

## Query

```sql
SELECT DISTINCT

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium – SELECT DISTINCT over a join through emr_observation → emr_diagnosticreport → emr_specimen builds one row per patient observation before de-duplicating, which masks fan-out and will be slow on production volumes. Since only definition-level attributes are returned, consider joining emr_activitydefinition → its observation definitions directly (if the model links them) instead of via patient results. Also, emr_chargeitem.service_resource_id = external_id::text is a cast on the indexed side, so it can't use the external_id index; confirm this is the only link. Note: the Purpose says "each distinct test", but the observation path only surfaces definitions that have actually been used.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 06:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The filename contains a typo, and the no-parameter placeholder conflicts with the repository template.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
Previously missed (1)

In code that hasn't changed since last review

Low severity Remove empty Parameters section

Care/​Clinical/​lab_test_with_activity_definition_reference_ranges_and_observation_defintion_ssmm.md:17

This query has no parameters, but the repository template explicitly says to delete the Parameters section in that case (TEMPLATE.md:9-15). Remove the placeholder table rather than documenting a synthetic “none” parameter.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Analytics SQL Review — SSMM lab test / activity definition / observation definition reference ranges

Ticket: NO TICKET FOUND. JIRA returned 404 for ENG-1017 (the branch name), so I can't review requirement fidelity. Please confirm the branch name is the ticket ID and that the ticket is visible.

Since last round

  • The LEFT JOIN null-rejection finding is addressed. The join is now an explicit inner JOIN, so I resolved that thread. Notes should state that tests with no observation or active definition are excluded.
  • The facility-scope point is settled by your explanation of the single-facility SSMM deployment. Please record that assumption in Notes.

Still open

  • The missing deleted = FALSE filters on emr_servicerequest and emr_chargeitem. These are correctness issues, not style.
  • SELECT DISTINCT over the observation → diagnostic report → specimen join, which fans out to one row per patient observation before de-duplicating. It masks the fan-out and will be slow on production volumes.
  • emr_chargeitem.service_resource_id = external_id::text puts a cast on the indexed side, so the external_id index can't be used.
  • Filename typo defintion (also raised by Copilot). Rename it to ...observation_definition_ssmm.md.

Verdict: I wouldn't publish this to the dashboard until the deleted filters are in and the DISTINCT fan-out is either justified or removed. The lint report found no parse or template issues.

Generated by Analytics SQL Reviewer for #160 · auto · 19.1 AIC · ⊞ 14.4K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants