diff --git a/common b/common index add5e20f22..2af3bd023d 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit add5e20f223c1f8c4c1e64dd62ac46d9e0e4a323 +Subproject commit 2af3bd023d5204c397ee94e7c24c3da065a70e53 diff --git a/src/Hl7.Fhir.Core.Tests/Model/CodeEnumTests.cs b/src/Hl7.Fhir.Core.Tests/Model/CodeEnumTests.cs index 93174c8eb1..527d382a47 100644 --- a/src/Hl7.Fhir.Core.Tests/Model/CodeEnumTests.cs +++ b/src/Hl7.Fhir.Core.Tests/Model/CodeEnumTests.cs @@ -6,21 +6,15 @@ * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE */ -using System; -using System.Text; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Hl7.Fhir.Model; -using System.Xml.Linq; -using System.ComponentModel.DataAnnotations; -using Hl7.Fhir.Validation; using Hl7.Fhir.Utility; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; namespace Hl7.Fhir.Tests.Model { [TestClass] - public class CodeEnumTests + public class CodeEnumTests { [TestMethod] public void SetValueUpdatesRawValue() @@ -74,6 +68,5 @@ private enum TestEnum { IHaveNoSystem = 4 } - } } diff --git a/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs b/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs index 9f71729e72..0a783bbea7 100644 --- a/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs +++ b/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs @@ -22,7 +22,7 @@ public class ValidationTests [TestMethod] public void TestIdValidation() { - Id id = new Id("az23"); + Id id = new("az23"); DotNetAttributeValidation.Validate(id); DotNetAttributeValidation.Validate(id, true); // recursive checking shouldnt matter @@ -61,7 +61,7 @@ public void ValidatesResourceTag() Assert.IsFalse(DotNetAttributeValidation.TryValidate(p, recurse: true)); } - private void validateErrorOrFail(object instance, bool recurse = false, string membername = null) + private static void validateErrorOrFail(object instance, bool recurse = false, string membername = null) { try { @@ -85,7 +85,7 @@ public void OIDandUUIDUrls() var illUuidUrl = "urn:uuid:ooknietgoed"; var oidWithZero = "urn:oid:1.2.0.3.4"; - FhirUri uri = new FhirUri(oidUrl); + FhirUri uri = new(oidUrl); #if NET40 Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true); #else @@ -120,9 +120,10 @@ public void OIDandUUIDUrls() [TestMethod] public void TestAllowedChoices() { - Patient p = new Patient(); - - p.Deceased = new FhirBoolean(true); + Patient p = new() + { + Deceased = new FhirBoolean(true) + }; DotNetAttributeValidation.Validate(p); // Deceased can either be boolean or dateTime, not FhirUri @@ -134,7 +135,7 @@ public void TestAllowedChoices() [TestMethod] public void TestCardinality() { - OperationOutcome oo = new OperationOutcome(); + OperationOutcome oo = new(); validateErrorOrFail(oo, true); oo.Issue = new List(); @@ -156,8 +157,10 @@ public void TestCardinality() [TestMethod] public void TestEmptyCollectionValidation() { - var p = new Patient(); - p.Identifier = new List(); + var p = new Patient + { + Identifier = new List() + }; p.Identifier.Add(null); validateErrorOrFail(p); @@ -166,12 +169,16 @@ public void TestEmptyCollectionValidation() [TestMethod] public void ContainedResourcesAreValidatedToo() { - Patient p = new Patient(); - // Deceased can either be boolean or dateTime, not FhirUri - p.Deceased = new FhirUri(); + Patient p = new() + { + // Deceased can either be boolean or dateTime, not FhirUri + Deceased = new FhirUri() + }; - var pr = new Patient(); - pr.Contained = new List { p }; + var pr = new Patient + { + Contained = new List { p } + }; validateErrorOrFail(pr, true); DotNetAttributeValidation.Validate(pr); @@ -191,8 +198,10 @@ public void TestContainedConstraints() patn.Contained = null; DotNetAttributeValidation.Validate(pat); - patn.Text = new Narrative(); - patn.Text.Div = "
Narrative in contained resource
"; + patn.Text = new Narrative + { + Div = "
Narrative in contained resource
" + }; // Contained resources should not contain narrative validateErrorOrFail(pat); @@ -213,8 +222,10 @@ public void ValidateResourceWithIncorrectChildElement() DotNetAttributeValidation.Validate(enc, true); // recursive checking shouldnt matter // Hide an incorrect datetime deep into the Encounter - FhirDateTime dt = new FhirDateTime(); - dt.Value = "Ewout Kramer"; // clearly, a wrong datetime + FhirDateTime dt = new() + { + Value = "Ewout Kramer" // clearly, a wrong datetime + }; enc.Period = new Period() { StartElement = dt }; @@ -228,9 +239,10 @@ public void ValidateResourceWithIncorrectChildElement() [TestMethod] // XHtml validation not available in portable library public void TestXhtmlValidation() { - var p = new Patient(); - - p.Text = new Narrative() { Div = "

should be valid

", Status = Narrative.NarrativeStatus.Generated }; + var p = new Patient + { + Text = new Narrative() { Div = "

should be valid

", Status = Narrative.NarrativeStatus.Generated } + }; DotNetAttributeValidation.Validate(p, true); p.Text.Div = "

should not be valid

"; diff --git a/src/Hl7.Fhir.Core/Model/Binary.cs b/src/Hl7.Fhir.Core/Model/Binary.cs deleted file mode 100644 index dbb02a6394..0000000000 --- a/src/Hl7.Fhir.Core/Model/Binary.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using Hl7.Fhir.Validation; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Runtime.Serialization; -using Hl7.Fhir.Introspection; - -/* - Copyright (c) 2011-2012, HL7, Inc - All rights reserved. - - 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 - 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 - 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 - 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 - POSSIBILITY OF SUCH DAMAGE. - - -*/ - -namespace Hl7.Fhir.Model -{ - /// - /// Resource for capturing binary data - /// - public partial class Binary - { - public override IEnumerable Validate(ValidationContext validationContext) - { - var result = new List(); - result.AddRange(base.Validate(validationContext)); - - if (Content == null) - result.Add(DotNetAttributeValidation.BuildResult(validationContext,"Entry must contain (possibly 0-length) data in Content element")); - - if (ContentType == null) - result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry must contain a ContentType")); - - return result; - } - } -} diff --git a/src/Hl7.Fhir.Core/Model/Bundle.cs b/src/Hl7.Fhir.Core/Model/Bundle.cs index 8e6528543d..47a44007e6 100644 --- a/src/Hl7.Fhir.Core/Model/Bundle.cs +++ b/src/Hl7.Fhir.Core/Model/Bundle.cs @@ -30,36 +30,23 @@ POSSIBILITY OF SUCH DAMAGE. using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; -using System.Text; -using Hl7.Fhir.Model; -using System.IO; -using Hl7.Fhir.Validation; -using System.ComponentModel.DataAnnotations; -using Hl7.Fhir.Introspection; -using System.Diagnostics; +#nullable enable namespace Hl7.Fhir.Model -{ - [InvokeIValidatableObject] - public partial class Bundle : Hl7.Fhir.Validation.IValidatableObject +{ + public partial class Bundle { - [System.Diagnostics.DebuggerDisplay(@"\{{DebuggerDisplay,nq}}")] // http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debuggerdisplay-attribute-best-practices.aspx + [DebuggerDisplay(@"\{{DebuggerDisplay,nq}}")] // http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debuggerdisplay-attribute-best-practices.aspx public partial class EntryComponent { [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay - { - get - { - string response = (this.Response != null && !string.IsNullOrEmpty(this.Response.Status)) ? " Result: " + this.Response.Status : null; - if (this.Request != null && this.Request.Method.HasValue) - return String.Format("{0}: {1}", this.Request.Method.Value, this.FullUrl); - - return String.Format("FullUrl = \"{0}\"", this.FullUrl); - } - } + private string DebuggerDisplay => + Request?.Method.HasValue == true + ? string.Format("{0}: {1}", Request.Method.Value, FullUrl) + : string.Format("FullUrl = \"{0}\"", FullUrl); } public const string ATOM_LINKREL_SELF = "self"; @@ -72,82 +59,87 @@ private string DebuggerDisplay public const string ATOM_LINKREL_PREDVERSION = "predecessor-version"; public const string ATOM_LINKREL_ALTERNATE = "alternate"; - public Uri SelfLink + public Uri? SelfLink { get { return getLink(ATOM_LINKREL_SELF); } set { setLink(ATOM_LINKREL_SELF, value); } } - public Uri FirstLink + public Uri? FirstLink { get { return getLink(ATOM_LINKREL_FIRST); } set { setLink(ATOM_LINKREL_FIRST, value); } } - public Uri PreviousLink + public Uri? PreviousLink { get { return getLink(ATOM_LINKREL_PREVIOUS) ?? getLink(ATOM_LINKREL_PREV); } set { setLink(ATOM_LINKREL_PREVIOUS, value); } } - public Uri NextLink + public Uri? NextLink { get { return getLink(ATOM_LINKREL_NEXT); } set { setLink(ATOM_LINKREL_NEXT, value); } } - public Uri LastLink + public Uri? LastLink { get { return getLink(ATOM_LINKREL_LAST); } set { setLink(ATOM_LINKREL_LAST, value); } } - public Uri SearchLink + public Uri? SearchLink { get { return getLink(ATOM_LINKREL_SEARCH); } set { setLink(ATOM_LINKREL_SEARCH, value); } } - public Uri PredecessorVersionLink + public Uri? PredecessorVersionLink { get { return getLink(ATOM_LINKREL_PREDVERSION); } set { setLink(ATOM_LINKREL_PREDVERSION, value); } } - public Uri Alternate + public Uri? Alternate { get { return getLink(ATOM_LINKREL_ALTERNATE); } set { setLink(ATOM_LINKREL_ALTERNATE, value); } } - private Uri getLink(string rel) + private Uri? getLink(string rel) { - if (Link == null) return null; + if (Link is null) return null; var entry = Link.FirstOrDefault(e => rel.Equals(e.Relation, StringComparison.OrdinalIgnoreCase)); - if (entry != null) - return new Uri(entry.Url, UriKind.RelativeOrAbsolute); - else - return null; + return entry != null ? new Uri(entry.Url, UriKind.RelativeOrAbsolute) : null; } - private void setLink(string rel, Uri uri) + private void setLink(string rel, Uri? uri) { + if (uri is null) throw new ArgumentNullException(nameof(uri)); + if (Link == null) Link = new List(); var entry = Link.FirstOrDefault(e => rel.Equals(e.Relation, StringComparison.OrdinalIgnoreCase)); + // Setting the link to null removes the entry + if (uri is null) + { + if (entry is not null) + Link.Remove(entry); + + return; + } + var uriString = uri.IsAbsoluteUri ? uri.AbsoluteUri : uri.OriginalString; if (entry != null) entry.Url = uriString; else Link.Add(new LinkComponent() { Relation = rel, Url = uriString }); } - - public override IEnumerable Validate(ValidationContext validationContext) - { - return base.Validate(validationContext); - } - } + } } + +#nullable restore \ No newline at end of file diff --git a/src/Hl7.Fhir.Core/Model/StructureDefinition.cs b/src/Hl7.Fhir.Core/Model/StructureDefinition.cs index 6f45a67061..9231a871f7 100644 --- a/src/Hl7.Fhir.Core/Model/StructureDefinition.cs +++ b/src/Hl7.Fhir.Core/Model/StructureDefinition.cs @@ -26,17 +26,16 @@ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIME POSSIBILITY OF SUCH DAMAGE. */ +using Hl7.Fhir.Introspection; using System.Collections.Generic; using System.ComponentModel; -using Hl7.Fhir.Introspection; -using Hl7.Fhir.Validation; -using System.Linq; using System.Diagnostics; +using System.Linq; namespace Hl7.Fhir.Model { // [WMR 20160803] Add common base interfaces - public interface IElementList : IModifierExtendable, INotifyPropertyChanged, IValidatableObject, IDeepCopyable, IDeepComparable + public interface IElementList : IModifierExtendable, INotifyPropertyChanged, IDeepCopyable, IDeepComparable { List Element { get; set; } } @@ -47,8 +46,8 @@ public partial class StructureDefinition { [DebuggerBrowsable(DebuggerBrowsableState.Never)] private Rest.ResourceIdentity DebuggerDisplay => this.ResourceIdentity(); - - public partial class SnapshotComponent : IElementList {} + + public partial class SnapshotComponent : IElementList { } public partial class DifferentialComponent : IElementList { } diff --git a/src/Hl7.Fhir.Specification/Hl7.Fhir.Specification.csproj b/src/Hl7.Fhir.Specification/Hl7.Fhir.Specification.csproj index 3f14aca9fc..c4a92a8eda 100644 --- a/src/Hl7.Fhir.Specification/Hl7.Fhir.Specification.csproj +++ b/src/Hl7.Fhir.Specification/Hl7.Fhir.Specification.csproj @@ -24,7 +24,12 @@ + + + + +