Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions extras/examples/inputs.db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CREATE TABLE "population" (
"hcv_link_state" INTEGER NOT NULL DEFAULT 0, -- never linked
"time_of_hcv_link_change" INTEGER NOT NULL DEFAULT -1,
"hcv_link_count" INTEGER NOT NULL DEFAULT 0,
"hiv_link_state" TEXT DEFAULT NULL, -- make foreign key
"hiv_link_state" INTEGER DEFAULT NULL,
"time_of_hiv_link_change" INTEGER DEFAULT NULL,
"hiv_link_count" INTEGER DEFAULT NULL,
"time_of_last_hcv_screening" INTEGER NOT NULL DEFAULT -1,
Expand All @@ -53,17 +53,17 @@ CREATE TABLE "population" (
"hcv_identified" INTEGER NOT NULL DEFAULT 0 CHECK (hcv_identified IN (0, 1)), -- not currently identified
"time_hcv_identified" INTEGER NOT NULL DEFAULT -1,
"num_hcv_identifications" INTEGER NOT NULL DEFAULT 0,
"hcv_screening_type" TEXT NOT NULL, -- make foreign key
"hcv_screening_type" INTEGER NOT NULL NOT NULL DEFAULT -1,
"num_hcv_false_negatives" INTEGER NOT NULL DEFAULT 0,
"identifications_cleared" INTEGER NOT NULL DEFAULT 0,
"time_of_last_hiv_screening" INTEGER DEFAULT NULL,
"num_hiv_ab_tests" INTEGER DEFAULT NULL,
"num_hiv_rna_tests" TEXT DEFAULT NULL,
"hiv_antibody_positive" TEXT DEFAULT NULL,
"num_hiv_rna_tests" INTEGER DEFAULT NULL,
"hiv_antibody_positive" INTEGER DEFAULT NULL,
"hiv_identified" INTEGER DEFAULT NULL,
"time_hiv_identified" INTEGER DEFAULT NULL,
"num_hiv_identified" INTEGER DEFAULT NULL,
"hiv_screening_type" TEXT DEFAULT NULL,
"hiv_screening_type" INTEGER DEFAULT NULL,
"initiated_hcv_treatment" INTEGER NOT NULL DEFAULT 0 CHECK (initiated_hcv_treatment IN (0, 1)), -- not started hcv treatment
"time_of_hcv_treatment_initiation" INTEGER NOT NULL DEFAULT -1,
"num_hcv_treatment_starts" INTEGER NOT NULL DEFAULT 0,
Expand Down Expand Up @@ -97,12 +97,14 @@ CREATE TABLE "population" (
FOREIGN KEY("death_reasons") REFERENCES "death_reasons"("id"),
FOREIGN KEY("drug_behavior") REFERENCES "drug_behaviors"("id"),
FOREIGN KEY("hcv") REFERENCES "hcv_states"("id"),
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_states"("id"),
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_diagnosis_states"("id"),
FOREIGN KEY("moud_state") REFERENCES "moud"("id"),
FOREIGN KEY("pregnancy_state") REFERENCES "pregnancy_states"("id"),
FOREIGN KEY("measured_fibrosis_state") REFERENCES "fibrosis_diagnosis_states"("id"),
FOREIGN KEY("hcv_link_state") REFERENCES "link_states"("id"),
FOREIGN KEY("link_states") REFERENCES "link_states"("id")
FOREIGN KEY ("hcv_screening_type") REFERENCES "screening_states"("id"),
FOREIGN KEY("hiv_link_states") REFERENCES "link_states"("id"),
FOREIGN KEY ("hiv_screening_type") REFERENCES "screening_states"("id")
);
DROP TABLE IF EXISTS "death_reasons";
CREATE TABLE "death_reasons" (
Expand All @@ -116,6 +118,12 @@ CREATE TABLE "link_states" (
"state" TEXT NOT NULL UNIQUE,
PRIMARY KEY ("id");
);
DROP TABLE IF EXISTS "screening_states";
CREATE TABLE "screening_states" (
"id" INTEGER NOT NULL UNIQUE,
"state" TEXT NOT NULL UNIQUE,
PRIMARY KEY ("id");
);
DROP TABLE IF EXISTS "antibody_testing";
CREATE TABLE "antibody_testing" (
"age_years" INTEGER NOT NULL,
Expand Down Expand Up @@ -192,16 +200,16 @@ CREATE TABLE "fibrosis" (
"fib4" REAL NOT NULL,
PRIMARY KEY("fibrosis_state","diagnosed_fibrosis"),
FOREIGN KEY("diagnosed_fibrosis") REFERENCES "fibrosis_diagnosis_states"("id"),
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_states"("id")
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_real_states"("id")
);
DROP TABLE IF EXISTS "fibrosis_diagnosis_states";
CREATE TABLE "fibrosis_diagnosis_states" (
"id" INTEGER NOT NULL UNIQUE,
"state" TEXT NOT NULL,
PRIMARY KEY("id")
);
DROP TABLE IF EXISTS "fibrosis_states";
CREATE TABLE "fibrosis_states" (
DROP TABLE IF EXISTS "fibrosis_real_states";
CREATE TABLE "fibrosis_real_states" (
"id" INTEGER NOT NULL UNIQUE,
"state" TEXT NOT NULL,
PRIMARY KEY("id")
Expand All @@ -213,7 +221,7 @@ CREATE TABLE "hcv_impacts" (
"cost" REAL NOT NULL DEFAULT 0.0,
"utility" REAL NOT NULL,
PRIMARY KEY("hcv_status","fibrosis_state"),
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_states"("id"),
FOREIGN KEY("fibrosis_state") REFERENCES "fibrosis_real_states"("id"),
FOREIGN KEY("hcv_status") REFERENCES "bool_lookup"("id")
);
DROP TABLE IF EXISTS "hcv_states";
Expand Down
14 changes: 7 additions & 7 deletions include/hepce/data/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2025-04-17 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2025-10-14 //
// Last Modified: 2025-11-12 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2025 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -33,10 +33,10 @@ POPULATION_HEADERS(bool pregnancy = false, bool hcc = false,
"acute_cleared,svrs,";
// HIVDetails
std::string hiv_details =
hiv ? "hiv,time_hiv_changed,low_cd4_months_count," : "none,-1,0,";
hiv ? "hiv,time_hiv_changed,low_cd4_months_count," : "NULL,-1,0,";
headers << hiv_details;
// HCCDetails
std::string hcc_details = hcc ? "hcc_state,hcc_diagnosed," : "none,false,";
std::string hcc_details = hcc ? "hcc_state,hcc_diagnosed," : "NULL,false,";
headers << hcc_details;
// overdose characteristics
std::string overdoses =
Expand All @@ -46,14 +46,14 @@ POPULATION_HEADERS(bool pregnancy = false, bool hcc = false,
std::string moud_details =
moud ? "moud_state,time_started_moud,current_moud_state_concurrent_"
"months,total_moud_months,"
: "none,-1,0,0,";
: "0,-1,0,0,";
headers << moud_details;
// PregnancyDetails
std::string pregnancy_details =
pregnancy ? "pregnancy_state,time_of_pregnancy_change,pregnancy_count,"
"num_infants,num_stillbirths,num_infant_hcv_exposures,num_"
"infant_hcv_infections,num_infant_hcv_tests,"
: "na,-1,0,0,0,0,0,0,";
: "-1,-1,0,0,0,0,0,0,";
headers << pregnancy_details;
// StagingDetails
headers << "measured_fibrosis_state,had_second_test,time_of_last_staging,";
Expand All @@ -62,7 +62,7 @@ POPULATION_HEADERS(bool pregnancy = false, bool hcc = false,
if (hiv) {
headers << "hiv_link_state,time_of_hiv_link_change,hiv_link_count,";
} else {
headers << "never,-1,0,";
headers << "0,-1,0,";
}
// ScreeningDetails
headers << "time_of_last_hcv_screening,num_hcv_ab_tests,num_hcv_rna_tests,"
Expand All @@ -75,7 +75,7 @@ POPULATION_HEADERS(bool pregnancy = false, bool hcc = false,
"hiv_antibody_positive,hiv_identified,time_hiv_identified,num_"
"hiv_identified,hiv_screening_type,";
} else {
headers << "-1,0,0,false,false,-1,0,na";
headers << "-1,0,0,false,false,-1,0,NULL,";
}
// TreatmentDetails
headers << "initiated_hcv_treatment,time_of_hcv_treatment_initiation,num_"
Expand Down
4 changes: 2 additions & 2 deletions src/model/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2025-04-22 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2025-10-31 //
// Last Modified: 2025-11-12 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2025 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -138,7 +138,7 @@ HepceImpl::ReadPopPopulation(const int population_size,
// TODO: Add string santization (i.e. verify no extra special characters/numbers/phrases/etc.)
query << "SELECT "
<< data::POPULATION_HEADERS(pregnancy, hcc, overdose, hiv, moud);
query << "FROM population ";
query << " FROM population ";
query << "ORDER BY id ";
query << "LIMIT " << std::to_string(population_size) << ";";

Expand Down
Loading