Introduction
Extracting meaningful data for healthcare machine learning (ML4H) remains a significant challenge. Researchers often encounter a "steep barrier" due to the massive, messy, and heterogeneous nature of Electronic Health Record (EHR) data stored across various hospital systems. Traditional tools present a difficult trade-off: database languages like SQL offer precision but require deep technical expertise and produce complex, hard-to-debug queries; graphical user interfaces (GUIs) are accessible but often lack the flexibility to express intricate temporal logic; and most queries lack portability, requiring extensive rewriting to move between different data standards like MIMIC-IV and eICU.
The TempoQL System
To address these challenges, we introduce TempoQL, a Python-based query system designed to simplify the extraction of complex temporal features. TempoQL is built upon four primary pillars:
- Domain-Specific Language (DSL): A concise, natural-language-like syntax for temporal aggregations, categorizing data into Attributes (static facts), Events (point-in-time), and Intervals (duration-based).
- Dataset Specification: A lightweight JSON-based mapping that acts as a bridge between the DSL and underlying database schemas, ensuring query portability across different data standards.
- Interactive Notebook Interface: An integrated Jupyter environment featuring a "Data Elements" browser for concept discovery and a "Query Results" sidebar for instant visual profiling of data distributions and missingness.
- LLM-Assisted Authoring: Integration with Large Language Models (e.g., Gemini 2.5 Pro) to translate natural language instructions into TempoQL code.
Evaluation and Key Results
TempoQL was evaluated using three major publicly available EHR datasets: MIMIC-IV, the eICU Collaborative Research Database, and EHRSHOT-MEDS. The evaluation focused on query conciseness, execution performance, and the effectiveness of LLM-based query generation.
LLM Performance and Accuracy
A key finding of this work is that LLMs are significantly more effective at generating TempoQL than traditional SQL. By abstracting away the boilerplate of joins and filters, TempoQL allows the LLM to focus on clinical logic. In head-to-head testing, Gemini 2.5 Pro generated correct TempoQL queries 81.5% of the time, a 2.5x improvement over its 31.9% accuracy for BigQuery SQL.
Conciseness and Portability
TempoQL queries are, on average, 5.9 times shorter than their SQL equivalents, making them easier for humans to read and reproduce. Furthermore, the system's portability was validated by successfully identifying a Sepsis prediction cohort across three different datasets using a single script.
Execution Performance
Despite performing aggregations locally using Python/Pandas, TempoQL showed comparable performance to BigQuery SQL across most query types. In several scenarios, it demonstrated superior scalability as the number of patient trajectories increased, avoiding expensive database-side operations.
Discussion and Future Work
While TempoQL offers significant improvements in readability and portability, some limitations remain. Local data processing can lead to a download bottleneck for certain large-scale patient-level aggregations. Currently, the system focuses on structured data; future iterations aim to incorporate unstructured clinical notes via information extraction. Additionally, while technical evaluations are promising, formal user studies with clinicians and data scientists are necessary to fully quantify usability gains. Future development may also explore hybrid execution models to optimize computation between local and database environments.
Summary updated