Skip to content

Commit

Permalink
fixed errors in usage of versionId
Browse files Browse the repository at this point in the history
  • Loading branch information
sebg-mio42 committed Jul 17, 2024
1 parent fa627f7 commit dd7e62f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/export/InstanceExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
)
) {
Expand Down
4 changes: 2 additions & 2 deletions src/fhirtypes/InstanceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '-'
});
Expand Down
24 changes: 18 additions & 6 deletions src/import/FSHImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ export function writeFHIRResources(
toJSON: (snapshot: boolean) => any;
url?: string;
id?: string;
versionId?: string;
resourceType?: string;
}[]
) => {
Expand All @@ -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);
Expand Down

0 comments on commit dd7e62f

Please sign in to comment.