Skip to content

Commit

Permalink
MAT-7348: Revision. Fix double encoding. Manually construct Query String
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Jul 12, 2024
1 parent ec5e919 commit a8b5490
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,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
Expand Down Expand Up @@ -72,19 +76,22 @@ 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 Expand Up @@ -113,6 +120,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)
Expand Down

0 comments on commit a8b5490

Please sign in to comment.