provider icon indicating copy to clipboard operation
provider copied to clipboard

Feature: CCN validator

Open andrewallenbruce opened this issue 1 year ago • 1 comments

Code

short <- dplyr::tibble(
  range = vctrs::vec_c(paste0("000", as.character(1:9)),
                       paste0("00", as.character(10:99)),
                       paste0("0", as.character(100:879))),
  type = "Short-term (General and Specialty) Hospital"
)

ord <- dplyr::tibble(
  range = paste0("0", as.character(880:899)),
  type = "Hospital participating in ORD demonstration project"
)

fqhc <- dplyr::tibble(
  range = vctrs::vec_c(as.character(1000:1199), as.character(1800:1989)),
  type = "Federally Qualified Health Center"
)

maf <- dplyr::tibble(
  range = as.character(1225:1299),
  type = "Medical Assistance Facility"
)

cah <- dplyr::tibble(
  range = as.character(1300:1399),
  type = "Critical Access Hospital"
)

cmhc <- dplyr::tibble(
  range = as.character(1400:1499),
  type = "Community Mental Health Center"
)

hospice <- dplyr::tibble(
  range = as.character(1500:1799),
  type = "Hospice"
)

rnmhci <- dplyr::tibble(
  range = as.character(1990:1999),
  type = "Religious Non-medical Health Care Institution (formerly Christian Science Sanatoria Hospital Services)"
)

ltch <- dplyr::tibble(
  range = as.character(2000:2299),
  type = "Long-Term Care Hospital"
)

hbrdf <- dplyr::tibble(
  range = as.character(2300:2499),
  type = "Hospital-based Renal Dialysis Facility"
)

irdf <- dplyr::tibble(
  range = as.character(2500:2899),
  type = "Independent Renal Dialysis Facility"
)

isprdf <- dplyr::tibble(
  range = as.character(2900:2999),
  type = "Independent Special Purpose Renal Dialysis Facility"
)

rehosp <- dplyr::tibble(
  range = as.character(3025:3099),
  type = "Rehabilitation Hospital"
)

hha <- dplyr::tibble(
  range = vctrs::vec_c(as.character(3100:3199),
                       as.character(7000:8499),
                       as.character(9000:9799)),
  type = "Home Health Agency"
)

child <- dplyr::tibble(
  range = as.character(3300:3399),
  type = "Children's Hospital"
)

rhcp <- dplyr::tibble(
  range = vctrs::vec_c(as.character(3400:3499),
                       as.character(3975:3999),
                       as.character(8500:8899)),
  type = "Rural Health Clinic (Provider-based)"
)

rhcf <- dplyr::tibble(
  range = vctrs::vec_c(as.character(3800:3974),
                       as.character(8900:8999)),
  type = "Rural Health Clinic (Free-standing)"
)

hbsrdf <- dplyr::tibble(
  range = as.character(3500:3699),
  type = "Hospital-based Satellite Renal Dialysis Facility"
)

hbsprdf <- dplyr::tibble(
  range = as.character(3700:3799),
  type = "Hospital-based Special Purpose Renal Dialysis Facility"
)

psych <- dplyr::tibble(
  range = as.character(4000:4499),
  type = "Psychiatric Hospital"
)

corf <- dplyr::tibble(
  range = vctrs::vec_c(as.character(3200:3299),
                       as.character(4500:4599),
                       as.character(4800:4899)),
  type = "Comprehensive Outpatient Rehabilitation Facility"
)

cmhc2 <- dplyr::tibble(
  range = vctrs::vec_c(as.character(4600:4799),
                       as.character(4900:4999)),
  type = "Community Mental Health Center"
)

snf <- dplyr::tibble(
  range = as.character(5000:6499),
  type = "Skilled Nursing Facility"
)

outpts <- dplyr::tibble(
  range = as.character(6500:6989),
  type = "Outpatient Physical Therapy Services"
)

tplant <- dplyr::tibble(
  range = as.character(9800:9899),
  type = "Transplant Center"
)

