Skip to content

Commit

Permalink
fix previous commit and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgpanw committed Jul 18, 2024
1 parent db384ac commit 7059cb7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
7 changes: 4 additions & 3 deletions R/get_subscribed_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
get_subscribed_metadata <- function(TRUD_API_KEY = NULL,
latest_only = FALSE) {
# validate args
TRUD_API_KEY <- get_trud_api_key(TRUD_API_KEY)
get_trud_api_key(TRUD_API_KEY)

validate_arg_latest_only(latest_only)

Expand All @@ -26,12 +26,13 @@ get_subscribed_metadata <- function(TRUD_API_KEY = NULL,
all_items %>%
dplyr::mutate("metadata" = purrr::map(.data[["item_number"]], \(item_number) tryCatch(
get_item_metadata(
item_number,
item = item_number,
TRUD_API_KEY = TRUD_API_KEY,
latest_only = latest_only
),
error = function(cnd)
httr2_http_404 = function(cnd) {
NA
}
), .progress = TRUE)) |>
dplyr::filter(!is.na(.data[["metadata"]]))
}
6 changes: 6 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ get_item_metadata(394) |>
purrr::map_at("releases", \(release) purrr::map(release, names))
```

Get metadata for all subscribed items:

```{r get-subscribed_metadata}
get_subscribed_metadata()
```

Download an item:

```{r download-item}
Expand Down
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ Retrieve available endpoints[^1]:
library(trud)

trud_items()
#> # A tibble: 70 × 2
#> item_number item_name
#> <int> <chr>
#> 1 246 Cancer Outcomes and Services Data Set XML Schema
#> 2 245 Commissioning Data Set XML Schema
#> 3 599 Community Services Data Set Intermediate Database
#> 4 393 Community Services Data Set post-deadline extract XML Schema
#> 5 394 Community Services Data Set pre-deadline extract XML Schema
#> 6 391 Community Services Data Set XML Schema
#> 7 248 Diagnostic Imaging Data Set XML Schema
#> 8 239 dm+d XML transformation tool
#> 9 1819 Emergency Care Data Set XML Schema
#> 10 263 eViewer application
#> # ℹ 60 more rows
#> # A tibble: 71 × 2
#> item_number item_name
#> <int> <chr>
#> 1 246 Cancer Outcomes and Services Data Set XML Schema
#> 2 245 Commissioning Data Set XML Schema
#> 3 599 Community Services Data Set Intermediate Database
#> 4 393 Community Services Data Set post-deadline extract XML Schema
#> 5 394 Community Services Data Set pre-deadline extract XML Schema
#> 6 391 Community Services Data Set XML Schema
#> 7 248 Diagnostic Imaging Data Set XML Schema
#> 8 239 dm+d XML transformation tool
#> 9 1859 Electronic Prescribing and Medicines Administration Data Sets XM…
#> 10 1819 Emergency Care Data Set XML Schema
#> # ℹ 61 more rows
```

Get metadata for an item:
Expand Down Expand Up @@ -107,6 +107,32 @@ get_item_metadata(394) |>
#> [1] "OK"
```

Get metadata for all subscribed items:

``` r
get_subscribed_metadata()
#> ■■■■■■■■■■■■■■■■ 49% | ETA: 2s
#> # A tibble: 16 × 3
#> item_number item_name metadata
#> <int> <chr> <list>
#> 1 394 Community Services Data Set pre-deadline extract XM… <named list>
#> 2 239 dm+d XML transformation tool <named list>
#> 3 263 eViewer application <named list>
#> 4 398 Global Trade Item Number to OPCS-4 code cross refer… <named list>
#> 5 1760 NHS Continuing Health Care (CHC) Data Set - JSON Sc… <named list>
#> 6 719 NHS Continuing Health Care (CHC) Data Set - XML Sch… <named list>
#> 7 9 NHS Data Migration <named list>
#> 8 258 NHS ICD-10 5th Edition data files <named list>
#> 9 8 NHS Read Browser <named list>
#> 10 19 NHS UK Read Codes Clinical Terms Version 3 <named list>
#> 11 255 NHS UK Read Codes Clinical Terms Version 3, Cross M… <named list>
#> 12 24 NHSBSA dm+d <named list>
#> 13 264 OPCS-4 eVersion book <named list>
#> 14 101 SNOMED CT UK Clinical Edition, RF2: Full, Snapshot … <named list>
#> 15 98 SNOMED CT UK Data Migration Workbench <named list>
#> 16 1799 SNOMED CT UK Monolith Edition, RF2: Snapshot <named list>
```

Download an item:

``` r
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-get_subscribed_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ test_that("`get_subscribed_metadata()` runs without error", {
expect_s3_class(result, "tbl")

expect_identical(names(result), c("item_number", "item_name", "metadata"))

# Tests to be run with valid API key, with at least one subscribed item
expect_true(nrow(result) > 0)
})

0 comments on commit 7059cb7

Please sign in to comment.