Skip to content
Snippets Groups Projects
harmonized_loc.R 5.02 KiB
Newer Older
### harmonized_loc.R - Analyse par localisation
Vincent DUPONT's avatar
Vincent DUPONT committed

##################
### Préparation des données de base
Vincent DUPONT's avatar
Vincent DUPONT committed
##################

# Fonctions réactives pour les dates
Vincent DUPONT's avatar
Vincent DUPONT committed
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)

# Création de la liste pour la sélection UI
HARLOC_residencial_area_list_co <- setNames(
  as.list(HARLOC_residencial_area_co$id),
  HARLOC_residencial_area_co$name
)

# Préparation des listes pour le Brésil
Vincent DUPONT's avatar
Vincent DUPONT committed
HARLOC_residencial_area_br <- JSON_area_har %>%
  filter(source == "BR") %>%
  select(id, name) %>%
  arrange(name)

HARLOC_residencial_area_list_br <- setNames(
  as.list(HARLOC_residencial_area_br$id),
  HARLOC_residencial_area_br$name
)

print("Listes de sélection :")
print("Colombie :")
print(str(HARLOC_residencial_area_list_co))
print("Brésil :")
print(str(HARLOC_residencial_area_list_br))

# Préparation des centres de santé
# Pour la Colombie
Vincent DUPONT's avatar
Vincent DUPONT committed
HARLOC_health_center_co <- JSON_healthcenter_har %>%
  filter(source == "CO") %>%
  select(id_center, name) %>%
  arrange(name)

HARLOC_health_center_list_co <- setNames(
  as.list(HARLOC_health_center_co$id_center),
  HARLOC_health_center_co$name
)

# Pour le Brésil
Vincent DUPONT's avatar
Vincent DUPONT committed
HARLOC_health_center_br <- JSON_healthcenter_har %>%
  filter(source == "BR") %>%
  select(id_center, name) %>%
  arrange(name)

HARLOC_health_center_list_br <- setNames(
  as.list(HARLOC_health_center_br$id_center),
  HARLOC_health_center_br$name
)

##################
### Interface utilisateur réactive
##################

# Interface pour la sélection des localités brésiliennes
output$HARLOClocation_br <- renderUI({
Vincent DUPONT's avatar
Vincent DUPONT committed
  switch(input$HARLOCtype,
         "residence_area" = {
           choices <- HARLOC_residencial_area_list_br
           selectInput(
             "HARLOCselection_br", 
             tr("BR"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         },
         "center" = {
           choices <- HARLOC_health_center_list_br
           selectInput(
             "HARLOCselection_br", 
             tr("BR"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         },
         "infection_place" = {
           choices <- HARLOC_residencial_area_list_br
           selectInput(
             "HARLOCselection_br", 
             tr("BR"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         }
Vincent DUPONT's avatar
Vincent DUPONT committed
  )
})

# Interface pour la sélection des localités colombiennes
output$HARLOClocation_co <- renderUI({
Vincent DUPONT's avatar
Vincent DUPONT committed
  switch(input$HARLOCtype,
         "residence_area" = {
           choices <- HARLOC_residencial_area_list_co
           selectInput(
             "HARLOCselection_co", 
             tr("CO"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         },
         "center" = {
           choices <- HARLOC_health_center_list_co
           selectInput(
             "HARLOCselection_co", 
             tr("CO"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         },
         "infection_place" = {
           choices <- HARLOC_residencial_area_list_co
           selectInput(
             "HARLOCselection_co", 
             tr("CO"), 
             choices = choices,
             multiple = TRUE,
             selectize = TRUE
           )
         }
Vincent DUPONT's avatar
Vincent DUPONT committed
  )
})

##################
### Filtrage des données
##################
Vincent DUPONT's avatar
Vincent DUPONT committed

# Données pour la Colombie
HARLOC_sub_co <- reactive({
  req(input$HARLOCtype)
  req(input$HARLOCselection_co)
Vincent DUPONT's avatar
Vincent DUPONT committed
  
  # Ajout de messages de diagnostic
  print("Filtrage des données colombiennes")
  print(paste("Type sélectionné:", input$HARLOCtype))
  print(paste("Sélections:", paste(input$HARLOCselection_co, collapse=", ")))
Vincent DUPONT's avatar
Vincent DUPONT committed
  
  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())
Vincent DUPONT's avatar
Vincent DUPONT committed
  
  # Filtrage selon le type de localisation
  df <- switch(input$HARLOCtype,
               "center" = df %>% filter(id_center %in% input$HARLOCselection_co),
               "residence_area" = df %>% filter(residence_place %in% input$HARLOCselection_co),
               "infection_place" = df %>% filter(infection_place %in% input$HARLOCselection_co)
  )
Vincent DUPONT's avatar
Vincent DUPONT committed
  
  print(paste("Nombre de cas après filtrage:", nrow(df)))
Vincent DUPONT's avatar
Vincent DUPONT committed
  return(df)
})

# Données pour le Brésil (même structure)
HARLOC_sub_br <- reactive({
  # Code similaire pour le Brésil
})