|
1 | 1 | /*
|
2 |
| - * Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg |
| 2 | + * Copyright 2021-2022 B2i Healthcare Pte Ltd, http://b2i.sg |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
15 | 15 | */
|
16 | 16 | package com.b2international.snowowl.fhir.rest;
|
17 | 17 |
|
18 |
| -import org.springframework.util.StringUtils; |
19 | 18 | import org.springframework.web.bind.annotation.*;
|
20 | 19 |
|
| 20 | +import com.b2international.commons.StringUtils; |
21 | 21 | import com.b2international.snowowl.core.events.util.Promise;
|
22 | 22 | import com.b2international.snowowl.fhir.core.exceptions.BadRequestException;
|
23 | 23 | import com.b2international.snowowl.fhir.core.model.codesystem.SubsumptionRequest;
|
@@ -190,51 +190,48 @@ private void validateSubsumptionRequest(String codeSystemId, String codeA, Strin
|
190 | 190 |
|
191 | 191 | private void validateSubsumptionRequest(String codeSystemId, String codeA, String codeB, String system, String version, Coding codingA, Coding codingB) {
|
192 | 192 |
|
193 |
| - //check the systems |
| 193 | + // check the systems |
194 | 194 | if (StringUtils.isEmpty(system) && StringUtils.isEmpty(codeSystemId)) {
|
195 | 195 | throw new BadRequestException("Parameter 'system' is not specified for subsumption testing.", "SubsumptionRequest.system");
|
196 | 196 | }
|
197 | 197 |
|
198 |
| - //TODO: this probably incorrect as codeSystemId is an internal id vs. system that is external |
199 |
| - if (!StringUtils.isEmpty(system) && !StringUtils.isEmpty(codeSystemId)) { |
200 |
| - if (!codeSystemId.equals(system)) { |
201 |
| - throw new BadRequestException(String.format("Parameter 'system: %s' and path parameter 'codeSystem: %s' are not the same.", system, codeSystemId), "SubsumptionRequest.system"); |
202 |
| - } |
203 |
| - } |
204 |
| - |
205 |
| - //all empty |
206 |
| - if (StringUtils.isEmpty(codeA) && StringUtils.isEmpty(codeA) && codingA == null && codingB == null) { |
207 |
| - throw new BadRequestException("No codes or Codings are provided for subsumption testing.", "SubsumptionRequest"); |
| 198 | + // TODO: this probably incorrect as codeSystemId is an internal id vs. system that is external |
| 199 | + if (!StringUtils.isEmpty(system) && !StringUtils.isEmpty(codeSystemId) && !codeSystemId.equals(system)) { |
| 200 | + throw new BadRequestException(String.format("Parameter 'system: %s' and path parameter 'codeSystem: %s' are not the same.", system, codeSystemId), "SubsumptionRequest.system"); |
208 | 201 | }
|
209 | 202 |
|
210 |
| - //No codes |
211 |
| - if (StringUtils.isEmpty(codeA) && StringUtils.isEmpty(codeA)) { |
| 203 | + if (StringUtils.isEmpty(codeA) && StringUtils.isEmpty(codeB)) { |
| 204 | + // No codes and no codings |
| 205 | + if (codingA == null && codingB == null) { |
| 206 | + throw new BadRequestException("No codes or Codings are provided for subsumption testing.", "SubsumptionRequest"); |
| 207 | + } |
| 208 | + |
| 209 | + // One coding is present, but the other is missing (both can not be missing as it was handled above) |
212 | 210 | if (codingA == null || codingB == null) {
|
213 | 211 | throw new BadRequestException("No Codings are provided for subsumption testing.", "SubsumptionRequest.Coding");
|
214 | 212 | }
|
215 |
| - } |
216 |
| - |
217 |
| - //No codings |
218 |
| - if (codingA == null && codingB == null) { |
219 |
| - if (StringUtils.isEmpty(codeA) || StringUtils.isEmpty(codeB)) { |
220 |
| - throw new BadRequestException("No codes are provided for subsumption testing.", "SubsumptionRequest.code"); |
221 |
| - } |
222 |
| - } |
223 |
| - |
224 |
| - //Codes are there |
225 |
| - if (!StringUtils.isEmpty(codeA) && !StringUtils.isEmpty(codeA)) { |
| 213 | + |
| 214 | + // Both codings are present at this point |
| 215 | + |
| 216 | + } else { |
| 217 | + |
| 218 | + // Some codes were provided, but a coding is also present, ambiguous |
226 | 219 | if (codingA != null || codingB != null) {
|
227 | 220 | throw new BadRequestException("Provide either codes or Codings.", "SubsumptionRequest");
|
228 | 221 | }
|
229 |
| - } |
230 |
| - |
231 |
| - //Coding are there |
232 |
| - if (codingA != null && codingB != null) { |
233 |
| - if (!StringUtils.isEmpty(codeA) || !StringUtils.isEmpty(codeA)) { |
234 |
| - throw new BadRequestException("Provide either codes or Codings.", "SubsumptionRequest"); |
| 222 | + |
| 223 | + // One code is present, but the other is missing (both can not be missing as it was handled in the outer "if" block above) |
| 224 | + if (StringUtils.isEmpty(codeA) || StringUtils.isEmpty(codeB)) { |
| 225 | + throw new BadRequestException("No codes are provided for subsumption testing.", "SubsumptionRequest.code"); |
235 | 226 | }
|
| 227 | + |
| 228 | + // Both codes are present at this point |
236 | 229 | }
|
237 |
| - } |
238 | 230 |
|
239 |
| - |
| 231 | + // Check system (URL) against version |
| 232 | + if (!StringUtils.isEmpty(system) && !StringUtils.isEmpty(version) && !system.endsWith("/" + version)) { |
| 233 | + throw new BadRequestException(String.format("Version specified in the URI [%s] does not match the version set in the request [%s]", |
| 234 | + system, version)); |
| 235 | + } |
| 236 | + } |
240 | 237 | }
|
0 commit comments