Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for ValueSet compose component without any concept #1540

Merged
merged 10 commits into from
Dec 23, 2024
10 changes: 9 additions & 1 deletion src/export/ValueSetExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,15 @@ export class ValueSetExporter {
});
}
}

if (conceptIndex == null) {
logger.error(
`Cannot process caret assignment rule for code ${system}#${code} because ` +
'this value set does not explicitly include or exclude this code in its ' +
'rules. To fix this error, add a rule that specifically includes or excludes ' +
'this code for the value set.'
);
return;
}
if (conceptIndex !== -1) {
if (rule.isInstance) {
const instanceExporter = new InstanceExporter(this.tank, this.pkg, this.fisher);
Expand Down
28 changes: 28 additions & 0 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,34 @@ describe('ValueSetExporter', () => {
});
});

it('should throw error for caret rule on valueset compose component without any concept', () => {
// ValueSet: SomeVS
// * include codes from system http://example.org/CS
// * http://example.org/CS#"some-code" ^designation.value = "some value"

const valueSet = new FshValueSet('SomeVS');

const component = new ValueSetConceptComponentRule(true);
component.from.system = 'http://example.org/CS';

const cvRule = new CaretValueRule('');
cvRule.pathArray = ['http://example.org/CS#"some-code"'];
cvRule.caretPath = 'designation.value';
cvRule.value = 'some value';

valueSet.rules.push(component, cvRule);
doc.valueSets.set(valueSet.name, valueSet);
const exported = exporter.export().valueSets;
expect(exported.length).toBe(1);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toBe(
'Cannot process caret assignment rule for code http://example.org/CS#"some-code" ' +
'because this value set does not explicitly include or exclude this code in its ' +
'rules. To fix this error, add a rule that specifically includes or excludes this ' +
'code for the value set.'
);
});

it('should export a value set with a contained resource created on the value set', () => {
// ValueSet: DinnerVS
// * ^contained.resourceType = "Observation"
Expand Down
Loading