forked from MGH-MPEC/CEPAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrugEfficacyUpdater.cpp
More file actions
547 lines (501 loc) · 29.1 KB
/
Copy pathDrugEfficacyUpdater.cpp
File metadata and controls
547 lines (501 loc) · 29.1 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#include "include.h"
/** \brief Constructor takes in the patient object */
DrugEfficacyUpdater::DrugEfficacyUpdater(Patient *patient) : StateUpdater(patient) {
}
/** \brief Destructor is empty, no cleanup required */
DrugEfficacyUpdater::~DrugEfficacyUpdater(void) {
}
/** \brief performInitialUpdates perform all of the state and statistics updates upon patient creation */
void DrugEfficacyUpdater::performInitialUpdates() {
/** Calls 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
*
* - If on ART, calls DrugEfficacyUpdater::performARTEfficacyUpdates
* - If either CD4 envelope or CD4 percentage envelope is active, calls DrugEfficacyUpdater::performARTEnvelopeEfficacyUpdates
* - If on any (non-TB) OI prophs, calls DrugEfficacyUpdater::performProphEfficacyUpdates
**/
void DrugEfficacyUpdater::performMonthlyUpdates() {
if (patient->getARTState()->isOnART)
performARTEfficacyUpdates();
if (patient->getARTState()->overallCD4Envelope.isActive ||
patient->getARTState()->overallCD4PercentageEnvelope.isActive)
performARTEnvelopeEfficacyUpdates();
if (patient->getProphState()->currTotalNumProphsOn > 0)
performProphEfficacyUpdates();
} /* end performMonthlyUpdates */
/** \brief performARTEfficacyUpdates handles all efficacy updates for ART regimens */
void DrugEfficacyUpdater::performARTEfficacyUpdates() {
int artLineNum = patient->getARTState()->currRegimenNum;
int subRegNum = patient->getARTState()->currSubRegimenNum;
SimContext::ART_EFF_TYPE efficacy = patient->getARTState()->currRegimenEfficacy;
int monthsEfficacy = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfEfficacyChange;
SimContext::RESP_TYPE responseType = patient->getARTState()->responseTypeCurrRegimen[SimContext::HET_OUTCOME_RESIST];
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
const SimContext::ARTInputs *artInputs = simContext->getARTInputs(artLineNum);
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(artLineNum);
const SimContext::AdolescentARTInputs *ayaART = simContext->getAdolescentARTInputs(artLineNum);
SimContext::PEDS_AGE_CAT pedsAgeCat = patient->getPedsState()->ageCategoryPediatrics;
int ayaAgeCat = getAgeCategoryAdolescent();
/** Increment the number of months on failed ART for resistance,
/* only count if patient is a full/partial responder */
if ((efficacy != SimContext::ART_EFF_SUCCESS) && (responseType != SimContext::RESP_TYPE_NON)) {
incrementMonthsUnsuccessfulART();
}
/** Check if patient is suppressed and has reached the next CD4 slope time segment, if so redraw slope */
if (efficacy == SimContext::ART_EFF_SUCCESS) {
if (patient->getGeneralState()->isAdolescent){
int ayaARTAgeCat = getAgeCategoryAdolescentART(artLineNum);
for (int i = 0; i < 2; i++) {
if (monthsEfficacy == ayaART->stageBoundsCD4ChangeOnSuppART[i]) {
double cd4SlopeMean = ayaART->CD4ChangeOnSuppARTMean[i + 1][ayaARTAgeCat];
double cd4SlopeStdDev = ayaART->CD4ChangeOnSuppARTStdDev[i + 1][ayaARTAgeCat];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70010, patient);
setCurrRegimenCD4Slope(cd4Slope);
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT) {
for (int i = 0; i < 2; i++) {
if (monthsEfficacy == artInputs->stageBoundsCD4ChangeOnSuppART[i]) {
double cd4SlopeMean = artInputs->CD4ChangeOnSuppARTMean[cd4Response][i + 1];
double cd4SlopeStdDev = artInputs->CD4ChangeOnSuppARTStdDev[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70010, patient);
setCurrRegimenCD4Slope(cd4Slope);
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_LATE) {
for (int i = 0; i < 2; i++) {
if (monthsEfficacy == pedsART->stageBoundsCD4ChangeOnSuppARTLate[i]) {
double cd4SlopeMean = pedsART->CD4ChangeOnSuppARTMeanLate[cd4Response][i + 1];
double cd4SlopeStdDev = pedsART->CD4ChangeOnSuppARTStdDevLate[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70011, patient);
setCurrRegimenCD4Slope(cd4Slope);
}
}
}
else {
for (int i = 0; i < 2; i++) {
if (monthsEfficacy == pedsART->stageBoundsCD4PercentageChangeOnSuppARTEarly[i]) {
int ageStartedEfficacyChange=patient->getGeneralState()->ageMonths-monthsEfficacy;
// for Peds early childhood, the slope comes from the age category they were in when they started successful ART, not their current age category
SimContext::PEDS_AGE_CAT pedsAgeCatStartedEfficacy=getAgeCategoryPediatrics(ageStartedEfficacyChange);
double cd4PercSlopeMean = pedsART->CD4PercentageChangeOnSuppARTMeanEarly[pedsAgeCatStartedEfficacy][cd4Response][i + 1];
double cd4PercSlopeStdDev = pedsART->CD4PercentageChangeOnSuppARTStdDevEarly[pedsAgeCatStartedEfficacy][cd4Response][i + 1];
double cd4PercSlope = CepacUtil::getRandomGaussian(cd4PercSlopeMean, cd4PercSlopeStdDev, 70012, patient);
setCurrRegimenCD4PercentageSlope(cd4PercSlope);
}
}
}
}
/** Trigger an emergency clinic visit if max months on ART or months to
/* subregimen switch has been reached */
int monthsOnART = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart;
if (patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
const SimContext::TreatmentInputs::ARTStopPolicy &stopART = simContext->getTreatmentInputs()->stopART[artLineNum];
if ((stopART.maxMonthsOnART != SimContext::NOT_APPL) &&
(monthsOnART >= stopART.maxMonthsOnART)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_ART, patient->getGeneralState()->monthNum);
}
}
else{
const SimContext::PedsInputs::ARTStopPolicy &stopART = simContext->getPedsInputs()->stopART[artLineNum];
if ((stopART.maxMonthsOnART != SimContext::NOT_APPL) &&
(monthsOnART >= stopART.maxMonthsOnART)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_ART, patient->getGeneralState()->monthNum);
}
}
int monthsOnSubReg = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrSubRegimenStart;
if ((artInputs->monthsToSwitchSubRegimen[subRegNum] != SimContext::NOT_APPL) &&
(monthsOnSubReg >= artInputs->monthsToSwitchSubRegimen[subRegNum])) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_ART, patient->getGeneralState()->monthNum);
}
/** Check if force failure month has been reached if it is set */
if (efficacy != SimContext::ART_EFF_FAILURE) {
bool forceFail = false;
if(patient->getGeneralState()->isAdolescent){
if((ayaART->forceFailAtMonth != SimContext::NOT_APPL) && monthsOnART >= ayaART->forceFailAtMonth)
forceFail = true;
}
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT){
if ((artInputs->forceFailAtMonth != SimContext::NOT_APPL) &&
(monthsOnART >= artInputs->forceFailAtMonth))
forceFail = true;
}
else if (pedsAgeCat == SimContext::PEDS_AGE_LATE) {
if ((pedsART->forceFailAtMonthLate != SimContext::NOT_APPL) &&
(monthsOnART >= pedsART->forceFailAtMonthLate))
forceFail = true;
}
else if ((pedsART->forceFailAtMonthEarly != SimContext::NOT_APPL) &&
(monthsOnART >= pedsART->forceFailAtMonthEarly))
forceFail = true;
if (forceFail) {
/** If forcing fail:
* - Set the efficacy to failure
*/
setCurrARTEfficacy(SimContext::ART_EFF_FAILURE, false);
/** - Set the target HVL to the setpoint HVL */
setTargetHVLStrata(patient->getDiseaseState()->setpointHVLStrata);
/** - Output tracing if enabled */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d ART LATE FAIL;\n", patient->getGeneralState()->monthNum);
}
return;
}
}
/** If this is the patient's initial suppression on the current regimen
// and it is within the efficacy time horizon, do not roll for any late transitions */
if (patient->getGeneralState()->isAdolescent){
int efficacyHorizon=ayaART->efficacyTimeHorizon[ayaAgeCat];
if (patient->getARTState()->hadSuccessOnRegimen &&
(patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart <= efficacyHorizon)){
//Only have efficacy time horizon for initial attempt or resupp attempt not RTC; return if within the efficacy time horizon
if(patient->getARTState()->isOnResupp || patient->getARTState()->monthOfCurrRegimenStart == patient->getARTState()->monthOfInitialRegimenSuccess){
return;
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT) {
int efficacyHorizon;
if (patient->getARTState()->isOnResupp)
efficacyHorizon = artInputs->efficacyTimeHorizonResuppression;
else
efficacyHorizon = artInputs->efficacyTimeHorizon;
if (patient->getARTState()->hadSuccessOnRegimen &&
(patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart <= efficacyHorizon)){
//Only have efficacy time horizon for initial attempt or resupp attempt not RTC; return if within the efficacy time horizon
if(patient->getARTState()->isOnResupp || patient->getARTState()->monthOfCurrRegimenStart == patient->getARTState()->monthOfInitialRegimenSuccess){
return;
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_LATE) {
int efficacyHorizon=pedsART->efficacyTimeHorizonLate;
if (patient->getARTState()->hadSuccessOnRegimen &&
(patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart <= efficacyHorizon)){
//Only have efficacy time horizon for initial attempt or resupp attempt not RTC; return if within the efficacy time horizon
if(patient->getARTState()->isOnResupp || patient->getARTState()->monthOfCurrRegimenStart == patient->getARTState()->monthOfInitialRegimenSuccess){
return;
}
}
}
else {
int efficacyHorizon=pedsART->efficacyTimeHorizonEarly;
if (patient->getARTState()->hadSuccessOnRegimen &&
(patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart <= efficacyHorizon)){
//Only have efficacy time horizon for initial attempt or resupp attempt not RTC; return if within the efficacy time horizon
if (patient->getARTState()->isOnResupp || patient->getARTState()->monthOfCurrRegimenStart == patient->getARTState()->monthOfInitialRegimenSuccess){
return;
}
}
}
if (efficacy == SimContext::ART_EFF_SUCCESS) {
/** If patient is suppressed, roll for late fail transition */
double probFail = 0.0;
probFail = patient->getARTState()->probLateFail;
double randNum = CepacUtil::getRandomDouble(70020, patient);
if ((probFail > 0) && (randNum < probFail)) {
/** If fail:
* - Set the efficacy to failure */
setCurrARTEfficacy(SimContext::ART_EFF_FAILURE, false);
/** - Set the target HVL to the setpoint HVL */
setTargetHVLStrata(patient->getDiseaseState()->setpointHVLStrata);
/** - Output tracing if enabled */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d ART LATE FAIL;\n", patient->getGeneralState()->monthNum);
}
}
}
} /* end performARTEfficacyUpdates */
/** \brief performARTEnvelopeEfficacyUpdates handles the efficacy updates of the ART CD4 envelope */
void DrugEfficacyUpdater::performARTEnvelopeEfficacyUpdates() {
SimContext::PEDS_AGE_CAT pedsAgeCat = patient->getPedsState()->ageCategoryPediatrics;
if (patient->getGeneralState()->isAdolescent){
/** Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope */
int overallEnvLineNum = patient->getARTState()->overallCD4Envelope.regimenNum;
int monthOverallEnvStart = patient->getARTState()->overallCD4Envelope.monthOfStart;
int monthsSinceOverallEnv = patient->getGeneralState()->monthNum - monthOverallEnvStart;
bool hasIndivEnv = patient->getARTState()->indivCD4Envelope.isActive;
int indivEnvLineNum = patient->getARTState()->indivCD4Envelope.regimenNum;
const SimContext::AdolescentARTInputs *ayaART = simContext->getAdolescentARTInputs(overallEnvLineNum);
int ayaARTAgeCat = getAgeCategoryAdolescentART(overallEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceOverallEnv == ayaART->stageBoundsCD4ChangeOnSuppART[i]) {
/** If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope */
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == overallEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthOverallEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, patient->getARTState()->currRegimenCD4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
/** Otherwise, draw for a new CD4 envelope slope */
double cd4SlopeMean = ayaART->CD4ChangeOnSuppARTMean[i + 1][ayaARTAgeCat];
double cd4SlopeStdDev = ayaART->CD4ChangeOnSuppARTStdDev[i + 1][ayaARTAgeCat];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70050, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
/** Update the individual regimen CD4 envelope */
if (hasIndivEnv && (indivEnvLineNum != overallEnvLineNum)) {
int monthIndivEnvStart = patient->getARTState()->indivCD4Envelope.monthOfStart;
int monthsSinceIndivEnv = patient->getGeneralState()->monthNum - monthIndivEnvStart;
/** Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope */
const SimContext::AdolescentARTInputs *ayaART = simContext->getAdolescentARTInputs(indivEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceIndivEnv == ayaART->stageBoundsCD4ChangeOnSuppART[i]) {
/** If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope */
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == indivEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthIndivEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
/** Otherwise, draw for a new CD4 envelope slope */
double cd4SlopeMean = ayaART->CD4ChangeOnSuppARTMean[i + 1][ayaARTAgeCat];
double cd4SlopeStdDev = ayaART->CD4ChangeOnSuppARTStdDev[i + 1][ayaARTAgeCat];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70051, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT) {
/** Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope */
int overallEnvLineNum = patient->getARTState()->overallCD4Envelope.regimenNum;
int monthOverallEnvStart = patient->getARTState()->overallCD4Envelope.monthOfStart;
int monthsSinceOverallEnv = patient->getGeneralState()->monthNum - monthOverallEnvStart;
bool hasIndivEnv = patient->getARTState()->indivCD4Envelope.isActive;
int indivEnvLineNum = patient->getARTState()->indivCD4Envelope.regimenNum;
const SimContext::ARTInputs *artInputs = simContext->getARTInputs(overallEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceOverallEnv == artInputs->stageBoundsCD4ChangeOnSuppART[i]) {
/** If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope */
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == overallEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthOverallEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, patient->getARTState()->currRegimenCD4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
/** Otherwise, draw for a new CD4 envelope slope */
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4SlopeMean = artInputs->CD4ChangeOnSuppARTMean[cd4Response][i + 1];
double cd4SlopeStdDev = artInputs->CD4ChangeOnSuppARTStdDev[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70050, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
/** Update the individual regimen CD4 envelope */
if (hasIndivEnv && (indivEnvLineNum != overallEnvLineNum)) {
int monthIndivEnvStart = patient->getARTState()->indivCD4Envelope.monthOfStart;
int monthsSinceIndivEnv = patient->getGeneralState()->monthNum - monthIndivEnvStart;
/** Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope */
const SimContext::ARTInputs *artInputs = simContext->getARTInputs(indivEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceIndivEnv == artInputs->stageBoundsCD4ChangeOnSuppART[i]) {
/** If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope */
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == indivEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthIndivEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
/** Otherwise, draw for a new CD4 envelope slope */
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4SlopeMean = artInputs->CD4ChangeOnSuppARTMean[cd4Response][i + 1];
double cd4SlopeStdDev = artInputs->CD4ChangeOnSuppARTStdDev[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70051, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
}
}
else if (pedsAgeCat == SimContext::PEDS_AGE_LATE) {
// Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope
int overallEnvLineNum = patient->getARTState()->overallCD4Envelope.regimenNum;
int monthOverallEnvStart = patient->getARTState()->overallCD4Envelope.monthOfStart;
int monthsSinceOverallEnv = patient->getGeneralState()->monthNum - monthOverallEnvStart;
bool hasIndivEnv = patient->getARTState()->indivCD4Envelope.isActive;
int indivEnvLineNum = patient->getARTState()->indivCD4Envelope.regimenNum;
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(overallEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceOverallEnv == pedsART->stageBoundsCD4ChangeOnSuppARTLate[i]) {
// If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == overallEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthOverallEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, patient->getARTState()->currRegimenCD4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
// Otherwise, draw for a new CD4 envelope slope
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4SlopeMean = pedsART->CD4ChangeOnSuppARTMeanLate[cd4Response][i + 1];
double cd4SlopeStdDev = pedsART->CD4ChangeOnSuppARTStdDevLate[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70052, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
// Update the individual regimen CD4 envelope
if (hasIndivEnv && (indivEnvLineNum != overallEnvLineNum)) {
int monthIndivEnvStart = patient->getARTState()->indivCD4Envelope.monthOfStart;
int monthsSinceIndivEnv = patient->getGeneralState()->monthNum - monthIndivEnvStart;
// Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(indivEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceIndivEnv == pedsART->stageBoundsCD4ChangeOnSuppARTLate[i]) {
// If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == indivEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthIndivEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, patient->getARTState()->currRegimenCD4Slope);
}
else {
// Otherwise, draw for a new CD4 envelope slope
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4SlopeMean = pedsART->CD4ChangeOnSuppARTMeanLate[cd4Response][i + 1];
double cd4SlopeStdDev = pedsART->CD4ChangeOnSuppARTStdDevLate[cd4Response][i + 1];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 70053, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
}
}
}
else {
/** For Peds early childhood, use the same process as above, but with the CD4 Percentage envelope */
// Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope
int overallEnvLineNum = patient->getARTState()->overallCD4PercentageEnvelope.regimenNum;
int monthOverallEnvStart = patient->getARTState()->overallCD4PercentageEnvelope.monthOfStart;
int monthsSinceOverallEnv = patient->getGeneralState()->monthNum - monthOverallEnvStart;
bool hasIndivEnv = patient->getARTState()->indivCD4PercentageEnvelope.isActive;
int indivEnvLineNum = patient->getARTState()->indivCD4PercentageEnvelope.regimenNum;
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(overallEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceOverallEnv == pedsART->stageBoundsCD4PercentageChangeOnSuppARTEarly[i]) {
// If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == overallEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthOverallEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_OVERALL, patient->getARTState()->currRegimenCD4PercentageSlope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_INDIV, patient->getARTState()->currRegimenCD4PercentageSlope);
}
else {
// Otherwise, draw for a new CD4 envelope slope
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4PercSlopeMean = pedsART->CD4PercentageChangeOnSuppARTMeanEarly[pedsAgeCat][cd4Response][i + 1];
double cd4PercSlopeStdDev = pedsART->CD4PercentageChangeOnSuppARTStdDevEarly[pedsAgeCat][cd4Response][i + 1];
double cd4PercSlope = CepacUtil::getRandomGaussian(cd4PercSlopeMean, cd4PercSlopeStdDev, 70054, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_OVERALL, cd4PercSlope);
if (hasIndivEnv && (overallEnvLineNum == indivEnvLineNum))
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_INDIV, cd4PercSlope);
}
}
}
// Update the individual regimen CD4 envelope
if (hasIndivEnv && (indivEnvLineNum != overallEnvLineNum)) {
int monthIndivEnvStart = patient->getARTState()->indivCD4PercentageEnvelope.monthOfStart;
int monthsSinceIndivEnv = patient->getGeneralState()->monthNum - monthIndivEnvStart;
// Check if patient has reached the next CD4 envelope slope time segment, if so redraw slope
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(indivEnvLineNum);
for (int i = 0; i < 2; i++) {
if (monthsSinceIndivEnv == pedsART->stageBoundsCD4PercentageChangeOnSuppARTEarly[i]) {
// If patient is still suppressed on the regimen that is setting the envelope,
// use the current CD4 slope as the CD4 envelope slope
if (patient->getARTState()->isOnART &&
(patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS) &&
(patient->getARTState()->currRegimenNum == indivEnvLineNum) &&
(patient->getARTState()->monthOfCurrRegimenStart == monthIndivEnvStart)) {
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_INDIV, patient->getARTState()->currRegimenCD4PercentageSlope);
}
else {
// Otherwise, draw for a new CD4 envelope slope
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
double cd4PercSlopeMean = pedsART->CD4PercentageChangeOnSuppARTMeanEarly[pedsAgeCat][cd4Response][i + 1];
double cd4PercSlopeStdDev = pedsART->CD4PercentageChangeOnSuppARTStdDevEarly[pedsAgeCat][cd4Response][i + 1];
double cd4PercSlope = CepacUtil::getRandomGaussian(cd4PercSlopeMean, cd4PercSlopeStdDev, 70055, patient);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_INDIV, cd4PercSlope);
}
}
}
}
}
} /* end performARTEnvelopeEfficacyUpdates */
/** \brief performProphEfficacyUpdates handles all efficacy updates for prophylaxis */
void DrugEfficacyUpdater::performProphEfficacyUpdates() {
/** Loop over all prophs that the patient is currently on */
for (int i = 0; i < SimContext::OI_NUM; i++) {
if (patient->getProphState()->isOnProph[i]) {
SimContext::PROPH_TYPE prophType = patient->getProphState()->currProphType[i];
int prophNum = patient->getProphState()->currProphNum[i];
const SimContext::ProphInputs *prophInputs;
if(patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
prophInputs=simContext->getProphInputs(prophType, i, prophNum);
}
else{
prophInputs=simContext->getPedsProphInputs(prophType, i, prophNum);
}
/** Trigger an emergency clinic visit if max month number, months on proph,
// or month to switch proph line has been reached */
int monthsOnProph = patient->getGeneralState()->monthNum - patient->getProphState()->monthOfProphStart[i];
const SimContext::TreatmentInputs::ProphStopPolicy &stopProph = simContext->getTreatmentInputs()->stopProph[prophType][i];
if ((stopProph.minMonthNum != SimContext::NOT_APPL)&&
(patient->getGeneralState()->monthNum >= stopProph.minMonthNum)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_PROPH, patient->getGeneralState()->monthNum);
}
else if ((stopProph.monthsOnProph != SimContext::NOT_APPL) &&
(monthsOnProph >= stopProph.monthsOnProph)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_PROPH, patient->getGeneralState()->monthNum);
}
else if ((prophInputs->monthsToSwitch != SimContext::NOT_APPL) &&
(monthsOnProph >= prophInputs->monthsToSwitch)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_PROPH, patient->getGeneralState()->monthNum);
}
/** Evaluate if proph resistance should begin for this drug */
if (!patient->getProphState()->useProphResistance[i]) {
double resistTime = prophInputs->timeOfResistance;
if (patient->getProphState()->isNonCompliant)
resistTime = resistTime / (1 - simContext->getCohortInputs()->OIProphNonComplianceDegree);
if (patient->getGeneralState()->monthNum - patient->getProphState()->monthOfProphStart[i] > resistTime) {
double randNum = CepacUtil::getRandomDouble(70060, patient);
if (randNum < prophInputs->monthlyProbResistance) {
setProphResistance((SimContext::OI_TYPE) i);
}
}
}
}
}
} /* end performProphEfficacyUpdates */