### Manifest.json Structure Example Source: https://github.com/firelyteam/firely-net-sdk/blob/develop/src/Hl7.Fhir.Specification.Shared.Tests/TestData/validation-test-suite/readme.md Illustrates the structure of a manifest.json file used to define validator test cases. It includes properties like 'use-test', 'allowed-extension-domain', 'language', 'codesystems', 'profiles', and 'version'. ```json { "test-cases": { "example-test": { "use-test": true, "allowed-extension-domain": "http://example.com/fhir/extensions", "language": "en-US", "codesystems": ["codesystems/my-codesystem.json"], "profiles": ["profiles/my-profile.json"], "version": "R4", "java": { "errorCount": 1, "warningCount": 0, "output": "Validation Error: ..." } } } } ``` -------------------------------- ### Example SetValue Method in POCO Source: https://github.com/firelyteam/firely-net-sdk/wiki/Attribute-validation-and-Overflow This code shows a basic implementation of the `SetValue` method within a POCO class. It demonstrates how specific keys are mapped to properties and highlights the potential for `InvalidCastException` if the provided value's type does not match the expected type. ```csharp public override Base SetValue(string key, object? value) { switch (key) { case "identifier": Identifier = (List?)value!; return this; ``` -------------------------------- ### ValueSet Filter Example (v3) Source: https://github.com/firelyteam/firely-net-sdk/wiki/Designing-code-filters-in-ValueSets This JSON snippet shows a ValueSet compose section with an include filter. It specifies a system and uses an 'is-a' operation on the 'concept' property with a value of 'DOCCLIN'. ```json { "compose" : { "include" : [ { "system" : "http://terminology.hl7.org/CodeSystem/v3-ActClass", "filter" : [ { "property" : "concept", "op" : "is-a", "value" : "DOCCLIN" } ] } ] } } ``` -------------------------------- ### Removed ConstraintComponent Example Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-2.0 Static members representing ConstraintComponents, such as Patient_PAT_1, have been removed. Use the Hl7.Fhir.Validation.Validator class for validation. ```csharp public static ElementDefinition.ConstraintComponent Patient_PAT_1 = new ElementDefinition.ConstraintComponent() ``` -------------------------------- ### Clone Repository with Submodules (Git CLI) Source: https://github.com/firelyteam/firely-net-sdk/wiki/Clone-this-repository-with-submodule-common Use this command to clone the firely-net-sdk repository and automatically initialize its submodules. The `-j8` option is a performance optimization for fetching up to 8 submodules in parallel. ```bash git clone --recurse-submodules -j8 https://github.com/FirelyTeam/firely-net-sdk.git . ``` -------------------------------- ### Logical Model Validation Configuration Source: https://github.com/firelyteam/firely-net-sdk/blob/develop/src/Hl7.Fhir.Specification.Shared.Tests/TestData/validation-test-suite/readme.md Demonstrates how to configure validation against a logical model. This involves specifying supporting files and FHIRPath expressions to be checked. ```json "logical": { "supporting": ["models/my-logical-model.json"], "expressions": [ "Patient.name.given.exists()", "Observation.value.exists()" ] } ``` -------------------------------- ### Profile Validation Configuration Source: https://github.com/firelyteam/firely-net-sdk/blob/develop/src/Hl7.Fhir.Specification.Shared.Tests/TestData/validation-test-suite/readme.md Shows how to configure profile validation within a test case. This includes specifying the profile source and any supporting files like value sets or other profiles. ```json "profile": { "source": "profiles/my-profile.json", "supporting": ["value-sets/my-value-set.json"] } ``` -------------------------------- ### Using ToPoco on ITypedElement or ISourceNode Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-6.0 Replace calls to `BaseFhirParser.Parse` with `ToPoco()` on `ITypedElement` or `ISourceNode`. This applies to `FhirXmlParser` and `FhirJsonParser` as well. ```csharp var poco = typedElement.ToPoco(); ``` ```csharp var poco = sourceNode.ToPoco(); ``` -------------------------------- ### Instantiate ModelInfo for Specific FHIR Versions Source: https://github.com/firelyteam/firely-net-sdk/wiki/SDK-5---New-Common Create separate ModelInfo instances for different FHIR versions (e.g., R3, R4) to manage version-specific POCO assemblies. This allows for distinct handling of metadata across versions. ```csharp IModelInfo r3ModelInfo = new ModelInfo(... POCO assembly loaded for R3....) IModelInfo r4ModelInfo = new ModelInfo(... POCO assembly loaded for R4....) ``` -------------------------------- ### Manifest.json Structure Source: https://github.com/firelyteam/firely-net-sdk/blob/develop/src/Hl7.Fhir.Specification.STU3.Tests/TestData/validation-test-suite/readme.md The manifest file is a JSON object that lists the tests. It contains a 'test-cases' object, which holds a series of named tests. ```json { "test-cases": { "test-name": { "use-test": true, "allowed-extension-domain": "string", "allowed-extension-domains": [ "string" ], "language": "string", "questionnaire": "string", "codesystems": [ "string" ], "profiles": [ "string" ], "version": "string", "java": {}, "profile": { "source": "string", "supporting": [ "string" ], "java": {} }, "logical": { "supporting": [ "string" ], "expressions": [ "string" ], "java": {} } } } } ``` -------------------------------- ### FHIR JSON Parsing to POCO Source: https://github.com/firelyteam/firely-net-sdk/wiki/Unifying-POCO-and-ITypedElement Demonstrates the simpler parsing pipeline when using POCOs, which is generally faster. ```mermaid flowchart LR Json[(Json)] -- parse --> POCO ``` -------------------------------- ### Mermaid Class Diagram for Serializer Inheritance Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-6.0 Illustrates the simplified inheritance structure of serializers in version 6.0, with obsolete classes indicating a rename. ```mermaid classDiagram BaseFhirXmlSerializer <|-- FhirXmlSerializer BaseFhirXmlSerializer <|-- BaseFhirXmlPocoSerializer BaseFhirXmlPocoSerializer <|-- FhirXmlPocoSerializer class BaseFhirXmlSerializer{ } class FhirXmlSerializer{ } class BaseFhirXmlPocoSerializer{ << Obsolete >> } class FhirXmlPocoSerializer{ << Obsolete >> } ``` -------------------------------- ### Update Extension Constructor Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-2.0 The Extension constructor now takes a DataType value instead of an Element. ```csharp Extension(string url, DataType value) ``` -------------------------------- ### Schema Validation with Event Handling Source: https://github.com/firelyteam/firely-net-sdk/wiki/Handling-errors-and-bugs Configure XML reader settings to perform schema validation and subscribe to the `ValidationEventHandler` to capture validation errors. This allows for continued processing while collecting errors. ```csharp public void SomeMethod() { XmlReaderSettings xmlsettings = new XmlReaderSettings(); xmlsettings.Schemas.Add("http://www.company.com/blah", "blah.xsd"); xmlsettings.ValidationType = ValidationType.Schema; xmlsettings.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); XmlReader reader= XmlReader.Create("somefile.xml", xmlsettings); while (reader.Read()) { } } ``` -------------------------------- ### Handle Schema Not Found Exception in C# Source: https://github.com/firelyteam/firely-net-sdk/wiki/Handling-errors-and-bugs This snippet demonstrates how to catch a potential ArgumentException when a schema is not found, converting it into a more user-friendly assertion. This is useful for transient errors where the user can retry later. ```csharp public static async Task Validate(Uri uri, ITypedElement input, ValidationContext vc) { var schema = await vc.ElementSchemaResolver!.GetSchema(uri).ConfigureAwait(false); if (schema is null) throw new ArgumentException($ ``` -------------------------------- ### GetSchema Method with Error Handling Source: https://github.com/firelyteam/firely-net-sdk/wiki/Handling-errors-and-bugs Retrieves a schema, returning null if not found. Throws InvalidOperationException for corrupt archives. ```csharp public Task GetSchema(Uri schemaUri) { var canonical = schemaUri.OriginalString; if (canonical.StartsWith("http://hl7.org/fhirpath/")) // Compiler magic: stop condition { return Task.FromResult((IElementSchema?)new ElementSchema(schemaUri)); } var hit = SdStorage.GetByCanonical(canonical, FhirRelease); if (hit is null) return Task.FromResult(default(IElementSchema)); var elementSchemaBytes = SdStorage.GetElementSchema(hit.Id) ?? throw new InvalidOperationException($"The archive does contain a profile with url {canonical} " + $"in FHIR release {FhirRelease}, but the profile has no ElementSchema attached."); var result = _elementSchemaSerializer.Deserialize(elementSchemaBytes) as IElementSchema; return Task.FromResult(result); } ``` -------------------------------- ### Define Framework for FHIR Version-Specific Instances Source: https://github.com/firelyteam/firely-net-sdk/wiki/SDK-5---New-Common A proposed static class structure to hold pre-configured instances for different FHIR versions, including ModelInfo, ModelInspector, JsonSerializerOptions, and SummaryProvider. Each FHIR version would have its own assembly containing these static frameworks. ```csharp public class Framework { public IModelInfo ModelInfo; public ModelInspector ModelInspector; public JsonSerializerOptions SerializerOptions; public IStructureDefinitionSummaryProvider SummaryProvider; } // Each of these in a FHIR versions specific assembly public static Framework R4Framework = ....; public static Framework R4BFramework = ....; public static Framework R5Framework = ....; ``` -------------------------------- ### CodeSystem Header Properties for Hierarchy Source: https://github.com/firelyteam/firely-net-sdk/wiki/Designing-code-filters-in-ValueSets This JSON snippet illustrates properties defined in a CodeSystem's header that formally describe hierarchical relationships. It includes properties like 'Specializes' and 'Generalizes' to define concept relationships. ```json "hierarchyMeaning" : "is-a", "content" : "complete", "property" : [ { // Stuff left out "code" : "Specializes", "type" : "Coding" }, { "code" : "Generalizes", "description" : "Inverse of Specializes. Only included as a derived relationship.", "type" : "Coding" }, { "code" : "internalId", "uri" : "http://terminology.hl7.org/CodeSystem/utg-concept-properties#v3-internal-id", "description" : "The internal identifier for the concept in the HL7 Access database repository.", "type" : "code" }, // etcetera ``` -------------------------------- ### Configuring Exception Filtering in Custom Parsers Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-6.0 The `FhirSerializationEngineFactory.Custom()` method no longer accepts an exception filter parameter. Configure exception filtering via the XML/JSON settings passed to the `Custom()` call. ```csharp var settings = new FhirXmlPocoDeserializerSettings { // Configure validation or other settings here }; var parser = FhirXmlParser.Custom(settings); ``` ```csharp var options = new FhirJsonConverterOptions { // Configure validation or other options here }; var parser = FhirJsonParser.Custom(options); ``` -------------------------------- ### CodeSystem Concept with 'subsumedBy' Property Source: https://github.com/firelyteam/firely-net-sdk/wiki/Designing-code-filters-in-ValueSets This JSON snippet represents a concept within a CodeSystem. It demonstrates the use of the 'subsumedBy' property to express an 'is-a' relationship, where 'CDALVLONE' is subsumed by 'DOCCLIN'. ```json { "code" : "CDALVLONE", "display" : "CDA Level One clinical document", "definition" : "A clinical document that conforms to Level One of the HL7 Clinical Document Architecture (CDA)", "property" : [ { "code" : "status", "valueCode" : "active" }, { "code" : "internalId", "valueCode" : "14795" }, { "code" : "Name:Class", "valueCode" : "CDALevelOneClinicalDocument" }, { "code" : "subsumedBy", "valueCode" : "DOCCLIN" }, { "code" : "Name:Participation:act:Act", "valueString" : "&" } ] } ``` -------------------------------- ### ModelInspector for Serializer Constructors Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-6.0 Serializers no longer accept an `Assembly` in their constructors. Use `ModelInspector.ForType(typeof(Patient))` or `ModelInspector.ForAssembly()` instead. ```csharp var settings = new FhirXmlPocoDeserializerSettings(); var inspector = ModelInspector.ForType(typeof(Patient)); var parser = new FhirXmlParser(settings, inspector); ``` ```csharp var settings = new FhirJsonConverterOptions(); var inspector = ModelInspector.ForAssembly(); var parser = new FhirJsonParser(settings, inspector); ``` -------------------------------- ### Derive ResourceType using Extension Method Source: https://github.com/firelyteam/firely-net-sdk/wiki/Breaking-changes-in-2.0 Use this extension method to derive the ResourceType when the 'ResourceType' member is no longer available. ```csharp bool TryDeriveResourceType(this Resource r, out ResourceType rt) ``` -------------------------------- ### Update Profile Resource Expression in Profile-resources.xml Source: https://github.com/firelyteam/firely-net-sdk/wiki/Technical-changes-for-TC-3.0.2 The 'expression' value in Profile-resources.xml has been updated to correctly handle encoded elements. This change modifies the comparison logic for resource kinds. ```xml ```