Skip to content

Commit

Permalink
Merge pull request #4 from MeasureAuthoringTool/MAT-7294_translatorVe…
Browse files Browse the repository at this point in the history
…rsion

MAT-7294 translator versions
  • Loading branch information
sb-cecilialiu authored Jun 18, 2024
2 parents 09d2d8e + f704cde commit bb1a742
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cms.mat.cql_elm_translation.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import lombok.Data;

@Configuration
@Data
public class TranslatorVersionConfig {

@Value("${madie.translatorVersion.currentVersion}")
private String currentTranslatorVersion;

@Value("${madie.translatorVersion.mostRecentVersion}")
private String mostRecentTranslatorVersion;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gov.cms.mat.cql_elm_translation.controllers;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gov.cms.mat.cql_elm_translation.config.TranslatorVersionConfig;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/translator-version")
public class TranslatorVersionController {

private TranslatorVersionConfig translatorVersionConfig;

@GetMapping()
public ResponseEntity<String> getTranslatorVersion(
@RequestParam(required = true, name = "draft") boolean draft) {
log.info(
"Current translator version: " + translatorVersionConfig.getCurrentTranslatorVersion());
log.info(
"Most recent translator version: "
+ translatorVersionConfig.getMostRecentTranslatorVersion());
String result =
draft
? translatorVersionConfig.getMostRecentTranslatorVersion()
: translatorVersionConfig.getCurrentTranslatorVersion();
return ResponseEntity.status(HttpStatus.OK).body(result);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 8084
port: 8083
servlet:
context-path: /api/fhir

Expand Down Expand Up @@ -28,6 +28,9 @@ madie:
baseUrl: ${CQL_LIBRARY_SERVICE_URL:http://localhost:8082/api}
cql:
uri: /cql-libraries/cql
translatorVersion:
currentVersion: "3.3.2"
mostRecentVersion: "3.10.0"

springdoc:
swagger-ui:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gov.cms.mat.cql_elm_translation.controllers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.lenient;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import gov.cms.mat.cql_elm_translation.config.TranslatorVersionConfig;

@ExtendWith(MockitoExtension.class)
public class TranslatorVersionControllerTest {

@Mock private TranslatorVersionConfig translatorVersionConfig;
@InjectMocks private TranslatorVersionController translatorVersionController;

private static final String CURRENT_VERSION = "3.3.2";
private static final String MOST_RECENT_VERSION = "3.10.0";

@BeforeEach
void beforeEach() {
lenient()
.when(translatorVersionConfig.getCurrentTranslatorVersion())
.thenReturn(CURRENT_VERSION);
lenient()
.when(translatorVersionConfig.getMostRecentTranslatorVersion())
.thenReturn(MOST_RECENT_VERSION);
}

@Test
public void testGetTranslatorVersionIsDraft() {
ResponseEntity<String> results = translatorVersionController.getTranslatorVersion(true);
assertTrue(results.getStatusCode().equals(HttpStatus.OK));
assertEquals(results.getBody(), MOST_RECENT_VERSION);
}

@Test
public void testGetTranslatorVersionVersioned() {
ResponseEntity<String> results = translatorVersionController.getTranslatorVersion(false);
assertTrue(results.getStatusCode().equals(HttpStatus.OK));
assertEquals(results.getBody(), CURRENT_VERSION);
}
}

0 comments on commit bb1a742

Please sign in to comment.