Skip to content

Commit

Permalink
* getting started vignette
Browse files Browse the repository at this point in the history
* added display_long helper
  • Loading branch information
andrewallenbruce committed Mar 31, 2024
1 parent 0c2cdcd commit 34aa11d
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Imports:
tidyr (>= 1.3.1),
vctrs (>= 0.6.5)
Suggests:
gt,
knitr,
rmarkdown,
roxyglobals
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(case_chapter_icd10)
export(display_long)
export(icd10api)
export(icd10cm)
export(is_valid_icd)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# pathologie (development version)

* Initial CRAN submission.
* Initial commit.
19 changes: 17 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gh_raw <- function(x) {

#' Mount [pins][pins::pins-package] board
#' @param source `"local"` or `"remote"`
#' @return `<pins_board_folder>` or `<pins_board_url>`
#' @return `<pins_board_folder>` if `source = "local"` or `<pins_board_url>` if `source = "remote"`
#' @noRd
mount_board <- function(source = c("local", "remote")) {

Expand All @@ -16,7 +16,22 @@ mount_board <- function(source = c("local", "remote")) {
source,
local = pins::board_folder(fs::path_package("extdata/pins", package = "pathologie")),
remote = pins::board_url(gh_raw(
"andrewallenbruce/northstar/master/inst/extdata/pins/"
"andrewallenbruce/pathologie/master/inst/extdata/pins/"
))
)
}

#' Pivot data frame to long format for easy printing
#' @param df `<data.frame>`
#' @param cols `<chr>` vector of columns to pivot long, default is [dplyr::everything()]
#' @return A [tibble][tibble::tibble-package] of the pivoted data frame.
#' @autoglobal
#' @export
#' @keywords internal
display_long <- function(df, cols = dplyr::everything()) {

df |> dplyr::mutate(
dplyr::across(
dplyr::everything(), as.character)) |>
tidyr::pivot_longer({{ cols }})
}
17 changes: 15 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The goal of pathologie is to ...

## Installation

You can install the development version of **pathologie** from [GitHub](https://github.com/) with:
You can install **pathologie** from [GitHub](https://github.com/) with:

``` r
# install.packages("pak")
Expand All @@ -33,6 +33,19 @@ pak::pak("andrewallenbruce/pathologie")

This is a basic example which shows you how to solve a common problem:

```{r example}
```{r setup}
library(pathologie)
library(dplyr)
```


```{r}
icd10cm(code = c("I10", "I15.0")) |>
glimpse()
```


```{r}
icd10api(code = "I1")
```

54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ The goal of pathologie is to …

## Installation

You can install the development version of **pathologie** from
[GitHub](https://github.com/) with:
You can install **pathologie** from [GitHub](https://github.com/) with:

``` r
# install.packages("pak")
Expand All @@ -24,4 +23,55 @@ This is a basic example which shows you how to solve a common problem:

``` r
library(pathologie)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
```

``` r
icd10cm(code = c("I10", "I15.0")) |>
glimpse()
#> Rows: 2
#> Columns: 10
#> $ ch <int> 9, 9
#> $ abb <chr> "CARDIO", "CARDIO"
#> $ chapter_name <chr> "Diseases of the circulatory system", "Diseases of the c…
#> $ chapter_range <chr> "I00 - I99", "I00 - I99"
#> $ section_name <chr> "Other rheumatic heart diseases", "Secondary hypertensio…
#> $ section_range <chr> "I09 - I10", "I15 - I15.9"
#> $ order <int> 11397, 11411
#> $ valid <int> 1, 1
#> $ code <chr> "I10", "I15.0"
#> $ description <chr> "Essential (primary) hypertension", "Renovascular hypert…
```

``` r
icd10api(code = "I1")
#> # A tibble: 18 × 2
#> code description
#> <chr> <chr>
#> 1 I10 Essential (primary) hypertension
#> 2 I11.0 Hypertensive heart disease with heart failure
#> 3 I11.9 Hypertensive heart disease without heart failure
#> 4 I12.0 Hypertensive chronic kidney disease with stage 5 chronic kidney disea…
#> 5 I12.9 Hypertensive chronic kidney disease with stage 1 through stage 4 chro…
#> 6 I13.0 Hypertensive heart and chronic kidney disease with heart failure and …
#> 7 I13.10 Hypertensive heart and chronic kidney disease without heart failure, …
#> 8 I13.11 Hypertensive heart and chronic kidney disease without heart failure, …
#> 9 I13.2 Hypertensive heart and chronic kidney disease with heart failure and …
#> 10 I15.0 Renovascular hypertension
#> 11 I15.1 Hypertension secondary to other renal disorders
#> 12 I15.2 Hypertension secondary to endocrine disorders
#> 13 I15.8 Other secondary hypertension
#> 14 I15.9 Secondary hypertension, unspecified
#> 15 I16.0 Hypertensive urgency
#> 16 I16.1 Hypertensive emergency
#> 17 I16.9 Hypertensive crisis, unspecified
#> 18 I1A.0 Resistant hypertension
```
20 changes: 20 additions & 0 deletions man/display_long.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 100 additions & 5 deletions vignettes/pathologie.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,108 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
collapse = FALSE,
echo = TRUE,
message = FALSE,
warning = FALSE,
error = TRUE,
comment = "#>",
dpi = 600,
out.width = "100%"
)
library(dplyr)
library(gt)
library(pathologie)
```

```{r setup}
```{r}
library(pathologie)
```


# ICD-10-CM

```{r}
icd10cm(code = "I10") |>
mutate(Chapter = paste0("* ", chapter_name, " \n ", "* Range: [", chapter_range, "]"),
Section = paste0("* ", section_name, " \n ", "* Range: [", section_range, "]")
) |>
select("ICD-10-Code" = code,
Description = description,
Chapter,
Section,
Abbreviation = abb) |>
display_long() |>
gt(groupname_col = "name",
row_group_as_column = TRUE) |>
fmt_markdown() |>
gt_style(tablign = "right",
tabsize = 16,
tabwt = "bold") |>
tab_style(
style = cell_text(
font = google_font(name = "Fira Code")),
locations = cells_body(
columns = contains("value"))) |>
tab_style(
style = list(
cell_fill(color = "powderblue"),
cell_text(weight = "bold"),
cell_borders(
sides = c("all"),
color = "powderblue",
weight = px(3))
),
locations = cells_row_groups())
```


# The NLM's ICD-10-CM API

The [National Library of Medicine](https://clinicaltables.nlm.nih.gov/apidoc/icd10cm/v3/doc.html)'s ICD-10-CM API is a RESTful API that provides access to the current ICD-10-CM code set.

The API allows users to search for codes by code or keyword(term), and returns the code and its description. Searching is case insensitive and greedy The following are some examples:


> Returns the seven ICD-10 codes beginning with `A15`:
```{r}
icd10api(code = "A15")
```

> Returns all 344 ICD-10 codes associated with tuberculosis:
```{r}
icd10api(term = "tuber")
```

> Returns the two ICD-10 codes associated with pleurisy:
```{r}
icd10api(term = "pleurisy")
```

## The `field` Parameter

The `field` parameter allows users to specify whether they want to search for ICD-10-CM codes by the codes themselves or by terms associated with their description. It defaults to `"code"` and it's behavior warrants some explanation.

If you're searching for codes beginning with a certain letter, you must set the `field` parameter to `"code"` or it will return both codes and terms that contain that letter.


For instance, the following call returns ICD-10 **codes** and **descriptions** containing the letter "Z":


```{r}
icd10api(code = "z", limit = 50)
```


While the call below returns only the ICD-10 **codes** containing "Z":


```{r}
icd10api(code = "z", field = "code", limit = 50)
```

0 comments on commit 34aa11d

Please sign in to comment.