necessary_functions_connection.R 2.52 KB
Newer Older
pxp9's avatar
pxp9 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

connect <- function (){
  
  cat("\n\n\n----------------------------------------------------------------------------------------------------------")
  cat("\nPlease select the number corresponding to the hospital you want to analyse, if you want to do a combined analysis select multiple hospitals")
  cat("\n  
        Princesa -> 1  
        CIPH -> 2  
        UMF_Iasis -> 3  
        SMUC -> 4  
        HM -> 5  
        Porto -> 6  
        FJD -> 7  
        Coimbra -> 8  
        UNAV -> 9 
        TU -> 10 
        
          Baskent:
          
          Ankara Impatient -> 11
          Konya Impatient -> 12
          Istambul Impatient -> 13
          Izmir Impatient -> 14
          Alanya Impatient -> 15
          Adana Impatient -> 16
          
          Ankara Outpatient -> 17
          Konya Outpatient -> 18
          Istambul Outpatient -> 19
          Izmir Outpatient -> 20
          Alanya Outpatient -> 21
          
        Sacrocuore:
        
          Emergency database -> 22
          Employees database -> 23
          Verona database -> 24
          Isaric -> 25
        
        TU Dublin -> 26
        UMF Cluj -> 27
        UdeA -> 28
        Inantro -> 29
        UNSA -> 30
        UZA -> 31
          
      ")
  
  inp <- scan()
  
  builder <- DSI::newDSLoginBuilder()
  
  
  hospital_names <- hospital_names[inp]
  project_names <- project_names[inp]
  resource_names <- resource_names[inp]
  urls <- urls[inp]
  users <- users[inp]
  pass <- pass[inp]
  
  print(hospital_names)
  print(project_names)
  print(resource_names)
  print(urls)
  print(users)
  print(pass)
  
  url_ctr <- 0
  for(i in 1:length(urls)){
    print(paste("Connecting to Server with URL:", urls[i], sep=" "))
    builder$append(server = hospital_names[i], url = urls[i],
                   user = users[i], password = pass[i],
                   resource = paste(project_names[i], resource_names[i], sep="."),
                   driver = "OpalDriver", options="list(ssl_verifyhost=0,ssl_verifypeer=0)")
    
    url_ctr <- url_ctr+1
  }
  
  logindata <- builder$build()
  
  connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D", failSafe = TRUE)
  
  
  datashield.assign.expr(connections, symbol = 'data', expr = quote(as.resource.data.frame(D)))
  #datashield.assign.expr(connections, symbol = 'auxDf', expr = quote(as.resource.data.frame(D)))
  
  
  print("Successful connection to servers.")
  
  return(list(connections,inp))
}