Skip to content

Commit

Permalink
edit to conditional, tests from feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelynJefferson committed Oct 20, 2024
1 parent 78a71b3 commit 14b7391
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 57 deletions.
15 changes: 5 additions & 10 deletions src/export/CodeSystemExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,11 @@ export class CodeSystemExporter {
}

exportCodeSystem(fshDefinition: FshCodeSystem): CodeSystem {
if (
this.pkg.codeSystems.some(cs => cs.name === fshDefinition.name) ||
this.pkg.instances.some(instance => fshDefinition.name === instance._instanceMeta.name) ||
this.pkg.profiles.some(prof => fshDefinition.name === prof.name) ||
this.pkg.extensions.some(extn => fshDefinition.name === extn.name) ||
this.pkg.logicals.some(logical => fshDefinition.name === logical.name) ||
this.pkg.resources.some(resource => fshDefinition.name === resource.name) ||
this.pkg.valueSets.some(valueSet => fshDefinition.name === valueSet.name)
) {
logger.error(`Multiple FSH entities created with name ${fshDefinition.name}.`);
const duplicatesList = Object.values(Object.fromEntries(this.pkg.fshMap)).find(entry => entry.fshName == fshDefinition.name);
if (duplicatesList) {
logger.error(`Cannot export CodeSystem ${fshDefinition.name}: a ${duplicatesList.fshType} with this name already exists.`,
fshDefinition.sourceInfo
);
return;
}
const codeSystem = new CodeSystem();
Expand Down
15 changes: 5 additions & 10 deletions src/export/InstanceExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,11 @@ export class InstanceExporter implements Fishable {
}

exportInstance(fshDefinition: Instance): InstanceDefinition {
if (
this.pkg.instances.some(i => i._instanceMeta.name === fshDefinition.name) ||
this.pkg.codeSystems.some(cs => cs.name === fshDefinition.name) ||
this.pkg.profiles.some(prof => fshDefinition.name === prof.name) ||
this.pkg.extensions.some(extn => fshDefinition.name === extn.name) ||
this.pkg.logicals.some(logical => fshDefinition.name === logical.name) ||
this.pkg.resources.some(resource => fshDefinition.name === resource.name) ||
this.pkg.valueSets.some(valueSet => fshDefinition.name === valueSet.name)
) {
logger.error(`Multiple FSH entities created with name ${fshDefinition.name}.`);
const duplicatesList = Object.values(Object.fromEntries(this.pkg.fshMap)).find(entry => entry.fshName == fshDefinition.name);
if (duplicatesList) {
logger.error(`Cannot export Instance ${fshDefinition.name}: a ${duplicatesList.fshType} with this name already exists.`,
fshDefinition.sourceInfo
);
return;
}

Expand Down
15 changes: 5 additions & 10 deletions src/export/StructureDefinitionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1337,16 +1337,11 @@ export class StructureDefinitionExporter implements Fishable {
* @throws {InvalidLogicalParentError} when Logical does not have valid parent
*/
exportStructDef(fshDefinition: Profile | Extension | Logical | Resource): StructureDefinition {
if (
this.pkg.profiles.some(sd => sd.name === fshDefinition.name) ||
this.pkg.extensions.some(sd => sd.name === fshDefinition.name) ||
this.pkg.logicals.some(sd => sd.name === fshDefinition.name) ||
this.pkg.resources.some(sd => sd.name === fshDefinition.name) ||
this.pkg.instances.some(i => i._instanceMeta.name === fshDefinition.name) ||
this.pkg.valueSets.some(valueSet => fshDefinition.name === valueSet.name) ||
this.pkg.codeSystems.some(cs => cs.name === fshDefinition.name)
) {
logger.error(`Multiple FSH entities created with name ${fshDefinition.name}.`);
const duplicatesList = Object.values(Object.fromEntries(this.pkg.fshMap)).find(entry => entry.fshName == fshDefinition.name);
if (duplicatesList) {
logger.error(`Cannot export StructureDefinition ${fshDefinition.name}: a ${duplicatesList.fshType} with this name already exists.`,
fshDefinition.sourceInfo
);
return;
}

Expand Down
15 changes: 5 additions & 10 deletions src/export/ValueSetExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,11 @@ export class ValueSetExporter {
}

exportValueSet(fshDefinition: FshValueSet): ValueSet {
if (
this.pkg.valueSets.some(vs => vs.name === fshDefinition.name) ||
this.pkg.profiles.some(sd => sd.name === fshDefinition.name) ||
this.pkg.extensions.some(sd => sd.name === fshDefinition.name) ||
this.pkg.logicals.some(sd => sd.name === fshDefinition.name) ||
this.pkg.resources.some(sd => sd.name === fshDefinition.name) ||
this.pkg.instances.some(i => i._instanceMeta.name === fshDefinition.name) ||
this.pkg.codeSystems.some(cs => cs.name === fshDefinition.name)
) {
logger.error(`Multiple FSH entities created with name ${fshDefinition.name}.`);
const duplicatesList = Object.values(Object.fromEntries(this.pkg.fshMap)).find(entry => entry.fshName == fshDefinition.name);
if (duplicatesList) {
logger.error(`Cannot export ValueSet ${fshDefinition.name}: a ${duplicatesList.fshType} with this name already exists.`,
fshDefinition.sourceInfo
);
return;
}
const vs = new ValueSet();
Expand Down
4 changes: 2 additions & 2 deletions test/export/CodeSystemExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe('CodeSystemExporter', () => {
exporter.exportCodeSystem(secondCodeSystem);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage()).toMatch(
/Multiple FSH entities created with name FirstCodeSystem/s
/Cannot export CodeSystem FirstCodeSystem: a CodeSystem with this name already exists/s
);
});

Expand All @@ -544,7 +544,7 @@ describe('CodeSystemExporter', () => {

expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage()).toMatch(
/Multiple FSH entities created with name FirstCodeSystem/s
/Cannot export Instance FirstCodeSystem: a CodeSystem with this name already exists/s
);
});

Expand Down
24 changes: 13 additions & 11 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ describe('InstanceExporter', () => {
exporter.exportInstance(secondExamplePractitioner);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage()).toMatch(
/Multiple FSH entities created with name MySameExampleName/s
/Cannot export Instance MySameExampleName: a Instance with this name already exists/s
);
});

Expand All @@ -1181,7 +1181,7 @@ describe('InstanceExporter', () => {
csExporter.exportCodeSystem(codeSystem);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage()).toMatch(
/Multiple FSH entities created with name MySameExampleName/s
/Cannot export CodeSystem MySameExampleName: a Instance with this name already exists/s
);
});

Expand Down Expand Up @@ -2236,7 +2236,6 @@ describe('InstanceExporter', () => {
seacowGiven.value = 'Seacow';
seacowName.rules.push(seacowGiven);
doc.instances.set(seacowName.name, seacowName);
exportInstance(seacowName);

// Instance: ThisIsSeacow
// InstanceOf: SeacowPatient
Expand All @@ -2247,8 +2246,14 @@ describe('InstanceExporter', () => {
thisIsName.value = 'SeacowName';
thisIsName.isInstance = true;
thisIsSeacow.rules.push(thisIsName);
const exported = exportInstance(thisIsSeacow);
// expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
doc.instances.set(thisIsSeacow.name, thisIsSeacow);

csExporter.export();
vsExporter.export();
sdExporter.export();
exporter.exportInstance(seacowName);
const exported = exporter.exportInstance(thisIsSeacow);
expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
expect(exported.contact[0].name.given).toEqual(['Manatee', 'Seacow']);
});

Expand Down Expand Up @@ -6905,9 +6910,9 @@ describe('InstanceExporter', () => {
// * instantiatesCanonical = Canonical(TestVS)
carePlanInstance.rules.push(assignedRefRule);

const exported = exportInstance(carePlanInstance);
const exported = exporter.exportInstance(carePlanInstance);
expect(exported.instantiatesCanonical).toEqual(undefined); // instantiatesCanonical is not set with invalid type
expect(loggerSpy.getMessageAtIndex(7, 'error')).toMatch(
expect(loggerSpy.getMessageAtIndex(1, 'error')).toMatch(
/The type "Canonical\(ValueSet\)" does not match any of the allowed types\D*/s
);
});
Expand Down Expand Up @@ -10342,10 +10347,7 @@ describe('InstanceExporter', () => {
afterEach(() => {
// None of the test expect warnings or errors. All should be clean.
expect(loggerSpy.getAllLogs('warn')).toHaveLength(0);
expect(loggerSpy.getAllLogs('error')).toHaveLength(1);
expect(loggerSpy.getMessageAtIndex(0, 'error')).toMatch(
/Multiple FSH entities created with name/
);
expect(loggerSpy.getAllLogs('error')).toHaveLength(1); // TODO
});

// Setting resourceType
Expand Down
4 changes: 2 additions & 2 deletions test/export/StructureDefinitionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ describe('StructureDefinitionExporter R4', () => {
exporter.exportStructDef(secondProfile);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toMatch(
/Multiple FSH entities created with name ExampleProfile/s
/Cannot export StructureDefinition ExampleProfile: a Profile with this name already exists/s
);
});

Expand All @@ -1046,7 +1046,7 @@ describe('StructureDefinitionExporter R4', () => {

expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toMatch(
/Multiple FSH entities created with name SameExampleName/s
/Cannot export Instance SameExampleName: a Profile with this name already exists/s
);
});

Expand Down
4 changes: 2 additions & 2 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ describe('ValueSetExporter', () => {
exporter.exportValueSet(dinner);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toMatch(
/Multiple FSH entities created with name BreakfastVS/s
/Cannot export ValueSet BreakfastVS: a ValueSet with this name already exists/s
);
});

Expand All @@ -358,7 +358,7 @@ describe('ValueSetExporter', () => {

expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toMatch(
/Multiple FSH entities created with name BreakfastVS/s
/Cannot export Instance BreakfastVS: a ValueSet with this name already exists/s
);
});

Expand Down

0 comments on commit 14b7391

Please sign in to comment.