numrsrv <- dplyr::tibble(
  range = as.character(6990:6999),
  type = "Number Reserved (formerly Christian Science Sanatoria Skilled Nursing Services)"
)

futrsrv <- dplyr::tibble(
  range = as.character(9900:9999),
  type = "Reserved for Future Use"
)

mhcmc <- dplyr::tibble(
  range = paste0("0", as.character(900:999)),
  type = "Multiple Hospital Component in a Medical Complex (Number Retired)"
)

adhret <- dplyr::tibble(
  range = as.character(1200:1224),
  type = "Alcohol/Drug Hospital (Number Retired)"
)

tubret <- dplyr::tibble(
  range = as.character(3000:3024),
  type = "Tuberculosis Hospital (Number Retired)"
)

facility_ranges <- dplyr::bind_rows(short, ord, fqhc, maf, cah, cmhc, hospice, rnmhci, ltch, hbrdf,
                 irdf, isprdf, rehosp, hha, child, rhcp, rhcf, hbsrdf, hbsprdf,
                 psych, corf, cmhc2, snf, outpts, tplant, numrsrv, futrsrv, mhcmc,
                 adhret, tubret)
facility_ranges |> count(type, sort = TRUE)

#> # A tibble: 29 × 2
#>    type                                                                        n
#>    <chr>                                                                   <int>
#>  1 Home Health Agency                                                       2400
#>  2 Skilled Nursing Facility                                                 1500
#>  3 Short-term (General and Specialty) Hospital                               879
#>  4 Rural Health Clinic (Provider-based)                                      525
#>  5 Psychiatric Hospital                                                      500
#>  6 Outpatient Physical Therapy Services                                      490
#>  7 Community Mental Health Center                                            400
#>  8 Independent Renal Dialysis Facility                                       400
#>  9 Federally Qualified Health Center                                         390
#> 10 Comprehensive Outpatient Rehabilitation Facility                          300
#> 11 Hospice                                                                   300
#> 12 Long-Term Care Hospital                                                   300
#> 13 Rural Health Clinic (Free-standing)                                       275
#> 14 Hospital-based Renal Dialysis Facility                                    200
#> 15 Hospital-based Satellite Renal Dialysis Facility                          200
#> 16 Children's Hospital                                                       100
#> 17 Critical Access Hospital                                                  100
#> 18 Hospital-based Special Purpose Renal Dialysis Facility                    100
#> 19 Independent Special Purpose Renal Dialysis Facility                       100
#> 20 Multiple Hospital Component in a Medical Complex (Number Retired)         100
#> 21 Reserved for Future Use                                                   100
#> 22 Transplant Center                                                         100
#> 23 Medical Assistance Facility                                                75
#> 24 Rehabilitation Hospital                                                    75
#> 25 Alcohol/Drug Hospital (Number Retired)                                     25
#> 26 Tuberculosis Hospital (Number Retired)                                     25
#> 27 Hospital participating in ORD demonstration project                        20
#> 28 Number Reserved (formerly Christian Science Sanatoria Skilled Nursing …    10
#> 29 Religious Non-medical Health Care Institution (formerly Christian Scie…    10

Created on 2023-11-29 with reprex v2.0.2

andrewallenbruce avatar Nov 19 '23 06:11 andrewallenbruce

Using {ivs}:

Code

short <- dplyr::tibble(
  type = "Short-term (General and Specialty) Hospital",
  start = 1L,
  end = 880L
)

ord <- dplyr::tibble(
  type = "Hospital participating in ORD demonstration project",
  start = 880L,
  end = 900L
)

fqhc <- dplyr::tibble(
  type = c("Federally Qualified Health Center", "Federally Qualified Health Center"),
  start = c(1000L, 1800L),
  end = c(1200L, 1990L),
)

maf <- dplyr::tibble(
  type = "Medical Assistance Facility",
  start = 1225L,
  end = 1300L
)

cah <- dplyr::tibble(
  type = "Critical Access Hospital",
  start = 1300L,
  end = 1400L
)

