-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Context keyword when defining Extensions (#1282)
* Import Extensions using Context keyword The Context keyword is used to specify the contexts in which the Extension should be used. Add the keyword to the grammar definition. Store contexts with source info when importing FSH. * Set context when exporting Extensions Contexts specified with the Context keyword are applied to Extensions during export. If the value is quoted, it is a "fhirpath" context. If the value is not quoted and resolves to an Extension definition, it is an "extension" context. Otherwise, it is an "element" context. * Use Context keyword only once The Context keyword is used at most once per extension. This is similar to other metadata keywords. To provide multiple contexts, a comma-separated list can be provided. * Validate extension context during export When using the Context keyword on an Extension, validate that the extension or element specified is something that actually exists. The element is specified by a FSH path, but is exported as a FHIR element id. Always use the resource id when the context is an element on a core FHIR resource. Otherwise, use the URL followed by an element id. * Find deep contained extensions A complex extension may contain more than one level of extension elements. Traverse the extension by url to find deeply nested extensions. When an element path is given as context, it may represent a deeply nested extension. If so, set the context as extension context. The element counts as a deeply nested extension if every element along its path is also an extension. * comment cleanup * Remove special syntax for contained extensions Contained extensions must be specified the same as any other element by using a FSH path. * Keep parent context if Context keyword is not used Only set the default context if the Context keyword is unused and there is no existing context. Assume that the last # present in an unquoted context is what separates the URL from the path. This helps with URLs that contain a # character. * Extension toFSH only writes Context keyword once * Discard extra whitespace tokens in list of contexts Remove unused code from Extension toFSH method.
- Loading branch information
1 parent
fa72a64
commit efcb2fa
Showing
21 changed files
with
5,912 additions
and
2,276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
import { SourceInfo } from './FshEntity'; | ||
import { FshStructure } from './FshStructure'; | ||
import { fshifyString } from './common'; | ||
import { SdRule } from './rules'; | ||
import { EOL } from 'os'; | ||
|
||
export class Extension extends FshStructure { | ||
rules: SdRule[]; | ||
contexts: ExtensionContext[]; | ||
|
||
constructor(public name: string) { | ||
super(name); | ||
// Init the parent to 'Extension', as this is what 99% of extensions do. | ||
// This can still be overridden via the FSH syntax (using Parent: keyword). | ||
this.parent = 'Extension'; // init to 'Extension' | ||
this.contexts = []; | ||
} | ||
|
||
get constructorName() { | ||
return 'Extension'; | ||
} | ||
|
||
metadataToFSH(): string { | ||
const sdMetadata = super.metadataToFSH(); | ||
const contextValue = this.contexts | ||
.map(extContext => | ||
extContext.isQuoted ? `"${fshifyString(extContext.value)}"` : extContext.value | ||
) | ||
.join(', '); | ||
if (contextValue.length > 0) { | ||
return `${sdMetadata}${EOL}Context: ${contextValue}`; | ||
} else { | ||
return sdMetadata; | ||
} | ||
} | ||
|
||
toFSH(): string { | ||
const metadataFSH = this.metadataToFSH(); | ||
const rulesFSH = this.rules.map(r => r.toFSH()).join(EOL); | ||
return `${metadataFSH}${rulesFSH.length ? EOL + rulesFSH : ''}`; | ||
} | ||
} | ||
|
||
export type ExtensionContext = { | ||
value: string; | ||
isQuoted: boolean; | ||
sourceInfo?: SourceInfo; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.