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-6175 get human readable for export #6

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -16,6 +16,9 @@ public class CqlElmTranslatorClientConfig {
@Value("${madie.cql-elm.service.cql-elm-urn}")
private String cqlElmUrn;

@Value("${madie.cql-elm.service.human-readable}")
private String humanReadableUrl;

@Bean
public RestTemplate elmTranslatorRestTemplate() {
return new RestTemplate();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gov/cms/madie/services/PackagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public byte[] createMeasurePackage(Measure measure, String accessToken) {
entries.put(resourcesDir + entryName + ".xml", translatedLibrary.getElmXml().getBytes());
entries.put(cqlDir + entryName + ".cql", translatedLibrary.getCql().getBytes());
}
String humanReadable = translationServiceClient.getHumanReadable(measure, accessToken);
if (humanReadable != null) {
entries.put(
measure.getEcqmTitle() + "-v" + measure.getVersion() + "-QDM" + ".html",
humanReadable.getBytes());
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
return new ZipUtility().zipEntries(entries, outputStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gov.cms.madie.Exceptions.TranslationServiceException;
import gov.cms.madie.config.CqlElmTranslatorClientConfig;
import gov.cms.madie.models.dto.TranslatedLibrary;
import gov.cms.madie.models.measure.Measure;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
Expand Down Expand Up @@ -41,4 +42,25 @@ public List<TranslatedLibrary> getTranslatedLibraries(String cql, String accessT
throw new TranslationServiceException(msg, ex);
}
}

public String getHumanReadable(Measure measure, String accessToken) {
URI uri =
URI.create(
translatorClientConfig.getBaseUrl() + translatorClientConfig.getHumanReadableUrl());

HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.AUTHORIZATION, accessToken);
HttpEntity<Measure> measureEntity = new HttpEntity<>(measure, headers);
try {
log.info("fetching human readable");
return elmTranslatorRestTemplate
.exchange(uri, HttpMethod.PUT, measureEntity, String.class)
.getBody();
} catch (Exception ex) {
String msg =
"An issue occurred while fetching human readable for measure id: " + measure.getId();
log.error(msg, ex);
throw new TranslationServiceException(msg, ex);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ madie:
service:
base-url: ${ELM_TRANSLATOR_SERVICE_URL:http://localhost:8084/api}
cql-elm-urn: /cql/elm
human-readable: /human-readable

management:
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ void setUp() throws Exception {
Measure.builder()
.id("1")
.ecqmTitle("test")
.version(
gov.cms.madie.models.common.Version.builder()
.major(1)
.minor(2)
.revisionNumber(3)
.build())
.cql("fake cql")
.model(String.valueOf(ModelType.QDM_5_6))
.build();
Expand All @@ -61,12 +67,14 @@ void testCreateMeasurePackage() {
.build();
when(translationServiceClient.getTranslatedLibraries(measure.getCql(), TOKEN))
.thenReturn(List.of(library1, library2));
when(translationServiceClient.getHumanReadable(measure, TOKEN)).thenReturn("success");
byte[] packageContents = packagingService.createMeasurePackage(measure, TOKEN);
String packageString = new String(packageContents);
String library1FileName = library1.getName() + "-" + library1.getVersion();
assertThat(packageString, containsString(library1FileName + ".cql"));
assertThat(packageString, containsString(library1FileName + ".xml"));
assertThat(packageString, containsString(library1FileName + ".json"));
assertThat(packageString, containsString("test-v1.2.003-QDM.html"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import gov.cms.madie.Exceptions.TranslationServiceException;
import gov.cms.madie.config.CqlElmTranslatorClientConfig;
import gov.cms.madie.models.dto.TranslatedLibrary;
import gov.cms.madie.models.measure.Measure;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -70,4 +72,34 @@ void getTranslatedLibrariesWhenTranslationServiceFailed() {
message);
assertThat(ex.getMessage(), containsString(message));
}

@Test
void testGetHumanReadableSuccess() {
when(translatorClientConfig.getBaseUrl()).thenReturn("baseurl");
when(translatorClientConfig.getHumanReadableUrl()).thenReturn("/human-readable");
when(elmTranslatorRestTemplate.exchange(
any(URI.class), eq(HttpMethod.PUT), any(HttpEntity.class), any(Class.class)))
.thenReturn(ResponseEntity.ok("success"));

String humanReadable =
translationServiceClient.getHumanReadable(Measure.builder().build(), "token");
assertThat(humanReadable, is(equalTo("success")));
}

@Test
void testGetHumanReadableFailure() {
String message =
"An issue occurred while fetching human readable for measure id: testMeasureId";
when(elmTranslatorRestTemplate.exchange(
any(URI.class), eq(HttpMethod.PUT), any(HttpEntity.class), any(Class.class)))
.thenThrow(new TranslationServiceException(message, new Exception()));
Exception ex =
assertThrows(
TranslationServiceException.class,
() ->
translationServiceClient.getHumanReadable(
Measure.builder().id("testMeasureId").build(), "token"),
message);
assertThat(ex.getMessage(), containsString(message));
}
}
Loading