Skip to content

Commit 8d21e12

Browse files
committed
Address case-sensitivity issue with inputs.
1 parent 9b11ce7 commit 8d21e12

File tree

1 file changed

+60
-45
lines changed

1 file changed

+60
-45
lines changed

src/data/types.cpp

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
// Created Date: 2025-04-30 //
55
// Author: Matthew Carroll //
66
// ----- //
7-
// Last Modified: 2025-05-13 //
8-
// Modified By: Matthew Carroll //
7+
// Last Modified: 2025-05-28 //
8+
// Modified By: Dimitri Baptiste //
99
// ----- //
1010
// Copyright (c) 2025 Syndemics Lab at Boston Medical Center //
1111
////////////////////////////////////////////////////////////////////////////////
1212

1313
// File Header
1414
#include <hepce/data/types.hpp>
15+
#include <hepce/utils/formatting.hpp>
1516

1617
#include <tuple>
1718

@@ -32,7 +33,8 @@ std::ostream &operator<<(std::ostream &os, const InfectionType &inst) {
3233
return os;
3334
}
3435
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") {
3638
inst = InfectionType::kHiv;
3739
} else {
3840
inst = InfectionType::kHcv;
@@ -68,9 +70,10 @@ std::ostream &operator<<(std::ostream &os, const HCV &inst) {
6870
return os;
6971
}
7072
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") {
7275
inst = HCV::kAcute;
73-
} else if (str == "chronic") {
76+
} else if (temp_string == "chronic") {
7477
inst = HCV::kChronic;
7578
} else {
7679
inst = HCV::kNone;
@@ -99,13 +102,14 @@ std::ostream &operator<<(std::ostream &os, const HIV &inst) {
99102
return os;
100103
}
101104
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") {
103107
inst = HIV::kHiUn;
104-
} else if (str == "hi-su") {
108+
} else if (temp_string == "hi-su") {
105109
inst = HIV::kHiSu;
106-
} else if (str == "lo-un") {
110+
} else if (temp_string == "lo-un") {
107111
inst = HIV::kLoUn;
108-
} else if (str == "lo-su") {
112+
} else if (temp_string == "lo-su") {
109113
inst = HIV::kLoSu;
110114
} else {
111115
inst = HIV::kNone;
@@ -137,15 +141,16 @@ std::ostream &operator<<(std::ostream &os, const DeathReason &inst) {
137141
return os;
138142
}
139143
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") {
141146
inst = DeathReason::kBackground;
142-
} else if (str == "liver") {
147+
} else if (temp_string == "liver") {
143148
inst = DeathReason::kLiver;
144-
} else if (str == "infection") {
149+
} else if (temp_string == "infection") {
145150
inst = DeathReason::kInfection;
146-
} else if (str == "age") {
151+
} else if (temp_string == "age") {
147152
inst = DeathReason::kAge;
148-
} else if (str == "overdose") {
153+
} else if (temp_string == "overdose") {
149154
inst = DeathReason::kOverdose;
150155
} else {
151156
inst = DeathReason::kNa;
@@ -174,13 +179,14 @@ std::ostream &operator<<(std::ostream &os, const Behavior &inst) {
174179
return os;
175180
}
176181
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") {
178184
inst = Behavior::kFormerInjection;
179-
} else if (str == "former_noninjection") {
185+
} else if (temp_string == "former_noninjection") {
180186
inst = Behavior::kFormerNoninjection;
181-
} else if (str == "injection") {
187+
} else if (temp_string == "injection") {
182188
inst = Behavior::kInjection;
183-
} else if (str == "noninjection") {
189+
} else if (temp_string == "noninjection") {
184190
inst = Behavior::kNoninjection;
185191
} else {
186192
inst = Behavior::kNever;
@@ -203,9 +209,10 @@ std::ostream &operator<<(std::ostream &os, const ScreeningType &inst) {
203209
return os;
204210
}
205211
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") {
207214
inst = ScreeningType::kBackground;
208-
} else if (str == "intervention") {
215+
} else if (temp_string == "intervention") {
209216
inst = ScreeningType::kIntervention;
210217
} else {
211218
inst = ScreeningType::kNa;
@@ -228,9 +235,10 @@ std::ostream &operator<<(std::ostream &os, const ScreeningTest &inst) {
228235
return os;
229236
}
230237
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") {
232240
inst = ScreeningTest::kAb;
233-
} else if (str == "rna") {
241+
} else if (temp_string == "rna") {
234242
inst = ScreeningTest::kRna;
235243
} else {
236244
inst = ScreeningTest::kNa;
@@ -253,9 +261,10 @@ std::ostream &operator<<(std::ostream &os, const LinkageState &inst) {
253261
return os;
254262
}
255263
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") {
257266
inst = LinkageState::kLinked;
258-
} else if (str == "unlinked") {
267+
} else if (temp_string == "unlinked") {
259268
inst = LinkageState::kUnlinked;
260269
} else {
261270
inst == LinkageState::kNever;
@@ -290,17 +299,18 @@ std::ostream &operator<<(std::ostream &os, const FibrosisState &inst) {
290299
return os;
291300
}
292301
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") {
294304
inst = FibrosisState::kDecomp;
295-
} else if (str == "f0") {
305+
} else if (temp_string == "f0") {
296306
inst = FibrosisState::kF0;
297-
} else if (str == "f1") {
307+
} else if (temp_string == "f1") {
298308
inst = FibrosisState::kF1;
299-
} else if (str == "f2") {
309+
} else if (temp_string == "f2") {
300310
inst = FibrosisState::kF2;
301-
} else if (str == "f3") {
311+
} else if (temp_string == "f3") {
302312
inst = FibrosisState::kF3;
303-
} else if (str == "f4") {
313+
} else if (temp_string == "f4") {
304314
inst = FibrosisState::kF4;
305315
} else {
306316
inst = FibrosisState::kNone;
@@ -354,9 +364,10 @@ std::ostream &operator<<(std::ostream &os, const HCCState &inst) {
354364
return os;
355365
}
356366
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") {
358369
inst = HCCState::kEarly;
359-
} else if (str == "late") {
370+
} else if (temp_string == "late") {
360371
inst = HCCState::kLate;
361372
} else {
362373
inst = HCCState::kNone;
@@ -386,13 +397,14 @@ std::ostream &operator<<(std::ostream &os, const MeasuredFibrosisState &inst) {
386397
}
387398
MeasuredFibrosisState &operator<<(MeasuredFibrosisState &inst,
388399
const std::string &str) {
389-
if (str == "decomp") {
400+
const std::string temp_string = utils::ToLower(str);
401+
if (temp_string == "decomp") {
390402
inst = MeasuredFibrosisState::kDecomp;
391-
} else if (str == "f01") {
403+
} else if (temp_string == "f01") {
392404
inst = MeasuredFibrosisState::kF01;
393-
} else if (str == "f23") {
405+
} else if (temp_string == "f23") {
394406
inst = MeasuredFibrosisState::kF23;
395-
} else if (str == "f4") {
407+
} else if (temp_string == "f4") {
396408
inst = MeasuredFibrosisState::kF4;
397409
} else {
398410
inst = MeasuredFibrosisState::kNone;
@@ -440,9 +452,10 @@ std::ostream &operator<<(std::ostream &os, const MOUD &inst) {
440452
return os;
441453
}
442454
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") {
444457
inst = MOUD::kCurrent;
445-
} else if (str == "post") {
458+
} else if (temp_string == "post") {
446459
inst = MOUD::kPost;
447460
} else {
448461
inst = MOUD::kNone;
@@ -465,7 +478,8 @@ std::ostream &operator<<(std::ostream &os, const Sex &inst) {
465478
return os;
466479
}
467480
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") {
469483
inst = Sex::kMale;
470484
} else {
471485
inst = Sex::kFemale;
@@ -497,15 +511,16 @@ std::ostream &operator<<(std::ostream &os, const PregnancyState &inst) {
497511
return os;
498512
}
499513
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") {
501516
inst = PregnancyState::kRestrictedPostpartum;
502-
} else if (str == "year-one-postpartum") {
517+
} else if (temp_string == "year-one-postpartum") {
503518
inst = PregnancyState::kYearOnePostpartum;
504-
} else if (str == "year-two-postpartum") {
519+
} else if (temp_string == "year-two-postpartum") {
505520
inst = PregnancyState::kYearTwoPostpartum;
506-
} else if (str == "pregnant") {
521+
} else if (temp_string == "pregnant") {
507522
inst = PregnancyState::kPregnant;
508-
} else if (str == "none") {
523+
} else if (temp_string == "none") {
509524
inst = PregnancyState::kNone;
510525
} else {
511526
inst = PregnancyState::kNa;
@@ -636,4 +651,4 @@ bool operator==(LifetimeUtility const &lhs, LifetimeUtility const &rhs) {
636651
rhs.discount_mult_util));
637652
}
638653
} // namespace data
639-
} // namespace hepce
654+
} // namespace hepce

0 commit comments

Comments
 (0)