.. _feature_prevalidation: Validating incoming resources ============================= .. note:: The features described on this page are available in **all** :ref:`Firely Server editions `. You can have Firely Server validate all resources that are sent in for create or update. The setting to do that is like this: :: "Validation": { "Parsing": "Permissive", // Permissive / Strict "Level": "Off", // Off / Core / Full "AllowedProfiles": [ "http://hl7.org/fhir/StructureDefinition/daf-patient", "http://hl7.org/fhir/StructureDefinition/daf-allergyintolerance" ] }, Parsing ------- Every incoming resource - xml or json - has to be syntactically correct. That is not configurable. Beyond that, you can choose between Permissive or Strict parsing. Permissive allows for: * empty elements (not having any value, child elements or extensions) * the fhir_comments element * errors in the xhtml of the Narrative * json specific: * array with a single value instead of just a value, or vice versa (json specific) * xml specific: * repeating elements interleaved with other elements * elements out of order * mis-representation (element instead of attribute etc.) Validation ---------- You can choose the level of validation: * Off: no validation is performed. * Core: the resource is validated against the core definition of the resource type. * Full: the resource is validated against the core definition of the resource type and against any profiles in its ``meta.profile`` element. If validation is set to ``Full`` the following validation rules will be checked: +-------------------------------+---------------------------------------------------------------+ | Validation Rule | Description | +===============================+===============================================================+ | BindingValidator | Validates that a coded value exists in the bound ValueSet | +-------------------------------+---------------------------------------------------------------+ | CanonicalValidator | Ensures a โ€˜canonicalโ€™ type is an absolute URI or fragment | +-------------------------------+---------------------------------------------------------------+ | CardinalityValidator | Verifies element occurrences match defined cardinality | +-------------------------------+---------------------------------------------------------------+ | ExtensionContextValidator | Ensures an extension is used in its allowed context | +-------------------------------+---------------------------------------------------------------+ | FhirPathValidator | Validates resource fields against FHIRPath expressions | +-------------------------------+---------------------------------------------------------------+ | FhirStringValidator | Checks that a FHIR โ€˜stringโ€™ is not empty | +-------------------------------+---------------------------------------------------------------+ | FhirTypeLabelValidator | Validates that instance type matches the declared label | +-------------------------------+---------------------------------------------------------------+ | FhirUriValidator | Ensures element value is a valid URI when serialized | +-------------------------------+---------------------------------------------------------------+ | FixedValidator | Checks that an element has the required fixed value | +-------------------------------+---------------------------------------------------------------+ | MaxLengthValidator | Enforces the maximum allowed string length | +-------------------------------+---------------------------------------------------------------+ | MinMaxValueValidator | Validates numeric or primitive values against min/max limits | +-------------------------------+---------------------------------------------------------------+ | PatternValidator | Validates element value against a defined pattern | +-------------------------------+---------------------------------------------------------------+ | RegExValidator | Checks element value against a regular expression | +-------------------------------+---------------------------------------------------------------+ | ReferencedInstanceValidator | Resolves and validates referenced resources | +-------------------------------+---------------------------------------------------------------+ | SchemaReferenceValidator | Validates element using its referenced schema | +-------------------------------+---------------------------------------------------------------+ | SliceValidator | Validates element against slice constraints | +-------------------------------+---------------------------------------------------------------+ | FhirEle1Validator | Requires element to have a value or children | +-------------------------------+---------------------------------------------------------------+ | FhirExt1Validator | Requires element to have a value or extension | +-------------------------------+---------------------------------------------------------------+ | FhirTxt1Validator | Validates that narrative contains valid HTML | +-------------------------------+---------------------------------------------------------------+ | FhirTxt2Validator | Ensures narrative is not whitespace-only | +-------------------------------+---------------------------------------------------------------+ | ChildrenValidator | Applies validation rules to child elements | +-------------------------------+---------------------------------------------------------------+ | DataTypeSchema / | Validates against data type, resource, or extension schema | | ResourceSchema / | | | ExtensionSchema | | +-------------------------------+---------------------------------------------------------------+ .. _feature_advancedvalidation: Advanced Validation ------------------- .. note:: The features described in this section are available in the following :ref:`Firely Server editions `: * Firely Scale - ๐ŸŒ / ๐Ÿ‡บ๐Ÿ‡ธ * Firely CMS Compliance - ๐Ÿ‡บ๐Ÿ‡ธ In the Firely Server editions mentioned above, Firely Server will execute additional advanced validation rules which are defined on top of the core FHIR specification for more quality control. If validation is set to ``Full`` the following validation rules will be checked: +--------------------------------+---------------------------------------------------------------------------------------------------------------+ | Validation Rule | Description | +================================+===============================================================================================================+ | ElementDefinitionValidator | Validates that ElementDefinitions paths are valid | +--------------------------------+---------------------------------------------------------------------------------------------------------------+ | StructureDefinitionValidator | Validates slicing and invariant definitions in StructureDefinitions | +--------------------------------+---------------------------------------------------------------------------------------------------------------+ | QuestionnaireResponseValidator | Validates a QuestionnaireResponse against a Questionnaire (can be stored in the Firely Server admin database) | +--------------------------------+---------------------------------------------------------------------------------------------------------------+ .. _feature_advisor_rules: Filter validation outcome based on advisor rules ------------------------------------------------ .. note:: This feature is currently in beta and is subject to change in future releases. .. note:: The features described in this section are available in the following :ref:`Firely Server editions `: * Firely Scale - ๐ŸŒ / ๐Ÿ‡บ๐Ÿ‡ธ * Firely CMS Compliance - ๐Ÿ‡บ๐Ÿ‡ธ Firely Serverโ€™s validator includes a powerful Advisor Rules system that enables users to dynamically customize validation behavior. Central to this system is the concept of filtering, which allows targeting specific validation issues or rule types based on precise criteria. Filtering allows for: * Applying custom validation behavior (e.g., override severity, suppress issues, skip rules) only when specific conditions are met * Controlling the scope of your rules by narrowing them to targeted elements, structures, codes, or messages * Combining multiple filters for granular validation strategies Configuration ^^^^^^^^^^^^^ The ``AdvisorRules`` setting in the ``Validation`` section of the appsettings allows to declaratively control how FHIR validation behaves at runtime. ``AdvisorRules`` must be provided as an escaped, JSON-encoded FHIR ``Parameters`` resource. The advisor rules are applied for all validation operations in Firely Server (i.e. $validate and pre-validation). Rules Structure (Post-Processing) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Each rule within the ``Parameters`` resource is defined as a ``parameter`` element of a specific type, which can be further configured using nested ``part`` elements. The following rule types are used for post-processing of the validation result: - ``override`` โ€“ Changes the severity of specific validation issues in the final ``OperationOutcome`` - ``suppress`` โ€“ Removes matching issues entirely from the final ``OperationOutcome`` These rules do **not** influence the core validation logic, but apply only after validation has completed. Override Rule ^^^^^^^^^^^^^ The ``override`` rule allows you to change the severity level of a validation issue **after** it has been generated by the validator. This is a post-processing operation that rewrites the final ``OperationOutcome`` without altering the validation logic itself. This rule is useful when you want to: - Downgrade known issues (e.g., from ``error`` to ``warning``) - Upgrade certain messages (e.g., from ``information`` to ``fatal``) - Mark ignorable issues as ``success`` Each ``override`` rule is defined using the following structure inside a FHIR ``Parameters`` resource: .. code-block:: json { "name": "override", "part": [ { "name": "", "valueString": "" }, { "name": "severity", "valueString": "" } ] } Fields: - ``filter-type``: One of the following: - ``code`` โ€“ Match on the validation issue code (e.g., ``6007``) - ``message`` โ€“ Match on the human-readable issue text - ``location`` โ€“ Match on the issue's path found in the ``expression`` field of the validation ``OperationOutcome``; this uses a prefix match (``startswith``), and you can use an asterisk (``*``) suffix to include child elements. - ``match-value``: The value to match for the selected filter - ``severity``: The new severity value to apply. Must be one of: - ``success``, ``information``, ``warning``, ``error``, ``fatal`` Suppress Rule ^^^^^^^^^^^^^ The ``suppress`` rule allows you to **remove specific validation issues** from the final ``OperationOutcome``. This is useful when: - You want to silence known or accepted validation deviations - You want to reduce noise in the output for downstream systems - You need to phase in conformance requirements without breaking clients Each ``suppress`` rule is defined using the following structure inside a FHIR ``Parameters`` resource: .. code-block:: json { "name": "suppress", "part": [ { "name": "", "valueString": "" } ] } Fields: - ``filter-type``: One of the following: - ``code`` โ€“ Match on the validation issue code (e.g., ``8000``) - ``message`` โ€“ Match on the issueโ€™s text exactly - ``location`` โ€“ Match on the issue's path found in the ``expression`` field of the validation ``OperationOutcome``; uses a **prefix match**, and may include an asterisk (``*``) to match children - ``match-value``: The value to compare for filtering Element Rule ^^^^^^^^^^^^ The ``element`` rule in Advisor Rules allows you to selectively apply specific types of validation checks on a given FHIR element path while skipping all other validation. This is useful when you want to fine-tune which rule types are enforced on certain parts of a resource. Each ``element`` rule is defined using the following structure inside a FHIR ``Parameters`` resource: .. code-block:: json { "name": "rules", "part": [ { "name": "element", "part": [ { "name": "filter", "part": [ { "name": "path", "valueString": "" } ] }, { "name": "options", "valueString": "" } ] } ] } Fields: - ``path``: The FHIR path to the element to be filtered. Note that child elements are not automatically assessed, you can use a trailing asterisk (``*``) to include child elements. - ``options``: The types of rules to apply. You can include one or more of the following: - ``cardinality`` โ€“ Enforces min/max occurrence constraints - ``invariant`` โ€“ Evaluates invariants defined in StructureDefinition (e.g., ``ele-1``, ``dom-3``) - ``fixed`` โ€“ Validates fixed or pattern values defined on the element Contained Rule ^^^^^^^^^^^^^^ The ``contained`` rule allows you to skip validation for specific contained resources within a parent resource. Each ``contained`` rule is defined using the following structure inside a FHIR ``Parameters`` resource: .. code-block:: json { "name": "rules", "part": [ { "name": "contained", "part": [ { "name": "filter", "part": [ { "name": "id", "valueString": "" }, { "name": "kind", "valueString": "" } ] }, { "name": "options", "valueString": "