Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Element as primary data type for polymorphic elements [STU3] #1842

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -7431,6 +7431,36 @@ public async T.Task SnapshotSucceedsWithExtendedVariantElementDef()

structureDef.Snapshot.Element.Where(element => element.Path == "Observation.value[x].extension").Should().HaveCount(2, "Elements are in the snapshot");
structureDef.Snapshot.Element.Where(element => element.Path == "Observation.extension").Should().HaveCount(1, "Only the root extension should be there");
}
}

[TestMethod]
public async T.Task TestExtensionValueXCommentShouldBeNull()
{
const string ElementId = "Extension.value[x]";

var zipSource = ZipSource.CreateValidationSource();
var resolver = new MultiResolver(zipSource);
var sd = await resolver.FindStructureDefinitionForCoreTypeAsync(nameof(Extension));

var element = sd.Snapshot.Element.Single(x => x.ElementId == ElementId);
element.Comment.Should().BeNull();

var generator = new SnapshotGenerator(resolver, SnapshotGeneratorSettings.CreateDefault());

generator.PrepareElement += (sender, e) =>
{
if (e.Element.Path == ElementId)
{
Debug.WriteLine($"Element:{ElementId} BaseElement:{e?.BaseElement?.ElementId}");
}
};

// Act
await generator.UpdateAsync(sd);

// Assert
element = sd.Snapshot.Element.Single(x => x.ElementId == ElementId);
element.Comment.Should().BeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Specification.Navigation;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -104,7 +104,16 @@ public static bool InRange(this ElementDefinition defn, int count)
/// <returns>A <see cref="ElementDefinition.TypeRefComponent"/> instance, or <c>null</c>.</returns>
public static ElementDefinition.TypeRefComponent PrimaryType(this ElementDefinition defn)
{
return defn.Type != null && defn.Type.Count > 0 ? defn.Type[0] : null;
if (defn.Type.IsNullOrEmpty())
return null;
else if (defn.Type.Count == 1)
return defn.Type[0];
else //if there are multiple types (value[x]), try to get a common type, otherwise, use Element as the common datatype
{
var distinctTypeCode = defn.CommonTypeCode() ?? FHIRAllTypes.Element.GetLiteral();
return new ElementDefinition.TypeRefComponent() { Code = distinctTypeCode };
}

}

/// <summary>Returns the type profile reference of the primary element type, if it exists, or <c>null</c></summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,7 @@ private async T.Task createNewElement(ElementDefinitionNavigator snap, ElementDe
{
var newElement = (ElementDefinition)baseElement.DeepCopy();
newElement.Path = ElementDefinitionNavigator.ReplacePathRoot(newElement.Path, diff.Path);
newElement.Base = null;

//Remove type specific constraints on polymorph type elements.
if(diff.Current.Type.Count > 1)
{
removeNewTypeConstraint(newElement, typeStructure);
}
newElement.Base = null;

// [WMR 20160915] NEW: Notify subscribers
OnPrepareElement(newElement, typeStructure, baseElement);
Expand Down