Skip to main content

Sample queries

Six worked queries. Adapt and run.

Each one shows the hypothesis, the cohort, the actual code (PostgreSQL/OMOP or R), the runtime envelope on our enclave, and the k-anonymized result we'd let leave the boundary. Use them as templates for your own protocol.

Cohort builder · live preview

● Live · enclave node us-east-2

Mock interactive. The real builder is inside the enclave once you have access. Click filters to see how the cohort size and axis coverage shift in real time.

AND
AND
AND
AND
1,143
Patients · k≥11 ✓
PO · NM · ER
· PV
Axis coverage
11.4 mo
Median follow-up
2.4s
Estimated runtime
Q1
OMOP SQL · 2.1s · k=11 enforced

PHQ-9 trajectory across Neurocognitive brackets in major depressive disorder.

Hypothesis
In adults with newly-diagnosed MDD, baseline Neurocognitive (NM) axis bracket predicts PHQ-9 trajectory at 12 weeks independent of antidepressant class.
Cohort
Adults ≥18 with first MDD diagnosis (ICD-10 F32.x / F33.x) within the platform window, ≥1 PHQ-9 administration within ±30d of dx, ≥1 PHQ-9 at 12 weeks ±14d. n = 612 across all CH primary-care + behavioral surfaces.
Cohort filters
F32.* / F33.* PHQ-9 baseline + 12w NM axis · daily Adults ≥18
Code
-- Cohort: first MDD + paired PHQ-9
WITH mdd AS (
  SELECT person_id, MIN(condition_start_date) AS dx
  FROM omop.condition_occurrence
  WHERE condition_concept_id IN (4252191, 4262111) -- F32, F33
    AND person_age >= 18
  GROUP BY person_id
), phq AS (
  SELECT person_id, observation_date,
         CAST(value_as_string AS int) AS phq9
  FROM omop.observation
  WHERE observation_concept_id = 3022875  -- PHQ-9 total
), paired AS (
  SELECT m.person_id,
         AVG(CASE WHEN ABS(p.observation_date - m.dx) <= 30 THEN phq9 END) AS phq_0,
         AVG(CASE WHEN ABS(p.observation_date - (m.dx + 84)) <= 14 THEN phq9 END) AS phq_12
  FROM mdd m JOIN phq p USING (person_id)
  GROUP BY m.person_id
), nm AS (
  -- CH extension: 8-axis daily telemetry, baseline window
  SELECT person_id, AVG(score) AS nm_avg
  FROM ch.axis_daily a JOIN mdd m USING (person_id)
  WHERE axis = 'NM' AND date BETWEEN m.dx - 30 AND m.dx
  GROUP BY person_id
)
SELECT ch_bracket(nm_avg) AS nm_bracket,
       AVG(phq_0 - phq_12)        AS phq_drop,
       k_anon(person_id, 11)  AS n
FROM paired JOIN nm USING (person_id)
WHERE phq_0 IS NOT NULL AND phq_12 IS NOT NULL
GROUP BY nm_bracket;
Result (mock)
NM bracket (baseline)Mean PHQ-9 drop, 0→12wn
Excellent (8)−7.461
Very good (7)−6.898
Good (6)−5.9132
Average (5)−4.7148
Below avg (4)−3.2102
Poor (3)−1.971
Ethical guardrails
k-anonymity ≥ 11 enforced at output. PHQ-9 individual scores never leave the enclave. Antidepressant class as covariate available; medication-naive patients counted separately.
Q2
OMOP SQL + CH axis-extension · 2.6s · k=11 enforced

Does Purposeful Vitality predict A1c reduction in adults with type-2 diabetes, independent of BMI?

Hypothesis
Purposeful Vitality (PV) at the time of T2DM diagnosis predicts A1c at 6 months independently of BMI, age, sex, and medication class. Effect persists after adjustment.
Cohort
Adults ≥18 with new T2DM (ICD-10 E11.*), paired A1c at baseline ±30d and 6 months ±30d, daily PV measurements over the dx → +180d window. n = 1,143.
Cohort filters
E11.* A1c paired PV daily ≥30 readings BMI baseline available
Code
WITH cohort AS (
  SELECT person_id, MIN(condition_start_date) AS dx
  FROM omop.condition_occurrence
  WHERE condition_concept_id = 201826 -- T2DM
    AND person_age >= 18
  GROUP BY person_id
), a1c AS (
  SELECT c.person_id,
    AVG(CASE WHEN measurement_date BETWEEN c.dx - 30 AND c.dx + 30
            THEN value_as_number END) AS a1c_0,
    AVG(CASE WHEN measurement_date BETWEEN c.dx + 150 AND c.dx + 210
            THEN value_as_number END) AS a1c_6
  FROM cohort c JOIN omop.measurement m USING (person_id)
  WHERE measurement_concept_id = 3004410 -- A1c
  GROUP BY c.person_id
), pv AS (
  SELECT person_id, AVG(score) AS pv_avg, COUNT(*) AS n_days
  FROM ch.axis_daily a JOIN cohort c USING (person_id)
  WHERE a.axis = 'PV'
    AND a.date BETWEEN c.dx AND c.dx + 180
  GROUP BY person_id
), bmi AS (
  SELECT person_id, AVG(value_as_number) AS bmi_0
  FROM omop.measurement m JOIN cohort c USING (person_id)
  WHERE measurement_concept_id = 3038553
    AND measurement_date BETWEEN c.dx - 90 AND c.dx
  GROUP BY person_id
)
SELECT quartile(pv_avg) AS pv_q,
       AVG(a1c_0 - a1c_6)         AS a1c_drop,
       AVG(bmi_0)                 AS mean_bmi,
       k_anon(person_id, 11)  AS n
