Skip to content

Commit

Permalink
add api_relationship #2, and make output of doc examples smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdutey committed Nov 12, 2020
1 parent d2be72c commit 520062a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(api_concept_descriptions)
export(api_concepts)
export(api_descriptions)
export(api_descriptions_semantic_tags)
export(api_relationship)
export(api_relationships)
export(api_version)
export(concepts_descendants)
Expand Down
50 changes: 39 additions & 11 deletions R/rest-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
#' commonly \code{"MAIN"}). See \code{\link{snomedizer_options}}.
#' @param catch404 whether to display a warning if the API operation returns a
#' '404 Not Found' status. Default is \code{TRUE}.
#' @param characteristicType a character string indicating whether to include
#' results for: \itemize{
#' \item all relationships: NULL (the default)
#' \item only stated relationships: "STATED_RELATIONSHIP"
#' \item only inferred relationships: "INFERRED_RELATIONSHIP"
#' \item only additional relationships: ""ADDITIONAL_RELATIONSHIP" (for
#' instance, \code{123005000 | Part of (attribute) |})
#' }
#' This parameter corresponds to \code{
#' 900000000000449001 | Characteristic type (core metadata concept)}
#' @param conceptId character string of a SNOMED-CT concept id (for example:
#' \code{"233604007"})
#' @param conceptIds a character vector of SNOMED-CT concept ids (for example:
Expand Down Expand Up @@ -68,16 +78,7 @@
#' @param preferredOrAcceptableIn character vector of description language reference sets
#' (example: \code{"900000000000509007"}).
#' The description must be preferred OR acceptable in at least one of these to match.
#' @param characteristicType a character string indicating whether to include
#' results for: \itemize{
#' \item all relationships: NULL (the default)
#' \item only stated relationships: "STATED_RELATIONSHIP"
#' \item only inferred relationships: "INFERRED_RELATIONSHIP"
#' \item only additional relationships: ""ADDITIONAL_RELATIONSHIP" (for
#' instance, \code{123005000 | Part of (attribute) |})
#' }
#' This parameter corresponds to \code{
#' 900000000000449001 | Characteristic type (core metadata concept)}
#' @param relationshipId string of a relationship concept
#' @param searchMode a character string for the search mode. Must be either
#' \code{"STANDARD"} (default) or \code{"REGEX"}.
#' @param semanticTag character string of a description semantic tag
Expand Down Expand Up @@ -116,7 +117,8 @@
#' api_concepts(conceptIds = c("233604007", "68566005"))
#'
#' # get the content of the server request
#' httr::content(api_concepts(term = "pneumonia"), limit = 1)
#' pneumonia <- httr::content(api_concepts(term = "pneumonia"), limit = 1)
#' str(pneumonia$items[[1]])
NULL

#' @rdname api_operations
Expand Down Expand Up @@ -723,7 +725,33 @@ api_relationships <- function(
}


#' @rdname api_operations
#' @export
api_relationship <- function(
endpoint = snomedizer_options_get("endpoint"),
branch = snomedizer_options_get("branch"),
relationshipId,
catch404 = TRUE,
...) {

stopifnot(length(relationshipId) == 1)

rest_url <- httr::parse_url(endpoint)
rest_url$path <- c(rest_url$path[rest_url$path != ""],
branch,
"relationships",
relationshipId)
.check_rest_query_length1(rest_url)

rest_url <- httr::build_url(rest_url)
rest_result <- GET(rest_url)

if(catch404){
.catch_http_error(rest_result)
}

rest_result
}



3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ snomedizer_version_compatibility <- function(
#' @export
#' @family utilities
#' @examples
#' result_flatten(
#' flattened_results <- result_flatten(
#' api_concepts(term = "pneumonia",
#' activeFilter = TRUE,
#' limit = 10))
#' str(flattened_results)
result_flatten <- function(x) {
x <- httr::content(x, as = "text", encoding = "ISO-8859-1")
x <- jsonlite::fromJSON(x, flatten = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' @family wrapper
#' @examples
#' # Free text search
#' concepts_find("asthma")
#' str(concepts_find("asthma"))
#'
#' # Retrieve multiple concepts
#' concepts_find(conceptIds = c("233604007", "68566005"))
Expand Down
14 changes: 13 additions & 1 deletion man/api_operations.Rd

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

2 changes: 1 addition & 1 deletion man/concepts_find.Rd

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

3 changes: 2 additions & 1 deletion man/result_flatten.Rd

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

11 changes: 11 additions & 0 deletions tests/testthat/test.rest-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,14 @@ test_that("api_relationships", {

expect_equal(api_relationships()$status_code, 200)
})


# api_relationship --------------------------------------------------------

test_that("api_relationship", {
expect_error(api_relationship())
is_a <- result_flatten(api_relationship(relationshipId = "1698297027"))
expect_equal(is_a$source.conceptId, "312119006")
expect_equal(is_a$type.conceptId, "116680003")
expect_equal(is_a$target.conceptId, "50417007")
})

0 comments on commit 520062a

Please sign in to comment.