You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.9KB

  1. library(tidyverse)
  2. library(magrittr)
  3. library(httr)
  4. #library(RCurl)
  5. library(stringr)
  6. library(rvest)
  7. extractOvalide <- function(annee, mois, table, subtable = "")
  8. {
  9. # Lire le fichier + corrections
  10. str_c("OVALIDE T2A.MCO.DGF", annee, mois, "html", sep = ".") %>%
  11. read_file(locale = locale(encoding = "ISO8859-1")) %>%
  12. str_replace_all("\\n", "") %>%
  13. str_replace_all("<br>", " ") -> current
  14. # Extraction de la table
  15. if (table == "1.D.2.EDMS")
  16. {
  17. current %<>%
  18. str_extract(str_c('<td class="c systemtitle">Tableau \\[', table, '\\] ', subtable, '(.*?<\\/table>){3}')) %>%
  19. str_replace_all("(\\d) (\\d)", "\\1\\2") %>%
  20. str_replace_all("\\.<\\/td>", "<\\/td>") %>%
  21. str_replace_all("&nbsp;", " ") %>%
  22. str_replace_all("<thead>.*?<\\/thead>", "") %>%
  23. read_html %>%
  24. html_table(trim = T, dec = ",")
  25. current[[1]]$X1 <- str_c(current[[1]]$X1, " - avant mars", sep = "")
  26. current[[2]]$X1 <- str_c(current[[2]]$X1, " - après mars", sep = "")
  27. if (mois < 3)
  28. current[[1]]
  29. else
  30. current %>% bind_rows
  31. } else
  32. {
  33. current %>%
  34. str_extract(str_c('<td class="c systemtitle">Tableau \\[', table, '\\] ', subtable, '(.*?<\\/table>){2}')) %>%
  35. str_replace_all("(\\d) (\\d)", "\\1\\2") %>%
  36. str_replace_all("\\.<\\/td>", "<\\/td>") %>%
  37. str_replace_all("&nbsp;", " ") %>%
  38. read_html %>%
  39. html_table(trim = T, dec = ",") %>%
  40. .[[1]]
  41. }
  42. }
  43. connectOvalide <- function(CHUuser, CHUpass, ATIHuser, ATIHpass)
  44. {
  45. pasrel <- 'https://pasrel.atih.sante.fr/cas/login'
  46. epmsi <- 'https://epmsi.atih.sante.fr/'
  47. # Config proxy
  48. set_config(use_proxy(url = "ssl-proxy.chu-nancy.fr", port = 8080, username = CHUuser, password = CHUpass))
  49. # Token
  50. print("ePMSI : TOKEN")
  51. GET(pasrel) %>%
  52. content %>%
  53. html_node("input[name='lt']") %>%
  54. html_attr("value") -> token
  55. # Login
  56. print("ePMSI : LOGIN")
  57. POST(pasrel, body = list(username = ATIHuser, password = ATIHpass, lt = token, "_eventId" = "submit", submit = "SE+CONNECTER"), encode = "form") %>% cookies -> cookie
  58. # Auth
  59. print("ePMSI : AUTH")
  60. GET(str_c(epmsi, 'authenticate.do'), set_cookies(cookie$value %>% setNames(cookie$name))) %>% cookies
  61. }
  62. getOvalide <- function(CHUuser, CHUpass, annee, mois)
  63. {
  64. epmsi <- 'https://epmsi.atih.sante.fr/'
  65. # Applis
  66. print("ePMSI : APPLIS")
  67. GET(str_c(epmsi, 'jsp/epmsi/applis/applis.jsp'))
  68. # Ovalide
  69. print("ePMSI : OVALIDE")
  70. GET(str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp'))
  71. # Ovalide MCO T2A
  72. print("ePMSI : MCO T2A")
  73. GET(str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3'))
  74. # Resultats pour annee/mois
  75. print("ePMSI : RESULTATS")
  76. GET(str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois))
  77. # Tableaux
  78. print("ePMSI : TABLEAUX")
  79. GET(str_c(epmsi, 'appli_05.zip?action=4&win=1')) %>%
  80. content %>%
  81. writeBin(con = str_c('ePMSI/', annee, '_', mois, '.zip'))
  82. unzip(str_c('ePMSI/', annee, '_', mois, '.zip'))
  83. }