Introduction: The Digital Archipelago in Obstetrics
In modern obstetrics, a patient’s medical journey is often fragmented across a "digital archipelago." Data resides in disparate electronic health record (EHR) modules, standalone spreadsheets, laboratory systems, and cardiotocography (CTG) device archives. This fragmentation hinders clinicians from obtaining a holistic view of patient history and complicates reproducible research. Existing systems are typically optimized for daily operations rather than analytical "secondary use." Furthermore, the technical barrier of writing SQL queries often prevents medical personnel from directly exploring centralized data.
Researchers at Udine University Hospital addressed these challenges by developing a unified relational database that consolidates peripartum data—from maternal history to real-time labor monitoring and neonatal outcomes—integrated with a natural-language-to-SQL (NL2SQL) layer.
Methodology: From Conceptual Design to NL2SQL Integration
The development followed a rigorous database design lifecycle involving three primary stages:
1. Conceptual and Logical Modeling
The team co-designed an Entity-Relationship (ER) diagram with clinicians to accurately capture the nuances of the peripartum domain. A key challenge was modeling the relationship between a single patient and multiple pregnancies. The resulting logical schema, implemented in PostgreSQL, utilized "synthetic IDs" for pregnancies to simplify complex joins.
A notable design choice was the "union-type" strategy for examinations. Rather than creating a fragmented hierarchy of different exam types, the authors consolidated them into a single relation. This simplified the schema while maintaining the ability to store diverse, type-specific data points.
2. The NL2SQL Layer
To make the database accessible to non-technical users, a two-part module was implemented:
- Frontend:
SQLChat, a web-based interface providing a familiar conversational paradigm. - Backend:
XiYanSQL-QwenCoder-32B-2504, a high-performance open-source Large Language Model (LLM) specialized in SQL generation.
3. Constraint Enforcement
Beyond standard schema rules, the system employs database triggers to enforce clinical logic. For instance, triggers ensure every pregnancy record is linked to at least one examination or delivery, maintaining data integrity for research purposes.
Results: Bridging the Technical Gap
The prototype was populated with data migrated from the Obstetrics Clinic of Udine University Hospital and tested against eight clinical queries of moderate complexity.
The system successfully translated seven out of eight queries correctly. It demonstrated a robust ability to handle multi-table joins—such as linking Patient to Pregnancy, Delivery, and Newborn—which are traditionally difficult for non-experts. In one instance, the system perfectly automated a complex SQL task: calculating the average interval between labor induction and delivery by extracting epochs from timestamps.
For benchmarking, the underlying XiYanSQL model achieved a 67.14% performance score on the BIRD (Big Bench for Large-scale Database Grounding) dataset, outperforming general-purpose models like GPT-4 in specific SQL generation tasks.
Discussion and Future Directions
The project highlights that co-design is essential; involving clinicians in the ER modeling phase ensured the database structure reflected actual obstetric workflows. By lowering the "audit barrier," the NL2SQL layer transforms the database from a passive storage bin into an active clinical tool. Clinicians can now perform complex data audits—such as identifying newborns with specific pH levels or counting C-sections within a timeframe—using simple prompts.
Limitations and Future Work
Despite its success, the NL2SQL model can struggle with ambiguous requests. Future work will focus on "schema enrichment," adding descriptive comments directly into the SQL schema to help the LLM understand hidden constraints and clinical context. Additionally, the authors aim to evolve the system into a hub for publishing anonymized datasets to foster broader reproducible research in perinatal care.
Summary updated