Skip to content

Stored procedure and data quality (J5)

Every successful operational sync records four checks in dq_check_result, grouped by a fresh run ID and evaluation time. /api/data-quality returns the latest run, and the Vue Data quality panel also reads the exported static snapshot.

The checks inspect mapped observations, conditions, immunizations, medications and allergies:

Check What is counted
null_code Records whose selected clinical code is null, empty or whitespace.
unknown_code_system Records outside the explicitly recognized LOINC, SNOMED CT, CVX, RxNorm, ICD-10-CM, ICD-9-CM and CPT systems, including absent systems. Local systems are review findings, not silently accepted terminology.
missing_unit Numeric scalar quantities lacking a unit, or numeric Observation components lacking both a usable unit and code. Each affected record is counted once. Nonquantitative results are not counted.
future_date Effective timestamps strictly after the run's evaluation time. Equality is allowed.

The denominator is the number of examined records, not the count of numeric measurements. Checks report data needing review; they neither repair nor impute values. They are not an exhaustive terminology or clinical validation service. Patient birth dates and source metadata timestamps are outside this check set.

EF migration 20261113000100_DataQualityResults creates the table on both providers. On SQL Server it also creates dbo.usp_RecordDataQualityResult, a parameterized upsert keyed by (RunId, CheckCode). Its update uses UPDLOCK, SERIALIZABLE inside a transaction before inserting a missing key. The service calls the procedure through EF's parameterized ExecuteSqlInterpolatedAsync; all four checks commit in one outer transaction.

SQLite has no stored procedures. The same service inserts the four check rows through EF and commits them in one transaction; this is the documented offline fallback. A new run gets a new ID, preserving history. Tests execute SQLite migrations and persistence and generate both SQL Server upgrade and rollback scripts. SQL Server procedure execution has not been demonstrated by those SQLite/script tests; no SQL Server execution claim is made.

Source tables preserve original FHIR alongside normalized columns. Component-unit checks inspect those preserved Observation components. The UI shows run ID, clock, scope, counts, source table and query, including when hosted as static files on a phone.