From a32f53dd70380dd79c3faa20cf8d8af251829fd8 Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 11:47:46 -0400 Subject: [PATCH 1/8] New schema --- data/schema_1_0_0.rda | Bin 1444 -> 0 bytes data/schema_1_1_0.rda | Bin 0 -> 1951 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 data/schema_1_0_0.rda create mode 100644 data/schema_1_1_0.rda diff --git a/data/schema_1_0_0.rda b/data/schema_1_0_0.rda deleted file mode 100644 index 226d54d15cdce226df77f23f4312b97a7d412598..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1444 zcmV;V1zY+;T4*^jL0KkKStYs(Z~z49e}MgTK!99l@R4u7-%h{(|M~y{U&dY5>p!Mofm9003w>$&*GQriKD&VrbJQAY@@Q zX{Hcl!bE{IAOy*wG=_$lk5JHPGyrHBq>OJ%^mo}!skC4`E<(~I)G`1>r67=!0XyDa z(K$(BK@taJA>g6k*w`ust&&s}uGo+^WY8L5F@S-jkif+fh$-0cR|J6uun;cLAYuWr z3&eV?I-jATX8)R$TCg*H-3uNf5`B7m-i~ zOUzdVW7TA@L|d;%bUb-2wm=Bkcop_BC{_X%I2gnx9BB`Nz=TMsTu9jzo5mF9a8#;i zR8lfVGDQtKUa*TaA6Vn6az`OIr0Zw`fqrfhdIn%?wM8P6e9*+IF`zin27`FW0j>$y zpr#b>6TLXt`z|yd68f!z>&rQ?m=bessGa^z;6h1FU7%dCPlz~>(Y}RAlSGJmWf{*& z%CakX(Rj|JssY@qh_EwIf45K91bnMDv( z0sil`zmL9L; zr4mZR+9?rg-K>(_YnaI4vLwySEXnsg0;J*XousMIMJZy05ec9Q$R-+#*QKl48ilG< z4R5)w@fE)4CL27(Bn7#U#dM2q69H`w$V+{t;nlrw#TaqJP{Tcd=~!7Zch{%GEm(Uz zJez3gNS=tvBE&B5jZWLS<{YWb7XXMBQp_${2J^1Q$=;`1(IkVxa?1pky=H`)Z8iWj#=tBf zE*!$W=7VT6t4@v6GzZYp!!cM*2FJ8ViwizQP4EpVhk&x_V`5>|K6T)5APa<(0b4GG zg%X`cFlA&KHxS>OX*VS}G8Wnv$U?28*fU17`*%}@)PzKxZt&SB4Ywh@LDi(|4y-%l zn00I@jpY(B*N6q0Nj9GN5x8O|9sBnrZ%JaqO=K|rqfI*<47FTZL*UL?@E4s3Hl#ZR z=fg;9+8{e80OZkd1`W2xlX_X23=uvoQ#Ga&rLIO%&F<2k8 zQEyXiGNn*xO(HKMlgy81>C>0azKy{`p-fA6y$--|s)6sjU@AARQx}p2t6=d8tc#269Y>6^qO~$!C5w0;2$Dow%yOQ2NhQ$27EDk_#EdLRf)UiA{x0N-aG@YebQIv-IE5_$ diff --git a/data/schema_1_1_0.rda b/data/schema_1_1_0.rda new file mode 100644 index 0000000000000000000000000000000000000000..76d9a6624c50cdb5d4fc4c007c6bedb437397bff GIT binary patch literal 1951 zcmV;Q2VnR@T4*^jL0KkKSy9_S#{da)e}MdUL_}PF`mq1E-(SD~|GoeLUw5V1L zmP(-^Km{5DAP|vF5s^vx6D2=QQ_-mO(rKVKs07f+Xb({Ik55!I^#?R)(9;M8m=jF^ zWHd1VXvAn>jDQ@`qeDy}8emN{0g%wd0izM2f-(Rk)JUiR0qE2K00w|E00000b4HB~ zFo0=+G|&b^Ll6dxMurH;08~*3X*2}MHiD;;Y2`mcBTR!DdQbp)Pf!htOA6Ay?_J`C z6R9fLk)a{$2`MOK?uZGb0bkYG2_f#fBuy-d_xjQ0*3MG?+!3NezZ3nLY(@w{Ba<2iE%cn78c9JrB2&yPy46 zL&e2$#k&)2jkR@amC@G2M(*uNvF8QVF}RiG_k5Gd>VWWtm3rZb4=&qujTux90t}<#rin zQLGp?InD{)LKz)Bq%KpxyT2)Jf_ZUgyB&1b4_7YAk*=)co-&sglN;<+`4qoONbELb zGBy>T9O!4Dk&25|`|Qz_uE|J@u^_>_wu@~M@rx$5T3aQhR7#Eg7?B(dty*M@nHg%F zEflli!fBePg=8t!-4%776q8L_mA1=!o*bs)PO1w90br{MrG(L{8g2$R+0x6ZRatdX zv(6e-QB@WSs;a7@g5brOS$WAtT`J5OO0-z3o-r|qvpFiTU|gs%g}aw)l#)5!OcN$& z7q?X?Dq9I~3&Dp-9x^=e5*?74Kh*Z0v{HRfa|dbo97oDN;{z!a(tDnr&Li}al>5FF zZV8n7%6x@LStQjC=KR{FVv2&OD#a8oQiQ2-N}=eX3RF>4RwD#r!5bpW;Lae-SnM6A z_i7syg%uFS2f!;cn2}a~{n@;*M z(bq;#Th*o_bDuzU2}=JuG#~c$wBt1wp1~$Nchff0w0lhEq{?wd2eiTc{XL#XIX^*x zNk_cGN%0h9D5!IMJ$^qwt9d^-_neR2^poj5=h!lmZTq7phNDyMCPqx7=^kmL)!W>5 zDwcj*YFd!kK)fO*LN7+WL@x^&QV{>&8Y|X{0=_n-c_=oR?j!3~KgKbt3-CvPE(E%b zM?ul~i#Lp3kC{@bR#_D(WwuHcJe}_?8y}6W4;SiAt|@pt(Z)R9ZibR#+Vn+fKbD`H zsm!v&Ivpni*CrCoq)aC+7+b>L7)Dz;7TDsbyr{*cGZtX~NEnqY=87N_tDtF~NM;om z02$cSjFA#tl~x$;*@jEn#x-|r&}_?9W#vq`HEpq_HnRzsTOu(k@TR(L9I?O8gyeBy zMiY)ksn;rf>8sC%hI}ob&lw-B>S2Z_D4Pu)-1}1Kk>Gr6MjJdUM`Ie!*9WE3Q?1Rx z$i=HXA0%(S$=3MQRc((-G`e-Uqp_lDkve)(Iuvt$#gkjRf5JVJs*~0~Wj)bO{bbCK zCX!XJmlF~&=RgH+49D#=jm|ke*e1WQz zNT^X5C3G2!#m?%g?$5@>EtM{bqvCOs%)I2rD89Kh+b!~P?)!XaP4$tyIu@;PEU8su zX*j(SX&Y%3WlFVIR(g%1#v$3ZjxD2s`YR$JXb{bpkjs~%mWpYFCfJR!NM=~$&e>Gi z!Zp^u8ch}vRO(YlHXMypgCfj1e)9^$d3g9d?CqMHpOL~z@8>7)kKjAi*oRe-C97n5 zvmZmwHb=zfqqU8b?|lrrn`vWR{jM)_bn89x%Uv1y&n!J@)}K-&@kNunlEOshvIn?S~j!x$efydKY64^D|%GOT0N(<_%X*sRr~(MiFWFqDd$I5DH1 zq>V;-(r(0z&E6@r`JECS$l2m^>TqsU@*-0aq?S%Gm2T*R4e-%Eh94na`#BLVXLFAs z_`I21RXbzMsLVLHCmR!v*mgB Date: Thu, 5 Sep 2024 12:58:03 -0400 Subject: [PATCH 2/8] save progress in reformatting dataset metadata --- R/archive/data_metadata.R | 56 +++++++++ R/data.R | 4 +- R/data_metadata.R | 138 --------------------- R/datasetjson.R | 16 +-- R/file_metadata.R | 247 ++++++++++++++++++++++++-------------- R/validate_dataset_json.R | 4 +- data-raw/data.R | 6 +- 7 files changed, 226 insertions(+), 245 deletions(-) create mode 100644 R/archive/data_metadata.R delete mode 100644 R/data_metadata.R diff --git a/R/archive/data_metadata.R b/R/archive/data_metadata.R new file mode 100644 index 0000000..1ab098a --- /dev/null +++ b/R/archive/data_metadata.R @@ -0,0 +1,56 @@ +#' Create the data metadata container for a Dataset JSON object +#' +#' @param study Study OID value +#' @param metadata_version Metadata version OID value +#' @param metadata_ref Metadata reference (i.e. path to Define.xml) +#' +#' @return data_metadata object +#' @export +#' +#' @examples +#' # Create object directly +#' data_meta <- data_metadata( +#' study = "SOMESTUDY", +#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", +#' metadata_ref = "some/define.xml" +#' ) +#' +#' # Use setter functions +#' data_meta <- data_metadata() +#' data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") +#' data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") +#' data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") +#' +data_metadata <- function(study = NULL, metadata_version = NULL, metadata_ref = NULL) { + + x <- list( + studyOID = study, + metaDataVersionOID = metadata_version, + metaDataRef = metadata_ref, + itemGroupData = NULL + ) + + structure( + x, + class = c("data_metadata", "list") + ) +} + +#' Set data metadata parameters +#' +#' This set of functions +#' @param x data metadata or datasetjson object +#' @param study Study OID value +#' @param ... Additional parameters +#' +#' @return A datasetjson or data_metadata object +#' @export +#' +#' @family Data metadata setters +#' @rdname data_metadata_setters +#' +#' @examples +#' data_meta <- data_metadata() +#' data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") +#' data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") +#' data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") \ No newline at end of file diff --git a/R/data.R b/R/data.R index bc658f8..7f2b9be 100644 --- a/R/data.R +++ b/R/data.R @@ -48,9 +48,9 @@ #' } "sas_time_formats" -#' Dataset JSON Schema Version 1.0.0 +#' Dataset JSON Schema Version 1.1.0 #' -#' This object is a character vector holding the schema for Dataset JSON Version 1.0.0 +#' This object is a character vector holding the schema for Dataset JSON Version 1.1.0 #' #' @format ## `schema_1_0_0` #' \describe{ diff --git a/R/data_metadata.R b/R/data_metadata.R deleted file mode 100644 index 0bf84d2..0000000 --- a/R/data_metadata.R +++ /dev/null @@ -1,138 +0,0 @@ -#' Create the data metadata container for a Dataset JSON object -#' -#' @param study Study OID value -#' @param metadata_version Metadata version OID value -#' @param metadata_ref Metadata reference (i.e. path to Define.xml) -#' -#' @return data_metadata object -#' @export -#' -#' @examples -#' # Create object directly -#' data_meta <- data_metadata( -#' study = "SOMESTUDY", -#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", -#' metadata_ref = "some/define.xml" -#' ) -#' -#' # Use setter functions -#' data_meta <- data_metadata() -#' data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") -#' data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") -#' data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") -#' -data_metadata <- function(study = NULL, metadata_version = NULL, metadata_ref = NULL) { - - x <- list( - studyOID = study, - metaDataVersionOID = metadata_version, - metaDataRef = metadata_ref, - itemGroupData = NULL - ) - - structure( - x, - class = c("data_metadata", "list") - ) -} - -#' Set data metadata parameters -#' -#' This set of functions -#' @param x data metadata or datasetjson object -#' @param study Study OID value -#' @param ... Additional parameters -#' -#' @return A datasetjson or data_metadata object -#' @export -#' -#' @family Data metadata setters -#' @rdname data_metadata_setters -#' -#' @examples -#' data_meta <- data_metadata() -#' data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") -#' data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") -#' data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") -set_study_oid <- function(x, study, ...) { - UseMethod("set_study_oid") -} - -#' @export -#' @noRd -set_study_oid.data_metadata <- function(x, study, ...) { - x[['studyOID']] <- study - x -} - -#' @export -#' @noRd -set_study_oid.datasetjson <- function(x, study, ...) { - data_type <- get_data_type(x) - x[[data_type]][['studyOID']] <- study - x -} - -#' @export -#' @noRd -set_study_oid.default <- function(x, study, ...) { - stopifnot_data_metadata(x) -} - -#' @param metadata_version Metadata version OID value -#' @family Data metadata setters -#' @rdname data_metadata_setters -#' @export -set_metadata_version <- function(x, metadata_version, ...) { - UseMethod("set_metadata_version") -} - -#' @export -#' @noRd -set_metadata_version.data_metadata <- function(x, metadata_version, ...) { - x[['metaDataVersionOID']] <- metadata_version - x -} - -#' @export -#' @noRd -set_metadata_version.datasetjson <- function(x, metadata_version, ...) { - data_type <- get_data_type(x) - x[[data_type]][['metaDataVersionOID']] <- metadata_version - x -} - -#' @export -#' @noRd -set_metadata_version.default <- function(x, metadata_version, ...) { - stopifnot_data_metadata(x) -} - -#' @param metadata_ref Metadata reference (i.e. path to Define.xml) -#' @family Data metadata setters -#' @rdname data_metadata_setters -#' @export -set_metadata_ref <- function(x, metadata_ref) { - UseMethod("set_metadata_ref") -} - -#' @export -#' @noRd -set_metadata_ref.data_metadata <- function(x, metadata_ref) { - x[['metaDataRef']] <- metadata_ref - x -} - -#' @export -#' @noRd -set_metadata_ref.datasetjson <- function(x, metadata_ref) { - data_type <- get_data_type(x) - x[[data_type]][['metaDataRef']] <- metadata_ref - x -} - -#' @export -#' @noRd -set_metadata_ref.default <- function(x, metadata_ref) { - stopifnot_data_metadata(x) -} diff --git a/R/datasetjson.R b/R/datasetjson.R index 9b015ac..4a32dd5 100644 --- a/R/datasetjson.R +++ b/R/datasetjson.R @@ -65,7 +65,7 @@ #' data_meta = data_meta #' ) dataset_json <- function(.data, item_id, name, label, items, dataset_meta, - version="1.0.0", data_type = c('clinicalData', 'referenceData'), + version="1.1.0", data_type = c('clinicalData', 'referenceData'), file_meta = file_metadata(), data_meta = data_metadata() ) { @@ -85,24 +85,24 @@ dataset_json <- function(.data, item_id, name, label, items, dataset_meta, new_dataset_json <- function(version, item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) { - if (!(version %in% c("1.0.0"))) { - stop("Unsupported version specified - currently only version 1.0.0 is supported", call.=FALSE) + if (!(version %in% c("1.1.0"))) { + stop("Unsupported version specified - currently only version 1.1.0 is supported", call.=FALSE) } # List of version specific generators funcs <- list( - "1.0.0" = new_dataset_json_v1_0_0 + "1.1.0" = new_dataset_json_v1_1_0 ) # Extract the function and call it to return the base structure funcs[[version]](item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) } -#' Dataset JSON v1.0.0 Generator +#' Dataset JSON v1.1.0 Generator #' -#' @return datasetjson_v1_0_0 object +#' @return datasetjson_v1_1_0 object #' @noRd -new_dataset_json_v1_0_0 <- function(item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) { +new_dataset_json_v1_1_0 <- function(item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) { if (missing(dataset_meta)) { if (any(missing(item_id), missing(name), missing(label), missing(items))) { @@ -123,6 +123,6 @@ new_dataset_json_v1_0_0 <- function(item_id, data_type, name, label, items, data structure( ds_json, - class = c("datasetjson_v1_0_0", "datasetjson", "list") + class = c("datasetjson_v1_1_0", "datasetjson", "list") ) } diff --git a/R/file_metadata.R b/R/file_metadata.R index 10a2f1f..51f0c97 100644 --- a/R/file_metadata.R +++ b/R/file_metadata.R @@ -1,69 +1,6 @@ -#' Create a file metadata object +#' Dataset Metadata Setters #' -#' @param originator originator parameter, defined as "The organization that -#' generated the Dataset-JSON file." -#' @param sys sourceSystem parameter, defined as "The computer system or -#' database management system that is the source of the information in this -#' file." -#' @param sys_version sourceSystemVersion, defined as "The version of the -#' sourceSystem" -#' @param file_oid fileOID parameter, defined as "A unique identifier for this -#' file." -#' @param version Dataset JSON schema version being used -#' -#' @return file_metadata object -#' @export -#' -#' @examples -#' # Create using parameters -#' file_meta <- file_metadata( -#' originator = "Some Org", -#' sys = "source system", -#' sys_version = "1.0" -#' ) -#' -#' # Set parameters after -#' file_meta <- file_metadata() -#' -#' file_meta_updated <- set_file_oid(file_meta, "/some/path") -#' file_meta_updated <- set_originator(file_meta_updated, "Some Org") -#' file_meta_updated <- set_source_system(file_meta_updated, "source system", "1.0") -file_metadata <- function(originator=NULL, sys = NULL, sys_version = NULL, file_oid = NULL, version = "1.0.0") { - - if (!(version %in% c("1.0.0"))) { - stop("Unsupported version specified - currently only version 1.0.0 is supported", call.=FALSE) - } - - x <- list( - "creationDateTime"= character(), - "datasetJSONVersion"= version, - "fileOID" = file_oid, - "asOfDateTime" = NULL, # Not sure we want this to exist? - "originator" = originator, - "sourceSystem" = sys, - "sourceSystemVersion" = sys_version - ) - - structure( - x, - class = c("file_metadata", "list") - ) -} - -#' Create an ISO8601 formatted datetime of the current time -#' -#' This is used to create the creationDateTime and asOfDateTime attributes of -#' the Dataset JSON object, called at the appropriate time for each attribute -#' -#' @return ISO8601 formatted datetime -#' @noRd -get_datetime <- function() { - format(Sys.time(), "%Y-%m-%dT%H:%M:%S") -} - -#' File Metadata Setters -#' -#' Set information about the file and source system used to generate the Dataset +#' Set information about the file, source system, study, and dataset used to generate the Dataset #' JSON object. #' #' @details @@ -86,54 +23,180 @@ get_datetime <- function() { #' generated the Dataset-JSON file." #' @param file_oid fileOID parameter, defined as "A unique identifier for this #' file." -#' @param data_type Type of data being written. clinicalData for subject level -#' data, and referenceData for non-subject level data (i.e. TDMs, Associated -#' Persons) +#' @param study Study OID value +#' @param metadata_version Metadata version OID value +#' @param metadata_ref Metadata reference (i.e. path to Define.xml) +#' @param item_oid ID used to label dataset with the itemGroupData parameter. +#' Defined as "Object of Datasets. Key value is a unique identifier for +#' Dataset, corresponding to ItemGroupDef/@OID in Define-XML." +#' @param name Dataset name +#' @param dataset_label Dataset Label #' -#' @return datasetjson or file_metadata object +#' @return datasetjson object #' @export -#' @family File Metadata Setters -#' @rdname file_metadata_setters +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters #' #' @examples -#' file_meta <- file_metadata() +#' ds_json <- dataset_json(iris) +#' +#' ds_json <- set_dataset_metadata( +#' iris, +#' file_oid = "/some/path" +#' originator = "Some Org", +#' sys = "source system", +#' sys_version = "1.0", +#' study = "SOMESTUDY", +#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", +#' metadata_ref = "some/define.xml", +#' item_oid = "IG.IRIS", +#' name = "IRIS", +#' dataset_label = "Iris" +#' ) #' -#' file_meta_updated <- set_file_oid(file_meta, "/some/path") -#' file_meta_updated <- set_originator(file_meta_updated, "Some Org") -#' file_meta_updated <- set_source_system(file_meta_updated, "source system", "1.0") +#' # Individual Elements +#' ds_json <- dataset_json(iris) +#' ds_json <- set_file_oid(ds_json, "/some/path") +#' ds_json <- set_study_oid(ds_json, "SOMESTUDY") +#' ds_json <- set_originator(ds_json, "Some Org") +#' ds_json <- set_source_system(ds_json, "source system", "1.0") +#' ds_json <- set_metadata_ref(ds_json, "some/define.xml") +#' ds_json <- set_metadata_version(ds_json, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") +#' ds_json <- set_item_oid(ds_json, "IG.IRIS") +#' ds_json <- set_dataset_name(ds_json, "IRIS") +#' ds_json <- set_dataseT_label(ds_json, "Iris") +set_dataset_metadata <- function(x, file_oid = NULL, originator=NULL, sys = NULL, + sys_version = NULL, study=NULL, metadata_version=NULL, + metadata_ref=NULL, item_oid=NULL, name = NULL, + dataset_label=NULL) { + stopifnot_datasetjson(x) + + if (!is.null(sys) && !is.null(sys_version)) { + attr(x, 'sourceSystem') <- list( + "name" = sys, + "version" = sys_version + ) + } + + attr(x, 'fileOID') <- file_oid + attr(x, 'originator') <- originator + attr(x, 'studyOID') <- study + attr(x, 'metaDataVersionOID') <- metadata_version + attr(x, 'metaDataRef') <- metadata_ref + attr(x, "itemGroupOID") <- item_oid + attr(x, 'records') <- nrow(x) + attr(x, 'name') <- name + attr(x, 'label') <- dataset_label + attr('isReferenceData') <- FALSE + x +} + +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters set_source_system <- function(x, sys, sys_version) { - stopifnot_file_metadata(x) - x[['sourceSystem']] <- sys - x[['sourceSystemVersion']] <- sys_version + stopifnot_datasetjson(x) + attr(x, 'sourceSystem') <- list( + "name" = sys, + "version" = sys_version + ) x } #' @export -#' @family File Metadata Setters -#' @rdname file_metadata_setters +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters set_originator <- function(x, originator) { - stopifnot_file_metadata(x) - x[['originator']] <- originator + stopifnot_datasetjson(x) + attr(x, 'originator') <- originator x } #' @export -#' @family File Metadata Setters -#' @rdname file_metadata_setters +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters set_file_oid <- function(x, file_oid) { - stopifnot_file_metadata(x) - x[['fileOID']] <- file_oid + stopifnot_datasetjson(x) + attr(x, 'fileOID') <- file_oid x } #' @export -#' @family File Metadata Setters -#' @rdname file_metadata_setters -set_data_type <- function(x, data_type = c('clinicalData', 'referenceData')) { +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_study_oid <- function(x, study) { stopifnot_datasetjson(x) - data_type = match.arg(data_type) + attr(x, 'studyOID') <- study + x +} + +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_metadata_version <- function(x, metadata_version) { + stopifnot_datasetjson(x) + attr(x, 'metaDataVersionOID') <- metadata_version + x +} - # For the clinicalData or referenceData, set the parameter correctly - names(x) <- c(names(x[1:7]), data_type) +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_metadata_ref <- function(x, metadata_ref) { + stopifnot_datasetjson(x) + attr(x, 'metaDataRef') <- metadata_ref x } + +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_item_oid <- function(x, item_oid) { + stopifnot_datasetjson(x) + attr(x, "itemGroupOID") <- item_oid +} + +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_dataset_name <- function(x, name) { + stopifnot_datasetjson(x) + attr(x, 'name') <- name +} + +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_dataset_label <- function(x, dataset_label) { + stopifnot_datasetjson(x) + attr(x, 'label') <- dataset_label +} + +#' Declare as reference data +#' +#' Sets DatasetJSON file to have the isReferenceData attribute set to TRUE +#' +#' @param x datasetjson object +#' +#' @return datasetjson object +#' @export +#' +#' @examples +#' ds_json <- dataset_json(iris) +#' ds_json <- set_as_reference_data(ds_json) +set_as_reference_data <- function(x) { + stopifnot_datasetjson(x) + attr(x, 'isReferenceData') <- TRUE +} + + +#' Create an ISO8601 formatted datetime of the current time +#' +#' This is used to create the creationDateTime and asOfDateTime attributes of +#' the Dataset JSON object, called at the appropriate time for each attribute +#' +#' @return ISO8601 formatted datetime +#' @noRd +get_datetime <- function() { + format(Sys.time(), "%Y-%m-%dT%H:%M:%S") +} diff --git a/R/validate_dataset_json.R b/R/validate_dataset_json.R index ae37d0c..096365d 100644 --- a/R/validate_dataset_json.R +++ b/R/validate_dataset_json.R @@ -29,12 +29,12 @@ validate_dataset_json <- function(x) { js <- x } - v <- jsonvalidate::json_validate(js, schema_1_0_0, engine="ajv", verbose=TRUE) + v <- jsonvalidate::json_validate(js, schema_1_1_0, engine="ajv", verbose=TRUE) if (!v) { warning("File contains errors!") return(attr(v, 'errors')) } else { - message("File is valid per the Dataset JSON v1.0.0 schema\n") + message("File is valid per the Dataset JSON v1.1.0 schema\n") data.frame( instancePath = character(), schemaPath = character(), diff --git a/data-raw/data.R b/data-raw/data.R index 83a1dc9..1444d4c 100644 --- a/data-raw/data.R +++ b/data-raw/data.R @@ -138,6 +138,6 @@ sas_time_formats <- c( usethis::use_data(sas_time_formats, overwrite = TRUE) # Dataset JSON Schema V1.0.0 as Character Vector -schema_file <- test_path("testdata", "dataset.schema.json") -schema_1_0_0 = readChar(schema_file, file.info(schema_file)$size) -usethis::use_data(schema_1_0_0, overwrite=TRUE) +schema_file <- testthat::test_path("testdata", "dataset.schema.json") +schema_1_1_0 = readChar(schema_file, file.info(schema_file)$size) +usethis::use_data(schema_1_1_0, overwrite=TRUE) From 945b6621671cb0012c45584a7f6f9097c7789118 Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 14:40:29 -0400 Subject: [PATCH 3/8] Modifications for new schema --- R/column_classes.R | 32 +++++++++++ R/data.R | 37 +----------- R/datasetjson.R | 139 +++++++++++++++++++++++---------------------- R/file_metadata.R | 48 +--------------- R/global.R | 4 +- 5 files changed, 106 insertions(+), 154 deletions(-) create mode 100644 R/column_classes.R diff --git a/R/column_classes.R b/R/column_classes.R new file mode 100644 index 0000000..2e19aac --- /dev/null +++ b/R/column_classes.R @@ -0,0 +1,32 @@ +# This file contains several helpers for reading and writing date / datetime +# columns from a Dataset JSON file + +#' Get the column classes off a data frame +#' +#' @param x A data.frame +#' +#' @return Named character vector of columns and types +#' @noRd +get_column_classes <- function(x) { + vapply(x, function(X) class(X)[1], FUN.VALUE=character(1)) +} + +#' Get the columns with a class of Date from a data.frame +#' +#' @param x A data.frame +#' +#' @return A data.frame +#' @noRd +get_date_cols <- function(x) { + x[get_column_classes(x) == "Date"] +} + +#' Get the columns with a class of POSIXct from a data.frame +#' +#' @param x A data.frame +#' +#' @return A data.frame +#' @noRd +get_datetime_cols <- function(x) { + x[get_column_classes(x) == "POSIXct"] +} diff --git a/R/data.R b/R/data.R index 7f2b9be..124a1ef 100644 --- a/R/data.R +++ b/R/data.R @@ -15,45 +15,12 @@ #' } "iris_items" -#' A List of valid SAS(c) date formats -#' -#' Valid SAS(c) date formats pulled from -#' https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -#' -#' @format ## `sas_date_formats` -#' \describe{ -#' A character vector with 45 elements -#' } -"sas_date_formats" - -#' A List of valid SAS(c) datetime formats -#' -#' Valid SAS(c) datetime formats pulled from -#' https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -#' -#' @format ## `sas_datetime_formats` -#' \describe{ -#' A character vector with 7 elements -#' } -"sas_datetime_formats" - -#' A List of valid SAS(c) time formats -#' -#' Valid SAS(c) time formats pulled from -#' https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -#' -#' @format ## `sas_time_formats` -#' \describe{ -#' A character vector with 4 elements -#' } -"sas_time_formats" - #' Dataset JSON Schema Version 1.1.0 #' #' This object is a character vector holding the schema for Dataset JSON Version 1.1.0 #' -#' @format ## `schema_1_0_0` +#' @format ## `schema_1_1_0` #' \describe{ #' A character vector with 1 element #' } -"schema_1_0_0" +"schema_1_1_0" diff --git a/R/datasetjson.R b/R/datasetjson.R index 4a32dd5..840eed0 100644 --- a/R/datasetjson.R +++ b/R/datasetjson.R @@ -2,24 +2,30 @@ #' #' Create the base object used to write a Dataset JSON file. #' +#' @details +#' +#' Note that DatasetJSON is on version 1.1.0. Based off findings from the pilot, +#' version 1.1.0 reflects feedback from the user community. Support for 1.0.0 has +#' been deprecated. +#' #' @param .data Input data to contain within the Dataset JSON file. Written to #' the itemData parameter. -#' @param item_id ID used to label dataset with the itemGroupData parameter. +#' @param sys sourceSystem parameter, defined as "The computer system or +#' database management system that is the source of the information in this +#' file." +#' @param sys_version sourceSystemVersion, defined as "The version of the +#' sourceSystem" +#' @param originator originator parameter, defined as "The organization that +#' generated the Dataset-JSON file." +#' @param file_oid fileOID parameter, defined as "A unique identifier for this +#' file." +#' @param study Study OID value +#' @param metadata_version Metadata version OID value +#' @param metadata_ref Metadata reference (i.e. path to Define.xml) +#' @param item_oid ID used to label dataset with the itemGroupData parameter. #' Defined as "Object of Datasets. Key value is a unique identifier for #' Dataset, corresponding to ItemGroupDef/@OID in Define-XML." -#' @param name Dataset name -#' @param label Dataset Label -#' @param items Variable metadata -#' @param dataset_meta A dataset_metadata object holding pre-specified -#' dataset metadata. -#' @param version Version of Dataset JSON schema to follow. -#' @param data_type Type of data being written. clinicalData for subject level -#' data, and referenceData for non-subject level data (i.e. TDMs, Associated -#' Persons) -#' @param file_meta A file_metadata object holding pre-specified file -#' metadata -#' @param data_meta A data_metadata object holding pre-specified data -#' metadata +#' @param version The DatasetJSON version to use. Currently only 1.1.0 is supported. #' #' @return dataset_json object pertaining to the specific Dataset JSON version #' specific @@ -27,7 +33,19 @@ #' #' @examples #' # Create a basic object -#' ds_json <- dataset_json(iris, "IG.IRIS", "IRIS", "Iris", iris_items) +#' ds_json <- dataset_json( +#' iris, +#' file_oid = "/some/path" +#' originator = "Some Org", +#' sys = "source system", +#' sys_version = "1.0", +#' study = "SOMESTUDY", +#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", +#' metadata_ref = "some/define.xml", +#' item_oid = "IG.IRIS", +#' name = "IRIS", +#' dataset_label = "Iris" +#' ) #' #' # Attach attributes directly #' ds_json_updated <- set_data_type(ds_json, "referenceData") @@ -37,40 +55,15 @@ #' ds_json_updated <- set_originator(ds_json_updated, "Some Org") #' ds_json_updated <- set_source_system(ds_json_updated, "source system", "1.0") #' ds_json_updated <- set_study_oid(ds_json_updated, "SOMESTUDY") -#' -#' # Create independent objects for metadata sections first -#' file_meta <- file_metadata( -#' originator = "Some Org", -#' sys = "source system", -#' sys_version = "1.0" -#' ) -#' -#' data_meta <- data_metadata( -#' study = "SOMESTUDY", -#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", -#' metadata_ref = "some/define.xml" -#' ) -#' -#' dataset_meta <- dataset_metadata( -#' item_id = "IG.IRIS", -#' name = "IRIS", -#' label = "Iris", -#' items = iris_items -#' ) -#' -#' ds_json_from_meta <- dataset_json( -#' iris, -#' dataset_meta = dataset_meta, -#' file_meta = file_meta, -#' data_meta = data_meta -#' ) -dataset_json <- function(.data, item_id, name, label, items, dataset_meta, - version="1.1.0", data_type = c('clinicalData', 'referenceData'), - file_meta = file_metadata(), - data_meta = data_metadata() - ) { - data_type = match.arg(data_type) - new_dataset_json(version, item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) +#' ds_json_updated <- set_item_oid(ds_json_updated, "IG.IRIS") +#' ds_json_updated <- set_dataset_name(ds_json_updated, "IRIS") +#' ds_json_updated <- set_dataseT_label(ds_json_updated, "Iris") +dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, + sys_version = NULL, study=NULL, metadata_version=NULL, + metadata_ref=NULL, item_oid=NULL, name=NULL, + dataset_label=NULL, version="1.1.0") { + new_dataset_json(.data, file_oid, originator, sys, sys_version, study, metadata_version, + metadata_ref, item_oid, name, dataset_label, version) } #' Create a base Dataset JSON Container @@ -82,8 +75,9 @@ dataset_json <- function(.data, item_id, name, label, items, dataset_meta, #' @return datasetjson object #' #' @noRd -new_dataset_json <- function(version, item_id, data_type, name, label, items, - dataset_meta, file_meta, data_meta, .data) { +new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, study, + metadata_version, metadata_ref, item_oid, name, dataset_label, + version) { if (!(version %in% c("1.1.0"))) { stop("Unsupported version specified - currently only version 1.1.0 is supported", call.=FALSE) @@ -95,34 +89,41 @@ new_dataset_json <- function(version, item_id, data_type, name, label, items, ) # Extract the function and call it to return the base structure - funcs[[version]](item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) + funcs[[version]](.data, file_oid, originator, sys, sys_version, study, + metadata_version, metadata_ref, item_oid, name, dataset_label) } #' Dataset JSON v1.1.0 Generator #' #' @return datasetjson_v1_1_0 object #' @noRd -new_dataset_json_v1_1_0 <- function(item_id, data_type, name, label, items, dataset_meta, file_meta, data_meta, .data) { - - if (missing(dataset_meta)) { - if (any(missing(item_id), missing(name), missing(label), missing(items))) { - stop("If dataset_meta is not provided, then name, label, and items must be provided", call.=FALSE) - } +new_dataset_json_v1_1_0 <- function(.data, file_oid, originator, sys, sys_version, study, + metadata_version, metadata_ref, item_oid, name, dataset_label) { - # Create the dataset metadata with provided info - dataset_meta <- dataset_metadata(item_id, name, label, items) + if (!inherits(.data, 'data.frame')) { + stop("datasetjson objects must inherit from a data.frame", call.=FALSE) } - # Attach .data into dataset_meta - dataset_meta <- set_item_data(dataset_meta, .data) - - # Combine file_meta, data_meta, and dataset_meta together - ds_json <- file_meta - ds_json[[data_type]] <- data_meta - ds_json[[data_type]][['itemGroupData']] <- dataset_meta + if (!is.null(sys) && !is.null(sys_version)) { + attr(.data, 'sourceSystem') <- list( + "name" = sys, + "version" = sys_version + ) + } + attr(.data, 'fileOID') <- file_oid + attr(.data, 'originator') <- originator + attr(.data, 'studyOID') <- study + attr(.data, 'metaDataVersionOID') <- metadata_version + attr(.data, 'metaDataRef') <- metadata_ref + attr(.data, "itemGroupOID") <- item_oid + attr(.data, 'records') <- nrow(x) + attr(.data, 'name') <- name + attr(.data, 'label') <- dataset_label + attr(.data, 'isReferenceData') <- FALSE + structure( - ds_json, - class = c("datasetjson_v1_1_0", "datasetjson", "list") + .data, + class = c("datasetjson_v1_1_0", "datasetjson", "data.frame") ) } diff --git a/R/file_metadata.R b/R/file_metadata.R index 51f0c97..e0ca4cd 100644 --- a/R/file_metadata.R +++ b/R/file_metadata.R @@ -39,23 +39,6 @@ #' #' @examples #' ds_json <- dataset_json(iris) -#' -#' ds_json <- set_dataset_metadata( -#' iris, -#' file_oid = "/some/path" -#' originator = "Some Org", -#' sys = "source system", -#' sys_version = "1.0", -#' study = "SOMESTUDY", -#' metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", -#' metadata_ref = "some/define.xml", -#' item_oid = "IG.IRIS", -#' name = "IRIS", -#' dataset_label = "Iris" -#' ) -#' -#' # Individual Elements -#' ds_json <- dataset_json(iris) #' ds_json <- set_file_oid(ds_json, "/some/path") #' ds_json <- set_study_oid(ds_json, "SOMESTUDY") #' ds_json <- set_originator(ds_json, "Some Org") @@ -64,36 +47,7 @@ #' ds_json <- set_metadata_version(ds_json, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") #' ds_json <- set_item_oid(ds_json, "IG.IRIS") #' ds_json <- set_dataset_name(ds_json, "IRIS") -#' ds_json <- set_dataseT_label(ds_json, "Iris") -set_dataset_metadata <- function(x, file_oid = NULL, originator=NULL, sys = NULL, - sys_version = NULL, study=NULL, metadata_version=NULL, - metadata_ref=NULL, item_oid=NULL, name = NULL, - dataset_label=NULL) { - stopifnot_datasetjson(x) - - if (!is.null(sys) && !is.null(sys_version)) { - attr(x, 'sourceSystem') <- list( - "name" = sys, - "version" = sys_version - ) - } - - attr(x, 'fileOID') <- file_oid - attr(x, 'originator') <- originator - attr(x, 'studyOID') <- study - attr(x, 'metaDataVersionOID') <- metadata_version - attr(x, 'metaDataRef') <- metadata_ref - attr(x, "itemGroupOID") <- item_oid - attr(x, 'records') <- nrow(x) - attr(x, 'name') <- name - attr(x, 'label') <- dataset_label - attr('isReferenceData') <- FALSE - x -} - -#' @export -#' @family Dataset Metadata Setters -#' @rdname dataset_metadata_setters +#' ds_json <- set_dataset_label(ds_json, "Iris") set_source_system <- function(x, sys, sys_version) { stopifnot_datasetjson(x) attr(x, 'sourceSystem') <- list( diff --git a/R/global.R b/R/global.R index 3bf88eb..089e027 100644 --- a/R/global.R +++ b/R/global.R @@ -1,5 +1,3 @@ globalVariables(c( - "schema_1_0_0", - "sas_date_formats", - "sas_datetime_formats" + "schema_1_1_0" )) From 3ace7ac17ce21e0b4329cb6c9d35b0704ce78a85 Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 14:40:45 -0400 Subject: [PATCH 4/8] archive --- R/{ => archive}/dataset_metadata.R | 0 R/date_time_conversions.R | 65 ------------------------------ 2 files changed, 65 deletions(-) rename R/{ => archive}/dataset_metadata.R (100%) delete mode 100644 R/date_time_conversions.R diff --git a/R/dataset_metadata.R b/R/archive/dataset_metadata.R similarity index 100% rename from R/dataset_metadata.R rename to R/archive/dataset_metadata.R diff --git a/R/date_time_conversions.R b/R/date_time_conversions.R deleted file mode 100644 index 9097c0c..0000000 --- a/R/date_time_conversions.R +++ /dev/null @@ -1,65 +0,0 @@ -# This file contains several helpers for reading and writing date / datetime -# columns from a Dataset JSON file - -#' Get the column classes off a data frame -#' -#' @param x A data.frame -#' -#' @return Named character vector of columns and types -#' @noRd -get_column_classes <- function(x) { - vapply(x, function(X) class(X)[1], FUN.VALUE=character(1)) -} - -#' Get the columns with a class of Date from a data.frame -#' -#' @param x A data.frame -#' -#' @return A data.frame -#' @noRd -get_date_cols <- function(x) { - x[get_column_classes(x) == "Date"] -} - -#' Get the columns with a class of POSIXct from a data.frame -#' -#' @param x A data.frame -#' -#' @return A data.frame -#' @noRd -get_datetime_cols <- function(x) { - x[get_column_classes(x) == "POSIXct"] -} - -#' Convert a Date object in R to a SAS date origin -#' -#' R uses POSIX date origins, and SAS uses a date origin of 1960-01-01, so to -#' convert you need to add 10 years (plus three leap year days) in days -#' -#' @param x A data.frame -#' -#' @return A data.frame -#' @noRd -convert_to_sas_datenum <- function(x) { - col_names <- names(get_date_cols(x)) - # Add 10 years in days (including 3 leap year days) - x[col_names] <- lapply(get_date_cols(x) + (365 * 10) + 3, as.numeric) - x -} - -#' Convert a POSIXct object in R to a SAS date origin -#' -#' R uses POSIX date origins, and SAS uses a date origin of 1960-01-01, so to -#' convert you need to add 10 years (plus three leap year days) in seconds -#' -#' @param x A data.frame -#' -#' @return A data.frame -#' @noRd -convert_to_sas_datetimenum <- function(x) { - col_names <- names(get_datetime_cols(x)) - # Add 10 years in seconds (including 3 leap year days) - x[col_names] <- lapply(get_datetime_cols(x) + (365 * 24 * 60 * 60 * 10) + (3 * 24 * 60 * 60), as.numeric) - - x -} From 70f4aa3f6a03056769110167a39b8eeb51606741 Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 14:41:11 -0400 Subject: [PATCH 5/8] Update docs --- NAMESPACE | 17 +--- data-raw/data.R | 73 ---------------- data/iris_items.rda | Bin 334 -> 334 bytes man/data_metadata.Rd | 36 -------- man/data_metadata_setters.Rd | 38 --------- man/dataset_json.Rd | 101 +++++++++++------------ man/dataset_metadata.Rd | 34 -------- man/dataset_metadata_setters.Rd | 91 ++++++++++++++++++++ man/file_metadata.Rd | 51 ------------ man/file_metadata_setters.Rd | 61 -------------- man/sas_date_formats.Rd | 22 ----- man/sas_datetime_formats.Rd | 22 ----- man/sas_time_formats.Rd | 22 ----- man/{schema_1_0_0.Rd => schema_1_1_0.Rd} | 12 +-- man/set_as_reference_data.Rd | 21 +++++ 15 files changed, 170 insertions(+), 431 deletions(-) delete mode 100644 man/data_metadata.Rd delete mode 100644 man/data_metadata_setters.Rd delete mode 100644 man/dataset_metadata.Rd create mode 100644 man/dataset_metadata_setters.Rd delete mode 100644 man/file_metadata.Rd delete mode 100644 man/file_metadata_setters.Rd delete mode 100644 man/sas_date_formats.Rd delete mode 100644 man/sas_datetime_formats.Rd delete mode 100644 man/sas_time_formats.Rd rename man/{schema_1_0_0.Rd => schema_1_1_0.Rd} (64%) create mode 100644 man/set_as_reference_data.Rd diff --git a/NAMESPACE b/NAMESPACE index a9a5cd9..5a563e6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,21 +1,12 @@ # Generated by roxygen2: do not edit by hand -S3method(set_metadata_ref,data_metadata) -S3method(set_metadata_ref,datasetjson) -S3method(set_metadata_ref,default) -S3method(set_metadata_version,data_metadata) -S3method(set_metadata_version,datasetjson) -S3method(set_metadata_version,default) -S3method(set_study_oid,data_metadata) -S3method(set_study_oid,datasetjson) -S3method(set_study_oid,default) -export(data_metadata) export(dataset_json) -export(dataset_metadata) -export(file_metadata) export(read_dataset_json) -export(set_data_type) +export(set_as_reference_data) +export(set_dataset_label) +export(set_dataset_name) export(set_file_oid) +export(set_item_oid) export(set_metadata_ref) export(set_metadata_version) export(set_originator) diff --git a/data-raw/data.R b/data-raw/data.R index 1444d4c..5a737e4 100644 --- a/data-raw/data.R +++ b/data-raw/data.R @@ -64,79 +64,6 @@ iris_items_bad <- tibble::tribble( NA_character_, 5, 'Flower Species', 'character', 10L, 1, ) -# Code for SAS date formats -sas_date_formats <- c( - 'DATE.', - 'DATE9.', - 'DAY.', - 'DDMMYY.', - 'DDMMYY10.', - 'DDMMYYB.', - 'DDMMYYB10.', - 'DDMMYYC.', - 'DDMMYYC10.', - 'DDMMYYD.', - 'DDMMYYD10.', - 'DDMMYYN6.', - 'DDMMYYN8.', - 'DDMMYYP.', - 'DDMMYYP10.', - 'DDMMYYS.', - 'DDMMYYS10.', - 'DOWNAME.', - 'JULIAN.', - 'MMDDYY.', - 'MMDDYY10.', - 'MMDDYYB.', - 'MMDDYYB10.', - 'MMDDYYC.', - 'MMDDYYC10.', - 'MMDDYYD.', - 'MMDDYYD10.', - 'MMDDYYN6.', - 'MMDDYYN8.', - 'MMDDYYP.', - 'MMDDYYP10.', - 'MMDDYYS.', - 'MMDDYYS10.', - 'MMYY.', - 'MMYYC.', - 'MMYYD.', - 'MMYYN.', - 'MMYYP.', - 'MMYYS.', - 'MONNAME.', - 'MONTH.', - 'MONYY.', - 'WEEKDATE.', - 'WEEKDATX', - 'WEEKDAY.' -) - -usethis::use_data(sas_date_formats, overwrite = TRUE) - -# Code for SAS datetime formats -sas_datetime_formats <- c( - 'DATEAMPM.', - 'DATETIME.', - 'DTDATE.', - 'DTMONYY.', - 'DTWKDATX.', - 'DTYEAR.', - 'DTYYQC.' -) - -usethis::use_data(sas_datetime_formats, overwrite = TRUE) - -# Code for SAS time formats -sas_time_formats <- c( - 'HOUR.', - 'TIME.', - 'TIMEAMPM.', - 'TOD.' -) -usethis::use_data(sas_time_formats, overwrite = TRUE) - # Dataset JSON Schema V1.0.0 as Character Vector schema_file <- testthat::test_path("testdata", "dataset.schema.json") schema_1_1_0 = readChar(schema_file, file.info(schema_file)$size) diff --git a/data/iris_items.rda b/data/iris_items.rda index f26da5cc54480104d0ef497de4ebf258d6a87fd7..c817b7bcade4b4c19ef7e04458e7bc780fc49fa3 100644 GIT binary patch delta 316 zcmV-C0mJ^z0?q;sLRx4!F+o`-Q&~9eJY$g#9e*?>6*L}+lT8?z01W^DJqR?^(wNi@ zr~ow4pglkU8VL~+o|=K628}c{9w-1bX{l>P17?cd%)4dGnM5TGa7-1jAtUNBl{p%D zP%I=VWQc;H52htRfC)$e+-B<}zY)q+7dqjtIW?`*5Ks_&}=-bQCqEtTm&ZV?b1bbx(GT%s)W{l1k3h zvq)3<%&aZYn;`i!L~Gx_K!Q{xNi>SdG-8rqMS700007p$3|oLrI9x z13{xeXaE{C5+sOE)iMBKFqoP=P}58%nK-U!pgL$*I=e3uWTc2n8t;@8+6YMB7D-E? zsY-z&Q(GJoLV@xnt_28)1U$2Lg4IanEQ_mOECPmF7@Wh!i5J8J0T99gr4a!Q2o;f@ zK!23xab<{MS{QwDomA=P@meaWzgp;ROHCzMV?je&TEi3*tOyE_PPy+F#yPs O{9VZu;X*+)O5sE}c75Ie diff --git a/man/data_metadata.Rd b/man/data_metadata.Rd deleted file mode 100644 index 9786158..0000000 --- a/man/data_metadata.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data_metadata.R -\name{data_metadata} -\alias{data_metadata} -\title{Create the data metadata container for a Dataset JSON object} -\usage{ -data_metadata(study = NULL, metadata_version = NULL, metadata_ref = NULL) -} -\arguments{ -\item{study}{Study OID value} - -\item{metadata_version}{Metadata version OID value} - -\item{metadata_ref}{Metadata reference (i.e. path to Define.xml)} -} -\value{ -data_metadata object -} -\description{ -Create the data metadata container for a Dataset JSON object -} -\examples{ -# Create object directly -data_meta <- data_metadata( - study = "SOMESTUDY", - metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", - metadata_ref = "some/define.xml" -) - -# Use setter functions -data_meta <- data_metadata() -data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") -data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") -data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") - -} diff --git a/man/data_metadata_setters.Rd b/man/data_metadata_setters.Rd deleted file mode 100644 index f02fe01..0000000 --- a/man/data_metadata_setters.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data_metadata.R -\name{set_study_oid} -\alias{set_study_oid} -\alias{set_metadata_version} -\alias{set_metadata_ref} -\title{Set data metadata parameters} -\usage{ -set_study_oid(x, study, ...) - -set_metadata_version(x, metadata_version, ...) - -set_metadata_ref(x, metadata_ref) -} -\arguments{ -\item{x}{data metadata or datasetjson object} - -\item{study}{Study OID value} - -\item{...}{Additional parameters} - -\item{metadata_version}{Metadata version OID value} - -\item{metadata_ref}{Metadata reference (i.e. path to Define.xml)} -} -\value{ -A datasetjson or data_metadata object -} -\description{ -This set of functions -} -\examples{ -data_meta <- data_metadata() -data_meta_updated <- set_metadata_ref(data_meta, "some/define.xml") -data_meta_updated <- set_metadata_version(data_meta_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") -data_meta_updated <- set_study_oid(data_meta_updated, "SOMESTUDY") -} -\concept{Data metadata setters} diff --git a/man/dataset_json.Rd b/man/dataset_json.Rd index c84ffc6..cd9f37d 100644 --- a/man/dataset_json.Rd +++ b/man/dataset_json.Rd @@ -6,45 +6,47 @@ \usage{ dataset_json( .data, - item_id, - name, - label, - items, - dataset_meta, - version = "1.0.0", - data_type = c("clinicalData", "referenceData"), - file_meta = file_metadata(), - data_meta = data_metadata() + file_oid = NULL, + originator = NULL, + sys = NULL, + sys_version = NULL, + study = NULL, + metadata_version = NULL, + metadata_ref = NULL, + item_oid = NULL, + name = NULL, + dataset_label = NULL, + version = "1.1.0" ) } \arguments{ \item{.data}{Input data to contain within the Dataset JSON file. Written to the itemData parameter.} -\item{item_id}{ID used to label dataset with the itemGroupData parameter. -Defined as "Object of Datasets. Key value is a unique identifier for -Dataset, corresponding to ItemGroupDef/@OID in Define-XML."} +\item{file_oid}{fileOID parameter, defined as "A unique identifier for this +file."} -\item{name}{Dataset name} +\item{originator}{originator parameter, defined as "The organization that +generated the Dataset-JSON file."} -\item{label}{Dataset Label} +\item{sys}{sourceSystem parameter, defined as "The computer system or +database management system that is the source of the information in this +file."} -\item{items}{Variable metadata} +\item{sys_version}{sourceSystemVersion, defined as "The version of the +sourceSystem"} -\item{dataset_meta}{A dataset_metadata object holding pre-specified -dataset metadata.} +\item{study}{Study OID value} -\item{version}{Version of Dataset JSON schema to follow.} +\item{metadata_version}{Metadata version OID value} -\item{data_type}{Type of data being written. clinicalData for subject level -data, and referenceData for non-subject level data (i.e. TDMs, Associated -Persons)} +\item{metadata_ref}{Metadata reference (i.e. path to Define.xml)} -\item{file_meta}{A file_metadata object holding pre-specified file -metadata} +\item{item_oid}{ID used to label dataset with the itemGroupData parameter. +Defined as "Object of Datasets. Key value is a unique identifier for +Dataset, corresponding to ItemGroupDef/@OID in Define-XML."} -\item{data_meta}{A data_metadata object holding pre-specified data -metadata} +\item{version}{The DatasetJSON version to use. Currently only 1.1.0 is supported.} } \value{ dataset_json object pertaining to the specific Dataset JSON version @@ -53,9 +55,26 @@ specific \description{ Create the base object used to write a Dataset JSON file. } +\details{ +Note that DatasetJSON is on version 1.1.0. Based off findings from the pilot, +version 1.1.0 reflects feedback from the user community. Support for 1.0.0 has +been deprecated. +} \examples{ # Create a basic object -ds_json <- dataset_json(iris, "IG.IRIS", "IRIS", "Iris", iris_items) +ds_json <- dataset_json( + iris, + file_oid = "/some/path" + originator = "Some Org", + sys = "source system", + sys_version = "1.0", + study = "SOMESTUDY", + metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", + metadata_ref = "some/define.xml", + item_oid = "IG.IRIS", + name = "IRIS", + dataset_label = "Iris" +) # Attach attributes directly ds_json_updated <- set_data_type(ds_json, "referenceData") @@ -65,31 +84,7 @@ ds_json_updated <- set_metadata_version(ds_json_updated, "MDV.MSGv2.0.SDTMIG.3.3 ds_json_updated <- set_originator(ds_json_updated, "Some Org") ds_json_updated <- set_source_system(ds_json_updated, "source system", "1.0") ds_json_updated <- set_study_oid(ds_json_updated, "SOMESTUDY") - -# Create independent objects for metadata sections first -file_meta <- file_metadata( - originator = "Some Org", - sys = "source system", - sys_version = "1.0" -) - -data_meta <- data_metadata( - study = "SOMESTUDY", - metadata_version = "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7", - metadata_ref = "some/define.xml" -) - -dataset_meta <- dataset_metadata( - item_id = "IG.IRIS", - name = "IRIS", - label = "Iris", - items = iris_items -) - -ds_json_from_meta <- dataset_json( - iris, - dataset_meta = dataset_meta, - file_meta = file_meta, - data_meta = data_meta - ) +ds_json_updated <- set_item_oid(ds_json_updated, "IG.IRIS") +ds_json_updated <- set_dataset_name(ds_json_updated, "IRIS") +ds_json_updated <- set_dataseT_label(ds_json_updated, "Iris") } diff --git a/man/dataset_metadata.Rd b/man/dataset_metadata.Rd deleted file mode 100644 index 9dea9fc..0000000 --- a/man/dataset_metadata.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dataset_metadata.R -\name{dataset_metadata} -\alias{dataset_metadata} -\title{Generate an individual element that fills the itemGroupData field} -\usage{ -dataset_metadata(item_id, name, label, items, .data) -} -\arguments{ -\item{item_id}{Data Object ID for item in Dataset JSON object, corresponding to -ItemGroupDef/@OID in Define-XML.} - -\item{name}{Dataset name} - -\item{label}{Dataset Label} - -\item{items}{Variable metadata} - -\item{.data}{Dataframe to be written to Dataset JSON file} -} -\value{ -dataset_metadata object -} -\description{ -Generate an individual element that fills the itemGroupData field -} -\examples{ -dataset_meta <- dataset_metadata( - item_id = "IG.IRIS", - name = "IRIS", - label = "Iris", - items = iris_items -) -} diff --git a/man/dataset_metadata_setters.Rd b/man/dataset_metadata_setters.Rd new file mode 100644 index 0000000..dcbab0a --- /dev/null +++ b/man/dataset_metadata_setters.Rd @@ -0,0 +1,91 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/file_metadata.R +\name{set_source_system} +\alias{set_source_system} +\alias{set_originator} +\alias{set_file_oid} +\alias{set_study_oid} +\alias{set_metadata_version} +\alias{set_metadata_ref} +\alias{set_item_oid} +\alias{set_dataset_name} +\alias{set_dataset_label} +\title{Dataset Metadata Setters} +\usage{ +set_source_system(x, sys, sys_version) + +set_originator(x, originator) + +set_file_oid(x, file_oid) + +set_study_oid(x, study) + +set_metadata_version(x, metadata_version) + +set_metadata_ref(x, metadata_ref) + +set_item_oid(x, item_oid) + +set_dataset_name(x, name) + +set_dataset_label(x, dataset_label) +} +\arguments{ +\item{x}{datasetjson object} + +\item{sys}{sourceSystem parameter, defined as "The computer system or +database management system that is the source of the information in this +file."} + +\item{sys_version}{sourceSystemVersion, defined as "The version of the +sourceSystem"} + +\item{originator}{originator parameter, defined as "The organization that +generated the Dataset-JSON file."} + +\item{file_oid}{fileOID parameter, defined as "A unique identifier for this +file."} + +\item{study}{Study OID value} + +\item{metadata_version}{Metadata version OID value} + +\item{metadata_ref}{Metadata reference (i.e. path to Define.xml)} + +\item{item_oid}{ID used to label dataset with the itemGroupData parameter. +Defined as "Object of Datasets. Key value is a unique identifier for +Dataset, corresponding to ItemGroupDef/@OID in Define-XML."} + +\item{name}{Dataset name} + +\item{dataset_label}{Dataset Label} +} +\value{ +datasetjson object +} +\description{ +Set information about the file, source system, study, and dataset used to generate the Dataset +JSON object. +} +\details{ +The fileOID parameter should be structured following description outlined in +the ODM V2.0 specification. "FileOIDs should be universally unique if at all +possible. One way to ensure this is to prefix every FileOID with an internet +domain name owned by the creator of the ODM file or database (followed by a +forward slash, "/"). For example, +FileOID="BestPharmaceuticals.com/Study5894/1" might be a good way to denote +the first file in a series for study 5894 from Best Pharmaceuticals." +} +\examples{ +ds_json <- dataset_json(iris) +ds_json <- set_file_oid(ds_json, "/some/path") +ds_json <- set_study_oid(ds_json, "SOMESTUDY") +ds_json <- set_originator(ds_json, "Some Org") +ds_json <- set_source_system(ds_json, "source system", "1.0") +ds_json <- set_metadata_ref(ds_json, "some/define.xml") +ds_json <- set_metadata_version(ds_json, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") +ds_json <- set_item_oid(ds_json, "IG.IRIS") +ds_json <- set_dataset_name(ds_json, "IRIS") +ds_json <- set_dataset_label(ds_json, "Iris") +} +\concept{Dataset Metadata Setters} diff --git a/man/file_metadata.Rd b/man/file_metadata.Rd deleted file mode 100644 index 342285d..0000000 --- a/man/file_metadata.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/file_metadata.R -\name{file_metadata} -\alias{file_metadata} -\title{Create a file metadata object} -\usage{ -file_metadata( - originator = NULL, - sys = NULL, - sys_version = NULL, - file_oid = NULL, - version = "1.0.0" -) -} -\arguments{ -\item{originator}{originator parameter, defined as "The organization that -generated the Dataset-JSON file."} - -\item{sys}{sourceSystem parameter, defined as "The computer system or -database management system that is the source of the information in this -file."} - -\item{sys_version}{sourceSystemVersion, defined as "The version of the -sourceSystem"} - -\item{file_oid}{fileOID parameter, defined as "A unique identifier for this -file."} - -\item{version}{Dataset JSON schema version being used} -} -\value{ -file_metadata object -} -\description{ -Create a file metadata object -} -\examples{ -# Create using parameters -file_meta <- file_metadata( - originator = "Some Org", - sys = "source system", - sys_version = "1.0" - ) - -# Set parameters after -file_meta <- file_metadata() - -file_meta_updated <- set_file_oid(file_meta, "/some/path") -file_meta_updated <- set_originator(file_meta_updated, "Some Org") -file_meta_updated <- set_source_system(file_meta_updated, "source system", "1.0") -} diff --git a/man/file_metadata_setters.Rd b/man/file_metadata_setters.Rd deleted file mode 100644 index 4b5dd0f..0000000 --- a/man/file_metadata_setters.Rd +++ /dev/null @@ -1,61 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/file_metadata.R -\name{set_source_system} -\alias{set_source_system} -\alias{set_originator} -\alias{set_file_oid} -\alias{set_data_type} -\title{File Metadata Setters} -\usage{ -set_source_system(x, sys, sys_version) - -set_originator(x, originator) - -set_file_oid(x, file_oid) - -set_data_type(x, data_type = c("clinicalData", "referenceData")) -} -\arguments{ -\item{x}{datasetjson object} - -\item{sys}{sourceSystem parameter, defined as "The computer system or -database management system that is the source of the information in this -file."} - -\item{sys_version}{sourceSystemVersion, defined as "The version of the -sourceSystem"} - -\item{originator}{originator parameter, defined as "The organization that -generated the Dataset-JSON file."} - -\item{file_oid}{fileOID parameter, defined as "A unique identifier for this -file."} - -\item{data_type}{Type of data being written. clinicalData for subject level -data, and referenceData for non-subject level data (i.e. TDMs, Associated -Persons)} -} -\value{ -datasetjson or file_metadata object -} -\description{ -Set information about the file and source system used to generate the Dataset -JSON object. -} -\details{ -The fileOID parameter should be structured following description outlined in -the ODM V2.0 specification. "FileOIDs should be universally unique if at all -possible. One way to ensure this is to prefix every FileOID with an internet -domain name owned by the creator of the ODM file or database (followed by a -forward slash, "/"). For example, -FileOID="BestPharmaceuticals.com/Study5894/1" might be a good way to denote -the first file in a series for study 5894 from Best Pharmaceuticals." -} -\examples{ -file_meta <- file_metadata() - -file_meta_updated <- set_file_oid(file_meta, "/some/path") -file_meta_updated <- set_originator(file_meta_updated, "Some Org") -file_meta_updated <- set_source_system(file_meta_updated, "source system", "1.0") -} -\concept{File Metadata Setters} diff --git a/man/sas_date_formats.Rd b/man/sas_date_formats.Rd deleted file mode 100644 index ebf3449..0000000 --- a/man/sas_date_formats.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{sas_date_formats} -\alias{sas_date_formats} -\title{A List of valid SAS(c) date formats} -\format{ -\subsection{\code{sas_date_formats}}{ - -\describe{ -A character vector with 45 elements -} -} -} -\usage{ -sas_date_formats -} -\description{ -Valid SAS(c) date formats pulled from -https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -} -\keyword{datasets} diff --git a/man/sas_datetime_formats.Rd b/man/sas_datetime_formats.Rd deleted file mode 100644 index d8358a6..0000000 --- a/man/sas_datetime_formats.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{sas_datetime_formats} -\alias{sas_datetime_formats} -\title{A List of valid SAS(c) datetime formats} -\format{ -\subsection{\code{sas_datetime_formats}}{ - -\describe{ -A character vector with 7 elements -} -} -} -\usage{ -sas_datetime_formats -} -\description{ -Valid SAS(c) datetime formats pulled from -https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -} -\keyword{datasets} diff --git a/man/sas_time_formats.Rd b/man/sas_time_formats.Rd deleted file mode 100644 index 60588f4..0000000 --- a/man/sas_time_formats.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{sas_time_formats} -\alias{sas_time_formats} -\title{A List of valid SAS(c) time formats} -\format{ -\subsection{\code{sas_time_formats}}{ - -\describe{ -A character vector with 4 elements -} -} -} -\usage{ -sas_time_formats -} -\description{ -Valid SAS(c) time formats pulled from -https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2pg/p0bz5detpfj01qn1kz2in7xymkdl.htm -} -\keyword{datasets} diff --git a/man/schema_1_0_0.Rd b/man/schema_1_1_0.Rd similarity index 64% rename from man/schema_1_0_0.Rd rename to man/schema_1_1_0.Rd index 633c00b..189a927 100644 --- a/man/schema_1_0_0.Rd +++ b/man/schema_1_1_0.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} -\name{schema_1_0_0} -\alias{schema_1_0_0} -\title{Dataset JSON Schema Version 1.0.0} +\name{schema_1_1_0} +\alias{schema_1_1_0} +\title{Dataset JSON Schema Version 1.1.0} \format{ -\subsection{\code{schema_1_0_0}}{ +\subsection{\code{schema_1_1_0}}{ \describe{ A character vector with 1 element @@ -13,9 +13,9 @@ A character vector with 1 element } } \usage{ -schema_1_0_0 +schema_1_1_0 } \description{ -This object is a character vector holding the schema for Dataset JSON Version 1.0.0 +This object is a character vector holding the schema for Dataset JSON Version 1.1.0 } \keyword{datasets} diff --git a/man/set_as_reference_data.Rd b/man/set_as_reference_data.Rd new file mode 100644 index 0000000..173bd93 --- /dev/null +++ b/man/set_as_reference_data.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/file_metadata.R +\name{set_as_reference_data} +\alias{set_as_reference_data} +\title{Declare as reference data} +\usage{ +set_as_reference_data(x) +} +\arguments{ +\item{x}{datasetjson object} +} +\value{ +datasetjson object +} +\description{ +Sets DatasetJSON file to have the isReferenceData attribute set to TRUE +} +\examples{ +ds_json <- dataset_json(iris) +ds_json <- set_as_reference_data(ds_json) +} From 836b803a9adfebc162cf728400705221b389b186 Mon Sep 17 00:00:00 2001 From: Michael Stackhouse Date: Thu, 5 Sep 2024 15:47:00 -0400 Subject: [PATCH 6/8] Update R/datasetjson.R Co-authored-by: Nicholas Masel <61123199+nicholas-masel@users.noreply.github.com> --- R/datasetjson.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datasetjson.R b/R/datasetjson.R index 840eed0..f3279ba 100644 --- a/R/datasetjson.R +++ b/R/datasetjson.R @@ -57,7 +57,7 @@ #' ds_json_updated <- set_study_oid(ds_json_updated, "SOMESTUDY") #' ds_json_updated <- set_item_oid(ds_json_updated, "IG.IRIS") #' ds_json_updated <- set_dataset_name(ds_json_updated, "IRIS") -#' ds_json_updated <- set_dataseT_label(ds_json_updated, "Iris") +#' ds_json_updated <- set_dataset_label(ds_json_updated, "Iris") dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, sys_version = NULL, study=NULL, metadata_version=NULL, metadata_ref=NULL, item_oid=NULL, name=NULL, From 6de009cdcf0b4d71daca76a2e6beb7f0967d9251 Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 16:48:30 -0400 Subject: [PATCH 7/8] Updates from discussion --- NAMESPACE | 2 +- R/datasetjson.R | 18 +++++---- R/file_metadata.R | 40 +++++++++++++++++-- man/dataset_json.Rd | 6 ++- man/dataset_metadata_setters.Rd | 3 ++ ...eference_data.Rd => set_reference_data.Rd} | 6 +-- 6 files changed, 60 insertions(+), 15 deletions(-) rename man/{set_as_reference_data.Rd => set_reference_data.Rd} (81%) diff --git a/NAMESPACE b/NAMESPACE index 5a563e6..ccbacf6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,7 +2,6 @@ export(dataset_json) export(read_dataset_json) -export(set_as_reference_data) export(set_dataset_label) export(set_dataset_name) export(set_file_oid) @@ -10,6 +9,7 @@ export(set_item_oid) export(set_metadata_ref) export(set_metadata_version) export(set_originator) +export(set_reference_data) export(set_source_system) export(set_study_oid) export(validate_dataset_json) diff --git a/R/datasetjson.R b/R/datasetjson.R index f3279ba..906a5b5 100644 --- a/R/datasetjson.R +++ b/R/datasetjson.R @@ -25,6 +25,8 @@ #' @param item_oid ID used to label dataset with the itemGroupData parameter. #' Defined as "Object of Datasets. Key value is a unique identifier for #' Dataset, corresponding to ItemGroupDef/@OID in Define-XML." +#' @param ref_data Boolean value that is set to "true" when the dataset contains +#' reference data (not subject data). The default value is "false". #' @param version The DatasetJSON version to use. Currently only 1.1.0 is supported. #' #' @return dataset_json object pertaining to the specific Dataset JSON version @@ -61,9 +63,9 @@ dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, sys_version = NULL, study=NULL, metadata_version=NULL, metadata_ref=NULL, item_oid=NULL, name=NULL, - dataset_label=NULL, version="1.1.0") { + dataset_label=NULL, ref_data=FALSE, version="1.1.0") { new_dataset_json(.data, file_oid, originator, sys, sys_version, study, metadata_version, - metadata_ref, item_oid, name, dataset_label, version) + metadata_ref, item_oid, name, dataset_label, ref_data, version) } #' Create a base Dataset JSON Container @@ -77,7 +79,7 @@ dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, #' @noRd new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, study, metadata_version, metadata_ref, item_oid, name, dataset_label, - version) { + ref_data, version) { if (!(version %in% c("1.1.0"))) { stop("Unsupported version specified - currently only version 1.1.0 is supported", call.=FALSE) @@ -90,7 +92,8 @@ new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, stud # Extract the function and call it to return the base structure funcs[[version]](.data, file_oid, originator, sys, sys_version, study, - metadata_version, metadata_ref, item_oid, name, dataset_label) + metadata_version, metadata_ref, item_oid, name, dataset_label, + ref_data) } #' Dataset JSON v1.1.0 Generator @@ -98,7 +101,8 @@ new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, stud #' @return datasetjson_v1_1_0 object #' @noRd new_dataset_json_v1_1_0 <- function(.data, file_oid, originator, sys, sys_version, study, - metadata_version, metadata_ref, item_oid, name, dataset_label) { + metadata_version, metadata_ref, item_oid, name, dataset_label, + ref_data) { if (!inherits(.data, 'data.frame')) { stop("datasetjson objects must inherit from a data.frame", call.=FALSE) @@ -111,16 +115,16 @@ new_dataset_json_v1_1_0 <- function(.data, file_oid, originator, sys, sys_versio ) } + attr(.data, 'datasetJSONVersion') <- "1.1.0" attr(.data, 'fileOID') <- file_oid attr(.data, 'originator') <- originator attr(.data, 'studyOID') <- study attr(.data, 'metaDataVersionOID') <- metadata_version attr(.data, 'metaDataRef') <- metadata_ref attr(.data, "itemGroupOID") <- item_oid - attr(.data, 'records') <- nrow(x) attr(.data, 'name') <- name attr(.data, 'label') <- dataset_label - attr(.data, 'isReferenceData') <- FALSE + attr(.data, 'isReferenceData') <- ref_data structure( .data, diff --git a/R/file_metadata.R b/R/file_metadata.R index e0ca4cd..cf5f15f 100644 --- a/R/file_metadata.R +++ b/R/file_metadata.R @@ -29,6 +29,8 @@ #' @param item_oid ID used to label dataset with the itemGroupData parameter. #' Defined as "Object of Datasets. Key value is a unique identifier for #' Dataset, corresponding to ItemGroupDef/@OID in Define-XML." +#' @param ref_data Boolean value that is set to "true" when the dataset contains +#' reference data (not subject data). The default value is "false". #' @param name Dataset name #' @param dataset_label Dataset Label #' @@ -50,6 +52,12 @@ #' ds_json <- set_dataset_label(ds_json, "Iris") set_source_system <- function(x, sys, sys_version) { stopifnot_datasetjson(x) + if (!is.character(sys)) { + stop("`sys` must be a character") + } + if (!is.character(sys_version)) { + stop("`sys_version` must be a character") + } attr(x, 'sourceSystem') <- list( "name" = sys, "version" = sys_version @@ -62,6 +70,9 @@ set_source_system <- function(x, sys, sys_version) { #' @rdname dataset_metadata_setters set_originator <- function(x, originator) { stopifnot_datasetjson(x) + if (!is.character(originator)) { + stop("`originator` must be a character") + } attr(x, 'originator') <- originator x } @@ -71,6 +82,9 @@ set_originator <- function(x, originator) { #' @rdname dataset_metadata_setters set_file_oid <- function(x, file_oid) { stopifnot_datasetjson(x) + if (!is.character(file_oid)) { + stop("`file_oid` must be a character") + } attr(x, 'fileOID') <- file_oid x } @@ -80,6 +94,9 @@ set_file_oid <- function(x, file_oid) { #' @rdname dataset_metadata_setters set_study_oid <- function(x, study) { stopifnot_datasetjson(x) + if (!is.character(study)) { + stop("`study` must be a character") + } attr(x, 'studyOID') <- study x } @@ -89,6 +106,9 @@ set_study_oid <- function(x, study) { #' @rdname dataset_metadata_setters set_metadata_version <- function(x, metadata_version) { stopifnot_datasetjson(x) + if (!is.character(metadata_version)) { + stop("`metadata_version` must be a character") + } attr(x, 'metaDataVersionOID') <- metadata_version x } @@ -98,6 +118,9 @@ set_metadata_version <- function(x, metadata_version) { #' @rdname dataset_metadata_setters set_metadata_ref <- function(x, metadata_ref) { stopifnot_datasetjson(x) + if (!is.character(metadata_ref)) { + stop("`metadata_ref` must be a character") + } attr(x, 'metaDataRef') <- metadata_ref x } @@ -107,6 +130,9 @@ set_metadata_ref <- function(x, metadata_ref) { #' @rdname dataset_metadata_setters set_item_oid <- function(x, item_oid) { stopifnot_datasetjson(x) + if (!is.character(item_oid)) { + stop("`item_oid` must be a character") + } attr(x, "itemGroupOID") <- item_oid } @@ -115,6 +141,9 @@ set_item_oid <- function(x, item_oid) { #' @rdname dataset_metadata_setters set_dataset_name <- function(x, name) { stopifnot_datasetjson(x) + if (!is.character(name)) { + stop("`name` must be a character") + } attr(x, 'name') <- name } @@ -123,6 +152,9 @@ set_dataset_name <- function(x, name) { #' @rdname dataset_metadata_setters set_dataset_label <- function(x, dataset_label) { stopifnot_datasetjson(x) + if (!is.character(dataset_labelx)) { + stop("`dataset_label` must be a character") + } attr(x, 'label') <- dataset_label } @@ -138,12 +170,14 @@ set_dataset_label <- function(x, dataset_label) { #' @examples #' ds_json <- dataset_json(iris) #' ds_json <- set_as_reference_data(ds_json) -set_as_reference_data <- function(x) { +set_reference_data <- function(x, is_refdata) { stopifnot_datasetjson(x) - attr(x, 'isReferenceData') <- TRUE + if (!is.logical(is_refdata)) { + stop("`is_refdata` must be a boolean") + } + attr(x, 'isReferenceData') <- is_refdata } - #' Create an ISO8601 formatted datetime of the current time #' #' This is used to create the creationDateTime and asOfDateTime attributes of diff --git a/man/dataset_json.Rd b/man/dataset_json.Rd index cd9f37d..d538d80 100644 --- a/man/dataset_json.Rd +++ b/man/dataset_json.Rd @@ -16,6 +16,7 @@ dataset_json( item_oid = NULL, name = NULL, dataset_label = NULL, + ref_data = FALSE, version = "1.1.0" ) } @@ -46,6 +47,9 @@ sourceSystem"} Defined as "Object of Datasets. Key value is a unique identifier for Dataset, corresponding to ItemGroupDef/@OID in Define-XML."} +\item{ref_data}{Boolean value that is set to "true" when the dataset contains +reference data (not subject data). The default value is "false".} + \item{version}{The DatasetJSON version to use. Currently only 1.1.0 is supported.} } \value{ @@ -86,5 +90,5 @@ ds_json_updated <- set_source_system(ds_json_updated, "source system", "1.0") ds_json_updated <- set_study_oid(ds_json_updated, "SOMESTUDY") ds_json_updated <- set_item_oid(ds_json_updated, "IG.IRIS") ds_json_updated <- set_dataset_name(ds_json_updated, "IRIS") -ds_json_updated <- set_dataseT_label(ds_json_updated, "Iris") +ds_json_updated <- set_dataset_label(ds_json_updated, "Iris") } diff --git a/man/dataset_metadata_setters.Rd b/man/dataset_metadata_setters.Rd index dcbab0a..c0c2caf 100644 --- a/man/dataset_metadata_setters.Rd +++ b/man/dataset_metadata_setters.Rd @@ -59,6 +59,9 @@ Dataset, corresponding to ItemGroupDef/@OID in Define-XML."} \item{name}{Dataset name} \item{dataset_label}{Dataset Label} + +\item{ref_data}{Boolean value that is set to "true" when the dataset contains +reference data (not subject data). The default value is "false".} } \value{ datasetjson object diff --git a/man/set_as_reference_data.Rd b/man/set_reference_data.Rd similarity index 81% rename from man/set_as_reference_data.Rd rename to man/set_reference_data.Rd index 173bd93..e52a644 100644 --- a/man/set_as_reference_data.Rd +++ b/man/set_reference_data.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/file_metadata.R -\name{set_as_reference_data} -\alias{set_as_reference_data} +\name{set_reference_data} +\alias{set_reference_data} \title{Declare as reference data} \usage{ -set_as_reference_data(x) +set_reference_data(x, is_refdata) } \arguments{ \item{x}{datasetjson object} From 7d4f4bae7f368f951c868abbe2c7b7cb1c1a136e Mon Sep 17 00:00:00 2001 From: mstackhouse Date: Thu, 5 Sep 2024 16:56:42 -0400 Subject: [PATCH 8/8] docs and cleanup --- NAMESPACE | 1 + R/datasetjson.R | 29 +++++++++++++++++------------ R/file_metadata.R | 24 +++++++++++++----------- man/dataset_json.Rd | 5 ++++- man/dataset_metadata_setters.Rd | 6 ++++++ man/set_reference_data.Rd | 21 --------------------- 6 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 man/set_reference_data.Rd diff --git a/NAMESPACE b/NAMESPACE index ccbacf6..03d40e1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(set_dataset_label) export(set_dataset_name) export(set_file_oid) export(set_item_oid) +export(set_last_modified) export(set_metadata_ref) export(set_metadata_version) export(set_originator) diff --git a/R/datasetjson.R b/R/datasetjson.R index 906a5b5..ec453cc 100644 --- a/R/datasetjson.R +++ b/R/datasetjson.R @@ -37,7 +37,8 @@ #' # Create a basic object #' ds_json <- dataset_json( #' iris, -#' file_oid = "/some/path" +#' file_oid = "/some/path", +#' last_modified = "2023-02-15T10:23:15", #' originator = "Some Org", #' sys = "source system", #' sys_version = "1.0", @@ -52,6 +53,7 @@ #' # Attach attributes directly #' ds_json_updated <- set_data_type(ds_json, "referenceData") #' ds_json_updated <- set_file_oid(ds_json_updated, "/some/path") +#' ds_json_updates <- set_last_modified(ds_json_updates, "2023-02-15T10:23:15") #' ds_json_updated <- set_metadata_ref(ds_json_updated, "some/define.xml") #' ds_json_updated <- set_metadata_version(ds_json_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") #' ds_json_updated <- set_originator(ds_json_updated, "Some Org") @@ -60,12 +62,14 @@ #' ds_json_updated <- set_item_oid(ds_json_updated, "IG.IRIS") #' ds_json_updated <- set_dataset_name(ds_json_updated, "IRIS") #' ds_json_updated <- set_dataset_label(ds_json_updated, "Iris") -dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, - sys_version = NULL, study=NULL, metadata_version=NULL, - metadata_ref=NULL, item_oid=NULL, name=NULL, - dataset_label=NULL, ref_data=FALSE, version="1.1.0") { - new_dataset_json(.data, file_oid, originator, sys, sys_version, study, metadata_version, - metadata_ref, item_oid, name, dataset_label, ref_data, version) +dataset_json <- function(.data, file_oid = NULL, last_modified=NULL, + originator=NULL, sys=NULL, sys_version = NULL, + study=NULL, metadata_version=NULL,metadata_ref=NULL, + item_oid=NULL, name=NULL, dataset_label=NULL, ref_data=FALSE, + version="1.1.0") { + new_dataset_json(.data, file_oid, last_modified, originator, sys, sys_version, study, + metadata_version, metadata_ref, item_oid, name, dataset_label, ref_data, + version) } #' Create a base Dataset JSON Container @@ -77,7 +81,7 @@ dataset_json <- function(.data, file_oid = NULL, originator=NULL, sys=NULL, #' @return datasetjson object #' #' @noRd -new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, study, +new_dataset_json <- function(.data, file_oid, last_modified, originator, sys, sys_version, study, metadata_version, metadata_ref, item_oid, name, dataset_label, ref_data, version) { @@ -91,7 +95,7 @@ new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, stud ) # Extract the function and call it to return the base structure - funcs[[version]](.data, file_oid, originator, sys, sys_version, study, + funcs[[version]](.data, file_oid, last_modified, originator, sys, sys_version, study, metadata_version, metadata_ref, item_oid, name, dataset_label, ref_data) } @@ -100,9 +104,9 @@ new_dataset_json <- function(.data, file_oid, originator, sys, sys_version, stud #' #' @return datasetjson_v1_1_0 object #' @noRd -new_dataset_json_v1_1_0 <- function(.data, file_oid, originator, sys, sys_version, study, - metadata_version, metadata_ref, item_oid, name, dataset_label, - ref_data) { +new_dataset_json_v1_1_0 <- function(.data, file_oid, last_modified, originator, sys, sys_version, + study, metadata_version, metadata_ref, item_oid, name, + dataset_label, ref_data) { if (!inherits(.data, 'data.frame')) { stop("datasetjson objects must inherit from a data.frame", call.=FALSE) @@ -117,6 +121,7 @@ new_dataset_json_v1_1_0 <- function(.data, file_oid, originator, sys, sys_versio attr(.data, 'datasetJSONVersion') <- "1.1.0" attr(.data, 'fileOID') <- file_oid + attr(.data, 'dbLastModifiedDateTime') <- last_modified attr(.data, 'originator') <- originator attr(.data, 'studyOID') <- study attr(.data, 'metaDataVersionOID') <- metadata_version diff --git a/R/file_metadata.R b/R/file_metadata.R index cf5f15f..738b382 100644 --- a/R/file_metadata.R +++ b/R/file_metadata.R @@ -158,18 +158,9 @@ set_dataset_label <- function(x, dataset_label) { attr(x, 'label') <- dataset_label } -#' Declare as reference data -#' -#' Sets DatasetJSON file to have the isReferenceData attribute set to TRUE -#' -#' @param x datasetjson object -#' -#' @return datasetjson object #' @export -#' -#' @examples -#' ds_json <- dataset_json(iris) -#' ds_json <- set_as_reference_data(ds_json) +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters set_reference_data <- function(x, is_refdata) { stopifnot_datasetjson(x) if (!is.logical(is_refdata)) { @@ -178,6 +169,17 @@ set_reference_data <- function(x, is_refdata) { attr(x, 'isReferenceData') <- is_refdata } +#' @export +#' @family Dataset Metadata Setters +#' @rdname dataset_metadata_setters +set_last_modified <- function(x, last_modified) { + stopifnot_datasetjson(x) + if (!is.character(last_modified)) { + stop("`last_modified` must be a character") + } + attr(x, 'dbLastModifiedDateTime') <- last_modified +} + #' Create an ISO8601 formatted datetime of the current time #' #' This is used to create the creationDateTime and asOfDateTime attributes of diff --git a/man/dataset_json.Rd b/man/dataset_json.Rd index d538d80..91f6532 100644 --- a/man/dataset_json.Rd +++ b/man/dataset_json.Rd @@ -7,6 +7,7 @@ dataset_json( .data, file_oid = NULL, + last_modified = NULL, originator = NULL, sys = NULL, sys_version = NULL, @@ -68,7 +69,8 @@ been deprecated. # Create a basic object ds_json <- dataset_json( iris, - file_oid = "/some/path" + file_oid = "/some/path", + last_modified = "2023-02-15T10:23:15", originator = "Some Org", sys = "source system", sys_version = "1.0", @@ -83,6 +85,7 @@ ds_json <- dataset_json( # Attach attributes directly ds_json_updated <- set_data_type(ds_json, "referenceData") ds_json_updated <- set_file_oid(ds_json_updated, "/some/path") +ds_json_updates <- set_last_modified(ds_json_updates, "2023-02-15T10:23:15") ds_json_updated <- set_metadata_ref(ds_json_updated, "some/define.xml") ds_json_updated <- set_metadata_version(ds_json_updated, "MDV.MSGv2.0.SDTMIG.3.3.SDTM.1.7") ds_json_updated <- set_originator(ds_json_updated, "Some Org") diff --git a/man/dataset_metadata_setters.Rd b/man/dataset_metadata_setters.Rd index c0c2caf..900f055 100644 --- a/man/dataset_metadata_setters.Rd +++ b/man/dataset_metadata_setters.Rd @@ -10,6 +10,8 @@ \alias{set_item_oid} \alias{set_dataset_name} \alias{set_dataset_label} +\alias{set_reference_data} +\alias{set_last_modified} \title{Dataset Metadata Setters} \usage{ set_source_system(x, sys, sys_version) @@ -29,6 +31,10 @@ set_item_oid(x, item_oid) set_dataset_name(x, name) set_dataset_label(x, dataset_label) + +set_reference_data(x, is_refdata) + +set_last_modified(x, last_modified) } \arguments{ \item{x}{datasetjson object} diff --git a/man/set_reference_data.Rd b/man/set_reference_data.Rd deleted file mode 100644 index e52a644..0000000 --- a/man/set_reference_data.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/file_metadata.R -\name{set_reference_data} -\alias{set_reference_data} -\title{Declare as reference data} -\usage{ -set_reference_data(x, is_refdata) -} -\arguments{ -\item{x}{datasetjson object} -} -\value{ -datasetjson object -} -\description{ -Sets DatasetJSON file to have the isReferenceData attribute set to TRUE -} -\examples{ -ds_json <- dataset_json(iris) -ds_json <- set_as_reference_data(ds_json) -}