Skip to content

Commit 470bd82

Browse files
authored
Merge pull request #3007 from FirelyTeam/6.0/2931-remove-isystemandcode
2931 Remove ISystemAndCode
2 parents d03a6b7 + 8ba7dfe commit 470bd82

File tree

24 files changed

+303
-718
lines changed

24 files changed

+303
-718
lines changed

src/Hl7.Fhir.Base/CompatibilitySuppressions.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
3030
<IsBaselineSuppression>true</IsBaselineSuppression>
3131
</Suppression>
32+
<Suppression>
33+
<DiagnosticId>CP0001</DiagnosticId>
34+
<Target>T:Hl7.Fhir.Introspection.BindableAttribute</Target>
35+
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
36+
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
37+
<IsBaselineSuppression>true</IsBaselineSuppression>
38+
</Suppression>
3239
<Suppression>
3340
<DiagnosticId>CP0001</DiagnosticId>
3441
<Target>T:Hl7.Fhir.Model.DeepComparable</Target>
@@ -43,6 +50,13 @@
4350
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
4451
<IsBaselineSuppression>true</IsBaselineSuppression>
4552
</Suppression>
53+
<Suppression>
54+
<DiagnosticId>CP0001</DiagnosticId>
55+
<Target>T:Hl7.Fhir.Model.ISystemAndCode</Target>
56+
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
57+
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
58+
<IsBaselineSuppression>true</IsBaselineSuppression>
59+
</Suppression>
4660
<Suppression>
4761
<DiagnosticId>CP0001</DiagnosticId>
4862
<Target>T:Hl7.Fhir.Serialization.BaseFhirSerializer</Target>

src/Hl7.Fhir.Base/Introspection/BindableAttribute.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Hl7.Fhir.Base/Introspection/ClassMapping.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static bool TryCreate(Type type, [NotNullWhen(true)]out ClassMapping? res
8686
}
8787

8888
// Now continue with the normal algorithm, types adorned with the [FhirTypeAttribute]
89-
if (GetAttribute<FhirTypeAttribute>(type.GetTypeInfo(), release) is not { } typeAttribute) return false;
89+
if (GetAttribute<FhirTypeAttribute>(type, release) is not { } typeAttribute) return false;
9090

9191
result = new ClassMapping(collectTypeName(typeAttribute, type), type, release)
9292
{
@@ -96,9 +96,9 @@ public static bool TryCreate(Type type, [NotNullWhen(true)]out ClassMapping? res
9696
type.GenericTypeArguments[0] : null,
9797
IsFhirPrimitive = typeof(PrimitiveType).IsAssignableFrom(type),
9898
IsBackboneType = typeAttribute.IsBackboneType,
99-
IsBindable = GetAttribute<BindableAttribute>(type.GetTypeInfo(), release)?.IsBindable ?? false,
99+
IsBindable = typeof(ICoded).IsAssignableFrom(type),
100100
Canonical = typeAttribute.Canonical,
101-
ValidationAttributes = GetAttributes<ValidationAttribute>(type.GetTypeInfo(), release).ToArray(),
101+
ValidationAttributes = GetAttributes<ValidationAttribute>(type, release).ToArray(),
102102
};
103103

104104
return true;

src/Hl7.Fhir.Base/Model/Code.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,22 @@ POSSIBILITY OF SUCH DAMAGE.
3030

3131
#nullable enable
3232

33-
using Hl7.Fhir.Introspection;
33+
using System.Collections.Generic;
3434
using System.Text.RegularExpressions;
3535

36-
namespace Hl7.Fhir.Model
36+
namespace Hl7.Fhir.Model;
37+
38+
public partial class Code : ICoded
3739
{
38-
[Bindable(true)]
39-
public partial class Code
40-
{
41-
/// <summary>
42-
/// Creates a <see cref="ElementModel.Types.Code"/> from an instance of a <see cref="Code"/>.
43-
/// </summary>
44-
public virtual ElementModel.Types.Code ToSystemCode() => new(system: null, code: Value, display: null, version: null);
40+
/// <summary>
41+
/// Creates a <see cref="ElementModel.Types.Code"/> from an instance of a <see cref="Code"/>.
42+
/// </summary>
43+
public virtual ElementModel.Types.Code ToSystemCode() => new(system: null, code: Value, display: null, version: null);
4544

46-
/// <summary>
47-
/// Checks whether the given literal is correctly formatted.
48-
/// </summary>
49-
public static bool IsValidValue(string value) => Regex.IsMatch(value, "^" + PATTERN + "$", RegexOptions.Singleline);
50-
}
51-
}
45+
/// <summary>
46+
/// Checks whether the given literal is correctly formatted.
47+
/// </summary>
48+
public static bool IsValidValue(string value) => Regex.IsMatch(value, "^" + PATTERN + "$", RegexOptions.Singleline);
5249

53-
#nullable restore
50+
public virtual IEnumerable<Coding> ToCodings() => [new(system: null, code: Value)];
51+
}

