Skip to content

Commit

Permalink
Do not list more than one concept at a time for a ValueSet
Browse files Browse the repository at this point in the history
The syntax that was used to support listing multiple concepts in a
single rule is removed. Tests related to this syntax are removed.

Add more tests for making sure that rule context is handled properly in
various combinations of rules on a ValueSet.
  • Loading branch information
mint-thompson committed Jul 31, 2023
1 parent cb87c1a commit dc137a5
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 364 deletions.
3 changes: 1 addition & 2 deletions antlr/src/main/antlr/FSH.g4
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ pathRule: STAR path;

// VALUESET COMPONENTS
vsComponent: STAR ( KW_INCLUDE | KW_EXCLUDE )? ( vsConceptComponent | vsFilterComponent );
vsConceptComponent: code vsComponentFrom?
| (code KW_AND)+ code vsComponentFrom;
vsConceptComponent: code vsComponentFrom?;
vsFilterComponent: KW_CODES vsComponentFrom (KW_WHERE vsFilterList)?;
vsComponentFrom: KW_FROM (vsFromSystem (KW_AND vsFromValueset)? | vsFromValueset (KW_AND vsFromSystem)?);
vsFromSystem: KW_SYSTEM name;
Expand Down
59 changes: 24 additions & 35 deletions src/import/FSHImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,8 @@ export class FSHImporter extends FSHVisitor {
return caretValueRule;
}

// when parsing a ValueSet, we need to keep the system.
// in all other cases, the system is not needed.
visitCodeCaretValueRule(ctx: pc.CodeCaretValueRuleContext, keepSystem = false): CaretValueRule {
const localCodePath = ctx.CODE()
? ctx.CODE().map(code => {
Expand Down Expand Up @@ -1787,6 +1789,8 @@ export class FSHImporter extends FSHVisitor {
return pathRule;
}

// when parsing a ValueSet, we need to keep the system.
// in all other cases, the system is not needed.
visitCodeInsertRule(ctx: pc.CodeInsertRuleContext, keepSystem = false): InsertRule {
const insertRule = new InsertRule('')
.withLocation(this.extractStartStop(ctx))
Expand Down Expand Up @@ -2059,41 +2063,26 @@ export class FSHImporter extends FSHVisitor {
const from: ValueSetComponentFrom = ctx.vsComponentFrom()
? this.visitVsComponentFrom(ctx.vsComponentFrom())
: {};
if (ctx.code().length === 1) {
const singleCode = this.visitCode(ctx.code()[0]);
if (singleCode.system && from.system) {
logger.error(`Concept ${singleCode.code} specifies system multiple times`, {
file: this.currentFile,
location: this.extractStartStop(ctx)
});
} else if (singleCode.system) {
from.system = singleCode.system;
concepts.push(singleCode);
} else if (from.system) {
singleCode.system = from.system;
concepts.push(singleCode);
} else {
logger.error(
`Concept ${singleCode.code} must include system as "SYSTEM#CONCEPT" or "#CONCEPT from system SYSTEM"`,
{
file: this.currentFile,
location: this.extractStartStop(ctx)
}
);
}
} else if (ctx.code().length > 1) {
if (from.system) {
ctx.code().forEach(code => {
const newCode = this.visitCode(code);
newCode.system = from.system;
concepts.push(newCode);
});
} else {
logger.error('System is required when listing concepts in a value set component', {
const singleCode = this.visitCode(ctx.code());
if (singleCode.system && from.system) {
logger.error(`Concept ${singleCode.code} specifies system multiple times`, {
file: this.currentFile,
location: this.extractStartStop(ctx)
});
} else if (singleCode.system) {
from.system = singleCode.system;
concepts.push(singleCode);
} else if (from.system) {
singleCode.system = from.system;
concepts.push(singleCode);
} else {
logger.error(
`Concept ${singleCode.code} must include system as "SYSTEM#CONCEPT" or "#CONCEPT from system SYSTEM"`,
{
file: this.currentFile,
location: this.extractStartStop(ctx)
});
}
}
);
}
return [concepts, from];
}
Expand Down Expand Up @@ -2479,9 +2468,9 @@ export class FSHImporter extends FSHVisitor {
endColumn: ctx.stop.stop - ctx.stop.start + ctx.stop.column + 1
};
if (
!suppressError &&
!(pc.containsPathContext(ctx) || pc.containsCodePathContext(ctx)) &&
location.startColumn - DEFAULT_START_COLUMN > 0 &&
!suppressError
location.startColumn - DEFAULT_START_COLUMN > 0
) {
logger.error(
'A rule that does not use a path cannot be indented to indicate context. The rule will be processed as if it is not indented.',
Expand Down
2 changes: 1 addition & 1 deletion src/import/generated/FSH.interp

Large diffs are not rendered by default.

Loading

0 comments on commit dc137a5

Please sign in to comment.