- Ya
- 25 Agosti 2026, 14:03 UTC
- Mwandishi
- Kamo
- Ahadi ya
- a776533
Three tables that between them make read, vread, _history, ETag and every form of _include work. fhir_resource_current is a pointer, one row per resource forever. It exists so a GET is a single primary-key lookup: finding the highest version_id instead would scan a resource's whole history on every read, so the most amended charts — the sick patients — would be the slowest to open. It is also what makes the version counter safe, because claiming the next version must be an UPDATE ... RETURNING as the FIRST statement of the write. Reading then writing is a read-after-write in one transaction, which Yugabyte aborts with 40001 under load — intermittently, so it presents as a random deadlock that a retry loop appears to fix without fixing. fhir_resource_version is append-only and holds the canonical JSON as a DERIVED read cache, not the system of record. projectorVersion is on it because that cache goes stale the moment the mapper or profile changes, and without it a US Core bump silently keeps serving last year's shape until certification testing finds out. The append-only guard is a throwing @PreUpdate/@PreRemove, NOT @Column(updatable = false): Hibernate silently omits such a column from the UPDATE, so the write appears to succeed and the value just does not change. The database half is a REVOKE in the migration, because entity callbacks are bypassed by bulk JPQL and native SQL. fhir_reference_link is the single backbone for _include, _revinclude, :iterate, chained search and _has, indexed in BOTH directions because _include and _revinclude are opposite scans and neither index serves the other. sourcePath keeps two references to the same target apart — an Encounter naming one practitioner as both participant and attending is two different clinical claims. Deleted resources keep their rows. FHIR requires a deleted resource to keep answering vread and _history, and removing the row would free the logical id for reuse, silently reattaching a new resource to an old audit trail. The discipline harness needed one rule rewritten. everyClinicalEntityExtends TheClinicalBase tested the MECHANISM; it is now everyClinicalEntityIsTenant Scoped and tests the PROPERTY, accepting either a ClinicalBaseEntity subclass or an @EmbeddedId whose first field is tenantId. The infrastructure tables need the second shape because on Yugabyte the primary key is also the co-location key. Both new rules are mutation-proven: stripping the append-only annotations and reordering the composite key each failed with their own explanation before the revert. 1624 tests green.