From f458f9223196041bb69d36e0b64ecf1fcb5573d9 Mon Sep 17 00:00:00 2001 From: 4478023 Date: Wed, 31 May 2023 16:54:33 +0000 Subject: [PATCH 1/2] Adds functions to call Comprehend Medical's ontology linking APIs --- NAMESPACE | 3 ++ NEWS.md | 2 + R/infer_icd10.R | 22 +++++++++++ R/infer_rxnorm.R | 22 +++++++++++ R/infer_snowmed_ct.R | 22 +++++++++++ man/infer_icd10.Rd | 34 +++++++++++++++++ man/infer_rxnorm.Rd | 34 +++++++++++++++++ man/infer_snowmed_ct.Rd | 34 +++++++++++++++++ tests/testthat/helper-medical_mocks.R | 5 ++- .../comprehendHTTP_medical/InferICD10CM.rds | Bin 0 -> 594 bytes .../comprehendHTTP_medical/InferRxNorm.rds | Bin 0 -> 506 bytes .../comprehendHTTP_medical/InferSNOMEDCT.rds | Bin 0 -> 631 bytes tests/testthat/test-infer_icd10.R | 35 +++++++++++++++++ tests/testthat/test-infer_rxnorm.R | 36 ++++++++++++++++++ tests/testthat/test-infer_snowmed_ct.R | 36 ++++++++++++++++++ 15 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 R/infer_icd10.R create mode 100644 R/infer_rxnorm.R create mode 100644 R/infer_snowmed_ct.R create mode 100644 man/infer_icd10.Rd create mode 100644 man/infer_rxnorm.Rd create mode 100644 man/infer_snowmed_ct.Rd create mode 100644 tests/testthat/mocks/comprehendHTTP_medical/InferICD10CM.rds create mode 100644 tests/testthat/mocks/comprehendHTTP_medical/InferRxNorm.rds create mode 100644 tests/testthat/mocks/comprehendHTTP_medical/InferSNOMEDCT.rds create mode 100644 tests/testthat/test-infer_icd10.R create mode 100644 tests/testthat/test-infer_rxnorm.R create mode 100644 tests/testthat/test-infer_snowmed_ct.R diff --git a/NAMESPACE b/NAMESPACE index b53124d..ec22612 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,9 @@ export(detect_medical_phi) export(detect_phrases) export(detect_sentiment) export(detect_syntax) +export(infer_icd10) +export(infer_rxnorm) +export(infer_snowmed_ct) import(httr) importFrom(aws.signature,locate_credentials) importFrom(aws.signature,signature_v4_auth) diff --git a/NEWS.md b/NEWS.md index a45a4c8..d6010b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # aws.comprehend (development version) +* Added `infer_icd10`, `infer_rxnorm`, and `infer_snowmed_ct` functions to call Comprehend Medical's ontology linking APIs. + # aws.comprehend 0.2.1 * Released on CRAN 2020-03-18 diff --git a/R/infer_icd10.R b/R/infer_icd10.R new file mode 100644 index 0000000..bcebfe3 --- /dev/null +++ b/R/infer_icd10.R @@ -0,0 +1,22 @@ +#' @title Detect conditions and associated ICD10 codes in a source medical text +#' @description Detect detect possible medical conditions as entities and link them to ICD10 codes in a source medical text +#' @param text A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element. +#' @param language A character string containing a two-letter language code. Currently only \dQuote{en} is supported. +#' @param \dots Additional arguments passed to \code{\link{comprehendHTTP}}. +#' @return A data frame +#' @references \href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-icd10.html}{AWS Comprehend Medical Developer Guide} +#' @examples +#' \dontrun{ +#' # simple example +#' infer_icd10("Mrs. Smith comes in today complaining of shortness of breath.") +#' +#' txt <-c("Mrs. Smith comes in today.", +#' "She is complaining of shortnesss of breath.") +#' infer_icd10(txt) +#' } +#' @export +infer_icd10 <- function(text, language = "en", ...) { + bod <- list(Text = text, LanguageCode = language) + out <- comprehendHTTP(action = "InferICD10CM", body = bod, service = "comprehendmedical", ...) + return(cbind(Index = 0, out$Entities)) + } diff --git a/R/infer_rxnorm.R b/R/infer_rxnorm.R new file mode 100644 index 0000000..02aa9e1 --- /dev/null +++ b/R/infer_rxnorm.R @@ -0,0 +1,22 @@ +#' @title Identify medications in a source medical text +#' @description Identify medications in a source medical text and link them to RxCUI codes +#' @param text A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element. +#' @param language A character string containing a two-letter language code. Currently only \dQuote{en} is supported. +#' @param \dots Additional arguments passed to \code{\link{comprehendHTTP}}. +#' @return A data frame +#' @references \href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-RxNorm.html}{AWS Comprehend Medical Developer Guide} +#' @examples +#' \dontrun{ +#' # simple example +#' infer_rxnorm("fluoride topical ( fluoride 1.1 % topical gel ) 1 application Topically daily. Patient is not on warfarin.") +#' +#' txt <-c("fluoride topical ( fluoride 1.1 % topical gel ) 1 application Topically daily.", +#' "Patient is not on warfarin.") +#' infer_rxnorm(txt) +#' } +#' @export +infer_rxnorm <- function(text, language = "en", ...) { + bod <- list(Text = text, LanguageCode = language) + out <- comprehendHTTP(action = "InferRxNorm", body = bod, service = "comprehendmedical", ...) + return(cbind(Index = 0, out$Entities)) +} diff --git a/R/infer_snowmed_ct.R b/R/infer_snowmed_ct.R new file mode 100644 index 0000000..700b499 --- /dev/null +++ b/R/infer_snowmed_ct.R @@ -0,0 +1,22 @@ +#' @title Identify clinical terms in a source medical text +#' @description Identify clinical terms in a source medical text and link them to Systematized Nomenclature of Medicine, Clinical Terms (SNOMED CT) codes +#' @param text A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element. +#' @param language A character string containing a two-letter language code. Currently only \dQuote{en} is supported. +#' @param \dots Additional arguments passed to \code{\link{comprehendHTTP}}. +#' @return A data frame +#' @references \href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-linking-snomed.html}{AWS Comprehend Medical Developer Guide} +#' @examples +#' \dontrun{ +#' # simple example +#' infer_snowmed_ct("BHEENT : Boggy inferior turbinates. No oropharyngeal lesion.") +#' +#' txt <-c("BHEENT : Boggy inferior turbinates.", +#' "No oropharyngeal lesion.") +#' infer_snowmed_ct(txt) +#' } +#' @export +infer_snowmed_ct <- function(text, language = "en", ...) { + bod <- list(Text = text, LanguageCode = language) + out <- comprehendHTTP(action = "InferSNOMEDCT", body = bod, service = "comprehendmedical", ...) + return(cbind(Index = 0, out$Entities)) +} diff --git a/man/infer_icd10.Rd b/man/infer_icd10.Rd new file mode 100644 index 0000000..0f209ce --- /dev/null +++ b/man/infer_icd10.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/infer_icd10.R +\name{infer_icd10} +\alias{infer_icd10} +\title{Detect conditions and associated ICD10 codes in a source medical text} +\usage{ +infer_icd10(text, language = "en", ...) +} +\arguments{ +\item{text}{A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element.} + +\item{language}{A character string containing a two-letter language code. Currently only \dQuote{en} is supported.} + +\item{\dots}{Additional arguments passed to \code{\link{comprehendHTTP}}.} +} +\value{ +A data frame +} +\description{ +Detect detect possible medical conditions as entities and link them to ICD10 codes in a source medical text +} +\examples{ +\dontrun{ + # simple example + infer_icd10("Mrs. Smith comes in today complaining of shortness of breath.") + + txt <-c("Mrs. Smith comes in today.", + "She is complaining of shortnesss of breath.") + infer_icd10(txt) +} +} +\references{ +\href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-icd10.html}{AWS Comprehend Medical Developer Guide} +} diff --git a/man/infer_rxnorm.Rd b/man/infer_rxnorm.Rd new file mode 100644 index 0000000..3ca5534 --- /dev/null +++ b/man/infer_rxnorm.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/infer_rxnorm.R +\name{infer_rxnorm} +\alias{infer_rxnorm} +\title{Identify medications in a source medical text} +\usage{ +infer_rxnorm(text, language = "en", ...) +} +\arguments{ +\item{text}{A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element.} + +\item{language}{A character string containing a two-letter language code. Currently only \dQuote{en} is supported.} + +\item{\dots}{Additional arguments passed to \code{\link{comprehendHTTP}}.} +} +\value{ +A data frame +} +\description{ +Identify medications in a source medical text and link them to RxCUI codes +} +\examples{ +\dontrun{ + # simple example + infer_rxnorm("fluoride topical ( fluoride 1.1 \% topical gel ) 1 application Topically daily. Patient is not on warfarin.") + + txt <-c("fluoride topical ( fluoride 1.1 \% topical gel ) 1 application Topically daily.", + "Patient is not on warfarin.") + infer_rxnorm(txt) +} +} +\references{ +\href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-RxNorm.html}{AWS Comprehend Medical Developer Guide} +} diff --git a/man/infer_snowmed_ct.Rd b/man/infer_snowmed_ct.Rd new file mode 100644 index 0000000..b0dbcb8 --- /dev/null +++ b/man/infer_snowmed_ct.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/infer_snowmed_ct.R +\name{infer_snowmed_ct} +\alias{infer_snowmed_ct} +\title{Identify clinical terms in a source medical text} +\usage{ +infer_snowmed_ct(text, language = "en", ...) +} +\arguments{ +\item{text}{A character string containing a text to entities analyze, or a character vector to perform analysis separately for each element.} + +\item{language}{A character string containing a two-letter language code. Currently only \dQuote{en} is supported.} + +\item{\dots}{Additional arguments passed to \code{\link{comprehendHTTP}}.} +} +\value{ +A data frame +} +\description{ +Identify clinical terms in a source medical text and link them to Systematized Nomenclature of Medicine, Clinical Terms (SNOMED CT) codes +} +\examples{ +\dontrun{ + # simple example + infer_snowmed_ct("BHEENT : Boggy inferior turbinates. No oropharyngeal lesion.") + + txt <-c("BHEENT : Boggy inferior turbinates.", + "No oropharyngeal lesion.") + infer_snowmed_ct(txt) +} +} +\references{ +\href{https://docs.aws.amazon.com/comprehend-medical/latest/dev/ontology-linking-snomed.html}{AWS Comprehend Medical Developer Guide} +} diff --git a/tests/testthat/helper-medical_mocks.R b/tests/testthat/helper-medical_mocks.R index 79b6544..43afb41 100644 --- a/tests/testthat/helper-medical_mocks.R +++ b/tests/testthat/helper-medical_mocks.R @@ -20,7 +20,10 @@ generate_mocks_medical <- function() { actions <- list( "DetectPHI" = body$medical, "DetectEntities" = body$medical, - "DetectEntitiesV2" = body$medical + "DetectEntitiesV2" = body$medical, + "InferICD10CM" = body$medical, + "InferRxNorm" = body$medical, + "InferSNOMEDCT" = body$medical ) mapply(generate_mock_medical, names(actions), actions) diff --git a/tests/testthat/mocks/comprehendHTTP_medical/InferICD10CM.rds b/tests/testthat/mocks/comprehendHTTP_medical/InferICD10CM.rds new file mode 100644 index 0000000000000000000000000000000000000000..36b635d20f5eaf2ec1ef6a628e71017fecfa7eb9 GIT binary patch literal 594 zcmV-Y0SoU!`5YW!{WZ_UpIu%YbrPP-NO&4)*RuiFX+ zL9e?2zWcY(yl~zm7ftfoquQ=p-!WeCL2b|7H_rOAJOCLXcw&Bc2gDhHM0*35ih|hKR*jM3_p*xbo6inylOX7~=#YA{a-Qmtjgpf+I2_ z7#YZ|fQAUaPD6>In4>4zm|%)c{6;g9&SlShESwKAwwEr zJcqT87gF&E(92xyH}WcMN8+#a7>N3?*mjFvkB7>mq)=b$HZm zcG~Cjhui#Yg|_KR#-``i+=}Z}Jg-u#R96^q g>~d`?mCP>oztT}+h@W6Cv;tJsKUk&+IyD3U025~xo&W#< literal 0 HcmV?d00001 diff --git a/tests/testthat/mocks/comprehendHTTP_medical/InferRxNorm.rds b/tests/testthat/mocks/comprehendHTTP_medical/InferRxNorm.rds new file mode 100644 index 0000000000000000000000000000000000000000..49cc56076ee9016a613db0e008b3b51028359fd1 GIT binary patch literal 506 zcmVTyaiN)U$fV7oZ5PG<=v z@o7pZN}%P~o;4X;ghr{wqLUP|`#s!$d+?xWC8+B<)+Dw5Pt@c@PdEbMcQ9s%VD8iq zWpsXgzq;W{=galoCm}x%f93M#!^c}8FTXy%&F5k2r6JUCG=Z7yg`xWDlSF0o@Bn5p zMbkW%^f`_Rg;kn21xh-P1=CUZQbNBPx+vRzg zw(b|R`g`5Vz>ULT5FGXVH-m0JSZ1ItBxYUZ*kz2OllP3LB1_(fV}ysJQC1AkHvK+GsY!*xwmq~f zdy#dTOu7SU5++l2i85efLwMhL^UU*p%rkRZ0syE$ zQ*uDfGZ*AfCa(@#04NXGLK8N}zI(#HVPR$MYoN$C1aOXG<{YGg4@U&gZ~*-Yx}?@Q zB+#LVaMU$R$0>PUNzE-tr8vy6-5>PqzSTWGvqnR^Kk1K#De#MwpSvMlCs74aUJwE-vFBlD;nSra z`v^rinCWE?2QG7-3(%u6|D(G&4vCA1UY4E&JWT)*q-Jg2%=O$*%Zb zJ3SYtR8lyG!E6C%8zH@Bj|cm0vpFVpZn0>x!_-S7h Date: Wed, 31 May 2023 17:06:00 +0000 Subject: [PATCH 2/2] Add name to DESCRIPTION per PR template --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a21cf17..c96f9d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,9 @@ Authors@R: c(person("Thomas J.", "Leeper", role = c("aut"), person("Antoine", "Sachet", role = c("aut", "cre"), email = "antoine.sac@gmail.com"), person("Dave", "Kincaid", role = c("ctb"), - email = "dave@kincaidlabs.ai")) + email = "dave@kincaidlabs.ai"), + person("Robert", "Norberg", role = c("ctb"), + email = "Robert.Norberg@moffitt.org")) Description: Client for 'AWS Comprehend' , a cloud natural language processing service that can perform a number of quantitative text analyses, including language detection, sentiment analysis, and feature extraction. License: GPL (>= 2) URL: https://github.com/cloudyr/aws.comprehend