Skip to content

Commit

Permalink
update reference warn message, account for reference case of uuid or oid
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelynJefferson committed Jun 24, 2024
1 parent 36a7162 commit 0b69980
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,15 +979,15 @@ export function replaceReferences<T extends AssignmentRule | CaretValueRule>(
clone = cloneDeep(rule);
(clone.value as FshReference).reference = value.reference.slice(0, firstPipe);
clone = replaceReferences(clone, tank, fisher);
}
// if the reference to an entity is provided but is unable to be resolved
else if (type == null && id == null && value.reference) {
// if reference does not have type / id reference format
// example: Patient-oops
if (!value.reference.includes('/')) {
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 (type == null && id == null && value.reference) {
// if the reference to an entity is provided but is unable to be resolved
if (!value.reference.startsWith('urn:')) {
if (!value.reference.includes('/')) {
logger.warn(
`Cannot find the entity referenced at ${value.reference}. The provided reference value will be used, but this reference does not conform to the FHIR Reference format.`,
rule.sourceInfo
);
}
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5547,9 +5547,22 @@ describe('InstanceExporter', () => {
]);
expect(loggerSpy.getAllMessages('warn')).toHaveLength(1);
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.'
'Cannot find the entity referenced at exampleReferenceUnableToBeResolved. The provided reference value will be used, but this reference does not conform to the FHIR Reference format.'
);
});
it('should not log warning when reference values do not resolve and is a UUID or OID', () => {
// * target = Reference(urn:uuid:exampleReference)
const assignedRefRule = new AssignmentRule('target');
assignedRefRule.value = new FshReference('urn:uuid:exampleReference');
provenanceInstance.rules.push(assignedRefRule);
const exported = exportInstance(provenanceInstance);
expect(exported.target).toEqual([
{
reference: 'urn:uuid:exampleReference'
}
]);
expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
});

it('should not log warning when reference values do not resolve and is a relative URL with correct number of parts', () => {
// * target = Reference(UnresolvableType/exampleReferenceUnableToBeResolved)
Expand Down

0 comments on commit 0b69980

Please sign in to comment.