Skip to content

Commit

Permalink
Merge pull request #283 from MeasureAuthoringTool/MAT-8144
Browse files Browse the repository at this point in the history
MAT-8144 fetch valueset definitions
  • Loading branch information
adongare authored Feb 12, 2025
2 parents 06d2517 + 98502dc commit 6a60443
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -28,6 +25,11 @@ public StructureDefinitionDto getStructureDefinition(@PathVariable String struct
return structureDefinitionService.getStructureDefinitionById(structureDefinitionId);
}

@GetMapping(value = "/value-set-definition", produces = MediaType.APPLICATION_JSON_VALUE)
public String getValueSetDefinition(@RequestParam String url) {
return structureDefinitionService.getValueSetDefinition(url);
}

@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public List<ResourceIdentifier> getAllResources() {
return structureDefinitionService.getAllResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public StructureDefinitionDto getStructureDefinitionById(String structureDefinit
.build();
}

/**
* Fetches the value set definition for the given value set url
*
* @param url of the value set definition
*/
public String getValueSetDefinition(String url) {
IBaseResource structureDefinition = validationSupportChainQiCore600.fetchValueSet(url);
IParser parser =
validationSupportChainQiCore600
.getFhirContext()
.newJsonParser()
.setParserErrorHandler(new StrictErrorHandler())
.setPrettyPrint(true);
return parser.encodeResourceToString(structureDefinition);
}

/**
* Return the ID, title, profile, category and type of all structure definitions that start with
* QICore and have a kind of "resource"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import gov.cms.madie.madiefhirservice.exceptions.ResourceNotFoundException;
import gov.cms.madie.madiefhirservice.services.StructureDefinitionService;
import gov.cms.madie.madiefhirservice.utils.ResourceFileUtil;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import java.util.List;
Expand Down Expand Up @@ -110,4 +112,31 @@ void testThatGetStructureDefinitionReturnsDefinitionDto() throws Exception {
// then
verify(structureDefinitionService, times(1)).getStructureDefinitionById(eq("qicore-patient"));
}

@Test
void testGetValueSetDefinition() throws Exception {
// given
String url = "test";
String valueSetDefinition =
"{\"resourceType\": \"ValueSet\", \"id\": \"omb-ethnicity-category\",\"url\": \"http://hl7.org/fhir/us/core/ValueSet/omb-ethnicity-category\"}";
;
when(structureDefinitionService.getValueSetDefinition(anyString()))
.thenReturn(valueSetDefinition);

// when
MvcResult result =
mockMvc
.perform(
MockMvcRequestBuilders.get(
"/qicore/6_0_0/resources/value-set-definition?url=" + url)
.with(user(TEST_USER_ID))
.with(csrf())
.header(HttpHeaders.AUTHORIZATION, "test-okta"))
.andExpect(status().isOk())
.andReturn();

// then
verify(structureDefinitionService, times(1)).getValueSetDefinition(eq(url));
Assertions.assertThat(result.getResponse().getContentAsString()).isEqualTo(valueSetDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ void testThatGetStructureDefinitionReturnsDefinitionDto() {
assertThat(output.getDefinition(), is(notNullValue()));
assertThat(output.getDefinition().contains("\"id\": \"qicore-patient\""), is(true));
}

@Test
void testGetValueSetDefinition() {
// given
String valueSetDefinition =
"{\"resourceType\": \"ValueSet\", \"id\": \"omb-ethnicity-category\",\"url\": \"http://hl7.org/fhir/us/core/ValueSet/omb-ethnicity-category\"}";
when(structureDefinitionService.getValueSetDefinition(anyString()))
.thenReturn(valueSetDefinition);

// when
String output = resourceController.getValueSetDefinition("url");

// then
assertThat(output, is(equalTo(valueSetDefinition)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.ValueSet;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -337,4 +338,21 @@ void testGetCategoryByTypeReturnsCategoryFromExtension() {
// then
assertThat(output, is(equalTo("Base.Individuals")));
}

@Test
void getValueSetDefinition() {
// given
ValueSet valueSet = new ValueSet().setUrl("test").setName("omb ethnicity category");
when(validationSupportChainQiCore600.fetchValueSet(valueSet.getUrl())).thenReturn(valueSet);
when(validationSupportChainQiCore600.getFhirContext()).thenReturn(fhirContextQiCoreStu600);
// when
String output = structureDefinitionService.getValueSetDefinition(valueSet.getUrl());

// then
assertThat(
output,
is(
equalTo(
"{\n \"resourceType\": \"ValueSet\",\n \"url\": \"test\",\n \"name\": \"omb ethnicity category\"\n}")));
}
}

0 comments on commit 6a60443

Please sign in to comment.