Skip to content

Commit

Permalink
convert error to warning, log singular warning with duplicate entity …
Browse files Browse the repository at this point in the history
…names
  • Loading branch information
KaelynJefferson committed Dec 14, 2024
1 parent 415d926 commit 2894758
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
19 changes: 12 additions & 7 deletions src/import/FSHTank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class FSHTank implements Fishable {
...this.getAllExtensions()
];

const duplicateEntities = new Set();
allEntities.forEach(entity => {
if (
this.docs.some(
Expand All @@ -168,15 +169,19 @@ export class FSHTank implements Fishable {
(doc.ruleSets.has(entity.name) && doc.ruleSets.get(entity.name) != entity)
)
) {
logger.error(
`Duplicate entity name: multiple entity types with name ${entity.name} exist.`,
{
file: entity.sourceInfo.file,
location: entity.sourceInfo.location
}
);
duplicateEntities.add(entity.name);
}
});

if (duplicateEntities.size > 0) {
logger.warn(
'Detected FSH entity definitions with duplicate names. While FSH allows for duplicate ' +
'names across entity types, they can lead to ambiguous results when referring to these ' +
'entities by name elsewhere (e.g., in references). Consider using unique names in FSH ' +
'declarations and assigning duplicated names using caret assignment rules instead. ' +
`Detected duplicate names: ${Array.from(duplicateEntities)}.`
);
}
}

fish(
Expand Down
15 changes: 8 additions & 7 deletions test/run/FshToFhir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,17 @@ describe('#FshToFhir', () => {
InstanceOf: MyPatient1
`)
]);
expect(results.errors).toHaveLength(2);
expect(results.warnings).toHaveLength(0);
expect(results.errors).toHaveLength(0);
expect(results.warnings).toHaveLength(1);
expect(results.fhir).toHaveLength(2);
expect(results.fhir[0].id).toBe('MyPatient1');
expect(results.fhir[1].id).toBe('MyPatient1');
expect(results.errors[0].message).toMatch(
/Duplicate entity name: multiple entity types with name MyPatient1 exist/
);
expect(results.errors[1].message).toMatch(
/Duplicate entity name: multiple entity types with name MyPatient1 exist/
expect(results.warnings[0].message).toMatch(
'Detected FSH entity definitions with duplicate names. While FSH allows for duplicate ' +
'names across entity types, they can lead to ambiguous results when referring to these ' +
'entities by name elsewhere (e.g., in references). Consider using unique names in FSH ' +
'declarations and assigning duplicated names using caret assignment rules instead. ' +
'Detected duplicate names: MyPatient1.'
);
});

Expand Down

0 comments on commit 2894758

Please sign in to comment.