66import java .util .ArrayList ;
77import java .util .Arrays ;
88import java .util .Collections ;
9+ import java .util .HashSet ;
910import java .util .List ;
11+ import java .util .Set ;
1012
1113import org .apache .commons .lang3 .math .NumberUtils ;
14+ import org .apache .commons .lang3 .tuple .Pair ;
1215
1316import com .imsweb .algorithms .internal .Utils ;
1417
@@ -26,6 +29,37 @@ public final class IarcUtils {
2629 public static final Integer PRIMARY = 1 ;
2730 public static final Integer INSITU = 9 ;
2831
32+ private static final Set <String > _SITE_GROUP_C02 = new HashSet <>(Arrays .asList ("C01" , "C02" ));
33+ private static final Set <String > _SITE_GROUP_C06 = new HashSet <>(Arrays .asList ("C00" , "C03" , "C04" , "C05" , "C06" ));
34+ private static final Set <String > _SITE_GROUP_C14 = new HashSet <>(Arrays .asList ("C09" , "C10" , "C12" , "C13" , "C14" ));
35+ private static final Set <String > _SITE_GROUP_C20 = new HashSet <>(Arrays .asList ("C19" , "C20" ));
36+ private static final Set <String > _SITE_GROUP_C24 = new HashSet <>(Arrays .asList ("C23" , "C24" ));
37+ private static final Set <String > _SITE_GROUP_C34 = new HashSet <>(Arrays .asList ("C33" , "C34" ));
38+ private static final Set <String > _SITE_GROUP_C41 = new HashSet <>(Arrays .asList ("C40" , "C41" ));
39+ private static final Set <String > _SITE_GROUP_C68 = new HashSet <>(Arrays .asList ("C65" , "C66" , "C67" , "C68" ));
40+
41+ private static final List <Pair <List <Object >, Integer >> _HISTOLOGY_RANGES = new ArrayList <>();
42+
43+ static {
44+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8051-8084,8120-8131" ), 1 ));
45+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8090-8110" ), 2 ));
46+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8140-8149,8160-8162,8190-8221,8260-8337,8350-8551,8570-8576,8940-8941" ), 3 ));
47+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8030-8046,8150-8157,8170-8180,8230-8255,8340-8347,8560-8562,8580-8671" ), 4 ));
48+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8010-8015,8020-8022,8050" ), 5 ));
49+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8680-8713,8800-8921,8990-8991,9040-9044,9120-9125,9130-9136,9141-9252,9370-9373,9540-9582" ), 6 ));
50+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9050-9055" ), 7 ));
51+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9840,9861-9931,9945-9946,9950,9961-9964,9980-9987,9991-9992" ), 8 ));
52+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9597,9670-9699,9712,9728,9731-9738,9761-9767,9769,9811-9818,9823-9826,9833,9836,9940" ), 9 ));
53+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9700-9726,9729,9768,9827-9831,9834,9837,9948" ), 10 ));
54+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9650-9667" ), 11 ));
55+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9740-9742" ), 12 ));
56+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9750-9759" ), 13 ));
57+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9590-9591,9596,9727,9760,9800-9809,9820,9832,9835,9860,9960,9965-9975,9989" ), 14 ));
58+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("9140" ), 15 ));
59+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8720-8790,8930-8936,8950-8983,9000-9030,9060-9110,9260-9365,9380-9539" ), 16 ));
60+ _HISTOLOGY_RANGES .add (Pair .of (Utils .expandHistologiesAsIntegers ("8000-8005" ), 17 ));
61+ }
62+
2963 private IarcUtils () {
3064 // utility class
3165 }
@@ -112,21 +146,21 @@ private static String calculateSiteGroup(String site) {
112146 String siteGroup = site != null && site .length () >= 3 ? site .toUpperCase ().substring (0 , 3 ) : null ;
113147
114148 if (siteGroup != null ) {
115- if (Arrays . asList ( "C01" , "C02" ) .contains (siteGroup ))
149+ if (_SITE_GROUP_C02 .contains (siteGroup ))
116150 siteGroup = "C02" ;
117- else if (Arrays . asList ( "C00" , "C03" , "C04" , "C05" , "C06" ) .contains (siteGroup ))
151+ else if (_SITE_GROUP_C06 .contains (siteGroup ))
118152 siteGroup = "C06" ;
119- else if (Arrays . asList ( "C09" , "C10" , "C12" , "C13" , "C14" ) .contains (siteGroup ))
153+ else if (_SITE_GROUP_C14 .contains (siteGroup ))
120154 siteGroup = "C14" ;
121- else if (Arrays . asList ( "C19" , "C20" ) .contains (siteGroup ))
155+ else if (_SITE_GROUP_C20 .contains (siteGroup ))
122156 siteGroup = "C20" ;
123- else if (Arrays . asList ( "C23" , "C24" ) .contains (siteGroup ))
157+ else if (_SITE_GROUP_C24 .contains (siteGroup ))
124158 siteGroup = "C24" ;
125- else if (Arrays . asList ( "C33" , "C34" ) .contains (siteGroup ))
159+ else if (_SITE_GROUP_C34 .contains (siteGroup ))
126160 siteGroup = "C34" ;
127- else if (Arrays . asList ( "C40" , "C41" ) .contains (siteGroup ))
161+ else if (_SITE_GROUP_C41 .contains (siteGroup ))
128162 siteGroup = "C41" ;
129- else if (Arrays . asList ( "C65" , "C66" , "C67" , "C68" ) .contains (siteGroup ))
163+ else if (_SITE_GROUP_C68 .contains (siteGroup ))
130164 siteGroup = "C68" ;
131165 }
132166
@@ -138,41 +172,12 @@ private static Integer calculateHistGroup(String histology) {
138172
139173 if (NumberUtils .isDigits (histology )) {
140174 int hist = NumberUtils .toInt (histology );
141-
142- if (Utils .isHistologyContained ("8051-8084,8120-8131" , hist ))
143- histologyGroup = 1 ;
144- else if (Utils .isHistologyContained ("8090-8110" , hist ))
145- histologyGroup = 2 ;
146- else if (Utils .isHistologyContained ("8140-8149,8160-8162,8190-8221,8260-8337,8350-8551,8570-8576,8940-8941" , hist ))
147- histologyGroup = 3 ;
148- else if (Utils .isHistologyContained ("8030-8046,8150-8157,8170-8180,8230-8255,8340-8347,8560-8562,8580-8671" , hist ))
149- histologyGroup = 4 ;
150- else if (Utils .isHistologyContained ("8010-8015,8020-8022,8050" , hist ))
151- histologyGroup = 5 ;
152- else if (Utils .isHistologyContained ("8680-8713,8800-8921,8990-8991,9040-9044,9120-9125,9130-9136,9141-9252,9370-9373,9540-9582" , hist ))
153- histologyGroup = 6 ;
154- else if (Utils .isHistologyContained ("9050-9055" , hist ))
155- histologyGroup = 7 ;
156- else if (Utils .isHistologyContained ("9840,9861-9931,9945-9946,9950,9961-9964,9980-9987,9991-9992" , hist ))
157- histologyGroup = 8 ;
158- else if (Utils .isHistologyContained ("9597,9670-9699,9712,9728,9731-9738,9761-9767,9769,9811-9818,9823-9826,9833,9836,9940" , hist ))
159- histologyGroup = 9 ;
160- else if (Utils .isHistologyContained ("9700-9726,9729,9768,9827-9831,9834,9837,9948" , hist ))
161- histologyGroup = 10 ;
162- else if (Utils .isHistologyContained ("9650-9667" , hist ))
163- histologyGroup = 11 ;
164- else if (Utils .isHistologyContained ("9740-9742" , hist ))
165- histologyGroup = 12 ;
166- else if (Utils .isHistologyContained ("9750-9759" , hist ))
167- histologyGroup = 13 ;
168- else if (Utils .isHistologyContained ("9590-9591,9596,9727,9760,9800-9809,9820,9832,9835,9860,9960,9965-9975,9989" , hist ))
169- histologyGroup = 14 ;
170- else if (hist == 9140 )
171- histologyGroup = 15 ;
172- else if (Utils .isHistologyContained ("8720-8790,8930-8936,8950-8983,9000-9030,9060-9110,9260-9365,9380-9539" , hist ))
173- histologyGroup = 16 ;
174- else if (Utils .isHistologyContained ("8000-8005" , hist ))
175- histologyGroup = 17 ;
175+ for (Pair <List <Object >, Integer > pair : _HISTOLOGY_RANGES ) {
176+ if (Utils .isContained (pair .getLeft (), hist )) {
177+ histologyGroup = pair .getRight ();
178+ break ;
179+ }
180+ }
176181 }
177182
178183 return histologyGroup ;
@@ -204,18 +209,18 @@ private static boolean isNosVsSpecific(IarcMpInputRecordDto rec1, IarcMpInputRec
204209 //14 is NOS for 8-13
205210 //5 is NOS for 1-4
206211 return (rec1 .getHistGroup () == 17 && ((rec2 .getHistGroup () >= 1 && rec2 .getHistGroup () <= 7 ) || rec2 .getHistGroup () == 15 || rec2 .getHistGroup () == 16 )) ||
207- (rec2 .getHistGroup () == 17 && ((rec1 .getHistGroup () >= 1 && rec1 .getHistGroup () <= 7 ) || rec1 .getHistGroup () == 15 || rec1 .getHistGroup () == 16 )) ||
208- (rec1 .getHistGroup () == 14 && rec2 .getHistGroup () >= 8 && rec2 .getHistGroup () <= 13 ) ||
209- (rec2 .getHistGroup () == 14 && rec1 .getHistGroup () >= 8 && rec1 .getHistGroup () <= 13 ) ||
210- (rec1 .getHistGroup () == 5 && rec2 .getHistGroup () >= 1 && rec2 .getHistGroup () <= 4 ) ||
211- (rec2 .getHistGroup () == 5 && rec1 .getHistGroup () >= 1 && rec1 .getHistGroup () <= 4 );
212+ (rec2 .getHistGroup () == 17 && ((rec1 .getHistGroup () >= 1 && rec1 .getHistGroup () <= 7 ) || rec1 .getHistGroup () == 15 || rec1 .getHistGroup () == 16 )) ||
213+ (rec1 .getHistGroup () == 14 && rec2 .getHistGroup () >= 8 && rec2 .getHistGroup () <= 13 ) ||
214+ (rec2 .getHistGroup () == 14 && rec1 .getHistGroup () >= 8 && rec1 .getHistGroup () <= 13 ) ||
215+ (rec1 .getHistGroup () == 5 && rec2 .getHistGroup () >= 1 && rec2 .getHistGroup () <= 4 ) ||
216+ (rec2 .getHistGroup () == 5 && rec1 .getHistGroup () >= 1 && rec1 .getHistGroup () <= 4 );
212217 }
213218
214219 private static boolean needToUpdateHistology (IarcMpInputRecordDto primaryRec , IarcMpInputRecordDto dupRecord ) {
215220 return (primaryRec .getHistGroup () == 17 && ((dupRecord .getHistGroup () >= 1 && dupRecord .getHistGroup () <= 7 ) || dupRecord .getHistGroup () == 15 || dupRecord .getHistGroup () == 16 )) ||
216- (primaryRec .getHistGroup () == 14 && dupRecord .getHistGroup () >= 8 && dupRecord .getHistGroup () <= 13 ) ||
217- (primaryRec .getHistGroup () == 5 && dupRecord .getHistGroup () >= 1 && dupRecord .getHistGroup () <= 4 ) ||
218- (primaryRec .getHistGroup ().equals (dupRecord .getHistGroup ()) && NumberUtils .toInt (primaryRec .getHistology ()) < NumberUtils .toInt (dupRecord .getHistology ()));
221+ (primaryRec .getHistGroup () == 14 && dupRecord .getHistGroup () >= 8 && dupRecord .getHistGroup () <= 13 ) ||
222+ (primaryRec .getHistGroup () == 5 && dupRecord .getHistGroup () >= 1 && dupRecord .getHistGroup () <= 4 ) ||
223+ (primaryRec .getHistGroup ().equals (dupRecord .getHistGroup ()) && NumberUtils .toInt (primaryRec .getHistology ()) < NumberUtils .toInt (dupRecord .getHistology ()));
219224 }
220225
221226 private static class InternalRecDto implements Comparable <InternalRecDto > {
0 commit comments