FROM a1c JOIN pv USING (person_id) JOIN bmi USING (person_id)
WHERE a1c_0 IS NOT NULL AND a1c_6 IS NOT NULL AND n_days >= 30
GROUP BY pv_q;
Result (mock)
PV quartileA1c drop, 0→6moMean BMIn
Q4 (highest PV)−1.431.8274
Q3−1.132.1298
Q2−0.732.4301
Q1 (lowest PV)−0.432.6270
Ethical guardrails
Aggregate-only output. Mediation analysis (PV via medication adherence) is a separate query; we'd ask for an IRB-approved analytic plan amendment first.
Q3
R · time-series · 4.8s · k=20 enforced

Wildfire PM2.5 exposure → respiratory + Emotional Resilience axis trajectory.

Hypothesis
In western US ZCTAs experiencing PM2.5 > 35 µg/m³ for ≥7 consecutive days, both pulmonary visit rates and a measurable drop in ER axis follow exposure with a 5–10 day lag.
Cohort
CH patients in 5-digit ZCTAs flagged by EPA AirNow during a wildfire-exposure event in the prior 12 mo. Coarsened to 3-digit ZCTA for output. n = 580 with ≥1 day in exposed window.
Cohort filters
EPA PM2.5 ≥ 35 ≥7 consecutive days PO + ER daily 3-digit ZCTA only on output
Code
library(tidyverse); library(survival); library(lubridate)

# Pull from enclave views (k≥20 enforced server-side)
exposure <- tbl(con, "epa_pm25_daily") %>%
  filter(pm25 >= 35) %>%
  collect()

person_zcta <- tbl(con, "ch.person_zcta3") %>% collect()

axis_er <- tbl(con, "ch.axis_daily") %>%
  filter(axis == "ER") %>%
  collect()

resp_visits <- tbl(con, "omop.condition_occurrence") %>%
  filter(condition_concept_id %in% c(4112352, 261061)) %>% # asthma exac, COPD exac
  collect()

# Lag-aligned event-study, 0..14 day window post-exposure
joined <- join_lagged(exposure, axis_er, resp_visits, lag = 0:14)
summarise_by_lag(joined, k = 20) %>% plot_event_study()
Result (mock)
Peak respiratory-visit rate ratio at lag day 6 (RR 2.8 vs baseline). ER axis drops by 0.8 bracket-points by lag day 9, recovers by day 18. Effect size larger in patients with prior asthma diagnosis.
Ethical guardrails
3-digit ZCTA enforced at output. Patients in exposed window get a passive notification ("a study is using your area's environmental data"); they may opt out without affecting any other consent.
Q4
OMOP + survival · 3.4s · k=11 enforced

SSRI response stratified by baseline Spiritual Coherence.

Hypothesis
Among adults initiated on an SSRI for MDD, time-to-PHQ-9 response (≥50% drop) varies by baseline Spiritual Coherence (SC) bracket independent of SSRI choice and dose.
Cohort
n = 412, adults with new MDD + first SSRI Rx, ≥1 PHQ-9 baseline, ≥3 PHQ-9 follow-ups within 24 weeks. SC scored daily during the 30 days pre-Rx.
Cohort filters
F32.* / F33.* SSRI initiator (RxNorm ATC class N06AB) PHQ-9 ≥4 readings SC baseline
Code
-- Construct survival object: response = ≥50% PHQ-9 drop
WITH rx AS (
  SELECT person_id, MIN(drug_exposure_start_date) AS rx_start
  FROM omop.drug_exposure d
  JOIN omop.concept_ancestor a ON d.drug_concept_id = a.descendant_concept_id
  WHERE a.ancestor_concept_id = 21601798  -- ATC N06AB
  GROUP BY person_id
), phq AS (...),
sc AS (
  SELECT person_id, AVG(score) AS sc_avg
  FROM ch.axis_daily a JOIN rx USING (person_id)
  WHERE axis = 'SC' AND date BETWEEN rx_start - 30 AND rx_start
  GROUP BY person_id
)
-- Survival analysis run in R via survival::coxph
SELECT person_id, t_to_response, response, ch_bracket(sc_avg) AS sc_bracket
FROM built_cohort;
# R fit <- coxph(Surv(t_to_response, response) ~ sc_bracket + age + sex + ssri_class + dose, data = cohort) summary(fit)
Result (mock)
Adjusted HR for response by SC quartile (Q1 reference): Q2 1.18, Q3 1.42, Q4 1.61 (95% CI excludes 1 for Q3, Q4). Effect persists after adjustment for adherence (PDC). Median time-to-response 5.8 weeks across cohort.
Ethical guardrails
SC is a sensitive axis; we publish only quartile aggregates, never individual scores. The SC instrument is anonymized about specific tradition or faith.
Q5
CH-extension SQL · 1.8s · k=11 enforced

