issue

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package issue provides diagnostic message templates for FHIR validation.

Package issue defines validation issues aligned with FHIR OperationOutcome.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDiagnostic

func FormatDiagnostic(id DiagnosticID, params map[string]any) string

FormatDiagnostic formats a diagnostic message with the given parameters.

func ReleaseResult

func ReleaseResult(r *Result)

ReleaseResult returns a Result to the pool for reuse. Do not use the Result after calling this function.

func ReleaseStats

func ReleaseStats(s *Stats)

ReleaseStats returns a Stats to the pool for reuse.

Types

type Code

type Code string

Code represents the type of validation issue (IssueType).

const (
	CodeInvalid       Code = "invalid"
	CodeStructure     Code = "structure"
	CodeRequired      Code = "required"
	CodeValue         Code = "value"
	CodeInvariant     Code = "invariant"
	CodeSecurity      Code = "security"
	CodeLogin         Code = "login"
	CodeUnknown       Code = "unknown"
	CodeExpired       Code = "expired"
	CodeForbidden     Code = "forbidden"
	CodeSuppressed    Code = "suppressed"
	CodeProcessing    Code = "processing"
	CodeNotSupported  Code = "not-supported"
	CodeDuplicate     Code = "duplicate"
	CodeMultipleMatch Code = "multiple-matches"
	CodeNotFound      Code = "not-found"
	CodeDeleted       Code = "deleted"
	CodeTooLong       Code = "too-long"
	CodeCodeInvalid   Code = "code-invalid"
	CodeExtension     Code = "extension"
	CodeTooCostly     Code = "too-costly"
	CodeBusinessRule  Code = "business-rule"
	CodeConflict      Code = "conflict"
	CodeTransient     Code = "transient"
	CodeLockError     Code = "lock-error"
	CodeNoStore       Code = "no-store"
	CodeException     Code = "exception"
	CodeTimeout       Code = "timeout"
	CodeIncomplete    Code = "incomplete"
	CodeThrottled     Code = "throttled"
	CodeInformational Code = "informational"
)

Code constants aligned with FHIR IssueType.

type DiagnosticID

type DiagnosticID string

DiagnosticID identifies a specific diagnostic message.

const (
	DiagStructureUnknownElement    DiagnosticID = "STRUCTURE_UNKNOWN_ELEMENT"
	DiagStructureInvalidJSON       DiagnosticID = "STRUCTURE_INVALID_JSON"
	DiagStructureNoResourceType    DiagnosticID = "STRUCTURE_NO_RESOURCE_TYPE"
	DiagStructureUnknownResource   DiagnosticID = "STRUCTURE_UNKNOWN_RESOURCE"
	DiagStructureInvalidChoiceType DiagnosticID = "STRUCTURE_INVALID_CHOICE_TYPE"
	DiagStructureNoType            DiagnosticID = "STRUCTURE_NO_TYPE"
)

Diagnostic IDs for structural validation (M1).

const (
	DiagCardinalityMin DiagnosticID = "CARDINALITY_MIN"
	DiagCardinalityMax DiagnosticID = "CARDINALITY_MAX"
)

Diagnostic IDs for cardinality validation (M2).

const (
	DiagBindingRequired           DiagnosticID = "BINDING_REQUIRED"
	DiagBindingExtensible         DiagnosticID = "BINDING_EXTENSIBLE"
	DiagBindingExtensibleNoCoding DiagnosticID = "BINDING_EXTENSIBLE_NO_CODING"
	DiagBindingDisplayMismatch    DiagnosticID = "BINDING_DISPLAY_MISMATCH"
	DiagBindingTextOnlyWarning    DiagnosticID = "BINDING_TEXT_ONLY_WARNING"
	DiagBindingCannotValidate     DiagnosticID = "BINDING_CANNOT_VALIDATE"
	DiagBindingValueSetNotFound   DiagnosticID = "BINDING_VALUESET_NOT_FOUND"
	DiagCodeNotInCodeSystem       DiagnosticID = "CODE_NOT_IN_CODESYSTEM"
	DiagCodeSystemNotFound        DiagnosticID = "CODESYSTEM_NOT_FOUND"
)

Diagnostic IDs for binding validation (M7).

