diff --git a/docs/aki.Rmd b/docs/aki.Rmd index ff06b25..63df265 100644 --- a/docs/aki.Rmd +++ b/docs/aki.Rmd @@ -11,7 +11,7 @@ vignette: > library(knitr) options(scipen = 5e5) knitr::opts_chunk$set(collapse = TRUE, comment = "#>") -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) # contains cred$pg +library(credx) # contains cred$pg library(wrap) ``` ```{r setup, message = FALSE} @@ -20,7 +20,7 @@ library(dplyr) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/aki.html b/docs/aki.html index 829c5d1..6842235 100644 --- a/docs/aki.html +++ b/docs/aki.html @@ -2278,7 +2278,7 @@

Kidney injury lab presentation

# Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). @@ -2471,11 +2471,68 @@

Calculate the phenotype

FALSE +2 +1 +2016-03-11 +00:00:00 +1.3 +1.3 +1.3 +120.9 +NA +2016-03-11 +2016-03-11 +2016-03-11 +2016-03-11 +NA +FALSE +FALSE +FALSE + + +3 +1 +2018-03-16 +00:00:00 +1.3 +1.3 +1.3 +151.7 +NA +2018-03-16 +2018-03-16 +2018-03-16 +2018-03-16 +NA +FALSE +FALSE +FALSE + + +12 +1 +2020-03-20 +00:00:00 +1.3 +1.3 +1.3 +107.3 +NA +2020-03-20 +2020-03-20 +2020-03-20 +2020-03-20 +NA +FALSE +FALSE +FALSE + + 5 1 2022-02-11 00:00:00 -1.8 +1.5 1.5 1.5 84.8 @@ -2485,11 +2542,11 @@

Calculate the phenotype

2022-02-11 2022-02-11 NA -TRUE +FALSE FALSE FALSE - + 16 1 2022-03-25 @@ -2497,7 +2554,7 @@

Calculate the phenotype

1.5 1.5 1.5 -84.1 +105.7 NA 2022-03-25 2022-02-11 @@ -2508,7 +2565,7 @@

Calculate the phenotype

FALSE FALSE - + 17 3 2004-11-26 @@ -2527,211 +2584,154 @@

Calculate the phenotype

FALSE FALSE - -60 + +47 3 -2016-01-29 -490 days -2.6 -2.1 -2.1 -65.5 -124.1 -2016-01-29 -2016-01-29 -2016-01-29 -2016-01-29 -2014-09-26 -TRUE +2005-12-02 +00:00:00 +1.5 +1.5 +1.5 +114.0 +NA +2005-12-02 +2005-12-02 +2005-12-02 +2005-12-02 +NA FALSE FALSE - - -33 -3 -2016-11-11 -777 days -3.7 -2.0 -2.0 -64.5 -124.1 -2016-11-11 -2016-11-11 -2016-11-11 -2016-11-11 -2014-09-26 -TRUE -TRUE FALSE -63 +19 3 -2017-02-03 -861 days -3.5 -3.5 -2.0 -37.0 -124.1 -2017-02-03 -2017-02-03 -2016-11-11 -2017-02-03 -2014-09-26 +2006-12-08 +00:00:00 +1.5 +1.5 +1.5 +111.9 +NA +2006-12-08 +2006-12-08 +2006-12-08 +2006-12-08 +NA +FALSE FALSE -TRUE FALSE -64 +49 3 -2017-02-17 -98 days -2.3 -2.3 -2.0 -57.4 -34.3 -2017-02-17 -2017-02-03 -2016-11-11 -2017-02-17 -2016-11-11 +2007-12-14 +00:00:00 +1.4 +1.4 +1.4 +131.9 +NA +2007-12-14 +2007-12-14 +2007-12-14 +2007-12-14 +NA FALSE FALSE -TRUE - - -69 -3 -2019-02-15 -133 days -3.9 -3.9 -2.6 -33.0 -49.3 -2019-02-15 -2019-02-15 -2018-10-05 -2019-02-15 -2018-10-05 FALSE -TRUE -TRUE - -70 + +50 3 -2020-02-21 -504 days -2.5 -2.5 -2.5 -50.6 -49.3 -2020-02-21 -2020-02-21 -2020-02-21 -2020-02-21 -2018-10-05 +2008-12-19 +00:00:00 +1.3 +1.3 +1.3 +147.5 +NA +2008-12-19 +2008-12-19 +2008-12-19 +2008-12-19 +NA FALSE FALSE -TRUE - - -74 -3 -2022-05-20 -210 days -4.0 -4.0 -2.2 -31.1 -33.6 -2022-05-20 -2022-05-20 -2021-10-22 -2022-05-20 -2021-10-22 FALSE -TRUE -TRUE -75 -6 -2022-07-06 +22 +3 +2009-12-25 00:00:00 -1.1 -1.1 -1.1 -NA +1.3 +1.3 +1.3 +149.6 NA -2022-07-06 -2022-07-06 -2022-07-06 -NA +2009-12-25 +2009-12-25 +2009-12-25 +2009-12-25 NA FALSE FALSE -NA +FALSE -76 -14 -2021-02-08 +23 +3 +2010-12-31 00:00:00 -2.7 -2.7 -2.7 -78.8 +1.3 +1.3 +1.3 +132.3 NA -2021-02-08 -2021-02-08 -2021-02-08 -2021-02-08 +2010-12-31 +2010-12-31 +2010-12-31 +2010-12-31 NA FALSE FALSE FALSE -80 -18 -2003-05-04 -00:00:00 -0.9 -0.9 -0.9 -NA -NA -2003-05-04 -2003-05-04 -2003-05-04 -NA -NA +24 +3 +2011-04-15 +105 days +1.4 +1.4 +1.3 +142.0 +132.3 +2011-04-15 +2011-04-15 +2010-12-31 +2011-04-15 +2010-12-31 +FALSE FALSE FALSE -NA -100 -19 -2003-08-03 -00:00:00 -1.4 -1.4 -1.4 -133.9 -NA -2003-08-03 -2003-08-03 -2003-08-03 -2003-08-03 -NA +54 +3 +2012-01-06 +371 days +1.5 +1.5 +1.5 +91.6 +132.3 +2012-01-06 +2012-01-06 +2012-01-06 +2012-01-06 +2010-12-31 FALSE FALSE FALSE @@ -2761,17 +2761,17 @@

Plot the phenotype for a random patient

random_patient <- sample(patients, 1) message('Sampled patient: ', random_patient) -#> Sampled patient: 1010 +#> Sampled patient: 19

Then we plot all data for the chosen patient (pid = -1010).

+19).

scr_change |>
   select(-ends_with('datetime')) |>
   mutate(
     scr_case_a_or_b = scr_case_a | scr_case_b) |>
   phea_plot(random_patient)
 #> Collecting lazy table, done. (turn this message off with `verbose = FALSE`)
-
- +
+

At the end of this report I include a large table with all the data for this patient, directly from the record sources, for maximum verification.

@@ -2797,171 +2797,134 @@

Obtain the SQL query that computes the phenotype

