From 17a9b23029d493ea2adccb3dc30e1877b7d36e91 Mon Sep 17 00:00:00 2001 From: Matthew Carroll <28577806+MJC598@users.noreply.github.com> Date: Wed, 12 Nov 2025 11:34:43 -0500 Subject: [PATCH] fixing the population table run --- extras/examples/inputs.db.sql | 30 +++++++++++++++++++----------- include/hepce/data/types.hpp | 14 +++++++------- src/model/simulation.cpp | 4 ++-- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/extras/examples/inputs.db.sql b/extras/examples/inputs.db.sql index b7755b0f..4b0c5cd8 100644 --- a/extras/examples/inputs.db.sql +++ b/extras/examples/inputs.db.sql @@ -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, @@ -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, @@ -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" ( @@ -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, @@ -192,7 +200,7 @@ 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" ( @@ -200,8 +208,8 @@ CREATE TABLE "fibrosis_diagnosis_states" ( "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") @@ -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"; diff --git a/include/hepce/data/types.hpp b/include/hepce/data/types.hpp index fc0b6ba1..763c865f 100644 --- a/include/hepce/data/types.hpp +++ b/include/hepce/data/types.hpp @@ -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 // @@ -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 = @@ -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,"; @@ -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," @@ -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_" diff --git a/src/model/simulation.cpp b/src/model/simulation.cpp index f72ea44f..dde792f7 100644 --- a/src/model/simulation.cpp +++ b/src/model/simulation.cpp @@ -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 // @@ -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) << ";";