src/Hl7.Fhir.Base/Model/CodeOfT.cs

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ POSSIBILITY OF SUCH DAMAGE.
2828
2929
*/
3030

31+
#nullable enable
3132

3233
using Hl7.Fhir.Introspection;
3334
using Hl7.Fhir.Specification;
@@ -40,81 +41,76 @@ POSSIBILITY OF SUCH DAMAGE.
4041
using COVE = Hl7.Fhir.Validation.CodedValidationException;
4142
using S = Hl7.Fhir.ElementModel.Types;
4243

43-
namespace Hl7.Fhir.Model
44+
namespace Hl7.Fhir.Model;
45+
46+
/// <summary>
47+
/// A <see cref="Code"/> that has a limited set of values and which <see cref="Code.Value"/> can therefore
48+
/// be represented as an enumerated type.
49+
/// </summary>
50+
[Serializable]
51+
[FhirType("codeOfT")]
52+
[DataContract]
53+
[System.Diagnostics.DebuggerDisplay(@"\{Value={Value}}")]
54+
public class Code<T> : Code, INullableValue<T> where T : struct, Enum
4455
{
45-
/// <summary>
46-
/// A <see cref="Code"/> that has a limited set of values and which <see cref="Code.Value"/> can therefore
47-
/// be represented as an enumerated type.
48-
/// </summary>
49-
[Serializable]
50-
[FhirType("codeOfT")]
51-
[DataContract]
52-
[System.Diagnostics.DebuggerDisplay(@"\{Value={Value}}")]
53-
public class Code<T> : Code, INullableValue<T>, ISystemAndCode where T : struct, Enum
56+
static Code()
5457
{
55-
static Code()
56-
{
57-
if (!typeof(T).IsEnum())
58-
throw new ArgumentException("T must be an enumerated type");
59-
}
58+
if (!typeof(T).IsEnum())
59+
throw new ArgumentException("T must be an enumerated type");
60+
}
6061

61-
public override string TypeName => "code";
62+
public override string TypeName => "code";
6263

63-
public Code() : this(null) { }
64+
public Code() : this(null) { }
6465

65-
public Code(T? value)
66-
{
67-
Value = value;
68-
}
66+
public Code(T? value)
67+
{
68+
Value = value;
69+
}
6970

70-
// Primitive value of element
71-
[FhirElement("value", IsPrimitiveValue = true, XmlSerialization = XmlRepresentation.XmlAttr, InSummary = true, Order = 30)]
72-
[DataMember]
73-
new public T? Value
71+
// Primitive value of element
72+
[FhirElement("value", IsPrimitiveValue = true, XmlSerialization = XmlRepresentation.XmlAttr, InSummary = true, Order = 30)]
73+
[DataMember]
74+
new public T? Value
75+
{
76+
get => TryParseObjectValue(out var value)
77+
? value
78+
: throw new InvalidCastException($"Value '{ObjectValue}' cannot be cast to a member of enumeration {typeof(T).Name}.");
79+
set
7480
{
75-
get => TryParseObjectValue(out var value)
76-
? value
77-
: throw new InvalidCastException($"Value '{ObjectValue}' cannot be cast to a member of enumeration {typeof(T).Name}.");
78-
set
79-
{
80-
ObjectValue = value?.GetLiteral();
81-
OnPropertyChanged("Value");
82-
}
81+
ObjectValue = value?.GetLiteral();
82+
OnPropertyChanged("Value");
8383
}
84+
}
85+
86+
internal bool TryParseObjectValue(out T? value)
87+
{
88+
value = default;
8489

85-
internal bool TryParseObjectValue(out T? value)
90+
if (ObjectValue is string s && EnumUtility.ParseLiteral<T>(s) is { } parsed)
8691
{
87-
value = default;
88-
89-
if (ObjectValue is string s && EnumUtility.ParseLiteral<T>(s) is { } parsed)
90-
{
91-
value = parsed;
92-
return true;
93-
}
94-
else return ObjectValue is null;
92+
value = parsed;
93+
return true;
9594
}
95+
else return ObjectValue is null;
96+
}
9697

97-
string ISystemAndCode.System => Value?.GetSystem();
98+
public override IEnumerable<Coding> ToCodings() => [new(Value?.GetSystem(), Value?.GetLiteral())];
9899

99-
string ISystemAndCode.Code => Value?.GetLiteral();
100+
public override S.Code ToSystemCode() =>
101+
new(Value?.GetSystem(),
102+
Value?.GetLiteral() ?? throw new InvalidOperationException("Code must have a value in order to be useable to construct a System.Code."),
103+
display: null,
104+
version: null);
100105

101-
public override S.Code ToSystemCode() =>
102-
new(Value?.GetSystem(),
103-
Value?.GetLiteral() ?? throw new InvalidOperationException("Code must have a value in order to be useable to construct a System.Code."),
104-
display: null,
105-
version: null);
106+
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
107+
{
108+
var baseResults = base.Validate(validationContext);
106109

107-
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
108-
{
109-
var baseResults = base.Validate(validationContext);
110-
111-
if (TryParseObjectValue(out _))
112-
return baseResults;
113-
else
114-
{
115-
var result = COVE.INVALID_CODED_VALUE(validationContext, ObjectValue, EnumUtility.GetName<T>()).AsResult(validationContext);
116-
return baseResults.Append(result);
117-
}
118-
}
110+
if (TryParseObjectValue(out _))
111+
return baseResults;
112+
113+
var result = COVE.INVALID_CODED_VALUE(validationContext, ObjectValue, EnumUtility.GetName<T>()).AsResult(validationContext);
114+
return baseResults.Append(result);
119115
}
120116
}

