4
4
// Created Date: 2025-04-18 //
5
5
// Author: Matthew Carroll //
6
6
// ----- //
7
- // Last Modified: 2025-05-12 //
7
+ // Last Modified: 2025-05-19 //
8
8
// Modified By: Matthew Carroll //
9
9
// ----- //
10
10
// Copyright (c) 2025 Syndemics Lab at Boston Medical Center //
16
16
#include < string>
17
17
18
18
// Library Includes
19
+ #include < hepce/data/types.hpp>
19
20
#include < hepce/utils/config.hpp>
20
21
#include < hepce/utils/formatting.hpp>
22
+ #include < hepce/utils/logging.hpp>
21
23
22
24
// Local Includes
23
25
#include " event_internals.hpp"
@@ -43,9 +45,10 @@ class TreatmentBase : public EventBase {
43
45
double toxicity = 1.0 ;
44
46
};
45
47
struct TreatmentProbabilities {
46
- double loss_to_follow_up = 0.0 ;
47
48
double initialization = 0.0 ;
48
49
};
50
+ using ltfu_map_t = std::unordered_map<data::PregnancyState, double >;
51
+ ltfu_map_t _ltfu_probability;
49
52
50
53
TreatmentBase (datamanagement::ModelData &model_data,
51
54
const std::string &log_name = " console" )
@@ -56,8 +59,6 @@ class TreatmentBase : public EventBase {
56
59
SetTreatmentLimit (
57
60
utils::GetIntFromConfig (" treatment.treatment_limit" , model_data));
58
61
59
- _probabilities.loss_to_follow_up = utils::GetDoubleFromConfig (
60
- " treatment.ltfu_probability" , model_data);
61
62
_costs.treatment =
62
63
utils::GetDoubleFromConfig (" treatment.treatment_cost" , model_data);
63
64
_utilities.treatment = utils::GetDoubleFromConfig (
@@ -78,9 +79,6 @@ class TreatmentBase : public EventBase {
78
79
_utilities = u;
79
80
}
80
81
inline void SetTreatmentCosts (const TreatmentCosts &c) { _costs = c; }
81
- inline void SetTreatmentProbabilities (const TreatmentProbabilities &p) {
82
- _probabilities = p;
83
- }
84
82
inline void SetEligibilities (const Eligibilities &e) { _eligibilities = e; }
85
83
86
84
inline bool GetTreatmentLimit () const { return _treatment_limit; }
@@ -105,6 +103,26 @@ class TreatmentBase : public EventBase {
105
103
" eligibility.ineligible_time_former_threshold" , model_data);
106
104
}
107
105
106
+ inline void LoadLostToFollowUpData (datamanagement::ModelData &model_data) {
107
+ std::any storage = ltfu_map_t {};
108
+ try {
109
+ model_data.GetDBSource (" inputs" ).Select (
110
+ LostToFollowUpSQL (), LostToFollowUpCallback, storage);
111
+ } catch (std::exception &e) {
112
+ std::stringstream msg;
113
+ msg << " Error getting " << GetInfectionType ()
114
+ << " Lost To Follow Up Data: " << e.what ();
115
+ hepce::utils::LogError (GetLogName (), msg.str ());
116
+ return ;
117
+ }
118
+ _ltfu_probability = std::any_cast<ltfu_map_t >(storage);
119
+ if (_ltfu_probability.empty ()) {
120
+ std::stringstream s;
121
+ s << GetInfectionType () << " Linking Data is Empty..." ;
122
+ hepce::utils::LogWarning (GetLogName (), s.str ());
123
+ }
124
+ }
125
+
108
126
// / @brief
109
127
// / @return
110
128
virtual data::InfectionType GetInfectionType () const = 0;
@@ -126,7 +144,9 @@ class TreatmentBase : public EventBase {
126
144
// follow up
127
145
if (!person.GetTreatmentDetails (GetInfectionType ())
128
146
.initiated_treatment &&
129
- (sampler.GetDecision ({_probabilities.loss_to_follow_up }) == 0 )) {
147
+ (sampler.GetDecision ({_ltfu_probability[person.GetPregnancyDetails ()
148
+ .pregnancy_state ]}) ==
149
+ 0 )) {
130
150
QuitEngagement (person);
131
151
return true ;
132
152
}
@@ -172,13 +192,25 @@ class TreatmentBase : public EventBase {
172
192
: false ;
173
193
}
174
194
195
+ static void LostToFollowUpCallback (std::any &storage,
196
+ const SQLite::Statement &stmt) {
197
+ ltfu_map_t *temp = std::any_cast<ltfu_map_t >(&storage);
198
+ data::PregnancyState state =
199
+ static_cast <data::PregnancyState>(stmt.getColumn (0 ).getInt ());
200
+ (*temp)[state] = stmt.getColumn (1 ).getDouble ();
201
+ }
202
+
175
203
private:
176
204
int _treatment_limit = 0 ;
177
205
TreatmentUtilities _utilities;
178
206
TreatmentCosts _costs;
179
207
TreatmentProbabilities _probabilities;
180
208
Eligibilities _eligibilities;
181
209
210
+ inline const std::string LostToFollowUpSQL () const {
211
+ return " SELECT pregnancy_state, probability FROM lost_to_follow_up;" ;
212
+ }
213
+
182
214
// / @brief
183
215
// / @param
184
216
// / @return
0 commit comments