Skip to content

Commit

Permalink
#181 M3 fix codelist value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Oct 4, 2024
1 parent 6e828e9 commit d452fd4
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions R/ISOCodeListValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ ISOCodeListValue <- R6Class("ISOCodeListValue",

if(length(cl$codeEntry)>0){
if(!is.null(value)){
clEntry <- cl$codeEntry[cl$codeEntry$value == value,]
if(nrow(clEntry)==0){
clEntry <- cl$codeEntry[sapply(cl$codeEntry, function(x){x$identifier == value})]
if(length(clEntry)==0){
warning(sprintf("No ISO '%s' codelist entry for value '%s'", id, value))
clValue <- value
if(!is.null(description)){
Expand All @@ -85,14 +85,14 @@ ISOCodeListValue <- R6Class("ISOCodeListValue",
}
}
}else{
clEntry <- cl$codeEntry[1,]
clEntry <- cl$codeEntry[[1]]$identifier
}

if(!is.null(value) & nrow(clEntry)>0){
clEntry <- clEntry[1L,]
clValue <- clEntry$value
clName <- clEntry$name
clDescription <- ifelse(!is.na(clName), clEntry$name, clEntry$description)
if(!is.null(value) & length(clEntry)>0){
clEntry <- clEntry[[1]]
clValue <- clEntry$identifier
clName <- clEntry$description
clDescription <- clEntry$description
if(setValueDescription) clDescription <- clEntry$description
self$valueDescription <- clDescription
}
Expand All @@ -105,17 +105,19 @@ ISOCodeListValue <- R6Class("ISOCodeListValue",
self$valueDescription <- clDescription
}
}

isLocalFile <- !grepl("^http", cl$refFile) & !grepl("^https", cl$refFile)
clUrl <- paste(cl$refFile, id, sep="#")
clUrl <- gsub("ML_", "", clUrl)
if(isLocalFile) clUrl <- paste(getGeometaOption("codelistUrl"), clUrl, sep="/")
if(id == "LanguageCode"){
langUrlOp <- getGeometaOption("languageUrl")
if(!is.null(langUrlOp)) clUrl <- langUrlOp

clUrl = ""
if(!is.na(cl$refFile)){
isLocalFile <- !grepl("^http", cl$refFile) & !grepl("^https", cl$refFile)
clUrl <- paste(cl$refFile, id, sep="#")
clUrl <- gsub("ML_", "", clUrl)
if(isLocalFile) clUrl <- paste(getGeometaOption("codelistUrl"), clUrl, sep="/")
if(id == "LanguageCode"){
langUrlOp <- getGeometaOption("languageUrl")
if(!is.null(langUrlOp)) clUrl <- langUrlOp
}
}


if(addCodeListAttrs){
self$attrs <- list(
codeList = clUrl,
Expand Down

0 comments on commit d452fd4

Please sign in to comment.