Skip to content

Commit

Permalink
Merge branch 'master' into datetime-only-year
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-thompson authored Sep 24, 2024
2 parents 9397183 + 04b9d7b commit 5f2944e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/export/ValueSetExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export class ValueSetExporter {
composeElement.valueSet = component.from.valueSets.map(vs => {
return this.fisher.fishForMetadata(vs, Type.ValueSet)?.url ?? vs;
});
composeElement.valueSet = composeElement.valueSet.filter(vs => {
if (vs == valueSet.url) {
logger.error(
`Value set with id ${valueSet.id} has component rule with self-referencing value set (by id, value set name, or url). Removing self-reference.`
);
}
return vs != valueSet.url;
});
composeElement.valueSet.forEach(vs => {
// Canonical URI may include | to specify version: https://www.hl7.org/fhir/references.html#canonical
if (!isUri(vs.split('|')[0])) {
Expand Down Expand Up @@ -176,7 +184,9 @@ export class ValueSetExporter {
this.addConceptComposeElement(composeElement, valueSet.compose.include);
}
} else {
valueSet.compose.include.push(composeElement);
if (composeElement.valueSet?.length !== 0 || composeElement.system != undefined) {
valueSet.compose.include.push(composeElement);
}
}
} else {
this.addConceptComposeElement(composeElement, valueSet.compose.exclude);
Expand Down
51 changes: 51 additions & 0 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,57 @@ describe('ValueSetExporter', () => {
});
});

it('should remove and log error when exporting a value set that includes a component from a self referencing value set', () => {
const valueSet = new FshValueSet('DinnerVS');
valueSet.id = 'dinner-vs';
const component = new ValueSetConceptComponentRule(true);
component.from = {
system: 'http://food.org/food1',
valueSets: [
'http://food.org/food/ValueSet/hot-food',
'http://food.org/food/ValueSet/cold-food',
'DinnerVS',
'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs',
'dinner-vs'
]
};
const component2 = new ValueSetConceptComponentRule(true);
component2.from = {
system: 'http://food.org/food2',
valueSets: ['DinnerVS', 'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs', 'dinner-vs']
};
valueSet.rules.push(component);
valueSet.rules.push(component2);
doc.valueSets.set(valueSet.name, valueSet);
const exported = exporter.export().valueSets;
expect(exported.length).toBe(1);
expect(exported[0]).toEqual({
resourceType: 'ValueSet',
id: 'dinner-vs',
name: 'DinnerVS',
url: 'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs',
status: 'draft',
compose: {
include: [
{
system: 'http://food.org/food1',
valueSet: [
'http://food.org/food/ValueSet/hot-food',
'http://food.org/food/ValueSet/cold-food'
]
},
{
system: 'http://food.org/food2'
}
]
}
});
expect(loggerSpy.getAllMessages('error')).toHaveLength(6);
expect(loggerSpy.getLastMessage('error')).toBe(
'Value set with id dinner-vs has component rule with self-referencing value set (by id, value set name, or url). Removing self-reference.'
);
});

it('should export a value set that includes a concept component with at least one concept', () => {
const valueSet = new FshValueSet('DinnerVS');
const component = new ValueSetConceptComponentRule(true);
Expand Down

0 comments on commit 5f2944e

Please sign in to comment.