Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validate code to comply to external term services #393

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion 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.10.3</FirelySdkVersion>
<FirelySdkVersion>5.11.1</FirelySdkVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion firely-validator-api.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.10.3</FirelySdkVersion>
<FirelySdkVersion>5.11.1</FirelySdkVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public IEnumerable<IAssertion> Build(ElementDefinitionNavigator nav, ElementConv

if (def.Binding?.ValueSet is not null)
#if STU3
yield return new BindingValidator(convertSTU3Binding(def.Binding.ValueSet), convertStrength(def.Binding.Strength), true, $"{nav.StructureDefinition.Url}#{def.Path}");
yield return new BindingValidator(convertSTU3Binding(def.Binding.ValueSet), convertStrength(def.Binding.Strength), true);
#else
yield return new BindingValidator(def.Binding.ValueSet, convertStrength(def.Binding.Strength), true, $"{nav.StructureDefinition.Url}#{def.Path}");
yield return new BindingValidator(def.Binding.ValueSet, convertStrength(def.Binding.Strength), true);
#endif

#if STU3
Expand Down
20 changes: 6 additions & 14 deletions src/Firely.Fhir.Validation/Impl/BindingValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,18 @@ public enum BindingStrength
[DataMember]
public bool AbstractAllowed { get; private set; }

/// <summary>
/// The context of the value set, so that the server can resolve this to a value set to
/// validate against.
/// </summary>
[DataMember]
public string? Context { get; private set; }

/// <summary>
/// Constructs a validator for validating a coded element.
/// </summary>
/// <param name="valueSetUri">Value set Canonical URL</param>
/// <param name="strength">Indicates the degree of conformance expectations associated with this binding</param>
/// <param name="abstractAllowed"></param>
/// <param name="context">The context of the value set, so that the server can resolve this to a value set to validate against.</param>
public BindingValidator(Canonical valueSetUri, BindingStrength? strength, bool abstractAllowed = true, string? context = null)
public BindingValidator(Canonical valueSetUri, BindingStrength? strength, bool abstractAllowed = true)
{
ValueSetUri = valueSetUri;
Strength = strength;
AbstractAllowed = abstractAllowed;
Context = context;
}

/// <inheritdoc />
Expand Down Expand Up @@ -189,13 +181,13 @@ ValidateCodeParameters buildParams()

return bindable switch
{
FhirString str => vcp.WithCode(str.Value, system: null, display: null, context: Context),
FhirUri uri => vcp.WithCode(uri.Value, system: null, display: null, context: Context),
Code co => vcp.WithCode(co.Value, system: null, display: null, context: Context),
FhirString str => vcp.WithCode(str.Value, system: null, display: null, systemVersion: null, displayLanguage: null, context: null, inferSystem: false),
FhirUri uri => vcp.WithCode(uri.Value, system: null, display: null, systemVersion: null, displayLanguage: null, context: null, inferSystem: false),
Code co => vcp.WithCode(co.Value, system: null, display: null, systemVersion: null, displayLanguage: null, context: null, inferSystem: true),
Coding cd => vcp.WithCoding(cd),
CodeableConcept cc => vcp.WithCodeableConcept(cc),
_ => throw Error.InvalidOperation($"Parsed bindable was of unexpected instance type '{bindable.TypeName}'.")
};
}; ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra colon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

mmsmits marked this conversation as resolved.
Show resolved Hide resolved
}

var display = buildCodingDisplay(parameters);
Expand Down Expand Up @@ -236,7 +228,7 @@ public JToken ToJson()
var props = new JObject(new JProperty("abstractAllowed", AbstractAllowed));
if (Strength is not null)
props.Add(new JProperty("strength", Strength!.GetLiteral()));

props.Add(new JProperty("valueSet", (string)ValueSetUri));

return new JProperty("binding", props);
Expand Down
3 changes: 1 addition & 2 deletions src/Firely.Fhir.Validation/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Firely.Fhir.Validation.BindingValidator.BindingStrength.Example = 3 -> Firely.Fh
Firely.Fhir.Validation.BindingValidator.BindingStrength.Extensible = 1 -> Firely.Fhir.Validation.BindingValidator.BindingStrength
Firely.Fhir.Validation.BindingValidator.BindingStrength.Preferred = 2 -> Firely.Fhir.Validation.BindingValidator.BindingStrength
Firely.Fhir.Validation.BindingValidator.BindingStrength.Required = 0 -> Firely.Fhir.Validation.BindingValidator.BindingStrength
Firely.Fhir.Validation.BindingValidator.BindingValidator(Firely.Fhir.Validation.Canonical! valueSetUri, Firely.Fhir.Validation.BindingValidator.BindingStrength? strength, bool abstractAllowed = true, string? context = null) -> void
Firely.Fhir.Validation.BindingValidator.Context.get -> string?
Firely.Fhir.Validation.BindingValidator.BindingValidator(Firely.Fhir.Validation.Canonical! valueSetUri, Firely.Fhir.Validation.BindingValidator.BindingStrength? strength, bool abstractAllowed = true) -> void
Firely.Fhir.Validation.BindingValidator.Strength.get -> Firely.Fhir.Validation.BindingValidator.BindingStrength?
Firely.Fhir.Validation.BindingValidator.ToJson() -> Newtonsoft.Json.Linq.JToken!
Firely.Fhir.Validation.BindingValidator.ValueSetUri.get -> Firely.Fhir.Validation.Canonical!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"updated": "2024-10-02T15:57:47.311953+02:00",
"updated": "2024-11-25T11:47:12.2332604+01:00",
"dependencies": {
"kbv.ita.erp": "1.0.2",
"hl7.fhir.r4.core": "4.0.1",
Expand Down
Submodule FhirTestCases updated 0 files
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private static SliceValidator.SliceCase getPatternSlice(string profile) =>
new("PatternBinding",
new PathSelectorValidator("system", new AllValidator(shortcircuitEvaluation: true,
new PatternValidator(new FhirUri("http://example.com/someuri").ToTypedElement()),
new BindingValidator("http://example.com/demobinding", strength: BindingValidator.BindingStrength.Required,
context: $"{profile}#Patient.identifier.system"))),
new BindingValidator("http://example.com/demobinding", strength: BindingValidator.BindingStrength.Required))),
new ElementSchema("#Patient.identifier:PatternBinding"));