src/Hl7.Fhir.Base/Model/CodeableConcept.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ POSSIBILITY OF SUCH DAMAGE.
2828
2929
*/
3030

31-
using Hl7.Fhir.Introspection;
31+
#nullable enable
32+
33+
using System.Collections.Generic;
3234
using System.Linq;
3335
using S = Hl7.Fhir.ElementModel.Types;
3436

37+
namespace Hl7.Fhir.Model;
3538

36-
namespace Hl7.Fhir.Model
39+
public partial class CodeableConcept : ICoded
3740
{
38-
[Bindable(true)]
39-
public partial class CodeableConcept
41+
public S.Concept ToSystemConcept()
4042
{
41-
public S.Concept ToSystemConcept()
42-
{
43-
var codes = Coding.Select(c => c.ToSystemCode());
44-
return new S.Concept(codes, display: Text);
45-
}
43+
var codes = Coding.Select(c => c.ToSystemCode());
44+
return new S.Concept(codes, display: Text);
4645
}
47-
}
46+
47+
public IEnumerable<Coding> ToCodings() => Coding;
48+
}

src/Hl7.Fhir.Base/Model/CodeableReference.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@
77
*/
88

99
#nullable enable
10-
using Hl7.Fhir.Introspection;
1110

12-
namespace Hl7.Fhir.Model
11+
using System.Collections.Generic;
12+
13+
namespace Hl7.Fhir.Model;
14+
15+
public partial class CodeableReference : ICoded
1316
{
14-
[Bindable(true)]
15-
public partial class CodeableReference
17+
public CodeableReference()
1618
{
17-
public CodeableReference()
18-
{
19-
// Nothing
20-
}
19+
// Nothing
20+
}
2121

22-
public CodeableReference(CodeableConcept concept)
23-
{
24-
Concept = concept;
25-
}
22+
public CodeableReference(CodeableConcept concept)
23+
{
24+
Concept = concept;
25+
}
2626

27-
public CodeableReference(ResourceReference reference)
28-
{
29-
Reference = reference;
30-
}
27+
public CodeableReference(ResourceReference reference)
28+
{
29+
Reference = reference;
3130
}
31+
32+
public IEnumerable<Coding> ToCodings() => Concept?.ToCodings() ?? [];
3233
}

0 commit comments

Comments
 (0)