VONK-10051: Add logical model support to the schema compiler and related validation rules - #682
Conversation
…elated validation rules Introduces compilation and runtime support for FHIR logical models (e.g. CDS Hooks / Da Vinci CRD), which use JSON shapes and marker extensions that don't fit the resource/datatype schema path: - Skip the fhir-type-label check and treat unresolvable base definitions as chain-terminal for logical models, since their type/base semantics differ from regular StructureDefinitions - Add LogicalModelSchema, plus builders/validators for id-expectation, implied-string-prefix, json-nullable, json-property-key (keyed objects), extension-style named-elements, and type-specifier markers from the hl7.fhir.uv.tools extension vocabulary - Resolve absolute canonical URLs used as type codes directly instead of wrapping them as core type references
There was a problem hiding this comment.
Pull request overview
Adds logical-model schema compilation and validation support for FHIR tooling extensions.
Changes:
- Adds logical-model schemas, JSON property mapping, keyed objects, and named extensions.
- Adds validators/builders for type specifiers, ID expectations, implied prefixes, and nullability.
- Updates type-reference and base-profile handling for logical models.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
PublicAPI.Unshipped.txt |
Registers new public APIs. |
TypeSpecifierValidator.cs |
Selects schemas using FHIRPath conditions. |
NamedExtensionsValidator.cs |
Resolves and validates named extensions. |
LogicalModelSchema.cs |
Adds logical-model schema behavior. |
KeyedObjectValidator.cs |
Validates object-map entries. |
JsonNullableValidator.cs |
Records JSON nullability. |
ImpliedStringPrefixValidator.cs |
Validates values with restored prefixes. |
IdExpectationValidator.cs |
Enforces resource ID expectations. |
ToolsExtensions.cs |
Reads logical-model tooling extensions. |
TypeSpecifierBuilder.cs |
Builds conditional type validation. |
TypeReferenceBuilder.cs |
Substitutes special logical-model type handling. |
StandardBuilders.cs |
Registers new builders. |
JsonNullableBuilder.cs |
Builds nullability assertions. |
ImpliedStringPrefixBuilder.cs |
Builds implied-prefix assertions. |
IdExpectationBuilder.cs |
Builds ID-expectation assertions. |
SchemaBuilder.cs |
Compiles logical-model serialization patterns. |
Firely.Fhir.Validation.Compilation.Shared.projitems |
Includes new compiler sources. |
CommonTypeRefComponentExtensions.cs |
Preserves canonical logical-model type codes. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| internal override ResultReport BasicValidate(PocoNode input, ValidationSettings vc, ValidationState s) => | ||
| // Documentation/schema only marker: JSON null never yields a child node to validate against per FHIR. | ||
| ResultReport.SUCCESS; |
There was a problem hiding this comment.
We accept this limitation as we do not have a way to communicate null object in either case, and we agreed the filtering of that will be left to the implementer via Advisor Framework
|
@copilot-pull-request-reviewer Fixing. Will be in the next commit |
|
@copilot - can you add examples of CDS hooks constructs that are validated by the newly added validators in this PR? |
Co-authored-by: ewoutkramer <2276305+ewoutkramer@users.noreply.github.com>
I actually meant: can you add comments to this PR that shows the CDS hook constructs in json that are being verified by the new validator blocks? I don't know the wire format exactly anymore and it would help to review it. By the way, the extra tests you have added did point out to me that there were no extra tests added to test the construction of the new validators by the builders, so they can stay (or adapted now you realize that they need not be examples, but just good tests for the builders). |
Absolutely — here are concrete wire-format JSON snippets that map to the new validator blocks: {
"hook": "order-sign",
"context": {
"patientId": "123"
}
}
{
"hookInstance": "550e8400-e29b-41d4-a716-446655440000"
}
{
"prefetch": {
"medications": { "resourceType": "Bundle" },
"allergies": { "resourceType": "Bundle" }
}
}
{
"cards": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"suggestions": [
{
"actions": [
{
"type": "create",
"description": "Draft order",
"resource": null
}
]
}
]
}
]
}
If useful, I can add a compact version of these snippets to the PR description too. |
This pull request introduces enhanced support for FHIR logical models, particularly those used in CDS Hooks and Da Vinci CRD, and adds several new schema builders to improve validation capabilities. The changes ensure correct handling of logical models' unique serialization patterns, such as property keying and named extensions, and make the schema compilation process more robust and extensible.
Logical model and schema compilation improvements:
deriveSystemTypeFromXsdType, avoiding incorrect wrapping as core FHIR types.LogicalModelSchemaand unresolvable logical model bases are now tolerated (rather than causing compilation errors), improving compatibility with real-world logical model hierarchies. [1] [2]SchemaBuilder.cs) has been extended to correctly handle logical models' special serialization cases:New schema builders:
IdExpectationBuilder,ImpliedStringPrefixBuilder, andJsonNullableBuilderto support new FHIR tooling extensions for id expectations, implied string prefixes, and JSON nullability, respectively. [1] [2] [3]These changes significantly improve the flexibility and correctness of FHIR logical model validation and extend the schema system to support new FHIR extension patterns.