GLP-1 agonist initiators — weight loss × axis-lift envelope across 8 axes.

Hypothesis
Among GLP-1 initiators, the magnitude of axis-lift over 6 months varies by which axis. PO and PV lifts dominate; relational and spiritual axes show smaller mean lifts but high inter-individual variance.
Cohort
Adults ≥18 initiating semaglutide, tirzepatide, or liraglutide for either T2DM or BMI ≥30. Continuous axis telemetry rx_start − 30 → rx_start + 180. n = 410.
Cohort filters
RxNorm: GLP-1 agonist class No prior GLP-1 exposure All 8 axes daily
Code
-- Compute per-axis baseline + 6mo, output the lift envelope
WITH rx AS (
  SELECT person_id, MIN(drug_exposure_start_date) AS rx0
  FROM omop.drug_exposure d
  JOIN omop.concept_ancestor a ON d.drug_concept_id = a.descendant_concept_id
  WHERE a.ancestor_concept_id IN (42873638, 793143, 1551860) -- sema, tirz, lira
  GROUP BY person_id
), bands AS (
  SELECT r.person_id, a.axis,
         AVG(CASE WHEN a.date BETWEEN r.rx0 - 30 AND r.rx0 THEN a.score END) AS base,
         AVG(CASE WHEN a.date BETWEEN r.rx0 + 150 AND r.rx0 + 210 THEN a.score END) AS mo6
  FROM ch.axis_daily a JOIN rx r USING (person_id)
  GROUP BY r.person_id, a.axis
)
SELECT axis, AVG(mo6 - base) AS mean_lift,
       stddev(mo6 - base) AS sd_lift,
       k_anon(person_id, 11) AS n
FROM bands
WHERE base IS NOT NULL AND mo6 IS NOT NULL
GROUP BY axis
ORDER BY mean_lift DESC;
Result (mock)
AxisMean lift, 0→6moSDn
PO · Physiological+1.40.9410
PV · Purposeful Vitality+0.91.2408
ER · Emotional Resilience+0.61.4405
NM · Neurocognitive+0.31.1404
RS · Relational & Social+0.21.6402
SC · Spiritual Coherence+0.11.5399
ES · Environmental+0.10.8410
TA · Technological Alignment−0.11.3410
Ethical guardrails
No individual axis trajectories leave the enclave. Patients receive an aggregated newsletter on findings if they consented to study-feedback at intake.
Q6
graph + cohort · 5.2s · k=11 enforced · pediatric guard

Pediatric ADHD stimulant response × Relational & Social network density.

Hypothesis
In pediatric ADHD (ages 6–17) initiated on a stimulant, response (Vanderbilt or NICHQ-VS-S response) at 8 weeks correlates with baseline RS network density (number of supportive household + school relations).
Cohort
Pediatric patients with ADHD dx, first stimulant Rx, paired Vanderbilt baseline + 8w. n = 268. RS network captured from CH-Family + school-affiliation graph the family opted into.
Cohort filters
F90.* Stimulant ATC N06BA Vanderbilt paired RS graph (opt-in) Pediatric guardrail
Code
-- Network density: count of distinct supportive ties in baseline household + school graph
WITH ties AS (
  SELECT person_id,
         COUNT(DISTINCT alter_id) FILTER (WHERE tie_type IN ('household', 'school')
                                       AND support_score >= 3) AS support_n
  FROM ch.rs_graph_edge_baseline
  GROUP BY person_id
), response AS (
  SELECT person_id,
         (vanderbilt_0 - vanderbilt_8w) / vanderbilt_0::float AS rel_drop
  FROM built_cohort
)
SELECT ntile(3) OVER (ORDER BY support_n) AS rs_tier,
       AVG(rel_drop) AS mean_response,
       k_anon(person_id, 11) AS n
FROM ties JOIN response USING (person_id)
GROUP BY rs_tier;
Result (mock)
RS network tierMean Vanderbilt responsen
High (8+ supportive ties)−54%82
Mid−42%98
Low (≤3 ties)−31%88
Ethical guardrails
Pediatric guardrail. All pediatric queries require IRB approval with explicit pediatric protocol. Only minor's parent/guardian-consented data appears in the graph. School affiliation is opt-in by guardian; school name never leaves the enclave.

Next steps

Adapt one of these to your protocol.

Each query is downloadable as an OMOP-compatible SQL file or an R notebook on apply. We'll set up a sandbox in 48 hours with synthetic data identical to schema.