const (
	DiagExtensionNoURL            DiagnosticID = "EXTENSION_NO_URL"
	DiagExtensionUnknown          DiagnosticID = "EXTENSION_UNKNOWN"
	DiagModifierExtensionUnknown  DiagnosticID = "MODIFIER_EXTENSION_UNKNOWN"
	DiagExtensionInvalidContext   DiagnosticID = "EXTENSION_INVALID_CONTEXT"
	DiagExtensionValueRequired    DiagnosticID = "EXTENSION_VALUE_REQUIRED"
	DiagExtensionValueNotAllowed  DiagnosticID = "EXTENSION_VALUE_NOT_ALLOWED"
	DiagExtensionInvalidValueType DiagnosticID = "EXTENSION_INVALID_VALUE_TYPE"
	DiagExtensionNestedUnknown    DiagnosticID = "EXTENSION_NESTED_UNKNOWN"
)

Diagnostic IDs for extension validation (M8).

const (
	DiagReferenceInvalidFormat     DiagnosticID = "REFERENCE_INVALID_FORMAT"
	DiagReferenceInvalidTarget     DiagnosticID = "REFERENCE_INVALID_TARGET"
	DiagReferenceTypeMismatch      DiagnosticID = "REFERENCE_TYPE_MISMATCH"
	DiagReferenceNotInBundle       DiagnosticID = "REFERENCE_NOT_IN_BUNDLE"
	DiagReferenceContainedNotFound DiagnosticID = "REFERENCE_CONTAINED_NOT_FOUND"
	DiagReferenceAggregationMode   DiagnosticID = "REFERENCE_AGGREGATION_MODE"
)

Diagnostic IDs for reference validation (M9).

const (
	DiagConstraintFailed       DiagnosticID = "CONSTRAINT_FAILED"
	DiagConstraintCompileError DiagnosticID = "CONSTRAINT_COMPILE_ERROR"
	DiagConstraintEvalError    DiagnosticID = "CONSTRAINT_EVAL_ERROR"
)

Diagnostic IDs for constraint validation (M10).

const (
	DiagSlicingNoMatch        DiagnosticID = "SLICING_NO_MATCH"
	DiagSlicingCardinalityMin DiagnosticID = "SLICING_CARDINALITY_MIN"
	DiagSlicingCardinalityMax DiagnosticID = "SLICING_CARDINALITY_MAX"
)

Diagnostic IDs for slicing validation.

const (
	DiagTypeInvalidBoolean     DiagnosticID = "TYPE_INVALID_BOOLEAN"
	DiagTypeInvalidInteger     DiagnosticID = "TYPE_INVALID_INTEGER"
	DiagTypeInvalidDecimal     DiagnosticID = "TYPE_INVALID_DECIMAL"
	DiagTypeInvalidString      DiagnosticID = "TYPE_INVALID_STRING"
	DiagTypeInvalidDate        DiagnosticID = "TYPE_INVALID_DATE"
	DiagTypeInvalidDateTime    DiagnosticID = "TYPE_INVALID_DATETIME"
	DiagTypeInvalidTime        DiagnosticID = "TYPE_INVALID_TIME"
	DiagTypeInvalidInstant     DiagnosticID = "TYPE_INVALID_INSTANT"
	DiagTypeInvalidURI         DiagnosticID = "TYPE_INVALID_URI"
	DiagTypeInvalidURL         DiagnosticID = "TYPE_INVALID_URL"
	DiagTypeInvalidUUID        DiagnosticID = "TYPE_INVALID_UUID"
	DiagTypeInvalidOID         DiagnosticID = "TYPE_INVALID_OID"
	DiagTypeInvalidID          DiagnosticID = "TYPE_INVALID_ID"
	DiagTypeInvalidCode        DiagnosticID = "TYPE_INVALID_CODE"
	DiagTypeInvalidBase64      DiagnosticID = "TYPE_INVALID_BASE64"
	DiagTypeInvalidPositiveInt DiagnosticID = "TYPE_INVALID_POSITIVE_INT"
	DiagTypeInvalidUnsignedInt DiagnosticID = "TYPE_INVALID_UNSIGNED_INT"
	DiagTypeWrongJSONType      DiagnosticID = "TYPE_WRONG_JSON_TYPE"
	DiagTypeInvalidFormat      DiagnosticID = "TYPE_INVALID_FORMAT"
)

Diagnostic IDs for primitive type validation (M3).

const (
	DiagBundleFullURLMismatch DiagnosticID = "BUNDLE_FULLURL_ID_MISMATCH"
)

Diagnostic IDs for Bundle validation.

type DiagnosticTemplate

type DiagnosticTemplate struct {
	ID       DiagnosticID
	Severity Severity
	Code     Code
	Template string
}

