Skip to content
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
7 changes: 3 additions & 4 deletions src/Hl7.Fhir.Base/Model/Canonical.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ public Canonical(Uri uri) : this(uri?.OriginalString)
/// </summary>
public Canonical(string? uri, string? version, string? fragment = null)
{
if (uri == null) throw Error.ArgumentNull(nameof(uri));
if (uri.IndexOfAny(['|', '#']) != -1)
if ((uri is not null) && uri.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(uri), "cannot contain version/fragment data");

if (version != null && version.IndexOfAny(['|', '#']) != -1)
if ((version is not null) && version.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(version), "cannot contain version/fragment data");

if (fragment != null && fragment.IndexOfAny(['|', '#']) != -1)
if ((fragment is not null) && fragment.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(fragment), "already contains version/fragment data");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ public ValidateCodeParameters WithValueSet(string? url, string? context = null,
return this;
}

/// <summary>
/// Takes a canonical and splits it into the correct "url", and "valueSetVersion" parameters.
/// </summary>
/// <param name="canonical">Canonical to be split up</param>
/// <returns></returns>
public ValidateCodeParameters WithValueSet(Canonical canonical)
{
var (uri, version, fragment) = canonical;
Url = new FhirUri(new Canonical(uri, null, fragment));
if (!string.IsNullOrWhiteSpace(version)) ValueSetVersion = new FhirString(version);
return this;
}

public ValidateCodeParameters WithCode(string? code = null, string? system = null,
string? systemVersion = null, string? display = null, string? displayLanguage = null,
string? context = null, bool? inferSystem = null)
Expand Down
10 changes: 10 additions & 0 deletions src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ public void TestValidateCodeParametersValueSet()
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");


parameters = new ValidateCodeParameters()
.WithValueSet(new Canonical("http://foo.bar/ValueSet/foo|1.0.4#fragment"));
parameters.Url.Value.Should().Be("http://foo.bar/ValueSet/foo#fragment");
parameters.ValueSetVersion.Value.Should().Be("1.0.4");

parameters = new ValidateCodeParameters()
.WithValueSet(new Canonical("#fragment"));
parameters.Url.Value.Should().Be("#fragment");
}


Expand Down