Skip to content

Commit aada9f1

Browse files
committed
excluding a code doesn't exclude it's children.
1 parent 7738a9e commit aada9f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Hl7.Fhir.Shims.Base/Specification/Terminology/ValueSetExpander.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,12 @@ public static ValueSet.ContainsComponent Add(this List<ValueSet.ContainsComponen
322322

323323
public static void Remove(this List<ValueSet.ContainsComponent> dest, string system, string code)
324324
{
325+
var children = dest.Where(c => c.System == system && c.Code == code).SelectMany(c => c.Contains).ToList();
325326
dest.RemoveAll(c => c.System == system && c.Code == code);
326327

328+
//add children back to the list, they do not necessarily need to be removed when the parent is removed.
329+
dest.AddRange(children);
330+
327331
// Look for this code in children too
328332
foreach (var component in dest)
329333
{
@@ -334,9 +338,15 @@ public static void Remove(this List<ValueSet.ContainsComponent> dest, string sys
334338

335339
public static void Remove(this List<ValueSet.ContainsComponent> dest, List<ValueSet.ContainsComponent> source)
336340
{
337-
//TODO: Pretty unclear what to do with child concepts in the source - they all need to be removed from dest?
338341
foreach (var sourceConcept in source)
342+
{
339343
dest.Remove(sourceConcept.System, sourceConcept.Code);
344+
345+
//check if there are children that need to be removed too.
346+
if (sourceConcept.Contains.Any())
347+
dest.Remove(sourceConcept.Contains);
348+
}
349+
340350
}
341351

342352
internal static ValueSet.ContainsComponent ToContainsComponent(this CodeSystem.ConceptDefinitionComponent source, CodeSystem system, ValueSetExpanderSettings settings)

0 commit comments

Comments
 (0)