"scr_7d_min_measurement_datetime", "gfr_measurement_datetime", "gfr_prior_measurement_datetime", - "scr_case_a", - "scr_case_b", - "gfr_case_c" + scr_value_as_number - scr_48h_min_value_as_number >= 0.3 AS "scr_case_a", + scr_value_as_number / scr_7d_min_value_as_number >= 1.5 AS "scr_case_b", + gfr_value_as_number < 60 AND gfr_prior_value_as_number < 60 AS "gfr_case_c" FROM ( SELECT *, - lag(phea_kco_var1) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag1", - lag(phea_kco_var2) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag2", - lag(phea_kco_var3) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag3", - lag(phea_kco_var4) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag4" - FROM ( - SELECT - *, - pid AS "phea_kco_var1", - scr_case_a AS "phea_kco_var2", - scr_case_b AS "phea_kco_var3", - gfr_case_c AS "phea_kco_var4" - FROM ( - SELECT - "row_id", - "pid", - "ts", - "window", - "scr_value_as_number", - "scr_48h_min_value_as_number", - "scr_7d_min_value_as_number", - "gfr_value_as_number", - "gfr_prior_value_as_number", - "scr_measurement_datetime", - "scr_48h_min_measurement_datetime", - "scr_7d_min_measurement_datetime", - "gfr_measurement_datetime", - "gfr_prior_measurement_datetime", - scr_value_as_number - scr_48h_min_value_as_number >= 0.3 AS "scr_case_a", - scr_value_as_number / scr_7d_min_value_as_number >= 1.5 AS "scr_case_b", - gfr_value_as_number < 60 AND gfr_prior_value_as_number < 60 AS "gfr_case_c" - FROM ( - SELECT - *, - greatest(scr_ts, scr_48h_min_ts, scr_7d_min_ts, gfr_ts, gfr_prior_ts) - least(scr_ts, scr_48h_min_ts, scr_7d_min_ts, gfr_ts, gfr_prior_ts) AS "window", - last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row" - FROM ( - SELECT - "row_id", - "pid", - "ts", - MAX("scr_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "scr_measurement_datetime", - MAX("scr_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "scr_value_as_number", - MAX("scr_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "scr_ts", - MAX("scr_48h_min_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "scr_48h_min_measurement_datetime", - MAX("scr_48h_min_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_5") AS "scr_48h_min_value_as_number", - MAX("scr_48h_min_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_6") AS "scr_48h_min_ts", - MAX("scr_7d_min_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_7") AS "scr_7d_min_measurement_datetime", - MAX("scr_7d_min_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_8") AS "scr_7d_min_value_as_number", - MAX("scr_7d_min_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_9") AS "scr_7d_min_ts", - MAX("gfr_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_10") AS "gfr_measurement_datetime", - MAX("gfr_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_11") AS "gfr_value_as_number", - MAX("gfr_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_12") AS "gfr_ts", - MAX("gfr_prior_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_13") AS "gfr_prior_measurement_datetime", - MAX("gfr_prior_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_14") AS "gfr_prior_value_as_number", - MAX("gfr_prior_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_15") AS "gfr_prior_ts" - FROM ( - SELECT - *, - SUM(CASE WHEN (("scr_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1", - SUM(CASE WHEN (("scr_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2", - SUM(CASE WHEN (("scr_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3", - SUM(CASE WHEN (("scr_48h_min_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4", - SUM(CASE WHEN (("scr_48h_min_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_5", - SUM(CASE WHEN (("scr_48h_min_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_6", - SUM(CASE WHEN (("scr_7d_min_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_7", - SUM(CASE WHEN (("scr_7d_min_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_8", - SUM(CASE WHEN (("scr_7d_min_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_9", - SUM(CASE WHEN (("gfr_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_10", - SUM(CASE WHEN (("gfr_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_11", - SUM(CASE WHEN (("gfr_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_12", - SUM(CASE WHEN (("gfr_prior_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_13", - SUM(CASE WHEN (("gfr_prior_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_14", - SUM(CASE WHEN (("gfr_prior_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_15" - FROM ( - SELECT - row_number() over () AS "row_id", - "pid", - "ts", - last_value(case when "name" = 'f4enaijqlv6k' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_measurement_datetime", - last_value(case when "name" = 'f4enaijqlv6k' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_value_as_number", - last_value(case when "name" = 'f4enaijqlv6k' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_ts", - min(case when "name" = 'f4enaijqlv6k' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_measurement_datetime", - min(case when "name" = 'f4enaijqlv6k' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_value_as_number", - last_value(case when "name" = 'f4enaijqlv6k' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_ts", - min(case when "name" = 'f4enaijqlv6k' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_measurement_datetime", - min(case when "name" = 'f4enaijqlv6k' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_value_as_number", - last_value(case when "name" = 'f4enaijqlv6k' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_ts", - last_value(case when "name" = 'ydcetbw9y26i' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_measurement_datetime", - last_value(case when "name" = 'ydcetbw9y26i' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_value_as_number", - last_value(case when "name" = 'ydcetbw9y26i' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_ts", - min(case when "name" = 'ydcetbw9y26i' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_measurement_datetime", - min(case when "name" = 'ydcetbw9y26i' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_value_as_number", - last_value(case when "name" = 'ydcetbw9y26i' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_ts" - FROM ( - ( - SELECT - 'f4enaijqlv6k' AS "name", - "person_id" AS "pid", - "measurement_datetime" AS "ts", - "measurement_datetime", - "value_as_number" - FROM ( - ( - SELECT * - FROM "cdm_new_york3"."measurement" - WHERE ("measurement_concept_id" IN (3051825.0, 3016723.0) AND "unit_source_value" = 'mg/dL') - ) - UNION ALL - ( - SELECT - "measurement_id", - "person_id", - "measurement_concept_id", - "measurement_date", - "measurement_datetime", - "measurement_time", - "measurement_type_concept_id", - "operator_concept_id", - "value_as_number" / 88.42 AS "value_as_number", - "value_as_concept_id", - "unit_concept_id", - "range_low", - "range_high", - "provider_id", - "visit_occurrence_id", - "visit_detail_id", - "measurement_source_value", - "measurement_source_concept_id", - 'mg/dL' AS "unit_source_value", - "unit_source_concept_id", - "value_source_value", - "measurement_event_id", - "meas_event_field_concept_id" - FROM "cdm_new_york3"."measurement" - WHERE ("measurement_concept_id" IN (3051825.0, 3016723.0) AND "unit_source_value" = 'µmol/L') - ) - ) "q01" - ) - UNION ALL - ( - SELECT - 'ydcetbw9y26i' AS "name", - "person_id" AS "pid", - "measurement_datetime" AS "ts", - "measurement_datetime", - "value_as_number" - FROM "cdm_new_york3"."measurement" - WHERE ("measurement_concept_id" = 46236952.0) - ) - ) "q02" - ) "q03" - ) "q04" - ) "q05" - ) "q06" - WHERE ("row_id" = "phea_ts_row") - ) "q07" - ) "q08" -) "q09" -WHERE ((("phea_kco_lag1" IS NULL) AND NOT(("phea_kco_var1" IS NULL))) OR "phea_kco_lag1" != "phea_kco_var1" OR (("phea_kco_lag2" IS NULL) AND NOT(("phea_kco_var2" IS NULL))) OR "phea_kco_lag2" != "phea_kco_var2" OR (("phea_kco_lag3" IS NULL) AND NOT(("phea_kco_var3" IS NULL))) OR "phea_kco_lag3" != "phea_kco_var3" OR (("phea_kco_lag4" IS NULL) AND NOT(("phea_kco_var4" IS NULL))) OR "phea_kco_lag4" != "phea_kco_var4") + greatest(scr_ts, scr_48h_min_ts, scr_7d_min_ts, gfr_ts, gfr_prior_ts) - least(scr_ts, scr_48h_min_ts, scr_7d_min_ts, gfr_ts, gfr_prior_ts) AS "window", + last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row" + FROM ( + SELECT + "row_id", + "pid", + "ts", + MAX("scr_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "scr_measurement_datetime", + MAX("scr_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "scr_value_as_number", + MAX("scr_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "scr_ts", + MAX("scr_48h_min_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "scr_48h_min_measurement_datetime", + MAX("scr_48h_min_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_5") AS "scr_48h_min_value_as_number", + MAX("scr_48h_min_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_6") AS "scr_48h_min_ts", + MAX("scr_7d_min_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_7") AS "scr_7d_min_measurement_datetime", + MAX("scr_7d_min_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_8") AS "scr_7d_min_value_as_number", + MAX("scr_7d_min_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_9") AS "scr_7d_min_ts", + MAX("gfr_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_10") AS "gfr_measurement_datetime", + MAX("gfr_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_11") AS "gfr_value_as_number", + MAX("gfr_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_12") AS "gfr_ts", + MAX("gfr_prior_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_13") AS "gfr_prior_measurement_datetime", + MAX("gfr_prior_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_14") AS "gfr_prior_value_as_number", + MAX("gfr_prior_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_15") AS "gfr_prior_ts" + FROM ( + SELECT + *, + SUM(CASE WHEN (("scr_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1", + SUM(CASE WHEN (("scr_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2", + SUM(CASE WHEN (("scr_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3", + SUM(CASE WHEN (("scr_48h_min_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4", + SUM(CASE WHEN (("scr_48h_min_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_5", + SUM(CASE WHEN (("scr_48h_min_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_6", + SUM(CASE WHEN (("scr_7d_min_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_7", + SUM(CASE WHEN (("scr_7d_min_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_8", + SUM(CASE WHEN (("scr_7d_min_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_9", + SUM(CASE WHEN (("gfr_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_10", + SUM(CASE WHEN (("gfr_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_11", + SUM(CASE WHEN (("gfr_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_12", + SUM(CASE WHEN (("gfr_prior_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_13", + SUM(CASE WHEN (("gfr_prior_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_14", + SUM(CASE WHEN (("gfr_prior_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_15" + FROM ( + SELECT + row_number() over () AS "row_id", + "pid", + "ts", + last_value(case when "name" = 'xl450dcw' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_measurement_datetime", + last_value(case when "name" = 'xl450dcw' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_value_as_number", + last_value(case when "name" = 'xl450dcw' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "scr_ts", + min(case when "name" = 'xl450dcw' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_measurement_datetime", + min(case when "name" = 'xl450dcw' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_value_as_number", + last_value(case when "name" = 'xl450dcw' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '48 days'::interval preceding and current row) AS "scr_48h_min_ts", + min(case when "name" = 'xl450dcw' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_measurement_datetime", + min(case when "name" = 'xl450dcw' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_value_as_number", + last_value(case when "name" = 'xl450dcw' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '7 months'::interval preceding and current row) AS "scr_7d_min_ts", + last_value(case when "name" = 'jfawg3sk' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_measurement_datetime", + last_value(case when "name" = 'jfawg3sk' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_value_as_number", + last_value(case when "name" = 'jfawg3sk' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "gfr_ts", + min(case when "name" = 'jfawg3sk' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_measurement_datetime", + min(case when "name" = 'jfawg3sk' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_value_as_number", + last_value(case when "name" = 'jfawg3sk' then "ts" else null end) over (partition by "pid", "name" order by "ts" range between '5 months'::interval preceding and '3 months days'::interval preceding) AS "gfr_prior_ts" + FROM ( + ( + SELECT + 'xl450dcw' AS "name", + "person_id" AS "pid", + "measurement_datetime" AS "ts", + "measurement_datetime", + "value_as_number" + FROM ( + ( + SELECT * + FROM "cdm_new_york3"."measurement" + WHERE ("measurement_concept_id" IN (3051825.0, 3016723.0) AND "unit_source_value" = 'mg/dL') + ) + UNION ALL + ( + SELECT + "measurement_id", + "person_id", + "measurement_concept_id", + "measurement_date", + "measurement_datetime", + "measurement_time", + "measurement_type_concept_id", + "operator_concept_id", + "value_as_number" / 88.42 AS "value_as_number", + "value_as_concept_id", + "unit_concept_id", + "range_low", + "range_high", + "provider_id", + "visit_occurrence_id", + "visit_detail_id", + "measurement_source_value", + "measurement_source_concept_id", + 'mg/dL' AS "unit_source_value", + "unit_source_concept_id", + "value_source_value", + "measurement_event_id", + "meas_event_field_concept_id" + FROM "cdm_new_york3"."measurement" + WHERE ("measurement_concept_id" IN (3051825.0, 3016723.0) AND "unit_source_value" = 'µmol/L') + ) + ) "q01" + ) + UNION ALL + ( + SELECT + 'jfawg3sk' AS "name", + "person_id" AS "pid", + "measurement_datetime" AS "ts", + "measurement_datetime", + "value_as_number" + FROM "cdm_new_york3"."measurement" + WHERE ("measurement_concept_id" = 46236952.0) + ) + ) "q02" + ) "q03" + ) "q04" + ) "q05" +) "q06" +WHERE ("row_id" = "phea_ts_row")

See the raw data that went into @@ -2996,717 +2959,395 @@

Serum creatinine records

-412430 -1010 -1975-05-23 -1.0 +6543 +19 +2003-08-03 +1.4 mg/dL -414817 -1010 -1976-04-01 -3.1 +6065 +19 +2004-08-08 +1.6 mg/dL -413259 -1010 -1976-05-28 -1.1 +6080 +19 +2004-08-08 +1.5 mg/dL -413703 -1010 -1977-04-01 -2.9 +5933 +19 +2005-08-14 +1.6 mg/dL -412468 -1010 -1977-06-03 -0.9 +5937 +19 +2005-08-14 +1.7 mg/dL -414266 -1010 -1978-04-01 -3.0 +6708 +19 +2005-11-27 +2.6 mg/dL -412982 -1010 -1978-05-19 -1.1 +6158 +19 +2006-08-20 +3.9 mg/dL -412995 -1010 -1978-05-19 -1.4 +6140 +19 +2006-09-24 +3.2 mg/dL -414044 -1010 -1978-06-09 -1.3 +5465 +19 +2007-08-26 +2.8 mg/dL -414058 -1010 -1978-06-09 -1.6 +6260 +19 +2007-10-14 +4.4 mg/dL -414445 -1010 -1978-06-23 -1.3 +6004 +19 +2007-11-18 +4.3 mg/dL -413888 -1010 -1978-07-14 -1.4 +5367 +19 +2008-04-13 +2.9 mg/dL -412766 -1010 -1978-08-25 -1.1 +5612 +19 +2008-08-31 +3.8 mg/dL -412405 -1010 -1979-04-01 -3.2 +6223 +19 +2009-02-08 +4.1 mg/dL -414188 -1010 -1979-06-15 -1.0 +5414 +19 +2009-09-06 +2.8 mg/dL -413420 -1010 -1979-10-12 -1.2 +6757 +19 +2009-11-01 +2.8 mg/dL -413814 -1010 -1980-03-31 -3.2 +6473 +19 +2010-05-02 +2.7 mg/dL -413608 -1010 -1980-06-20 -1.2 +5695 +19 +2010-09-12 +3.6 mg/dL -413974 -1010 -1980-10-31 -1.2 +6623 +19 +2011-09-18 +3.5 mg/dL -412874 -1010 -1981-03-06 -1.4 +6288 +19 +2011-12-25 +2.9 mg/dL -414611 -1010 -1981-03-31 -3.1 +6438 +19 +2012-02-19 +3.4 mg/dL -413530 -1010 -1981-05-01 -1.2 +5754 +19 +2012-09-23 +2.4 mg/dL -413037 -1010 -1981-06-26 -1.4 +6672 +19 +2013-01-20 +3.3 mg/dL -414777 -1010 -1981-07-10 -1.0 +5717 +19 +2013-09-29 +3.2 mg/dL -413293 -1010 -1981-10-30 -1.1 +6371 +19 +2014-08-10 +2.9 mg/dL -412331 -1010 -1982-03-31 -2.9 +6385 +19 +2014-08-10 +2.2 mg/dL -414703 -1010 -1982-05-28 -1.2 +5517 +19 +2014-10-05 +2.3 mg/dL -414861 -1010 -1982-07-02 -1.1 +6686 +19 +2014-11-02 +2.4 mg/dL -412678 -1010 -1982-10-22 -1.2 +5657 +19 +2015-08-31 +3.5 mg/dL -414399 -1010 -1983-03-31 -3.0 +6108 +19 +2015-10-11 +3.4 mg/dL -413942 -1010 -1983-07-08 -1.2 +5791 +19 +2016-02-28 +3.4 mg/dL -413993 -1010 -1984-01-20 -1.3 +5546 +19 +2016-08-30 +2.9 mg/dL -412651 -1010 -1984-03-30 -3.4 +5982 +19 +2016-10-16 +2.2 mg/dL -413009 -1010 -1984-05-18 -1.0 +5879 +19 +2016-11-27 +3.8 mg/dL -414382 -1010 -1984-07-13 -1.1 +6213 +19 +2016-12-25 +3.3 mg/dL -414729 -1010 -1984-10-12 -1.0 +5644 +19 +2017-08-30 +2.9 mg/dL -412487 -1010 -1985-01-11 -1.1 +6517 +19 +2017-10-22 +2.2 mg/dL -412591 -1010 -1985-03-30 -2.8 +6490 +19 +2018-08-30 +3.1 mg/dL -414652 -1010 -1985-07-12 -1.0 +5915 +19 +2018-10-28 +2.9 mg/dL -414488 -1010 -1985-07-26 -1.1 +5853 +19 +2018-11-18 +2.5 mg/dL -412304 -1010 -1986-03-30 -2.8 +6575 +19 +2018-12-16 +3.3 mg/dL -412660 -1010 -1986-08-01 -1.2 +6113 +19 +2019-08-30 +2.6 mg/dL -413298 -1010 -1987-03-30 -2.7 +6618 +19 +2019-09-22 +2.4 mg/dL -412536 -1010 -1987-07-03 -1.0 +5623 +19 +2019-11-03 +3.4 mg/dL -414505 -1010 -1987-08-07 -1.3 -mg/dL - - -413369 -1010 -1988-01-29 -1.4 -mg/dL - - -414023 -1010 -1988-03-29 -3.4 -mg/dL - - -414128 -1010 -1988-08-12 -1.2 -mg/dL - - -414663 -1010 -1988-12-23 -1.8 -mg/dL - - -414546 -1010 -1989-02-17 -1.5 -mg/dL - - -413578 -1010 -1989-03-29 -3.3 -mg/dL - - -413772 -1010 -1989-04-21 -2.5 -mg/dL - - -413392 -1010 -1989-07-28 -2.0 -mg/dL - - -413443 -1010 -1989-08-18 -2.2 -mg/dL - - -412396 -1010 -1989-09-15 -1.8 -mg/dL - - -414835 -1010 -1989-10-20 -1.5 -mg/dL - - -412859 -1010 -1990-01-19 -1.9 -mg/dL - - -414097 -1010 -1990-03-29 -3.3 -mg/dL - - -412572 -1010 -1990-04-13 -1.4 -mg/dL - - -412913 -1010 -1990-07-13 -2.0 -mg/dL - - -413837 -1010 -1990-08-10 -2.0 -mg/dL - - -413145 -1010 -1990-08-24 -1.8 -mg/dL - - -414421 -1010 -1990-10-12 -2.0 -mg/dL - - -414321 -1010 -1991-01-11 -1.7 -mg/dL - - -412337 -1010 -1991-02-15 -1.4 -mg/dL - - -413475 -1010 -1991-03-29 +6022 +19 +2020-07-12 3.0 mg/dL - -413661 -1010 -1991-03-29 -2.3 -mg/dL - - -412380 -1010 -1991-04-19 -1.9 -mg/dL - - -414562 -1010 -1991-05-17 -2.1 -mg/dL - -412627 -1010 -1991-06-07 -1.5 -mg/dL - - -413542 -1010 -1991-08-30 -2.1 -mg/dL - - -413128 -1010 -1991-10-11 -1.5 -mg/dL - - -412718 -1010 -1991-12-06 -1.3 -mg/dL - - -412549 -1010 -1992-03-13 -1.5 -mg/dL - - -414718 -1010 -1992-03-28 -2.6 -mg/dL - - -412733 -1010 -1992-04-10 -2.0 -mg/dL - - -413177 -1010 -1992-09-04 -1.3 -mg/dL - - -414580 -1010 -1992-09-18 -1.4 -mg/dL - - -414019 -1010 -1992-10-02 -1.3 -mg/dL - - -413325 -1010 -1992-11-27 -2.1 -mg/dL - - -413365 -1010 -1993-01-29 -1.7 -mg/dL - - -413197 -1010 -1993-03-28 -3.1 -mg/dL - - -413203 -1010 -1993-04-02 -1.9 -mg/dL - - -413634 -1010 -1993-04-30 -2.1 -mg/dL - - -413693 -1010 -1993-07-04 -2.2 -mg/dL - - -413782 -1010 -1993-07-23 -1.6 -mg/dL - - -412786 -1010 -1993-08-27 -1.4 -mg/dL - - -414241 -1010 -1993-09-10 -1.2 +5529 +19 +2020-08-29 +2.7 mg/dL -412606 -1010 -1993-09-24 -1.7 +6733 +19 +2020-10-04 +2.9 mg/dL -414876 -1010 -1993-11-26 -1.3 +6305 +19 +2020-11-08 +2.9 mg/dL -414757 -1010 -1993-12-31 -1.4 +5488 +19 +2020-11-22 +3.5 mg/dL -414217 -1010 -1994-01-19 -1.3 +5401 +19 +2021-07-04 +3.5 mg/dL -414350 -1010 -1994-01-19 -1.3 +6414 +19 +2021-08-01 +2.8 mg/dL -413917 -1010 -1994-03-04 -1.2 +5567 +19 +2021-08-29 +2.9 mg/dL -413240 -1010 -1994-03-28 +6182 +19 +2021-10-03 2.7 mg/dL -413505 -1010 -1994-06-03 -2.0 -mg/dL - - -413742 -1010 -1994-07-19 -1.6 -mg/dL - - -414149 -1010 -1994-07-19 -1.6 -mg/dL - - -414525 -1010 -1994-09-16 -1.4 -mg/dL - - -412899 -1010 -1994-10-07 -1.7 +6775 +19 +2021-11-14 +3.5 mg/dL -412811 -1010 -1995-01-16 -1.9 +5774 +19 +2022-08-29 +3.3 mg/dL -413805 -1010 -1995-03-28 -2.6 +6515 +19 +2022-10-30 +2.5 mg/dL @@ -3739,705 +3380,397 @@

Glomerular filtration rate records

-412459 -1010 -1975-05-23 -120.2 -mL/min/{1.73_m2} - - -414811 -1010 -1976-04-01 -72.9 -mL/min - - -413273 -1010 -1976-05-28 -83.7 +6552 +19 +2003-08-03 +133.9 mL/min/{1.73_m2} -413706 -1010 -1977-04-01 -67.1 -mL/min - - -412473 -1010 -1977-06-03 -106.8 +6076 +19 +2004-08-08 +83.5 mL/min/{1.73_m2} - -414273 -1010 -1978-04-01 -84.6 -mL/min - -412966 -1010 -1978-05-19 -124.3 +6086 +19 +2004-08-08 +141.2 mL/min -412993 -1010 -1978-05-19 -80.5 +5922 +19 +2005-08-14 +82.8 mL/min/{1.73_m2} -414074 -1010 -1978-06-09 -100.4 +5966 +19 +2005-08-14 +91.2 mL/min -414080 -1010 -1978-06-09 -70.1 +6719 +19 +2005-11-27 +52.4 mL/min/{1.73_m2} -414434 -1010 -1978-06-23 -68.3 +6156 +19 +2006-08-20 +34.1 mL/min/{1.73_m2} -413904 -1010 -1978-07-14 -63.8 -mL/min/{1.73_m2} - - -412778 -1010 -1978-08-25 -80.4 +6146 +19 +2006-09-24 +41.6 mL/min/{1.73_m2} - -412419 -1010 -1979-04-01 -83.3 -mL/min - -414178 -1010 -1979-06-15 -89.2 -mL/min/{1.73_m2} - - -413455 -1010 -1979-10-12 -74.8 +5453 +19 +2007-08-26 +47.8 mL/min/{1.73_m2} - -413820 -1010 -1980-03-31 -82.6 -mL/min - -413604 -1010 -1980-06-20 -77.7 +6258 +19 +2007-10-14 +30.2 mL/min/{1.73_m2} -413960 -1010 -1980-10-31 -79.7 -mL/min/{1.73_m2} - - -412885 -1010 -1981-03-06 -64.2 +5996 +19 +2007-11-18 +30.8 mL/min/{1.73_m2} - -414617 -1010 -1981-03-31 -89.5 -mL/min - -413538 -1010 -1981-05-01 -72.9 +5388 +19 +2008-04-13 +44.3 mL/min/{1.73_m2} -413023 -1010 -1981-06-26 -64.4 +5611 +19 +2008-08-31 +34.0 mL/min/{1.73_m2} -414785 -1010 -1981-07-10 -86.7 -mL/min/{1.73_m2} - - -413284 -1010 -1981-10-30 -85.7 +6235 +19 +2009-02-08 +31.5 mL/min/{1.73_m2} - -412322 -1010 -1982-03-31 -67.7 -mL/min - -414669 -1010 -1982-05-28 -77.3 +5435 +19 +2009-09-06 +45.9 mL/min/{1.73_m2} -414853 -1010 -1982-07-02 -84.8 -mL/min/{1.73_m2} - - -412685 -1010 -1982-10-22 -77.5 +6746 +19 +2009-11-01 +46.9 mL/min/{1.73_m2} - -414390 -1010 -1983-03-31 -69.1 -mL/min - -413950 -1010 -1983-07-08 -76.7 -mL/min/{1.73_m2} - - -413986 -1010 -1984-01-20 -67.5 +6462 +19 +2010-05-02 +46.5 mL/min/{1.73_m2} - -412642 -1010 -1984-03-30 -87.1 -mL/min - -413020 -1010 -1984-05-18 -86.0 +5694 +19 +2010-09-12 +35.9 mL/min/{1.73_m2} -414362 -1010 -1984-07-13 -80.7 +6638 +19 +2011-09-18 +35.6 mL/min/{1.73_m2} -414745 -1010 -1984-10-12 -86.8 -mL/min/{1.73_m2} - - -412492 -1010 -1985-01-11 -82.0 +6276 +19 +2011-12-25 +43.3 mL/min/{1.73_m2} - -412585 -1010 -1985-03-30 -67.4 -mL/min - -414631 -1010 -1985-07-12 -85.2 +6449 +19 +2012-02-19 +36.3 mL/min/{1.73_m2} -414484 -1010 -1985-07-26 -76.4 +5764 +19 +2012-09-23 +53.1 mL/min/{1.73_m2} -412299 -1010 -1986-03-30 -71.2 -mL/min - - -412668 -1010 -1986-08-01 -68.9 +6670 +19 +2013-01-20 +37.0 mL/min/{1.73_m2} - -413317 -1010 -1987-03-30 -85.4 -mL/min - -412507 -1010 -1987-07-03 -87.1 +5741 +19 +2013-09-29 +38.6 mL/min/{1.73_m2} -414494 -1010 -1987-08-07 -61.8 +6366 +19 +2014-08-10 +56.6 mL/min/{1.73_m2} -413377 -1010 -1988-01-29 -60.4 -mL/min/{1.73_m2} - - -414029 -1010 -1988-03-29 -73.1 +6402 +19 +2014-08-10 +89.2 mL/min - -414130 -1010 -1988-08-12 -67.5 -mL/min/{1.73_m2} - -414705 -1010 -1988-12-23 -44.3 +5508 +19 +2014-10-05 +52.3 mL/min/{1.73_m2} -414559 -1010 -1989-02-17 -53.5 +6677 +19 +2014-11-02 +50.2 mL/min/{1.73_m2} -413565 -1010 -1989-03-29 -86.0 +5659 +19 +2015-08-31 +68.2 mL/min -413781 -1010 -1989-04-21 -31.7 -mL/min/{1.73_m2} - - -413405 -1010 -1989-07-28 -39.9 -mL/min/{1.73_m2} - - -413432 -1010 -1989-08-18 -37.2 -mL/min/{1.73_m2} - - -412404 -1010 -1989-09-15 -44.9 -mL/min/{1.73_m2} - - -414824 -1010 -1989-10-20 -52.6 +6101 +19 +2015-10-11 +35.5 mL/min/{1.73_m2} -412854 -1010 -1990-01-19 -43.1 +5780 +19 +2016-02-28 +35.0 mL/min/{1.73_m2} -414098 -1010 -1990-03-29 -83.8 +5543 +19 +2016-08-30 +75.5 mL/min -412564 -1010 -1990-04-13 -56.9 -mL/min/{1.73_m2} - - -412917 -1010 -1990-07-13 -40.2 -mL/min/{1.73_m2} - - -413845 -1010 -1990-08-10 -40.6 -mL/min/{1.73_m2} - - -413163 -1010 -1990-08-24 -44.1 -mL/min/{1.73_m2} - - -414411 -1010 -1990-10-12 -40.0 +5971 +19 +2016-10-16 +55.4 mL/min/{1.73_m2} -414306 -1010 -1991-01-11 -43.8 +5870 +19 +2016-11-27 +31.9 mL/min/{1.73_m2} -412350 -1010 -1991-02-15 -55.8 +6206 +19 +2016-12-25 +36.5 mL/min/{1.73_m2} -413469 -1010 -1991-03-29 -79.3 +5650 +19 +2017-08-30 +69.1 mL/min -413650 -1010 -1991-03-29 -31.9 -mL/min/{1.73_m2} - - -412360 -1010 -1991-04-19 -38.4 -mL/min/{1.73_m2} - - -414592 -1010 -1991-05-17 -34.8 +6536 +19 +2017-10-22 +54.1 mL/min/{1.73_m2} -412638 -1010 -1991-06-07 -50.0 -mL/min/{1.73_m2} +6477 +19 +2018-08-30 +66.6 +mL/min -413550 -1010 -1991-08-30 -33.5 +5895 +19 +2018-10-28 +40.5 mL/min/{1.73_m2} -413132 -1010 -1991-10-11 -47.0 +5842 +19 +2018-11-18 +47.1 mL/min/{1.73_m2} -412707 -1010 -1991-12-06 -54.4 +6579 +19 +2018-12-16 +35.3 mL/min/{1.73_m2} -412530 -1010 -1992-03-13 -47.8 -mL/min/{1.73_m2} - - -414725 -1010 -1992-03-28 -69.9 +6121 +19 +2019-08-30 +71.7 mL/min - -412734 -1010 -1992-04-10 -35.7 -mL/min/{1.73_m2} - - -413169 -1010 -1992-09-04 -55.9 -mL/min/{1.73_m2} - - -414597 -1010 -1992-09-18 -50.4 -mL/min/{1.73_m2} - -414012 -1010 -1992-10-02 -54.1 +6615 +19 +2019-09-22 +48.9 mL/min/{1.73_m2} -413326 -1010 -1992-11-27 -32.7 +5633 +19 +2019-11-03 +34.0 mL/min/{1.73_m2} -413359 -1010 -1993-01-29 -40.3 +6033 +19 +2020-07-12 +38.6 mL/min/{1.73_m2} -413218 -1010 -1993-03-28 -65.2 +5535 +19 +2020-08-29 +76.4 mL/min -413205 -1010 -1993-04-02 -37.0 -mL/min/{1.73_m2} - - -413623 -1010 -1993-04-30 -33.4 +6724 +19 +2020-10-04 +39.4 mL/min/{1.73_m2} - -413673 -1010 -1993-07-04 -31.5 -mL/min - -412758 -1010 -1993-08-27 -48.3 +6308 +19 +2020-11-08 +39.6 mL/min/{1.73_m2} -414233 -1010 -1993-09-10 -58.6 +5477 +19 +2020-11-22 +32.6 mL/min/{1.73_m2} -412596 -1010 -1993-09-24 -41.4 +5412 +19 +2021-07-04 +32.5 mL/min/{1.73_m2} -414880 -1010 -1993-11-26 -55.1 -mL/min/{1.73_m2} - - -414761 -1010 -1993-12-31 -50.2 +6416 +19 +2021-08-01 +40.1 mL/min/{1.73_m2} - -414231 -1010 -1994-01-19 -53.8 -mL/min - -414378 -1010 -1994-01-19 -53.8 +5561 +19 +2021-08-29 +74.6 mL/min -413908 -1010 -1994-03-04 -57.7 +6184 +19 +2021-10-03 +42.0 mL/min/{1.73_m2} -413251 -1010 -1994-03-28 -86.1 -mL/min - - -413515 -1010 -1994-06-03 -33.9 +6779 +19 +2021-11-14 +31.9 mL/min/{1.73_m2} - -413722 -1010 -1994-07-19 -43.3 -mL/min - -414143 -1010 -1994-07-19 -43.3 +5703 +19 +2022-08-29 +67.6 mL/min -414536 -1010 -1994-09-16 -47.8 -mL/min/{1.73_m2} - - -412888 -1010 -1994-10-07 -40.6 +6508 +19 +2022-10-30 +45.5 mL/min/{1.73_m2} - -413798 -1010 -1995-03-28 -72.3 -mL/min -
@@ -4480,65 +3813,65 @@

Produce events for Atlas

-2022-02-11 -1 -0.3 -2000000001 - - 2016-01-29 3 0.5 2000000001 - + 2014-08-10 19 0.7 2000000001 - + 2016-11-27 19 1.6 2000000001 - + 2018-12-16 19 0.8 2000000001 - + 2019-11-03 19 1.0 2000000001 - + 2020-11-22 19 0.6 2000000001 - + 2021-11-14 19 0.8 2000000001 - + 2021-02-21 30 0.4 2000000001 - + 2021-02-23 30 0.3 2000000001 + +2021-02-24 +30 +0.3 +2000000001 +
diff --git a/docs/ascvd.Rmd b/docs/ascvd.Rmd index 58b7d9d..1c62b10 100644 --- a/docs/ascvd.Rmd +++ b/docs/ascvd.Rmd @@ -11,7 +11,7 @@ vignette: > library(knitr) options(scipen = 5e5) knitr::opts_chunk$set(collapse = TRUE, comment = "#>") -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) # contains cred$pg +library(credx) # contains cred$pg library(wrap) usn <- function(n, decimals = 0) { @@ -29,7 +29,7 @@ library(dplyr) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/ascvd.html b/docs/ascvd.html index d7f24e6..a243695 100644 --- a/docs/ascvd.html +++ b/docs/ascvd.html @@ -2279,7 +2279,7 @@

Calculating the ASCVD Risk Estimator Plus # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). @@ -2789,7 +2789,7 @@

Results

-21 +11 1 2005-05-13 00:00:00 @@ -2819,7 +2819,7 @@

Results

0.0100000 -22 +21 1 2006-05-12 364 days @@ -2849,7 +2849,7 @@

Results

0.0100000 -13 +12 1 2008-05-16 00:00:00 @@ -2879,7 +2879,7 @@

Results

0.0100000 -24 +13 1 2011-05-20 00:00:00 @@ -2909,7 +2909,7 @@

Results

0.0100000 -25 +24 1 2014-03-07 00:00:00 @@ -2939,7 +2939,7 @@

Results

0.0206787 -26 +6 1 2016-03-11 00:00:00 @@ -2969,7 +2969,7 @@

Results

0.0254284 -17 +7 1 2018-03-16 00:00:00 @@ -2999,7 +2999,7 @@

Results

0.0293479 -28 +17 1 2020-03-20 00:00:00 @@ -3029,7 +3029,7 @@

Results

0.0383479 -29 +9 1 2022-02-11 00:00:00 @@ -3059,7 +3059,7 @@

Results

0.0581121 -20 +10 1 2022-03-25 00:00:00 @@ -3089,7 +3089,7 @@

Results

0.0397026 -106 +105 2 2004-07-17 00:00:00 @@ -3119,7 +3119,7 @@

Results

0.0877214 -79 +86 2 2005-07-23 371 days @@ -3149,7 +3149,7 @@

Results

0.0722231 -80 +87 2 2006-07-29 742 days @@ -3179,7 +3179,7 @@

Results

0.0855555 -99 +39 2 2007-08-04 00:00:00 @@ -3209,7 +3209,7 @@

Results

0.0695121 -110 +109 2 2008-08-09 371 days @@ -3239,7 +3239,7 @@

Results

0.0999609 -83 +110 2 2009-08-15 742 days @@ -3269,7 +3269,7 @@

Results

0.0792618 -100 +91 2 2010-08-21 00:00:00 @@ -3299,7 +3299,7 @@

Results

0.1446872 -113 +112 2 2011-08-27 371 days @@ -3329,7 +3329,7 @@

Results

0.1641586 -86 +113 2 2012-09-01 742 days @@ -3359,7 +3359,7 @@

Results

0.1313929 -115 +114 2 2013-09-07 00:00:00 @@ -3412,7 +3412,7 @@

Plots

random_patient <- sample(patients_with_most_data, 1)
 
 message('Sampled patient: ', random_patient)
-#> Sampled patient: 7770
+#> Sampled patient: 18592

And then we plot the chosen patient.

ascvd |> select(
   # Let's NOT plot the columns below
@@ -3424,8 +3424,8 @@ 

Plots

-calculated_risk, -baseline_survival) |> phea_plot(random_patient, verbose = FALSE)
-
- +
+

Obtain the SQL query that computes the phenotype

@@ -3433,452 +3433,386 @@

Obtain the SQL query that computes the phenotype

code_shot(), or dbplyr::sql_render(), or the .clip_sql option in calculate_formula().

code_shot(ascvd)
-
SELECT
-  "row_id",
-  "pid",
-  "ts",
-  "window",
-  "person_gender_concept_id",
-  "person_race_concept_id",
-  "person_birth_datetime",
-  "smoker_observation_datetime",
-  "diabetes_condition_start_datetime",
-  "htt_drug_exposure_start_datetime",
-  "sbp_measurement_datetime",
-  "tc_value_as_number",
-  "hdl_value_as_number",
-  "sbp_value_as_number",
-  "diabetes_condition_concept_id",
-  "htt_drug_concept_id",
-  "is_woman",
-  "is_black",
-  "age",
-  "is_smoker",
-  "has_diabetes",
-  "htt_sbp_dist",
-  "baseline_survival",
-  "group_mean",
-  "htt",
-  "individual_sum",
-  "calculated_risk",
-  "estimated_risk"
-FROM (
-  SELECT
-    *,
-    lag(phea_kco_var1) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag1",
-    lag(phea_kco_var2) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag2",
-    lag(phea_kco_var3) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag3",
-    lag(phea_kco_var4) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag4",
-    lag(phea_kco_var5) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag5",
-    lag(phea_kco_var6) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag6",
-    lag(phea_kco_var7) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag7",
-    lag(phea_kco_var8) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag8",
-    lag(phea_kco_var9) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag9",
-    lag(phea_kco_var10) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag10",
-    lag(phea_kco_var11) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag11",
-    lag(phea_kco_var12) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag12",
-    lag(phea_kco_var13) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag13"
-  FROM (
-    SELECT
-      *,
-      pid AS "phea_kco_var1",
-      is_woman AS "phea_kco_var2",
-      is_black AS "phea_kco_var3",
-      age AS "phea_kco_var4",
-      is_smoker AS "phea_kco_var5",
-      has_diabetes AS "phea_kco_var6",
-      htt_sbp_dist AS "phea_kco_var7",
-      baseline_survival AS "phea_kco_var8",
-      group_mean AS "phea_kco_var9",
-      htt AS "phea_kco_var10",
-      individual_sum AS "phea_kco_var11",
-      calculated_risk AS "phea_kco_var12",
-      estimated_risk AS "phea_kco_var13"
-    FROM (
-      SELECT *, least(0.3, greatest(0.01, calculated_risk)) AS "estimated_risk"
-      FROM (
-        SELECT
-          *,
-          (1 - baseline_survival) * exp(individual_sum - group_mean) AS "calculated_risk"
-        FROM (
-          SELECT
-            *,
-            case when is_woman then (
-    case when is_black then (17.114 * ln(age) + 0.940 * ln(tc_value_as_number) + -18.920 * ln(hdl_value_as_number) + 4.475 * ln(age) * ln(hdl_value_as_number) + case when htt is true then
-    29.291 * ln(sbp_value_as_number) else 0 end + case when htt is true then
-    -6.432 * ln(age) * ln(sbp_value_as_number) else 0 end + case when htt is false then
-    27.820 * ln(sbp_value_as_number) else 0 end + case when htt is false then
-    -6.087 * ln(age) * ln(sbp_value_as_number) else 0 end + 0.691 * case when is_smoker then 1 else 0 end + 0.874 * case when has_diabetes then 1 else 0 end)
-    else (-29.799 * ln(age) + 4.884 * ln(age)^2 + 13.540 * ln(tc_value_as_number) + -3.114 * ln(age) * ln(tc_value_as_number) + -13.578 * ln(hdl_value_as_number) + 3.149 * ln(age) * ln(hdl_value_as_number) + case when htt is true then
-    2.019 * ln(sbp_value_as_number) else 0 end + case when htt is false then
-    1.957 * ln(sbp_value_as_number) else 0 end + 7.574 * case when is_smoker then 1 else 0 end + -1.665 * ln(age) * case when is_smoker then 1 else 0 end + 0.661 * case when has_diabetes then 1 else 0 end)
-    end)
-  else (
-    case when is_black then (2.469 * ln(age) + 0.30 * ln(tc_value_as_number) + -0.307 * ln(hdl_value_as_number) + case when htt is true then
-    1.916 * ln(sbp_value_as_number) else 0 end + case when htt is false then
-    1.809 * ln(sbp_value_as_number) else 0 end + 0.549 * case when is_smoker then 1 else 0 end + 0.645 * case when has_diabetes then 1 else 0 end)
-    else (12.344 * ln(age) + 11.853 * ln(tc_value_as_number) + -2.664 * ln(age) * ln(tc_value_as_number) + -7.990 * ln(hdl_value_as_number) + 1.769 * ln(age) * ln(hdl_value_as_number) + case when htt is true then 
-    1.797 * ln(sbp_value_as_number) else 0 end + case when htt is false then
-    1.764 * ln(sbp_value_as_number) else 0 end + 7.837 * case when is_smoker then 1 else 0 end + -1.795 * ln(age) * case when is_smoker then 1 else 0 end + 0.658 * case when has_diabetes then 1 else 0 end)
-    end)
-  end AS "individual_sum"
-          FROM (
-            SELECT
-              *,
-              case when is_woman then (
-    case when is_black then 0.9533
-    else 0.9665
-    end)
-  else (
-    case when is_black then 0.8954
-    else 0.9144
-    end)
-  end AS "baseline_survival",
-              case when is_woman then (
-    case when is_black then 86.61
-    else -29.18
-    end)
-  else (
-    case when is_black then 19.54
-    else 61.18
-    end)
-  end AS "group_mean",
-              htt_drug_exposure_start_datetime is not null
-        and htt_sbp_dist < '4 months' AS "htt"
-            FROM (
-              SELECT
-                "row_id",
-                "pid",
-                "ts",
-                "window",
-                "person_gender_concept_id",
-                "person_race_concept_id",
-                "person_birth_datetime",
-                "smoker_observation_datetime",
-                "diabetes_condition_start_datetime",
-                "htt_drug_exposure_start_datetime",
-                "sbp_measurement_datetime",
-                "tc_value_as_number",
-                "hdl_value_as_number",
-                "sbp_value_as_number",
-                "diabetes_condition_concept_id",
-                "htt_drug_concept_id",
-                person_gender_concept_id = 8532 AS "is_woman",
-                person_race_concept_id = 8516 AS "is_black",
-                extract(year from age(ts, person_birth_datetime)) AS "age",
-                smoker_observation_datetime is not null AS "is_smoker",
-                diabetes_condition_start_datetime is not null AS "has_diabetes",
-                case when htt_drug_exposure_start_datetime < sbp_measurement_datetime
-        then sbp_measurement_datetime - htt_drug_exposure_start_datetime
-        else htt_drug_exposure_start_datetime - sbp_measurement_datetime end AS "htt_sbp_dist"
-              FROM (
-                SELECT
-                  *,
-                  greatest(sbp_ts, tc_ts, hdl_ts, smoker_ts, htt_ts) - least(sbp_ts, tc_ts, hdl_ts, smoker_ts, htt_ts) AS "window",
-                  last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row"
-                FROM (
-                  SELECT
-                    "row_id",
-                    "pid",
-                    "ts",
-                    MAX("sbp_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "sbp_measurement_datetime",
-                    MAX("sbp_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "sbp_value_as_number",
-                    MAX("sbp_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "sbp_ts",
-                    MAX("tc_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "tc_value_as_number",
-                    MAX("tc_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_5") AS "tc_ts",
-                    MAX("hdl_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_6") AS "hdl_value_as_number",
-                    MAX("hdl_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_7") AS "hdl_ts",
-                    MAX("diabetes_condition_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_8") AS "diabetes_condition_concept_id",
-                    MAX("diabetes_condition_start_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_9") AS "diabetes_condition_start_datetime",
-                    MAX("diabetes_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_10") AS "diabetes_ts",
-                    MAX("smoker_observation_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_11") AS "smoker_observation_datetime",
-                    MAX("smoker_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_12") AS "smoker_ts",
-                    MAX("htt_drug_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_13") AS "htt_drug_concept_id",
-                    MAX("htt_drug_exposure_start_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_14") AS "htt_drug_exposure_start_datetime",
-                    MAX("htt_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_15") AS "htt_ts",
-                    MAX("person_gender_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_16") AS "person_gender_concept_id",
-                    MAX("person_birth_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_17") AS "person_birth_datetime",
-                    MAX("person_race_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_18") AS "person_race_concept_id",
-                    MAX("person_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_19") AS "person_ts"
-                  FROM (
-                    SELECT
-                      *,
-                      SUM(CASE WHEN (("sbp_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1",
-                      SUM(CASE WHEN (("sbp_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2",
-                      SUM(CASE WHEN (("sbp_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3",
-                      SUM(CASE WHEN (("tc_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4",
-                      SUM(CASE WHEN (("tc_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_5",
-                      SUM(CASE WHEN (("hdl_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_6",
-                      SUM(CASE WHEN (("hdl_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_7",
-                      SUM(CASE WHEN (("diabetes_condition_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_8",
-                      SUM(CASE WHEN (("diabetes_condition_start_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_9",
-                      SUM(CASE WHEN (("diabetes_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_10",
-                      SUM(CASE WHEN (("smoker_observation_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_11",
-                      SUM(CASE WHEN (("smoker_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_12",
-                      SUM(CASE WHEN (("htt_drug_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_13",
-                      SUM(CASE WHEN (("htt_drug_exposure_start_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_14",
-                      SUM(CASE WHEN (("htt_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_15",
-                      SUM(CASE WHEN (("person_gender_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_16",
-                      SUM(CASE WHEN (("person_birth_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_17",
-                      SUM(CASE WHEN (("person_race_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_18",
-                      SUM(CASE WHEN (("person_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_19"
-                    FROM (
-                      SELECT
-                        row_number() over () AS "row_id",
-                        "pid",
-                        "ts",
-                        last_value(case when "name" = 'vy3u7foijxrw' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_measurement_datetime",
-                        last_value(case when "name" = 'vy3u7foijxrw' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_value_as_number",
-                        last_value(case when "name" = 'vy3u7foijxrw' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_ts",
-                        last_value(case when "name" = 'dxutkza0n14d' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "tc_value_as_number",
-                        last_value(case when "name" = 'dxutkza0n14d' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "tc_ts",
-                        last_value(case when "name" = 'm5vge4r7mz8b' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "hdl_value_as_number",
-                        last_value(case when "name" = 'm5vge4r7mz8b' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "hdl_ts",
-                        last_value(case when "name" = 'ljisonwcvt9b' then "condition_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_condition_concept_id",
-                        last_value(case when "name" = 'ljisonwcvt9b' then "condition_start_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_condition_start_datetime",
-                        last_value(case when "name" = 'ljisonwcvt9b' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_ts",
-                        last_value(case when "name" = 'wqrs93jem870' then "observation_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "smoker_observation_datetime",
-                        last_value(case when "name" = 'wqrs93jem870' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "smoker_ts",
-                        last_value(case when "name" = 'j7dyz2gantvs' then "drug_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_drug_concept_id",
-                        last_value(case when "name" = 'j7dyz2gantvs' then "drug_exposure_start_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_drug_exposure_start_datetime",
-                        last_value(case when "name" = 'j7dyz2gantvs' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_ts",
-                        last_value(case when "name" = 'lsfy3jg97b8i' then "gender_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_gender_concept_id",
-                        last_value(case when "name" = 'lsfy3jg97b8i' then "birth_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_birth_datetime",
-                        last_value(case when "name" = 'lsfy3jg97b8i' then "race_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_race_concept_id",
-                        last_value(case when "name" = 'lsfy3jg97b8i' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_ts"
-                      FROM (
-                        (
-                          SELECT
-                            *,
-                            NULL AS "gender_concept_id",
-                            NULL AS "birth_datetime",
-                            NULL AS "race_concept_id"
-                          FROM (
-                            (
-                              SELECT
-                                *,
-                                NULL AS "drug_concept_id",
-                                NULL AS "drug_exposure_start_datetime"
-                              FROM (
-                                (
-                                  SELECT *, NULL AS "observation_datetime"
-                                  FROM (
-                                    (
-                                      SELECT
-                                        *,
-                                        NULL AS "condition_concept_id",
-                                        NULL AS "condition_start_datetime"
-                                      FROM (
-                                        (
-                                          (
-                                            SELECT
-                                              'vy3u7foijxrw' AS "name",
-                                              "person_id" AS "pid",
-                                              "measurement_datetime" AS "ts",
-                                              "measurement_datetime",
-                                              "value_as_number"
-                                            FROM "cdm_new_york3"."measurement"
-                                            WHERE ("measurement_concept_id" = 3004249.0)
-                                          )
-                                          UNION ALL
-                                          (
-                                            SELECT
-                                              "name",
-                                              "pid",
-                                              "ts",
-                                              NULL AS "measurement_datetime",
-                                              "value_as_number"
-                                            FROM (
-                                              SELECT
-                                                'dxutkza0n14d' AS "name",
-                                                "person_id" AS "pid",
-                                                "measurement_datetime" AS "ts",
-                                                "value_as_number"
-                                              FROM "cdm_new_york3"."measurement"
-                                              WHERE ("measurement_concept_id" = 3027114.0)
-                                            ) "q01"
-                                          )
-                                        )
-                                        UNION ALL
-                                        (
-                                          SELECT
-                                            "name",
-                                            "pid",
-                                            "ts",
-                                            NULL AS "measurement_datetime",
-                                            "value_as_number"
-                                          FROM (
-                                            SELECT
-                                              'm5vge4r7mz8b' AS "name",
-                                              "person_id" AS "pid",
-                                              "measurement_datetime" AS "ts",
-                                              "value_as_number"
-                                            FROM "cdm_new_york3"."measurement"
-                                            WHERE ("measurement_concept_id" = 3007070.0)
-                                          ) "q02"
-                                        )
-                                      ) "q03"
-                                    )
-                                    UNION ALL
-                                    (
-                                      SELECT
-                                        "name",
-                                        "pid",
-                                        "ts",
-                                        NULL AS "measurement_datetime",
-                                        NULL AS "value_as_number",
-                                        "condition_concept_id",
-                                        "condition_start_datetime"
-                                      FROM (
-                                        SELECT
-                                          'ljisonwcvt9b' AS "name",
-                                          "person_id" AS "pid",
-                                          "condition_start_datetime" AS "ts",
-                                          "condition_concept_id",
-                                          "condition_start_datetime"
-                                        FROM "cdm_new_york3"."condition_occurrence"
-                                        WHERE ("condition_concept_id" = 201826.0)
-                                      ) "q04"
-                                    )
-                                  ) "q05"
-                                )
-                                UNION ALL
-                                (
-                                  SELECT
-                                    "name",
-                                    "pid",
-                                    "ts",
-                                    NULL AS "measurement_datetime",
-                                    NULL AS "value_as_number",
-                                    NULL AS "condition_concept_id",
-                                    NULL AS "condition_start_datetime",
-                                    "observation_datetime"
-                                  FROM (
-                                    SELECT
-                                      'wqrs93jem870' AS "name",
-                                      "person_id" AS "pid",
-                                      "observation_datetime" AS "ts",
-                                      "observation_datetime"
-                                    FROM "cdm_new_york3"."observation"
-                                    WHERE ("observation_concept_id" IN (42709996.0))
-                                  ) "q06"
-                                )
-                              ) "q07"
-                            )
-                            UNION ALL
-                            (
-                              SELECT
-                                "name",
-                                "pid",
-                                "ts",
-                                NULL AS "measurement_datetime",
-                                NULL AS "value_as_number",
-                                NULL AS "condition_concept_id",
-                                NULL AS "condition_start_datetime",
-                                NULL AS "observation_datetime",
-                                "drug_concept_id",
-                                "drug_exposure_start_datetime"
-                              FROM (
-                                SELECT
-                                  'j7dyz2gantvs' AS "name",
-                                  "person_id" AS "pid",
-                                  "drug_exposure_start_datetime" AS "ts",
-                                  "drug_concept_id",
-                                  "drug_exposure_start_datetime"
-                                FROM (
-                                  SELECT
-                                    "drug_exposure_id",
-                                    "person_id",
-                                    "drug_concept_id",
-                                    "drug_exposure_start_date",
-                                    "drug_exposure_start_datetime",
-                                    "drug_exposure_end_date",
-                                    "drug_exposure_end_datetime",
-                                    "verbatim_end_date",
-                                    "drug_type_concept_id",
-                                    "stop_reason",
-                                    "refills",
-                                    "quantity",
-                                    "days_supply",
-                                    "sig",
-                                    "route_concept_id",
-                                    "lot_number",
-                                    "provider_id",
-                                    "visit_occurrence_id",
-                                    "visit_detail_id",
-                                    "drug_source_value",
-                                    "drug_source_concept_id",
-                                    "route_source_value",
-                                    "dose_unit_source_value"
-                                  FROM "cdm_new_york3"."drug_exposure" AS "LHS"
-                                  INNER JOIN (
-                                    SELECT "descendant_concept_id"
-                                    FROM (
-                                      SELECT
-                                        "ancestor_concept_id",
-                                        "descendant_concept_id",
-                                        "min_levels_of_separation",
-                                        "max_levels_of_separation"
-                                      FROM "cdm_new_york3"."concept_ancestor" AS "LHS"
-                                      INNER JOIN (
-                                        SELECT "concept_id"
-                                        FROM "cdm_new_york3"."concept"
-                                        WHERE ("vocabulary_id" = 'ATC' AND "concept_code" IN ('C02', 'C03', 'C07', 'C08', 'C09'))
-                                      ) "RHS"
-                                        ON ("LHS"."ancestor_concept_id" = "RHS"."concept_id")
-                                    ) "q08"
-                                  ) "RHS"
-                                    ON ("LHS"."drug_concept_id" = "RHS"."descendant_concept_id")
-                                ) "q09"
-                              ) "q10"
-                            )
-                          ) "q11"
-                        )
-                        UNION ALL
-                        (
-                          SELECT
-                            "name",
-                            "pid",
-                            "ts",
-                            NULL AS "measurement_datetime",
-                            NULL AS "value_as_number",
-                            NULL AS "condition_concept_id",
-                            NULL AS "condition_start_datetime",
-                            NULL AS "observation_datetime",
-                            NULL AS "drug_concept_id",
-                            NULL AS "drug_exposure_start_datetime",
-                            "gender_concept_id",
-                            "birth_datetime",
-                            "race_concept_id"
-                          FROM (
-                            SELECT
-                              'lsfy3jg97b8i' AS "name",
-                              "person_id" AS "pid",
-                              "birth_datetime" AS "ts",
-                              "gender_concept_id",
-                              "birth_datetime",
-                              "race_concept_id"
-                            FROM "cdm_new_york3"."person"
-                          ) "q12"
-                        )
-                      ) "q13"
-                    ) "q14"
-                  ) "q15"
-                ) "q16"
-              ) "q17"
-              WHERE ("row_id" = "phea_ts_row" AND sbp_ts is not null and tc_ts is not null and hdl_ts is not null and person_ts is not null)
-            ) "q18"
-          ) "q19"
-        ) "q20"
-      ) "q21"
-    ) "q22"
-  ) "q23"
-) "q24"
-WHERE ((("phea_kco_lag1" IS NULL) AND NOT(("phea_kco_var1" IS NULL))) OR "phea_kco_lag1" != "phea_kco_var1" OR (("phea_kco_lag2" IS NULL) AND NOT(("phea_kco_var2" IS NULL))) OR "phea_kco_lag2" != "phea_kco_var2" OR (("phea_kco_lag3" IS NULL) AND NOT(("phea_kco_var3" IS NULL))) OR "phea_kco_lag3" != "phea_kco_var3" OR (("phea_kco_lag4" IS NULL) AND NOT(("phea_kco_var4" IS NULL))) OR "phea_kco_lag4" != "phea_kco_var4" OR (("phea_kco_lag5" IS NULL) AND NOT(("phea_kco_var5" IS NULL))) OR "phea_kco_lag5" != "phea_kco_var5" OR (("phea_kco_lag6" IS NULL) AND NOT(("phea_kco_var6" IS NULL))) OR "phea_kco_lag6" != "phea_kco_var6" OR (("phea_kco_lag7" IS NULL) AND NOT(("phea_kco_var7" IS NULL))) OR "phea_kco_lag7" != "phea_kco_var7" OR (("phea_kco_lag8" IS NULL) AND NOT(("phea_kco_var8" IS NULL))) OR "phea_kco_lag8" != "phea_kco_var8" OR (("phea_kco_lag9" IS NULL) AND NOT(("phea_kco_var9" IS NULL))) OR "phea_kco_lag9" != "phea_kco_var9" OR (("phea_kco_lag10" IS NULL) AND NOT(("phea_kco_var10" IS NULL))) OR "phea_kco_lag10" != "phea_kco_var10" OR (("phea_kco_lag11" IS NULL) AND NOT(("phea_kco_var11" IS NULL))) OR "phea_kco_lag11" != "phea_kco_var11" OR (("phea_kco_lag12" IS NULL) AND NOT(("phea_kco_var12" IS NULL))) OR "phea_kco_lag12" != "phea_kco_var12" OR (("phea_kco_lag13" IS NULL) AND NOT(("phea_kco_var13" IS NULL))) OR "phea_kco_lag13" != "phea_kco_var13")
+
SELECT *, least(0.3, greatest(0.01, calculated_risk)) AS "estimated_risk"
+FROM (
+  SELECT
+    *,
+    (1 - baseline_survival) * exp(individual_sum - group_mean) AS "calculated_risk"
+  FROM (
+    SELECT
+      *,
+      case when is_woman then (
+    case when is_black then (17.114 * ln(age) + 0.940 * ln(tc_value_as_number) + -18.920 * ln(hdl_value_as_number) + 4.475 * ln(age) * ln(hdl_value_as_number) + case when htt is true then
+    29.291 * ln(sbp_value_as_number) else 0 end + case when htt is true then
+    -6.432 * ln(age) * ln(sbp_value_as_number) else 0 end + case when htt is false then
+    27.820 * ln(sbp_value_as_number) else 0 end + case when htt is false then
+    -6.087 * ln(age) * ln(sbp_value_as_number) else 0 end + 0.691 * case when is_smoker then 1 else 0 end + 0.874 * case when has_diabetes then 1 else 0 end)
+    else (-29.799 * ln(age) + 4.884 * ln(age)^2 + 13.540 * ln(tc_value_as_number) + -3.114 * ln(age) * ln(tc_value_as_number) + -13.578 * ln(hdl_value_as_number) + 3.149 * ln(age) * ln(hdl_value_as_number) + case when htt is true then
+    2.019 * ln(sbp_value_as_number) else 0 end + case when htt is false then
+    1.957 * ln(sbp_value_as_number) else 0 end + 7.574 * case when is_smoker then 1 else 0 end + -1.665 * ln(age) * case when is_smoker then 1 else 0 end + 0.661 * case when has_diabetes then 1 else 0 end)
+    end)
+  else (
+    case when is_black then (2.469 * ln(age) + 0.30 * ln(tc_value_as_number) + -0.307 * ln(hdl_value_as_number) + case when htt is true then
+    1.916 * ln(sbp_value_as_number) else 0 end + case when htt is false then
+    1.809 * ln(sbp_value_as_number) else 0 end + 0.549 * case when is_smoker then 1 else 0 end + 0.645 * case when has_diabetes then 1 else 0 end)
+    else (12.344 * ln(age) + 11.853 * ln(tc_value_as_number) + -2.664 * ln(age) * ln(tc_value_as_number) + -7.990 * ln(hdl_value_as_number) + 1.769 * ln(age) * ln(hdl_value_as_number) + case when htt is true then 
+    1.797 * ln(sbp_value_as_number) else 0 end + case when htt is false then
+    1.764 * ln(sbp_value_as_number) else 0 end + 7.837 * case when is_smoker then 1 else 0 end + -1.795 * ln(age) * case when is_smoker then 1 else 0 end + 0.658 * case when has_diabetes then 1 else 0 end)
+    end)
+  end AS "individual_sum"
+    FROM (
+      SELECT
+        *,
+        case when is_woman then (
+    case when is_black then 0.9533
+    else 0.9665
+    end)
+  else (
+    case when is_black then 0.8954
+    else 0.9144
+    end)
+  end AS "baseline_survival",
+        case when is_woman then (
+    case when is_black then 86.61
+    else -29.18
+    end)
+  else (
+    case when is_black then 19.54
+    else 61.18
+    end)
+  end AS "group_mean",
+        htt_drug_exposure_start_datetime is not null
+        and htt_sbp_dist < '4 months' AS "htt"
+      FROM (
+        SELECT
+          "row_id",
+          "pid",
+          "ts",
+          "window",
+          "person_gender_concept_id",
+          "person_race_concept_id",
+          "person_birth_datetime",
+          "smoker_observation_datetime",
+          "diabetes_condition_start_datetime",
+          "htt_drug_exposure_start_datetime",
+          "sbp_measurement_datetime",
+          "tc_value_as_number",
+          "hdl_value_as_number",
+          "sbp_value_as_number",
+          "diabetes_condition_concept_id",
+          "htt_drug_concept_id",
+          person_gender_concept_id = 8532 AS "is_woman",
+          person_race_concept_id = 8516 AS "is_black",
+          extract(year from age(ts, person_birth_datetime)) AS "age",
+          smoker_observation_datetime is not null AS "is_smoker",
+          diabetes_condition_start_datetime is not null AS "has_diabetes",
+          case when htt_drug_exposure_start_datetime < sbp_measurement_datetime
+        then sbp_measurement_datetime - htt_drug_exposure_start_datetime
+        else htt_drug_exposure_start_datetime - sbp_measurement_datetime end AS "htt_sbp_dist"
+        FROM (
+          SELECT
+            *,
+            greatest(sbp_ts, tc_ts, hdl_ts, smoker_ts, htt_ts) - least(sbp_ts, tc_ts, hdl_ts, smoker_ts, htt_ts) AS "window",
+            last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row"
+          FROM (
+            SELECT
+              "row_id",
+              "pid",
+              "ts",
+              MAX("sbp_measurement_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "sbp_measurement_datetime",
+              MAX("sbp_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "sbp_value_as_number",
+              MAX("sbp_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "sbp_ts",
+              MAX("tc_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "tc_value_as_number",
+              MAX("tc_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_5") AS "tc_ts",
+              MAX("hdl_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_6") AS "hdl_value_as_number",
+              MAX("hdl_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_7") AS "hdl_ts",
+              MAX("diabetes_condition_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_8") AS "diabetes_condition_concept_id",
+              MAX("diabetes_condition_start_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_9") AS "diabetes_condition_start_datetime",
+              MAX("diabetes_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_10") AS "diabetes_ts",
+              MAX("smoker_observation_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_11") AS "smoker_observation_datetime",
+              MAX("smoker_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_12") AS "smoker_ts",
+              MAX("htt_drug_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_13") AS "htt_drug_concept_id",
+              MAX("htt_drug_exposure_start_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_14") AS "htt_drug_exposure_start_datetime",
+              MAX("htt_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_15") AS "htt_ts",
+              MAX("person_gender_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_16") AS "person_gender_concept_id",
+              MAX("person_birth_datetime") OVER (PARTITION BY "pid", "..dbplyr_partion_17") AS "person_birth_datetime",
+              MAX("person_race_concept_id") OVER (PARTITION BY "pid", "..dbplyr_partion_18") AS "person_race_concept_id",
+              MAX("person_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_19") AS "person_ts"
+            FROM (
+              SELECT
+                *,
+                SUM(CASE WHEN (("sbp_measurement_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1",
+                SUM(CASE WHEN (("sbp_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2",
+                SUM(CASE WHEN (("sbp_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3",
+                SUM(CASE WHEN (("tc_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4",
+                SUM(CASE WHEN (("tc_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_5",
+                SUM(CASE WHEN (("hdl_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_6",
+                SUM(CASE WHEN (("hdl_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_7",
+                SUM(CASE WHEN (("diabetes_condition_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_8",
+                SUM(CASE WHEN (("diabetes_condition_start_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_9",
+                SUM(CASE WHEN (("diabetes_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_10",
+                SUM(CASE WHEN (("smoker_observation_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_11",
+                SUM(CASE WHEN (("smoker_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_12",
+                SUM(CASE WHEN (("htt_drug_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_13",
+                SUM(CASE WHEN (("htt_drug_exposure_start_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_14",
+                SUM(CASE WHEN (("htt_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_15",
+                SUM(CASE WHEN (("person_gender_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_16",
+                SUM(CASE WHEN (("person_birth_datetime" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_17",
+                SUM(CASE WHEN (("person_race_concept_id" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_18",
+                SUM(CASE WHEN (("person_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_19"
+              FROM (
+                SELECT
+                  row_number() over () AS "row_id",
+                  "pid",
+                  "ts",
+                  last_value(case when "name" = 'uy6nx45f' then "measurement_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_measurement_datetime",
+                  last_value(case when "name" = 'uy6nx45f' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_value_as_number",
+                  last_value(case when "name" = 'uy6nx45f' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "sbp_ts",
+                  last_value(case when "name" = 'jtg6cqw2' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "tc_value_as_number",
+                  last_value(case when "name" = 'jtg6cqw2' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "tc_ts",
+                  last_value(case when "name" = 'g4hyu9kr' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "hdl_value_as_number",
+                  last_value(case when "name" = 'g4hyu9kr' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "hdl_ts",
+                  last_value(case when "name" = 'c0ul98tj' then "condition_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_condition_concept_id",
+                  last_value(case when "name" = 'c0ul98tj' then "condition_start_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_condition_start_datetime",
+                  last_value(case when "name" = 'c0ul98tj' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "diabetes_ts",
+                  last_value(case when "name" = 'bmspi6h9' then "observation_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "smoker_observation_datetime",
+                  last_value(case when "name" = 'bmspi6h9' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "smoker_ts",
+                  last_value(case when "name" = 'uuo8fc4l' then "drug_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_drug_concept_id",
+                  last_value(case when "name" = 'uuo8fc4l' then "drug_exposure_start_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_drug_exposure_start_datetime",
+                  last_value(case when "name" = 'uuo8fc4l' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "htt_ts",
+                  last_value(case when "name" = 'yafxl04m' then "gender_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_gender_concept_id",
+                  last_value(case when "name" = 'yafxl04m' then "birth_datetime" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_birth_datetime",
+                  last_value(case when "name" = 'yafxl04m' then "race_concept_id" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_race_concept_id",
+                  last_value(case when "name" = 'yafxl04m' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "person_ts"
+                FROM (
+                  (
+                    SELECT
+                      *,
+                      NULL AS "gender_concept_id",
+                      NULL AS "birth_datetime",
+                      NULL AS "race_concept_id"
+                    FROM (
+                      (
+                        SELECT
+                          *,
+                          NULL AS "drug_concept_id",
+                          NULL AS "drug_exposure_start_datetime"
+                        FROM (
+                          (
+                            SELECT *, NULL AS "observation_datetime"
+                            FROM (
+                              (
+                                SELECT
+                                  *,
+                                  NULL AS "condition_concept_id",
+                                  NULL AS "condition_start_datetime"
+                                FROM (
+                                  (
+                                    (
+                                      SELECT
+                                        'uy6nx45f' AS "name",
+                                        "person_id" AS "pid",
+                                        "measurement_datetime" AS "ts",
+                                        "measurement_datetime",
+                                        "value_as_number"
+                                      FROM "cdm_new_york3"."measurement"
+                                      WHERE ("measurement_concept_id" = 3004249.0)
+                                    )
+                                    UNION ALL
+                                    (
+                                      SELECT
+                                        "name",
+                                        "pid",
+                                        "ts",
+                                        NULL AS "measurement_datetime",
+                                        "value_as_number"
+                                      FROM (
+                                        SELECT
+                                          'jtg6cqw2' AS "name",
+                                          "person_id" AS "pid",
+                                          "measurement_datetime" AS "ts",
+                                          "value_as_number"
+                                        FROM "cdm_new_york3"."measurement"
+                                        WHERE ("measurement_concept_id" = 3027114.0)
+                                      ) "q01"
+                                    )
+                                  )
+                                  UNION ALL
+                                  (
+                                    SELECT
+                                      "name",
+                                      "pid",
+                                      "ts",
+                                      NULL AS "measurement_datetime",
+                                      "value_as_number"
+                                    FROM (
+                                      SELECT
+                                        'g4hyu9kr' AS "name",
+                                        "person_id" AS "pid",
+                                        "measurement_datetime" AS "ts",
+                                        "value_as_number"
+                                      FROM "cdm_new_york3"."measurement"
+                                      WHERE ("measurement_concept_id" = 3007070.0)
+                                    ) "q02"
+                                  )
+                                ) "q03"
+                              )
+                              UNION ALL
+                              (
+                                SELECT
+                                  "name",
+                                  "pid",
+                                  "ts",
+                                  NULL AS "measurement_datetime",
+                                  NULL AS "value_as_number",
+                                  "condition_concept_id",
+                                  "condition_start_datetime"
+                                FROM (
+                                  SELECT
+                                    'c0ul98tj' AS "name",
+                                    "person_id" AS "pid",
+                                    "condition_start_datetime" AS "ts",
+                                    "condition_concept_id",
+                                    "condition_start_datetime"
+                                  FROM "cdm_new_york3"."condition_occurrence"
+                                  WHERE ("condition_concept_id" = 201826.0)
+                                ) "q04"
+                              )
+                            ) "q05"
+                          )
+                          UNION ALL
+                          (
+                            SELECT
+                              "name",
+                              "pid",
+                              "ts",
+                              NULL AS "measurement_datetime",
+                              NULL AS "value_as_number",
+                              NULL AS "condition_concept_id",
+                              NULL AS "condition_start_datetime",
+                              "observation_datetime"
+                            FROM (
+                              SELECT
+                                'bmspi6h9' AS "name",
+                                "person_id" AS "pid",
+                                "observation_datetime" AS "ts",
+                                "observation_datetime"
+                              FROM "cdm_new_york3"."observation"
+                              WHERE ("observation_concept_id" IN (42709996.0))
+                            ) "q06"
+                          )
+                        ) "q07"
+                      )
+                      UNION ALL
+                      (
+                        SELECT
+                          "name",
+                          "pid",
+                          "ts",
+                          NULL AS "measurement_datetime",
+                          NULL AS "value_as_number",
+                          NULL AS "condition_concept_id",
+                          NULL AS "condition_start_datetime",
+                          NULL AS "observation_datetime",
+                          "drug_concept_id",
+                          "drug_exposure_start_datetime"
+                        FROM (
+                          SELECT
+                            'uuo8fc4l' AS "name",
+                            "person_id" AS "pid",
+                            "drug_exposure_start_datetime" AS "ts",
+                            "drug_concept_id",
+                            "drug_exposure_start_datetime"
+                          FROM (
+                            SELECT
+                              "drug_exposure_id",
+                              "person_id",
+                              "drug_concept_id",
+                              "drug_exposure_start_date",
+                              "drug_exposure_start_datetime",
+                              "drug_exposure_end_date",
+                              "drug_exposure_end_datetime",
+                              "verbatim_end_date",
+                              "drug_type_concept_id",
+                              "stop_reason",
+                              "refills",
+                              "quantity",
+                              "days_supply",
+                              "sig",
+                              "route_concept_id",
+                              "lot_number",
+                              "provider_id",
+                              "visit_occurrence_id",
+                              "visit_detail_id",
+                              "drug_source_value",
+                              "drug_source_concept_id",
+                              "route_source_value",
+                              "dose_unit_source_value"
+                            FROM "cdm_new_york3"."drug_exposure" AS "LHS"
+                            INNER JOIN (
+                              SELECT "descendant_concept_id"
+                              FROM (
+                                SELECT
+                                  "ancestor_concept_id",
+                                  "descendant_concept_id",
+                                  "min_levels_of_separation",
+                                  "max_levels_of_separation"
+                                FROM "cdm_new_york3"."concept_ancestor" AS "LHS"
+                                INNER JOIN (
+                                  SELECT "concept_id"
+                                  FROM "cdm_new_york3"."concept"
+                                  WHERE ("vocabulary_id" = 'ATC' AND "concept_code" IN ('C02', 'C03', 'C07', 'C08', 'C09'))
+                                ) "RHS"
+                                  ON ("LHS"."ancestor_concept_id" = "RHS"."concept_id")
+                              ) "q08"
+                            ) "RHS"
+                              ON ("LHS"."drug_concept_id" = "RHS"."descendant_concept_id")
+                          ) "q09"
+                        ) "q10"
+                      )
+                    ) "q11"
+                  )
+                  UNION ALL
+                  (
+                    SELECT
+                      "name",
+                      "pid",
+                      "ts",
+                      NULL AS "measurement_datetime",
+                      NULL AS "value_as_number",
+                      NULL AS "condition_concept_id",
+                      NULL AS "condition_start_datetime",
+                      NULL AS "observation_datetime",
+                      NULL AS "drug_concept_id",
+                      NULL AS "drug_exposure_start_datetime",
+                      "gender_concept_id",
+                      "birth_datetime",
+                      "race_concept_id"
+                    FROM (
+                      SELECT
+                        'yafxl04m' AS "name",
+                        "person_id" AS "pid",
+                        "birth_datetime" AS "ts",
+                        "gender_concept_id",
+                        "birth_datetime",
+                        "race_concept_id"
+                      FROM "cdm_new_york3"."person"
+                    ) "q12"
+                  )
+                ) "q13"
+              ) "q14"
+            ) "q15"
+          ) "q16"
+        ) "q17"
+        WHERE ("row_id" = "phea_ts_row" AND sbp_ts is not null and tc_ts is not null and hdl_ts is not null and person_ts is not null)
+      ) "q18"
+    ) "q19"
+  ) "q20"
+) "q21"

Author contact

Fabrício Kury
-2022/Dec/16
+2022/Dec/20
Be always welcome to reach me at .

diff --git a/docs/computing_bmi.html b/docs/computing_bmi.html index 087fc17..81113d4 100644 --- a/docs/computing_bmi.html +++ b/docs/computing_bmi.html @@ -2388,94 +2388,94 @@

Calculate the phenotype

27.43167 -21 -2 -2003-07-12 +12 +1 +2006-05-12 00:00:00 -183.4 -100.7 -1.834 -29.93855 +189.3 +98.3 +1.893 +27.43167 -42 -2 -2004-07-17 +13 +1 +2008-05-16 00:00:00 -183.4 -101.6 -1.834 -30.20613 +189.3 +98.3 +1.893 +27.43167 -52 -2 -2014-09-13 +14 +1 +2011-05-20 00:00:00 -183.4 -96.4 -1.834 -28.66014 +189.3 +98.3 +1.893 +27.43167 -33 -2 -2015-09-19 +5 +1 +2014-03-07 00:00:00 -183.4 -94.5 -1.834 -28.09527 +189.3 +98.3 +1.893 +27.43167 -54 -2 -2016-09-24 +6 +1 +2016-03-11 00:00:00 -183.4 -96.6 -1.834 -28.71961 +189.3 +98.3 +1.893 +27.43167 -55 -2 -2017-09-30 +7 +1 +2018-03-16 00:00:00 -183.4 -98.8 -1.834 -29.37367 +189.3 +98.3 +1.893 +27.43167 -36 -2 -2018-10-06 +18 +1 +2020-03-20 00:00:00 -183.4 -100.9 -1.834 -29.99801 +189.3 +98.3 +1.893 +27.43167 -57 -2 -2019-10-12 +19 +1 +2022-02-11 00:00:00 -183.4 -101.6 -1.834 -30.20613 +189.3 +98.3 +1.893 +27.43167 -61 -3 -2002-11-15 +20 +1 +2022-03-25 00:00:00 -187.3 -105.4 -1.873 -30.04451 +189.3 +98.3 +1.893 +27.43167 @@ -2497,8 +2497,8 @@

Plot the phenotype result

rename(weight_in_kg = weight_value_as_number) |> # Rename column phea_plot(pid = 2105) #> Collecting lazy table, done. (turn this message off with `verbose = FALSE`) -
- +
+

Computing aggregates from a phenotype result

@@ -2530,71 +2530,71 @@

Computing aggregates from a phenotype result

11872 34.82498 -36.71216 +36.72123 38.41281 81 22242 27.40980 -28.88162 +28.91259 30.29330 78 22906 27.58095 -29.15314 +29.46034 30.35070 76 4191 27.40982 -28.88852 +28.92541 30.28767 75 20198 27.53843 -29.02783 +29.35831 30.34387 73 5274 27.42844 -29.11970 +29.46449 30.36412 72 18843 27.14441 -28.85581 +29.09229 30.09168 71 -1665 -27.32200 -28.79019 -30.09031 -69 - - 10583 27.57425 -29.13246 +29.14332 30.36699 69 + +1665 +27.32200 +29.18407 +30.09031 +69 + -5333 -27.27405 -28.78132 -30.08615 +8055 +27.60844 +28.86689 +30.37667 68 @@ -2607,93 +2607,74 @@

Obtain SQL query that computes the phenotype

.clip_sql option in calculate_formula().

code_shot(bmi)
SELECT
-  "row_id",
-  "pid",
-  "ts",
-  "window",
-  "height_value_as_number",
-  "weight_value_as_number",
-  "height_in_meters",
-  "bmi"
-FROM (
-  SELECT
-    *,
-    lag(pid) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag1",
-    lag(height_in_meters) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag2",
-    lag(bmi) OVER (PARTITION BY "pid" ORDER BY "ts") AS "phea_kco_lag3"
-  FROM (
-    SELECT
-      *,
-      weight_value_as_number / (height_in_meters * height_in_meters) AS "bmi"
-    FROM (
-      SELECT
-        "row_id",
-        "pid",
-        "ts",
-        "window",
-        "height_value_as_number",
-        "weight_value_as_number",
-        height_value_as_number / 100 AS "height_in_meters"
-      FROM (
-        SELECT
-          *,
-          greatest(weight_ts, height_ts) - least(weight_ts, height_ts) AS "window",
-          last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row"
+  *,
+  weight_value_as_number / (height_in_meters * height_in_meters) AS "bmi"
+FROM (
+  SELECT
+    "row_id",
+    "pid",
+    "ts",
+    "window",
+    "height_value_as_number",
+    "weight_value_as_number",
+    height_value_as_number / 100 AS "height_in_meters"
+  FROM (
+    SELECT
+      *,
+      greatest(weight_ts, height_ts) - least(weight_ts, height_ts) AS "window",
+      last_value(row_id) over (partition by "pid", "ts") AS "phea_ts_row"
+    FROM (
+      SELECT
+        "row_id",
+        "pid",
+        "ts",
+        MAX("weight_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "weight_value_as_number",
+        MAX("weight_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "weight_ts",
+        MAX("height_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "height_value_as_number",
+        MAX("height_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "height_ts"
+      FROM (
+        SELECT
+          *,
+          SUM(CASE WHEN (("weight_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1",
+          SUM(CASE WHEN (("weight_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2",
+          SUM(CASE WHEN (("height_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3",
+          SUM(CASE WHEN (("height_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4"
         FROM (
           SELECT
-            "row_id",
+            row_number() over () AS "row_id",
             "pid",
             "ts",
-            MAX("weight_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_1") AS "weight_value_as_number",
-            MAX("weight_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_2") AS "weight_ts",
-            MAX("height_value_as_number") OVER (PARTITION BY "pid", "..dbplyr_partion_3") AS "height_value_as_number",
-            MAX("height_ts") OVER (PARTITION BY "pid", "..dbplyr_partion_4") AS "height_ts"
+            last_value(case when "name" = 'sh6icwld' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "weight_value_as_number",
+            last_value(case when "name" = 'sh6icwld' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "weight_ts",
+            last_value(case when "name" = 'fx43o2rt' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "height_value_as_number",
+            last_value(case when "name" = 'fx43o2rt' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "height_ts"
           FROM (
-            SELECT
-              *,
-              SUM(CASE WHEN (("weight_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_1",
-              SUM(CASE WHEN (("weight_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_2",
-              SUM(CASE WHEN (("height_value_as_number" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_3",
-              SUM(CASE WHEN (("height_ts" IS NULL)) THEN 0 ELSE 1 END) OVER (PARTITION BY "pid" ORDER BY "pid", "ts" ROWS UNBOUNDED PRECEDING) AS "..dbplyr_partion_4"
-            FROM (
-              SELECT
-                row_number() over () AS "row_id",
-                "pid",
-                "ts",
-                last_value(case when "name" = 'tkvriq8w' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "weight_value_as_number",
-                last_value(case when "name" = 'tkvriq8w' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "weight_ts",
-                last_value(case when "name" = 'dfjwhsaq' then "value_as_number" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "height_value_as_number",
-                last_value(case when "name" = 'dfjwhsaq' then "ts" else null end) over (partition by "pid", "name" order by "ts" rows between unbounded preceding and current row) AS "height_ts"
-              FROM (
-                (
-                  SELECT
-                    'tkvriq8w' AS "name",
-                    "person_id" AS "pid",
-                    "measurement_datetime" AS "ts",
-                    "value_as_number"
-                  FROM "cdm_new_york3"."measurement"
-                  WHERE ("measurement_concept_id" = 3025315.0)
-                )
-                UNION ALL
-                (
-                  SELECT
-                    'dfjwhsaq' AS "name",
-                    "person_id" AS "pid",
-                    "measurement_datetime" AS "ts",
-                    "value_as_number"
-                  FROM "cdm_new_york3"."measurement"
-                  WHERE ("measurement_concept_id" = 3036277.0)
-                )
-              ) "q01"
-            ) "q02"
-          ) "q03"
-        ) "q04"
-      ) "q05"
-      WHERE ("row_id" = "phea_ts_row")
-    ) "q06"
-  ) "q07"
-) "q08"
-WHERE ((("phea_kco_lag1" IS NULL) AND NOT(("pid" IS NULL))) OR "phea_kco_lag1" != "pid" OR (("phea_kco_lag2" IS NULL) AND NOT(("height_in_meters" IS NULL))) OR "phea_kco_lag2" != "height_in_meters" OR (("phea_kco_lag3" IS NULL) AND NOT(("bmi" IS NULL))) OR "phea_kco_lag3" != "bmi")
+ ( + SELECT + 'sh6icwld' AS "name", + "person_id" AS "pid", + "measurement_datetime" AS "ts", + "value_as_number" + FROM "cdm_new_york3"."measurement" + WHERE ("measurement_concept_id" = 3025315.0) + ) + UNION ALL + ( + SELECT + 'fx43o2rt' AS "name", + "person_id" AS "pid", + "measurement_datetime" AS "ts", + "value_as_number" + FROM "cdm_new_york3"."measurement" + WHERE ("measurement_concept_id" = 3036277.0) + ) + ) "q01" + ) "q02" + ) "q03" + ) "q04" + ) "q05" + WHERE ("row_id" = "phea_ts_row") +) "q06"
diff --git a/docs/dic_score.Rmd b/docs/dic_score.Rmd index a2e5ffe..064e683 100644 --- a/docs/dic_score.Rmd +++ b/docs/dic_score.Rmd @@ -13,13 +13,13 @@ opts_chunk$set( collapse = TRUE, comment = "#>" ) -# kury - credenciais.R contains the cred$pg credentials. -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) + +library(credx) # contains cred$pg ``` Here we use [Phea](https://github.com/fabkury/phea) to compute the overt disseminated intravascular coagulation score produced by the International Society for Thrombosis and Hemostasis: -![](C:/Users/Fab/Dropbox/PC/Documents/Estudo/Tecnologia/phea/phea/docs/img/isthcriteria.webp) +![](C:/Users/Fab/Dropbox/PC/Documents/Estudo/Tecnologia/phea/phea/docs/img/isthcriteria.webp){ width=100% } For this vignette, we will assume you have a SQL server at `localhost`, with patient data in OMOP Common Data Model v5.4 format, inside schema `cdm_new_york3`. @@ -36,7 +36,7 @@ suppressPackageStartupMessages(library(dplyr)) # Connect to SQL server. dbcon <- DBI::dbConnect( RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Provide the connection to Phea so we can use the sqlt() and sql0() shorthands. diff --git a/docs/dic_score.html b/docs/dic_score.html index 940a37c..7a8e266 100644 --- a/docs/dic_score.html +++ b/docs/dic_score.html @@ -2272,7 +2272,7 @@

Computing the ISTH disseminated

Here we use Phea to compute the overt disseminated intravascular coagulation score produced by the International Society for Thrombosis and Hemostasis:
-

+

For this vignette, we will assume you have a SQL server at localhost, with patient data in OMOP Common Data Model v5.4 format, inside schema cdm_new_york3.

@@ -2290,7 +2290,7 @@

Setup Phea

# Connect to SQL server. dbcon <- DBI::dbConnect( RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Provide the connection to Phea so we can use the sqlt() and sql0() shorthands. @@ -2375,8 +2375,8 @@

Plot the phenotype result

pull()
phea_plot(dic_score, sample(pids, 1))
 #> Collecting lazy table, done. (turn this message off with `verbose = FALSE`)
-
- +
+

Compute aggregates from a phenotype result

diff --git a/docs/index.Rmd b/docs/index.Rmd index dcda9ff..ada2642 100644 --- a/docs/index.Rmd +++ b/docs/index.Rmd @@ -13,8 +13,7 @@ knitr::opts_chunk$set( comment = "#>" ) -# kury - credenciais.R contains the cred$pg credentials. -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) +library(credx) # contains cred$pg library(phea) suppressPackageStartupMessages(library(dplyr)) # Connect to SQL server. @@ -22,7 +21,7 @@ if(!exists('dbcon')) dbcon <- DBI::dbConnect( RPostgres::Postgres(), host = 'localhost', - port = 7654, + port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) @@ -128,7 +127,7 @@ library(phea) dbcon <- DBI::dbConnect( RPostgres::Postgres(), host = 'localhost', - port = 7654, + port = 8765, dbname = 'fort', user = cred$pg$user, # Credentials not declared in this file password = cred$pg$pass) # Credentials not declared in this file diff --git a/docs/index.html b/docs/index.html index 4550c7b..25737cb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2343,7 +2343,7 @@

How to set up

dbcon <- DBI::dbConnect( RPostgres::Postgres(), host = 'localhost', - port = 7654, + port = 8765, dbname = 'fort', user = cred$pg$user, # Credentials not declared in this file password = cred$pg$pass) # Credentials not declared in this file
diff --git a/docs/stress_test_a.Rmd b/docs/stress_test_a.Rmd index 24a0a35..7c56ece 100644 --- a/docs/stress_test_a.Rmd +++ b/docs/stress_test_a.Rmd @@ -11,7 +11,7 @@ vignette: > library(knitr) options(scipen = 5e5) knitr::opts_chunk$set(collapse = TRUE, comment = "#>") -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) # contains cred$pg +library(credx) # contains cred$pg library(wrap) usn <- function(n, decimals = 0) { @@ -29,7 +29,7 @@ library(dplyr) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/stress_test_a.html b/docs/stress_test_a.html index 302c054..37b4bca 100644 --- a/docs/stress_test_a.html +++ b/docs/stress_test_a.html @@ -2278,7 +2278,7 @@

Stress-testing Phea, test A

# Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/stress_test_a2.Rmd b/docs/stress_test_a2.Rmd index b824ca4..97c5bb6 100644 --- a/docs/stress_test_a2.Rmd +++ b/docs/stress_test_a2.Rmd @@ -29,7 +29,7 @@ library(dplyr) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/stress_test_a2.html b/docs/stress_test_a2.html index f0da19e..56636a6 100644 --- a/docs/stress_test_a2.html +++ b/docs/stress_test_a2.html @@ -2278,7 +2278,7 @@

Stress-testing Phea, test A2

# Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/stress_test_b.Rmd b/docs/stress_test_b.Rmd index 398096e..7ba6154 100644 --- a/docs/stress_test_b.Rmd +++ b/docs/stress_test_b.Rmd @@ -29,7 +29,7 @@ library(dplyr) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, dbname = 'fort', + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Call setup_phea so we can use sqlt() and sql0(). diff --git a/docs/weight-increase.Rmd b/docs/weight-increase.Rmd index cee3284..4cd6098 100644 --- a/docs/weight-increase.Rmd +++ b/docs/weight-increase.Rmd @@ -12,8 +12,8 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -# kury - credenciais.R contains the cred$pg credentials. -source(paste0(Sys.getenv("HOME"), '/Estudo/Tecnologia/R/espinha/credenciais.R')) + +library(credx) # contains cred$pg ``` ```{r setup} library(knitr) @@ -22,7 +22,7 @@ suppressPackageStartupMessages(library(dplyr)) # Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Provide the connection to Phea so we can use the sqlt() and sql0() shorthands. @@ -93,7 +93,7 @@ phen <- calculate_formula( ```{r, include = FALSE} # # Source: SQL [?? x 3] -# # Database: postgres [postgres@localhost:7654/fort] +# # Database: postgres [postgres@localhost:8765/fort] # # Ordered by: desc(uvals) # pid lines uvals # diff --git a/docs/weight-increase.html b/docs/weight-increase.html index 13f8a23..fe37315 100644 --- a/docs/weight-increase.html +++ b/docs/weight-increase.html @@ -2279,7 +2279,7 @@

Calculate increase in body weight

# Connect to SQL server. dbcon <- DBI::dbConnect(RPostgres::Postgres(), - host = 'localhost', port = 7654, + host = 'localhost', port = 8765, dbname = 'fort', user = cred$pg$user, password = cred$pg$pass) # Provide the connection to Phea so we can use the sqlt() and sql0() shorthands.