Skip to content

Commit

Permalink
Merge pull request #75 from MeasureAuthoringTool/feature/MAT-7054_v2
Browse files Browse the repository at this point in the history
MAT-7054 Need different env variable for different services of elm tr…
  • Loading branch information
RohitKandimalla authored Jun 4, 2024
2 parents 25cde64 + c7045b5 commit b6b1a60
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
@Configuration
public class EnvironmentConfig {

@Value("${madie.cql-elm.service.base-url}")
private String cqlElmServiceBaseUrl;
@Value("${madie.cql-elm.service.qdm-base-url}")
private String qdmCqlElmServiceBaseUrl;

@Value("${madie.cql-elm.service.fhir-base-url}")
private String fhirCqlElmServiceBaseUrl;

@Value("${madie.cql-elm.service.elm-json-uri}")
private String cqlElmServiceElmJsonUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ public class ElmTranslatorClient {

public ElmJson getElmJson(final String cql, String libraryModel, String accessToken) {
try {
URI uri =
URI.create(
environmentConfig.getCqlElmServiceBaseUrl()
+ (StringUtils.equals(libraryModel, ModelType.QDM_5_6.getValue())
? "/qdm"
: "/fhir")
+ environmentConfig.getCqlElmServiceElmJsonUri());
URI uri = getCqlElmTranslationSerivceUri(libraryModel);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
headers.set(HttpHeaders.AUTHORIZATION, accessToken);
Expand All @@ -48,6 +42,16 @@ public ElmJson getElmJson(final String cql, String libraryModel, String accessTo
}
}

private URI getCqlElmTranslationSerivceUri(String libraryModel) {
var isQdm = StringUtils.equals(libraryModel, ModelType.QDM_5_6.getValue());
String baseUrl =
isQdm
? environmentConfig.getQdmCqlElmServiceBaseUrl()
: environmentConfig.getFhirCqlElmServiceBaseUrl();
return URI.create(
baseUrl + (isQdm ? "/qdm" : "/fhir") + environmentConfig.getCqlElmServiceElmJsonUri());
}

public boolean hasErrors(ElmJson elmJson) {
if (elmJson == null) {
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ madie:
allowedApi: http://localhost:9000
cql-elm:
service:
base-url: ${ELM_TRANSLATOR_SERVICE_URL:http://localhost:8084/api}
qdm-base-url: ${QDM_ELM_TRANSLATOR_SERVICE_URL:http://localhost:8084/api}
fhir-base-url: ${FHIR_ELM_TRANSLATOR_SERVICE_URL:http://localhost:8083/api}
elm-json-uri: /cql/translator/cql
management:
endpoints:
Expand All @@ -28,7 +29,7 @@ okta:
audience: ${OKTA_AUDIENCE:api://default}

lambda-api-key: ${LAMBDA_API_KEY:9202c9fa}

mongock:
migration-scan-package:
- gov.cms.madie.cqllibraryservice.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import gov.cms.madie.cqllibraryservice.config.EnvironmentConfig;
import gov.cms.madie.cqllibraryservice.exceptions.CqlElmTranslationServiceException;
import gov.cms.madie.models.common.ModelType;
import gov.cms.madie.models.measure.ElmJson;
import java.net.URI;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -36,7 +37,12 @@ class ElmTranslatorClientTest {

@BeforeEach
void beforeEach() {
lenient().when(environmentConfig.getCqlElmServiceBaseUrl()).thenReturn("http://test");
lenient()
.when(environmentConfig.getQdmCqlElmServiceBaseUrl())
.thenReturn("http://test/api/qdm");
lenient()
.when(environmentConfig.getFhirCqlElmServiceBaseUrl())
.thenReturn("http://test/api/fhir");
lenient()
.when(environmentConfig.getCqlElmServiceElmJsonUri())
.thenReturn("/cql/translator/cql");
Expand All @@ -58,7 +64,8 @@ void testRestTemplateReturnsElmJson() {
when(restTemplate.exchange(
any(URI.class), eq(HttpMethod.PUT), any(HttpEntity.class), any(Class.class)))
.thenReturn(ResponseEntity.ok(elmJson));
ElmJson output = elmTranslatorClient.getElmJson("TEST_CQL", "QDM v5.6", "TEST_TOKEN");
ElmJson output =
elmTranslatorClient.getElmJson("TEST_CQL", ModelType.QI_CORE.getValue(), "TEST_TOKEN");
assertThat(output, is(equalTo(elmJson)));
}

Expand Down

0 comments on commit b6b1a60

Please sign in to comment.