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

Handle CodeableReferences that have a reference, not a code. #69

Merged
merged 6 commits into from
Feb 16, 2024
Merged
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ working/
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
Expand Down Expand Up @@ -164,4 +163,6 @@ src/.vs/
.vs/
build/runbuild.txt

dist/
dist/
/.idea/.idea.Hl7.Fhir.Validation.Legacy/.idea/indexLayout.xml
/.idea/.idea.Hl7.Fhir.Validation.Legacy/.idea/workspace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void TestValueValidation()

v = new Quantity(4.0m, "not-human", "http://hl7.org/fhir/administrative-gender"); // nonsense, but hey UCUM is not provided with the spec
node = v.ToTypedElement();
Assert.False(validator.Validate(node, vc).Success);
var r = validator.Validate(node, vc);
Assert.False(r.Success);

v = new Quantity(4.0m, "kg"); // sorry, UCUM is not provided with the spec - still validate against data-absent-reason
node = v.ToTypedElement();
Expand All @@ -69,6 +70,27 @@ public void TestValueValidation()
ic.Code = "not=human";
node = ext.ToTypedElement();
Assert.False(validator.Validate(node, vc).Success);

var cr1 = new CodeableReference
{
Concept = new CodeableConcept("http://hl7.org/fhir/administrative-gender", "female")
}.ToTypedElement();

validator.Validate(cr1, vc).Success.Should().BeTrue();

var cr2 = new CodeableReference
{
Concept = new CodeableConcept("http://hl7.org/fhir/administrative-gender", "femaleX")
}.ToTypedElement();

validator.Validate(cr2, vc).Success.Should().BeFalse();

var cr3 = new CodeableReference
{
Reference = new ResourceReference("http://some.uri")
}.ToTypedElement();

validator.Validate(cr3, vc).Success.Should().BeTrue();
}


Expand Down Expand Up @@ -194,6 +216,8 @@ public void TestCodeableConceptValidation()
Assert.Equal(0, result.Warnings);
}



[Fact]
public void TestValidationErrorMessageForCodings()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.Model;
using Hl7.FhirPath;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Hl7.Fhir.Validation
Expand Down Expand Up @@ -109,6 +102,28 @@ public void TestParseBindableUri()
Assert.NotNull(c);
Assert.Equal(iu.Value, c.Value);
}

[Fact]
public void TestParseBindableCodeableReference()
{
var i = new Model.CodeableReference
{
Reference = new("http://unitsofmeasure.org"),
Concept = new CodeableConcept
{
Text = "Entered text"
}
};
i.Concept.Coding.Add(
new Coding("system", "code"));

var node = i.ToTypedElement();
var c = node.ParseBindable() as CodeableConcept;

Assert.NotNull(node);
Assert.Equal(i.Concept.Coding[0].Code, c.Coding[0].Code);
Assert.Equal("system", c.Coding[0].System);
}

[Fact]
public void TestParseBindableExtension()
Expand All @@ -133,7 +148,7 @@ public void TestParseBindableExtension()

[Fact]
public void TestParseUnbindable()
{
{
// Now, something non-bindable
var x = new HumanName().WithGiven("Ewout");
var node = x.ToTypedElement();
Expand Down
19 changes: 9 additions & 10 deletions src/Hl7.Fhir.Validation.Legacy.Shared/Schema/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,21 @@ public OperationOutcome Validate(ITypedElement input, ValidationContext vc)
if (!ModelInfo.IsBindable(input.InstanceType))
return new OperationOutcome(); // success

var bindable = parseBindable(input);
var bindable = input.ParseBindable();

if (bindable is null)
{
// When there is no bindable content, the binding is not applicable to the instance, and we will
// just return a successful result.
return new OperationOutcome();
}

var outcome = VerifyContentRequirements(input, bindable);
if (!outcome.Success) return outcome;

return TaskHelper.Await(() => ValidateCode(input, bindable, vc));
}

private static Element parseBindable(ITypedElement input)
{
var bindable = input.ParseBindable();
if (bindable == null) // should never happen, since we already checked IsBindable
throw Error.NotSupported($"Type '{input.InstanceType}' is bindable, but could not be parsed by ParseBindable().");

return bindable;
}

internal async Task<OperationOutcome> ValidateCode(ITypedElement source, Element bindable, ValidationContext vc)
{
OperationOutcome outcome;
Expand Down
2 changes: 1 addition & 1 deletion src/firely-net-sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.5.1</FirelySdkVersion>
<FirelySdkVersion>5.6.1</FirelySdkVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down