cmhc <- dplyr::tibble(
  type = c("Community Mental Health Center",
           "Community Mental Health Center",
           "Community Mental Health Center"),
  start = c(1400L, 4600L, 4900L),
  end = c(1500L, 4800L, 5000L)
)

hospice <- dplyr::tibble(
  type = "Hospice",
  start = 1500L,
  end = 1800L
)

rnmhci <- dplyr::tibble(
  type = "Religious Non-medical Health Care Institution (formerly Christian Science Sanatoria Hospital Services)",
  start = 1990L,
  end = 2000L
)

ltch <- dplyr::tibble(
  type = "Long-Term Care Hospital",
  start = 2000L,
  end = 2300L
)

hbrdf <- dplyr::tibble(
  type = "Hospital-based Renal Dialysis Facility",
  start = 2300L,
  end = 2500L
)

irdf <- dplyr::tibble(
  type = "Independent Renal Dialysis Facility",
  start = 2500L,
  end = 2900L
)

isprdf <- dplyr::tibble(
  type = "Independent Special Purpose Renal Dialysis Facility",
  start = 2900L,
  end = 3000L
)

rehosp <- dplyr::tibble(
  type = "Rehabilitation Hospital",
  start = 3025L,
  end = 3100L
)

hha <- dplyr::tibble(
  type = c("Home Health Agency",
           "Home Health Agency",
           "Home Health Agency"),
  start = c(3100L, 7000L, 9000L),
  end = c(3200L, 8500L, 9800L)
)

child <- dplyr::tibble(
  type = "Children's Hospital",
  start = 3300L,
  end = 3400L
)

rhcp <- dplyr::tibble(
  type = c("Rural Health Clinic (Provider-based)",
           "Rural Health Clinic (Provider-based)",
           "Rural Health Clinic (Provider-based)"),
  start = c(3400L, 3975L, 8500L),
  end = c(3500L, 4000L, 8900L)
)

rhcf <- dplyr::tibble(
  type = c("Rural Health Clinic (Free-standing)",
           "Rural Health Clinic (Free-standing)"),
  start = c(3800L, 8900L),
  end = c(3975L, 9000L)
)

hbsrdf <- dplyr::tibble(
  type = "Hospital-based Satellite Renal Dialysis Facility",
  start = 3500L,
  end = 3700L
)

hbsprdf <- dplyr::tibble(
  type = "Hospital-based Special Purpose Renal Dialysis Facility",
  start = 3700L,
  end = 3800L
)

psych <- dplyr::tibble(
  type = "Psychiatric Hospital",
  start = 4000L,
  end = 4500L
)

corf <- dplyr::tibble(
  type = c("Comprehensive Outpatient Rehabilitation Facility",
           "Comprehensive Outpatient Rehabilitation Facility",
           "Comprehensive Outpatient Rehabilitation Facility"),
  start = c(3200L, 4500L, 4800L),
  end = c(3300L, 4600L, 4900L)
)

snf <- dplyr::tibble(
  type = "Skilled Nursing Facility",
  start = 5000L,
  end = 6500L
)

outpts <- dplyr::tibble(
  type = "Outpatient Physical Therapy Services",
  start = 6500L,
  end = 6990L
)

tplant <- dplyr::tibble(
  type = "Transplant Center",
  start = 9800L,
  end = 9900L
)

numrsrv <- dplyr::tibble(
  type = "Number Reserved (formerly Christian Science Sanatoria Skilled Nursing Services)",
  start = 6990L,
  end = 7000L
)

futrsrv <- dplyr::tibble(
  type = "Reserved for Future Use",
  start = 9900L,
  end = 10000L
)

mhcmc <- dplyr::tibble(
  type = "Multiple Hospital Component in a Medical Complex (Number Retired)",
  start = 900L,
  end = 1000L
)

adhret <- dplyr::tibble(
  type = "Alcohol/Drug Hospital (Number Retired)",
  start = 1200L,
  end = 1225L
)

tubret <- dplyr::tibble(
  type = "Tuberculosis Hospital (Number Retired)",
  start = 3000L,
  end = 3025L
)

