R/get_data_from_num.R

Defines functions get_data_from_num

Documented in get_data_from_num

#' get_data_from_num
#' @export
get_data_from_num <- function(cohorte_num,
                              num_type,
                              cohort, 
                              progress = NULL, 
                              icd_prefix = '',
                              neg , 
                              config, 
                              step_p) {
  
  if(!is.null(progress)) {
    step_p<-step_p+1
    progress$set(step_p, detail = stringr::str_interp('Loading ${cohort} patients') )
  } else {
    cat('Loading cases...')
  }
  
  cohort_data <- list()
  #cases$patients <- get_patients(base_url, token, num = cohorte_num, num_type = "cohorte", only_num = "false", count = "true" )
  cohort_data$patients <- DWHtools2::get_patients(num = cohorte_num, num_type = num_type, only_num = FALSE, count = TRUE, config) 
  #cases$concepts <- get_concepts(base_url, token, num = cohorte_num, num_type = "cohorte")
  cohort_data$concepts <- DWHtools2::get_concepts(num = cohorte_num, num_type = num_type, config)
  
  if(!is.null(progress)) {
    step_p<-step_p
    progress$set(step_p, detail = stringr::str_interp('Loading ${cohort} concepts') )
  } else {
    cat('concepts...')
  }
  
  if (!is.null(cohort_data$concepts)) {
    cohort_data$concepts <- modify_code_given_certitude(cohort_data$concepts, neg)
    cohort_data$concepts$group = cohort
  }
  
  cohort_data$patients$group = cohort
  
  if(!is.null(progress)) {
    step_p<-step_p+1
    progress$set(step_p, detail = stringr::str_interp('Loading ${cohort} bio') )
  } else {
    cat('bio...')
  }
  
  #cases$bio <- get_data(base_url, token, num = cohorte_num, num_type = "cohorte", data_type = 'bio_num') 
  cohort_data$bio <- DWHtools2::get_data(num = cohorte_num, num_type = num_type, data_type = 'bio_num', config = config)
  
  if (!is.null(cohort_data$bio)) {
    cohort_data$bio$group = cohort
    #cohort_data$bio <- preprocess_bio_concepts(cohort_data$bio, type = 'iep', nb_occurrences =1, map_loinc = TRUE)
  }
  
  if(!is.null(progress)) {
    step_p<-step_p+1
    progress$set(step_p, detail = stringr::str_interp('Loading ${cohort} cim10') )
  } else {
    cat('cim10...')
  }
  #cases$cim <- get_data(base_url, token, num = cohorte_num, num_type = "cohorte", data_type = 'cim10')
  cohort_data$cim <- DWHtools2::get_data(num = cohorte_num, num_type = num_type, data_type = 'cim10', config = config)
  if (!is.null(cohort_data$cim)) {
    cohort_data$cim$group = cohort
    #cohort_data$cim <- preprocess_cim(cohort_data$cim, scale1, icd_prefix  = icd_prefix, nb_occurrences = 1)
  }
  
  if(is.null(progress)) {
    cat('Done\n')
  }
  
  return (cohort_data)
  
}
aneuraz/multiWAS documentation built on July 29, 2017, 3:39 a.m.