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.

112 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. br(),
  29. a(href = "https://livenne.chu-nancy.fr/shiny_files/actes/actes_pims.wid", "Requête webPIMS"),
  30. hr(),
  31. fileInput("collact", "Fichier collact", accept = "text/csv"),
  32. fileInput("webpims", "Fichier webpims", accept = "text/csv"),
  33. width = 3
  34. ),
  35. mainPanel(
  36. DT::dataTableOutput("resultat")
  37. )
  38. )
  39. )
  40. # SERVER ====
  41. server <- function(input, output)
  42. {
  43. # collact ====
  44. collact <- reactive({
  45. req(input$collact)
  46. read_csv(input$collact$datapath) %>%
  47. setNames(c("nda", "entree", "sortie", "code", "date", "uf", "uf_lib")) %>%
  48. mutate(date = date %>% as.Date(format = "%Y/%m/%d %H:%M:%S")) -> collact
  49. })
  50. # webpims ====
  51. pims <- reactive({
  52. req(input$webpims)
  53. read_csv(input$webpims$datapath) %>%
  54. setNames(c("nda", "code", "date")) %>%
  55. mutate(date = date %>% as.Date(format = "%Y/%m/%d %H:%M:%S"),
  56. code = code %>% str_sub(1,7)) -> pims
  57. })
  58. # Output
  59. output$resultat <- DT::renderDataTable(
  60. {
  61. req(collact(), pims())
  62. withProgress(message = "Calcul…",
  63. value = 0.25,
  64. detail = "Différence collact-pims",
  65. {
  66. # Collact - PIMS ====
  67. collact() %>%
  68. anti_join(pims(), by = c("nda", "code", "date")) %>%
  69. left_join(ccam, by = "code") -> collact_pims
  70. setProgress(.5, detail = "Agrégation")
  71. # Summary ====
  72. collact_pims %>%
  73. filter(classant == "Oui") %>%
  74. group_by(code, libelle) %>%
  75. summarize(n = n(),
  76. ICR = sum(ICR)) %>%
  77. ungroup %>%
  78. arrange(desc(ICR)) -> summ_actes
  79. setProgress(.75, detail = "Liste finale")
  80. # Liste finale ====
  81. collact_pims %>%
  82. inner_join(summ_actes, by = c("code", "libelle")) %>%
  83. rename(`ICR acte` = ICR.x,
  84. `ICR total` = ICR.y) %>%
  85. arrange(desc(`ICR total`)) %>%
  86. mutate(code = code %>% factor) %>%
  87. select(-classant)
  88. })},
  89. extensions = "Buttons",
  90. filter = "top",
  91. options = list(paging = F,
  92. searching = T,
  93. dom = "Bfrtip",
  94. buttons = c("copy", "excel")))
  95. }
  96. shinyApp(ui = ui, server = server)