Skip to content

Commit

Permalink
resolved the feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed May 10, 2024
1 parent 0cefa23 commit 83238bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public ResponseEntity<Code> getCode(
.body(fhirTerminologyService.retrieveCode(code, codeSystem, version, user.getApiKey()));
}

@PostMapping(path = "/codesList", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Code>> getCodesList(
@PostMapping(path = "/codes", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Code>> getCodesAndCodeSystems(
@RequestBody() List<Map<String, String>> codeList, Principal principal) {
final String username = principal.getName();
UmlsUser user = vsacService.verifyUmlsAccess(username);
return ResponseEntity.ok()
.body(fhirTerminologyService.retrieveCodesList(codeList, user.getApiKey()));
.body(fhirTerminologyService.retrieveCodesAndCodeSystems(codeList, user.getApiKey()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void updateOrInsertAllCodeSystems(List<CodeSystem> codeSystemList) {
}
}

public List<Code> retrieveCodesList(List<Map<String, String>> codeList, String apiKey) {
public List<Code> retrieveCodesAndCodeSystems(List<Map<String, String>> codeList, String apiKey) {
return codeList.stream()
.map(
code -> {
Expand All @@ -248,12 +248,9 @@ public List<Code> retrieveCodesList(List<Map<String, String>> codeList, String a
String codeSystemName = code.get("codeSystem");
String oid = code.get("oid") != null ? code.get("oid").replaceAll("'|'", "") : null;

Optional<Map.Entry<String, String>> mappedVersion =
oid != null
? mapToFhirVersion(code.get("version"), oid, codeSystemEntries)
: null;
Optional<Map.Entry<String, String>> mappedVersion = mapToFhirVersion(code.get("version"), oid, codeSystemEntries);

if (mappedVersion != null) {
if (mappedVersion.isPresent()) {
String vsacVersion = mappedVersion.get().getKey();
String fhirVersion = mappedVersion.get().getValue();

Expand All @@ -269,6 +266,10 @@ public List<Code> retrieveCodesList(List<Map<String, String>> codeList, String a
private Optional<Map.Entry<String, String>> mapToFhirVersion(
String version, String oid, List<CodeSystemEntry> codeSystemEntries) {

if(oid == null){
return Optional.empty();
}

Optional<Map.Entry<String, String>> result;
if (version == null) {
result =
Expand All @@ -295,7 +296,7 @@ private Optional<Map.Entry<String, String>> mapToFhirVersion(
if (result.isPresent()) {
return result;
}
return null;
return result;
}

private Code retrieveCodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ void testGetCodesList() {
Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn(TEST_USER);
when(vsacService.verifyUmlsAccess(anyString())).thenReturn(umlsUser);
when(fhirTerminologyService.retrieveCodesList(any(), anyString())).thenReturn(List.of(code));
when(fhirTerminologyService.retrieveCodesAndCodeSystems(any(), anyString()))
.thenReturn(List.of(code));
ResponseEntity<List<Code>> response =
vsacFhirTerminologyController.getCodesList(codeList, principal);
vsacFhirTerminologyController.getCodesAndCodeSystems(codeList, principal);
assertEquals(response.getStatusCode(), HttpStatus.OK);
assertEquals(response.getBody().get(0), code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void testRetrieveCodesListSuccessfully() {
.thenReturn(codeJson);
when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser());
when(vsacService.getCodeStatus(any(), anyString())).thenReturn(CodeStatus.ACTIVE);
List<Code> code = fhirTerminologyService.retrieveCodesList(codeList, TEST_API_KEY);
List<Code> code = fhirTerminologyService.retrieveCodesAndCodeSystems(codeList, TEST_API_KEY);
assertThat(code.get(0).getName(), is(equalTo("1963-8")));
assertThat(code.get(0).getDisplay(), is(equalTo("Bicarbonate [Moles/volume] in Serum")));
assertThat(code.get(0).getCodeSystem(), is(equalTo("LOINC")));
Expand Down

0 comments on commit 83238bd

Please sign in to comment.