andrewallenbruce / northstar

Tidy Healthcare Revenue Integrity :compass:
https://andrewallenbruce.github.io/northstar/
Apache License 2.0
3 stars 0 forks source link

`adjustments()` Implementation #18

Open andrewallenbruce opened 3 weeks ago

andrewallenbruce commented 3 weeks ago

Using {triebeard}

library(tidyverse)
library(northstar)
library(triebeard)

carc_group <- search_adjustments()$group

carc_group_trie <- triebeard::trie(
  keys = carc_group$code,
  values = carc_group$description
)

carc_code <- search_adjustments()$carc |> 
  select(code, description)

carc_code_trie <- triebeard::trie(
  keys = carc_code$code,
  values = carc_code$description
)

rpt |>
  select(pid, eid, adj_code_1, adj_code_2, adj_code_3) |>
  distinct() |> 
  pivot_longer(
    cols = starts_with("adj_code_"), 
    values_drop_na = TRUE,
    names_to = "adj_ord",
    names_prefix = "adj_code_",
    names_transform = list(adj_ord = as.integer),
    values_to = "adj_code"
    ) |>
  mutate(
    adj_code = if_else(str_detect(adj_code, regex("^-\\d+")), paste0("ZZ", adj_code), adj_code),
    adj_group_desc = triebeard::longest_match(carc_group_trie, substr(adj_code, 1, 2)),
    adj_code_desc = triebeard::longest_match(carc_code_trie, substr(adj_code, 4, 8))
  ) |> 
  count(adj_code, adj_group_desc, adj_code_desc, sort = TRUE)

#> # A tibble: 41 × 4
#>    adj_code adj_group_desc             adj_code_desc                           n
#>    <chr>    <chr>                      <chr>                               <int>
#>  1 CO-45    Contractual Obligations    Charge exceeds fee schedule/maximu… 28906
#>  2 CO-253   Contractual Obligations    Sequestration - reduction in feder…  1959
#>  3 CO-96    Contractual Obligations    Non-covered charge(s). At least on…   126
#>  4 CO-197   Contractual Obligations    Precertification/authorization/not…    95
#>  5 CO-29    Contractual Obligations    The time limit for filing has expi…    84
#>  6 OA-23    Other Adjustments          The impact of prior payer(s) adjud…    75
#>  7 PR-45    Patient Responsibility     Charge exceeds fee schedule/maximu…    42
#>  8 CO-23    Contractual Obligations    The impact of prior payer(s) adjud…    39
#>  9 OA-45    Other Adjustments          Charge exceeds fee schedule/maximu…    37
#> 10 CO-97    Contractual Obligations    The benefit for this service is in…    13
#> 11 PI-185   Payer Initiated Reductions The rendering provider is not elig…    10
#> 12 CO-18    Contractual Obligations    Exact duplicate claim/service (Use…     9
#> 13 CO-131   Contractual Obligations    Claim specific negotiated discount.     8
#> 14 PI-131   Payer Initiated Reductions Claim specific negotiated discount.     7
#> 15 PR-187   Patient Responsibility     Consumer Spending Account payments…     7
#> 16 CO-170   Contractual Obligations    Payment is denied when performed/b…     5
#> 17 PR-A1    Patient Responsibility     Claim/Service denied. At least one…     4
#> 18 CO-16    Contractual Obligations    Claim/service lacks information or…     3
#> 19 CO-198   Contractual Obligations    Precertification/notification/auth…     3
#> 20 CO-242   Contractual Obligations    Services not provided by network/p…     3
#> 21 ZZ-45    <NA>                       Charge exceeds fee schedule/maximu…     3
#> 22 CO-208   Contractual Obligations    National Provider Identifier - Not…     2
#> 23 CO-62    Contractual Obligations    Payment denied/reduced for absence…     2
#> 24 CO-B7    Contractual Obligations    This provider was not certified/el…     2
#> 25 PI-253   Payer Initiated Reductions Sequestration - reduction in feder…     2
#> 26 CO-151   Contractual Obligations    Payment adjusted because the payer…     1
#> 27 CO-187   Contractual Obligations    Consumer Spending Account payments…     1
#> 28 CO-21    Contractual Obligations    This injury/illness is the liabili…     1
#> 29 CO-22    Contractual Obligations    This care may be covered by anothe…     1
#> 30 CO-234   Contractual Obligations    This procedure is not paid separat…     1
#> 31 CO-B13   Contractual Obligations    Previously paid. Payment for this …     1
#> 32 CR       Corrections and Reversals  <NA>                                    1
#> 33 OA-187   Other Adjustments          Consumer Spending Account payments…     1
#> 34 OA-29    Other Adjustments          The time limit for filing has expi…     1
#> 35 PI-18    Payer Initiated Reductions Exact duplicate claim/service (Use…     1
#> 36 PI-45    Payer Initiated Reductions Charge exceeds fee schedule/maximu…     1
#> 37 PI-96    Payer Initiated Reductions Non-covered charge(s). At least on…     1
#> 38 PR-204   Patient Responsibility     This service/equipment/drug is not…     1
#> 39 PR-242   Patient Responsibility     Services not provided by network/p…     1
#> 40 PR-8     Patient Responsibility     The procedure code is inconsistent…     1
#> 41 PR-96    Patient Responsibility     Non-covered charge(s). At least on…     1

Created on 2024-06-11 with reprex v2.1.0

andrewallenbruce commented 2 weeks ago

Testing regex to differentiate CARC codes from RARC codes:

