-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClinicVisitUpdater.cpp
More file actions
2147 lines (1911 loc) · 94.3 KB
/
Copy pathClinicVisitUpdater.cpp
File metadata and controls
2147 lines (1911 loc) · 94.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
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "include.h"
/** \brief Constructor takes in the patient as a pointer */
ClinicVisitUpdater::ClinicVisitUpdater(Patient *patient) :
StateUpdater(patient)
{
}
/** \brief Destructor is empty, no cleanup required */
ClinicVisitUpdater::~ClinicVisitUpdater(void) {
}
/** \brief performInitialUpdates perform all of the state and statistics updates upon patient creation */
void ClinicVisitUpdater::performInitialUpdates() {
/** First calls the parent function to perform general updates and initialization */
StateUpdater::performInitialUpdates();
/** Sets the type of clinic visits and available treatments for the patient */
SimContext::CLINIC_VISITS visitType = SimContext::CLINIC_SCHED;
SimContext::THERAPY_IMPL treatmentType = SimContext::THERAPY_IMPL_PROPH_ART;
double randNum = CepacUtil::getRandomDouble(60010, patient);
for (int i = 0; i < SimContext::CLINIC_VISITS_NUM; i++) {
if ((simContext->getCohortInputs()->clinicVisitTypeDistribution[i] != 0) &&
(randNum < simContext->getCohortInputs()->clinicVisitTypeDistribution[i])) {
visitType = (SimContext::CLINIC_VISITS) i;
break;
}
randNum -= simContext->getCohortInputs()->clinicVisitTypeDistribution[i];
}
randNum = CepacUtil::getRandomDouble(60020, patient);
for (int i = 0; i < SimContext::THERAPY_IMPL_NUM; i++) {
if ((simContext->getCohortInputs()->therapyImplementationDistribution[i] != 0) &&
(randNum < simContext->getCohortInputs()->therapyImplementationDistribution[i])) {
treatmentType = (SimContext::THERAPY_IMPL) i;
break;
}
randNum -= simContext->getCohortInputs()->therapyImplementationDistribution[i];
}
setClinicVisitType(visitType, treatmentType);
/** Set the initial ART state to not on ART and determine next available regimen */
setInitialARTState();
/** Set the initial proph state to not on any prophs and determine next available ones */
setInitialProphState();
/** Sets the patients baseline ART response propensity coefficient */
double baselineMean = simContext->getHeterogeneityInputs()->propRespondBaselineLogitMean;
double baselineStdDev = simContext->getHeterogeneityInputs()->propRespondBaselineLogitStdDev;
double baselineCoeff = CepacUtil::getRandomGaussian(baselineMean, baselineStdDev, 60030, patient);
setResponseBaseline(baselineCoeff);
/** Set the patients CD4 response type */
randNum = CepacUtil::getRandomDouble(60040, patient);
SimContext::CD4_RESPONSE_TYPE responseType = SimContext::CD4_RESPONSE_1;
for (int i = 0; i < SimContext::CD4_RESPONSE_NUM_TYPES; i++) {
if ((simContext->getCohortInputs()->CD4ResponseTypeOnARTDistribution[i] != 0) &&
(randNum < simContext->getCohortInputs()->CD4ResponseTypeOnARTDistribution[i])) {
responseType = (SimContext::CD4_RESPONSE_TYPE) i;
break;
}
randNum -= simContext->getCohortInputs()->CD4ResponseTypeOnARTDistribution[i];
}
setCD4ResponseType(responseType);
/** Schedules the initial clinic visits and CD4/HVL test for detected HIV positive patients*/
if (patient->getMonitoringState()->isDetectedHIVPositive) {
scheduleInitialClinicVisit();
}
else {
scheduleRegularClinicVisit(false);
scheduleCD4Test(false);
scheduleHVLTest(false);
}
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_NONE);
/** Sets the observed health state of the patient to unknown values */
setObservedCD4(false);
setObservedCD4Percentage(false);
setObservedHVLStrata(false);
resetClinicVisitState(true);
/** Initialize LTFU state to not lost and STI state to not interrupted */
setCurrLTFUState(SimContext::LTFU_STATE_NONE);
setCurrSTIState(SimContext::STI_STATE_NONE);
/** Identify the first available art line */
bool hasNext = false;
int nextRegimen = SimContext::NOT_APPL;
for (int i = 0; i < SimContext::ART_NUM_LINES; i++) {
if (simContext->getARTInputs(i)) {
hasNext = true;
nextRegimen = i;
break;
}
}
setNextARTRegimen(hasNext, nextRegimen);
/** Determine patient prophylaxis non compliance */
randNum = CepacUtil::getRandomDouble(60060, patient);
if (randNum < simContext->getCohortInputs()->OIProphNonComplianceRisk)
setProphNonCompliance(true);
else
setProphNonCompliance(false);
for (int i = 0; i < SimContext::OI_NUM; i++) {
/** Set the initial proph that is available for use */
bool hasNext = false;
int prophNum = SimContext::NOT_APPL;
SimContext::PROPH_TYPE prophType = SimContext::PROPH_PRIMARY;
if (patient->getDiseaseState()->hasTrueOIHistory[i])
prophType = SimContext::PROPH_SECONDARY;
for (int k = 0; k < SimContext::PROPH_NUM; k++) {
const SimContext::ProphInputs *prophInput;
if(patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
prophInput=simContext->getProphInputs(SimContext::PROPH_PRIMARY, i, k);
}
else{
prophInput=simContext->getPedsProphInputs(SimContext::PROPH_PRIMARY, i, k);
}
if (prophInput) {
hasNext = true;
prophNum = k;
break;
}
}
setNextProph(hasNext, prophType, (SimContext::OI_TYPE) i, prophNum);
}
} /* end performInitialUpdates */
/** \brief performMonthlyUpdates performs all of the state and statistics updates for a simulated month */
void ClinicVisitUpdater::performMonthlyUpdates() {
/** Calls StateUpdater::willAttendClinicThisMonth() and only proceeds if it returns true */
if (!willAttendClinicThisMonth())
return;
/** Calls ClinicVisitUpdater::performOIDetectionUpdates() to handle emergency visits for OIs and determine if OIs are observed */
performOIDetectionUpdates();
/** Accrue general costs for the clinic visit and increment number of visits */
int cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
SimContext::GENDER_TYPE gender = patient->getGeneralState()->gender;
bool isRegularPaidVisit = false;
if(patient->getMonitoringState()->hasRegularClinicVisit &&
(patient->getGeneralState()->monthNum >= patient->getMonitoringState()->monthOfRegularClinicVisit)) {
isRegularPaidVisit = true;
const double *costs = simContext->getCostInputs()->clinicVisitCostRoutine[patient->getGeneralState()->ageCategoryCost][gender][cd4Strata];
incrementCostsClinicVisit(costs);
}
incrementNumClinicVisits();
/** Print tracing for the clinic visit if enabled */
if (patient->getGeneralState()->tracingEnabled) {
if(!isRegularPaidVisit && (patient->getMonitoringState()->emergencyClinicVisitType != SimContext::EMERGENCY_NONE)){
tracer->printTrace(1, "**%d EMERGENCY CLINIC VISIT, Triggered by: %s, $ %1.0lf;\n",
patient->getGeneralState()->monthNum, SimContext::EMERGENCY_TYPE_STRS[patient->getMonitoringState()->emergencyClinicVisitType], patient->getGeneralState()->costsDiscounted);
}
else{
tracer->printTrace(1, "**%d CLINIC VISIT, $ %1.0lf;\n",
patient->getGeneralState()->monthNum, patient->getGeneralState()->costsDiscounted);
}
}
/** schedule the next regular clinic visit **/
// if an emergency visit does not count as a regular visit, they will not schedule a new regular non-emergency appointment until they have attended the last scheduled non-emergency one **/
if (simContext->getTreatmentInputs()->emergencyVisitIsNotRegularVisit) {
if (patient->getMonitoringState()->hasRegularClinicVisit &&
(patient->getGeneralState()->monthNum >= patient->getMonitoringState()->monthOfRegularClinicVisit)) {
scheduleRegularClinicVisit(true, patient->getGeneralState()->monthNum + simContext->getTreatmentInputs()->clinicVisitInterval);
}
}
// if an emergency visit counts as a regular visit, always schedule their next regular non-emergency visit after the regular interval regardless of the reason for the current visit, potentially resulting in a postponement of their next regular non-emergency visit
else {
scheduleRegularClinicVisit(true, patient->getGeneralState()->monthNum + simContext->getTreatmentInputs()->clinicVisitInterval);
}
/** if clinic visit was an emergency one, update state to indicate that it occurred */
if ((patient->getMonitoringState()->emergencyClinicVisitType != SimContext::EMERGENCY_NONE) &&
(patient->getGeneralState()->monthNum >= patient->getMonitoringState()->monthOfEmergencyClinicVisit)) {
scheduleEmergencyClinicVisit(SimContext::EMERGENCY_NONE);
}
/** Evaluate ART and prophylaxis policies and make changes to the treatment programs by calling ClinicVisitUpdater::performARTProgramUpdates and ClinicVisitUpdater::performProphProgramUpdates */
performARTProgramUpdates();
performProphProgramUpdates();
/** reset the state for events since the last clinic visit */
resetClinicVisitState();
} /* end performMonthlyUpdates */
/** \brief setSimContext changes the inputs the updater uses to determine disease progression -- to be used primarily by the transmission model.
*
* Also changes the "nextARTRegimen" based on the ART regimens of the new simContext
* \param newSimContext a pointer to a SimContext which should now be used to determine future HIV progression
**/
void ClinicVisitUpdater::setSimContext(SimContext *newSimContext){
/** First call the parent function to switch to newSimContext */
StateUpdater::setSimContext(newSimContext);
/** determine next available regimen
//Identify the current (if any) art line or the last ART line taken (if ever) */
int potentialNextARTRegimenNum = 0;
if (patient->getARTState()->hasTakenART){
if (patient->getARTState()->isOnART){
potentialNextARTRegimenNum = patient->getARTState()->currRegimenNum + 1;
} else {
potentialNextARTRegimenNum = patient->getARTState()->prevRegimenNum + 1;
}
}
/** Identify the next available art line from the newSimContext
// Need to do here or if there are new/different ART lines in the new simContext, the patient will ignore them */
bool hasNext = false;
int nextRegimen = SimContext::NOT_APPL;
for (int i = potentialNextARTRegimenNum; i < SimContext::ART_NUM_LINES; i++) {
if (simContext->getARTInputs(i)) {
hasNext = true;
nextRegimen = i;
break;
}
}
setNextARTRegimen(hasNext, nextRegimen);
/** Identify current proph state and determine next available one for each OI */
for (int i = 0; i < SimContext::OI_NUM; i++) {
// Set the initial proph that is available for use
bool hasNext = false;
int prophNum = SimContext::NOT_APPL;
SimContext::PROPH_TYPE prophType = SimContext::PROPH_PRIMARY;
if (patient->getDiseaseState()->hasTrueOIHistory[i])
prophType = SimContext::PROPH_SECONDARY;
/** The first proph to look for -- will be 0 if the patient has never been on Proph or the current/last proph if patient *has* been on proph */
int potentialNextProphNum = 0;
if (patient->getProphState()->hasTakenProph[i][prophType]){
potentialNextProphNum = patient->getProphState()->currProphNum[i];
}
for (int k = potentialNextProphNum; k < SimContext::PROPH_NUM; k++) {
const SimContext::ProphInputs *prophInput;
if(patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
prophInput=simContext->getProphInputs(SimContext::PROPH_PRIMARY, i, k);
}
else{
prophInput=simContext->getPedsProphInputs(SimContext::PROPH_PRIMARY, i, k);
}
if (prophInput) {
hasNext = true;
prophNum = k;
break;
}
}
setNextProph(hasNext, prophType, (SimContext::OI_TYPE) i, prophNum);
}
}
/** \brief performOIDetectionUpdates handles the emergency OI clinic visit and
determines if the current and prior OIs are observed */
void ClinicVisitUpdater::performOIDetectionUpdates() {
for (int i = 0; i < SimContext::OI_NUM; i++) {
bool isObserved = false;
/** Determine if OIs are observed */
if (patient->getDiseaseState()->hasCurrTrueOI && (patient->getDiseaseState()->typeCurrTrueOI == i)) {
/** If Patient currently has acute OI, always count as observed */
isObserved = true;
setCurrObservedOI(true);
}
else if (!patient->getMonitoringState()->hadPrevClinicVisit && patient->getDiseaseState()->hasTrueOIHistory[i]) {
/** If first clinic visit and patient has history of OI, roll for being observed */
double randNum = CepacUtil::getRandomDouble(60070, patient);
if (randNum < simContext->getTreatmentInputs()->probDetectOIAtEntry[i]) {
isObserved = true;
}
}
else if (patient->getMonitoringState()->hadPrevClinicVisit && (patient->getDiseaseState()->numTrueOIsSinceLastVisit[i] > 0)) {
/** If subsequent clinic visit and patient had OI since last visit, roll for being observed */
double randNum = CepacUtil::getRandomDouble(60080, patient);
if (randNum < simContext->getTreatmentInputs()->probDetectOISinceLastVisit[i]) {
isObserved = true;
}
}
/** If OI is observed, increment number observed and output tracing */
if (isObserved) {
incrementNumObservedOIs((SimContext::OI_TYPE) i, 1);
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d OBSV OI %s;\n",
patient->getGeneralState()->monthNum, SimContext::OI_STRS[i]);
}
/** If on ART, determine if observed OI should count towards ART failure */
if (patient->getARTState()->isOnART) {
int artLineNum = patient->getARTState()->currRegimenNum;
if (patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
const SimContext::TreatmentInputs::ARTFailPolicy &failART = simContext->getTreatmentInputs()->failART[artLineNum];
bool isFailureOI = false;
if (patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart >= failART.OIsMonthsFromInit) {
if (failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_ANY)
isFailureOI = true;
else if (!patient->getDiseaseState()->hasTrueOIHistory[i] &&
(failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_PRIMARY))
isFailureOI = true;
else if (patient->getDiseaseState()->hasTrueOIHistory[i] &&
(failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_SECONDARY))
isFailureOI = true;
}
/** If OI should count towards failure, increment count and trigger a CD4 or HVL test if
// confirmatory testing is needed */
if (isFailureOI) {
incrementARTFailedOIs();
if (patient->getARTState()->numFailedOIs >= failART.OIsMinNum) {
if (failART.diagnoseUseCD4TestsConfirm)
patient->getCD4TestUpdater()->performMonthlyUpdates();
if (failART.diagnoseUseHVLTestsConfirm)
patient->getHVLTestUpdater()->performMonthlyUpdates();
}
}
}
// early childhood uses pediatric ART inputs
else{
const SimContext::PedsInputs::ARTFailPolicy &failART = simContext->getPedsInputs()->failART[artLineNum];
bool isFailureOI = false;
if (patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart >= failART.OIsMonthsFromInit) {
if (failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_ANY)
isFailureOI = true;
else if (!patient->getDiseaseState()->hasTrueOIHistory[i] &&
(failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_PRIMARY))
isFailureOI = true;
else if (patient->getDiseaseState()->hasTrueOIHistory[i] &&
(failART.OIsEvent[i] == SimContext::ART_FAIL_BY_OI_SECONDARY))
isFailureOI = true;
}
/** If OI should count towards failure, increment count and trigger a CD4 or HVL test if
// confirmatory testing is needed */
if (isFailureOI) {
incrementARTFailedOIs();
if (patient->getARTState()->numFailedOIs >= failART.OIsMinNum) {
if (failART.diagnoseUseCD4TestsConfirm)
patient->getCD4TestUpdater()->performMonthlyUpdates();
if (failART.diagnoseUseHVLTestsConfirm)
patient->getHVLTestUpdater()->performMonthlyUpdates();
}
}
}
}
}
}
} /* end performOIDetectionUpdates */
/** \brief performARTProgramUpdates evaluates ART policies and alters the treatment program */
void ClinicVisitUpdater::performARTProgramUpdates() {
/** return if ART treatments are not available to the patient */
if (!patient->getARTState()->mayReceiveART)
return;
bool hadObservedFailCurrMonth = false;
/** If patient is currently on ART and not already observed to have failed,
// determine if failure is observed this month by calling ClinicVisitUpdater::evaluateFailARTPolicy() */
if (patient->getARTState()->isOnART && !patient->getARTState()->hasObservedFailure) {
if (patient->getARTState()->currSTIState == SimContext::STI_STATE_NONE) {
SimContext::ART_FAIL_TYPE failType;
if (patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
failType=evaluateFailARTPolicy();
}
else{
failType=evaluateFailARTPolicyPeds();
}
if (failType != SimContext::ART_FAIL_NOT_FAILED) {
setCurrARTObservedFailure(failType);
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d ART %d FAIL OBSV BY %s;\n", patient->getGeneralState()->monthNum,
patient->getARTState()->currRegimenNum + 1,
SimContext::ART_FAIL_TYPE_STRS[patient->getARTState()->typeObservedFailure]);
}
}
}
else if (patient->getARTState()->currSTIState == SimContext::STI_STATE_RESTART) {
SimContext::ART_FAIL_TYPE failType = evaluateSTIEndpointPolicy();
if (failType != SimContext::ART_FAIL_NOT_FAILED) {
setCurrSTIState(SimContext::STI_STATE_ENDPOINT);
setCurrARTObservedFailure(failType);
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d ART %d STI ENDPOINT OBSV BY %s;\n", patient->getGeneralState()->monthNum,
patient->getARTState()->currRegimenNum + 1,
SimContext::ART_FAIL_TYPE_STRS[patient->getARTState()->typeObservedFailure]);
}
}
}
/** If failure was observed this month, determine if regimen should be restarted based on
// the patient's response type */
if (patient->getARTState()->hasObservedFailure) {
/** Get the current ART regimen information */
int currRegimen = patient->getARTState()->currRegimenNum;
const SimContext::ARTInputs *artInput = simContext->getARTInputs(currRegimen);
if (patient->getARTState()->numFailedResupp < artInput->maxRestartAttempts){
SimContext::RESP_TYPE responseType = patient->getARTState()->responseTypeCurrRegimen[SimContext::HET_OUTCOME_RESTART];
double probRestart = patient->getARTState()->probRestartAfterFail;
double randNum = CepacUtil::getRandomDouble(60090, patient);
if (randNum < probRestart) {
setNextARTRegimen(true, patient->getARTState()->currRegimenNum, true);
}
}
hadObservedFailCurrMonth = true;
}
}
/** If patient is on ART, evaluate stopping criteria by calling ClinicVisitUpdater::evaluateStopARTPolicy()
* Also check for STI (standard treatment interruption) stopping here by calling ClinicVisitUpdater::evaluateSTIInitialStopPolicy()
* or ClinicVisitUpdater::evaluateSTISubsequentStopPolicy() depending on whether or not an STI has previously been applied.
**/
SimContext::ART_STOP_TYPE stopType = SimContext::ART_STOP_NOT_STOPPED;
bool stiInterrupt = false;
if (patient->getARTState()->isOnART) {
if (patient->getARTState()->currSTIState == SimContext::STI_STATE_NONE) {
if(patient->getPedsState()->ageCategoryPediatrics>=SimContext::PEDS_AGE_LATE){
stopType = evaluateStopARTPolicy();
}
else{
stopType = evaluateStopARTPolicyPeds();
}
if (stopType == SimContext::ART_STOP_NOT_STOPPED) {
if (evaluateSTIInitialStopPolicy()) {
stopType = SimContext::ART_STOP_STI;
stiInterrupt = true;
}
}
}
else if (patient->getARTState()->currSTIState == SimContext::STI_STATE_RESTART) {
if (evaluateSTISubsequentStopPolicy()) {
stopType = SimContext::ART_STOP_STI;
stiInterrupt = true;
}
}
}
/** Stop the current ART regimen if it was determined to do so */
if (stopType != SimContext::ART_STOP_NOT_STOPPED) {
/** For STI stop, update the state to interrupt and set next regimen to the current one */
if (stiInterrupt) {
setCurrSTIState(SimContext::STI_STATE_INTERRUPT);
setNextARTRegimen(true, patient->getARTState()->currRegimenNum);
}
//Check to see if stopping is due to major tox and set next line if it is
if(patient->getPedsState()->ageCategoryPediatrics == SimContext::PEDS_AGE_ADULT){
int artLineNum = patient->getARTState()->currRegimenNum;
const SimContext::TreatmentInputs::ARTStopPolicy &stopART = simContext->getTreatmentInputs()->stopART[artLineNum];
int nextLineAfterTox = stopART.nextLineAfterMajorTox;
if (stopType == SimContext::ART_STOP_MAJ_TOX && nextLineAfterTox != SimContext::NOT_APPL){
if (simContext->getARTInputs(nextLineAfterTox))
setNextARTRegimen(true, nextLineAfterTox);
}
}
//Check to see if stopping is due to chronic tox and set the next line accordingly
if (stopType == SimContext::ART_STOP_CHRN_TOX){
setNextARTRegimen(true, patient->getARTState()->chronicToxSwitchToLine);
}
/** Stop the ART regimen and set target HVL back to the setpoint */
stopCurrARTRegimen(stopType);
setTargetHVLStrata(patient->getDiseaseState()->setpointHVLStrata);
/** Output tracing if enabled */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d TAKEN OFF ART %d by %s;\n", patient->getGeneralState()->monthNum,
patient->getARTState()->prevRegimenNum + 1,
SimContext::ART_STOP_TYPE_STRS[patient->getARTState()->typeCurrStop]);
}
/** If no more lines are available, set the post-ART CD4/HVL testing interval */
if (!patient->getARTState()->hasNextRegimenAvailable) {
int intervalCD4 = simContext->getTreatmentInputs()->CD4TestingIntervalPostART;
if (intervalCD4 != SimContext::NOT_APPL)
scheduleCD4Test(true, patient->getGeneralState()->monthNum + intervalCD4);
else
scheduleCD4Test(false);
int intervalHVL = simContext->getTreatmentInputs()->HVLTestingIntervalPostART;
if (intervalHVL != SimContext::NOT_APPL)
scheduleHVLTest(true, patient->getGeneralState()->monthNum + intervalHVL);
else
scheduleHVLTest(false);
}
}
//Restart CD4 Monitoring if it was turned off and patient has either observed fail or is stopping ART
if (simContext->getTreatmentInputs()->cd4MonitoringStopEnable && !patient->getMonitoringState()->CD4TestingAvailable){
if (hadObservedFailCurrMonth || stopType != SimContext::ART_STOP_NOT_STOPPED){
setCD4TestingAvailable(true);
/** Output tracing if enabled */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d STARTING CD4 MONITORING;\n", patient->getGeneralState()->monthNum);
}
int testingInterval;
if (patient->getARTState()->hasNextRegimenAvailable) {
/** - If Patient has taken ART and is not on the last line of ART, use months on ART threshold to
// determine testing interval */
int monthsOnART = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart;
if (monthsOnART < simContext->getTreatmentInputs()->testingIntervalARTMonthsThreshold)
testingInterval = simContext->getTreatmentInputs()->CD4TestingIntervalOnART[0];
else
testingInterval = simContext->getTreatmentInputs()->CD4TestingIntervalOnART[1];
}
else if (!patient->getARTState()->hasObservedFailure) {
/** - If Patient is on last ART line and has no yet been observed to fail, use months on ART
// threshold to determine testing interval */
int monthsOnART = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrRegimenStart;
if (monthsOnART < simContext->getTreatmentInputs()->testingIntervalLastARTMonthsThreshold)
testingInterval = simContext->getTreatmentInputs()->CD4TestingIntervalOnLastART[0];
else
testingInterval = simContext->getTreatmentInputs()->CD4TestingIntervalOnLastART[1];
}
else {
/** - If Patient has failed last ART line, use post-ART testing interval */
testingInterval = simContext->getTreatmentInputs()->CD4TestingIntervalPostART;
}
/** Schedule the CD4 test if there should be a next one */
if (testingInterval != SimContext::NOT_APPL) {
scheduleCD4Test(true, patient->getGeneralState()->monthNum + testingInterval);
}
else {
scheduleCD4Test(false);
}
}
}
/** If patient is not on ART, determine if the patient should start a new regimen this month
* by calling ClinicVisitUpdater::evaluateStartARTPolicy(). If in the middle of an STI,
* check for restart criteria by calling ClinicVisitUpdater::evaluateSTIRestartPolicy().
* Also check if the patient returned to care from LTFU this month and if LTFU policies
* indicate an ART restart.
**/
bool startNextART = false;
bool rtcStart = false;
bool stiRestart = false;
if (!patient->getARTState()->isOnART) {
// If returning to care and was on ART when lost, ART should be restarted
if ((patient->getMonitoringState()->currLTFUState == SimContext::LTFU_STATE_RETURNED && patient->getMonitoringState()->monthOfLTFUStateChange == patient->getGeneralState()->monthNum)){
rtcStart = true;
}
// Check whether they should restart automatically due to RTC
if(rtcStart && !simContext->getLTFUInputs()->recheckARTStartPoliciesAtRTC && patient->getARTState()->hasNextRegimenAvailable &&
patient->getMonitoringState()->wasOnARTWhenLostToFollowUp) {
startNextART = true;
}
// If currently on STI interruption, evaluate STI restart criteria
else if (patient->getARTState()->currSTIState == SimContext::STI_STATE_INTERRUPT) {
if (evaluateSTIRestartPolicy()) {
stiRestart = true;
startNextART = true;
}
}
// Otherwise, evaluate normal ART starting criteria
else{
if (patient->getPedsState()->ageCategoryPediatrics >= SimContext::PEDS_AGE_LATE){
// If patient's next line has passed max month number to start ART parameter look for the next one which is still available this month
if (patient->getARTState()->hasNextRegimenAvailable){
int artLineNum = patient->getARTState()->nextRegimenNum;
const SimContext::TreatmentInputs::ARTStartPolicy &startART = simContext->getTreatmentInputs()->startART[artLineNum];
if ((startART.maxMonthNum != SimContext::NOT_APPL) &&
(patient->getGeneralState()->monthNum > startART.maxMonthNum)) {
bool hasNext = false;
int nextRegimen = SimContext::NOT_APPL;
for (int i = patient->getARTState()->nextRegimenNum + 1; i < SimContext::ART_NUM_LINES; i++) {
if (simContext->getARTInputs(i)) {
// Search for the next regimen which is still available to start this calendar month by checking for max mth number inputs
const SimContext::TreatmentInputs::ARTStartPolicy &startART = simContext->getTreatmentInputs()->startART[i];
if(startART.maxMonthNum == SimContext::NOT_APPL ||
patient->getGeneralState()->monthNum <= startART.maxMonthNum){
hasNext = true;
nextRegimen = i;
break;
}
}
}
setNextARTRegimen(hasNext, nextRegimen);
}
}
if (evaluateStartARTPolicy()){
startNextART = true;
}
}
else{
if (evaluateStartARTPolicyPeds()){
startNextART = true;
}
}
}
} // end if patient is not on ART
/** Start the next ART regimen if it was determined to do so */
if (startNextART) {
//Check to see if we should guarantee initial suppression (They are on a resuppression regimen and they where obsv to fail but not true fail previous regimen
bool guaranteeSuppression = false;
bool isNewARTLine = false;
if(!patient->getARTState()->hasTakenARTRegimen[patient->getARTState()->nextRegimenNum]){
isNewARTLine = true;
}
if (patient->getPedsState()->ageCategoryPediatrics == SimContext::PEDS_AGE_ADULT){
if (patient->getARTState()->hasTakenART)
if (patient->getARTState()->hasObservedFailure && patient->getARTState()->currRegimenEfficacy == SimContext::ART_EFF_SUCCESS)
guaranteeSuppression = simContext->getTreatmentInputs()->startART[patient->getARTState()->nextRegimenNum].ensureSuppFalsePositiveFailure;
}
/** Start the ART regimen, update STI state if this is a restart, by calling StateUpdater::startNextARTRegimen() */
if (stiRestart) {
setCurrSTIState(SimContext::STI_STATE_RESTART);
}
startNextARTRegimen(patient->getARTState()->nextRegimenIsResupp);
/** Get the current ART regimen information */
int currRegimen = patient->getARTState()->currRegimenNum;
int currSubRegimen = patient->getARTState()->currSubRegimenNum;
const SimContext::ARTInputs *artInput = simContext->getARTInputs(currRegimen);
const SimContext::PedsARTInputs *pedsART = simContext->getPedsARTInputs(currRegimen);
const SimContext::AdolescentARTInputs *ayaART = simContext->getAdolescentARTInputs(currRegimen);
SimContext::PEDS_AGE_CAT pedsAgeCat = patient->getPedsState()->ageCategoryPediatrics;
int ayaAgeCat = getAgeCategoryAdolescent();
/** Determine and set the ART response type for this regimen */
double responseLogit = patient->getGeneralState()->responseBaselineLogit;
int ageCat = patient->getGeneralState()->ageCategoryHeterogeneity;
if(pedsAgeCat==SimContext::PEDS_AGE_ADULT){
responseLogit += simContext->getHeterogeneityInputs()->propRespondAge[ageCat];
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
responseLogit += simContext->getHeterogeneityInputs()->propRespondCD4[cd4Strata];
}
else if(pedsAgeCat==SimContext::PEDS_AGE_LATE){
responseLogit += simContext->getHeterogeneityInputs()->propRespondAgeLate;
SimContext::CD4_STRATA cd4Strata = patient->getDiseaseState()->currTrueCD4Strata;
responseLogit += simContext->getHeterogeneityInputs()->propRespondCD4[cd4Strata];
}
else{
responseLogit += simContext->getHeterogeneityInputs()->propRespondAgeEarly;
}
if (patient->getGeneralState()->gender == SimContext::GENDER_FEMALE)
responseLogit += simContext->getHeterogeneityInputs()->propRespondFemale;
if (patient->getDiseaseState()->typeTrueOIHistory != SimContext::HIST_EXT_N)
responseLogit += simContext->getHeterogeneityInputs()->propRespondHistoryOIs;
if (patient->getARTState()->hadPrevToxicity)
responseLogit += simContext->getHeterogeneityInputs()->propRespondPriorARTToxicity;
for (int i = 0; i < SimContext::RISK_FACT_NUM; i++) {
if (patient->getGeneralState()->hasRiskFactor[i])
responseLogit += simContext->getHeterogeneityInputs()->propRespondRiskFactor[i];
}
// Draw the regimen-specific logit adjustment for the patient using the mean, SD, and distribution from the inputs
double responseStdDev;
double responseIncrRegimenMean;
SimContext::HET_ART_LOGIT_DISTRIBUTION responseDist = SimContext::HET_ART_LOGIT_DISTRIBUTION_NORMAL;
if (patient->getGeneralState()->isAdolescent){
int ayaARTAgeCat = getAgeCategoryAdolescentART(currRegimen);
responseIncrRegimenMean = simContext->getAdolescentARTInputs(currRegimen)->propRespondARTRegimenLogitMean[ayaARTAgeCat];
responseStdDev = simContext->getAdolescentARTInputs(currRegimen)->propRespondARTRegimenLogitStdDev[ayaARTAgeCat];
}
else if (patient->getPedsState()->ageCategoryPediatrics == SimContext::PEDS_AGE_ADULT){
responseIncrRegimenMean = simContext->getARTInputs(currRegimen)->propRespondARTRegimenLogitMean;
responseStdDev = simContext->getARTInputs(currRegimen)->propRespondARTRegimenLogitStdDev;
responseDist = (SimContext::HET_ART_LOGIT_DISTRIBUTION) simContext->getARTInputs(currRegimen)->propRespondARTRegimenLogitDistribution;
}
else if (patient->getPedsState()->ageCategoryPediatrics == SimContext::PEDS_AGE_LATE){
responseIncrRegimenMean = simContext->getPedsARTInputs(currRegimen)->propRespondARTRegimenLogitMeanLate;
responseStdDev = simContext->getPedsARTInputs(currRegimen)->propRespondARTRegimenLogitStdDevLate;
}
else{
responseIncrRegimenMean = simContext->getPedsARTInputs(currRegimen)->propRespondARTRegimenLogitMeanEarly;
responseStdDev = simContext->getPedsARTInputs(currRegimen)->propRespondARTRegimenLogitStdDevEarly;
}
// Adult patients have a choice of distributions, while the Pediatrics and Adolescent modules only use a normal distribution
double responseLogitDraw = -1;
if (responseDist == SimContext::HET_ART_LOGIT_DISTRIBUTION_NORMAL)
responseLogitDraw = CepacUtil::getRandomGaussian(responseIncrRegimenMean, responseStdDev, 60100, patient);
else if (responseDist == SimContext::HET_ART_LOGIT_DISTRIBUTION_TRUNC_NORMAL){
while (responseLogitDraw < 0)
responseLogitDraw = CepacUtil::getRandomGaussian(responseIncrRegimenMean, responseStdDev, 60120, patient);
}
else{
while (responseLogitDraw < 0)
responseLogitDraw = CepacUtil::getRandomGaussian(responseIncrRegimenMean, responseStdDev, 60120, patient);
responseLogitDraw = responseLogitDraw * responseLogitDraw;
}
// preIncrResponseLogit is the response logit before any regimen-specific adjustments are made
double preIncrResponseLogit = responseLogit;
responseLogit += responseLogitDraw;
/** Draw for duration of increment if enabled */
int logitDuration = -1;
bool enableDuration = simContext->getARTInputs(currRegimen)->propRespondARTRegimenUseDuration;
if (enableDuration){
double randNum = CepacUtil::getRandomGaussian(simContext->getARTInputs(currRegimen)->propRespondARTRegimenDurationMean,simContext->getARTInputs(currRegimen)->propRespondARTRegimenDurationStdDev,60130, patient);
logitDuration = (int)(randNum + 0.5);
if (logitDuration < 0)
logitDuration = 0;
}
setARTResponseCurrRegimenBase(responseLogit, responseLogitDraw, preIncrResponseLogit, enableDuration, logitDuration);
if (patient->getGeneralState()->isOnAdherenceIntervention)
responseLogit += patient->getGeneralState()->responseLogitAdherenceInterventionIncrement;
setCurrARTResponse(responseLogit, isNewARTLine);
/** Determine and set the initial efficacy of the regimen
// Determine the probability of suppression */
SimContext::HVL_STRATA hvlStrata = patient->getDiseaseState()->currTrueHVLStrata;
double probSuppress = 0.0;
if (patient->getARTState()->isOnResupp)
probSuppress = patient->getARTState()->probResuppEfficacy;
else
probSuppress =patient->getARTState()->probInitialEfficacy;
/** If just Returned To Care and restarting the previous ART, and the users have enabled the alternate probabilities of suppression, find the probability based on their previous outcomes */
if (rtcStart && currRegimen == patient->getARTState()->prevRegimenNum && simContext->getLTFUInputs()->useProbSuppByPrevOutcome) {
if (patient->getARTState()->prevRegimenEfficacy == SimContext::ART_EFF_SUCCESS){
probSuppress = simContext->getLTFUInputs()->probSuppressionWhenReturnToSuppressed[currRegimen];
}
else {
probSuppress = simContext->getLTFUInputs()->probSuppressionWhenReturnToFailed[currRegimen];
}
}
/** Modify probability of suppression by resistance penalty */
for (int i = 0; i <= currRegimen; i++) {
int numMonths = patient->getARTState()->numMonthsOnUnsuccessfulByRegimen[i];
double resistFactor = simContext->getTreatmentInputs()->ARTResistancePriorRegimen[currRegimen][i];
probSuppress *= pow(1 - resistFactor, numMonths);
}
for (int i = 0; i < SimContext::HVL_NUM_STRATA; i++) {
int numMonths = patient->getARTState()->numMonthsOnUnsuccessfulByHVL[i];
double resistFactor = simContext->getTreatmentInputs()->ARTResistanceHVL[i];
probSuppress *= pow(1 - resistFactor, numMonths);
}
/** Set the initial efficacy of the regimen using the calculated probabilities */
SimContext::ART_EFF_TYPE efficacy;
if (guaranteeSuppression){
efficacy = SimContext::ART_EFF_SUCCESS;
}
else{
double randNum = CepacUtil::getRandomDouble(60110, patient);
if ((probSuppress > 0) && (randNum < probSuppress)) {
efficacy = SimContext::ART_EFF_SUCCESS;
}
else {
efficacy = SimContext::ART_EFF_FAILURE;
}
}
setCurrARTEfficacy(efficacy, true);
// Update consecutive failed resupp attempts based on efficacy
if (patient->getARTState()->isOnResupp){
if(efficacy == SimContext::ART_EFF_FAILURE){
incrementARTFailedResupp();
}
else{
resetARTFailedResupp();
}
}
// Reset count if starting first ever regimen or switching to a new one
else if(!(rtcStart && currRegimen == patient->getARTState()->prevRegimenNum)){
resetARTFailedResupp();
}
/** Set the target HVL based on the destined efficacy */
if (efficacy == SimContext::ART_EFF_SUCCESS) {
setTargetHVLStrata(SimContext::HVL_VLO);
}
else {
setTargetHVLStrata(patient->getDiseaseState()->setpointHVLStrata);
}
/** Set the initial CD4 slope for suppressive ART based on the response type,
// also set the CD4 envelope regimen and slope if this is the first successful regimen and the envelope is enabled; this controls the CD4 gain on successive ART regimens*/
// the overall CD4 envelope holds across all regimens, so once active the patient always has an active overall envelope
// The individual regimen envelope is regimen-specific, so a patient could have an active individual envelope on one regimen and then when they start a new regimen, it is reset to inactive until they are successful on it. It should also be inactivated while LTFU.
if (efficacy == SimContext::ART_EFF_SUCCESS) {
SimContext::CD4_RESPONSE_TYPE cd4Response = patient->getARTState()->CD4ResponseType;
//Adolescent starting successful regimen
if (patient->getGeneralState()->isAdolescent){
int ayaARTAgeCat = getAgeCategoryAdolescentART(currRegimen);
double cd4SlopeMean = ayaART->CD4ChangeOnSuppARTMean[0][ayaARTAgeCat];
double cd4SlopeStdDev = ayaART->CD4ChangeOnSuppARTStdDev[0][ayaARTAgeCat];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 60120, patient);
setCurrRegimenCD4Slope(cd4Slope);
// if this is their first success on the regimen, update the patient state to indicate that they have been successful on it, then update the CD4 envelopes if enabled
if (!patient->getARTState()->hadSuccessOnRegimen)
setSuccessfulARTRegimen();
if (!patient->getARTState()->overallCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_OVERALL, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
}
if (!patient->getARTState()->indivCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_INDIV, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
//Non-adolescent adult starting successful regimen
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT) {
double cd4SlopeMean = artInput->CD4ChangeOnSuppARTMean[cd4Response][0];
double cd4SlopeStdDev = artInput->CD4ChangeOnSuppARTStdDev[cd4Response][0];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 60120, patient);
setCurrRegimenCD4Slope(cd4Slope);
// if this is their first success on the regimen, update the patient state to indicate that they have been successful on it, then update the CD4 envelopes if enabled
if (!patient->getARTState()->hadSuccessOnRegimen)
setSuccessfulARTRegimen();
if (!patient->getARTState()->overallCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_OVERALL, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
}
if (!patient->getARTState()->indivCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_INDIV, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
//Late childhood patient starting successful regimen
else if (pedsAgeCat == SimContext::PEDS_AGE_LATE) {
double cd4SlopeMean = pedsART->CD4ChangeOnSuppARTMeanLate[cd4Response][0];
double cd4SlopeStdDev = pedsART->CD4ChangeOnSuppARTStdDevLate[cd4Response][0];
double cd4Slope = CepacUtil::getRandomGaussian(cd4SlopeMean, cd4SlopeStdDev, 60121, patient);
setCurrRegimenCD4Slope(cd4Slope);
// if this is their first success on the regimen, update the patient state to indicate that they have been successful on it, then update the CD4 envelopes if enabled
if (!patient->getARTState()->hadSuccessOnRegimen)
setSuccessfulARTRegimen();
if (!patient->getARTState()->overallCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_OVERALL, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_OVERALL, cd4Slope);
}
if (!patient->getARTState()->indivCD4Envelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_INDIV, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_INDIV, cd4Slope);
}
}
//Early childhood patient starting successful regimen
else {
/** For Peds early childhood, use CD4 Percentage */
double cd4PercSlopeMean = pedsART->CD4PercentageChangeOnSuppARTMeanEarly[pedsAgeCat][cd4Response][0];
double cd4PercSlopeStdDev = pedsART->CD4PercentageChangeOnSuppARTStdDevEarly[pedsAgeCat][cd4Response][0];
double cd4PercSlope = CepacUtil::getRandomGaussian(cd4PercSlopeMean, cd4PercSlopeStdDev, 60122, patient);
setCurrRegimenCD4PercentageSlope(cd4PercSlope);
// if this is their first success on the regimen, update the patient state to indicate that they have been successful on it, then update the CD4 envelopes if enabled
if (!patient->getARTState()->hadSuccessOnRegimen)
setSuccessfulARTRegimen();
if (!patient->getARTState()->overallCD4PercentageEnvelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_PERC_OVERALL, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_OVERALL, cd4PercSlope);
}
if (!patient->getARTState()->indivCD4PercentageEnvelope.isActive) {
setCD4EnvelopeRegimen(SimContext::ENVL_CD4_PERC_INDIV, currRegimen);
setCD4EnvelopeSlope(SimContext::ENVL_CD4_PERC_INDIV, cd4PercSlope);
}
}
} // end if (efficacy == SimContext::ART_EFF_SUCCESS)
/** Accumulate the initial startup cost for this regimen */
if (patient->getGeneralState()->isAdolescent){
incrementCostsARTInit(currRegimen, ayaART->costInitial[ayaAgeCat] );
}
else if (pedsAgeCat == SimContext::PEDS_AGE_ADULT) {
incrementCostsARTInit(currRegimen, artInput->costInitial);
}
else{
incrementCostsARTInit(currRegimen, pedsART->costInitial[patient->getPedsState()->ageCategoryPedsARTCost]);
}
/** Print debugging information if enabled */
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d INIT NEW ART %d, $ %1.0lf;\n", patient->getGeneralState()->monthNum,
patient->getARTState()->currRegimenNum + 1, patient->getGeneralState()->costsDiscounted);
tracer->printTrace(1, "**%d ART DRAW %s;\n", patient->getGeneralState()->monthNum,
SimContext::ART_EFF_STRS[efficacy]);
if (patient->getARTState()->isOnResupp)
tracer->printTrace(1, "**%d RESUPPRESSION ATTEMPT;\n", patient->getGeneralState()->monthNum);
for(int i=0;i<SimContext::HET_NUM_OUTCOMES;i++){
SimContext::RESP_TYPE responseType = patient->getARTState()->responseTypeCurrRegimen[i];
tracer->printTrace(1, "**%d ART DRAW %s:%s;\n", patient->getGeneralState()->monthNum,
SimContext::HET_OUTCOME_STRS[i], SimContext::RESP_TYPE_STRS[responseType]);
}
}
/** Identify the next available art line, need to do here since starting
// criteria for the next line may be evaluated before current one is stopped */
bool hasNext = false;
int nextRegimen = SimContext::NOT_APPL;
for (int i = patient->getARTState()->currRegimenNum + 1; i < SimContext::ART_NUM_LINES; i++) {
if (simContext->getARTInputs(i)) {
hasNext = true;
nextRegimen = i;
break;
}
}
setNextARTRegimen(hasNext, nextRegimen);
/** If CD4/HVL tests should happen at ART init, trigger them here if they have not yet occurred */
if (simContext->getTreatmentInputs()->numARTInitialCD4Tests > 0) {
patient->getCD4TestUpdater()->performMonthlyUpdates();
}
if (simContext->getTreatmentInputs()->numARTInitialHVLTests > 0) {
patient->getHVLTestUpdater()->performMonthlyUpdates();
}
/** Set the on-ART CD4/HVL testing intervals */
int intervalCD4 = SimContext::NOT_APPL;
if (patient->getARTState()->hasNextRegimenAvailable)
intervalCD4 = simContext->getTreatmentInputs()->CD4TestingIntervalOnART[0];
else
intervalCD4 = simContext->getTreatmentInputs()->CD4TestingIntervalOnLastART[0];
if (intervalCD4 != SimContext::NOT_APPL)
scheduleCD4Test(true, patient->getGeneralState()->monthNum + intervalCD4);
else
scheduleCD4Test(false);
int intervalHVL = SimContext::NOT_APPL;
if (patient->getARTState()->hasNextRegimenAvailable)
intervalHVL = simContext->getTreatmentInputs()->HVLTestingIntervalOnART[0];
else
intervalHVL = simContext->getTreatmentInputs()->HVLTestingIntervalOnLastART[0];
if (intervalHVL != SimContext::NOT_APPL)
scheduleHVLTest(true, patient->getGeneralState()->monthNum + intervalHVL);
else
scheduleHVLTest(false);
} //end if (startNextART)
/** Set the initial ART subregimen or determine if the subregimen needs to be switched */
if (patient->getARTState()->isOnART) {
int currRegimen = patient->getARTState()->currRegimenNum;
const SimContext::ARTInputs *artInput = simContext->getARTInputs(currRegimen);
bool startSubRegimen = false;
int nextSubRegimen = 0;
// Always start the first subregimen for a new ART line
if (startNextART) {
startSubRegimen = true;
nextSubRegimen = 0;
}
else {
int currSubRegimen = patient->getARTState()->currSubRegimenNum;
int monthsSubRegimen = patient->getGeneralState()->monthNum - patient->getARTState()->monthOfCurrSubRegimenStart;
// Switch subregimen if triggered by a toxicity
if (patient->getARTState()->hasSevereToxicity) {
startSubRegimen = true;
const SimContext::ARTToxicityEffect *toxEffect = patient->getARTState()->severeToxicityEffect;
const SimContext::ARTInputs::ARTToxicity &toxInputs = artInput->toxicity[toxEffect->ARTSubRegimenNum][toxEffect->toxSeverityType][toxEffect->toxNum];
nextSubRegimen = toxInputs.switchSubRegimenOnToxicity;
}
// Switch subregimen if specified time on subregimen has been exceeded
else if ((artInput->monthsToSwitchSubRegimen[currSubRegimen] != SimContext::NOT_APPL) &&
(monthsSubRegimen >= artInput->monthsToSwitchSubRegimen[currSubRegimen])) {
startSubRegimen = true;
nextSubRegimen = currSubRegimen + 1;
}
}
if (startSubRegimen) {
// Start that next ART subregimen
startNextARTSubRegimen(nextSubRegimen);
int currSubRegimen = nextSubRegimen;
// Output tracing for the start of the ART subregimen
if (patient->getGeneralState()->tracingEnabled) {
tracer->printTrace(1, "**%d %s ART SUBREGIMEN %d.%d\n",
patient->getGeneralState()->monthNum, startNextART ? "INIT" : "SWITCH",
currRegimen + 1, currSubRegimen);
}
// Roll for all ART toxicities for new subregimen, toxicity does not occur for non-responders
if (patient->getARTState()->responseTypeCurrRegimen[SimContext::HET_OUTCOME_TOX] != SimContext::RESP_TYPE_NON) {
for (int i = 0; i < SimContext::ART_NUM_TOX_SEVERITY; i++) {
for (int j = 0; j < SimContext::ART_NUM_TOX_PER_SEVERITY; j++) {
double randNum = CepacUtil::getRandomDouble(60130, patient);