DiagnosticTemplate defines the structure for a diagnostic message.

func GetDiagnosticTemplate

func GetDiagnosticTemplate(id DiagnosticID) (DiagnosticTemplate, bool)

GetDiagnosticTemplate returns the template for a diagnostic ID.

type Issue

type Issue struct {
	// Severity indicates the severity level (error, warning, etc.)
	Severity Severity

	// Code indicates the type of issue
	Code Code

	// Diagnostics is the human-readable description of the issue
	Diagnostics string

	// Expression contains FHIRPath expression(s) pointing to the issue location
	Expression []string

	// Location contains line and column information
	Location *Location

	// Source identifies the validation phase that generated this issue
	Source string

	// MessageID is the identifier from the error catalog
	MessageID string
}

Issue represents a single validation issue.

type Location

type Location struct {
	Line   int
	Column int
}

Location represents the position in the source JSON.

type Result

type Result struct {
	Issues []Issue
	Stats  *Stats
}

Result holds the collection of issues from validation.

func GetPooledResult

func GetPooledResult() *Result

GetPooledResult returns a Result from the pool. Call ReleaseResult when done to return it to the pool.

func NewResult

func NewResult() *Result

NewResult creates a new empty Result with pre-allocated capacity.

func (*Result) AddError

func (r *Result) AddError(code Code, diagnostics string, expression ...string)

AddError adds an error-level issue.

func (*Result) AddErrorWithID

func (r *Result) AddErrorWithID(id DiagnosticID, params map[string]any, expression ...string)

AddErrorWithID adds an error using a diagnostic template.

func (*Result) AddInfo

func (r *Result) AddInfo(code Code, diagnostics string, expression ...string)

AddInfo adds an information-level issue.

func (*Result) AddInfoWithID

func (r *Result) AddInfoWithID(id DiagnosticID, params map[string]any, expression ...string)

AddInfoWithID adds an informational message using a diagnostic template.

func (*Result) AddIssue

func (r *Result) AddIssue(issue Issue)

AddIssue adds an issue to the result.

func (*Result) AddWarning

func (r *Result) AddWarning(code Code, diagnostics string, expression ...string)

AddWarning adds a warning-level issue.

func (*Result) AddWarningWithID

func (r *Result) AddWarningWithID(id DiagnosticID, params map[string]any, expression ...string)

AddWarningWithID adds a warning using a diagnostic template.

func (*Result) EnrichLocations added in v1.4.0

func (r *Result) EnrichLocations(locator func(expression string) *Location)

EnrichLocations adds line and column information to issues based on their expressions. The locator function maps an expression path to a Location.

func (*Result) ErrorCount

func (r *Result) ErrorCount() int

ErrorCount returns the number of error-level issues.

func (*Result) Filter

func (r *Result) Filter(severity Severity) *Result

Filter returns a new Result with only issues matching the given severity.

func (*Result) HasErrors

func (r *Result) HasErrors() bool

HasErrors returns true if there are any error-level issues.

func (*Result) InfoCount

func (r *Result) InfoCount() int

InfoCount returns the number of information-level issues.

func (*Result) Merge

func (r *Result) Merge(other *Result)

Merge combines another result into this one.

func (*Result) WarningCount

func (r *Result) WarningCount() int

WarningCount returns the number of warning-level issues.

type Severity

type Severity string

Severity represents the severity of a validation issue.

const (
	SeverityFatal       Severity = "fatal"
	SeverityError       Severity = "error"
	SeverityWarning     Severity = "warning"
	SeverityInformation Severity = "information"
)

Severity constants aligned with FHIR IssueSeverity.

type Stats

type Stats struct {
	// ResourceType is the type of resource validated
	ResourceType string
	// ResourceSize is the size of the input in bytes
	ResourceSize int
	// ProfileURL is the profile used for validation
	ProfileURL string
	// IsCustomProfile indicates if a custom profile was used (vs core)
	IsCustomProfile bool
	// Duration is the total validation time
	Duration int64 // nanoseconds
	// ElementsChecked is the number of elements validated
	ElementsChecked int
	// PhasesRun is the number of validation phases executed
	PhasesRun int
}

Stats contains validation statistics.

func GetPooledStats

func GetPooledStats() *Stats

GetPooledStats returns a Stats from the pool.

func (*Stats) DurationMs

func (s *Stats) DurationMs() float64

DurationMs returns the duration in milliseconds.

Jump to

Keyboard shortcuts

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