-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEndMonthUpdater.cpp
More file actions
385 lines (356 loc) · 19.3 KB
/
Copy pathEndMonthUpdater.cpp
File metadata and controls
385 lines (356 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#include "include.h"
/** \brief Constructor takes in the patient object and determines if updates can occur */
EndMonthUpdater::EndMonthUpdater(Patient *patient) : StateUpdater(patient) {
}
/** \brief Destructor is empty, no cleanup required */
EndMonthUpdater::~EndMonthUpdater(void) {
}
/** \brief performInitialUpdates perform all of the state and statistics updates upon patient creation */
void EndMonthUpdater::performInitialUpdates() {
/** Call the parent function to perform general updates and initialization */
StateUpdater::performInitialUpdates();
} /* end performInitialUpdates */
/** \brief performMonthlyUpdates perform all of the state and statistics updates for a simulated month */
void EndMonthUpdater::performMonthlyUpdates() {
/** Uses a half month for applicable costs and survival stats in the month of death */
double percentOfMonth = 1.0;
if (!patient->isAlive()) {
percentOfMonth = 0.5;
}
SimContext::PEDS_COST_AGE pedsCostAgeCat = patient->getPedsState()->ageCategoryPedsCost;
int costAgeCat = patient->getGeneralState()->ageCategoryCost;
SimContext::GENDER_TYPE gender = patient->getGeneralState()->gender;
/** Increment the monthly patient costs and statistics for routine care */
if(pedsCostAgeCat == SimContext::PEDS_COST_AGE_ADULT){
double multiplier = simContext->getLTFUInputs()->propGeneralMedicineCost[patient->getMonitoringState()->careState];
incrementCostsGeneralMedicine(simContext->getCostInputs()->generalMedicineCost[gender][costAgeCat], percentOfMonth, multiplier);
}
if (patient->getDiseaseState()->infectedHIVState == SimContext::HIV_INF_NEG) {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
if (simContext->getCostInputs()->routineCareCostHIVNegativeStopAge == SimContext::NOT_APPL ||
patient->getGeneralState()->ageMonths < simContext->getCostInputs()->routineCareCostHIVNegativeStopAge)
incrementCostsMisc(simContext->getCostInputs()->routineCareCostHIVNegative[gender][costAgeCat], percentOfMonth);
}
else{
incrementCostsMisc(simContext->getPedsCostInputs()->routineCareCostHIVNegative[gender][pedsCostAgeCat], percentOfMonth);
}
}
else if (!patient->getMonitoringState()->isDetectedHIVPositive) {
//add costs from two different areas
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
incrementCostsMisc(simContext->getHIVTestInputs()->monthCostHIVUndetected[cd4Strata], percentOfMonth);
if (simContext->getCostInputs()->routineCareCostHIVPositiveUndetectedStopAge == SimContext::NOT_APPL ||
patient->getGeneralState()->ageMonths < simContext->getCostInputs()->routineCareCostHIVPositiveUndetectedStopAge)
incrementCostsMisc(simContext->getCostInputs()->routineCareCostHIVPositiveUndetected[gender][costAgeCat], percentOfMonth);
}
else {
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
SimContext::GENDER_TYPE gender = patient->getGeneralState()->gender;
SimContext::ART_STATES artState = (patient->getARTState()->isOnART) ? SimContext::ART_ON_STATE : SimContext::ART_OFF_STATE;
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsRoutineCare(simContext->getCostInputs()->routineCareCostHIVPositive[artState][cd4Strata][gender][costAgeCat], percentOfMonth);
}
else{
incrementCostsRoutineCare(simContext->getPedsCostInputs()->routineCareCostHIVPositive[artState][cd4Strata][gender][pedsCostAgeCat], percentOfMonth);
}
}
/**Increment costs for those on PrEP */
if(simContext->getHIVTestInputs()->enableHIVTesting && simContext->getHIVTestInputs()->enablePrEP && patient->getMonitoringState()->everPrEP){
if(patient->getMonitoringState()->hasPrEP){
SimContext::HIV_BEHAV risk = patient->getMonitoringState()->isHighRiskForHIV?SimContext::HIV_BEHAV_HI:SimContext::HIV_BEHAV_LO;
// For now, we are incrementing the full cost in the month of death - may revisit later
incrementCostsPrEP(simContext->getHIVTestInputs()->costPrEPMonthly[risk], 1.0);
}
// For those who have ever had PrEP and died this month, accumulate their final PrEP costs by PrEP state
if(!patient->isAlive())
finalizePrEPCostsByState();
}
/** Increment costs for ART treatments */
if (patient->getARTState()->isOnART) {
int artLineNum = patient->getARTState()->currRegimenNum;
double cost = 0.0;
if (patient->getGeneralState()->isAdolescent){
int ayaAgeCat = getAgeCategoryAdolescent();
cost = simContext->getAdolescentARTInputs(artLineNum)->costMonthly[ayaAgeCat];
}
else if (patient->getPedsState()->ageCategoryPediatrics == SimContext::PEDS_AGE_ADULT) {
cost = simContext->getARTInputs(artLineNum)->costMonthly;
}
else{
cost = simContext->getPedsARTInputs(artLineNum)->costMonthly[patient->getPedsState()->ageCategoryPedsARTCost];
}
//always incur full cost on month of regimen start
if (patient->getARTState()->monthOfCurrRegimenStart != patient->getGeneralState()->monthNum){
/** - Adjust cost for non-responders by the proportion of monthly costs they incur */
double responseFactor = patient->getARTState()->responseFactorCurrRegimen[SimContext::HET_OUTCOME_COST];
double upperValue = cost;
double lowerValue = cost * patient->getARTState()->propMthCostNonResponders;
cost = lowerValue+responseFactor*(upperValue-lowerValue);
}
incrementCostsARTMonthly(artLineNum, cost);
}
/** Increment costs for OI prophylaxis treatments */
if (patient->getProphState()->currTotalNumProphsOn > 0) {
for (int i = 0; i < SimContext::OI_NUM; i++) {
if (patient->getProphState()->isOnProph[i]) {
int prophNum = patient->getProphState()->currProphNum[i];
SimContext::PROPH_TYPE prophType = patient->getProphState()->currProphType[i];
double cost;
if(patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
cost=simContext->getProphInputs(prophType,i,prophNum)->costMonthly;
}
else{
cost=simContext->getPedsProphInputs(prophType,i,prophNum)->costMonthly;
}
incrementCostsProph((SimContext::OI_TYPE) i, prophNum, cost);
}
}
}
/** Increment costs for TB proph and treatments */
if (patient->getTBState()->isOnProph) {
int prophNum = patient->getTBState()->currProphNum;
double cost = simContext->getTBInputs()->tbProphInputs[prophNum].costMonthly;
incrementCostsTBProph(prophNum, cost);
}
//Due to the timing of treatment start within the simulation month, the first TB treatment stage is calculated differently depending on whether it is at the end of the month (LTFU and costs: threshold month excluded) or the beginning of the month (toxicity: threshold month included)
if (patient->getTBState()->isOnTreatment) {
int treatNum = patient->getTBState()->currTreatmentNum;
int stage = 1;
if((patient->getGeneralState()->monthNum - patient->getTBState()->monthOfTreatmentStart + patient->getTBState()->previousTreatmentDuration) < simContext->getTBInputs()->TBTreatments[treatNum].stage1Duration)
stage = 0;
double cost = simContext->getTBInputs()->TBTreatments[treatNum].costMonthly[stage];
incrementCostsTBTreatment(cost, treatNum);
}
if (patient->getTBState()->isOnEmpiricTreatment) {
int treatNum = patient->getTBState()->currEmpiricTreatmentNum;
int stage = 1;
if((patient->getGeneralState()->monthNum - patient->getTBState()->monthOfEmpiricTreatmentStart + patient->getTBState()->previousEmpiricTreatmentDuration) < simContext->getTBInputs()->TBTreatments[treatNum].stage1Duration)
stage = 0;
double cost = simContext->getTBInputs()->TBTreatments[treatNum].costMonthly[stage];
incrementCostsTBTreatment(cost, treatNum);
}
/** Increment costs of mortality in the month of death */
if (!patient->isAlive()) {
SimContext::DTH_CAUSES causeOfDeath = patient->getDiseaseState()->causeOfDeath;
SimContext::ART_STATES artState = (patient->getARTState()->isOnART) ? SimContext::ART_ON_STATE : SimContext::ART_OFF_STATE;
if (causeOfDeath < SimContext::OI_NUM) {
if (patient->getMonitoringState()->clinicVisitType != SimContext::CLINIC_INITIAL) {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostTreated[costAgeCat][artState][causeOfDeath], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostTreated[pedsCostAgeCat][artState][causeOfDeath], 1.0);
}
}
else {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostUntreated[costAgeCat][artState][causeOfDeath], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostUntreated[pedsCostAgeCat][artState][causeOfDeath], 1.0);
}
}
}
else if(causeOfDeath == SimContext::DTH_ACTIVE_TB){
if(pedsCostAgeCat == SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getTBInputs()->costTBDeath, 1.0);
}
else{
incrementCostsDeath(simContext->getTBInputs()->costTBDeathPeds[pedsCostAgeCat], 1.0);
}
}
else if (causeOfDeath == SimContext::DTH_HIV) {
if (patient->getMonitoringState()->isDetectedHIVPositive) {
if (patient->getMonitoringState()->clinicVisitType != SimContext::CLINIC_INITIAL) {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostTreated[costAgeCat][artState][SimContext::DTH_HIV], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostTreated[pedsCostAgeCat][artState][SimContext::DTH_HIV], 1.0);
}
}
else {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostUntreated[costAgeCat][artState][SimContext::DTH_HIV], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostUntreated[pedsCostAgeCat][artState][SimContext::DTH_HIV], 1.0);
}
}
}
else {
double cost = simContext->getHIVTestInputs()->HIVDeathCostHIVUndetected;
incrementCostsMisc(cost, 1.0);
}
}
else if (causeOfDeath == SimContext::DTH_BKGD_MORT) {
if (patient->getDiseaseState()->infectedHIVState == SimContext::HIV_INF_NEG) {
double cost = simContext->getHIVTestInputs()->deathCostHIVNegative;
incrementCostsMisc(cost, 1.0);
}
// HIV+ detected
else if (patient->getMonitoringState()->isDetectedHIVPositive) {
if (patient->getMonitoringState()->clinicVisitType != SimContext::CLINIC_INITIAL) {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostTreated[costAgeCat][artState][SimContext::DTH_BKGD_MORT], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostTreated[pedsCostAgeCat][artState][SimContext::DTH_BKGD_MORT], 1.0);
}
}
else {
if(pedsCostAgeCat==SimContext::PEDS_COST_AGE_ADULT){
incrementCostsDeath(simContext->getCostInputs()->deathCostUntreated[costAgeCat][artState][SimContext::DTH_BKGD_MORT], 1.0);
}
else{
incrementCostsDeath(simContext->getPedsCostInputs()->deathCostUntreated[pedsCostAgeCat][artState][SimContext::DTH_BKGD_MORT], 1.0);
}
}
}
// HIV+ undetected
else {
double cost = simContext->getHIVTestInputs()->backgroundMortDeathCostHIVUndetected;
incrementCostsMisc(cost, 1.0);
}
}
else if ((causeOfDeath >= SimContext::DTH_CHRM_1) && (causeOfDeath < SimContext::DTH_CHRM_1 + SimContext::CHRM_NUM)) {
double cost = simContext->getCHRMsInputs()->costDeathCHRMs[causeOfDeath - SimContext::DTH_CHRM_1];
incrementCostsMisc(cost, 1.0);
}
/** - ART toxicity death is incurred in the MortalityUpdater
- Other causes of death incur no additional costs */
}
/** Assess routine care QOL or QOL in the month of death */
if (patient->isAlive()) {
/** If alive, use QOL modifier with either acute OI, undetected HIV, or routine care levels */
if (patient->getDiseaseState()->hasCurrTrueOI) {
SimContext::OI_TYPE oiType = patient->getDiseaseState()->typeCurrTrueOI;
accumulateQOLModifier(simContext->getQOLInputs()->acuteOIQOL[oiType]);
}
else if ((!patient->getMonitoringState()->isDetectedHIVPositive)&& !patient->getDiseaseState()->infectedHIVState==SimContext::HIV_INF_NEG) {
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
accumulateQOLModifier(simContext->getHIVTestInputs()->monthQOLHIVUndetected[cd4Strata]);
}
else if(!patient->getDiseaseState()->infectedHIVState==SimContext::HIV_INF_NEG){
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
double routineCareQOL = simContext->getQOLInputs()->routineCareQOL[cd4Strata][SimContext::HIST_EXT_N];
// if they are within the OI history effect duration, use their OI history to determine the QOL modifier
for (int i = 0; i < SimContext::OI_NUM; i++) {
if ((patient->getGeneralState()->monthNum - patient->getDiseaseState()->lastMonthSevereOI[i]) <= simContext->getQOLInputs()->routineCareQOLSevereOIHistDuration[cd4Strata]){
routineCareQOL = simContext->getQOLInputs()->routineCareQOL[cd4Strata][patient->getDiseaseState()->typeTrueOIHistory];
break;
}
}
accumulateQOLModifier(routineCareQOL);
}
if((patient->getTBState()->currTrueTBDiseaseState == SimContext::TB_STATE_ACTIVE_PULM) || (patient->getTBState()->currTrueTBDiseaseState == SimContext::TB_STATE_ACTIVE_EXTRAPULM)){
accumulateQOLModifier(simContext->getTBInputs()->QOLModActiveTB);
}
/** Accumulate PrEP QoL modifier if applicable */
if(simContext->getHIVTestInputs()->enableHIVTesting && simContext->getHIVTestInputs()->enablePrEP && patient->getMonitoringState()->hasPrEP){
SimContext::HIV_BEHAV risk = patient->getMonitoringState()->isHighRiskForHIV?SimContext::HIV_BEHAV_HI:SimContext::HIV_BEHAV_LO;
accumulateQOLModifier(simContext->getHIVTestInputs()->PrEPQOL[risk]);
}
}
else {
/** If month of death, use QOL modifier for the cause of death */
SimContext::DTH_CAUSES causeOfDeath = patient->getDiseaseState()->causeOfDeath;
if ((causeOfDeath < SimContext::OI_NUM)) {
accumulateQOLModifier(simContext->getQOLInputs()->deathBasicQOL[causeOfDeath]);
}
else if (causeOfDeath == SimContext::DTH_HIV) {
if (!patient->getMonitoringState()->isDetectedHIVPositive) {
accumulateQOLModifier(simContext->getHIVTestInputs()->HIVDeathQOLHIVUndetected);
}
else {
accumulateQOLModifier(simContext->getQOLInputs()->deathBasicQOL[SimContext::DTH_HIV]);
}
}
else if (causeOfDeath == SimContext::DTH_BKGD_MORT) {
if (patient->getDiseaseState()->infectedHIVState == SimContext::HIV_INF_NEG) {
accumulateQOLModifier(simContext->getHIVTestInputs()->deathQOLHIVNegative);
}
else if (!patient->getMonitoringState()->isDetectedHIVPositive) {
accumulateQOLModifier(simContext->getHIVTestInputs()->backgroundMortDeathQOLHIVUndetected);
}
else {
accumulateQOLModifier(simContext->getQOLInputs()->deathBasicQOL[SimContext::DTH_BKGD_MORT]);
}
}
else if(causeOfDeath == SimContext::DTH_ACTIVE_TB){
accumulateQOLModifier(simContext->getTBInputs()->QOLModDeathActiveTB);
}
else if ((causeOfDeath >= SimContext::DTH_CHRM_1) && (causeOfDeath < SimContext::DTH_CHRM_1 + SimContext::CHRM_NUM)) {
accumulateQOLModifier(simContext->getCHRMsInputs()->QOLModDeathCHRMs[causeOfDeath - SimContext::DTH_CHRM_1]);
}
/** Other causes of death incur no additional QOL modifiers */
}
/** now all the QOL modifiers have been applied, finalize the patient's QOL value */
finalizeQOLValue();
/** update statistics for the coststats file */
updateCostStats(percentOfMonth);
/** update Pediatric HIV exposure statistics regardless of whether the patient died this month */
if(patient->getPedsState()->ageCategoryPediatrics < SimContext::PEDS_AGE_LATE && patient->getDiseaseState()->infectedPediatricsHIVState == SimContext::PEDS_HIV_NEG){
updatePedsHIVExposureStats(patient->getPedsState()->maternalStatus);
}
/** Update additional state, statistics and tracing for regular month or month of death */
if (patient->isAlive()) {
/** Increment the patient, overall, and longitudinal survival stats */
updatePatientSurvival(percentOfMonth);
updateOverallSurvival(percentOfMonth);
updateLongitSurvival();
/** update the patients OI history with any new OIs and OI history logging stats */
if (patient->getDiseaseState()->infectedHIVState != SimContext::HIV_INF_NEG) {
setOIHistory();
updateOIHistoryLogging();
/** Update the ART suppression stats */
updateARTEfficacyStats();
}
/** If tracing is enabled, print out either monthly status */
if (patient->getGeneralState()->tracingEnabled) {
if (patient->getDiseaseState()->infectedHIVState != SimContext::HIV_INF_NEG) {
if (patient->getPedsState()->ageCategoryPediatrics < SimContext::PEDS_AGE_LATE) {
tracer->printTrace(1, " %d upd: true CD4 perc %1.3f %s, true HVL %s;\n", patient->getGeneralState()->monthNum,
patient->getDiseaseState()->currTrueCD4Percentage, SimContext::CD4_STRATA_STRS[patient->getDiseaseState()->currTrueCD4Strata],
SimContext::HVL_STRATA_STRS[patient->getDiseaseState()->currTrueHVLStrata]);
}
else {
tracer->printTrace(1, " %d upd: true CD4 %1.0f %s, true HVL %s;\n", patient->getGeneralState()->monthNum,
patient->getDiseaseState()->currTrueCD4, SimContext::CD4_STRATA_STRS[patient->getDiseaseState()->currTrueCD4Strata],
SimContext::HVL_STRATA_STRS[patient->getDiseaseState()->currTrueHVLStrata]);
}
}
tracer->printTrace(1, " %d mth: ", patient->getGeneralState()->monthNum);
if (simContext->getTBInputs()->enableTB)
tracer->printTrace(1, "TB Symptoms: %s, ", patient->getTBState()->currTrueTBTracker[SimContext::TB_TRACKER_SYMPTOMS]?"Yes":"No");
tracer->printTrace(1, "LM %1.2lf QA %1.2lf, $ %1.0lf;\n",
patient->getGeneralState()->LMsDiscounted, patient->getGeneralState()->qualityAdjustLMsDiscounted,
patient->getGeneralState()->costsDiscounted);
}
/** Increment the simulation month number and patient age */
incrementMonth();
/** Increment the discount factor */
incrementDiscountFactor(simContext->getRunSpecsInputs()->discountFactor);
for(int i = 0; i < simContext->NUM_DISCOUNT_RATES; i++){
incrementMultDiscountFactor(simContext->getRunSpecsInputs()->multDiscountRatesCost[i], simContext->getRunSpecsInputs()->multDiscountRatesBenefit[i], i);
}
} /** end if patient is alive */
else {
/** Increment the patient and overall survival stats */
updatePatientSurvival(percentOfMonth);
updateOverallSurvival(percentOfMonth);
/** Update population statistics and add the patient summary if death occurred */
updatePopulationStats();
addPatientSummary();
/** If tracing is enabled, print out death tracing */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d DEATH %s;\n", patient->getGeneralState()->monthNum,
SimContext::DTH_CAUSES_STRS[patient->getDiseaseState()->causeOfDeath]);
tracer->printTrace(1, " LMs %1.2lf QA %1.2lf $ %1.0lf ;\n",
patient->getGeneralState()->LMsDiscounted,
patient->getGeneralState()->qualityAdjustLMsDiscounted,
patient->getGeneralState()->costsDiscounted);
tracer->printTrace(1, " END PATIENT\n\n");
}
}
} /* end performMonthlyUpdates */