Skip to content

Commit 4fe362e

Browse files
authored
Merge pull request #462 from MeasureAuthoringTool/feature/MAT-10341-structure-def-ignore-version
MAT-10341: update config to match other toolchain order; update getStructureDefinitionById to ignore version (if present) for now
2 parents 916266e + ae38fd8 commit 4fe362e

3 files changed

Lines changed: 65 additions & 16 deletions

File tree

src/main/java/gov/cms/madie/madiefhirservice/config/HapiFhirConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public IValidationSupport uscore6ValidationSupportChain(@Autowired FhirContext u
156156
validationConfig);
157157

158158
return new ValidationSupportChain(
159-
npmPackageSupport,
160159
vsesValidationSupport,
160+
npmPackageSupport,
161161
new DefaultProfileValidationSupport(uscore6FhirContext),
162162
new CustomQiCoreInMemoryValidationSupport(uscore6FhirContext, validationConfig),
163163
new CommonCodeSystemsTerminologyService(uscore6FhirContext),
@@ -192,8 +192,8 @@ public IValidationSupport usqualitycore05ValidationSupportChain(
192192
validationConfig);
193193

194194
return new ValidationSupportChain(
195-
npmPackageSupport,
196195
vsesValidationSupport,
196+
npmPackageSupport,
197197
new DefaultProfileValidationSupport(usqualitycore05FhirContext),
198198
new CustomQiCoreInMemoryValidationSupport(usqualitycore05FhirContext, validationConfig),
199199
new CommonCodeSystemsTerminologyService(usqualitycore05FhirContext),

src/main/java/gov/cms/madie/madiefhirservice/services/StructureDefinitionService.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,21 @@ public class StructureDefinitionService {
3535
* Fetches the structure definition for the given resource
3636
*
3737
* @param modelType the model to fetch the structure definition for
38-
* @param structureDefinitionId ID of the structure definition, as found in the
39-
* StructureDefinitions based on model and version. e.g. Patient, us-core-patient,
40-
* qicore-patient
38+
* @param structureDefinitionId ID of the structure definition, optionally followed by a
39+
* pipe-delimited version, as found in the StructureDefinitions for the model. e.g. Patient,
40+
* us-core-patient, qicore-patient|6.0.0
4141
*/
4242
public StructureDefinitionDto getStructureDefinitionById(
4343
ModelType modelType, String structureDefinitionId) {
4444
IValidationSupport chain = modelAwareFhirFactory.getValidationSupportForModel(modelType);
4545

46+
String unversionedId = structureDefinitionId.split("\\|", 2)[0];
47+
4648
IBaseResource structureDefinition =
4749
Objects.requireNonNull(chain.fetchAllStructureDefinitions()).stream()
48-
.filter(resource -> structureDefinitionId.equals(resource.getIdElement().getIdPart()))
50+
.filter(resource -> unversionedId.equals(resource.getIdElement().getIdPart()))
4951
.findFirst()
50-
.orElseThrow(
51-
() -> new ResourceNotFoundException("StructureDefinition", structureDefinitionId));
52+
.orElseThrow(() -> new ResourceNotFoundException("StructureDefinition", unversionedId));
5253

5354
IParser parser =
5455
chain

src/test/java/gov/cms/madie/madiefhirservice/services/StructureDefinitionServiceTest.java

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ void testGetStructureDefinitionByIdThrowsNotFoundForNoDefinitions() {
5858
// given
5959
when(mockChain.fetchAllStructureDefinitions()).thenReturn(List.of());
6060

61-
// when / then
62-
assertThrows(
63-
ResourceNotFoundException.class,
61+
// when
62+
Executable action =
6463
() ->
6564
structureDefinitionService.getStructureDefinitionById(
66-
ModelType.QI_CORE_6_0_0, "qicore-practitioner"));
65+
ModelType.QI_CORE_6_0_0, "qicore-practitioner");
66+
67+
// then
68+
assertThrows(ResourceNotFoundException.class, action);
6769
}
6870

6971
@Test
@@ -79,12 +81,35 @@ void testGetStructureDefinitionByIdThrowsNotFoundForNoMatchingDefinitions() {
7981
def3.setId("us-core-practitioner");
8082
when(mockChain.fetchAllStructureDefinitions()).thenReturn(List.of(def1, def3));
8183

82-
// when / then
83-
assertThrows(
84-
ResourceNotFoundException.class,
84+
// when
85+
Executable action =
86+
() ->
87+
structureDefinitionService.getStructureDefinitionById(
88+
ModelType.QI_CORE_6_0_0, "qicore-practitioner");
89+
90+
// then
91+
assertThrows(ResourceNotFoundException.class, action);
92+
}
93+
94+
@Test
95+
void testGetStructureDefinitionByIdThrowsNotFoundForVersionedIdWithNoMatch() {
96+
// given
97+
when(mockChain.fetchAllStructureDefinitions()).thenReturn(List.of());
98+
99+
// when
100+
Executable action =
85101
() ->
86102
structureDefinitionService.getStructureDefinitionById(
87-
ModelType.QI_CORE_6_0_0, "qicore-practitioner"));
103+
ModelType.QI_CORE_6_0_0, "qicore-practitioner|6.0.0");
104+
105+
// then
106+
ResourceNotFoundException exception = assertThrows(ResourceNotFoundException.class, action);
107+
assertThat(
108+
exception.getMessage(),
109+
is(
110+
equalTo(
111+
"Could not find StructureDefinition resource for measure: "
112+
+ "qicore-practitioner")));
88113
}
89114

90115
@Test
@@ -288,6 +313,29 @@ void testGetStructureDefinitionByIdReturnsQiCoreResourceStructureDefinitionDto()
288313
output.getDefinition().contains("\"resourceType\": \"StructureDefinition\""), is(true));
289314
}
290315

316+
@Test
317+
void testGetStructureDefinitionByIdReturnsResourceForVersionedId() {
318+
// given
319+
StructureDefinition definition =
320+
new StructureDefinition()
321+
.setKind(StructureDefinition.StructureDefinitionKind.RESOURCE)
322+
.setTitle("QICore Patient")
323+
.setVersion("6.0.0");
324+
definition.setId("qicore-patient");
325+
when(mockChain.fetchAllStructureDefinitions()).thenReturn(List.of(definition));
326+
when(mockChain.getFhirContext()).thenReturn(fhirContextQiCoreStu600);
327+
328+
// when
329+
StructureDefinitionDto output =
330+
structureDefinitionService.getStructureDefinitionById(
331+
ModelType.QI_CORE_6_0_0, "qicore-patient|6.0.0");
332+
333+
// then
334+
assertThat(output, is(notNullValue()));
335+
assertThat(output.getDefinition().contains("\"id\": \"qicore-patient\""), is(true));
336+
assertThat(output.getDefinition().contains("\"version\": \"6.0.0\""), is(true));
337+
}
338+
291339
@Test
292340
void testGetStructureDefinitionByIdReturnsComplexTypeStructureDefinitionDto() {
293341
// given

0 commit comments

Comments
 (0)