Compare commits
2 Commits
eb89b01baa
...
5a6dba25ee
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a6dba25ee | |||
| 5dfe7328b6 |
56
app.R
56
app.R
@@ -55,7 +55,7 @@ ui <- page_sidebar(
|
|||||||
actionButton("clean_data_button", "Главная страница", icon("house", lib = "font-awesome")),
|
actionButton("clean_data_button", "Главная страница", icon("house", lib = "font-awesome")),
|
||||||
actionButton("load_data_button", "Загрузить данные", icon("pencil", lib = "font-awesome")),
|
actionButton("load_data_button", "Загрузить данные", icon("pencil", lib = "font-awesome")),
|
||||||
downloadButton("downloadDocx", "get .docx (test only)"),
|
downloadButton("downloadDocx", "get .docx (test only)"),
|
||||||
textOutput("status_message"),
|
uiOutput("status_message"),
|
||||||
textOutput("status_message2"),
|
textOutput("status_message2"),
|
||||||
uiOutput("display_log"),
|
uiOutput("display_log"),
|
||||||
position = "left",
|
position = "left",
|
||||||
@@ -282,7 +282,7 @@ server <- function(input, output, session) {
|
|||||||
exported_df <- exported_df |>
|
exported_df <- exported_df |>
|
||||||
mutate(
|
mutate(
|
||||||
!!dplyr::sym(mhcs()$get_main_key_id) := values$main_key,
|
!!dplyr::sym(mhcs()$get_main_key_id) := values$main_key,
|
||||||
!!dplyr::sym(nested_key_id) := values$nested_key,
|
!!dplyr::sym(nested_key_id) := values$nested_key,
|
||||||
.before = 1
|
.before = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ server <- function(input, output, session) {
|
|||||||
df = exported_df,
|
df = exported_df,
|
||||||
table_name = table_name,
|
table_name = table_name,
|
||||||
schm = mhcs(),
|
schm = mhcs(),
|
||||||
main_key_value = values$main_key,
|
main_key_value = values$main_key,
|
||||||
nested_key_value = values$nested_key,
|
nested_key_value = values$nested_key,
|
||||||
con = con
|
con = con
|
||||||
)
|
)
|
||||||
@@ -650,12 +650,16 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
# STATUSES ===============================
|
# STATUSES ===============================
|
||||||
# вывести отображение что что-то не так
|
# вывести отображение что что-то не так
|
||||||
output$status_message <- renderText({
|
output$status_message <- renderUI({
|
||||||
scheme()
|
|
||||||
shiny::validate(
|
shiny::validate(
|
||||||
need(values$main_key, "⚠️ Необходимо указать id пациента!")
|
need(values$main_key, "⚠️ Необходимо указать id пациента!")
|
||||||
)
|
)
|
||||||
paste0("ID: ", values$main_key)
|
span(
|
||||||
|
strong("Таблица: "), names(enabled_schemas)[enabled_schemas == scheme()],
|
||||||
|
br(),
|
||||||
|
strong("ID: "), values$main_key
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
output$status_message2 <- renderText({
|
output$status_message2 <- renderText({
|
||||||
@@ -806,8 +810,8 @@ server <- function(input, output, session) {
|
|||||||
ui_load_menu,
|
ui_load_menu,
|
||||||
title = "Загрузить имеющиеся данные",
|
title = "Загрузить имеющиеся данные",
|
||||||
footer = tagList(
|
footer = tagList(
|
||||||
actionButton("close_modal_button", "Отмена", class = "btn btn-danger"),
|
|
||||||
actionButton("load_data", "Загрузить данные"),
|
actionButton("load_data", "Загрузить данные"),
|
||||||
|
actionButton("close_modal_button", "Отмена", class = "btn-danger"),
|
||||||
),
|
),
|
||||||
easyClose = TRUE
|
easyClose = TRUE
|
||||||
)
|
)
|
||||||
@@ -1005,8 +1009,8 @@ server <- function(input, output, session) {
|
|||||||
),
|
),
|
||||||
checkboxInput("upload_data_from_xlsx_owerwrite_all_data", "перезаписать все данные", width = 450),
|
checkboxInput("upload_data_from_xlsx_owerwrite_all_data", "перезаписать все данные", width = 450),
|
||||||
footer = tagList(
|
footer = tagList(
|
||||||
modalButton("Отмена"),
|
actionButton("button_upload_data_from_xlsx_confirm", "Добавить"),
|
||||||
actionButton("button_upload_data_from_xlsx_confirm", "Добавить")
|
actionButton("close_modal_button", "Отмена", class = "btn-danger")
|
||||||
),
|
),
|
||||||
easyClose = FALSE
|
easyClose = FALSE
|
||||||
))
|
))
|
||||||
@@ -1034,19 +1038,17 @@ server <- function(input, output, session) {
|
|||||||
for (table_name in mhcs()$all_tables_names) {
|
for (table_name in mhcs()$all_tables_names) {
|
||||||
|
|
||||||
df <- openxlsx2::read_xlsx(wb, table_name)
|
df <- openxlsx2::read_xlsx(wb, table_name)
|
||||||
scheme <- mhcs()$get_schema(table_name) |>
|
scheme <- mhcs()$get_schema_with_values_forms(table_name)
|
||||||
filter(!form_type %in% c("description", "nested_forms"))
|
|
||||||
|
|
||||||
# столбцы в таблицы и схема
|
# столбцы в таблицы и схема
|
||||||
df_to_schema_compare <- setdiff(colnames(df), unique(scheme$form_id))
|
df_to_schema_compare <- setdiff(colnames(df), unique(scheme$form_id))
|
||||||
schema_to_df_compare <- setdiff(unique(scheme$form_id), colnames(df))
|
schema_to_df_compare <- setdiff(unique(scheme$form_id), colnames(df))
|
||||||
|
|
||||||
if (length(schema_to_df_compare) > 0 ) {
|
if (length(df_to_schema_compare) > 0 ) {
|
||||||
cli::cli_warn(c("в схеме для '{table_name}' нет следующих столбцов:", paste("- ", df_to_schema_compare)))
|
cli::cli_warn(c("в схеме для '{table_name}' нет следующих столбцов:", paste("- ", df_to_schema_compare)))
|
||||||
}
|
}
|
||||||
|
|
||||||
# схема и столбцы в таблице
|
# схема и столбцы в таблице
|
||||||
schema_to_df_compare <- setdiff(unique(scheme$form_id), colnames(df))
|
|
||||||
if (length(schema_to_df_compare) > 0 ) {
|
if (length(schema_to_df_compare) > 0 ) {
|
||||||
|
|
||||||
message <- glue::glue("столбцы в таблице '{table_name}' не соответсвуют схеме")
|
message <- glue::glue("столбцы в таблице '{table_name}' не соответсвуют схеме")
|
||||||
@@ -1061,8 +1063,7 @@ server <- function(input, output, session) {
|
|||||||
for (table_name in mhcs()$all_tables_names) {
|
for (table_name in mhcs()$all_tables_names) {
|
||||||
|
|
||||||
df <- openxlsx2::read_xlsx(wb, table_name)
|
df <- openxlsx2::read_xlsx(wb, table_name)
|
||||||
scheme <- mhcs()$get_schema(table_name) |>
|
scheme <- mhcs()$get_schema_with_values_forms(table_name)
|
||||||
filter(!form_type %in% c("description", "nested_forms"))
|
|
||||||
|
|
||||||
date_columns <- subset(scheme, form_type == "date", form_id, drop = TRUE)
|
date_columns <- subset(scheme, form_type == "date", form_id, drop = TRUE)
|
||||||
number_columns <- subset(scheme, form_type == "number", form_id, drop = TRUE)
|
number_columns <- subset(scheme, form_type == "number", form_id, drop = TRUE)
|
||||||
@@ -1091,17 +1092,24 @@ server <- function(input, output, session) {
|
|||||||
df_original <- DBI::dbReadTable(con, table_name) |>
|
df_original <- DBI::dbReadTable(con, table_name) |>
|
||||||
as_tibble()
|
as_tibble()
|
||||||
|
|
||||||
if (input$upload_data_from_xlsx_owerwrite_all_data == TRUE) cli::cli_abort("not implemented yet")
|
if (input$upload_data_from_xlsx_owerwrite_all_data == TRUE) {
|
||||||
|
|
||||||
walk(
|
DBI::dbRemoveTable(con, table_name)
|
||||||
.x = unique(df[[main_key_id]]),
|
|
||||||
.f = \(main_key) {
|
|
||||||
|
|
||||||
if (main_key %in% unique(df_original[[main_key_id]])) {
|
} else {
|
||||||
DBI::dbExecute(con, glue::glue("DELETE FROM {table_name} WHERE {main_key_id} = '{main_key}'"))
|
|
||||||
|
# удаление данных в базе данных по ключам
|
||||||
|
walk(
|
||||||
|
.x = unique(df[[main_key_id]]),
|
||||||
|
.f = \(main_key) {
|
||||||
|
|
||||||
|
if (main_key %in% unique(df_original[[main_key_id]])) {
|
||||||
|
DBI::dbExecute(con, glue::glue("DELETE FROM {table_name} WHERE {main_key_id} = '{main_key}'"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
|
}
|
||||||
|
|
||||||
DBI::dbWriteTable(
|
DBI::dbWriteTable(
|
||||||
con,
|
con,
|
||||||
@@ -1116,7 +1124,7 @@ server <- function(input, output, session) {
|
|||||||
type = "message"
|
type = "message"
|
||||||
)
|
)
|
||||||
cli::cli_alert_success(message)
|
cli::cli_alert_success(message)
|
||||||
}
|
}
|
||||||
log_action_to_db("importing data from xlsx", con = con)
|
log_action_to_db("importing data from xlsx", con = con)
|
||||||
removeModal()
|
removeModal()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ check_if_table_is_exist_and_init_if_not = function(
|
|||||||
|
|
||||||
if (table_name %in% DBI::dbListTables(con)) {
|
if (table_name %in% DBI::dbListTables(con)) {
|
||||||
|
|
||||||
cli::cli_inform(c("*" = "таблица есть такая: '{table_name}'"))
|
cli::cli_inform(c("*" = "проверка таблицы в базе данных: '{table_name}'"))
|
||||||
|
|
||||||
# если таблица существует, производим проверку структуры таблицы
|
# если таблица существует, производим проверку структуры таблицы
|
||||||
compare_existing_table_with_schema(
|
compare_existing_table_with_schema(
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ check_and_init_scheme = function() {
|
|||||||
|
|
||||||
cli::cli_inform(c("*" = "проверка схемы..."))
|
cli::cli_inform(c("*" = "проверка схемы..."))
|
||||||
|
|
||||||
|
files_to_watch <- c(
|
||||||
|
"modules/scheme_generator.R"
|
||||||
|
)
|
||||||
|
|
||||||
scheme_names <- enabled_schemas
|
scheme_names <- enabled_schemas
|
||||||
scheme_file <- paste0("configs/schemas/", scheme_names, ".xlsx")
|
scheme_file <- paste0("configs/schemas/", scheme_names, ".xlsx")
|
||||||
scheme_file <- stats::setNames(scheme_file, scheme_names)
|
scheme_file <- stats::setNames(scheme_file, scheme_names)
|
||||||
@@ -40,7 +44,7 @@ check_and_init_scheme = function() {
|
|||||||
hash_file <- "temp/schema_hash.rds"
|
hash_file <- "temp/schema_hash.rds"
|
||||||
|
|
||||||
#
|
#
|
||||||
exist_hash <- tools::md5sum(scheme_file)
|
exist_hash <- tools::md5sum(c(scheme_file, files_to_watch))
|
||||||
|
|
||||||
# если первый запуск (нет файла с кешем) инициализация схемы
|
# если первый запуск (нет файла с кешем) инициализация схемы
|
||||||
if (!file.exists(hash_file) | !file.exists("scheme.rds") | !all(file.exists(db_files))) {
|
if (!file.exists(hash_file) | !file.exists("scheme.rds") | !all(file.exists(db_files))) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ scheme_R6 <- R6::R6Class(
|
|||||||
private$main_key_id <- self$get_key_id("main")
|
private$main_key_id <- self$get_key_id("main")
|
||||||
|
|
||||||
box::use(modules/utils)
|
box::use(modules/utils)
|
||||||
private$testest <- bslib::navset_card_underline(
|
private$bslib_rendered_ui <- bslib::navset_card_underline(
|
||||||
id = "main",
|
id = "main",
|
||||||
!!!utils$make_list_of_pages(private$schemes_list[["main"]], private$main_key_id),
|
!!!utils$make_list_of_pages(private$schemes_list[["main"]], private$main_key_id),
|
||||||
header = NULL,
|
header = NULL,
|
||||||
@@ -47,7 +47,7 @@ scheme_R6 <- R6::R6Class(
|
|||||||
get_all_ids = function(table_name) {
|
get_all_ids = function(table_name) {
|
||||||
|
|
||||||
private$schemes_list[[table_name]] |>
|
private$schemes_list[[table_name]] |>
|
||||||
dplyr::filter(!form_type %in% private$exluded_types) |>
|
dplyr::filter(!form_type %in% private$excluded_types) |>
|
||||||
dplyr::distinct(form_id) |>
|
dplyr::distinct(form_id) |>
|
||||||
dplyr::pull(form_id)
|
dplyr::pull(form_id)
|
||||||
|
|
||||||
@@ -65,32 +65,24 @@ scheme_R6 <- R6::R6Class(
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
extract_forms_id_and_types_from_scheme2 = function(scheme) {
|
# возврат схемы ------------------------------------
|
||||||
|
## полностью -------
|
||||||
form_id_and_types_list <- scheme |>
|
|
||||||
dplyr::filter(!form_type %in% private$exluded_types) |>
|
|
||||||
dplyr::distinct(form_id, form_type) |>
|
|
||||||
tibble::deframe()
|
|
||||||
|
|
||||||
list(
|
|
||||||
key = form_id_and_types_list[1],
|
|
||||||
form = form_id_and_types_list[-1]
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
# get_key_id = function(table_name) {
|
|
||||||
# self$extract_forms_id_and_types_from_scheme2(private$schemes_list[[table_name]])
|
|
||||||
# },
|
|
||||||
get_schema = function(table_name) {
|
get_schema = function(table_name) {
|
||||||
private$schemes_list[[table_name]]
|
private$schemes_list[[table_name]]
|
||||||
},
|
},
|
||||||
|
## с полями имеющие значение -------
|
||||||
|
get_schema_with_values_forms = function(table_name) {
|
||||||
|
private$schemes_list[[table_name]] |>
|
||||||
|
dplyr::filter(!form_type %in% private$excluded_types)
|
||||||
|
},
|
||||||
|
|
||||||
get_id_type_list = function(table_name) {
|
get_id_type_list = function(table_name) {
|
||||||
|
|
||||||
# wo main key
|
# wo main key
|
||||||
this_key_id <- self$get_key_id(table_name)
|
this_key_id <- self$get_key_id(table_name)
|
||||||
|
|
||||||
private$schemes_list[[table_name]] |>
|
private$schemes_list[[table_name]] |>
|
||||||
dplyr::filter(!form_type %in% private$exluded_types) |>
|
dplyr::filter(!form_type %in% private$excluded_types) |>
|
||||||
dplyr::filter(form_id != {{this_key_id}}) |>
|
dplyr::filter(form_id != {{this_key_id}}) |>
|
||||||
dplyr::distinct(form_id, form_type) |>
|
dplyr::distinct(form_id, form_type) |>
|
||||||
tibble::deframe()
|
tibble::deframe()
|
||||||
@@ -107,7 +99,7 @@ scheme_R6 <- R6::R6Class(
|
|||||||
private$nested_forms_names
|
private$nested_forms_names
|
||||||
},
|
},
|
||||||
get_main_form_ui = function() {
|
get_main_form_ui = function() {
|
||||||
private$testest
|
private$bslib_rendered_ui
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
private = list(
|
private = list(
|
||||||
@@ -115,8 +107,8 @@ scheme_R6 <- R6::R6Class(
|
|||||||
schemes_list = NULL,
|
schemes_list = NULL,
|
||||||
main_key_id = NA,
|
main_key_id = NA,
|
||||||
nested_forms_names = NA,
|
nested_forms_names = NA,
|
||||||
testest = NA,
|
bslib_rendered_ui = NA,
|
||||||
exluded_types = c("inline_table", "nested_forms","description", "description_header"),
|
excluded_types = c("nested_forms", "description", "description_header"),
|
||||||
|
|
||||||
load_scheme_from_xlsx = function(sheet_name) {
|
load_scheme_from_xlsx = function(sheet_name) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#' @export
|
#' @export
|
||||||
make_list_of_pages = function(main_schema, main_key_id) {
|
make_list_of_pages = function(main_schema, main_key_id) {
|
||||||
cli::cli_alert_success("AAAA")
|
|
||||||
purrr::map(
|
purrr::map(
|
||||||
.x = unique(main_schema$part),
|
.x = unique(main_schema$part),
|
||||||
.f = \(page_name) {
|
.f = \(page_name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user