Skip to content

Error with pulling concept lists with nested criteria in cohort #123

@k-m-li

Description

@k-m-li

When you have a multi-layer nested criteria in a cohort definition where the outer nested portion has only one element, you are unable to pull the concept list from the cohort: functions for pulling the list return an empty list instead. This makes it very hard to generate a working JSON.

A temp workaround can be to add an extra line into the outer nest using a dummy cs
atLeast(0, conditionOccurrence(cs(9999999, name = "dummy")))

A working example is below.

## Pass:
x <- cohort(
  entry(
    conditionOccurrence(cs(1, name = "test"),
                         nestedWithAll(
                           atLeast(1, conditionOccurrence(cs(2, name = "test2"))),
                           atLeast(1, conditionOccurrence(cs(3, name = "test3"),
                                                          nestedWithAll(atLeast(1, conditionOccurrence(cs(1, name = "test"))))
                           ))))
  )
)
Capr:::listConceptSets(x)

## Fail: returns empty list
x <- cohort(
  entry(
    conditionOccurrence(cs(1, name = "test"),
                        nestedWithAll(
                          # atLeast(1, conditionOccurrence(cs(2, name = "test2"))),
                          atLeast(1, conditionOccurrence(cs(3, name = "test3"),
                                                         nestedWithAll(atLeast(1, conditionOccurrence(cs(1, name = "test"))))
                          ))))
  )
)
Capr:::listConceptSets(x)

## Pass:
x <- entry(
  conditionOccurrence(cs(1, name = "test"),
                      nestedWithAll(
                        # atLeast(1, conditionOccurrence(cs(2, name = "test2"))),
                        atLeast(1, conditionOccurrence(cs(3, name = "test3"),
                                                       nestedWithAll(atLeast(1, conditionOccurrence(cs(1, name = "test"))))
                        ))))
)
Capr:::listConceptSets(x)

## Workaround:
x <- cohort(
  entry(
    conditionOccurrence(cs(1, name = "test"),
                        nestedWithAll(
                          atLeast(0, conditionOccurrence(cs(9999999, name = "dummy"))),
                          atLeast(1, conditionOccurrence(cs(3, name = "test3"),
                                                         nestedWithAll(atLeast(1, conditionOccurrence(cs(1, name = "test"))))
                          ))))
  )
)
Capr:::listConceptSets(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions