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.

111 lines
3.1KB

  1. library(tidyverse)
  2. library(rmarkdown)
  3. library(lubridate)
  4. library(magrittr)
  5. library(stringr)
  6. library(shiny)
  7. library(DT)
  8. options(shiny.maxRequestSize = 500*1024^2)
  9. if (!dir.exists("/var/www/html/shiny_files/actes"))
  10. dir.create("/var/www/html/shiny_files/actes")
  11. file.copy("actes_collact.wid", "/var/www/html/shiny_files/actes", overwrite = T) -> null
  12. file.copy("actes_pims.wid", "/var/www/html/shiny_files/actes", overwrite = T) -> null
  13. # CCAM ====
  14. read_csv("CCAM.csv") %>%
  15. `names<-`(c("code", "libelle", "classant", "ICR", "phase")) %>%
  16. arrange(code) %>%
  17. distinct %>%
  18. group_by(code) %>%
  19. summarize(libelle = first(libelle),
  20. classant = max(classant),
  21. ICR = max(ICR, na.rm = T)) -> ccam
  22. # UI ====
  23. ui <- fluidPage(
  24. titlePanel("Actes manquants collact → pims"),
  25. sidebarLayout(
  26. sidebarPanel(
  27. a(href = "https://livenne.chu-nancy.fr/shiny_files/actes/actes_collact.wid", "Requête collact"),
  28. a(href = "https://livenne.chu-nancy.fr/shiny_files/actes/actes_pims.wid", "Requête webPIMS"),
  29. hr(),
  30. fileInput("collact", "Fichier collact", accept = "text/csv"),
  31. fileInput("webpims", "Fichier webpims", accept = "text/csv"),
  32. width = 3
  33. ),
  34. mainPanel(
  35. DT::dataTableOutput("resultat")
  36. )
  37. )
  38. )
  39. # SERVER ====
  40. server <- function(input, output)
  41. {
  42. # collact ====
  43. collact <- reactive({
  44. req(input$collact)
  45. read_csv(input$collact$datapath) %>%
  46. setNames(c("nda", "entree", "sortie", "code", "date", "uf", "uf_lib")) %>%
  47. mutate(date = date %>% as.Date(format = "%Y/%m/%d %H:%M:%S")) -> collact
  48. })
  49. # webpims ====
  50. pims <- reactive({
  51. req(input$webpims)
  52. read_csv(input$webpims$datapath) %>%
  53. setNames(c("nda", "code", "date")) %>%
  54. mutate(date = date %>% as.Date(format = "%Y/%m/%d %H:%M:%S"),
  55. code = code %>% str_sub(1,7)) -> pims
  56. })
  57. # Output
  58. output$resultat <- DT::renderDataTable(
  59. {
  60. req(collact(), pims())
  61. withProgress(message = "Calcul…",
  62. value = 0.25,
  63. detail = "Différence collact-pims",
  64. {
  65. # Collact - PIMS ====
  66. collact() %>%
  67. anti_join(pims(), by = c("nda", "code", "date")) %>%
  68. left_join(ccam, by = "code") -> collact_pims
  69. setProgress(.5, detail = "Agrégation")
  70. # Summary ====
  71. collact_pims %>%
  72. filter(classant == "Oui") %>%
  73. group_by(code, libelle) %>%
  74. summarize(n = n(),
  75. ICR = sum(ICR)) %>%
  76. ungroup %>%
  77. arrange(desc(ICR)) -> summ_actes
  78. setProgress(.75, detail = "Liste finale")
  79. # Liste finale ====
  80. collact_pims %>%
  81. inner_join(summ_actes, by = c("code", "libelle")) %>%
  82. rename(`ICR acte` = ICR.x,
  83. `ICR total` = ICR.y) %>%
  84. arrange(desc(`ICR total`)) %>%
  85. mutate(code = code %>% factor) %>%
  86. select(-classant)
  87. })},
  88. extensions = "Buttons",
  89. filter = "top",
  90. options = list(paging = F,
  91. searching = T,
  92. dom = "Bfrtip",
  93. buttons = c("copy", "excel")))
  94. }
  95. shinyApp(ui = ui, server = server)