Skip to content

Commit

Permalink
Merge pull request #96 from MeasureAuthoringTool/MAT-7438
Browse files Browse the repository at this point in the history
MAT-7348: Revision. Fix double encoding. Manually construct Query String
  • Loading branch information
mcmcphillips authored Jul 15, 2024
2 parents b47cf36 + d2bdf15 commit 63624f4
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
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.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.stream.Collectors;

@Component
@Slf4j
Expand Down Expand Up @@ -73,19 +74,27 @@ public String searchValueSets(String apiKey, Map<String, String> 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<String, String> 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");
}
Expand Down

0 comments on commit 63624f4

Please sign in to comment.