Skip to content

Commit

Permalink
Merge branch 'develop-6.0' into spike/remove-iscopednode
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutkramer authored Feb 25, 2025
2 parents 9c0f146 + 930fb98 commit 2745a35
Show file tree
Hide file tree
Showing 47 changed files with 1,011 additions and 260 deletions.
14 changes: 14 additions & 0 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,13 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Canonical.CanonicalUriForFhirCoreType(System.String)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Date.op_Equality(Hl7.Fhir.Model.Date,Hl7.Fhir.Model.Date)</Target>
Expand Down Expand Up @@ -2563,6 +2570,13 @@
<Right>lib/netstandard2.1/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Canonical.CanonicalUriForFhirCoreType(System.String)</Target>
<Left>lib/netstandard2.1/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.1/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Date.op_Equality(Hl7.Fhir.Model.Date,Hl7.Fhir.Model.Date)</Target>
Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/Introspection/ModelInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void extractBackbonesFromClasses(IEnumerable<Type> classTypes)

#region IModelInfo

public Canonical? CanonicalUriForFhirCoreType(string typeName) => Canonical.CanonicalUriForFhirCoreType(typeName);
public Canonical? CanonicalUriForFhirCoreType(string typeName) => Canonical.ForCoreType(typeName);

public Canonical? CanonicalUriForFhirCoreType(Type type) => GetFhirTypeNameForType(type) is { } name ? CanonicalUriForFhirCoreType(name) : null;

Expand Down
93 changes: 53 additions & 40 deletions src/Hl7.Fhir.Base/Model/Canonical.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of HL7 nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
* Neither the name of HL7 nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

using P=Hl7.Fhir.ElementModel.Types;
using P = Hl7.Fhir.ElementModel.Types;
using Hl7.Fhir.Utility;
using Hl7.Fhir.Rest;
using System;

#nullable enable
Expand All @@ -37,6 +38,11 @@ namespace Hl7.Fhir.Model;

public partial class Canonical
{
/// <summary>
/// The base uri for FHIR core profiles, which is "http://hl7.org/fhir/StructureDefinition/".
/// </summary>
public static readonly Uri FHIR_CORE_PROFILE_BASE_URI = new(ResourceIdentity.CORE_BASE_URL);

/// <summary>
/// Constructs a Canonical based on a given <see cref="Uri"/>.
/// </summary>
Expand All @@ -46,20 +52,19 @@ public Canonical(Uri uri) : this(uri.OriginalString)
// nothing
}

/// <summary>
/// Constructs a canonical from its components.
/// </summary>
public Canonical(string? uri, string? version, string? fragment = null)
{
if ((uri is not null) && uri.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(uri), "cannot contain version/fragment data");

if ((version is not null) && version.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(version), "cannot contain version/fragment data");
/// <summary>
/// Constructs a canonical from its components.
/// </summary>
public Canonical(string? uri, string? version, string? fragment = null)
{
if ((uri is not null) && uri.IndexOfAny(['|', '#']) != -1)
throw Error.Argument(nameof(uri), "cannot contain version/fragment data");

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

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

Value = uri +
(version is not null ? "|" + version : null) +
Expand All @@ -80,7 +85,7 @@ public void Deconstruct(out string? uri, out string? version, out string? fragme
/// Converts a string to a canonical.
/// </summary>
/// <param name="value"></param>
public static implicit operator Canonical(string value) => new(value);
public static implicit operator Canonical(string? value) => new(value);

/// <summary>
/// Converts a canonical to a string.
Expand All @@ -93,9 +98,17 @@ public void Deconstruct(out string? uri, out string? version, out string? fragme
/// </summary>
public static bool IsValidValue(string value) => FhirUri.IsValidValue(value);

public static readonly Uri FHIR_CORE_PROFILE_BASE_URI = new(@"http://hl7.org/fhir/StructureDefinition/");
public static Canonical CanonicalUriForFhirCoreType(string typename) => new(FHIR_CORE_PROFILE_BASE_URI + typename);

/// <summary>
/// Constructs a Canonical to represent a FHIR core type given by name.
/// </summary>
/// <remarks>If the typename is an absolute url, this function assumes the
/// typename is already fully qualified and will return a canonical with that value.
/// </remarks>
public static Canonical ForCoreType(string typename)
{
var typeNameUri = new Canonical(typename);
return typeNameUri.IsAbsolute ? typeNameUri : ResourceIdentity.Core(typename).OriginalString;
}

/// <summary>
/// The version string of the canonical (if present).
Expand Down Expand Up @@ -145,8 +158,8 @@ private static (string? url, string? version, string? fragment) splitCanonical(s
if (url.EndsWith(separator.ToString())) url = url[..^1];
var position = url.LastIndexOf(separator);

return position == -1 ?
(url, null)
return position == -1
? (url, null)
: (url[..position], url[(position + 1)..]);
}
}
Expand All @@ -157,8 +170,8 @@ private static (string? url, string? version, string? fragment) splitCanonical(s
/// <exception cref="InvalidOperationException">The value of this canonical is null,
/// which is not valid for System strings.</exception>
public P.String ToSystemString() => (P.String?)TryConvertToSystemTypeInternal() ??
throw new InvalidOperationException("Value is null.");
throw new InvalidOperationException("Value is null.");

protected internal override P.Any? TryConvertToSystemTypeInternal() =>
Value is not null ? new P.String(Value) : null;
Value is not null ? new P.String(Value) : null;
}
Loading

0 comments on commit 2745a35

Please sign in to comment.