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.

110 lines
3.0KB

  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 = 100*1024^2)
  9. # CCAM ====
  10. read_csv("CCAM.csv") %>%
  11. `names<-`(c("code", "libelle", "classant", "ICR", "phase")) %>%
  12. arrange(code) %>%
  13. distinct %>%
  14. group_by(code) %>%
  15. summarize(libelle = first(libelle),
  16. classant = max(classant),
  17. ICR = max(ICR, na.rm = T)) -> ccam
  18. # UI ====
  19. ui <- fluidPage(
  20. titlePanel("Actes manquants collact → pims"),
  21. sidebarLayout(
  22. sidebarPanel(
  23. a(href = "README.html", "Manuel d'utilisation"),
  24. hr(),
  25. numericInput("annee", "Année", Sys.Date() %>% year),
  26. fileInput("collact", "Fichier collact", accept = "text/csv"),
  27. fileInput("webpims", "Fichier webpims", accept = "text/csv"),
  28. width = 3
  29. ),
  30. mainPanel(
  31. DT::dataTableOutput("resultat")
  32. )
  33. )
  34. )
  35. # SERVER ====
  36. server <- function(input, output)
  37. {
  38. # collact ====
  39. collact <- reactive({
  40. req(input$collact)
  41. read_csv(input$collact$datapath, col_types = "cccc") %>%
  42. `names<-`(c("idhosp", "code", "date", "internum")) %>%
  43. #mutate(date = date %>% as.Date(format = "%d/%m/%Y") + years(2000)) %>%
  44. mutate(date = date %>% as.Date(format = "%d/%m/%Y")) %>%
  45. filter(date <= as.Date(str_c(input$annee, "-12-31")))
  46. })
  47. # webpims ====
  48. pims <- reactive({
  49. req(input$webpims)
  50. read_csv(input$webpims$datapath, col_types = "ccc") %>%
  51. `names<-`(c("idhosp", "code", "date")) %>%
  52. #mutate(date = date %>% as.Date(format = "%Y/%m/%d"),
  53. mutate(date = date %>% as.Date(format = "%d/%m/%Y"),
  54. code = code %>% str_sub(1,7)) %>%
  55. filter(date <= as.Date(str_c(input$annee, "-12-31")))
  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. filter(!((code %>% str_detect("^JVJF")) & (date < str_c(input$annee, "-01-01")))) %>%
  68. anti_join(pims()) %>%
  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)