diff --git a/src/export/InstanceExporter.ts b/src/export/InstanceExporter.ts index 4020254f2..5c61aae41 100644 --- a/src/export/InstanceExporter.ts +++ b/src/export/InstanceExporter.ts @@ -746,7 +746,13 @@ export class InstanceExporter implements Fishable { } exportInstance(fshDefinition: Instance): InstanceDefinition { - if (this.pkg.instances.some(i => i._instanceMeta.name === fshDefinition.name)) { + if ( + this.pkg.instances.some( + i => + i._instanceMeta.name === fshDefinition.name && + i._instanceMeta.versionId === fshDefinition.versionId + ) + ) { return; } @@ -955,8 +961,7 @@ export class InstanceExporter implements Fishable { instanceDef.resourceType === instance.resourceType && (instanceDef.id ?? instanceDef._instanceMeta.name) === (instance.id ?? instance._instanceMeta.name) && - (instanceDef.versionId) === - (instance.versionId) && + instanceDef._instanceMeta.versionId === instance._instanceMeta.versionId && instanceDef !== instance ) ) { diff --git a/src/fhirtypes/InstanceDefinition.ts b/src/fhirtypes/InstanceDefinition.ts index 3dc124626..48ee97ba4 100644 --- a/src/fhirtypes/InstanceDefinition.ts +++ b/src/fhirtypes/InstanceDefinition.ts @@ -26,8 +26,8 @@ export class InstanceDefinition { getFileName(): string { // Logical instances should use Binary type. See: https://fshschool.org/docs/sushi/tips/#instances-of-logical-models const type = this._instanceMeta.sdKind === 'logical' ? 'Binary' : this.resourceType; - let versionString = (this._instanceMeta.versionId) ? `_v${this._instanceMeta.versionId}` : `` - let filename = `${type}-${this.id ?? this._instanceMeta.name}${versionString}.json`; + const versionString = this._instanceMeta.versionId ? `_v${this._instanceMeta.versionId}` : ''; + const filename = `${type}-${this.id ?? this._instanceMeta.name}${versionString}.json`; return sanitize(filename, { replacement: '-' }); diff --git a/src/import/FSHImporter.ts b/src/import/FSHImporter.ts index 296f08d9c..c0d904aaa 100644 --- a/src/import/FSHImporter.ts +++ b/src/import/FSHImporter.ts @@ -451,11 +451,23 @@ export class FSHImporter extends FSHVisitor { { try { this.parseInstance(instance, location, ctx.instanceMetadata(), ctx.instanceRule()); - if (this.docs.some(doc => (doc.instances.has(instance.name) && (Array.from(doc.instances.values()).some(entity => entity.name === instance.name && entity.versionId === instance.versionId))))) { - logger.error(`Skipping Instance: an Instance named ${instance.name} with versionId ${instance.versionId} already exists.`, { - file: this.currentFile, - location - }); + if ( + this.docs.some( + doc => + doc.instances.has(instance.name) && + Array.from(doc.instances.values()).some( + entity => entity.name === instance.name && entity.versionId === instance.versionId + ) + ) + ) { + const versionString = instance.versionId ? `with versionId ${instance.versionId} ` : ''; + logger.error( + `Skipping Instance: an Instance named ${instance.name} ${versionString}already exists.`, + { + file: this.currentFile, + location + } + ); } else { this.currentDoc.instances.set(instance.name, instance); } @@ -520,7 +532,7 @@ export class FSHImporter extends FSHVisitor { const rule = this.visitInstanceRule(instanceRule); if (rule) { instance.rules.push(rule); - if (rule instanceof AssignmentRule && rule.path === `meta.versionId`) { + if (rule instanceof AssignmentRule && rule.path === 'meta.versionId') { instance.versionId = rule.value.toString(); } } diff --git a/src/utils/Processing.ts b/src/utils/Processing.ts index 353dd38ab..450ed2dab 100644 --- a/src/utils/Processing.ts +++ b/src/utils/Processing.ts @@ -550,6 +550,7 @@ export function writeFHIRResources( toJSON: (snapshot: boolean) => any; url?: string; id?: string; + versionId?: string; resourceType?: string; }[] ) => { @@ -560,7 +561,8 @@ export function writeFHIRResources( predef => predef.url === resource.url && predef.resourceType === resource.resourceType && - predef.id === resource.id + predef.id === resource.id && + predef.versionId === resource.versionId ) ) { checkNullValuesOnArray(resource);