Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firely-validator-api-tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.11.4</FirelySdkVersion>
<FirelySdkVersion>6.0.0-alpha1</FirelySdkVersion>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>

<PropertyGroup>
<NoWarn>ExperimentalApi</NoWarn>
<NoWarn>ExperimentalApi;SDK0001</NoWarn>
</PropertyGroup>

</Project>
7 changes: 4 additions & 3 deletions firely-validator-api.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<!-- Solution-wide properties for NuGet packaging -->
<PropertyGroup>
<VersionPrefix>2.6.3</VersionPrefix>
<VersionPrefix>2.6.4</VersionPrefix>
<VersionSuffix>alpha</VersionSuffix>
<Authors>Firely</Authors>
<Company>Firely (https://fire.ly)</Company>
<Copyright>Copyright 2015-2024 Firely</Copyright>
Expand All @@ -27,7 +28,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.11.4</FirelySdkVersion>
<FirelySdkVersion>6.0.0-alpha1</FirelySdkVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down Expand Up @@ -55,7 +56,7 @@
<WarningsAsErrors>CS4014</WarningsAsErrors>
<WarningsNotAsErrors>NU5104</WarningsNotAsErrors>
<!-- RS0027 falsely complains about misuse of optional parameters in the public API-->
<NoWarn>RS0027;ExperimentalApi</NoWarn>
<NoWarn>RS0027;ExperimentalApi;SDK0001</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal StructureDefinitionToElementSchemaResolver(IAsyncResourceResolver sourc
{
try
{
return TaskHelper.Await(() => Source.FindStructureDefinitionAsync((string)schemaUri)) is StructureDefinition sd
return TaskHelper.Await(() => Source.FindStructureDefinitionAsync((string)schemaUri)) is { } sd
? _schemaBuilder.BuildSchema(sd)
: null;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Firely.Fhir.Validation.Shared/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Validator(
{
null => null,
ElementNode en => en,
Resource r => r.ToTypedElement(),
Resource r => r.ToElementNode(),
_ => throw new ArgumentException("Reference resolver must return either a Resource or ElementNode.")
};

Expand All @@ -72,15 +72,17 @@ public Validator(
/// <returns>A report containing the issues found during validation.</returns>
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
// Suppressing this issue since this will be a single method call when we introduce IScopedNode.
public OperationOutcome Validate(Resource instance, string? profile = null) => Validate(instance.ToTypedElement(ModelInfo.ModelInspector).AsScopedNode(), profile);
#pragma warning disable CS0618 // Type or member is obsolete
public OperationOutcome Validate(Resource instance, string? profile = null) => Validate(instance.ToTypedElement(ModelInfo.ModelInspector).ToScopedNode(), profile);
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters

/// <summary>
/// Validates an instance against a profile.
/// </summary>
/// <returns>A report containing the issues found during validation.</returns>
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
public OperationOutcome Validate(ElementNode instance, string? profile = null) => Validate(instance.AsScopedNode(), profile);
public OperationOutcome Validate(ElementNode instance, string? profile = null) => Validate(instance.ToScopedNode(), profile);
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters

internal OperationOutcome Validate(IScopedNode sn, string? profile = null)
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/AllValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/


using Hl7.Fhir.Model;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/AnyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/BasicValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Newtonsoft.Json.Linq;
using System.ComponentModel;

Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/BindingValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/CanonicalValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/CardinalityValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/ChildrenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Newtonsoft.Json.Linq;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/DatatypeSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/ElementSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down
4 changes: 3 additions & 1 deletion src/Firely.Fhir.Validation/Impl/ExtensionContextValidator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Hl7.FhirPath;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -100,7 +102,7 @@ private static bool validateContext(IScopedNode input, TypedContext context, Val
{
ContextType.DATATYPE => contextNode.InstanceType == context.Expression,
ContextType.EXTENSION => contextNode.Parent?.InstanceType == "Extension" && (contextNode.Parent?.Children("url").SingleOrDefault()?.Value as string) == context.Expression,
ContextType.FHIRPATH => contextNode.ResourceContext.IsTrue(context.Expression),
ContextType.FHIRPATH => contextNode.IsTrue("%resource." + context.Expression),
ContextType.ELEMENT => validateElementContext(context.Expression, state),
ContextType.RESOURCE => context.Expression == "*" || validateElementContext(context.Expression, state),
_ => throw new InvalidOperationException($"Unknown context type {context.Expression}")
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/ExtensionSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using System;
using System.Collections.Generic;
Expand Down
8 changes: 4 additions & 4 deletions src/Firely.Fhir.Validation/Impl/FhirPathValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ public override JToken ToJson()
internal override InvariantResult RunInvariant(IScopedNode input, ValidationSettings vc, ValidationState s) =>
RunInvariant(input.ToScopedNode(), vc, s);

internal InvariantResult RunInvariant(ScopedNode input, ValidationSettings vc, ValidationState s, params (string key, IEnumerable<ITypedElement> value)[] env) =>
internal InvariantResult RunInvariant(IScopedNode input, ValidationSettings vc, ValidationState s, params (string key, IEnumerable<ITypedElement> value)[] env) =>
runInvariantInternal(input, vc, s, env);

private InvariantResult runInvariantInternal(ScopedNode input, ValidationSettings vc, ValidationState s, params (string key, IEnumerable<ITypedElement> value)[] env)
private InvariantResult runInvariantInternal(IScopedNode input, ValidationSettings vc, ValidationState s, params (string key, IEnumerable<ITypedElement> value)[] env)
{
try
{
var context = new FhirEvaluationContext
{
TerminologyService = new ValidateCodeServiceToTerminologyServiceAdapter(vc.ValidateCodeService),
Environment = new Dictionary<string, IEnumerable<ITypedElement>>(env.Select(kvp => new KeyValuePair<string, IEnumerable<ITypedElement>>(kvp.key, kvp.value)))
Environment = new Dictionary<string, IEnumerable<IScopedNode>>(env.Select(kvp => new KeyValuePair<string, IEnumerable<IScopedNode>>(kvp.key, kvp.value.Select(x => x.ToScopedNode()))))
};

var success = predicate(input, context, vc);
Expand Down Expand Up @@ -167,7 +167,7 @@ private CompiledExpression getDefaultCompiledExpression(FhirPathCompiler compile
}
}

private bool predicate(ScopedNode input, EvaluationContext context, ValidationSettings vc)
private bool predicate(IScopedNode input, EvaluationContext context, ValidationSettings vc)
{
var compiler = vc?.FhirPathCompiler ?? DefaultCompiler;
var compiledExpression = getDefaultCompiledExpression(compiler);
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/FhirSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down
3 changes: 2 additions & 1 deletion src/Firely.Fhir.Validation/Impl/FhirStringValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hl7.Fhir.Support;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
using System.ComponentModel;
using System.Runtime.Serialization;
Expand Down
3 changes: 2 additions & 1 deletion src/Firely.Fhir.Validation/Impl/FhirTypeLabelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using System.ComponentModel;
using System.Runtime.Serialization;
Expand All @@ -16,7 +17,7 @@ namespace Firely.Fhir.Validation
/// <summary>
/// Assertion about the stated instance type of an element.
/// </summary>
/// <remarks>The instance type is taken from <see cref="IBaseElementNavigator{IScopedNode}.InstanceType" /></remarks>
/// <remarks>The instance type is taken from <see cref="ITypedElement.InstanceType" /></remarks>
[DataContract]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET8_0_OR_GREATER
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/FixedValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/InvariantValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
using System;
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/IssueAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public JToken ToJson()
public static class Pattern
{
/// <summary>
/// Will be replaced by <see cref="IBaseElementNavigator{IScopedNode}.InstanceType"/> at runtime.
/// Will be replaced by <see cref="ITypedElement.InstanceType"/> at runtime.
/// </summary>
public const string INSTANCETYPE = "%INSTANCETYPE%";

Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/MaxLengthValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel.Types;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/MinMaxValueValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.ElementModel.Types;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Hl7.FhirPath.Functions;
Expand Down
9 changes: 3 additions & 6 deletions src/Firely.Fhir.Validation/Impl/PathSelectorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.Model;
using Hl7.FhirPath;
using Hl7.FhirPath.Expressions;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
Expand Down Expand Up @@ -62,7 +61,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, Val
initializeFhirPathCache(vc, state);

#pragma warning disable CS0618 // Type or member is obsolete
var selected = state.Global.FPCompilerCache!.Select(input.AsTypedElement(), Path).ToList();
var selected = state.Global.FPCompilerCache!.Select(input, Path).ToList();
#pragma warning restore CS0618 // Type or member is obsolete

if (selected.Any())
Expand All @@ -72,7 +71,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, Val
state = state.UpdateInstanceLocation(ip => ip.AddInternalReference(selected.First().Location));
}

var selectedScopedNodes = cast(selected);
var selectedScopedNodes = selected;

return selectedScopedNodes switch
{
Expand Down Expand Up @@ -100,8 +99,6 @@ static void initializeFhirPathCache(ValidationSettings vc, ValidationState state
state.Global.FPCompilerCache = new FhirPathCompilerCache(compiler);
}
}

List<IScopedNode> cast(List<ITypedElement> elements) => elements.Select(e => e.AsScopedNode()).ToList();
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/PatternValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -179,7 +180,7 @@ private record ResolutionResult(ITypedElement? ReferencedResource, AggregationMo
/// <summary>
/// Try to fetch the resource within this instance (e.g. a contained or bundled resource).
/// </summary>
private static ResultReport resolveLocally(ScopedNode instance, string reference, ValidationState s, out ResolutionResult resolution)
private static ResultReport resolveLocally(IScopedNode instance, string reference, ValidationState s, out ResolutionResult resolution)
{
resolution = new ResolutionResult(null, null, null);
var identity = new ResourceIdentity(reference);
Expand Down Expand Up @@ -231,14 +232,14 @@ private ResultReport validateReferencedResource(string reference, ValidationSett
// references to external entities will operate within a new instance of a validator (and hence a new tracking context).
// In both cases, the outcome is included in the result.
if (resolution.ReferenceKind != AggregationMode.Referenced)
return Schema.ValidateOne(resolution.ReferencedResource.AsScopedNode(), vc, state.UpdateInstanceLocation(dp => dp.AddInternalReference(resolution.ReferencedResource.Location)));
return Schema.ValidateOne(resolution.ReferencedResource.ToScopedNode(), vc, state.UpdateInstanceLocation(dp => dp.AddInternalReference(resolution.ReferencedResource.Location)));
else
{
//TODO: We're using state to track the external URL, but this actually would be better
//implemented on the ScopedNode instead - add this (and combine with FullUrl?) there.
var newState = state.NewInstanceScope();
newState.Instance.ResourceUrl = reference;
return Schema.ValidateOne(resolution.ReferencedResource.AsScopedNode(), vc, newState);
return Schema.ValidateOne(resolution.ReferencedResource.ToScopedNode(), vc, newState);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/RegExValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Support;
using System;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/ResourceSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/ResultAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using System;
using System.ComponentModel;
Expand Down
1 change: 1 addition & 0 deletions src/Firely.Fhir.Validation/Impl/SliceValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* available at https://github.com/FirelyTeam/firely-validator-api/blob/main/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Newtonsoft.Json.Linq;
using System;
Expand Down
Loading
Loading