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

Valueset versioned caret rules #1493

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/export/ValueSetExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,16 @@ export class ValueSetExporter {
for (const rule of rules) {
const splitConcept = rule.pathArray[0].split('#');
const system = splitConcept[0];
const baseSystem = system?.split('|')[0];
const version = system?.split('|')[1];
const code = splitConcept.slice(1).join('#');
const systemMeta = this.fisher.fishForMetadata(system, Type.CodeSystem);
const systemMeta = this.fisher.fishForMetadata(baseSystem, Type.CodeSystem);
let composeIndex =
vs.compose?.include?.findIndex(composeElement => {
return composeElement.system === system || composeElement.system === systemMeta?.url;
return (
(composeElement.system === baseSystem && composeElement.version === version) ||
(composeElement.system === systemMeta?.url && composeElement.version === version)
);
}) ?? -1;
let composeArray: string;
let composeElement: ValueSetComposeIncludeOrExclude;
Expand All @@ -317,7 +322,7 @@ export class ValueSetExporter {
if (conceptIndex === -1) {
composeIndex =
vs.compose?.exclude?.findIndex(composeElement => {
return composeElement.system === system;
return composeElement.system === baseSystem;
}) ?? -1;
if (composeIndex !== -1) {
composeArray = 'exclude';
Expand Down
59 changes: 59 additions & 0 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,65 @@ describe('ValueSetExporter', () => {
expect(loggerSpy.getLastMessage('error')).toMatch(/File: ValueSet\.fsh.*Line: 4\D*/s);
});

it('should not throw an error when caret rules are applied to a code from a specific version of a codeSystem', () => {
const valueSet = new FshValueSet('DinnerVS');
const unversionedComponent = new ValueSetConceptComponentRule(true);
unversionedComponent.from = { system: 'http://food.org/food' };
unversionedComponent.concepts.push(
new FshCode('Pizza', 'http://food.org/food', 'Delicious pizza to share.')
);
const versionComponent = new ValueSetConceptComponentRule(true);
versionComponent.from = { system: 'http://food.org/food|2.0.1' };
versionComponent.concepts.push(
new FshCode('Salad', 'http://food.org/food|2.0.1', 'Plenty of fresh vegetables.')
);
const designationValue = new CaretValueRule('');
designationValue.caretPath = 'designation.value';
designationValue.pathArray = ['http://food.org/food|2.0.1#Salad'];
designationValue.value = 'Salat';
valueSet.rules.push(unversionedComponent, versionComponent, designationValue);
doc.valueSets.set(valueSet.name, valueSet);
const exported = exporter.export().valueSets;
expect(exported.length).toBe(1);
expect(exported[0]).toEqual({
resourceType: 'ValueSet',
id: 'DinnerVS',
name: 'DinnerVS',
url: 'http://hl7.org/fhir/us/minimal/ValueSet/DinnerVS',
status: 'draft',
compose: {
include: [
{
system: 'http://food.org/food',
concept: [
{
code: 'Pizza',
display: 'Delicious pizza to share.'
}
]
},
{
system: 'http://food.org/food',
version: '2.0.1',
concept: [
{
code: 'Salad',
display: 'Plenty of fresh vegetables.',
designation: [
{
value: 'Salat'
}
]
}
]
}
]
}
});
expect(designationValue.isCodeCaretRule).toBeTrue();
expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
});

describe('#insertRules', () => {
let vs: FshValueSet;
let ruleSet: RuleSet;
Expand Down
Loading