---
title: Endoscopies
output:
  html_document:
    toc: true
    toc_float: true
params:
  endoscopies: NA
  endoscopies_ext: NA
  endoscopies_hos: NA
  liste_actes: NA
---

```{r setup, message = F, warning = F, echo = F}
library(tidyverse)
library(DT)
library(knitr)
library(magrittr)
library(stringr)

endoscopies <- params$endoscopies
endoscopies_ext <- params$endoscopies_ext
endoscopies_hos <- params$endoscopies_hos
liste_actes <- params$liste_actes

opts_chunk$set(message = F,
               echo = F,
               warning = F)
options(DT.options = list(paging = F,
                          searching = F,
                          info = F,
                          dom = "Bfrtip",
                          buttons = c("copy", "excel")))
```

# Codes utilisés {.tabset}

## ORL

```{r liste_orl}
liste_actes %>%
  filter(Appareil == "ORL") %>%
  select(- Appareil) %>%
  datatable(rownames = F, options = list(paging = T, searching = T))
```

## Digestif

```{r liste_dig}
liste_actes %>%
  filter(Appareil == "Digestif") %>%
  select(- Appareil) %>%
  datatable(rownames = F, options = list(paging = T, searching = T))
```

## Respiratoire

```{r liste_respi}
liste_actes %>%
  filter(Appareil == "Respiratoire") %>%
  select(- Appareil) %>%
  datatable(rownames = F, options = list(paging = T, searching = T))
```

## Génito-urinaire

```{r liste_uro}
liste_actes %>%
  filter(Appareil == "Genito-urinaire") %>%
  select(- Appareil) %>%
  datatable(rownames = F, options = list(paging = T, searching = T))
```

# Global

## Total

```{r global_total}
endoscopies %>%
  summarise(Venues = n_distinct(Venue)) %>%
  datatable(rownames = F,
            extensions = "Buttons")
```

## Par service exécutant
```{r global_par_service}
endoscopies %>%
  group_by(Service) %>%
  summarise(Venues = n_distinct(Venue)) %>%
  ungroup %>%
  arrange(desc(Venues)) %>%
  datatable(rownames = F,
            extensions = "Buttons")
```

# Externe

## Total
```{r ext_total}
endoscopies_ext %>%
  summarise(Venues = n_distinct(Venue),
            Valorisation = sum(Tarif)) %>%
  datatable(rownames = F,
            extensions = "Buttons") %>%
  formatCurrency(2, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par appareil
```{r ext_par_appareil}
endoscopies_ext %>%
  group_by(Appareil) %>%
  summarise(Venues = n_distinct(Venue),
            Valorisation = sum(Tarif)) %>%
  arrange(desc(Valorisation)) %>%
  datatable(rownames = F,
            extensions = "Buttons") %>%
  formatCurrency(3, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par acte
```{r ext_par_acte}
endoscopies_ext %>%
  group_by(Acte, Acte_libelle) %>%
  summarise(Venues = n_distinct(Venue),
            Valorisation = sum(Tarif)) %>%
  ungroup %>%
  arrange(desc(Valorisation)) %>%
  datatable(options = list(paging = T, searching = T),
            colnames = c("Libelle" = "Acte_libelle"),
            rownames = F,
            extensions = "Buttons") %>%
  formatCurrency(4, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par service exécutant
```{r ext_par_service}
endoscopies_ext %>%
  group_by(Service) %>%
  summarise(Venues = n_distinct(Venue),
            Valorisation = sum(Tarif)) %>%
  ungroup %>%
  arrange(desc(Valorisation)) %>%
  datatable(rownames = F,
            extensions = "Buttons") %>%
  formatCurrency(3, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par service exécutant et par acte
```{r ext_par_acte_et_service}
endoscopies_ext %>%
  group_by(Service, Acte, Acte_libelle) %>%
  summarise(Venues = n_distinct(Venue),
            Valorisation = sum(Tarif)) %>%
  arrange(Service, desc(Valorisation)) %>%
  ungroup %>%
  datatable(options = list(paging = T, searching = T),
            colnames = c("Libelle" = "Acte_libelle"),
            rownames = F,
            extensions = "Buttons",
            filter = "top") %>%
  formatCurrency(5, currency = "€", dec.mark = ",", mark = " ", before = F)
```


# Hospitalisation

## Total
```{r total_hos}
endoscopies_hos %>%
  summarise(RSS = n(),
            Valorisation = sum(Valorisation)) %>%
  datatable(rownames = F,
            extensions = "Buttons") %>%
  formatCurrency(2, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par durée d'hospitalisation
```{r hos_par_durée}
endoscopies_hos %>%
  group_by(Type_duree) %>%
  summarise(RSS = n(),
            Valorisation = sum(Valorisation)) %>%
  datatable(rownames = F,
            colnames = c("Durée" = "Type_duree"),
            extensions = "Buttons") %>%
  formatCurrency(3, currency = "€", dec.mark = ",", mark = " ", before = F)
```

## Par GHM {.tabset}

### 0 ou 1j
```{r ghm_hos_0j}
endoscopies_hos %>%
  filter(Type_duree == "0 ou 1 j") %>%
  group_by(GHM, GHM_libelle) %>%
  summarise(RSS = n(),
            Valorisation = sum(Valorisation)) %>%
  ungroup %>%
  arrange(desc(RSS)) %>%
  datatable(rownames = F,
            colnames = c("Libelle GHM" = "GHM_libelle"),
            options = list(paging = T),
            extensions = "Buttons") %>%
  formatCurrency(4, currency = "€", dec.mark = ",", mark = " ", before = F) %>%
  formatRound(5)
```

### 1+ j
```{r ghm_hos_1j}
endoscopies_hos %>%
  filter(Type_duree == "1+ j") %>%
  group_by(GHM, GHM_libelle) %>%
  summarise(RSS = n(),
            Valorisation = sum(Valorisation)) %>%
  ungroup %>%
  arrange(desc(RSS)) %>%
  datatable(rownames = F,
            colnames = c("Libelle GHM" = "GHM_libelle"),
            options = list(paging = T),
            extensions = "Buttons") %>%
  formatCurrency(4, currency = "€", dec.mark = ",", mark = " ", before = F) %>%
  formatRound(5)
```
