4
4
// Created Date: 2025-04-30 //
5
5
// Author: Matthew Carroll //
6
6
// ----- //
7
- // Last Modified: 2025-05-13 //
8
- // Modified By: Matthew Carroll //
7
+ // Last Modified: 2025-05-28 //
8
+ // Modified By: Dimitri Baptiste //
9
9
// ----- //
10
10
// Copyright (c) 2025 Syndemics Lab at Boston Medical Center //
11
11
// //////////////////////////////////////////////////////////////////////////////
12
12
13
13
// File Header
14
14
#include < hepce/data/types.hpp>
15
+ #include < hepce/utils/formatting.hpp>
15
16
16
17
#include < tuple>
17
18
@@ -32,7 +33,8 @@ std::ostream &operator<<(std::ostream &os, const InfectionType &inst) {
32
33
return os;
33
34
}
34
35
InfectionType &operator <<(InfectionType &inst, const std::string &str) {
35
- if (str == " kHiv" ) {
36
+ const std::string temp_string = utils::ToLower (str);
37
+ if (temp_string == " hiv" ) {
36
38
inst = InfectionType::kHiv ;
37
39
} else {
38
40
inst = InfectionType::kHcv ;
@@ -68,9 +70,10 @@ std::ostream &operator<<(std::ostream &os, const HCV &inst) {
68
70
return os;
69
71
}
70
72
HCV &operator <<(HCV &inst, const std::string &str) {
71
- if (str == " acute" ) {
73
+ const std::string temp_string = utils::ToLower (str);
74
+ if (temp_string == " acute" ) {
72
75
inst = HCV::kAcute ;
73
- } else if (str == " chronic" ) {
76
+ } else if (temp_string == " chronic" ) {
74
77
inst = HCV::kChronic ;
75
78
} else {
76
79
inst = HCV::kNone ;
@@ -99,13 +102,14 @@ std::ostream &operator<<(std::ostream &os, const HIV &inst) {
99
102
return os;
100
103
}
101
104
HIV &operator <<(HIV &inst, const std::string &str) {
102
- if (str == " hi-un" ) {
105
+ const std::string temp_string = utils::ToLower (str);
106
+ if (temp_string == " hi-un" ) {
103
107
inst = HIV::kHiUn ;
104
- } else if (str == " hi-su" ) {
108
+ } else if (temp_string == " hi-su" ) {
105
109
inst = HIV::kHiSu ;
106
- } else if (str == " lo-un" ) {
110
+ } else if (temp_string == " lo-un" ) {
107
111
inst = HIV::kLoUn ;
108
- } else if (str == " lo-su" ) {
112
+ } else if (temp_string == " lo-su" ) {
109
113
inst = HIV::kLoSu ;
110
114
} else {
111
115
inst = HIV::kNone ;
@@ -137,15 +141,16 @@ std::ostream &operator<<(std::ostream &os, const DeathReason &inst) {
137
141
return os;
138
142
}
139
143
DeathReason &operator <<(DeathReason &inst, const std::string &str) {
140
- if (str == " background" ) {
144
+ const std::string temp_string = utils::ToLower (str);
145
+ if (temp_string == " background" ) {
141
146
inst = DeathReason::kBackground ;
142
- } else if (str == " liver" ) {
147
+ } else if (temp_string == " liver" ) {
143
148
inst = DeathReason::kLiver ;
144
- } else if (str == " infection" ) {
149
+ } else if (temp_string == " infection" ) {
145
150
inst = DeathReason::kInfection ;
146
- } else if (str == " age" ) {
151
+ } else if (temp_string == " age" ) {
147
152
inst = DeathReason::kAge ;
148
- } else if (str == " overdose" ) {
153
+ } else if (temp_string == " overdose" ) {
149
154
inst = DeathReason::kOverdose ;
150
155
} else {
151
156
inst = DeathReason::kNa ;
@@ -174,13 +179,14 @@ std::ostream &operator<<(std::ostream &os, const Behavior &inst) {
174
179
return os;
175
180
}
176
181
Behavior &operator <<(Behavior &inst, const std::string &str) {
177
- if (str == " former_injection" ) {
182
+ const std::string temp_string = utils::ToLower (str);
183
+ if (temp_string == " former_injection" ) {
178
184
inst = Behavior::kFormerInjection ;
179
- } else if (str == " former_noninjection" ) {
185
+ } else if (temp_string == " former_noninjection" ) {
180
186
inst = Behavior::kFormerNoninjection ;
181
- } else if (str == " injection" ) {
187
+ } else if (temp_string == " injection" ) {
182
188
inst = Behavior::kInjection ;
183
- } else if (str == " noninjection" ) {
189
+ } else if (temp_string == " noninjection" ) {
184
190
inst = Behavior::kNoninjection ;
185
191
} else {
186
192
inst = Behavior::kNever ;
@@ -203,9 +209,10 @@ std::ostream &operator<<(std::ostream &os, const ScreeningType &inst) {
203
209
return os;
204
210
}
205
211
ScreeningType &operator <<(ScreeningType &inst, const std::string &str) {
206
- if (str == " background" ) {
212
+ const std::string temp_string = utils::ToLower (str);
213
+ if (temp_string == " background" ) {
207
214
inst = ScreeningType::kBackground ;
208
- } else if (str == " intervention" ) {
215
+ } else if (temp_string == " intervention" ) {
209
216
inst = ScreeningType::kIntervention ;
210
217
} else {
211
218
inst = ScreeningType::kNa ;
@@ -228,9 +235,10 @@ std::ostream &operator<<(std::ostream &os, const ScreeningTest &inst) {
228
235
return os;
229
236
}
230
237
ScreeningTest &operator <<(ScreeningTest &inst, const std::string &str) {
231
- if (str == " antibody" ) {
238
+ const std::string temp_string = utils::ToLower (str);
239
+ if (temp_string == " antibody" ) {
232
240
inst = ScreeningTest::kAb ;
233
- } else if (str == " rna" ) {
241
+ } else if (temp_string == " rna" ) {
234
242
inst = ScreeningTest::kRna ;
235
243
} else {
236
244
inst = ScreeningTest::kNa ;
@@ -253,9 +261,10 @@ std::ostream &operator<<(std::ostream &os, const LinkageState &inst) {
253
261
return os;
254
262
}
255
263
LinkageState &operator <<(LinkageState &inst, const std::string &str) {
256
- if (str == " linked" ) {
264
+ const std::string temp_string = utils::ToLower (str);
265
+ if (temp_string == " linked" ) {
257
266
inst = LinkageState::kLinked ;
258
- } else if (str == " unlinked" ) {
267
+ } else if (temp_string == " unlinked" ) {
259
268
inst = LinkageState::kUnlinked ;
260
269
} else {
261
270
inst == LinkageState::kNever ;
@@ -290,17 +299,18 @@ std::ostream &operator<<(std::ostream &os, const FibrosisState &inst) {
290
299
return os;
291
300
}
292
301
FibrosisState &operator <<(FibrosisState &inst, const std::string &str) {
293
- if (str == " decomp" ) {
302
+ const std::string temp_string = utils::ToLower (str);
303
+ if (temp_string == " decomp" ) {
294
304
inst = FibrosisState::kDecomp ;
295
- } else if (str == " f0" ) {
305
+ } else if (temp_string == " f0" ) {
296
306
inst = FibrosisState::kF0 ;
297
- } else if (str == " f1" ) {
307
+ } else if (temp_string == " f1" ) {
298
308
inst = FibrosisState::kF1 ;
299
- } else if (str == " f2" ) {
309
+ } else if (temp_string == " f2" ) {
300
310
inst = FibrosisState::kF2 ;
301
- } else if (str == " f3" ) {
311
+ } else if (temp_string == " f3" ) {
302
312
inst = FibrosisState::kF3 ;
303
- } else if (str == " f4" ) {
313
+ } else if (temp_string == " f4" ) {
304
314
inst = FibrosisState::kF4 ;
305
315
} else {
306
316
inst = FibrosisState::kNone ;
@@ -354,9 +364,10 @@ std::ostream &operator<<(std::ostream &os, const HCCState &inst) {
354
364
return os;
355
365
}
356
366
HCCState &operator <<(HCCState &inst, const std::string &str) {
357
- if (str == " early" ) {
367
+ const std::string temp_string = utils::ToLower (str);
368
+ if (temp_string == " early" ) {
358
369
inst = HCCState::kEarly ;
359
- } else if (str == " late" ) {
370
+ } else if (temp_string == " late" ) {
360
371
inst = HCCState::kLate ;
361
372
} else {
362
373
inst = HCCState::kNone ;
@@ -386,13 +397,14 @@ std::ostream &operator<<(std::ostream &os, const MeasuredFibrosisState &inst) {
386
397
}
387
398
MeasuredFibrosisState &operator <<(MeasuredFibrosisState &inst,
388
399
const std::string &str) {
389
- if (str == " decomp" ) {
400
+ const std::string temp_string = utils::ToLower (str);
401
+ if (temp_string == " decomp" ) {
390
402
inst = MeasuredFibrosisState::kDecomp ;
391
- } else if (str == " f01" ) {
403
+ } else if (temp_string == " f01" ) {
392
404
inst = MeasuredFibrosisState::kF01 ;
393
- } else if (str == " f23" ) {
405
+ } else if (temp_string == " f23" ) {
394
406
inst = MeasuredFibrosisState::kF23 ;
395
- } else if (str == " f4" ) {
407
+ } else if (temp_string == " f4" ) {
396
408
inst = MeasuredFibrosisState::kF4 ;
397
409
} else {
398
410
inst = MeasuredFibrosisState::kNone ;
@@ -440,9 +452,10 @@ std::ostream &operator<<(std::ostream &os, const MOUD &inst) {
440
452
return os;
441
453
}
442
454
MOUD &operator <<(MOUD &inst, const std::string &str) {
443
- if (str == " current" ) {
455
+ const std::string temp_string = utils::ToLower (str);
456
+ if (temp_string == " current" ) {
444
457
inst = MOUD::kCurrent ;
445
- } else if (str == " post" ) {
458
+ } else if (temp_string == " post" ) {
446
459
inst = MOUD::kPost ;
447
460
} else {
448
461
inst = MOUD::kNone ;
@@ -465,7 +478,8 @@ std::ostream &operator<<(std::ostream &os, const Sex &inst) {
465
478
return os;
466
479
}
467
480
Sex &operator <<(Sex &inst, const std::string &str) {
468
- if (str == " male" ) {
481
+ const std::string temp_string = utils::ToLower (str);
482
+ if (temp_string == " male" ) {
469
483
inst = Sex::kMale ;
470
484
} else {
471
485
inst = Sex::kFemale ;
@@ -497,15 +511,16 @@ std::ostream &operator<<(std::ostream &os, const PregnancyState &inst) {
497
511
return os;
498
512
}
499
513
PregnancyState &operator <<(PregnancyState &inst, const std::string &str) {
500
- if (str == " restricted-postpartum" ) {
514
+ const std::string temp_string = utils::ToLower (str);
515
+ if (temp_string == " restricted-postpartum" ) {
501
516
inst = PregnancyState::kRestrictedPostpartum ;
502
- } else if (str == " year-one-postpartum" ) {
517
+ } else if (temp_string == " year-one-postpartum" ) {
503
518
inst = PregnancyState::kYearOnePostpartum ;
504
- } else if (str == " year-two-postpartum" ) {
519
+ } else if (temp_string == " year-two-postpartum" ) {
505
520
inst = PregnancyState::kYearTwoPostpartum ;
506
- } else if (str == " pregnant" ) {
521
+ } else if (temp_string == " pregnant" ) {
507
522
inst = PregnancyState::kPregnant ;
508
- } else if (str == " none" ) {
523
+ } else if (temp_string == " none" ) {
509
524
inst = PregnancyState::kNone ;
510
525
} else {
511
526
inst = PregnancyState::kNa ;
@@ -636,4 +651,4 @@ bool operator==(LifetimeUtility const &lhs, LifetimeUtility const &rhs) {
636
651
rhs.discount_mult_util ));
637
652
}
638
653
} // namespace data
639
- } // namespace hepce
654
+ } // namespace hepce
0 commit comments