Skip to content

Commit

Permalink
resolves #133 charts will need more review in general but this fixes …
Browse files Browse the repository at this point in the history
…the error by making units in legend conditional on their existence
  • Loading branch information
pburnsdata committed May 2, 2024
1 parent 052a5fd commit c7e760b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion R/patient_profile_charts.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ drawRawChange <- function(adlb, settings, labs = c("Creatinine", "Cystatin C"),

n_orig_test <- n_distinct(adlb_raw_chg[[settings$measure_col]]) #save number of tests for warning information later

# Add units to Test so that legend includes units for user to see
# Add units to Test so that legend includes units for user to see, if units provided in data

if (settings$unit_col != "") {

adlb_raw_chg <- adlb_raw_chg %>%
mutate(!!settings$measure_col := paste0(.data[[settings$measure_col]], " (", .data[[settings$unit_col]], ")"))

}

n_der_test <- n_distinct(adlb_raw_chg[[settings$measure_col]])

if (n_orig_test != n_der_test) {
Expand Down
15 changes: 8 additions & 7 deletions R/patient_profile_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ patientProfileServer <- function(id, df, settings, subj_id) {
function(input, output, session) {

#grab settings from each domain
dm_settings <-settings$dm
lab_settings <-settings$labs
vitals_settings <-settings$vitals
dm_settings <- settings$dm
lab_settings <- settings$labs
vitals_settings <- settings$vitals

# filter to selected patient
patient_df <- df %>%
patient_df <- df %>%
filter(.data[[dm_settings$id_col]] == subj_id)

## TO DO: pass settings object into charts and use names from there in dplyr etc
Expand All @@ -66,7 +66,7 @@ patientProfileServer <- function(id, df, settings, subj_id) {
})

output$raw_change <- renderUI({

default_labs <- c(lab_settings$measure_values$CREAT, lab_settings$measure_values$CYSTC)
available_labs <- intersect(patient_df[[lab_settings$measure_col]] %>% unique(), default_labs)

Expand Down Expand Up @@ -118,7 +118,7 @@ patientProfileServer <- function(id, df, settings, subj_id) {
default_vitals <- c(vitals_settings$measure_values$DIABP,
vitals_settings$measure_values$SYSBP)

available_vitals <- intersect(patient_df[[vitals_settings$measure_col]] %>% unique(), default_labs)
available_vitals <- intersect(patient_df[[vitals_settings$measure_col]] %>% unique(), default_vitals)

if (length(available_vitals) > 0) {
drawBloodPressure(adlb = patient_df, settings = vitals_settings,
Expand All @@ -130,7 +130,8 @@ patientProfileServer <- function(id, df, settings, subj_id) {

output$normalized_albumin <- renderUI({

if (lab_settings$measure_values[["ALB/CREAT"]] %in% patient_df[[lab_settings$measure_col]] %>% unique()) {
if (length(lab_settings$measure_values[["ALB/CREAT"]] %in%
patient_df[[lab_settings$measure_col]] %>% unique()) > 0) {
drawNormalizedAlbumin(adlb = patient_df, settings = lab_settings)
} else {
div()
Expand Down

0 comments on commit c7e760b

Please sign in to comment.