|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 Information Management Services, Inc. |
| 3 | + */ |
| 4 | +package com.imsweb.seerapi.compare; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.Date; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.LinkedHashMap; |
| 11 | +import java.util.List; |
| 12 | +import java.util.Map; |
| 13 | +import java.util.Objects; |
| 14 | + |
| 15 | +import org.junit.jupiter.api.Disabled; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +import com.imsweb.seerapi.client.SeerApi; |
| 19 | +import com.imsweb.seerapi.client.disease.Disease; |
| 20 | +import com.imsweb.seerapi.client.disease.DiseaseSearchResults; |
| 21 | +import com.imsweb.seerapi.client.disease.DiseaseService; |
| 22 | +import com.imsweb.seerapi.client.glossary.Glossary; |
| 23 | +import com.imsweb.seerapi.client.glossary.GlossarySearchResults; |
| 24 | +import com.imsweb.seerapi.client.glossary.GlossaryService; |
| 25 | +import com.imsweb.seerapi.client.hcpcs.Hcpcs; |
| 26 | +import com.imsweb.seerapi.client.hcpcs.HcpcsService; |
| 27 | +import com.imsweb.seerapi.client.ndc.NdcProduct; |
| 28 | +import com.imsweb.seerapi.client.ndc.NdcService; |
| 29 | +import com.imsweb.seerapi.client.rx.Rx; |
| 30 | +import com.imsweb.seerapi.client.rx.RxSearchResults; |
| 31 | +import com.imsweb.seerapi.client.rx.RxService; |
| 32 | +import com.imsweb.seerapi.client.staging.StagingAlgorithm; |
| 33 | +import com.imsweb.seerapi.client.staging.StagingSchema; |
| 34 | +import com.imsweb.seerapi.client.staging.StagingSchemaInfo; |
| 35 | +import com.imsweb.seerapi.client.staging.StagingService; |
| 36 | +import com.imsweb.seerapi.client.staging.StagingTable; |
| 37 | +import com.imsweb.seerapi.client.staging.StagingVersion; |
| 38 | + |
| 39 | +import static org.assertj.core.api.Assertions.assertThat; |
| 40 | + |
| 41 | +@Disabled("Only for manual testing") |
| 42 | +class ComparisonTest { |
| 43 | + |
| 44 | + private static final String PROD_URL = "https://api.seer.cancer.gov/rest/"; |
| 45 | + private static final String LOCAL_URL = "http://localhost:8080/rest/"; |
| 46 | + |
| 47 | + private String getApiKey() { |
| 48 | + return System.getenv("TESTING_API_KEY"); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + void testNdc() throws IOException { |
| 53 | + NdcService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().ndc(); |
| 54 | + NdcService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().ndc(); |
| 55 | + |
| 56 | + long page = 1; |
| 57 | + long processed = 0; |
| 58 | + |
| 59 | + Map<String, String> params = new HashMap<>(); |
| 60 | + params.put("page", String.valueOf(page)); |
| 61 | + params.put("per_page", "100"); |
| 62 | + params.put("order", "ndc"); |
| 63 | + List<NdcProduct> prodList = prodService.search(params).execute().body(); |
| 64 | + List<NdcProduct> localList = localService.search(params).execute().body(); |
| 65 | + |
| 66 | + while (!Objects.requireNonNull(prodList).isEmpty() && !Objects.requireNonNull(localList).isEmpty()) { |
| 67 | + processed += prodList.size(); |
| 68 | + assertThat(localList) |
| 69 | + .hasSameSizeAs(prodList) // Ensure both lists have the same size |
| 70 | + .usingRecursiveComparison() |
| 71 | + .isEqualTo(prodList); |
| 72 | + |
| 73 | + System.out.println("NDC page " + page + " (processed " + processed + " so far)"); |
| 74 | + |
| 75 | + page += 1; |
| 76 | + params.put("page", String.valueOf(page)); |
| 77 | + prodList = prodService.search(params).execute().body(); |
| 78 | + localList = localService.search(params).execute().body(); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + void testHcpcs() throws IOException { |
| 84 | + HcpcsService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().hcpcs(); |
| 85 | + HcpcsService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().hcpcs(); |
| 86 | + |
| 87 | + long processed = 0; |
| 88 | + long page = 1; |
| 89 | + |
| 90 | + Map<String, String> params = new HashMap<>(); |
| 91 | + params.put("page", String.valueOf(page)); |
| 92 | + params.put("per_page", "100"); |
| 93 | + params.put("order", "hcpcs_code"); |
| 94 | + |
| 95 | + List<Hcpcs> prodList = prodService.search(params).execute().body(); |
| 96 | + List<Hcpcs> localList = localService.search(params).execute().body(); |
| 97 | + |
| 98 | + while (!Objects.requireNonNull(prodList).isEmpty()) { |
| 99 | + processed += prodList.size(); |
| 100 | + System.out.println("HCPCS page " + page + " (processed " + processed + " so far)"); |
| 101 | + |
| 102 | + assertThat(localList) |
| 103 | + .hasSameSizeAs(prodList) // Ensure both lists have the same size |
| 104 | + .usingRecursiveComparison() |
| 105 | + .ignoringCollectionOrderInFields("categories") |
| 106 | + .isEqualTo(prodList); |
| 107 | + |
| 108 | + page += 1; |
| 109 | + params.put("page", String.valueOf(page)); |
| 110 | + prodList = prodService.search(params).execute().body(); |
| 111 | + localList = localService.search(params).execute().body(); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + private Map<String, String> getAlgorithmVersions() { |
| 116 | + Map<String, String> versions = new LinkedHashMap<>(); |
| 117 | + |
| 118 | + versions.put("pediatric", "1.2"); |
| 119 | + versions.put("eod_public", "3.2"); |
| 120 | + versions.put("tnm", "2.0"); |
| 121 | + versions.put("cs", "02.05.50"); |
| 122 | + |
| 123 | + return versions; |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + void testStagingAlgorithmsAndVersions() throws IOException { |
| 128 | + StagingService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().staging(); |
| 129 | + StagingService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().staging(); |
| 130 | + |
| 131 | + List<StagingAlgorithm> prodAlgorithms = prodService.algorithms().execute().body(); |
| 132 | + List<StagingAlgorithm> localAlgorithms = localService.algorithms().execute().body(); |
| 133 | + |
| 134 | + assertThat(localAlgorithms) |
| 135 | + .hasSameSizeAs(prodAlgorithms) // Ensure both lists have the same size |
| 136 | + .usingRecursiveComparison() |
| 137 | + .isEqualTo(prodAlgorithms); |
| 138 | + |
| 139 | + for (StagingAlgorithm algorithm : Objects.requireNonNull(prodAlgorithms)) { |
| 140 | + List<StagingVersion> prodVersions = prodService.versions(algorithm.getAlgorithm()).execute().body(); |
| 141 | + List<StagingVersion> localVersions = localService.versions(algorithm.getAlgorithm()).execute().body(); |
| 142 | + |
| 143 | + assertThat(localVersions) |
| 144 | + .hasSameSizeAs(prodVersions) |
| 145 | + .usingRecursiveComparison() |
| 146 | + .isEqualTo(prodVersions); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + void testStagingSchemas() throws IOException { |
| 152 | + StagingService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().staging(); |
| 153 | + StagingService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().staging(); |
| 154 | + |
| 155 | + Map<String, String> algorithmMap = getAlgorithmVersions(); |
| 156 | + for (String algorithmId : algorithmMap.keySet()) { |
| 157 | + String algorithmVersion = algorithmMap.get(algorithmId); |
| 158 | + |
| 159 | + System.out.println("Getting list of all schemas in " + algorithmId + ":" + algorithmVersion); |
| 160 | + |
| 161 | + List<StagingSchemaInfo> prodSchemas = prodService.schemas(algorithmId, algorithmVersion).execute().body(); |
| 162 | + List<StagingSchemaInfo> localSchemas = localService.schemas(algorithmId, algorithmVersion).execute().body(); |
| 163 | + |
| 164 | + assertThat(localSchemas) |
| 165 | + .hasSameSizeAs(prodSchemas) // Ensure both lists have the same size |
| 166 | + .usingRecursiveComparison() |
| 167 | + .ignoringCollectionOrder() |
| 168 | + .isEqualTo(prodSchemas); |
| 169 | + |
| 170 | + for (StagingSchemaInfo prodSchema : Objects.requireNonNull(prodSchemas)) { |
| 171 | + StagingSchema prod = prodService.schemaById(algorithmId, algorithmVersion, prodSchema.getId()).execute().body(); |
| 172 | + StagingSchema local = localService.schemaById(algorithmId, algorithmVersion, prodSchema.getId()).execute().body(); |
| 173 | + |
| 174 | + System.out.println("Comparing [" + algorithmId + ":" + algorithmVersion + "] schema " + prodSchema.getId()); |
| 175 | + |
| 176 | + assertThat(local) |
| 177 | + .usingRecursiveComparison() |
| 178 | + .ignoringCollectionOrder() |
| 179 | + .withComparatorForType( |
| 180 | + (date1, date2) -> { |
| 181 | + // ignore milliseconds when comparing two Date objects |
| 182 | + long time1 = date1.getTime() / 1000; |
| 183 | + long time2 = date2.getTime() / 1000; |
| 184 | + return Long.compare(time1, time2); |
| 185 | + }, |
| 186 | + Date.class |
| 187 | + ) |
| 188 | + .isEqualTo(prod); |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + void testStagingTables() throws IOException { |
| 195 | + StagingService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().staging(); |
| 196 | + StagingService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().staging(); |
| 197 | + |
| 198 | + Map<String, String> algorithmMap = getAlgorithmVersions(); |
| 199 | + for (String algorithmId : algorithmMap.keySet()) { |
| 200 | + String algorithmVersion = algorithmMap.get(algorithmId); |
| 201 | + |
| 202 | + System.out.println("Getting list of all tables in " + algorithmId + ":" + algorithmVersion); |
| 203 | + |
| 204 | + List<StagingTable> prodTables = prodService.tables(algorithmId, algorithmVersion).execute().body(); |
| 205 | + List<StagingTable> localTables = localService.tables(algorithmId, algorithmVersion).execute().body(); |
| 206 | + |
| 207 | + assertThat(localTables) |
| 208 | + .hasSameSizeAs(prodTables) // Ensure both lists have the same size |
| 209 | + .usingRecursiveComparison() |
| 210 | + .ignoringCollectionOrder() |
| 211 | + .isEqualTo(prodTables); |
| 212 | + |
| 213 | + for (StagingTable prodTable : Objects.requireNonNull(prodTables)) { |
| 214 | + StagingTable prod = prodService.tableById(algorithmId, algorithmVersion, prodTable.getId()).execute().body(); |
| 215 | + StagingTable local = localService.tableById(algorithmId, algorithmVersion, prodTable.getId()).execute().body(); |
| 216 | + |
| 217 | + System.out.println("Comparing [" + algorithmId + ":" + algorithmVersion + "] table " + prodTable.getId()); |
| 218 | + |
| 219 | + assertThat(local) |
| 220 | + .usingRecursiveComparison() |
| 221 | + .withComparatorForType( |
| 222 | + (date1, date2) -> { |
| 223 | + // ignore milliseconds when comparing two Date objects |
| 224 | + long time1 = date1.getTime() / 1000; |
| 225 | + long time2 = date2.getTime() / 1000; |
| 226 | + return Long.compare(time1, time2); |
| 227 | + }, |
| 228 | + Date.class |
| 229 | + ) |
| 230 | + .isEqualTo(prod); |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + @Test |
| 236 | + void testGlossary() throws IOException { |
| 237 | + GlossaryService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().glossary(); |
| 238 | + GlossaryService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().glossary(); |
| 239 | + |
| 240 | + Map<String, String> params = new HashMap<>(); |
| 241 | + |
| 242 | + long offset = 0; |
| 243 | + long perPage = 100; |
| 244 | + params.put("offset", String.valueOf(offset)); |
| 245 | + params.put("count", String.valueOf(perPage)); |
| 246 | + |
| 247 | + // get a list of ids |
| 248 | + List<String> ids = new ArrayList<>(); |
| 249 | + |
| 250 | + System.out.println("Collecting identifiers for glossary 'latest' version"); |
| 251 | + |
| 252 | + GlossarySearchResults prod = prodService.search("latest", params).execute().body(); |
| 253 | + |
| 254 | + while (Objects.requireNonNull(prod).getResults() != null && !prod.getResults().isEmpty()) { |
| 255 | + for (Glossary glossary : prod.getResults()) |
| 256 | + ids.add(glossary.getId()); |
| 257 | + |
| 258 | + offset += perPage; |
| 259 | + params.put("offset", String.valueOf(offset)); |
| 260 | + |
| 261 | + prod = prodService.search("latest", params).execute().body(); |
| 262 | + } |
| 263 | + |
| 264 | + System.out.println("Found " + ids.size() + " identifiers for glossary 'latest' version"); |
| 265 | + |
| 266 | + for (String id : ids) { |
| 267 | + System.out.println("Comparing " + id); |
| 268 | + Glossary prodGlossary = prodService.getById("latest", id).execute().body(); |
| 269 | + Glossary localGlossary = localService.getById("latest", id).execute().body(); |
| 270 | + |
| 271 | + assertThat(localGlossary) |
| 272 | + .usingRecursiveComparison() |
| 273 | + .isEqualTo(prodGlossary); |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + @Test |
| 278 | + void testRx() throws IOException { |
| 279 | + RxService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().rx(); |
| 280 | + RxService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().rx(); |
| 281 | + |
| 282 | + Map<String, String> params = new HashMap<>(); |
| 283 | + |
| 284 | + long offset = 0; |
| 285 | + long perPage = 100; |
| 286 | + params.put("offset", String.valueOf(offset)); |
| 287 | + params.put("count", String.valueOf(perPage)); |
| 288 | + |
| 289 | + // get a list of ids |
| 290 | + List<String> ids = new ArrayList<>(); |
| 291 | + |
| 292 | + System.out.println("Collecting identifiers for rx 'latest' version"); |
| 293 | + |
| 294 | + RxSearchResults prod = prodService.search("latest", params).execute().body(); |
| 295 | + |
| 296 | + while (Objects.requireNonNull(prod).getResults() != null && !prod.getResults().isEmpty()) { |
| 297 | + for (Rx rx : prod.getResults()) |
| 298 | + ids.add(rx.getId()); |
| 299 | + |
| 300 | + offset += perPage; |
| 301 | + params.put("offset", String.valueOf(offset)); |
| 302 | + |
| 303 | + prod = prodService.search("latest", params).execute().body(); |
| 304 | + } |
| 305 | + |
| 306 | + System.out.println("Found " + ids.size() + " identifiers for rx 'latest' version"); |
| 307 | + |
| 308 | + for (String id : ids) { |
| 309 | + System.out.println("Comparing " + id); |
| 310 | + Rx prodRx = prodService.getById("latest", id).execute().body(); |
| 311 | + Rx localRx = localService.getById("latest", id).execute().body(); |
| 312 | + |
| 313 | + assertThat(localRx) |
| 314 | + .usingRecursiveComparison() |
| 315 | + .isEqualTo(prodRx); |
| 316 | + } |
| 317 | + } |
| 318 | + |
| 319 | + @Test |
| 320 | + void testDisease() throws IOException { |
| 321 | + DiseaseService prodService = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().disease(); |
| 322 | + DiseaseService localService = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().disease(); |
| 323 | + |
| 324 | + Map<String, String> params = new HashMap<>(); |
| 325 | + |
| 326 | + long offset = 0; |
| 327 | + long perPage = 100; |
| 328 | + params.put("offset", String.valueOf(offset)); |
| 329 | + params.put("count", String.valueOf(perPage)); |
| 330 | + |
| 331 | + // get a list of ids |
| 332 | + List<String> ids = new ArrayList<>(); |
| 333 | + |
| 334 | + System.out.println("Collecting identifiers for disease 'latest' version"); |
| 335 | + |
| 336 | + DiseaseSearchResults prod = prodService.search("latest", params).execute().body(); |
| 337 | + |
| 338 | + while (Objects.requireNonNull(prod).getResults() != null && !prod.getResults().isEmpty()) { |
| 339 | + for (Disease disease : prod.getResults()) |
| 340 | + ids.add(disease.getId()); |
| 341 | + |
| 342 | + offset += perPage; |
| 343 | + params.put("offset", String.valueOf(offset)); |
| 344 | + |
| 345 | + prod = prodService.search("latest", params).execute().body(); |
| 346 | + } |
| 347 | + |
| 348 | + System.out.println("Found " + ids.size() + " identifiers for disease 'latest' version"); |
| 349 | + |
| 350 | + for (String id : ids) { |
| 351 | + System.out.println("Comparing " + id); |
| 352 | + Disease prodDisease = prodService.getById("latest", id).execute().body(); |
| 353 | + Disease localDisease = localService.getById("latest", id).execute().body(); |
| 354 | + |
| 355 | + assertThat(localDisease) |
| 356 | + .usingRecursiveComparison() |
| 357 | + .isEqualTo(prodDisease); |
| 358 | + } |
| 359 | + } |
| 360 | +} |
0 commit comments