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

Fix isNotA filter code in ValueSet expander #2847

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

mmsmits
Copy link
Member

@mmsmits mmsmits commented Sep 2, 2024

fixes #2801

@mmsmits mmsmits requested a review from Kasdejong September 2, 2024 12:40
@mmsmits mmsmits enabled auto-merge September 2, 2024 12:40
@@ -67,27 +67,23 @@ internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string co

private static ICollection<CSDC> removeCodeByPredicate(this ICollection<CSDC> concepts, Predicate<CSDC> predicate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we have side effects: we remove items, but we return the collection because we want to keep the fluent syntax. We should really be making this pure, that way the signature makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are suggesting to make this a void you mean?

@@ -67,27 +67,23 @@ internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string co

private static ICollection<CSDC> removeCodeByPredicate(this ICollection<CSDC> concepts, Predicate<CSDC> predicate)
{
foreach (var concept in concepts)
var itemsToBeRemoved = concepts.Where(c => predicate(c)).ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We iterate 3 times now. We can get away with only doing this once, by just putting all the calls in a foreach loop, or better yet: a select (if we are going pure)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to do this in a single forloop (or linq statement), but I couldn't figure it out without duplicating collections, and making it a mess.
You have a suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case duplicating subsets of collections is a fact of life I think. The most optimized version is a big chain call, since the compiler can chain the methods together into a single loop. I will suggest a commit (once I find out how to)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it seems like i'm not able to suggest it the way I wanted to. I would like to suggest something along the lines of:

internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string code)
{
    return concepts.getNonMatchingCodes(c => c.Code == code);
}

private static List<CSDC> getNonMatchingCodes(this ICollection<CSDC> concepts, Predicate<CSDC> predicate)
{
    var filtered = concepts.Where(c => !predicate(c)).ToList();
    
    foreach (var concept in filtered.Where(concept => concept.Concept?.Count is > 0))
    {
        concept.Concept = concept.Concept.getNonMatchingCodes(predicate).ToList();
    }
    
    return filtered;
}

@mmsmits mmsmits disabled auto-merge September 3, 2024 14:28
@mmsmits mmsmits merged commit 70db02e into develop Sep 3, 2024
16 checks passed
@mmsmits mmsmits deleted the bugfix/2801-removal-in-flat-lists-doesnt-work branch September 3, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expanded codes of Value set with filter "op" : "is-not-a" includes the code that should not be included
2 participants