Skip to content

Commit

Permalink
Support config groups with no resources
Browse files Browse the repository at this point in the history
Fixes #1019
  • Loading branch information
cmoesel committed May 18, 2022
1 parent 6bb534a commit 1516148
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/fshtypes/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export type ConfigurationGroup = {
id: string;
name: string;
description?: string;
resources: string[];
resources?: string[];
};

export type ConfigurationResource = ImplementationGuideDefinitionResource & { omit?: boolean };
Expand Down
36 changes: 19 additions & 17 deletions src/ig/IGExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,25 +1069,27 @@ export class IGExporter {
private addConfiguredGroups(): void {
for (const group of this.config.groups ?? []) {
this.addGroup(group.id, group.name, group.description);
for (const resourceKey of group.resources) {
const existingResource = this.ig.definition.resource.find(
resource => resource.reference?.reference === resourceKey
);
if (!existingResource) {
logger.error(`Group ${group.id} configured with nonexistent resource ${resourceKey}`);
} else {
if (existingResource.groupingId) {
if (existingResource.groupingId === group.id) {
logger.warn(
`Resource ${resourceKey} is listed as a member of group ${group.id}, and does not need a groupingId.`
);
} else {
logger.error(
`Resource ${resourceKey} configured with groupingId ${existingResource.groupingId}, but listed as member of group ${group.id}.`
);
if (group.resources) {
for (const resourceKey of group.resources) {
const existingResource = this.ig.definition.resource.find(
resource => resource.reference?.reference === resourceKey
);
if (!existingResource) {
logger.error(`Group ${group.id} configured with nonexistent resource ${resourceKey}`);
} else {
if (existingResource.groupingId) {
if (existingResource.groupingId === group.id) {
logger.warn(
`Resource ${resourceKey} is listed as a member of group ${group.id}, and does not need a groupingId.`
);
} else {
logger.error(
`Resource ${resourceKey} configured with groupingId ${existingResource.groupingId}, but listed as member of group ${group.id}.`
);
}
}
existingResource.groupingId = group.id;
}
existingResource.groupingId = group.id;
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/ig/IGExporter.IG.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ describe('IGExporter', () => {
name: 'My Observation Group',
description: 'Group for some observation-related things.',
resources: ['StructureDefinition/sample-observation']
},
{
id: 'MyEmptyGroup',
name: 'My Empty Group',
description: 'A group for when nothing is better than something.'
}
];
exporter.export(tempOut);
Expand All @@ -621,6 +626,11 @@ describe('IGExporter', () => {
name: 'My Observation Group',
description: 'Group for some observation-related things.'
});
expect(content.definition.grouping).toContainEqual({
id: 'MyEmptyGroup',
name: 'My Empty Group',
description: 'A group for when nothing is better than something.'
});
const samplePatient: ImplementationGuideDefinitionResource = content.definition.resource.find(
(r: ImplementationGuideDefinitionResource) =>
r?.reference?.reference === 'StructureDefinition/sample-patient'
Expand Down

0 comments on commit 1516148

Please sign in to comment.