Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on empty strings #1158

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/export/CodeSystemExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export class CodeSystemExporter {
private setMetadata(codeSystem: CodeSystem, fshDefinition: FshCodeSystem): void {
codeSystem.setName(fshDefinition);
codeSystem.setId(fshDefinition);
if (fshDefinition.title == '') {
logger.warn(`Code system ${fshDefinition.name} has a title field that should not be empty.`);
}
if (fshDefinition.description == '') {
logger.warn(
`Code system ${fshDefinition.name} has a description field that should not be empty.`
);
}
if (fshDefinition.title) codeSystem.title = fshDefinition.title;
if (fshDefinition.description) codeSystem.description = fshDefinition.description;
// Version is set to value provided in config, will be overriden if reset by rules
Expand Down
8 changes: 8 additions & 0 deletions src/export/InstanceExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ export class InstanceExporter implements Fishable {
const instanceOfStructureDefinition = StructureDefinition.fromJSON(json);
let instanceDef = new InstanceDefinition();
instanceDef._instanceMeta.name = fshDefinition.id; // This is name of the instance in the FSH
if (fshDefinition.title == '') {
logger.warn(`Instance ${fshDefinition.name} has a title field that should not be empty.`);
}
if (fshDefinition.description == '') {
logger.warn(
`Instance ${fshDefinition.name} has a description field that should not be empty.`
);
}
if (fshDefinition.title) {
instanceDef._instanceMeta.title = fshDefinition.title;
}
Expand Down
12 changes: 12 additions & 0 deletions src/export/StructureDefinitionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ export class StructureDefinitionExporter implements Fishable {
delete structDef.identifier;
structDef.version = this.tank.config.version; // can be overridden using a rule
structDef.setName(fshDefinition);
if (fshDefinition.title == '') {
if (fshDefinition instanceof Profile) {
}
logger.warn(
`${fshDefinition.constructorName} ${fshDefinition.name} has a title field that should not be empty.`
);
}
if (fshDefinition.description == '') {
logger.warn(
`${fshDefinition.constructorName} ${fshDefinition.name} has a description field that should not be empty.`
);
}
if (fshDefinition.title) {
structDef.title = fshDefinition.title;
if (
Expand Down
8 changes: 8 additions & 0 deletions src/export/ValueSetExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class ValueSetExporter {
private setMetadata(valueSet: ValueSet, fshDefinition: FshValueSet): void {
valueSet.setName(fshDefinition);
valueSet.setId(fshDefinition);
if (fshDefinition.title == '') {
logger.warn(`Value set ${fshDefinition.name} has a title field that should not be empty.`);
}
if (fshDefinition.description == '') {
logger.warn(
`Value set ${fshDefinition.name} has a description field that should not be empty.`
);
}
if (fshDefinition.title) {
valueSet.title = fshDefinition.title;
}
Expand Down
17 changes: 17 additions & 0 deletions test/export/CodeSystemExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ describe('CodeSystemExporter', () => {
});
});

it('should warn when title and/or description is an empty string', () => {
const codeSystem = new FshCodeSystem('MyCodeSystem');
codeSystem.title = '';
codeSystem.description = '';
doc.codeSystems.set(codeSystem.name, codeSystem);
const exported = exporter.export().codeSystems;
expect(exported.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Code system MyCodeSystem has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Code system MyCodeSystem has a description field that should not be empty.'
);
});

it('should log a message when the code system has an invalid id', () => {
const codeSystem = new FshCodeSystem('StrangeSystem')
.withFile('Strange.fsh')
Expand Down
19 changes: 19 additions & 0 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ describe('InstanceExporter', () => {
expect(loggerSpy.getLastMessage('error')).toMatch(/File: Incorrect\.fsh.*Line: 15 - 18\D*/s);
});

it('should warn when title and/or description is an empty string', () => {
const instance = new Instance('MyInstance');
instance.instanceOf = 'Patient';
instance.title = '';
instance.description = '';
doc.instances.set(instance.name, instance);
const exported = exporter.export().instances;

expect(exported.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Instance MyInstance has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Instance MyInstance has a description field that should not be empty.'
);
});

it('should export instances with InstanceOf FSHy profile', () => {
const profileFoo = new Profile('Foo');
profileFoo.parent = 'Patient';
Expand Down
74 changes: 74 additions & 0 deletions test/export/StructureDefinitionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,80 @@ describe('StructureDefinitionExporter R4', () => {
expect(pkg.extensions.length).toBe(1);
});

it('should warn when the structDef is a profile and title and/or description is an empty string', () => {
const profile = new Profile('Foo');
profile.parent = 'Patient';
profile.title = '';
profile.description = '';
doc.profiles.set(profile.name, profile);
const exported = exporter.export();
expect(exported.profiles.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Profile Foo has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Profile Foo has a description field that should not be empty.'
);
});

it('should warn when the structDef is an extension and title and/or description is an empty string', () => {
const extension = new Extension('Bar');
extension.parent = 'Extension';
extension.title = '';
extension.description = '';
doc.extensions.set(extension.name, extension);
const exported = exporter.export();

expect(exported.extensions.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Extension Bar has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Extension Bar has a description field that should not be empty.'
);
});

it('should warn when the structDef is a logical and title and/or description is an empty string', () => {
const logical = new Logical('BackFooTheFuture');
logical.parent = 'Element';
logical.title = '';
logical.description = '';
doc.logicals.set(logical.name, logical);
const exported = exporter.export();

expect(exported.logicals.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Logical BackFooTheFuture has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Logical BackFooTheFuture has a description field that should not be empty.'
);
});

it('should warn when the structDef is a resource and title and/or description is an empty string', () => {
const resource = new Resource('SpidermanBarFromHome');
resource.parent = 'Resource';
resource.id = 'PatientResource';
resource.title = '';
resource.description = '';
doc.resources.set(resource.name, resource);
exporter.exportStructDef(resource);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Resource SpidermanBarFromHome has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Resource SpidermanBarFromHome has a description field that should not be empty.'
);
});

it('should log a message when the structure definition has an invalid id', () => {
const profile = new Profile('Wrong').withFile('Wrong.fsh').withLocation([1, 8, 4, 18]);
profile.id = 'will?not?work';
Expand Down
17 changes: 17 additions & 0 deletions test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ describe('ValueSetExporter', () => {
});
});

it('should warn when title and/or description is an empty string', () => {
const valueSet = new FshValueSet('BreakfastVS');
valueSet.title = '';
valueSet.description = '';
doc.valueSets.set(valueSet.name, valueSet);
const exported = exporter.export().valueSets;
expect(exported.length).toBe(1);

expect(loggerSpy.getAllMessages('warn').length).toBe(2);
expect(loggerSpy.getFirstMessage('warn')).toMatch(
'Value set BreakfastVS has a title field that should not be empty.'
);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Value set BreakfastVS has a description field that should not be empty.'
);
});

it('should log a message when the value set has an invalid id', () => {
const valueSet = new FshValueSet('BreakfastVS')
.withFile('Breakfast.fsh')
Expand Down