Skip to content

Commit

Permalink
MAT-6736 Added Caching at Service level for Manifest list
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitKandimalla committed Mar 15, 2024
1 parent 8ff6512 commit bae5bd8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableCaching
public class TerminologyServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public ResponseEntity<List<ManifestExpansion>> getManifests(Principal principal)
if (umlsUser.isPresent() && !StringUtils.isBlank(umlsUser.get().getApiKey())) {
return ResponseEntity.ok().body(fhirTerminologyService.getManifests(umlsUser.get()));
}
log.error("Unable to Retrieve List of available manifests, UMLS Authentication Key Not found for user : [{}}]", username);
log.error(
"Unable to Retrieve List of available manifests, UMLS Authentication Key Not found for user : [{}}]",
username);
throw new VsacUnauthorizedException("Please login to UMLS before proceeding");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hl7.fhir.r4.model.Bundle;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
Expand All @@ -20,6 +21,7 @@ public class FhirTerminologyService {
FhirContext ctx = FhirContext.forR4();
private final FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient;

@Cacheable("manifest-list")
public List<ManifestExpansion> getManifests(UmlsUser umlsUser) {
IParser parser = ctx.newJsonParser();
String responseString = fhirTerminologyServiceWebClient.getManifestBundle(umlsUser.getApiKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,86 +15,90 @@
@ExtendWith(MockitoExtension.class)
class FhirTerminologyServiceTest {

@Mock
FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient;
@Mock FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient;

@InjectMocks FhirTerminologyService fhirTerminologyService;
private UmlsUser umlsUser;
private static final String TEST_HARP_ID = "te$tHarpId";
private static final String TEST_API_KEY = "te$tKey";
@InjectMocks FhirTerminologyService fhirTerminologyService;
private UmlsUser umlsUser;
private static final String TEST_HARP_ID = "te$tHarpId";
private static final String TEST_API_KEY = "te$tKey";

private final String responseFromServer = """
{
"resourceType": "Bundle",
"id": "library-search",
"meta":
{
"lastUpdated": "2024-03-14T14:04:52.456-04:00"
},
"type": "searchset",
"total": 25,
"link":
[
{
"relation": "self",
"url": "https://uat-cts.nlm.nih.gov/fhir/Library"
}
],
"entry":
[
{
"fullUrl": "http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh",
"resource":
private final String responseFromServer =
"""
{
"resourceType": "Library",
"id": "ecqm-update-4q2017-eh",
"meta":
{
"profile":
[
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/publishable-library-cqfm",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/quality-program-cqfm"
]
},
"url": "http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh",
"version": "2017-09-15",
"status": "active"
}
},
{
"fullUrl": "http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25",
"resource":
{
"resourceType": "Library",
"id": "mu2-update-2012-10-25",
"meta":
{
"profile":
[
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/publishable-library-cqfm",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/quality-program-cqfm"
]
},
"url": "http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25",
"version": "2012-10-25",
"status": "active"
}
}
]
}""";
"resourceType": "Bundle",
"id": "library-search",
"meta":
{
"lastUpdated": "2024-03-14T14:04:52.456-04:00"
},
"type": "searchset",
"total": 25,
"link":
[
{
"relation": "self",
"url": "https://uat-cts.nlm.nih.gov/fhir/Library"
}
],
"entry":
[
{
"fullUrl": "http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh",
"resource":
{
"resourceType": "Library",
"id": "ecqm-update-4q2017-eh",
"meta":
{
"profile":
[
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/publishable-library-cqfm",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/quality-program-cqfm"
]
},
"url": "http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh",
"version": "2017-09-15",
"status": "active"
}
},
{
"fullUrl": "http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25",
"resource":
{
"resourceType": "Library",
"id": "mu2-update-2012-10-25",
"meta":
{
"profile":
[
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/publishable-library-cqfm",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/quality-program-cqfm"
]
},
"url": "http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25",
"version": "2012-10-25",
"status": "active"
}
}
]
}""";

@BeforeEach
public void setUp() {
umlsUser = UmlsUser.builder().apiKey(TEST_API_KEY).harpId(TEST_HARP_ID).build();
}

@BeforeEach
public void setUp() {
umlsUser = UmlsUser.builder().apiKey(TEST_API_KEY).harpId(TEST_HARP_ID).build();
}
@Test
void getManifests() {
when(fhirTerminologyServiceWebClient.getManifestBundle(anyString())).thenReturn(responseFromServer);
var result = fhirTerminologyService.getManifests(umlsUser);
assertEquals(2, result.size());
assertEquals("ecqm-update-4q2017-eh", result.get(0).getId());
assertEquals("http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh", result.get(0).getFullUrl());
assertEquals("mu2-update-2012-10-25", result.get(1).getId());
assertEquals("http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25", result.get(1).getFullUrl());
}
@Test
void getManifests() {
when(fhirTerminologyServiceWebClient.getManifestBundle(anyString()))
.thenReturn(responseFromServer);
var result = fhirTerminologyService.getManifests(umlsUser);
assertEquals(2, result.size());
assertEquals("ecqm-update-4q2017-eh", result.get(0).getId());
assertEquals(
"http://cts.nlm.nih.gov/fhir/Library/ecqm-update-4q2017-eh", result.get(0).getFullUrl());
assertEquals("mu2-update-2012-10-25", result.get(1).getId());
assertEquals(
"http://cts.nlm.nih.gov/fhir/Library/mu2-update-2012-10-25", result.get(1).getFullUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void tearDown() throws IOException {
void getManifestBundleSuccessfully() {
mockBackEnd.enqueue(
new MockResponse()
.setResponseCode(200)
.setResponseCode(200)
.setBody(MOCK_RESPONSE_STRING)
.addHeader("Content-Type", "application/fhir+json"));
String actualResponse = fhirTerminologyServiceWebClient.getManifestBundle(MOCK_API_KEY);
Expand All @@ -57,9 +57,9 @@ void getManifestBundleSuccessfully() {

@Test
void getManifestBundle_ReturnsException() {
mockBackEnd.enqueue(
new MockResponse()
.setResponseCode(HttpStatus.UNAUTHORIZED.value()));
assertThrows(WebClientResponseException.class, () -> fhirTerminologyServiceWebClient.getManifestBundle(MOCK_API_KEY));
mockBackEnd.enqueue(new MockResponse().setResponseCode(HttpStatus.UNAUTHORIZED.value()));
assertThrows(
WebClientResponseException.class,
() -> fhirTerminologyServiceWebClient.getManifestBundle(MOCK_API_KEY));
}
}

0 comments on commit bae5bd8

Please sign in to comment.