structuremap

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package structuremap provides a minimal FHIR StructureMap execution engine for SDC questionnaire extraction.

The engine executes StructureMap group rules against Questionnaire and QuestionnaireResponse inputs and produces FHIR resources for transaction bundle entries. Full FHIR Mapping Language transform parity is not a goal; the supported transforms cover common SDC extraction patterns (create, copy, uuid, cc, evaluate).

The entry group is selected by matching StructureMap.name to a group name, otherwise the first group is executed. Helper groups are invoked through rule dependents.

Integrate with pkg/sdc via ExtractorRun or NewExtractor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonical

func Canonical(m Map) string

func ExtractorRun

ExtractorRun builds the Run hook used by sdc.StructureMapExtractor.

func NewExtractor

func NewExtractor(cfg Config) sdc.StructureMapExtractor

NewExtractor returns a StructureMapExtractor backed by this runtime.

Types

type CardinalityResolver

type CardinalityResolver interface {
	IsRepeating(ctx context.Context, fhirPath string) (bool, bool)
}

CardinalityResolver reports whether a FHIR element path allows multiple values.

type Config

type Config struct {
	Resolver Resolver
	Engine   Engine
}

Config wires StructureMap extraction into pkg/sdc.

type Dependent

type Dependent struct {
	Name     string   `json:"name"`
	Variable []string `json:"variable,omitempty"`
}

type Engine

type Engine struct {
	FHIRPath fhirpath.Engine
	// Strict reports an error when a rule declares sources but none match.
	Strict bool
	// Translator resolves translate transforms via ConceptMap resources.
	Translator conceptmap.Translator
	// Cardinality resolves repeating elements from StructureDefinitions.
	Cardinality CardinalityResolver
}

Engine executes StructureMap group rules.

func (Engine) Execute

func (e Engine) Execute(ctx context.Context, m Map, inputs ExecuteInput) ([]json.RawMessage, error)

Execute runs a StructureMap and returns produced FHIR resources.

type ExecuteInput

type ExecuteInput map[string]any

ExecuteInput names resources available to the map by variable name.

type Group

type Group struct {
	Name     string  `json:"name"`
	TypeMode string  `json:"typeMode,omitempty"`
	Input    []Input `json:"input,omitempty"`
	Rule     []Rule  `json:"rule,omitempty"`
}

type Input

type Input struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Mode string `json:"mode"`
}

type Map

type Map struct {
	ResourceType string      `json:"resourceType"`
	URL          string      `json:"url"`
	Version      string      `json:"version,omitempty"`
	Status       string      `json:"status,omitempty"`
	Name         string      `json:"name,omitempty"`
	Structure    []Structure `json:"structure,omitempty"`
	Group        []Group     `json:"group,omitempty"`
}

Map is the JSON representation of a FHIR StructureMap resource.

func ParseMap

func ParseMap(raw []byte) (Map, error)

func ResolveEnvelope

func ResolveEnvelope(env *types.ResourceEnvelope) (Map, error)

ResolveEnvelope parses a StructureMap envelope.

type Parameter

type Parameter struct {
	ValueID      string   `json:"valueId,omitempty"`
	ValueString  string   `json:"valueString,omitempty"`
	ValueBoolean *bool    `json:"valueBoolean,omitempty"`
	ValueInteger *int     `json:"valueInteger,omitempty"`
	ValueDecimal *float64 `json:"valueDecimal,omitempty"`
}

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, canonical string) (Map, error)
}

Resolver loads StructureMap resources by canonical URL.

type ResourceCardinalityResolver

type ResourceCardinalityResolver interface {
	CardinalityResolver
	IsRepeatingFor(ctx context.Context, root map[string]any, fhirPath string) (bool, bool)
}

ResourceCardinalityResolver resolves cardinality using resource instance metadata.

type Rule

type Rule struct {
	Name      string      `json:"name,omitempty"`
	Source    []Source    `json:"source,omitempty"`
	Target    []Target    `json:"target,omitempty"`
	Rule      []Rule      `json:"rule,omitempty"`
	Dependent []Dependent `json:"dependent,omitempty"`
}

type Source

type Source struct {
	Context   string   `json:"context"`
	Element   []string `json:"element,omitempty"`
	Variable  string   `json:"variable,omitempty"`
	Condition string   `json:"condition,omitempty"`
	ListMode  string   `json:"listMode,omitempty"`
	Min       int      `json:"min,omitempty"`
	Max       string   `json:"max,omitempty"`
}

type StaticResolver

type StaticResolver map[string]Map

StaticResolver resolves maps from an in-memory table keyed by canonical URL.

func (StaticResolver) Resolve

func (r StaticResolver) Resolve(_ context.Context, canonical string) (Map, error)

type StoreCardinalityResolver

type StoreCardinalityResolver struct {
	Store store.DefinitionStore
}

StoreCardinalityResolver resolves cardinality from StructureDefinition resources. Use cardinalityForMap during map execution for profile-aware, per-run indexes.

func (*StoreCardinalityResolver) IsRepeating

func (r *StoreCardinalityResolver) IsRepeating(ctx context.Context, fhirPath string) (bool, bool)

type StoreResolver

type StoreResolver struct {
	Resources store.ResourceStore
	Registry  store.DefinitionStore
	// contains filtered or unexported fields
}

StoreResolver resolves StructureMap resources from a ResourceStore and, when available, a DefinitionStore fallback. The resource-store index is rebuilt on each resolve so newly stored maps are visible immediately.

func (*StoreResolver) Resolve

func (r *StoreResolver) Resolve(ctx context.Context, canonical string) (Map, error)

type Structure

type Structure struct {
	URL  string `json:"url"`
	Mode string `json:"mode"`
}

type Target

type Target struct {
	Context   string      `json:"context"`
	Element   []string    `json:"element,omitempty"`
	Variable  string      `json:"variable,omitempty"`
	Transform string      `json:"transform,omitempty"`
	Parameter []Parameter `json:"parameter,omitempty"`
	ListMode  []string    `json:"listMode,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL