Skip to content
Snippets Groups Projects
harmonized_loc.R 5.82 KiB
Newer Older
Vincent DUPONT's avatar
Vincent DUPONT committed
### harmonized_loc.R
### Module pour l'analyse des localisations harmonisées

##################
### Objets de données
##################

date1 <- reactive({
  as.Date(paste0(input$HARLOCdates[1],"-01-01"))
})

date2 <- reactive({
  as.Date(paste0(input$HARLOCdates[2],"-12-31"))
})

# Préparation des listes de zones pour la Colombie
HARLOC_residencial_area_co <- JSON_area_har %>%
  filter(source == "CO") %>%
  select(id, name) %>%
  arrange(name)
HARLOC_residencial_area_list_co <- with(HARLOC_residencial_area_co, split(id, name))

# Préparation des listes de zones pour le Brésil
HARLOC_residencial_area_br <- JSON_area_har %>%
  filter(source == "BR") %>%
  select(id, name) %>%
  arrange(name)
HARLOC_residencial_area_list_br <- with(HARLOC_residencial_area_br, split(id, name))

# Préparation des centres de santé pour la Colombie
HARLOC_health_center_co <- JSON_healthcenter_har %>%
  filter(source == "CO") %>%
  select(id_center, name) %>%
  arrange(name)
HARLOC_health_center_list_co <- with(HARLOC_health_center_co, split(id_center, name))

# Préparation des centres de santé pour le Brésil
HARLOC_health_center_br <- JSON_healthcenter_har %>%
  filter(source == "BR") %>%
  select(id_center, name) %>%
  arrange(name)
HARLOC_health_center_list_br <- with(HARLOC_health_center_br, split(id_center, name))

# Interface utilisateur réactive pour la sélection des localisations
output$HARLOClocation_co <- renderUI({
  switch(input$HARLOCtype,
         "residence_area" = selectInput("HARLOCselection_co", tr("CO"), 
                                        HARLOC_residencial_area_list_co, 
                                        multiple = TRUE),
         "center" = selectInput("HARLOCselection_co", tr("CO"), 
                                HARLOC_health_center_list_co, 
                                multiple = TRUE),
         "infection_place" = selectInput("HARLOCselection_co", tr("CO"), 
                                         HARLOC_residencial_area_list_co, 
                                         multiple = TRUE)
  )
})

# Interface pour la sélection des localisations brésiliennes (inchangée)
output$HARLOClocation_br <- renderUI({
  switch(input$HARLOCtype,
         "residence_area" = selectInput("HARLOCselection_br", tr("BR"), 
                                        HARLOC_residencial_area_list_br, 
                                        multiple = TRUE),
         "center" = selectInput("HARLOCselection_br", tr("BR"), 
                                HARLOC_health_center_list_br, 
                                multiple = TRUE),
         "infection_place" = selectInput("HARLOCselection_br", tr("BR"), 
                                         HARLOC_residencial_area_list_br, 
                                         multiple = TRUE)
  )
})

# Filtrage des données pour la Colombie
HARLOC_sub_co <- reactive({
  df <- consultation_har_filter(JSON_cons_har,
                                source = "CO",
                                new_attack = input$HARLOCnew_attack,
                                diagn = input$HARLOCdiagn,
                                sex = input$HARLOCsex,
                                minAge = input$HARLOCage[1], 
                                maxAge = input$HARLOCage[2]
  ) %>%
    filter(consultation_date >= date1() & consultation_date <= date2()) 
  
  if(input$HARLOCtype == "center"){
    df <- df %>% filter(id_center %in% input$HARLOCselection_co)
  } else if(input$HARLOCtype == "residence_area"){
    df <- df %>% filter(residence_place %in% input$HARLOCselection_co)
  } else if(input$HARLOCtype == "infection_place"){
    df <- df %>% filter(infection_place %in% input$HARLOCselection_co)
  }
  
  return(df)
})

# Filtrage des données pour le Brésil (similaire au code existant)
HARLOC_sub_br <- reactive({
  df <- consultation_har_filter(JSON_cons_har,
                                source = "BR",
                                new_attack = input$HARLOCnew_attack,
                                diagn = input$HARLOCdiagn,
                                sex = input$HARLOCsex,
                                minAge = input$HARLOCage[1], 
                                maxAge = input$HARLOCage[2]
  ) %>%
    filter(consultation_date >= date1() & consultation_date <= date2())
  
  if(input$HARLOCtype == "center"){
    df <- df %>% filter(id_center %in% input$HARLOCselection_br)
  } else if(input$HARLOCtype == "residence_area"){
    df <- df %>% filter(residence_place %in% input$HARLOCselection_br)
  } else if(input$HARLOCtype == "infection_place"){
    df <- df %>% filter(infection_place %in% input$HARLOCselection_br)
  }
  
  return(df)
})

# Qualité de l'information pour la Colombie
HARLOC_sub_infqual_co <- reactive({
  df <- consultation_har_filter(JSON_cons_har,
                                source = "CO",
                                new_attack = input$HARLOCnew_attack,
                                diagn = input$HARLOCdiagn,
                                sex = input$HARLOCsex,
                                minAge = input$HARLOCage[1], 
                                maxAge = input$HARLOCage[2]
  ) %>%
    filter(consultation_date >= date1() & consultation_date <= date2()) %>%
    is.na() %>%
    colMeans() * 100
  
  df <- replace(df, is.nan(df), 100)
  
  return(df)
})

# Qualité de l'information pour le Brésil
HARLOC_sub_infqual_br <- reactive({
  # [Code existant inchangé]
})

# Tableaux par jour de la semaine
HARLOC_co_tab_day_week <- reactive({
  if(nrow(HARLOC_sub_co()) > 0){
    as.data.frame(incidence(HARLOC_sub_co()$consultation_date, interval = 1))
  }
})

HARLOC_br_tab_day_week <- reactive({
  # [Code existant inchangé]
})

##################
### Graphiques
##################

# Graphique d'incidence
output$HARLOC_plot_incidence <- renderPlotly({
  # [Suite du code avec les adaptations nécessaires]
})

# [Autres graphiques et visualisations avec adaptations similaires]