Text Wrangling: EDI Payer List

healthcare EDI HL7 HIPAA rstats r-bloggers

Coding a more intuitive framework for an EDI Payer List from external sources for internal use.

Andrew Bruce https://andrewbruce.netlify.app
2022-05-30

Introduction

Electronic Data Interchange (EDI)

Electronic Data Interchange (EDI) is a technology that allows the exchange of commercial information between organizations in a structured digital form based on regulated message formats and standards. Any standard business document exchanged between companies can be transferred using the EDI standard.

ANSI X12, HIPAA & HL7

These are all different standards to exchange electronic business documents. Some of these standards have been developed for use in a specific industry, according to its special needs. Other standards are developed and widely used, based on geography. For example, the EDI ANSI X12 standard is developed by the American National Standards Institute (ANSI). HIPAA (the Health Insurance Portability and Accountability Act of 1996) is designed specifically to comply with healthcare law. HL7 (Health Level 7) is the standard to exchange medical information.

Payer ID

The Payer ID or EDI is a unique ID assigned to each insurance company. It allows provider and payer systems to talk to one another to verify eligibility, benefits and submit claims. The payer ID is generally five (5) characters but it may be longer. It may also be alpha, numeric or a combination. The payer ID is often located on the back of the insurance card in the Provider or Claims Submission section. Below are some common examples. If you are unable to locate the payer ID, please enter NA or None.

Packages

Dataset

Data downloaded from url: https://payers.gatewayedi.com/payerlist/default.aspx

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Data Cleaning & Wrangling

Rename Columns

With column names like Available \n Transactions, we need to rename them to follow a tidy format:

hcfa_payers <- hcfa_payers |>
  rename(
    payername = "Payer Name",
    id = "PayerId",
    avail_trans = "Available \n Transactions",
    enroll_req = "Enrollment \n Required",
    format = "Payer \n Format",
    icd_vers = "Payer ICD Version",
    transition_date = "Payer ICD \n Transition Date"
  )

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Remove Unneeded Columns

We can remove three columns, for the following reasons:

hcfa_payers <- hcfa_payers |>
  select(payername, id, avail_trans, enroll_req)

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

payername Column

The payername column has the payer’s name and the states that the payer operates in. To make this information searchable in our data frame, we’ll need to do some data wrangling.

Split payername into two columns

We’ll start by splitting it into two columns, payer and service_states, using the str_detect() and str_match() functions from the {stringr} package:

hcfa_payers <- hcfa_payers |>
  mutate(
    payer = ifelse(
      str_detect(
        payername,
        "\\sServicing States"
      ),
      str_match(
        payername,
        "(.*)\\sServicing States"
      )[, 2],
      payername
    ),
    service_states = str_match(
      payername,
      "Servicing States:\\s(.*)"
    )[, 2]
  ) |>
  select(
    payer,
    service_states,
    id,
    avail_trans,
    enroll_req
  )

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Replace NAs in service_states with “ALL”

Payers designated as servicing all states were given an “NA” in the new service_states column because there was no space between the colon and “ALL” (i.e., “States:ALL”) and the regex expression that I used indicated that there would be a space between the payer name and the state. We fix this by simply replacing all NAs with “ALL”:

hcfa_payers <- hcfa_payers |>
  mutate(service_states = ifelse(is.na(service_states), "ALL", service_states))

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Split avail_trans and enroll_req into individual columns

These two columns are a little bit trickier. We want each available transaction to correspond to whether or not enrollment is required to use them. I’ll use str_match() to split them one-by-one into a wide format, merge each pair together with {tidyr}’s unite() function, pivot to a longer format, and then perform some general cleanup to finish up.

Here, I’m splitting each transaction available to it’s own column as well it’s corresponding enrollment required indicator. This may look like overkill (and I’m almost certain that it absolutely is) but I want to make sure I get every transaction. I can remove any duplicates later on.

hcfa_payers <- hcfa_payers |>
  separate_rows(avail_trans, enroll_req, sep = " \n ")

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Remove Duplicate Rows

hcfa_payers <- hcfa_payers |>
  distinct()

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Rename avail_trans Variables

