Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-6401 no context error #753

Merged
merged 17 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;

Expand All @@ -28,7 +29,7 @@ public class ElmTranslatorClient {

public ElmJson getElmJson(final String cql, String measureModel, String accessToken) {
try {
URI uri = getElmJsonURI(measureModel, false);
URI uri = getElmJsonURI(measureModel);
HttpEntity<String> cqlEntity = getCqlHttpEntity(cql, accessToken, null, null);
return elmTranslatorRestTemplate
.exchange(uri, HttpMethod.PUT, cqlEntity, ElmJson.class)
Expand All @@ -55,13 +56,25 @@ public boolean hasErrors(ElmJson elmJson) {
}
}

protected URI getElmJsonURI(String measureModel, boolean isForMatTransferred) {
protected URI getElmJsonURI(String measureModel) {
var isQdm = StringUtils.equals(measureModel, ModelType.QDM_5_6.getValue());
String baseUrl =
isQdm
? elmTranslatorClientConfig.getQdmCqlElmServiceBaseUrl()
: elmTranslatorClientConfig.getFhirCqlElmServiceBaseUrl();
return URI.create(baseUrl + elmTranslatorClientConfig.getCqlElmServiceElmJsonUri());
URI uri = null;
if (!isQdm) {
uri =
UriComponentsBuilder.fromHttpUrl(
baseUrl + elmTranslatorClientConfig.getCqlElmServiceElmJsonUri())
.queryParam("checkContext", true)
.build()
.encode()
.toUri();
} else {
uri = URI.create(baseUrl + elmTranslatorClientConfig.getCqlElmServiceElmJsonUri());
}
return uri;
}

protected HttpEntity<String> getCqlHttpEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cms.gov.madie.measure.config.ElmTranslatorClientConfig;
import cms.gov.madie.measure.exceptions.CqlElmTranslationServiceException;
import gov.cms.madie.models.common.ModelType;
import gov.cms.madie.models.measure.ElmJson;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -11,6 +12,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -22,6 +24,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -38,6 +41,9 @@ class ElmTranslatorClientTest {

@BeforeEach
void beforeEach() {
lenient()
.when(elmTranslatorClientConfig.getFhirCqlElmServiceBaseUrl())
.thenReturn("http://test");
lenient()
.when(elmTranslatorClientConfig.getQdmCqlElmServiceBaseUrl())
.thenReturn("http://test");
Expand All @@ -46,6 +52,8 @@ void beforeEach() {
.thenReturn("/cql/translator/cql");
}

private final String HEADER_1 = "api-key";
adongare marked this conversation as resolved.
Show resolved Hide resolved

@Test
void testRestTemplateHandlesClientErrorException() {
when(restTemplate.exchange(
Expand Down Expand Up @@ -129,4 +137,19 @@ void testHasErrorsReturnsFalseForMissingField() {
boolean output = elmTranslatorClient.hasErrors(elmJson);
assertThat(output, is(false));
}

@Test
void testQiCoreGetElmJsonURI() {
URI uri = elmTranslatorClient.getElmJsonURI(ModelType.QI_CORE.getValue());
assertEquals("http://test/cql/translator/cql?checkContext=true", uri.toString());
}

@Test
void testGetCqlHttpEntity() {
HttpEntity<String> httpEntity =
elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_1 + "1", "HARP_ID1");
HttpHeaders headers = httpEntity.getHeaders();
assertEquals(headers.get(HEADER_1).get(0), HEADER_1 + "1");
assertEquals(headers.get("harp-id").get(0), "HARP_ID1");
}
}
Loading