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

Calculate percentage of usage for selected codes #30

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

milanwiedemann
Copy link
Member

@milanwiedemann milanwiedemann commented Nov 20, 2024

This is just an example how to calculate the percentage of code usage for selected codes. The main additions are:

  1. The calculation in server.R:

    group_by(code, description) |>
    summarise(total_usage = sum(usage, na.rm = TRUE)) |>
    ungroup() |>
    mutate(total_pct = total_usage / sum(total_usage, na.rm = TRUE)) |>
    arrange(desc(total_usage))
  2. Changes to the table formatting in tables.R:

    formatPercentage(
      "total_pct",
      digits = 3
    )

Note that in cases where a code has slightly different descriptions across the years this will show each unique code and description pair separately but I think that's acceptable. For example code SNOMED-CD code 103069003 had three slightly different descriptions over the years:

  start_date end_date   snomed_concept_id description                                       
  <date>     <date>     <chr>             <chr>        
1 2023-08-01 2024-07-31 103069003         Vitamin B and/or vitamin B derivative (substance)          
2 2022-08-01 2023-07-31 103069003         Vitamin B and/or vitamin B derivative (substance)         
3 2020-08-01 2021-07-31 103069003         Vitamin B and vitamin B derivative (substance)          
4 2019-08-01 2020-07-31 103069003         Vitamin B (substance)                                      

@milanwiedemann milanwiedemann marked this pull request as ready for review November 28, 2024 10:34
@milanwiedemann milanwiedemann merged commit b2bb89a into main Nov 28, 2024
6 checks passed
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.

1 participant