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-6917: Add endpoint for get all, add missing functionality for MAT-6916 #68

Merged
merged 5 commits into from
Apr 5, 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 @@ -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 Expand Up @@ -179,6 +182,17 @@ private void updateOrInsertAllCodeSystems(List<CodeSystem> codeSystemList){
// Insert new CodeSystem
codeSystemRepository.save(codeSystem);
log.info("New CodeSystem inserted: {}", codeSystem);
} else {
CodeSystem existingCodeSystem = existingCodeSystemOptional.get();
existingCodeSystem.setTitle(codeSystem.getTitle());
existingCodeSystem.setName(codeSystem.getName());
existingCodeSystem.setVersion(codeSystem.getVersion());
existingCodeSystem.setVersionId(codeSystem.getVersionId());
existingCodeSystem.setOid(codeSystem.getOid());
existingCodeSystem.setLastUpdated(codeSystem.getLastUpdated());
existingCodeSystem.setLastUpdatedUpstream(codeSystem.getLastUpdatedUpstream());
codeSystemRepository.save(existingCodeSystem);
log.info("CodeSystem updated: {}", existingCodeSystem);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.security.Principal;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -122,6 +123,7 @@ void retrieveAndUpdateCodeSystemsSuccessfully() {
.versionId("vid")
.oid("urlval")
.lastUpdated(Instant.now())
.lastUpdatedUpstream(new Date())
.build());
Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn(TEST_USER);
Expand Down Expand Up @@ -153,4 +155,29 @@ 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())
.lastUpdatedUpstream(new Date())
.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);
}

}
Loading
Loading