Skip to content

Commit

Permalink
Warn when reference values do not resolve and are not in correct form…
Browse files Browse the repository at this point in the history
…at for a reference.
  • Loading branch information
KaelynJefferson committed Jun 5, 2024
1 parent 2b2f51b commit b2c2f16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ export function replaceReferences<T extends AssignmentRule | CaretValueRule>(
(clone.value as FshReference).reference = value.reference.slice(0, firstPipe);
clone = replaceReferences(clone, tank, fisher);
}
// In the case of a user providing a reference to an entity that is unable to be resolved: log warning if
// the type of the reference cannot be resolved, there is no instance found for that reference value, and it has a reference field value
else if (type == null && !instance && value.reference) {
logger.warn(
`Cannot find the entity referenced at ${value.reference}. The provided reference value will be used, however, this reference does not conform to the FHIR Reference() format.`
);
}
}
} else if (value instanceof FshCode) {
// the version on a CodeSystem resource is not the same as the system's actual version out in the world.
Expand Down
20 changes: 19 additions & 1 deletion test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5486,6 +5486,7 @@ describe('InstanceExporter', () => {
expect(exported.managingOrganization).toEqual({
reference: 'Organization/org-id'
});
expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
});

it('should assign a reference while resolving the Instance of a profile being referred to', () => {
Expand Down Expand Up @@ -5533,6 +5534,23 @@ describe('InstanceExporter', () => {
]);
});

it('should log warning when reference values do not resolve and are not in correct format for a reference', () => {
// * target = Reference(exampleReferenceUnableToBeResolved)
const assignedRefRule = new AssignmentRule('target');
assignedRefRule.value = new FshReference('exampleReferenceUnableToBeResolved');
provenanceInstance.rules.push(assignedRefRule);
const exported = exportInstance(provenanceInstance);
expect(exported.target).toEqual([
{
reference: 'exampleReferenceUnableToBeResolved'
}
]);
expect(loggerSpy.getAllMessages('warn')).toHaveLength(2);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Cannot find the entity referenced at exampleReferenceUnableToBeResolved. The provided reference value will be used, however, this reference does not conform to the FHIR Reference() format.'
);
});

it('should assign a reference leaving the full profile URL when it is specified', () => {
const assignedRefRule = new AssignmentRule('target');
assignedRefRule.value = new FshReference(
Expand Down Expand Up @@ -10190,7 +10208,7 @@ describe('InstanceExporter', () => {
}
]
});
expect(loggerSpy.getAllLogs('warn')).toBeEmpty();
expect(loggerSpy.getAllMessages('warn')).toHaveLength(1);
expect(loggerSpy.getAllLogs('error')).toBeEmpty();
});

Expand Down

0 comments on commit b2c2f16

Please sign in to comment.