hcfa_payers <- hcfa_payers |>
  mutate(avail_trans = case_when(
    avail_trans == "ProfessionalClaims" ~ "Professional Claims",
    avail_trans == "Rtpa" ~ "RTPA",
    avail_trans == "ClaimAttachments" ~ "Claim Attachments",
    avail_trans == "ElectronicRemits" ~ "Electronic Remits",
    avail_trans == "Remits" ~ "Remits",
    avail_trans == "InsuranceEligibilityDiscovery" ~ "Insurance Eligibility Discovery",
    avail_trans == "ClaimStatus" ~ "Claim Status",
    avail_trans == "ElectronicCob" ~ "Electronic COB",
    avail_trans == "Eligibility" ~ "Eligibility",
    avail_trans == "InstitutionalClaims" ~ "Institutional Claims",
    avail_trans == "AuthorizationAndReferrals" ~ "Authorization & Referrals",
    avail_trans == "DentalClaims" ~ "Dental Claims",
    TRUE ~ "Unknown"
  ))

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Building the Table

Add Color Columns for {reactablefmtr}

hcfa_payers <- hcfa_payers |>
  mutate(
    trans_colors = case_when(
      avail_trans == "Professional Claims" ~ "#FFACAC",
      avail_trans == "RTPA" ~ "#A45746",
      avail_trans == "Claim Attachments" ~ "#132F3C",
      avail_trans == "Electronic Remits" ~ "#140E0F",
      avail_trans == "Remits" ~ "#74AAEB",
      avail_trans == "Insurance Eligibility Discovery" ~ "#1D4C62",
      avail_trans == "Claim Status" ~ "#95A494",
      avail_trans == "Electronic COB" ~ "#DBB592",
      avail_trans == "Eligibility" ~ "#F6CCB0",
      avail_trans == "Institutional Claims" ~ "#EBA42B",
      avail_trans == "Authorization & Referrals" ~ "#E85569",
      avail_trans == "Dental Claims" ~ "#5C2C2D",
      TRUE ~ "Unknown"
    ),
    enroll_colors = case_when(
      enroll_req == "NO" ~ "#f0fff0",
      enroll_req == "Yes" ~ "#C7662A",
      TRUE ~ "Unknown"
    )
  )

payer_preview <- head(hcfa_payers, 10)
paged_table(payer_preview)

Final Table with {reactable}

Show code
reactable(hcfa_payers,
  filterable = TRUE,
  striped = FALSE,
  highlight = TRUE,
  showPageSizeOptions = TRUE,
  class = "packages-table",
  onClick = "expand",
  rowStyle = list(cursor = "pointer"),
  paginationType = "simple",
  groupBy = "payer",
  defaultSorted = "payer",
  defaultColDef = colDef(
    headerClass = "col-header",
    footerClass = "col-footer"
  ),
  columns = list(
    payer = colDef(
      name = "Payer"
    ),
    service_states = colDef(
      name = "States",
      width = 100,
      aggregate = "unique"
    ),
    id = colDef(
      name = "Payer ID",
      class = "number",
      width = 100,
      aggregate = "unique"
    ),
    avail_trans = colDef(
      name = "Available Transactions",
      aggregate = "unique",
      cell = pill_buttons(
        data = hcfa_payers,
        color_ref = "trans_colors",
        box_shadow = FALSE
      )
    ),
    enroll_req = colDef(
      name = "Enrollment Required",
      width = 200,
      aggregate = "frequency",
      cell = pill_buttons(
        data = hcfa_payers,
        color_ref = "enroll_colors",
        box_shadow = FALSE
      )
    ),
    trans_colors = colDef(show = FALSE),
    enroll_colors = colDef(show = FALSE)
  )
) |>
  add_title(
    title = "Insurance Payer Information",
    margin = reactablefmtr::margin(t = 10, r = 0, b = 15, l = 0)
  ) |>
  add_subtitle(
    subtitle = "For Electronic Data Interchange (EDI): Treatment, Payment, Operations (TPO)",
    margin = reactablefmtr::margin(t = 10, r = 0, b = 15, l = 0)
  ) |>
  add_source(
    font_color = "#C8C8C8",
    align = "right",
    margin = reactablefmtr::margin(t = 0, r = 10, b = 0, l = 0),
    source = html("Table: <a href='https://twitter.com/aabrucehimni'>@aabrucehimni</a> | Data: <a href='https://payers.gatewayedi.com/payerlist/default.aspx'>Trizetto Gateway EDI</a> & <a href='http://www.healthdataservices.com/payerid/payerlist.htm'>Health Data Services, Inc.</a>")
  )

