Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FEATURE] Make a Better Default for GetPatientAgeGroup #73

Closed
TheCedarPrince opened this issue Feb 3, 2024 · 2 comments · Fixed by #75
Closed

[FEATURE] Make a Better Default for GetPatientAgeGroup #73

TheCedarPrince opened this issue Feb 3, 2024 · 2 comments · Fixed by #75
Labels
enhancement New feature or request help wanted Extra attention is needed moderate Issue of moderate difficulty

Comments

@TheCedarPrince
Copy link
Member

I've been working with GetPatientAgeGroup and realized: I don't like the default I built-in here. Basically, this piece of code in the core functionality:

    age_arr = []

    for grp in age_groupings
        push!(age_arr, Get.age .< grp[2] + 1)
        push!(age_arr, "$(grp[1]) - $(grp[2])")
    end

Should have one more value added to the age_arr and what it should be is a kind of "finalizer" where, if someone does not fit into the specified age buckets, they get placed into here. I think this finalized label could be called something like "Unspecified". It would entail creating a final case within the FunSQL block that would act as the generic ELSE clause: https://www.w3schools.com/sql/sql_case.asp

I don't have a quick way to implement this in my mind, but would love some help here! Happy to brainstorm. :)

@TheCedarPrince TheCedarPrince added enhancement New feature or request help wanted Extra attention is needed moderate Issue of moderate difficulty labels Feb 3, 2024
@TheCedarPrince
Copy link
Member Author

More explicitly, the way the FunSQL code renders the existing defaults is like this:

SELECT
  "person_2"."person_id",
  (CASE WHEN ("person_2"."age" < 10) THEN '0 - 9' WHEN ("person_2"."age" < 20) THEN '10 - 19' WHEN ("person_2"."age" < 30) THEN '20 - 29' WHEN ("person_2"."age" < 40) THEN '30 - 39' WHEN ("person_2"."age" < 50) THEN '40 - 49' WHEN ("person_2"."age" < 60) THEN '50 - 59' WHEN ("person_2"."age" < 70) THEN '60 - 69' WHEN ("person_2"."age" < 80) THEN '70 - 79' WHEN ("person_2"."age" < 90) THEN '80 - 89' END) AS "age_group"
FROM (
  SELECT
    "person_1"."person_id",
    (2024 - "person_1"."year_of_birth") AS "age"
  FROM "omop"."person" AS "person_1"
  WHERE ("person_1"."person_id" IN (1))
) AS "person_2"

Ideally, there should be an additional part in the case blog that says something like this:

SELECT
  "person_2"."person_id",
  (CASE WHEN ("person_2"."age" < 10) THEN '0 - 9' WHEN ("person_2"."age" < 20) THEN '10 - 19' WHEN ("person_2"."age" < 30) THEN '20 - 29' WHEN ("person_2"."age" < 40) THEN '30 - 39' WHEN ("person_2"."age" < 50) THEN '40 - 49' WHEN ("person_2"."age" < 60) THEN '50 - 59' WHEN ("person_2"."age" < 70) THEN '60 - 69' WHEN ("person_2"."age" < 80) THEN '70 - 79' WHEN ("person_2"."age" < 90) THEN '80 - 89' ELSE 'Unspecified' END) AS "age_group"
FROM (
  SELECT
    "person_1"."person_id",
    (2024 - "person_1"."year_of_birth") AS "age"
  FROM "omop"."person" AS "person_1"
  WHERE ("person_1"."person_id" IN (1))
) AS "person_2"

Looking at this example, it could actually be as simple as modifying the existing line:

Define(:age_group => Fun.case(age_arr...)) |>

to this:

Define(:age_group => Fun.case(age_arr...), "Unspecified") |>

@TheCedarPrince
Copy link
Member Author

Otherwise, we get missings in the resulting dataframe for the age label which can just be a pain to work with:

10×4 DataFrame
 Row │ age_group  gender_concept_id  race_concept_id  count
     │ String?    Int32?             Int32?           Int64
─────┼──────────────────────────────────────────────────────
   150 - 59                 8532             8527    403
   240 - 49                 8532             8515     51
   330 - 39                 8507             8516     20
   450 - 59                 8507             8527    445
   540 - 49                 8532             8516     59
   6missing                 8532             8527    139
   760 - 69                 8532             8516     43
   850 - 59                 8532             8516     69
   980 - 89                 8532             8527    102
  1030 - 39                 8507             8527    114

See above table for example.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request help wanted Extra attention is needed moderate Issue of moderate difficulty
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant