Skip to content

Commit

Permalink
MAT-6917: Add endpoint for get all, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Apr 2, 2024
1 parent b92a5bb commit ef9dee3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public ResponseEntity<List<CodeSystem>> retrieveAndUpdateCodeSystems(
throw new VsacUnauthorizedException("Please login to UMLS before proceeding");
}
}
@GetMapping(path = "/get-code-systems", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<CodeSystem>> getAllCodeSystems(Principal principal) {
final String username = principal.getName();
log.info("Retrieving list of codeSystems for user: {}", username);
return ResponseEntity.ok().body(fhirTerminologyService.getAllCodeSystems());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ private List<QdmValueSet.Concept> getValueSetConcepts(
}


public List<CodeSystem> getAllCodeSystems(){
return codeSystemRepository.findAll();
}
public List<CodeSystem> retrieveAllCodeSystems(UmlsUser umlsUser) {
List<CodeSystem> allCodeSystems = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,28 @@ void testUnAuthorizedUmlsUserWhileretrievingAndUpdatingCodeSystems() {
VsacUnauthorizedException.class,
() -> vsacFhirTerminologyController.retrieveAndUpdateCodeSystems(principal, request, TEST_API_KEY, TEST_USER));
}

@Test
void testGetAllCodeSystemsSuccessfully() {
List<CodeSystem> mockCodeSystemsPage = new ArrayList<>();
mockCodeSystemsPage.add(
CodeSystem.builder()
.id("titleversion")
.title("title")
.name("name")
.version("version")
.versionId("vid")
.oid("urlval")
.lastUpdated(Instant.now())
.build());
Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn(TEST_USER);
when(fhirTerminologyService.getAllCodeSystems()).thenReturn(mockCodeSystemsPage);

ResponseEntity<List<CodeSystem>> response =
vsacFhirTerminologyController.getAllCodeSystems(principal);
assertEquals(response.getStatusCode(), HttpStatus.OK);
assertEquals(response.getBody(), mockCodeSystemsPage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,20 @@ void testRetrieveAllCodeSystems() {
verify(codeSystemRepository, times(2)).save(any(gov.cms.madie.terminology.models.CodeSystem.class));
}

@Test
void testGetAllCodeSystems(){
var c1 = new gov.cms.madie.terminology.models.CodeSystem();
c1.setTitle("t1");
var c2 = new gov.cms.madie.terminology.models.CodeSystem();
c2.setTitle("t2");
List<gov.cms.madie.terminology.models.CodeSystem> codeSystems = Arrays.asList(c1, c2);
when(codeSystemRepository.findAll()).thenAnswer(invocation -> codeSystems);
List<gov.cms.madie.terminology.models.CodeSystem> result = fhirTerminologyService.getAllCodeSystems();

verify(codeSystemRepository).findAll();
assertEquals(2, result.size());
assertEquals("t1", result.get(0).getTitle());
assertEquals("t2", result.get(1).getTitle());
}

}

0 comments on commit ef9dee3

Please sign in to comment.