Skip to content

Commit

Permalink
Merge pull request #1419 from FirelyTeam/bugfix/618-simple-quantity-s…
Browse files Browse the repository at this point in the history
…napshot

fix: snapshot generator: ignore invalid sliceName error on SimpleQuantity root
  • Loading branch information
marcovisserFurore authored Jul 13, 2020
2 parents ee9793f + fa1fc6e commit 48bf76f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
57 changes: 31 additions & 26 deletions src/Hl7.Fhir.Specification.Tests/Snapshot/SnapshotGeneratorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2018, Firely ([email protected]) and contributors
* See the file CONTRIBUTORS for details.
*
Expand Down Expand Up @@ -3194,12 +3194,9 @@ public void TestInvalidChoiceTypeConstraints()
Assert.AreEqual(nav.Current.Type.FirstOrDefault().Code, FHIRAllTypes.Integer.GetLiteral());

Assert.IsNotNull(outcome);
// [WMR 20170810] Fixed, now also expecting issue about invalid slice name on SimpleQuantity root element
//Assert.AreEqual(1, outcome.Issue.Count);
// assertIssue(outcome.Issue[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_CHOICE_CONSTRAINT);
Assert.AreEqual(2, outcome.Issue.Count);
assertIssue(outcome.Issue[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_SLICENAME_ON_ROOT);
assertIssue(outcome.Issue[1], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_CHOICE_CONSTRAINT);

Assert.AreEqual(1, outcome.Issue.Count);
assertIssue(outcome.Issue[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_CHOICE_CONSTRAINT);
}

static StructureDefinition ClosedExtensionSliceObservationProfile => new StructureDefinition()
Expand Down Expand Up @@ -4438,7 +4435,7 @@ public void TestPatientNonTypeSlice()

// [WMR 20170321] NEW
[TestMethod]
public void TestSimpleQuantityProfile()
public void TestSimpleQuantityObservationProfile()
{
var profile = ObservationSimpleQuantityProfile;

Expand All @@ -4453,16 +4450,14 @@ public void TestSimpleQuantityProfile()
dumpOutcome(_generator.Outcome);

var issues = _generator.Outcome?.Issue;
Assert.AreEqual(1, issues.Count);
assertIssue(issues[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_SLICENAME_ON_ROOT);
Assert.IsNull(issues);

// [WMR 20180115] NEW - Use alternative (iterative) approach for full expansion
issues = new List<OperationOutcome.IssueComponent>();
var elems = expanded.Snapshot.Element;
elems = expanded.Snapshot.Element = fullyExpand(elems, issues).ToList();
// Generator should report same issue as during regular snapshot expansion
Assert.AreEqual(1, issues.Count);
assertIssue(issues[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_SLICENAME_ON_ROOT);
Assert.AreEqual(0, issues.Count);

// Ensure that renamed diff elements override base elements with original names
var nav = ElementDefinitionNavigator.ForSnapshot(expanded);
Expand All @@ -4478,13 +4473,25 @@ public void TestSimpleQuantityProfile()
Debug.Print($"{nav.Path} : {type.Code} - '{type.Profile}'");
}

// [WMR 20170406] NEW
// Issue reported by Vadim
// Complex extension: structure.cdstools-typedstage
// Referencing Profile: structure.cdstools-basecancer
// Profile defines constraints on child elements of the complex extension
// Snapshot generator adds slicing component to Condition.extension.extension.extension:type - WRONG!
[TestMethod] // test data needs to be converted from dstu2 -> stu3
//Ignore invalid slice name error on the root of SimpleQuantity.
[TestMethod]
public void TestSimpleQuantity()
{
var resource = _testResolver.FindStructureDefinition(ModelInfo.CanonicalUriForFhirCoreType(FHIRAllTypes.SimpleQuantity));
_generator = new SnapshotGenerator(_testResolver);
var snapshot = _generator.Generate(resource);
Assert.IsNotNull(snapshot);
Assert.IsNull(snapshot.GetRootElement().SliceName);
Assert.IsNull(_generator.Outcome);
}

// [WMR 20170406] NEW
// Issue reported by Vadim
// Complex extension: structure.cdstools-typedstage
// Referencing Profile: structure.cdstools-basecancer
// Profile defines constraints on child elements of the complex extension
// Snapshot generator adds slicing component to Condition.extension.extension.extension:type - WRONG!
[TestMethod] // test data needs to be converted from dstu2 -> stu3
public void TestProfileConstraintsOnComplexExtensionChildren()
{
var profile = _testResolver.FindStructureDefinition("https://example.org/fhir/StructureDefinition/cds-basecancer");
Expand Down Expand Up @@ -5688,10 +5695,11 @@ public void TestSimpleQuantitySlice()
dumpElements(elems);
// dumpBaseElems(elems);

var issues = _generator.Outcome?.Issue.Where(i => i.Details.Coding.FirstOrDefault().Code == SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_PROFILE_TYPE.Code.ToString());

// Verify there is NO warning about invalid element type constraint
Assert.IsFalse(_generator.Outcome.Issue.Any(
i => i.Details.Coding.FirstOrDefault().Code == SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_PROFILE_TYPE.Code.ToString())
);
Assert.IsTrue(issues == null || !issues.Any());

}

// [WMR 20170925] BUG: Stefan Lang - Forge displays both valueString and value[x]
Expand Down Expand Up @@ -6863,11 +6871,8 @@ public void TestObservationWithDisplayCodes()
Assert.IsNotNull(expanded);
Assert.IsTrue(expanded.HasSnapshot);

// Expecting single issue about invalid slice name on SimpleQuantity root element
var outcome = generator.Outcome;
//Assert.IsNull(outcome);
Assert.AreEqual(1, outcome.Issue.Count);
assertIssue(outcome.Issue[0], SnapshotGenerator.PROFILE_ELEMENTDEF_INVALID_SLICENAME_ON_ROOT);
Assert.IsNull(outcome);

var nav = ElementDefinitionNavigator.ForSnapshot(expanded);
Assert.IsNotNull(nav);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,22 @@ public async System.Threading.Tasks.Task RunValueSetExpanderMultiThreaded()
Assert.Equal(nrOfParrallelTasks, successes);
}

[Fact]
public void testSimpleQuantityForInvalidSliceOnRoot()
{
var sq = new SimpleQuantity
{
Code = "m",
Value = 1,
System = "http://unitsofmeasure.org"
};

var sqSd = _source.FindStructureDefinitionForCoreType(FHIRAllTypes.SimpleQuantity);
sqSd.Snapshot = null;
var result = _validator.Validate(sq, sqSd);
Assert.True(result.Success);
}

/// <summary>
/// This test should show that the rng-2 constraint is totally ignored (it's
/// incorrect in DSTU2 and STU3), but others are not.
Expand Down Expand Up @@ -1174,6 +1190,8 @@ private static void assertElementConstraints(List<ElementDefinition> patientElem
}
}



private class ClearSnapshotResolver : IResourceResolver
{
private IResourceResolver _resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ void fixInvalidSliceNameOnRootElement(ElementDefinition elem, StructureDefinitio
Debug.Assert(elem.IsRootElement());
if (!string.IsNullOrEmpty(elem.SliceName))
{
addIssueInvalidSliceNameOnRootElement(elem, sd);
if (sd.Url != ModelInfo.CanonicalUriForFhirCoreType(FHIRAllTypes.SimpleQuantity))
{
addIssueInvalidSliceNameOnRootElement(elem, sd);
}
elem.SliceName = null;
}
}
Expand Down

0 comments on commit 48bf76f

Please sign in to comment.