From aada9f10b7917449c3e1acbd3b21df0f18e85aff Mon Sep 17 00:00:00 2001 From: mmsmits Date: Wed, 24 Jul 2024 14:43:05 +0200 Subject: [PATCH] excluding a code doesn't exclude it's children. --- .../Specification/Terminology/ValueSetExpander.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Hl7.Fhir.Shims.Base/Specification/Terminology/ValueSetExpander.cs b/src/Hl7.Fhir.Shims.Base/Specification/Terminology/ValueSetExpander.cs index 132feca381..981eb1a01e 100644 --- a/src/Hl7.Fhir.Shims.Base/Specification/Terminology/ValueSetExpander.cs +++ b/src/Hl7.Fhir.Shims.Base/Specification/Terminology/ValueSetExpander.cs @@ -322,8 +322,12 @@ public static ValueSet.ContainsComponent Add(this List dest, string system, string code) { + var children = dest.Where(c => c.System == system && c.Code == code).SelectMany(c => c.Contains).ToList(); dest.RemoveAll(c => c.System == system && c.Code == code); + //add children back to the list, they do not necessarily need to be removed when the parent is removed. + dest.AddRange(children); + // Look for this code in children too foreach (var component in dest) { @@ -334,9 +338,15 @@ public static void Remove(this List dest, string sys public static void Remove(this List dest, List source) { - //TODO: Pretty unclear what to do with child concepts in the source - they all need to be removed from dest? foreach (var sourceConcept in source) + { dest.Remove(sourceConcept.System, sourceConcept.Code); + + //check if there are children that need to be removed too. + if (sourceConcept.Contains.Any()) + dest.Remove(sourceConcept.Contains); + } + } internal static ValueSet.ContainsComponent ToContainsComponent(this CodeSystem.ConceptDefinitionComponent source, CodeSystem system, ValueSetExpanderSettings settings)