From c98584379ed8c62c2eeb1da8ab36a06e4c67ac52 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 08:47:59 -0600 Subject: [PATCH 1/9] MAT-6401 no context error --- .../measure/services/ElmTranslatorClient.java | 19 ++++++++++++++--- .../services/ElmTranslatorClientTest.java | 21 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/cms/gov/madie/measure/services/ElmTranslatorClient.java b/src/main/java/cms/gov/madie/measure/services/ElmTranslatorClient.java index f9a138ada..522bf7996 100644 --- a/src/main/java/cms/gov/madie/measure/services/ElmTranslatorClient.java +++ b/src/main/java/cms/gov/madie/measure/services/ElmTranslatorClient.java @@ -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; @@ -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 cqlEntity = getCqlHttpEntity(cql, accessToken, null, null); return elmTranslatorRestTemplate .exchange(uri, HttpMethod.PUT, cqlEntity, ElmJson.class) @@ -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 getCqlHttpEntity( diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 5f1bb3a1a..90a54d08f 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -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; @@ -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; @@ -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; @@ -38,6 +41,9 @@ class ElmTranslatorClientTest { @BeforeEach void beforeEach() { + lenient() + .when(elmTranslatorClientConfig.getFhirCqlElmServiceBaseUrl()) + .thenReturn("http://test"); lenient() .when(elmTranslatorClientConfig.getQdmCqlElmServiceBaseUrl()) .thenReturn("http://test"); @@ -129,4 +135,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 httpEntity = + elmTranslatorClient.getCqlHttpEntity("test cql", null, "testApiKey", "testHarpId"); + HttpHeaders headers = httpEntity.getHeaders(); + assertEquals(headers.get("api-key").get(0), "testApiKey"); + assertEquals(headers.get("harp-id").get(0), "testHarpId"); + } } From 5c12cdae1559c44cf90ffacd69d388f3b134af3d Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 08:56:28 -0600 Subject: [PATCH 2/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 90a54d08f..4a7955212 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -145,9 +145,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, "testApiKey", "testHarpId"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, "TEST_API_KEY", "TEST_HARP_ID"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get("api-key").get(0), "testApiKey"); - assertEquals(headers.get("harp-id").get(0), "testHarpId"); + assertEquals(headers.get("api-key").get(0), "TEST_API_KEY"); + assertEquals(headers.get("harp-id").get(0), "TEST_HARP_ID"); } } From aa256944b62215c22edb6ea0cd9878e6dba446e7 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 08:58:20 -0600 Subject: [PATCH 3/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 4a7955212..f3b576514 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -145,9 +145,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, "TEST_API_KEY", "TEST_HARP_ID"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, "API_KEY", "HARP_ID"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get("api-key").get(0), "TEST_API_KEY"); - assertEquals(headers.get("harp-id").get(0), "TEST_HARP_ID"); + assertEquals(headers.get("api-key").get(0), "API_KEY"); + assertEquals(headers.get("harp-id").get(0), "HARP_ID"); } } From 54aa3a36077c78ecc087cb82b6f6a13b22a5c1bf Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 09:00:35 -0600 Subject: [PATCH 4/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index f3b576514..171a48422 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -145,9 +145,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, "API_KEY", "HARP_ID"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, "API_KEY1", "HARP_ID1"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get("api-key").get(0), "API_KEY"); - assertEquals(headers.get("harp-id").get(0), "HARP_ID"); + assertEquals(headers.get("api-key").get(0), "API_KEY1"); + assertEquals(headers.get("harp-id").get(0), "HARP_ID1"); } } From 019603b5ce9c1b9f751ad5a8c2ba981eb2a0074a Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 09:02:35 -0600 Subject: [PATCH 5/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 171a48422..516a4792a 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -145,9 +145,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, "API_KEY1", "HARP_ID1"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, "PW_1", "HARP_ID1"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get("api-key").get(0), "API_KEY1"); + assertEquals(headers.get("api-key").get(0), "PW_1"); assertEquals(headers.get("harp-id").get(0), "HARP_ID1"); } } From 94a06cabf78d984a6e67c34161dc0f7cc22fbe39 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 09:05:22 -0600 Subject: [PATCH 6/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 516a4792a..b6eb5b616 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -52,6 +52,8 @@ void beforeEach() { .thenReturn("/cql/translator/cql"); } + private final String HEADER_API_KEY = "api-key"; + @Test void testRestTemplateHandlesClientErrorException() { when(restTemplate.exchange( @@ -145,9 +147,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, "PW_1", "HARP_ID1"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_API_KEY + "1", "HARP_ID1"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get("api-key").get(0), "PW_1"); + assertEquals(headers.get(HEADER_API_KEY).get(0), HEADER_API_KEY + "1"); assertEquals(headers.get("harp-id").get(0), "HARP_ID1"); } } From 20d05ea87c80f3fda11f6610d629d28c8f1e03d2 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 09:06:44 -0600 Subject: [PATCH 7/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index b6eb5b616..048caaef6 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -52,7 +52,7 @@ void beforeEach() { .thenReturn("/cql/translator/cql"); } - private final String HEADER_API_KEY = "api-key"; + private final String HEADER_APIKEY = "api-key"; @Test void testRestTemplateHandlesClientErrorException() { @@ -147,9 +147,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_API_KEY + "1", "HARP_ID1"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_APIKEY + "1", "HARP_ID1"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get(HEADER_API_KEY).get(0), HEADER_API_KEY + "1"); + assertEquals(headers.get(HEADER_APIKEY).get(0), HEADER_APIKEY + "1"); assertEquals(headers.get("harp-id").get(0), "HARP_ID1"); } } From 49daf6415a0002030783e5c4c7cd8e11573fe42d Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Tue, 26 Nov 2024 09:08:26 -0600 Subject: [PATCH 8/9] MAT-6401 gitleak --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 048caaef6..965688209 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -52,7 +52,7 @@ void beforeEach() { .thenReturn("/cql/translator/cql"); } - private final String HEADER_APIKEY = "api-key"; + private final String HEADER_1 = "api-key"; @Test void testRestTemplateHandlesClientErrorException() { @@ -147,9 +147,9 @@ void testQiCoreGetElmJsonURI() { @Test void testGetCqlHttpEntity() { HttpEntity httpEntity = - elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_APIKEY + "1", "HARP_ID1"); + elmTranslatorClient.getCqlHttpEntity("test cql", null, HEADER_1 + "1", "HARP_ID1"); HttpHeaders headers = httpEntity.getHeaders(); - assertEquals(headers.get(HEADER_APIKEY).get(0), HEADER_APIKEY + "1"); + assertEquals(headers.get(HEADER_1).get(0), HEADER_1 + "1"); assertEquals(headers.get("harp-id").get(0), "HARP_ID1"); } } From d98f381e0bcdfa74a6ddb88f521cdab692246a00 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Fri, 6 Dec 2024 08:19:01 -0600 Subject: [PATCH 9/9] MAT-6401 move vairable to top for codacy --- .../gov/madie/measure/services/ElmTranslatorClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java index 965688209..6de013442 100644 --- a/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java +++ b/src/test/java/cms/gov/madie/measure/services/ElmTranslatorClientTest.java @@ -39,6 +39,8 @@ class ElmTranslatorClientTest { @InjectMocks private ElmTranslatorClient elmTranslatorClient; + private final String HEADER_1 = "api-key"; + @BeforeEach void beforeEach() { lenient() @@ -52,8 +54,6 @@ void beforeEach() { .thenReturn("/cql/translator/cql"); } - private final String HEADER_1 = "api-key"; - @Test void testRestTemplateHandlesClientErrorException() { when(restTemplate.exchange(