Documentation
¶
Overview ¶
Package registry provides the shared FHIR definition catalog for the monorepo.
It seeds bundled R4 StructureDefinition and SearchParameter resources, persists catalog and install overlay state through pkg/store contracts, and compiles an immutable in-memory snapshot for fast runtime lookups.
Index ¶
- Constants
- Variables
- func ContextWithJobTerminologyInstalls(ctx context.Context, job store.JobRecord, ...) (context.Context, error)
- func ContextWithTerminologyInstalls(ctx context.Context, installs store.TerminologyInstallStore) context.Context
- func DefinitionStoreWithEmbeddedBase(primary store.DefinitionStore) store.DefinitionStore
- func EmbeddedDefinitionStore() store.DefinitionStore
- func LoadDefinitionJSONs(fsys fs.FS, root string) ([][]byte, error)
- func ModulesPackageID(moduleName string) string
- func TerminologyInstallsFromContext(ctx context.Context) store.TerminologyInstallStore
- func WarmBundledDefinitionCache() error
- type CapabilitySnapshot
- type CompositeComponent
- type Config
- type DefinitionRef
- type InstallProvenance
- type Manager
- func (m *Manager) CompletePackageInstall(ctx context.Context, provenance InstallProvenance) error
- func (m *Manager) DeleteDefinition(ctx context.Context, canonicalURL, version string) error
- func (m *Manager) DisableResource(ctx context.Context, resourceType string) error
- func (m *Manager) EnableResource(ctx context.Context, resourceType string) error
- func (m *Manager) EnsureTerminologyPackEnabled(ctx context.Context, packName, packVersion, sourceModule string) error
- func (m *Manager) InstallDefinition(ctx context.Context, jsonData []byte, provenance InstallProvenance) error
- func (m *Manager) InstallDefinitionsFromDir(ctx context.Context, dir string, provenance InstallProvenance) error
- func (m *Manager) InstallDefinitionsFromFS(ctx context.Context, fsys fs.FS, root string, provenance InstallProvenance) error
- func (m *Manager) PackageVersionInstalled(ctx context.Context, packageName, packageVersion string) (bool, error)
- func (m *Manager) RebuildSnapshot(ctx context.Context) (*Snapshot, error)
- func (m *Manager) SeedBundled(ctx context.Context) error
- func (m *Manager) Snapshot() *Snapshot
- type ParsedDefinition
- type PatientReferenceResolver
- type ResourceCapability
- type SearchParameterInfo
- type SearchParameterReindexNotifier
- type SearchReindexNotifier
- type Snapshot
- func (s *Snapshot) AnyDefinitionByCanonical(canonicalURL string) ([]byte, bool)
- func (s *Snapshot) CapabilitySnapshot() CapabilitySnapshot
- func (s *Snapshot) DefinitionsByCanonical(canonicalURL, version string) ([]byte, bool)
- func (s *Snapshot) EnabledResourceTypes() []string
- func (s *Snapshot) IsInstalled(resourceType string) bool
- func (s *Snapshot) IsResourceEnabled(resourceType string) bool
- func (s *Snapshot) Operations() []DefinitionRef
- func (s *Snapshot) PatientSearchParameter(resourceType string) (SearchParameterInfo, bool)
- func (s *Snapshot) PatientSearchParameterCode(resourceType string) (string, bool)
- func (s *Snapshot) ProfilesFor(resourceType string) []DefinitionRef
- func (s *Snapshot) SearchExpression(resourceType, code string) (string, bool)
- func (s *Snapshot) SearchParameter(resourceType, code string) (*SearchParameterInfo, bool)
- func (s *Snapshot) SearchParametersFor(resourceType string) []SearchParameterInfo
- func (s *Snapshot) StructureDefinitionFor(resourceType string) ([]byte, bool)
Constants ¶
const BundledCorePackageName = "hl7.fhir.r4.core"
BundledCorePackageName is the package id for embedded R4 base definitions. SeedBundled intentionally does not enqueue ValueSet pre-expand for this pack.
const DefaultFHIRVersion = "4.0.1"
const ModulesPackageName = "haistack-modules"
ModulesPackageName is the prefix for haistack module package ids.
Variables ¶
var ( ErrInvalidDefinition = errors.New("invalid definition resource") ErrMissingDefinition = errors.New("missing required definition") ErrSnapshotCompile = errors.New("snapshot compilation failed") ErrResourceNotEnabled = errors.New("resource type not enabled") ErrDefinitionNotFound = errors.New("definition not found") ErrDefinitionConflict = errors.New("definition ownership conflict") )
Functions ¶
func ContextWithJobTerminologyInstalls ¶
func ContextWithJobTerminologyInstalls(ctx context.Context, job store.JobRecord, factory store.TerminologyInstallStoreFactory, defaultTenantID string) (context.Context, error)
ContextWithJobTerminologyInstalls opts the job owner's tenant into terminology installs. When the job has no tenant owner, defaultTenantID is used.
func ContextWithTerminologyInstalls ¶
func ContextWithTerminologyInstalls(ctx context.Context, installs store.TerminologyInstallStore) context.Context
ContextWithTerminologyInstalls overrides the terminology opt-in store for one call tree.
func DefinitionStoreWithEmbeddedBase ¶
func DefinitionStoreWithEmbeddedBase(primary store.DefinitionStore) store.DefinitionStore
DefinitionStoreWithEmbeddedBase returns a store that resolves from primary first and falls back to bundled HL7 R4 StructureDefinitions.
func EmbeddedDefinitionStore ¶
func EmbeddedDefinitionStore() store.DefinitionStore
EmbeddedDefinitionStore resolves HL7 R4 base StructureDefinitions from the embedded bundle.
func LoadDefinitionJSONs ¶
LoadDefinitionJSONs reads every .json file under root from fsys in walk order.
func ModulesPackageID ¶
ModulesPackageID returns the package id for one module (haistack-modules/<name>). Completion is tracked as ModulesPackageID(name)@manifestVersion.
func TerminologyInstallsFromContext ¶
func TerminologyInstallsFromContext(ctx context.Context) store.TerminologyInstallStore
TerminologyInstallsFromContext returns a per-request terminology opt-in store when set.
func WarmBundledDefinitionCache ¶
func WarmBundledDefinitionCache() error
WarmBundledDefinitionCache preloads embedded HL7 definition bytes used by SeedBundled.
Types ¶
type CapabilitySnapshot ¶
type CapabilitySnapshot struct {
FHIRVersion string `json:"fhirVersion"`
Resources []ResourceCapability `json:"resources"`
CompiledAt time.Time `json:"compiledAt"`
}
CapabilitySnapshot is a lightweight capability view for HTTP and runtime consumers.
type CompositeComponent ¶
type CompositeComponent struct {
Definition string `json:"definition"`
Expression string `json:"expression"`
}
CompositeComponent describes one component of a composite SearchParameter.
type Config ¶
type Config struct {
Definitions store.DefinitionStore
Installs store.RegistryInstallStore
FHIRVersion string
Now func() time.Time
SearchReindex SearchReindexNotifier
Terminology store.TerminologyStore
TerminologyScope string
GlobalTerminology store.TerminologyStore
TerminologyInstalls store.TerminologyInstallStore
TerminologyCache terminology.Invalidator
JobStore store.JobStore
PackageInstalls store.PackageInstallStore
PreExpandValueSets bool
}
Config configures a registry Manager.
type DefinitionRef ¶
type DefinitionRef struct {
CanonicalURL string `json:"canonicalUrl"`
Version string `json:"version"`
}
DefinitionRef identifies one installed definition by canonical URL and version.
type InstallProvenance ¶
type InstallProvenance struct {
PackageName string
PackageVersion string
ModuleName string
SourceModule string
}
InstallProvenance captures where an installed definition came from.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager seeds, installs, enables, and compiles the FHIR definition catalog.
func NewManager ¶
NewManager constructs a registry manager from persistence stores.
func (*Manager) CompletePackageInstall ¶
func (m *Manager) CompletePackageInstall(ctx context.Context, provenance InstallProvenance) error
CompletePackageInstall enqueues one batched ValueSet pre-expand job for a package after callers finish a loop of InstallDefinition calls and records completion.
func (*Manager) DeleteDefinition ¶
DeleteDefinition removes a catalog entry and its terminology projection.
func (*Manager) DisableResource ¶
DisableResource marks a resource type as disabled in the install overlay.
func (*Manager) EnableResource ¶
EnableResource marks a resource type as enabled when its base StructureDefinition exists.
func (*Manager) EnsureTerminologyPackEnabled ¶
func (m *Manager) EnsureTerminologyPackEnabled(ctx context.Context, packName, packVersion, sourceModule string) error
EnsureTerminologyPackEnabled opts the current tenant into all CodeSystems and ValueSets from an already-installed package version. Safe to call repeatedly; explicit tenant opt-out is preserved.
func (*Manager) InstallDefinition ¶
func (m *Manager) InstallDefinition(ctx context.Context, jsonData []byte, provenance InstallProvenance) error
InstallDefinition ingests one additional definition resource with provenance.
func (*Manager) InstallDefinitionsFromDir ¶
func (m *Manager) InstallDefinitionsFromDir(ctx context.Context, dir string, provenance InstallProvenance) error
InstallDefinitionsFromDir ingests every .json definition file under dir on the local filesystem.
func (*Manager) InstallDefinitionsFromFS ¶
func (m *Manager) InstallDefinitionsFromFS(ctx context.Context, fsys fs.FS, root string, provenance InstallProvenance) error
InstallDefinitionsFromFS ingests every .json definition file under root from fsys.
func (*Manager) PackageVersionInstalled ¶
func (m *Manager) PackageVersionInstalled(ctx context.Context, packageName, packageVersion string) (bool, error)
PackageVersionInstalled reports whether packageName@packageVersion finished install successfully (CompletePackageInstall was called). When PackageInstalls is not wired (unit tests only), this always returns false so installs proceed.
func (*Manager) RebuildSnapshot ¶
RebuildSnapshot reloads catalog and install state into an immutable compiled view.
func (*Manager) SeedBundled ¶
SeedBundled loads embedded R4 base definitions into the catalog idempotently. Bundled core definitions never enqueue ValueSet pre-expand jobs; see BundledCorePackageName.
type ParsedDefinition ¶
type ParsedDefinition struct {
CanonicalURL string
Version string
FHIRVersion string
FHIRResourceType string
DefinitionKind store.DefinitionKind
Name string
Status string
}
ParsedDefinition is normalized metadata extracted from one definition JSON resource.
func ParseDefinition ¶
func ParseDefinition(jsonData []byte) (ParsedDefinition, []store.DefinitionTargetRecord, error)
ParseDefinition extracts catalog metadata and target mappings from raw JSON.
type PatientReferenceResolver ¶
type PatientReferenceResolver struct {
Snapshot *Snapshot
Engine fhirpath.Engine
// contains filtered or unexported fields
}
PatientReferenceResolver extracts the patient id linked to a FHIR resource using the same SearchParameter selection as patient-scoped search.
func (*PatientReferenceResolver) PatientIDForResource ¶
func (r *PatientReferenceResolver) PatientIDForResource(ctx context.Context, resourceType string, resource *types.ResourceEnvelope) (string, bool, error)
PatientIDForResource returns the patient id when the resource is linked to exactly one patient via the registry patient scope SearchParameter.
func (*PatientReferenceResolver) SetSnapshot ¶
func (r *PatientReferenceResolver) SetSnapshot(snapshot *Snapshot)
SetSnapshot replaces the compiled snapshot used for patient resolution.
type ResourceCapability ¶
type ResourceCapability struct {
ResourceType string `json:"resourceType"`
StructureDefinition *DefinitionRef `json:"structureDefinition,omitempty"`
SearchParameters []SearchParameterInfo `json:"searchParameters,omitempty"`
}
ResourceCapability describes one enabled resource type in the compiled registry.
type SearchParameterInfo ¶
type SearchParameterInfo struct {
CanonicalURL string `json:"canonicalUrl"`
Version string `json:"version"`
Code string `json:"code"`
Name string `json:"name"`
Type string `json:"type"`
Expression string `json:"expression"`
Target []string `json:"target,omitempty"`
Component []CompositeComponent `json:"component,omitempty"`
// BaseCount is the number of resource types in the SearchParameter.base array.
// Single-base parameters are preferred for patient scoping because they index
// reliably; cross-resource parameters such as clinical-patient may not.
BaseCount int `json:"baseCount,omitempty"`
}
SearchParameterInfo is compiled search parameter metadata for one resource type.
type SearchParameterReindexNotifier ¶
type SearchParameterReindexNotifier interface {
SearchReindexNotifier
ScheduleSearchParameterReindex(ctx context.Context, canonicalURL, version string, resourceTypes ...string) error
}
SearchParameterReindexNotifier schedules reindex jobs for one SearchParameter definition.
type SearchReindexNotifier ¶
type SearchReindexNotifier interface {
ScheduleReindex(ctx context.Context, resourceTypes ...string) error
}
SearchReindexNotifier schedules search reindex jobs when search parameters change.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is an immutable compiled registry view.
func CompileSnapshot ¶
func CompileSnapshot( ctx context.Context, definitions store.DefinitionStore, installs store.RegistryInstallStore, fhirVersion string, now func() time.Time, ) (*Snapshot, error)
CompileSnapshot builds an immutable registry view from persisted catalog state.
func (*Snapshot) AnyDefinitionByCanonical ¶
AnyDefinitionByCanonical returns raw JSON for canonicalURL, preferring common FHIR and module versions when multiple are installed.
func (*Snapshot) CapabilitySnapshot ¶
func (s *Snapshot) CapabilitySnapshot() CapabilitySnapshot
CapabilitySnapshot returns a lightweight capability view for runtime consumers.
func (*Snapshot) DefinitionsByCanonical ¶
DefinitionsByCanonical returns raw JSON for canonicalURL and version.
func (*Snapshot) EnabledResourceTypes ¶
EnabledResourceTypes returns installed resource types in sorted order.
func (*Snapshot) IsInstalled ¶
IsInstalled implements validate.ResourceTypeRegistry.
func (*Snapshot) IsResourceEnabled ¶
IsResourceEnabled reports whether resourceType is enabled in the compiled snapshot.
func (*Snapshot) Operations ¶
func (s *Snapshot) Operations() []DefinitionRef
Operations returns installed operation definition references. Reserved for future operation compilation; empty in the MVP snapshot.
func (*Snapshot) PatientSearchParameter ¶
func (s *Snapshot) PatientSearchParameter(resourceType string) (SearchParameterInfo, bool)
PatientSearchParameter returns the installed SearchParameter used to scope resourceType to one patient.
func (*Snapshot) PatientSearchParameterCode ¶
PatientSearchParameterCode returns the FHIR search parameter code that scopes resourceType to one Patient, derived from installed reference SearchParameters. Resource-specific parameters are preferred over cross-resource definitions such as clinical-patient so the chosen code matches indexed search fields.
func (*Snapshot) ProfilesFor ¶
func (s *Snapshot) ProfilesFor(resourceType string) []DefinitionRef
ProfilesFor returns installed profile references for resourceType. Reserved for future profile compilation; empty in the MVP snapshot.
func (*Snapshot) SearchExpression ¶
SearchExpression returns the FHIRPath search expression for resourceType and code.
func (*Snapshot) SearchParameter ¶
func (s *Snapshot) SearchParameter(resourceType, code string) (*SearchParameterInfo, bool)
SearchParameter returns one search parameter for resourceType and code.
func (*Snapshot) SearchParametersFor ¶
func (s *Snapshot) SearchParametersFor(resourceType string) []SearchParameterInfo
SearchParametersFor returns installed search parameters for an enabled resource type.