library(tidyverse) library(magrittr) library(httr) #library(RCurl) 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("
", " ") -> current # Extraction de la table if (table == "1.D.2.EDMS") { current %<>% str_extract(str_c('Tableau \\[', table, '\\] ', subtable, '(.*?<\\/table>){3}')) %>% str_replace_all("(\\d) (\\d)", "\\1\\2") %>% str_replace_all("\\.<\\/td>", "<\\/td>") %>% str_replace_all(" ", " ") %>% str_replace_all(".*?<\\/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('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) { pasrel <- 'https://pasrel.atih.sante.fr/cas/login' epmsi <- 'https://epmsi.atih.sante.fr/' # Config proxy set_config(use_proxy(url = "ssl-proxy.chu-nancy.fr", port = 8080, username = CHUuser, password = CHUpass)) # Token print("ePMSI : TOKEN") GET(pasrel) %>% content %>% html_node("input[name='lt']") %>% html_attr("value") -> token # Login print("ePMSI : LOGIN") POST(pasrel, body = list(username = ATIHuser, password = ATIHpass, lt = token, "_eventId" = "submit", submit = "SE+CONNECTER"), encode = "form") %>% cookies -> cookie # Auth print("ePMSI : AUTH") GET(str_c(epmsi, 'authenticate.do'), set_cookies(cookie$value %>% setNames(cookie$name))) %>% cookies } getOvalide <- function(CHUuser, CHUpass, annee, mois) { epmsi <- 'https://epmsi.atih.sante.fr/' # Applis print("ePMSI : APPLIS") GET(str_c(epmsi, 'jsp/epmsi/applis/applis.jsp')) # Ovalide print("ePMSI : OVALIDE") GET(str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp')) # Ovalide MCO T2A print("ePMSI : MCO T2A") GET(str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3')) # Resultats pour annee/mois print("ePMSI : RESULTATS") GET(str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois)) # Tableaux print("ePMSI : TABLEAUX") GET(str_c(epmsi, 'appli_05.zip?action=4&win=1')) %>% content %>% writeBin(con = str_c('ePMSI/', annee, '_', mois, '.zip')) unzip(str_c('ePMSI/', annee, '_', mois, '.zip')) }