Skip to content

Commit

Permalink
moving self reference check to setCompose
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelynJefferson committed Aug 7, 2024
1 parent d678c0d commit 80a54b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
26 changes: 8 additions & 18 deletions 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). Skipping rule.`
);
};
return vs != valueSet.url

Check failure on line 95 in src/export/ValueSetExporter.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier

Missing semicolon
});
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 @@ -448,24 +456,6 @@ export class ValueSetExporter {
);
}

// check value sets to ensure not self referencing
let selfReferencedIncludeValueSets = vs?.compose?.include?.[0]?.valueSet?.filter((valueSetItem) => valueSetItem == vs.url) ?? [];
let selfReferencedExcludeValueSets = vs?.compose?.exclude?.[0]?.valueSet?.filter((valueSetItem) => valueSetItem == vs.url) ?? [];

if ( selfReferencedIncludeValueSets.length > 0 || selfReferencedExcludeValueSets.length > 0 ) {
logger.error(
`Value set with id ${vs.id} has component rule with self referencing value sets (by id, value set name, or url). Skipping rule.`
)
// remove the self referenced rules for the output
// if (selfReferencedIncludeValueSets.length > 0 ) {
// let nonSelfReferenceValueSets = vs.compose.include[0].valueSet.filter((valueSetItem) => valueSetItem != vs.url)
// vs.compose.include[0].valueSet = nonSelfReferenceValueSets;
// }
// if (selfReferencedExcludeValueSets.length > 0 ) {
// let nonSelfReferenceValueSets = vs.compose.exclude[0].valueSet.filter((valueSetItem) => valueSetItem != vs.url)
// vs.compose.exclude[0].valueSet = nonSelfReferenceValueSets;
// }
}

cleanResource(vs, (prop: string) => ['_sliceName', '_primitive'].includes(prop));
this.pkg.valueSets.push(vs);
Expand Down
7 changes: 2 additions & 5 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,13 @@ describe('ValueSetExporter', () => {
{
valueSet: [
'http://food.org/food/ValueSet/hot-food',
'http://food.org/food/ValueSet/cold-food',
'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs',
'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs',
'http://hl7.org/fhir/us/minimal/ValueSet/dinner-vs'
'http://food.org/food/ValueSet/cold-food'
]
}
]
}
});
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getAllMessages('error')).toHaveLength(3);
expect(loggerSpy.getLastMessage('error')).toBe('Value set with id dinner-vs has component rule with self referencing value sets (by id, value set name, or url). Skipping rule.');
});

Expand Down

0 comments on commit 80a54b5

Please sign in to comment.