Skip to content

Commit

Permalink
Merge branch 'master' into cimpl-1130-compose-caret-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-thompson authored Aug 3, 2023
2 parents 1b55608 + 93ebd39 commit ea9b3cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit ea9b3cb

Please sign in to comment.