Skip to content

Commit 6a860d7

Browse files
authored
Population Schema (#148)
* Adding in the population, death reason, and linking tables to the example schema * Addressing PR comments * Addressing other PR comment * lmao love how I literally created the descrepency you were asking about
1 parent 750f6de commit 6a860d7

File tree

1 file changed

+117
-9
lines changed

1 file changed

+117
-9
lines changed

extras/examples/inputs.db.sql

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,121 @@
1-
/*
2-
* Filename: /home/matt/Repos/hep-ce/extras/examples/inputs.db.sql
3-
* Path: /home/matt/Repos/hep-ce/extras/examples
4-
* Created Date: Thursday, June 12th 2025, 2:53:18 pm
5-
* Author: Matthew Carroll
6-
*
7-
* Copyright (c) 2025 Syndemics Lab
8-
*/
9-
101
BEGIN TRANSACTION;
2+
DROP TABLE IF EXISTS "population";
3+
CREATE TABLE "population" (
4+
"id" INTEGER NOT NULL UNIQUE,
5+
"sex" INTEGER NOT NULL DEFAULT 0, -- male
6+
"age" INTEGER NOT NULL DEFAULT 0, -- in months
7+
"is_alive" INTEGER NOT NULL DEFAULT 1 CHECK (is_alive IN (0, 1)), -- default alive
8+
"boomer_classification" INTEGER NOT NULL DEFAULT 0 CHECK (boomer_classification IN (0, 1)), -- default not boomer
9+
"death_reason" INTEGER NOT NULL DEFAULT -1, -- not dead
10+
"drug_behavior" INTEGER NOT NULL DEFAULT 0, -- never used
11+
"time_last_active_drug_use" INTEGER NOT NULL DEFAULT 0,
12+
"hcv" INTEGER NOT NULL DEFAULT 0, -- no hcv
13+
"fibrosis_state" INTEGER NOT NULL DEFAULT -1, -- no fibrosis
14+
"is_genotype_three" INTEGER NOT NULL DEFAULT 0 CHECK (is_genotype_three IN (0, 1)), -- not genotype 3
15+
"seropositive" INTEGER NOT NULL DEFAULT 0 CHECK (seropositive IN (0, 1)), -- not seropositive
16+
"time_hcv_changed" INTEGER NOT NULL DEFAULT -1,
17+
"time_fibrosis_state_changed" INTEGER NOT NULL DEFAULT -1,
18+
"times_hcv_infected" INTEGER NOT NULL DEFAULT 0,
19+
"times_acute_cleared" INTEGER NOT NULL DEFAULT 0,
20+
"svrs" INTEGER NOT NULL DEFAULT 0,
21+
"hiv" TEXT DEFAULT NULL, -- make foreign key
22+
"time_hiv_changed" INTEGER DEFAULT NULL,
23+
"low_cd4_months_count" INTEGER DEFAULT NULL,
24+
"hcc_state" TEXT DEFAULT NULL, -- make foreign key
25+
"hcc_diagnosed" INTEGER NOT NULL DEFAULT 0 CHECK (hcc_diagnosed IN (0, 1)),
26+
"currently_overdosing" INTEGER NOT NULL DEFAULT 0 CHECK (currently_overdosing IN (0, 1)), -- not overdosing
27+
"num_overdoses" INTEGER NOT NULL DEFAULT 0,
28+
"moud_state" INTEGER NOT NULL DEFAULT 0, -- not in moud
29+
"time_started_moud" INTEGER NOT NULL DEFAULT -1,
30+
"current_moud_state_concurrent_months" INTEGER NOT NULL DEFAULT 0,
31+
"total_moud_months" INTEGER NOT NULL DEFAULT 0,
32+
"pregnancy_state" INTEGER NOT NULL DEFAULT -1, -- NA
33+
"time_of_pregnancy_change" INTEGER NOT NULL DEFAULT -1,
34+
"pregnancy_count" INTEGER NOT NULL DEFAULT 0,
35+
"num_infants" INTEGER NOT NULL DEFAULT 0,
36+
"num_stillbirths" INTEGER NOT NULL DEFAULT 0,
37+
"num_infant_hcv_exposures" INTEGER NOT NULL DEFAULT 0,
38+
"num_infant_hcv_infections" INTEGER NOT NULL DEFAULT 0,
39+
"num_infant_hcv_tests" INTEGER NOT NULL DEFAULT 0,
40+
"measured_fibrosis_state" INTEGER NOT NULL DEFAULT 4, -- no staging
41+
"had_second_test" INTEGER NOT NULL DEFAULT 0 CHECK (had_second_test IN (0, 1)), -- no second test
42+
"time_of_last_staging" INTEGER NOT NULL DEFAULT -1,
43+
"hcv_link_state" INTEGER NOT NULL DEFAULT 0, -- never linked
44+
"time_of_hcv_link_change" INTEGER NOT NULL DEFAULT -1,
45+
"hcv_link_count" INTEGER NOT NULL DEFAULT 0,
46+
"hiv_link_state" TEXT DEFAULT NULL, -- make foreign key
47+
"time_of_hiv_link_change" INTEGER DEFAULT NULL,
48+
"hiv_link_count" INTEGER DEFAULT NULL,
49+
"time_of_last_hcv_screening" INTEGER NOT NULL DEFAULT -1,
50+
"num_hcv_ab_tests" INTEGER NOT NULL DEFAULT 0,
51+
"num_hcv_rna_tests" INTEGER NOT NULL DEFAULT 0,
52+
"hcv_antibody_positive" INTEGER NOT NULL DEFAULT 0 CHECK (hcv_antibody_positive IN (0, 1)), -- not AB positive
53+
"hcv_identified" INTEGER NOT NULL DEFAULT 0 CHECK (hcv_identified IN (0, 1)), -- not currently identified
54+
"time_hcv_identified" INTEGER NOT NULL DEFAULT -1,
55+
"num_hcv_identifications" INTEGER NOT NULL DEFAULT 0,
56+
"hcv_screening_type" TEXT NOT NULL, -- make foreign key
57+
"num_hcv_false_negatives" INTEGER NOT NULL DEFAULT 0,
58+
"identifications_cleared" INTEGER NOT NULL DEFAULT 0,
59+
"time_of_last_hiv_screening" INTEGER DEFAULT NULL,
60+
"num_hiv_ab_tests" INTEGER DEFAULT NULL,
61+
"num_hiv_rna_tests" TEXT DEFAULT NULL,
62+
"hiv_antibody_positive" TEXT DEFAULT NULL,
63+
"hiv_identified" INTEGER DEFAULT NULL,
64+
"time_hiv_identified" INTEGER DEFAULT NULL,
65+
"num_hiv_identified" INTEGER DEFAULT NULL,
66+
"hiv_screening_type" TEXT DEFAULT NULL,
67+
"initiated_hcv_treatment" INTEGER NOT NULL DEFAULT 0 CHECK (initiated_hcv_treatment IN (0, 1)), -- not started hcv treatment
68+
"time_of_hcv_treatment_initiation" INTEGER NOT NULL DEFAULT -1,
69+
"num_hcv_treatment_starts" INTEGER NOT NULL DEFAULT 0,
70+
"num_hcv_treatment_withdrawals" INTEGER NOT NULL DEFAULT 0,
71+
"num_hcv_treatment_toxic_reactions" INTEGER NOT NULL DEFAULT 0,
72+
"num_completed_hcv_treatments" INTEGER NOT NULL DEFAULT 0,
73+
"num_hcv_salvages" INTEGER NOT NULL DEFAULT 0,
74+
"in_hcv_salvage_treatment" INTEGER NOT NULL DEFAULT 0 CHECK (in_hcv_salvage_treatment IN (0, 1)), -- not in hcv salvage treatment
75+
"initiated_hiv_treatment" INTEGER DEFAULT NULL,
76+
"time_of_hiv_treatment_initiation" INTEGER DEFAULT NULL,
77+
"num_hiv_treatment_starts" INTEGER DEFAULT NULL,
78+
"num_hiv_treatment_withdrawals" INTEGER DEFAULT NULL,
79+
"num_hiv_treatment_toxic_reactions" REAL DEFAULT NULL,
80+
"behavior_utility" REAL NOT NULL DEFAULT 1.0,
81+
"liver_utility" REAL NOT NULL DEFAULT 1.0,
82+
"treatment_utility" REAL NOT NULL DEFAULT 1.0,
83+
"background_utility" REAL NOT NULL DEFAULT 1.0,
84+
"moud_utility" REAL NOT NULL DEFAULT 1.0,
85+
"overdose_utility" REAL NOT NULL DEFAULT 1.0,
86+
"hiv_utility" REAL NOT NULL DEFAULT 1.0,
87+
"min_utility" REAL NOT NULL DEFAULT 0.0,
88+
"mult_utility" REAL NOT NULL DEFAULT 0.0,
89+
"discounted_min_utility" REAL NOT NULL DEFAULT 0.0,
90+
"discounted_mult_utility" REAL NOT NULL DEFAULT 0.0,
91+
"life_span" REAL NOT NULL DEFAULT 0.0,
92+
"discounted_life_span" REAL NOT NULL DEFAULT 0.0,
93+
"cost" REAL NOT NULL,
94+
"discount_cost" REAL NOT NULL DEFAULT 0.0,
95+
PRIMARY KEY("id"),
96+
FOREIGN KEY("sex") REFERENCES "sex"("id"),
97+
FOREIGN KEY("death_reasons") REFERENCES "death_reasons"("id"),
98+
FOREIGN KEY("drug_behavior") REFERENCES "drug_behaviors"("id"),
99+
FOREIGN KEY("hcv") REFERENCES "hcv_states"("id"),
100+
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_states"("id"),
101+
FOREIGN KEY("moud_state") REFERENCES "moud"("id"),
102+
FOREIGN KEY("pregnancy_state") REFERENCES "pregnancy_states"("id"),
103+
FOREIGN KEY("measured_fibrosis_state") REFERENCES "fibrosis_diagnosis_states"("id"),
104+
FOREIGN KEY("hcv_link_state") REFERENCES "link_states"("id"),
105+
FOREIGN KEY("link_states") REFERENCES "link_states"("id")
106+
);
107+
DROP TABLE IF EXISTS "death_reasons";
108+
CREATE TABLE "death_reasons" (
109+
"id" INTEGER NOT NULL UNIQUE,
110+
"reason" TEXT NOT NULL UNIQUE,
111+
PRIMARY KEY ("id");
112+
);
113+
DROP TABLE IF EXISTS "link_states";
114+
CREATE TABLE "link_states" (
115+
"id" INTEGER NOT NULL UNIQUE,
116+
"state" TEXT NOT NULL UNIQUE,
117+
PRIMARY KEY ("id");
118+
);
11119
DROP TABLE IF EXISTS "antibody_testing";
12120
CREATE TABLE "antibody_testing" (
13121
"age_years" INTEGER NOT NULL,

0 commit comments

Comments
 (0)