Skip to content

Commit

Permalink
Remove duplicate definitions from Package (#63)
Browse files Browse the repository at this point in the history
There is currently a bug in how we do exports that causes some duplicates in the  Package.  More specifically, if a FSH Extension is resolved while exporting a Profile,  then the resolved Extension will be put in the Profiles array.  The reverse is also true.  We need to determine how best to fix that bug, but in the meantime, we will just remove the duplicates when we return a Package in FHIRExporter.
  • Loading branch information
cmoesel authored and jafeltra committed Dec 20, 2019
1 parent e6c2cae commit 747a140
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/export/FHIRExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export class FHIRExporter {
this.extensionExporter = new ExtensionExporter(this.FHIRDefs, tank);
const profileDefs = this.profileExporter.export();
const extensionDefs = this.extensionExporter.export();
return new Package(profileDefs, extensionDefs, tank.config);
// TODO: There is currently a bug in how we do exports that causes some duplicates in the
// Package. More specifically, if a FSH Extension is resolved while exporting a Profile,
// then the resolved Extension will be put in the Profiles array. The reverse is also
// true. We need to determine how best to fix that bug, but in the meantime, we will
// just remove the duplicates here so the downstream processes don't have to deal with it.
const deduplicatedProfileDefs = profileDefs.filter(sd => tank.findProfile(sd.name));
const deduplicatedExtensionDefs = extensionDefs.filter(sd => tank.findExtension(sd.name));
return new Package(deduplicatedProfileDefs, deduplicatedExtensionDefs, tank.config);
}
}
17 changes: 12 additions & 5 deletions src/export/StructureDefinitionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,18 @@ export class StructureDefinitionExporter {
this.structDefs.find(sd => sd.name === type || sd.id === type || sd.url === type)
);
if (!structDef) {
// If we find a parent, then we can export and resolve for its type again
const parentDefinition = this.tank.findProfile(type) ?? this.tank.findExtension(type);
if (parentDefinition) {
this.exportStructDef(parentDefinition);
structDef = this.resolve(parentDefinition.name);
// If we find a FSH definition, then we can export and resolve for its type again
// TODO: This causes a problem because this instance of StructureDefinitionExporter is
// either a ProfileExporter or ExtensionExporter -- but we are resolving profiles and
// extensions here. So the end result is that an Extension definition might end up in
// the ProfileExporter's structDefs array and/or a Profile definition might end up in the
// ExtensionExporter's array. This causes duplicates in the final Package. We need to
// fix this, but until we decide the best solution, we are just deduplicating in the
// FHIRExporter.
const fshDefinition = this.tank.findProfile(type) ?? this.tank.findExtension(type);
if (fshDefinition) {
this.exportStructDef(fshDefinition);
structDef = this.resolve(fshDefinition.name);
}
}
return structDef;
Expand Down

0 comments on commit 747a140

Please sign in to comment.