diff --git a/src/fhirtypes/common.ts b/src/fhirtypes/common.ts index 03097562a..5d6dec9f7 100644 --- a/src/fhirtypes/common.ts +++ b/src/fhirtypes/common.ts @@ -940,6 +940,16 @@ export function replaceReferences( 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( diff --git a/test/export/InstanceExporter.test.ts b/test/export/InstanceExporter.test.ts index b5b61c423..3430f9905 100644 --- a/test/export/InstanceExporter.test.ts +++ b/test/export/InstanceExporter.test.ts @@ -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';