From beca90014d81521c62788740377fb5f1bd049395 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 12 Jul 2024 08:56:01 -0700 Subject: [PATCH 1/2] MAT-7348: Revision. Fix double encoding. Manually construct Query String --- .../FhirTerminologyServiceWebClient.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java index 6082d01..56a7aab 100644 --- a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java +++ b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java @@ -20,8 +20,12 @@ import reactor.core.publisher.Mono; import java.net.URI; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Map; +import java.util.stream.Collectors; @Component @Slf4j @@ -73,19 +77,22 @@ public String searchValueSets(String apiKey, Map queryParams) { if (!urlValue.startsWith("http://cts.nlm.nih.gov/fhir/ValueSet/")) { urlValue = "http://cts.nlm.nih.gov/fhir/ValueSet/" + urlValue; } - // if user didnt add htpp:// we do + // if user didn't add http:// we do if (!urlValue.startsWith("http://")) { urlValue = "http://" + urlValue; } queryParams.put("url", urlValue); } - MultiValueMap multiValueMap = new LinkedMultiValueMap<>(); - multiValueMap.setAll(queryParams); - URI uri = - UriComponentsBuilder.fromUriString(searchValueSetEndpoint) - .queryParams(multiValueMap) - .build() - .toUri(); + + // Manually construct the query string + String queryString = queryParams.entrySet().stream() + .map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) + .collect(Collectors.joining("&")); + + String url = searchValueSetEndpoint + "?" + queryString; + + URI uri = URI.create(url); + log.info("value set search url is: {}", uri.toString()); return fetchResourceFromVsac(uri.toString(), apiKey, "bundle"); } @@ -114,6 +121,8 @@ public String getCodeResource(String code, CodeSystem codeSystem, String apiKey) } private String fetchResourceFromVsac(String uri, String apiKey, String resourceType) { + var currentUri = uri; + log.info("[{}] currentUri is", currentUri); return fhirTerminologyWebClient .get() .uri(uri) From d2bdf155cc8f4f54ed6d874e7c73b65391a5846d Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 12 Jul 2024 09:22:54 -0700 Subject: [PATCH 2/2] MAT-7348: Remove dead code --- .../webclient/FhirTerminologyServiceWebClient.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java index 56a7aab..4e04c7d 100644 --- a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java +++ b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java @@ -13,14 +13,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Mono; import java.net.URI; -import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -85,8 +82,13 @@ public String searchValueSets(String apiKey, Map queryParams) { } // Manually construct the query string - String queryString = queryParams.entrySet().stream() - .map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) + String queryString = + queryParams.entrySet().stream() + .map( + entry -> + URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + + "=" + + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) .collect(Collectors.joining("&")); String url = searchValueSetEndpoint + "?" + queryString; @@ -121,8 +123,6 @@ public String getCodeResource(String code, CodeSystem codeSystem, String apiKey) } private String fetchResourceFromVsac(String uri, String apiKey, String resourceType) { - var currentUri = uri; - log.info("[{}] currentUri is", currentUri); return fhirTerminologyWebClient .get() .uri(uri)