feat: referential integrity on write and query-time search narrowing - #53
Merged
Merged
Conversation
Check local typed references with GetReferences + Exists before persist. Rewrite patient and SMART search params instead of fetch-then-hide of primary matches; keep compartment checks on include/revinclude entries. Co-authored-by: Adegoke Adewoye <[email protected]>
Search narrowing skips post-filter only for mode=match. Empty-mode operation bundles still hide out-of-scope entries. Transaction tests create the referenced Patient with POST so Exists sees it. Co-authored-by: Adegoke Adewoye <[email protected]>
Keep query rewrite while post-filtering out-of-scope match rows without recomputing Bundle.total. Add EnforceReferentialIntegrity (default on) and treat intra-bundle Type/id plus matching urn:uuid fullUrl values as present so unordered transaction creates succeed. Co-authored-by: Adegoke Adewoye <[email protected]>
Co-authored-by: Adegoke Adewoye <[email protected]>
Rewrite intra-bundle urn:uuid references to Type/id before persist so stored JSON matches assigned identities. Route writes through prepareWrite so optional pre-storage always runs before referential integrity and version meta. Co-authored-by: Adegoke Adewoye <[email protected]>
degoke
marked this pull request as ready for review
September 21, 2026 11:55
Keep both Hooks and EnforceReferentialIntegrity. prepareWrite now runs the real pre-storage SPI, then Exists checks, then version meta. Co-authored-by: Adegoke Adewoye <[email protected]>
Use the envelope returned by pre-storage for delete persist, history, events, and post-commit. Keep a clone of the stored resource for terminology cleanup and Previous. Create Encounter/enc-1 before Observation in postgres search tests so default-on integrity succeeds. Co-authored-by: Adegoke Adewoye <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HAPI-style write-time referential integrity and search narrowing that rewrites the query instead of fetching then hiding primary matches.
Merged
mainafter #52 (hook SPI). Persist prep is pre-storage → referential integrity → version meta. The placeholderwriteHooksSPI is gone;prepareWritecalls the realhooks.Hookspre-storage point, thenExists.Referential integrity
On create/update (including transaction-bundle entries),
pkg/corewalks local typed relative references withtypes.GetReferencesand requiresResourceStore.Existsbefore persist.Skipped:
#id)http(s)URLsType/id/_history/vidchecksType/id)EnforceReferentialIntegritydefaults on; set the pointer to false to disable.Same-bundle entries (including Observation-before-Patient and
urn:uuid:fullUrls that map to an entry) satisfy Exists.Missing local targets return
ErrorKindInvalid.Search narrowing
Patient compartment and SMART 2.2 scope filters inject query parameters (
subject=Patient/{id}, scopecategory=…).Bundle.totalstays the query-time count. Primarymatchrows are still compartment/SMART-checked as a safety net if a backend ignores the rewrite._include/_revincludeand empty-mode ($everything) entries remain filtered.History filtering is unchanged.
Review follow-ups
pkg/core/doc.goEncounter/enc-1before Observation so default-on integrity no longer fails on the dangling encounter ref