Skip to content

EHR queries - #103

Open
jeremyestein wants to merge 88 commits into
devfrom
ehr_queries_clean
Open

jeremyestein wants to merge 88 commits into
devfrom
ehr_queries_clean

Conversation

@jeremyestein

@jeremyestein jeremyestein commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

This is now deployed and apparently working on the GAE, along with the branch for PR 1 in the private queries repo.

(vs the original PR: I have linearised the previous branches somewhat and removed all merges from dev (or janitoring), then done a big merge at the end. This took us up to the equivalent of commit 061dca7 in the other branch. Then I made some further fixes.)

skeating and others added 30 commits February 2, 2026 15:06
Introduces new queries for airway and sputum/secretions data, and refactors the flow sheet query to consolidate multiple values into a wider format. A new README documents the overall data extraction goal and the current set of scripts.
Transforms specific lab test results (e.g., CRP, WCC) from a long format into distinct columns using `MAX() FILTER`. This enables direct consumption of lab data in a wider format, simplifying downstream analysis.

Additionally, the query is updated to use parameters for `hospital_visit_id` and to include date range filtering, improving its flexibility.
@jeremyestein
jeremyestein marked this pull request as ready for review September 17, 2026 17:59

@skeating skeating left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is great Jeremy

Comment thread src/sql/lab_results.sql
ON r.lab_order_id = o.lab_order_id

WHERE
r.result_status LIKE 'FINAL'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually no you could just use =

"LabCRP",
"LabWCC",
]

@skeating skeating Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I had envisioned only recording one column of dateTime - but this is probably something we need feedback on

Comment thread src/pseudon/pseudon.py
("TubeType", pa.string()),
("TubeSize", pa.string()),
# ("Repositioned", ),
# ("Position frequency", ),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should these be commented out

Comment thread src/sql/README.md
Comment on lines +38 to +43
---

## Unfinished scripts

| script | arguments | record | location of script in repo | database |
|- | --- | --- |- | --- |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread src/sql/README.md

| script | arguments | record | location of script in repo | database |
|- | --- | --- |- | --- |
| airway.sql | csn/today/yesterday | part of the table above | waveform-private-queries/src/sql | caboodle |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one is no longer unfinished

Comment thread src/db_mssql.py
) -> pd.DataFrame:
"""Retrieve airflow data from database."""

airway_query = get_sql_query_text("private/airway.sql")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does that address the issue of differences between mssql and postgres time zones? If it does then it seems the most sensible thing to do, if not do you have plans to do that

Comment thread tests/test_ehr.py
None,
"mL",
),
# Temperature (why no units?)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

epic doesn't record a unit for temperature !!

This branch was successfully deployed

1 active deployment
hasher — 9c510557 Deployed Sep 17, 2026 by jeremyestein via Run pytest #214
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.

3 participants