Skip to content

Commit

Permalink
adding test, conditional check
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelynJefferson committed Oct 21, 2024
1 parent faaf076 commit 7d4ac22
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/fhirtypes/StructureDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,18 @@ export class StructureDefinition {
) {
// We throw an error if the currentElement doesn't exist, has been zeroed out,
// or is being incorrectly accessed as an array
throw new CannotResolvePathError(path);
if (
pathPart.base === 'concept' &&
pathPart.brackets[0] === 'undefined' &&
pathPart.slices[0] === 'undefined'
) {
throw new Error(
'This rule is invalid. The rule does not contain a concept array in the compose element with the code system given.'
);
// TODO: code system --> fisher.tank.docs[0].valueSets[0].value.rules[0].from.system
} else {
throw new CannotResolvePathError(path);
}
}

// Determine if base and/or current are arrays. Note that this is not perfect (if base or current max is missing),
Expand Down
25 changes: 25 additions & 0 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,31 @@ 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')).toMatch(
/This rule is invalid. The rule does not contain a concept array in the compose element/
);
});

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';
Expand Down

0 comments on commit 7d4ac22

Please sign in to comment.