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

Warn and ignore version when replacing reference #1316

Merged
merged 1 commit into from
Aug 3, 2023
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
10 changes: 10 additions & 0 deletions src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,16 @@ export function replaceReferences<T extends AssignmentRule | CaretValueRule>(
rule.sourceInfo
);
}
} else {
// if we still haven't found anything, there's one more possibility:
// the reference includes a version, which it doesn't need.
const firstPipe = value.reference.indexOf('|');
if (firstPipe > -1) {
logger.warn('Reference assignments should not include a version.', rule.sourceInfo);
clone = cloneDeep(rule);
(clone.value as FshReference).reference = value.reference.slice(0, firstPipe);
clone = replaceReferences(clone, tank, fisher);
}
}
} else if (value instanceof FshCode) {
const codeSystemMeta = fishForMetadataBestVersion(
Expand Down
23 changes: 23 additions & 0 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5902,6 +5902,29 @@ describe('InstanceExporter', () => {
});
});

it('should log a warning and ignore the version when assigning a reference that contains a version', () => {
const orgInstance = new Instance('TestOrganization');
orgInstance.instanceOf = 'Organization';
const assignedIdRule = new AssignmentRule('id');
assignedIdRule.value = 'org-id';
orgInstance.rules.push(assignedIdRule);
const assignedRefRule = new AssignmentRule('managingOrganization')
.withFile('Reference.fsh')
.withLocation([5, 3, 5, 33]);
assignedRefRule.value = new FshReference('TestOrganization|2.3.4');
patientInstance.rules.push(assignedRefRule);
doc.instances.set(patientInstance.name, patientInstance);
doc.instances.set(orgInstance.name, orgInstance);
const exported = exportInstance(patientInstance);
expect(exported.managingOrganization).toEqual({
reference: 'Organization/org-id'
});
expect(loggerSpy.getAllMessages('warn')).toHaveLength(1);
expect(loggerSpy.getLastMessage('warn')).toMatch(
/Reference assignments should not include a version\..*File: Reference\.fsh.*Line: 5\D*/s
);
});

it('should log an error when an invalid reference is assigned', () => {
const observationInstance = new Instance('TestObservation');
observationInstance.instanceOf = 'Observation';
Expand Down
Loading