<commit_before>#' ### CODE OWNERS: <NAME>
#'
#' ### OBJECTIVE:
#'   * Server side code of Epic FHIR Shiny App.
#'
#' ### DEVELOPER NOTES:
#'   * None

require(shiny)
require(dplyr)
require(magrittr)

source('r/load_data.r', chdir=TRUE)

#' ### LIBRARIES, LOCATIONS, LITERALS, ETC. GO ABOVE HERE

freq.name <- df.results %>%
  group_by(name) %>% 
  summarize(n=n()) %>% 
  ungroup()

choices.name <- df.patients %>% 
  inner_join(freq.name) %>% 
  mutate(
    n = ifelse(is.na(n), 0, n)
    ,name.disp = paste0(name, ' (n=', n, ')')
    ) %>%
  arrange(desc(n)) %>% {
    names.decorated <- .$name
    names(names.decorated) <- .$name.disp
    names.decorated
  }

shinyServer(function(input, output) {

  output$ui_name <- renderUI({
    selectInput(
      "select_name"
      ,label="Patient Name"
      ,choices=choices.name
      ,selected=choices.name[1]
      )
  })
  
  output$patient_dob <- renderText({
    df.patients %>%
      filter(name == input$select_name) %>% {
        as.character(.$dob.r)
      }
  })
  
  output$patient_address <- renderText({
    df.patients %>%
      filter(name == input$select_name) %>% {
        ifelse(.$address=='','Unknown',.$address)
      }
  })
  
  output$ui_loinc <- renderUI({
    
    choices.loinc <- freq.loinc %>% 
      filter(name == input$select_name) %>% 
      inner_join(df.labs, by = 'loinc') %>% 
      mutate(
        loinc.disp = paste0(
          loinc
          ,' '
          ,desc
          ,' (n='
          ,n
          ,')'
          )
      ) %>% {
        loinc.decorated <- .$loinc
        names(loinc.decorated) <- .$loinc.disp
        loinc.decorated
      }
    
    selectInput(
      "select_loinc"
      ,label="LOINC Code"
      ,choices=choices.loinc
      ,selected=choices.loinc<commit_msg>Improve selectors.<commit_after>#' ### CODE OWNERS: <NAME>
#'
#' ### OBJECTIVE:
#'   * Server side code of Epic FHIR Shiny App.
#'
#' ### DEVELOPER NOTES:
#'   * None

require(shiny)
require(dplyr)
require(magrittr)

source('r/load_data.r', chdir=TRUE)

#' ### LIBRARIES, LOCATIONS, LITERALS, ETC. GO ABOVE HERE

freq.name <- df.results %>%
  group_by(name) %>% 
  summarize(n=n()) %>% 
  ungroup()

choices.name <- df.patients %>% 
  inner_join(freq.name) %>% 
  mutate(
    n = ifelse(is.na(n), 0, n)
    ,name.disp = paste0(name, ' (n=', n, ')')
    ) %>%
  arrange(desc(n)) %>% {
    names.decorated <- .$name
    names(names.decorated) <- .$name.disp
    names.decorated
  }

freq.loinc <- df.results %>%
  group_by(name, loinc) %>% 
  summarize(n=n()) %>% 
  ungroup()


shinyServer(function(input, output) {

  output$ui_name <- renderUI({
    radioButtons(
      "select_name"
      ,label="Patient Name"
      ,choices=choices.name
      ,selected=choices.name[1]
      )
  })
  
  output$patient_dob <- renderText({
    df.patients %>%
      filter(name == input$select_name) %>% {
        as.character(.$dob.r)
      }
  })
  
  output$patient_address <- renderText({
    df.patients %>%
      filter(name == input$select_name) %>% {
        ifelse(.$address=='','Unknown',.$address)
      }
  })
  
  output$ui_loinc <- renderUI({
    
    choices.loinc <- freq.loinc %>% 
      filter(name == input$select_name) %>% 
      inner_join(df.labs, by = 'loinc') %>% 
      mutate(
        loinc.disp = paste0(
          loinc
          ,' '
          ,desc
          ,' (n='
          ,n
          ,')'
          )
      ) %>% 
      arrange(desc(n)) %>% {
        loinc.decorated <- .$loinc
        names(loinc.decorated) <- .$loinc.disp
        loinc.decorated
      }
    
    radioButtons(
      "select_loinc"
      ,label="LOINC Code"
      ,choices=choices.loinc
      ,selected=choices.loinc[1]
{'fraction_non_alphanumeric': 0.17986977753662506, 'fraction_numerical': 0.0024416711882799783, 'mean_word_length': 2.242744063324538, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '151039', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1347, 'n_words': 207}