[Fact]
Expand Down Expand Up @@ -225,11 +224,11 @@ public async T.Task TestResliceGeneration()
var expectedSlice = new SliceValidator(false, true, ResultAssertion.SUCCESS,
new SliceValidator.SliceCase("phone", new PathSelectorValidator("system", new AllValidator(shortcircuitEvaluation: true,
new FixedValidator(new Code("phone").ToTypedElement()),
new BindingValidator(contactPointSystem, BindingValidator.BindingStrength.Required, context: "http://validationtest.org/fhir/StructureDefinition/ResliceTestcase#Patient.telecom.system"))),
new BindingValidator(contactPointSystem, BindingValidator.BindingStrength.Required))),
new ElementSchema("#Patient.telecom:phone")),
new SliceValidator.SliceCase("email", new PathSelectorValidator("system", new AllValidator(shortcircuitEvaluation: true,
new FixedValidator(new Code("email").ToTypedElement()),
new BindingValidator(contactPointSystem, BindingValidator.BindingStrength.Required, context: "http://validationtest.org/fhir/StructureDefinition/ResliceTestcase#Patient.telecom.system"))),
new BindingValidator(contactPointSystem, BindingValidator.BindingStrength.Required))),
new ElementSchema("#Patient.telecom:email"))
);

Expand All @@ -247,11 +246,11 @@ void testResliceInSlice2(SliceValidator.SliceCase slice2)
var email = new SliceValidator(false, false, _sliceClosedAssertion,
new SliceValidator.SliceCase("email/home", new PathSelectorValidator("use", new AllValidator(shortcircuitEvaluation: true,
new FixedValidator(new Code("home").ToTypedElement()),
new BindingValidator(contactPointUse, BindingValidator.BindingStrength.Required, context: "http://validationtest.org/fhir/StructureDefinition/ResliceTestcase#Patient.telecom.use"))),
new BindingValidator(contactPointUse, BindingValidator.BindingStrength.Required))),
new ElementSchema("#Patient.telecom:email/home")),
new SliceValidator.SliceCase("email/work", new PathSelectorValidator("use", new AllValidator(shortcircuitEvaluation: true,
new FixedValidator(new Code("work").ToTypedElement()),
new BindingValidator(contactPointUse, BindingValidator.BindingStrength.Required, context: "http://validationtest.org/fhir/StructureDefinition/ResliceTestcase#Patient.telecom.use"))),
new BindingValidator(contactPointUse, BindingValidator.BindingStrength.Required))),
new ElementSchema("#Patient.telecom:email/work"))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BindingValidatorTests()
{
var valueSetUri = "http://hl7.org/fhir/ValueSet/data-absent-reason";
_bindingAssertion =
new BindingValidator(valueSetUri, BindingValidator.BindingStrength.Required, true, CONTEXT);
new BindingValidator(valueSetUri, BindingValidator.BindingStrength.Required, true);

_validateCodeService = new Mock<ICodeValidationTerminologyService>();
_validationSettingsM =
Expand Down Expand Up @@ -95,6 +95,7 @@ public void ValidateWithCode()

Assert.IsTrue(result.IsSuccessful);
verify(p => p.Code.IsExactly(new Code("CD123")));
verify(p => p.InferSystem?.Value == true);
}

[TestMethod]
Expand Down Expand Up @@ -231,11 +232,11 @@ public void ValidateCodeableReference()
{
Concept = new CodeableConcept("http://terminology.hl7.org/CodeSystem/data-absent-reason", "masked")
}.ToTypedElement();

var result = _bindingAssertion.Validate(input, _validationSettingsM);
result.Warnings.Should().OnlyContain(w => w.IssueNumber == Issue.TERMINOLOGY_OUTPUT_WARNING.Code);
result.Errors.Should().BeEmpty();

input = new CodeableReference
{
Reference = new ResourceReference("http://some.uri")
Expand Down