|
- library(dplyr)
- library(magrittr)
- library(RCurl)
- library(readr)
- library(stringr)
- library(rvest)
-
- extractOvalide <- function(annee, mois, table, subtable = "")
- {
- # Lire le fichier + corrections
- str_c("OVALIDE T2A.MCO.DGF", annee, mois, "html", sep = ".") %>%
- read_file(locale = locale(encoding = "ISO8859-1")) %>%
- str_replace_all("\\n", "") %>%
- str_replace_all("<br>", " ") -> current
-
- # Extraction de la table
- if (table == "1.D.2.EDMS")
- {
- current %<>%
- str_extract(str_c('<td class="c systemtitle">Tableau \\[', table, '\\] ', subtable, '(.*?<\\/table>){3}')) %>%
- str_replace_all("(\\d) (\\d)", "\\1\\2") %>%
- str_replace_all("\\.<\\/td>", "<\\/td>") %>%
- str_replace_all(" ", " ") %>%
- str_replace_all("<thead>.*?<\\/thead>", "") %>%
- read_html %>%
- html_table(trim = T, dec = ",")
- current[[1]]$X1 <- str_c(current[[1]]$X1, " - avant mars", sep = "")
- current[[2]]$X1 <- str_c(current[[2]]$X1, " - après mars", sep = "")
- if (mois < 3)
- current[[1]]
- else
- current %>% bind_rows
- } else
- {
- current %>%
- str_extract(str_c('<td class="c systemtitle">Tableau \\[', table, '\\] ', subtable, '(.*?<\\/table>){2}')) %>%
- str_replace_all("(\\d) (\\d)", "\\1\\2") %>%
- str_replace_all("\\.<\\/td>", "<\\/td>") %>%
- str_replace_all(" ", " ") %>%
- read_html %>%
- html_table(trim = T, dec = ",") %>%
- .[[1]]
- }
- }
-
- connectOvalide <- function(CHUuser, CHUpass, ATIHuser, ATIHpass)
- {
- curlopts <- list(proxy = str_c(CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080'),
- follow = T,
- cookiejar = 'cookie.jar',
- cookiefile = 'cookie.jar')
-
- curl <- str_c('curl -x "', CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080" -b cookie.jar -c cookie.jar -L ')
- pasrel <- 'https://pasrel.atih.sante.fr/cas/login'
- epmsi <- 'https://epmsi.atih.sante.fr/'
-
- unlink("cookie.jar")
-
- # Cookie
- print("ePMSI : COOKIE")
- system(str_c(curl, pasrel))
-
- # Token
- print("ePMSI : TOKEN")
- getURL(pasrel, .opts = curlopts) %>%
- read_html %>%
- html_node("input[name='lt']") %>%
- html_attr("value") -> token
- print(token)
-
- # Login
- print("ePMSI : LOGIN")
- system(str_c(curl, '-d "username=', ATIHuser, '&password=', curlPercentEncode(ATIHpass), '<=', token, '&_eventId=submit&submit=SE+CONNECTER" ', pasrel))
-
- # Auth
- print("ePMSI : AUTH")
- system(str_c(curl, epmsi, 'authenticate.do'))
- }
-
- getOvalide <- function(CHUuser, CHUpass, annee, mois)
- {
- curlopts <- list(proxy = str_c(CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080'),
- follow = T,
- cookiejar = 'cookie.jar',
- cookiefile = 'cookie.jar')
-
- epmsi <- 'https://epmsi.atih.sante.fr/'
-
- # Applis
- print("ePMSI : APPLIS")
- getURL(str_c(epmsi, 'jsp/epmsi/applis/applis.jsp'),
- .opts = curlopts) %>%
- cat
-
- # Ovalide
- print("ePMSI : OVALIDE")
- getURL(str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp'),
- referer = str_c(epmsi, 'jsp/epmsi/applis/applis.jsp'),
- .opts = curlopts) %>%
- cat
-
- # Ovalide MCO T2A
- print("ePMSI : MCO T2A")
- getURL(str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3'),
- referer = str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp'),
- .opts = curlopts) %>%
- cat
-
- # Resultats pour annee/mois
- print("ePMSI : RESULTATS")
- getURL(str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois),
- referer = str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3'),
- .opts = curlopts) %>%
- cat
-
- # Tableaux
- print("ePMSI : TABLEAUX")
- getBinaryURL(str_c(epmsi, 'appli_05.zip?action=4&win=1'),
- referer = str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois),
- .opts = curlopts) %>%
- writeBin(con = str_c('ePMSI/', annee, '_', mois, '.zip'))
-
- unzip(str_c('ePMSI/', annee, '_', mois, '.zip'))
- }
|