diff --git a/src/Hl7.Fhir.Base/Specification/Terminology/ValidateCodeParameters.cs b/src/Hl7.Fhir.Base/Specification/Terminology/ValidateCodeParameters.cs index 34a59ade03..6534a4d727 100644 --- a/src/Hl7.Fhir.Base/Specification/Terminology/ValidateCodeParameters.cs +++ b/src/Hl7.Fhir.Base/Specification/Terminology/ValidateCodeParameters.cs @@ -164,9 +164,9 @@ public Parameters Build() { var result = new Parameters(); - if (Url is { }) result.Add(_urlAttribute, Url); //Either Url, ValueSet or Context is allowed. So try Url first. - if (ValueSet is { } && Url is not { }) result.Add(_valueSetAttribute, ValueSet); - if (Context is { } && ValueSet is not { } && Url is not { }) result.Add(_contextAttribute, Context); //And then context as last resort. + if (Url is { }) result.Add(_urlAttribute, Url); + if (ValueSet is { }) result.Add(_valueSetAttribute, ValueSet); + if (Context is { }) result.Add(_contextAttribute, Context); if (ValueSetVersion is { }) result.Add(_valueSetVersionAttribute, ValueSetVersion); if (Code is { }) result.Add(_codeAttribute, Code); if (System is { }) result.Add(_systemAttribute, System); @@ -176,7 +176,7 @@ public Parameters Build() if (CodeableConcept is { }) result.Add(_codeableConceptAttribute, CodeableConcept); if (Date is { }) result.Add(_dateAttribute, Date); if (Abstract is { }) result.Add(_abstractAttribute, Abstract); - if (DisplayLanguage is { }) result.Add(_displayAttribute, DisplayLanguage); + if (DisplayLanguage is { }) result.Add(_displayLanguageAttribute, DisplayLanguage); if (InferSystem is { }) result.Add(_inferSystemAttribute, InferSystem); return result; } diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs index f6d41e5958..327ceefc19 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs @@ -757,6 +757,52 @@ void expandAction(string url) } } + [Fact] + public void TestValidateCodeParametersCode() + { + var parameters = new ValidateCodeParameters() + .WithCode("bar", "http://foo.com", "1.0.4", "barDisplay", "nl-NL", "Patient.gender", true); + + parameters.Code.Value.Should().Be("bar"); + parameters.System.Value.Should().Be("http://foo.com"); + parameters.SystemVersion.Value.Should().Be("1.0.4"); + parameters.DisplayLanguage.Value.Should().Be("nl-NL"); + parameters.Display.Value.Should().Be("barDisplay"); + parameters.Context.Value.Should().Be("Patient.gender"); + parameters.InferSystem.Value.Should().Be(true); + + var paramResource = parameters.Build(); + + paramResource.Parameter.Should().HaveCount(7); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "code" && ((Code)p.Value).Value == "bar"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "system" && ((FhirUri)p.Value).Value == "http://foo.com"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "systemVersion" && ((FhirString)p.Value).Value == "1.0.4"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "display" && ((FhirString)p.Value).Value == "barDisplay"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "displayLanguage" && ((Code)p.Value).Value == "nl-NL"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "context" && ((FhirUri)p.Value).Value == "Patient.gender"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "inferSystem" && ((FhirBoolean)p.Value).Value == true); + } + + [Fact] + public void TestValidateCodeParametersValueSet() + { + var parameters = new ValidateCodeParameters() + .WithValueSet("http://foo.bar", "Patient.gender", new ValueSet(), "1.0.4"); + + parameters.Url.Value.Should().Be("http://foo.bar"); + parameters.Context.Value.Should().Be("Patient.gender"); + parameters.ValueSet.Should().NotBeNull(); + parameters.ValueSetVersion.Value.Should().Be("1.0.4"); + + var paramResource = parameters.Build(); + + paramResource.Parameter.Should().HaveCount(4); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "url" && ((FhirUri)p.Value).Value == "http://foo.bar"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "context" && ((FhirUri)p.Value).Value == "Patient.gender"); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "valueSet" && ((ValueSet)p.Resource) != null); + paramResource.Parameter.Should().ContainSingle(p => p.Name == "valueSetVersion" && ((FhirString)p.Value).Value == "1.0.4"); + } + #region helper functions private static Tasks.Task validateCodedValue(ITerminologyService service, string url = null, string context = null, string code = null,