Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed May 8, 2024
1 parent 7de5296 commit 0cefa23
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gov.cms.madie.models.measure.ManifestExpansion;
import gov.cms.madie.terminology.dto.Code;
import gov.cms.madie.terminology.dto.CodeStatus;
import gov.cms.madie.terminology.dto.QdmValueSet;
import gov.cms.madie.terminology.dto.ValueSetsSearchCriteria;
import gov.cms.madie.terminology.exceptions.VsacUnauthorizedException;
Expand All @@ -22,10 +23,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;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -230,4 +228,32 @@ void testGetCodeIfNoUmlsUserFound() {
() -> vsacFhirTerminologyController.getCode(codeName, codeSystem, version, principal));
assertEquals(ex.getMessage(), "Please login to UMLS before proceeding");
}

@Test
void testGetCodesList() {
List<Map<String, String>> codeList =
List.of(
Map.of(
"code", "1963-8", "codeSystem", "LOINC", "oid", "'urn:oid:2.16.840.1.113883.6.1'"),
Map.of(
"code", "8462-4", "codeSystem", "LOINC", "oid", "'urn:oid:2.16.840.1.113883.6.1'"));
Code code =
Code.builder()
.name("1963-8")
.codeSystem("LOINC")
.version("2.72")
.display("Bicarbonate [Moles/volume] in Serum")
.codeSystemOid("2.16.840.1.113883.6.1")
.status(CodeStatus.valueOf("ACTIVE"))
.build();

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));
ResponseEntity<List<Code>> response =
vsacFhirTerminologyController.getCodesList(codeList, principal);
assertEquals(response.getStatusCode(), HttpStatus.OK);
assertEquals(response.getBody().get(0), code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,70 @@ void testRetrieveCodeSuccessfully() {
assertThat(code.getVersion(), is(equalTo(version)));
assertThat(code.getStatus(), is(equalTo(CodeStatus.ACTIVE)));
}

@Test
void testRetrieveCodesListSuccessfully() {
List<Map<String, String>> codeList =
List.of(
Map.of(
"code", "1963-8", "codeSystem", "LOINC", "oid", "'urn:oid:2.16.840.1.113883.6.1'"));

String codeJson =
"{\n"
+ " \"resourceType\": \"Parameters\",\n"
+ " \"parameter\": [ {\n"
+ " \"name\": \"name\",\n"
+ " \"valueString\": \"LOINC\"\n"
+ " }, {\n"
+ " \"name\": \"version\",\n"
+ " \"valueString\": \"2.40\"\n"
+ " }, {\n"
+ " \"name\": \"display\",\n"
+ " \"valueString\": \"Bicarbonate [Moles/volume] in Serum\"\n"
+ " }, {\n"
+ " \"name\": \"Oid\",\n"
+ " \"valueString\": \"2.16.840.1.113883.6.1\"\n"
+ " } ]\n"
+ "}";

codeSystemEntries = new ArrayList<>();
CodeSystemEntry.Version version = new CodeSystemEntry.Version();
version.setVsac("2.40");
version.setFhir("2.40");
var codeSystemEntry =
CodeSystemEntry.builder()
.name("8462-4")
.oid("urn:oid:2.16.840.1.113883.6.1")
.url("http://loinc.org")
.versions(Collections.toList(version))
.build();
codeSystemEntries.add(codeSystemEntry);

gov.cms.madie.terminology.models.CodeSystem codeSystem =
gov.cms.madie.terminology.models.CodeSystem.builder()
.id("LOINC2.40")
.fullUrl("http://loinc.org")
.title("LOINC")
.name("LOINC")
.version("2.40")
.versionId("404676818")
.oid("urn:oid:2.16.840.1.113883.6.1")
.lastUpdated(Instant.parse("2024-04-30T20:18:48.706Z"))
.lastUpdatedUpstream(new Date("Fri Apr 01 00:00:00 EDT 2022"))
.build();

when(mappingService.getCodeSystemEntries()).thenReturn(codeSystemEntries);
when(codeSystemRepository.findByOidAndVersion(anyString(), anyString()))
.thenReturn(Optional.ofNullable(codeSystem));
when(fhirTerminologyServiceWebClient.getCodeResource(anyString(), any(), any()))
.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);
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")));
assertThat(code.get(0).getVersion(), is(equalTo("2.40")));
assertThat(code.get(0).getStatus(), is(equalTo(CodeStatus.ACTIVE)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class UpdateCodeSystemTaskTest {
@Mock private FhirTerminologyService fhirTerminologyService;
@InjectMocks UpdateCodeSystemTask updateCodeSystemTask;

@Test
void updateCodeSystemTaskTest() {
UmlsUser umlsUser = new UmlsUser();
Expand Down

0 comments on commit 0cefa23

Please sign in to comment.