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"