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.

125 lines
3.8KB

  1. library(dplyr)
  2. library(magrittr)
  3. library(RCurl)
  4. library(readr)
  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. curlopts <- list(proxy = str_c(CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080'),
  46. follow = T,
  47. cookiejar = 'cookie.jar',
  48. cookiefile = 'cookie.jar')
  49. curl <- str_c('curl -x "', CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080" -b cookie.jar -c cookie.jar -L ')
  50. pasrel <- 'https://pasrel.atih.sante.fr/cas/login'
  51. epmsi <- 'https://epmsi.atih.sante.fr/'
  52. unlink("cookie.jar")
  53. # Cookie
  54. print("ePMSI : COOKIE")
  55. system(str_c(curl, pasrel))
  56. # Token
  57. print("ePMSI : TOKEN")
  58. getURL(pasrel, .opts = curlopts) %>%
  59. read_html %>%
  60. html_node("input[name='lt']") %>%
  61. html_attr("value") -> token
  62. print(token)
  63. # Login
  64. print("ePMSI : LOGIN")
  65. system(str_c(curl, '-d "username=', ATIHuser, '&password=', curlPercentEncode(ATIHpass), '&lt=', token, '&_eventId=submit&submit=SE+CONNECTER" ', pasrel))
  66. # Auth
  67. print("ePMSI : AUTH")
  68. system(str_c(curl, epmsi, 'authenticate.do'))
  69. }
  70. getOvalide <- function(CHUuser, CHUpass, annee, mois)
  71. {
  72. curlopts <- list(proxy = str_c(CHUuser, ':', CHUpass, '@ssl-proxy.chu-nancy.fr:8080'),
  73. follow = T,
  74. cookiejar = 'cookie.jar',
  75. cookiefile = 'cookie.jar')
  76. epmsi <- 'https://epmsi.atih.sante.fr/'
  77. # Applis
  78. print("ePMSI : APPLIS")
  79. getURL(str_c(epmsi, 'jsp/epmsi/applis/applis.jsp'),
  80. .opts = curlopts) %>%
  81. cat
  82. # Ovalide
  83. print("ePMSI : OVALIDE")
  84. getURL(str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp'),
  85. referer = str_c(epmsi, 'jsp/epmsi/applis/applis.jsp'),
  86. .opts = curlopts) %>%
  87. cat
  88. # Ovalide MCO T2A
  89. print("ePMSI : MCO T2A")
  90. getURL(str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3'),
  91. referer = str_c(epmsi, 'jsp/epmsi/applis/applisMat2a.jsp'),
  92. .opts = curlopts) %>%
  93. cat
  94. # Resultats pour annee/mois
  95. print("ePMSI : RESULTATS")
  96. getURL(str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois),
  97. referer = str_c(epmsi, 'appli_16.do?champPmsi=1&statut=1&applicationType=3'),
  98. .opts = curlopts) %>%
  99. cat
  100. # Tableaux
  101. print("ePMSI : TABLEAUX")
  102. getBinaryURL(str_c(epmsi, 'appli_05.zip?action=4&win=1'),
  103. referer = str_c(epmsi, 'appli_05.do?year=', annee, '&period=', mois),
  104. .opts = curlopts) %>%
  105. writeBin(con = str_c('ePMSI/', annee, '_', mois, '.zip'))
  106. unzip(str_c('ePMSI/', annee, '_', mois, '.zip'))
  107. }