Browse Source

Count the instance_num when pushing observations

master
Maxime Wack 6 years ago
parent
commit
3962c7add4
1 changed files with 5 additions and 21 deletions
  1. +5
    -21
      R/demodata.R

+ 5
- 21
R/demodata.R View File

@@ -262,16 +262,6 @@ add_patients_demodata <- function(patients, project, host = "", admin = "", pass
{
demodata <- RPostgreSQL::dbConnect(RPostgreSQL::PostgreSQL(), host = host, dbname = stringr::str_c("i2b2", stringr::str_to_lower(project), "data"), user = admin, password = pass)

# Upsert patients mappings
# patients %>%
# dplyr::mutate(patient_ide_source = "HIVE",
# patient_ide_status = "A",
# project_id = project,
# patient_num = patient_ide,
# update_date = format(Sys.Date(), "%m/%d/%Y")) %>%
# dplyr::select(patient_ide, patient_ide_source, patient_num, patient_ide_status, project_id, update_date) %>%
# dbUpsert(demodata, "patient_mapping", c("patient_ide", "patient_ide_source", "project_id"))

# Upsert patients mappings
patients %>%
dplyr::mutate(patient_ide_source = project,
@@ -319,7 +309,6 @@ add_encounters <- function(encounters, project, host = "", admin = "", pass = ""

demodata %>%
dplyr::tbl("encounter_mapping") %>%
# dplyr::filter(encounter_ide_source == "HIVE") %>%
dplyr::select(encounter_ide, encounter_num) %>%
dplyr::collect() ->
mapping
@@ -336,15 +325,6 @@ add_encounters <- function(encounters, project, host = "", admin = "", pass = ""
dplyr::anti_join(mapping) %>%
dplyr::mutate(encounter_num = seq(start, length.out = nrow(.))) -> unmapped

# unmapped %>%
# dplyr::mutate(encounter_ide_source = "HIVE",
# encounter_ide_status = "A",
# project_id = project,
# patient_ide_source = "HIVE",
# update_date = format(Sys.Date(), "%m/%d/%Y")) %>%
# dplyr::select(encounter_ide, encounter_ide_source, project_id, encounter_num, patient_ide, patient_ide_source, encounter_ide_status, update_date) %>%
# dbUpsert(demodata, "encounter_mapping", c("encounter_ide", "encounter_ide_source", "project_id", "patient_ide", "patient_ide_source"))

unmapped %>%
dplyr::mutate(encounter_ide_source = project,
encounter_ide_status = "A",
@@ -395,9 +375,9 @@ add_observations <- function(observations, project, host = "", admin = "", pass
{
demodata <- RPostgreSQL::dbConnect(RPostgreSQL::PostgreSQL(), host = host, dbname = stringr::str_c("i2b2", stringr::str_to_lower(project), "data"), user = admin, password = pass)

# Get the encounter mapping
demodata %>%
dplyr::tbl("encounter_mapping") %>%
# dplyr::filter(encounter_ide_source == "HIVE") %>%
dplyr::select(encounter_ide, encounter_num) %>%
dplyr::collect() ->
mapping
@@ -405,6 +385,7 @@ add_observations <- function(observations, project, host = "", admin = "", pass
observations %>%
dplyr::inner_join(mapping) -> observations

# create the text_search_index column
RPostgreSQL::dbGetQuery(demodata, "SELECT max(text_search_index) from observation_fact;") %>%
.$max -> nextval

@@ -419,6 +400,9 @@ add_observations <- function(observations, project, host = "", admin = "", pass
patient_num = patient_ide,
update_date = format(Sys.Date(), "%m/%d/%Y"),
text_search_index = seq(nextval+1, length.out = nrow(.))) %>%
dplyr::group_by(patient_ide, encounter_ide, start_date, provider_id, concept_cd, modifier_cd) %>%
dplyr::mutate(instance_num = seq(1, length.out = n())) %>%
dplyr::ungroup() %>%
dplyr::select(-patient_ide, -encounter_ide) %>%
dbUpsert(demodata, "observation_fact", c("patient_num", "concept_cd", "modifier_cd", "start_date", "encounter_num", "instance_num", "provider_id"))



Loading…
Cancel
Save