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

keep snapshot when differential is missing #2754

Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ private static IAsyncResourceResolver verifySource(IAsyncResourceResolver resolv
/// <param name="structure">A <see cref="StructureDefinition"/> instance.</param>
public async T.Task UpdateAsync(StructureDefinition structure)
{
structure.Snapshot = new StructureDefinition.SnapshotComponent()
{
Element = await GenerateAsync(structure).ConfigureAwait(false)
};
structure.Snapshot.SetCreatedBySnapshotGenerator();
var result = await GenerateAsync(structure).ConfigureAwait(false);

if (result == null && structure.Snapshot?.Element != null) return;

structure.Snapshot = new StructureDefinition.SnapshotComponent { Element = result };
structure.Snapshot.SetCreatedBySnapshotGenerator();

// [WMR 20170209] TODO: also merge global StructureDefinition.Mapping components
// structure.Mappings = ElementDefnMerger.Merge(...)
// [WMR 20170209] TODO: also merge global StructureDefinition.Mapping components
// structure.Mappings = ElementDefnMerger.Merge(...)
}

/// <inheritdoc cref="UpdateAsync(StructureDefinition)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,42 @@ public async T.Task FindComplexTestExtensions()
}
};

private static StructureDefinition LogicalModelWithoutDiff => new()
{
Name = "MyLogicalModel",
Url = "http://example.org/fhir/StructureDefinition/MyLogicalModel",
Type = "http://foo.org/bar",
Derivation = StructureDefinition.TypeDerivationRule.Constraint,
BaseDefinition = "http://hl7.org/fhir/StructureDefinition/Base",
Kind = StructureDefinition.StructureDefinitionKind.Logical,
Snapshot = new()
{
Element = new()
{
new()
{
ElementId = "logicalmodel",
Path = "logicalmodel",
Short = "root"

},
new()
{
ElementId = "logicalmodel.Identifier",
Path = "logicalmodel.Identifier",
Short = "Identifier",
Min = 1,
Max = "*",
Type = new()
{
new() {Code = "Identifier"}
}
},
}
}

};

[Conditional("DEBUG")]
private void dumpElements(IEnumerable<ElementDefinition> elements, string header = null) => dumpElements(elements.ToList(), header);

Expand Down Expand Up @@ -3295,6 +3331,23 @@ public async T.Task TestMissingDifferential()
expanded.Snapshot.Element.Dump();
}

[TestMethod]
public async T.Task TestMissingDifferentialLogicalModel()
{
// Create a profile without a differential
var profile = LogicalModelWithoutDiff;

var resolver = new InMemoryResourceResolver(profile);
var multiResolver = new MultiResolver(_testResolver, resolver);
_generator = new SnapshotGenerator(multiResolver, _settings);

var (_, expanded) = await generateSnapshotAndCompare(profile);
Assert.IsNotNull(expanded);
Assert.IsTrue(expanded.HasSnapshot);

expanded.Snapshot.Element.Dump();
}

[TestMethod]
public async T.Task TestUnresolvedBaseProfile()
{
Expand Down