library(tidyverse)
library(northstar)

search_denials()$site |> 
  select(adj_code) |> 
  mutate(
    adj_dash = adj_code,
    adj_code = str_remove_all(adj_code, "-"),
    is_carc_dash = str_detect(adj_dash, 
      regex("^[ACIOPR]{2}-?[ABDPW]?[0-9]{1,3}$")),
    is_carc_nodash = str_detect(adj_code, 
      regex("^[ACIOPR]{2}-?[ABDPW]?[0-9]{1,3}$")),
    works = is_carc_dash == is_carc_nodash
  ) |> 
  print(n = 100)

#> # A tibble: 64 × 5
#>    adj_code adj_dash is_carc_dash is_carc_nodash works
#>    <chr>    <chr>    <lgl>        <lgl>          <lgl>
#>  1 CO16     CO-16    TRUE         TRUE           TRUE 
#>  2 M51      M51      FALSE        FALSE          TRUE 
#>  3 N56      N56      FALSE        FALSE          TRUE 
#>  4 CO16     CO-16    TRUE         TRUE           TRUE 
#>  5 M81      M81      FALSE        FALSE          TRUE 
#>  6 CO16     CO-16    TRUE         TRUE           TRUE 
#>  7 MA04     MA04     FALSE        FALSE          TRUE 
#>  8 CO16     CO-16    TRUE         TRUE           TRUE 
#>  9 MA36     MA36     FALSE        FALSE          TRUE 
#> 10 N704     N704     FALSE        FALSE          TRUE 
#> 11 CO16     CO-16    TRUE         TRUE           TRUE 
#> 12 MA120    MA120    FALSE        FALSE          TRUE 
#> 13 CO16     CO-16    TRUE         TRUE           TRUE 
#> 14 MA121    MA121    FALSE        FALSE          TRUE 
#> 15 MA122    MA122    FALSE        FALSE          TRUE 
#> 16 N264     N264     FALSE        FALSE          TRUE 
#> 17 N265     N265     FALSE        FALSE          TRUE 
#> 18 CO16     CO-16    TRUE         TRUE           TRUE 
#> 19 CO16     CO-16    TRUE         TRUE           TRUE 
#> 20 N290     N290     FALSE        FALSE          TRUE 
#> 21 N257     N257     FALSE        FALSE          TRUE 
#> 22 CO16     CO-16    TRUE         TRUE           TRUE 
#> 23 N382     N382     FALSE        FALSE          TRUE 
#> 24 N704     N704     FALSE        FALSE          TRUE 
#> 25 CO19     CO-19    TRUE         TRUE           TRUE 
#> 26 M418     M418     FALSE        FALSE          TRUE 
#> 27 CO22     CO-22    TRUE         TRUE           TRUE 
#> 28 N598     N598     FALSE        FALSE          TRUE 
#> 29 CO24     CO-24    TRUE         TRUE           TRUE 
#> 30 CO29     CO-29    TRUE         TRUE           TRUE 
#> 31 N211     N211     FALSE        FALSE          TRUE 
#> 32 PR31     PR-31    TRUE         TRUE           TRUE 
#> 33 CO45     CO-45    TRUE         TRUE           TRUE 
#> 34 PR45     PR-45    TRUE         TRUE           TRUE 
#> 35 PR49     PR-49    TRUE         TRUE           TRUE 
#> 36 N111     N111     FALSE        FALSE          TRUE 
#> 37 N429     N429     FALSE        FALSE          TRUE 
#> 38 CO50     CO-50    TRUE         TRUE           TRUE 
#> 39 N115     N115     FALSE        FALSE          TRUE 
#> 40 CO96     CO-96    TRUE         TRUE           TRUE 
#> 41 M117     M117     FALSE        FALSE          TRUE 
#> 42 CO96     CO-96    TRUE         TRUE           TRUE 
#> 43 N431     N431     FALSE        FALSE          TRUE 
#> 44 CO97     CO-97    TRUE         TRUE           TRUE 
#> 45 M15      M15      FALSE        FALSE          TRUE 
#> 46 CO97     CO-97    TRUE         TRUE           TRUE 
#> 47 COB20    CO-B20   TRUE         TRUE           TRUE 
#> 48 N111     N111     FALSE        FALSE          TRUE 
#> 49 CO107    CO-107   TRUE         TRUE           TRUE 
#> 50 CO151    CO-151   TRUE         TRUE           TRUE 
#> 51 CO236    CO-236   TRUE         TRUE           TRUE 
#> 52 CO252    CO-252   TRUE         TRUE           TRUE 
#> 53 M23      M23      FALSE        FALSE          TRUE 
#> 54 N704     N704     FALSE        FALSE          TRUE 
#> 55 CO252    CO-252   TRUE         TRUE           TRUE 
#> 56 N706     N706     FALSE        FALSE          TRUE 
#> 57 N704     N704     FALSE        FALSE          TRUE 
#> 58 COB7     CO-B7    TRUE         TRUE           TRUE 
#> 59 N570     N570     FALSE        FALSE          TRUE 
#> 60 PRB8     PR-B8    TRUE         TRUE           TRUE 
#> 61 OA18     OA-18    TRUE         TRUE           TRUE 
#> 62 N522     N522     FALSE        FALSE          TRUE 
#> 63 N103     N103     FALSE        FALSE          TRUE 
#> 64 OA258    OA-258   TRUE         TRUE           TRUE

Created on 2024-06-21 with reprex v2.1.0