Skip to content

Commit

Permalink
Merge branch 'develop' into MAT-7947
Browse files Browse the repository at this point in the history
  • Loading branch information
ethankaplan authored Dec 9, 2024
2 parents 987d1f3 + ad0b646 commit aab54b1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-rest-commons</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
Expand Down
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 @@ -316,13 +316,15 @@ && isEmpty(group.getStratificationValues()))

// Mismatch between target and import Stratification, don't set any expected values
boolean measureHasStrats =
measureGroups.stream().allMatch(group -> isNotEmpty(group.getStratifications()));
measureGroups != null
? measureGroups.stream().allMatch(group -> isNotEmpty(group.getStratifications()))
: false;
if ((measureHasStrats && isEmpty(stratification))
|| (!measureHasStrats && isNotEmpty(stratification))) {
return null;
}

if (measureGroups.size() > 1 && isNotEmpty(stratification)) {
if (measureGroups != null && measureGroups.size() > 1 && isNotEmpty(stratification)) {
Deque<TestCaseStratificationValue> stratificationQueue = new ArrayDeque<>(stratification);
try {
do {
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 @@ -36,8 +39,13 @@ class ElmTranslatorClientTest {

@InjectMocks private ElmTranslatorClient elmTranslatorClient;

private final String HEADER_1 = "api-key";

@BeforeEach
void beforeEach() {
lenient()
.when(elmTranslatorClientConfig.getFhirCqlElmServiceBaseUrl())
.thenReturn("http://test");
lenient()
.when(elmTranslatorClientConfig.getQdmCqlElmServiceBaseUrl())
.thenReturn("http://test");
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");
}
}

0 comments on commit aab54b1

Please sign in to comment.