Skip to content

feat(hts): coexisting multi-version CodeSystems with version-aware co…#99

Merged
smunini merged 1 commit into
feat/hts-terminology-servicefrom
feat/hts-multi-version-cs
May 5, 2026
Merged

feat(hts): coexisting multi-version CodeSystems with version-aware co…#99
smunini merged 1 commit into
feat/hts-terminology-servicefrom
feat/hts-multi-version-cs

Conversation

@smunini
Copy link
Copy Markdown
Contributor

@smunini smunini commented May 5, 2026

…mpose

Drop the column-level UNIQUE on code_systems.url (both SQLite and PG schemas) and replace it with a composite UNIQUE index on (url, version). Two CodeSystems sharing a canonical URL now coexist whenever they declare distinct version values, matching tx-ecosystem fixtures version/codesystem-version-1.json / -2.json (both ship id:"version", url http://hl7.org/fhir/test/CodeSystem/version, versions 1.0.0 and 1.2.0). Add an idempotent SQLite migration (migrate_code_systems_drop_url_unique) that rebuilds the table without the legacy constraint, plus a PG DO-block that drops any pre-existing UNIQUE (url) constraint.

Storage id is now <fhir-id>|<version> (or <fhir-id> when version absent) so per-(url, version) rows have stable, distinct PK values without colliding when fixtures reuse the FHIR id across versions. Concepts / hierarchy / properties / designations FK to that synthetic storage id, so each version owns its own normalized data.

resolve_code_system (both backends) now picks the highest version when no version parameter is supplied, exact-matches when a literal version is given, and supports tx-ecosystem version-pattern syntax (1.x.x, 1.x, bare 1) — each x segment is a wildcard, bare numeric prefixes match any version starting with that segment, and the highest matching version wins.

Compose includes that pin a version (compose.include[].version) now resolve to the matching code_systems row instead of arbitrarily grabbing the first row by URL. The mixed value set tests/version/valueset-version-mixed.json (which pulls code1 from 1.0.0 and code2 from 1.2.0 of the same canonical URL) expands correctly. CRUD lookups by FHIR id (e.g. /CodeSystem/version) fall back to matching resource_json.id and pick the latest version when the synthetic storage id miss occurs. The hierarchy/concept-map helpers that look up system_id from a URL now ORDER BY version DESC LIMIT 1 so subsumption walks the most recent revision.

Targets the largest remaining tx-ecosystem bucket — the 147 failing version/ tests including coding-v10-vs1w, vs-expand-v1, code-vnn-* families, codeableconcept-v10-* and the mixed-version paths.

Adds 8 new unit tests covering: dual-version coexistence after import, exact / wildcard / short-prefix / unknown-version lookup, and three compose-version pinning scenarios (pin v1, pin v2, mixed). Updates the existing cs_create_indexes_into_hts_tables and
cs_delete_removes_hts_normalized_rows tests to match by URL rather than the now-synthetic storage id.

cargo test -p helios-hts --lib: 473 passed, 0 failed

…mpose

Drop the column-level UNIQUE on `code_systems.url` (both SQLite and PG
schemas) and replace it with a composite UNIQUE index on (url, version).
Two CodeSystems sharing a canonical URL now coexist whenever they
declare distinct `version` values, matching tx-ecosystem fixtures
`version/codesystem-version-1.json` / `-2.json` (both ship `id:"version"`,
url `http://hl7.org/fhir/test/CodeSystem/version`, versions `1.0.0` and
`1.2.0`). Add an idempotent SQLite migration (`migrate_code_systems_drop_url_unique`)
that rebuilds the table without the legacy constraint, plus a PG
DO-block that drops any pre-existing `UNIQUE (url)` constraint.

Storage id is now `<fhir-id>|<version>` (or `<fhir-id>` when version
absent) so per-(url, version) rows have stable, distinct PK values
without colliding when fixtures reuse the FHIR `id` across versions.
Concepts / hierarchy / properties / designations FK to that synthetic
storage id, so each version owns its own normalized data.

`resolve_code_system` (both backends) now picks the highest version
when no `version` parameter is supplied, exact-matches when a literal
version is given, and supports tx-ecosystem version-pattern syntax
(`1.x.x`, `1.x`, bare `1`) — each `x` segment is a wildcard, bare
numeric prefixes match any version starting with that segment, and
the highest matching version wins.

Compose includes that pin a `version` (`compose.include[].version`)
now resolve to the matching `code_systems` row instead of arbitrarily
grabbing the first row by URL. The mixed value set
`tests/version/valueset-version-mixed.json` (which pulls `code1` from
1.0.0 and `code2` from 1.2.0 of the same canonical URL) expands
correctly. CRUD lookups by FHIR id (e.g. `/CodeSystem/version`) fall
back to matching `resource_json.id` and pick the latest version when
the synthetic storage id miss occurs. The hierarchy/concept-map
helpers that look up `system_id` from a URL now `ORDER BY version DESC
LIMIT 1` so subsumption walks the most recent revision.

Targets the largest remaining tx-ecosystem bucket — the 147 failing
`version/` tests including coding-v10-vs1w, vs-expand-v1, code-vnn-*
families, codeableconcept-v10-* and the mixed-version paths.

Adds 8 new unit tests covering: dual-version coexistence after import,
exact / wildcard / short-prefix / unknown-version lookup, and three
compose-version pinning scenarios (pin v1, pin v2, mixed). Updates the
existing `cs_create_indexes_into_hts_tables` and
`cs_delete_removes_hts_normalized_rows` tests to match by URL rather
than the now-synthetic storage id.

cargo test -p helios-hts --lib: 473 passed, 0 failed
@smunini smunini merged commit b6d4b71 into feat/hts-terminology-service May 5, 2026
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.

1 participant