ranges <- dplyr::bind_rows(adhret, cah, child, cmhc, corf, fqhc,
                           futrsrv, hbrdf, hha, hospice, hbsprdf,
                           hbsrdf, irdf, isprdf, ltch, maf, mhcmc,
                           numrsrv, ord, outpts, psych, rehosp, rhcf,
                           rhcp, rnmhci, short, snf, tplant, tubret)
range_test <- ranges |>
  dplyr::arrange(start) |>
  dplyr::mutate(range = ivs::iv(start, end), .keep = "unused")

range_test
#> # A tibble: 39 × 2
#>    type                                                                    range
#>    <chr>                                                               <iv<int>>
#>  1 Short-term (General and Specialty) Hospital                          [1, 880)
#>  2 Hospital participating in ORD demonstration project                [880, 900)
#>  3 Multiple Hospital Component in a Medical Complex (Number Retir…   [900, 1000)
#>  4 Federally Qualified Health Center                                [1000, 1200)
#>  5 Alcohol/Drug Hospital (Number Retired)                           [1200, 1225)
#>  6 Medical Assistance Facility                                      [1225, 1300)
#>  7 Critical Access Hospital                                         [1300, 1400)
#>  8 Community Mental Health Center                                   [1400, 1500)
#>  9 Hospice                                                          [1500, 1800)
#> 10 Federally Qualified Health Center                                [1800, 1990)
#> 11 Religious Non-medical Health Care Institution (formerly Christ…  [1990, 2000)
#> 12 Long-Term Care Hospital                                          [2000, 2300)
#> 13 Hospital-based Renal Dialysis Facility                           [2300, 2500)
#> 14 Independent Renal Dialysis Facility                              [2500, 2900)
#> 15 Independent Special Purpose Renal Dialysis Facility              [2900, 3000)
#> 16 Tuberculosis Hospital (Number Retired)                           [3000, 3025)
#> 17 Rehabilitation Hospital                                          [3025, 3100)
#> 18 Home Health Agency                                               [3100, 3200)
#> 19 Comprehensive Outpatient Rehabilitation Facility                 [3200, 3300)
#> 20 Children's Hospital                                              [3300, 3400)
#> 21 Rural Health Clinic (Provider-based)                             [3400, 3500)
#> 22 Hospital-based Satellite Renal Dialysis Facility                 [3500, 3700)
#> 23 Hospital-based Special Purpose Renal Dialysis Facility           [3700, 3800)
#> 24 Rural Health Clinic (Free-standing)                              [3800, 3975)
#> 25 Rural Health Clinic (Provider-based)                             [3975, 4000)
#> 26 Psychiatric Hospital                                             [4000, 4500)
#> 27 Comprehensive Outpatient Rehabilitation Facility                 [4500, 4600)
#> 28 Community Mental Health Center                                   [4600, 4800)
#> 29 Comprehensive Outpatient Rehabilitation Facility                 [4800, 4900)
#> 30 Community Mental Health Center                                   [4900, 5000)
#> 31 Skilled Nursing Facility                                         [5000, 6500)
#> 32 Outpatient Physical Therapy Services                             [6500, 6990)
#> 33 Number Reserved (formerly Christian Science Sanatoria Skilled …  [6990, 7000)
#> 34 Home Health Agency                                               [7000, 8500)
#> 35 Rural Health Clinic (Provider-based)                             [8500, 8900)
#> 36 Rural Health Clinic (Free-standing)                              [8900, 9000)
#> 37 Home Health Agency                                               [9000, 9800)
#> 38 Transplant Center                                                [9800, 9900)
#> 39 Reserved for Future Use                                         [9900, 10000)

facility_code <- 3000L

range_test |>
  dplyr::mutate(is_between = ivs::iv_includes(range, facility_code)) |>
  dplyr::filter(is_between == TRUE) |>
  dplyr::pull(type)

#> [1] "Tuberculosis Hospital (Number Retired)"

Created on 2023-11-29 with reprex v2.0.2

andrewallenbruce avatar Nov 29 '23 14:11 andrewallenbruce