Insurance Payer Information

For Electronic Data Interchange (EDI): Treatment, Payment, Operations (TPO)

Table: @aabrucehimni | Data: Trizetto Gateway EDI & Health Data Services, Inc.

Citations

Package Version Citation
base 4.2.0 R Core Team (2022)
distill 1.4 Dervieux et al. (2022)
gdata 2.18.0.1 Warnes et al. (2022)
grateful 0.1.11 Rodríguez-Sánchez, Jackson, and Hutchins (2022)
htmltools 0.5.2 Cheng et al. (2021)
knitr 1.39 Xie (2014); Xie (2015); Xie (2022)
reactable 0.3.0 Lin (2022)
reactablefmtr 2.0.0 Cuilla (2022)
rio 0.5.29 Chan et al. (2021)
rmarkdown 2.14 Xie, Allaire, and Grolemund (2018); Xie, Dervieux, and Riederer (2020); Allaire et al. (2022)
sessioninfo 1.2.2 Wickham et al. (2021)
tidyverse 1.3.1 Wickham et al. (2019)
xaringanExtra 0.5.5 Aden-Buie and Warkentin (2022)

Last updated on

[1] "2022-06-02 01:38:09 EDT"

Session Info

sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.0 (2022-04-22 ucrt)
 os       Windows 10 x64 (build 25126)
 system   x86_64, mingw32
 ui       RTerm
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/New_York
 date     2022-06-02
 pandoc   2.17.1.1 @ C:/Program Files/RStudio/bin/quarto/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
 package       * version  date (UTC) lib source
 assertthat      0.2.1    2019-03-21 [1] CRAN (R 4.2.0)
 backports       1.4.1    2021-12-13 [1] CRAN (R 4.2.0)
 broom           0.8.0    2022-04-13 [1] CRAN (R 4.2.0)
 bslib           0.3.1    2021-10-06 [1] CRAN (R 4.2.0)
 cachem          1.0.6    2021-08-19 [1] CRAN (R 4.2.0)
 cellranger      1.1.0    2016-07-27 [1] CRAN (R 4.2.0)
 cli             3.3.0    2022-04-25 [1] CRAN (R 4.2.0)
 colorspace      2.0-3    2022-02-21 [1] CRAN (R 4.2.0)
 crayon          1.5.1    2022-03-26 [1] CRAN (R 4.2.0)
 crosstalk       1.2.0    2021-11-04 [1] CRAN (R 4.2.0)
 curl            4.3.2    2021-06-23 [1] CRAN (R 4.2.0)
 data.table      1.14.2   2021-09-27 [1] CRAN (R 4.2.0)
 DBI             1.1.2    2021-12-20 [1] CRAN (R 4.2.0)
 dbplyr          2.1.1    2021-04-06 [1] CRAN (R 4.2.0)
 digest          0.6.29   2021-12-01 [1] CRAN (R 4.2.0)
 distill         1.4      2022-05-12 [1] CRAN (R 4.2.0)
 downlit         0.4.0    2021-10-29 [1] CRAN (R 4.2.0)
 dplyr         * 1.0.9    2022-04-28 [1] CRAN (R 4.2.0)
 ellipsis        0.3.2    2021-04-29 [1] CRAN (R 4.2.0)
 evaluate        0.15     2022-02-18 [1] CRAN (R 4.2.0)
 fansi           1.0.3    2022-03-24 [1] CRAN (R 4.2.0)
 fastmap         1.1.0    2021-01-25 [1] CRAN (R 4.2.0)
 forcats       * 0.5.1    2021-01-27 [1] CRAN (R 4.2.0)
 foreign         0.8-82   2022-01-16 [2] CRAN (R 4.2.0)
 fs              1.5.2    2021-12-08 [1] CRAN (R 4.2.0)
 gdata         * 2.18.0.1 2022-05-10 [1] CRAN (R 4.2.0)
 generics        0.1.2    2022-01-31 [1] CRAN (R 4.2.0)
 ggplot2       * 3.3.6    2022-05-03 [1] CRAN (R 4.2.0)
 glue            1.6.2    2022-02-24 [1] CRAN (R 4.2.0)
 grateful      * 0.1.11   2022-05-07 [1] Github (Pakillo/grateful@ba9b003)
 gtable          0.3.0    2019-03-25 [1] CRAN (R 4.2.0)
 gtools          3.9.2.1  2022-05-23 [1] CRAN (R 4.2.0)
 haven           2.5.0    2022-04-15 [1] CRAN (R 4.2.0)
 highr           0.9      2021-04-16 [1] CRAN (R 4.2.0)
 hms             1.1.1    2021-09-26 [1] CRAN (R 4.2.0)
 htmltools     * 0.5.2    2021-08-25 [1] CRAN (R 4.2.0)
 htmlwidgets     1.5.4    2021-09-08 [1] CRAN (R 4.2.0)
 httr            1.4.3    2022-05-04 [1] CRAN (R 4.2.0)
 jquerylib       0.1.4    2021-04-26 [1] CRAN (R 4.2.0)
 jsonlite        1.8.0    2022-02-22 [1] CRAN (R 4.2.0)
 knitr         * 1.39     2022-04-26 [1] CRAN (R 4.2.0)
 lifecycle       1.0.1    2021-09-24 [1] CRAN (R 4.2.0)
 lubridate     * 1.8.0    2021-10-07 [1] CRAN (R 4.2.0)
 magrittr        2.0.3    2022-03-30 [1] CRAN (R 4.2.0)
 memoise         2.0.1    2021-11-26 [1] CRAN (R 4.2.0)
 modelr          0.1.8    2020-05-19 [1] CRAN (R 4.2.0)
 munsell         0.5.0    2018-06-12 [1] CRAN (R 4.2.0)
 openxlsx        4.2.5    2021-12-14 [1] CRAN (R 4.2.0)
 pillar          1.7.0    2022-02-01 [1] CRAN (R 4.2.0)
 pkgconfig       2.0.3    2019-09-22 [1] CRAN (R 4.2.0)
 purrr         * 0.3.4    2020-04-17 [1] CRAN (R 4.2.0)
 R.cache         0.15.0   2021-04-30 [1] CRAN (R 4.2.0)
 R.methodsS3     1.8.1    2020-08-26 [1] CRAN (R 4.2.0)
 R.oo            1.24.0   2020-08-26 [1] CRAN (R 4.2.0)
 R.utils         2.11.0   2021-09-26 [1] CRAN (R 4.2.0)
 R6              2.5.1    2021-08-19 [1] CRAN (R 4.2.0)
 Rcpp            1.0.8.3  2022-03-17 [1] CRAN (R 4.2.0)
 reactable     * 0.3.0    2022-05-26 [1] CRAN (R 4.2.0)
 reactablefmtr * 2.0.0    2022-03-16 [1] CRAN (R 4.2.0)
 reactR          0.4.4    2021-02-22 [1] CRAN (R 4.2.0)
 readr         * 2.1.2    2022-01-30 [1] CRAN (R 4.2.0)
 readxl          1.4.0    2022-03-28 [1] CRAN (R 4.2.0)
 renv            0.15.5   2022-05-26 [1] CRAN (R 4.2.0)
 reprex          2.0.1    2021-08-05 [1] CRAN (R 4.2.0)
 rio             0.5.29   2021-11-22 [1] CRAN (R 4.2.0)
 rlang           1.0.2    2022-03-04 [1] CRAN (R 4.2.0)
 rmarkdown     * 2.14     2022-04-25 [1] CRAN (R 4.2.0)
 rstudioapi      0.13     2020-11-12 [1] CRAN (R 4.2.0)
 rvest           1.0.2    2021-10-16 [1] CRAN (R 4.2.0)
 sass            0.4.1    2022-03-23 [1] CRAN (R 4.2.0)
 scales          1.2.0    2022-04-13 [1] CRAN (R 4.2.0)
 sessioninfo     1.2.2    2021-12-06 [1] CRAN (R 4.2.0)
 stringi         1.7.6    2021-11-29 [1] CRAN (R 4.2.0)
 stringr       * 1.4.0    2019-02-10 [1] CRAN (R 4.2.0)
 styler          1.7.0    2022-03-13 [1] CRAN (R 4.2.0)
 tibble        * 3.1.7    2022-05-03 [1] CRAN (R 4.2.0)
 tidyr         * 1.2.0    2022-02-01 [1] CRAN (R 4.2.0)
 tidyselect      1.1.2    2022-02-21 [1] CRAN (R 4.2.0)
 tidyverse     * 1.3.1    2021-04-15 [1] CRAN (R 4.2.0)
 tzdb            0.3.0    2022-03-28 [1] CRAN (R 4.2.0)
 utf8            1.2.2    2021-07-24 [1] CRAN (R 4.2.0)
 uuid            1.1-0    2022-04-19 [1] CRAN (R 4.2.0)
 vctrs           0.4.1    2022-04-13 [1] CRAN (R 4.2.0)
 withr           2.5.0    2022-03-03 [1] CRAN (R 4.2.0)
 xaringanExtra   0.5.5    2022-04-26 [1] Github (gadenbuie/xaringanExtra@ee5092d)
 xfun            0.31     2022-05-10 [1] CRAN (R 4.2.0)
 xml2            1.3.3    2021-11-30 [1] CRAN (R 4.2.0)
 yaml            2.3.5    2022-02-21 [1] CRAN (R 4.2.0)
 zip             2.2.0    2021-05-31 [1] CRAN (R 4.2.0)

 [1] C:/Users/andyb/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.0/library

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Aden-Buie, Garrick, and Matthew T. Warkentin. 2022. xaringanExtra: Extras and Extensions for Xaringan Slides. https://github.com/gadenbuie/xaringanExtra.
Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2022. Rmarkdown: Dynamic Documents for r. https://github.com/rstudio/rmarkdown.
Chan, Chung-hong, Geoffrey CH Chan, Thomas J. Leeper, and Jason Becker. 2021. Rio: A Swiss-Army Knife for Data File i/o.
Cheng, Joe, Carson Sievert, Barret Schloerke, Winston Chang, Yihui Xie, and Jeff Allen. 2021. Htmltools: Tools for HTML. https://CRAN.R-project.org/package=htmltools.
Cuilla, Kyle. 2022. Reactablefmtr: Streamlined Table Styling and Formatting for Reactable. https://CRAN.R-project.org/package=reactablefmtr.
Dervieux, Christophe, JJ Allaire, Rich Iannone, Alison Presmanes Hill, and Yihui Xie. 2022. Distill: ’R Markdown’ Format for Scientific and Technical Writing. https://CRAN.R-project.org/package=distill.
Lin, Greg. 2022. Reactable: Interactive Data Tables Based on ’React Table’. https://CRAN.R-project.org/package=reactable.
R Core Team. 2022. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Rodríguez-Sánchez, Francisco, Connor P. Jackson, and Shaurita D. Hutchins. 2022. Grateful: Facilitate Citation of r Packages. https://github.com/Pakillo/grateful.
Warnes, Gregory R., Ben Bolker, Gregor Gorjanc, Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni Magnusson, Jim Rogers, et al. 2022. Gdata: Various r Programming Tools for Data Manipulation. https://CRAN.R-project.org/package=gdata.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Robert Flight, Kirill Müller, and Jim Hester. 2021. Sessioninfo: R Session Information. https://CRAN.R-project.org/package=sessioninfo.
Xie, Yihui. 2014. “Knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC. http://www.crcpress.com/product/isbn/9781466561595.
———. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2022. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.

References

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/andrewallenbruce, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Bruce (2022, May 30). Andrew Bruce: Text Wrangling: EDI Payer List. Retrieved from https://andrewbruce.netlify.app/posts/text-wrangling-edi-payer-list/

BibTeX citation

@misc{bruce2022text,
  author = {Bruce, Andrew},
  title = {Andrew Bruce: Text Wrangling: EDI Payer List},
  url = {https://andrewbruce.netlify.app/posts/text-wrangling-edi-payer-list/},
  year = {2022}
}