-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract extension contexts to keyword
When processing an Extension definition, set the contexts directly on the ExportableExtension object. When doing so, convert paths back to FSH-style paths. When extracting caret value rules on an Extension definition, do not extract any rules for contexts. Add optimizer plugin to resolve URLs in contexts.
- Loading branch information
1 parent
f56e8fa
commit 70a4e78
Showing
10 changed files
with
431 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { utils } from 'fsh-sushi'; | ||
import { OptimizerPlugin } from '../OptimizerPlugin'; | ||
import { optimizeURL } from '../utils'; | ||
import { Package } from '../../processor'; | ||
import { MasterFisher, ProcessingOptions } from '../../utils'; | ||
import { isUri } from 'valid-url'; | ||
|
||
const FISHER_TYPES = [ | ||
utils.Type.Resource, | ||
utils.Type.Type, | ||
utils.Type.Profile, | ||
utils.Type.Extension, | ||
utils.Type.Logical | ||
]; | ||
|
||
export default { | ||
name: 'resolve_context_urls', | ||
description: 'Replace declared extension context URLs with their names or aliases', | ||
|
||
optimize(pkg: Package, fisher: MasterFisher, options: ProcessingOptions = {}): void { | ||
for (const extension of pkg.extensions) { | ||
if (extension.contexts) { | ||
extension.contexts.forEach(context => { | ||
if (!context.isQuoted) { | ||
// if the context is an extension, value is just a url without a # | ||
// if the context is an element of a non-core resource, value is a url, #, and a path | ||
if (context.value.indexOf('#') > -1) { | ||
const [url, path] = context.value.split('#'); | ||
const newUrl = optimizeURL( | ||
url, | ||
pkg.aliases, | ||
FISHER_TYPES, | ||
fisher, | ||
options.alias ?? true | ||
); | ||
if (newUrl !== url) { | ||
let separator: string; | ||
if (newUrl.startsWith('$')) { | ||
separator = '#'; | ||
} else { | ||
separator = '.'; | ||
} | ||
context.value = `${newUrl}${separator}${path}`; | ||
} | ||
} else if (isUri(context.value)) { | ||
context.value = optimizeURL( | ||
context.value, | ||
pkg.aliases, | ||
FISHER_TYPES, | ||
fisher, | ||
options.alias ?? true | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} as OptimizerPlugin; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"resourceType": "StructureDefinition", | ||
"id": "ExtensionWithContext", | ||
"url": "http://hl7.org/fhir/sushi-test/StructureDefinition/ExtensionWithContext", | ||
"name": "ExtensionWithContext", | ||
"fhirVersion": "4.0.1", | ||
"mapping": [ | ||
{ | ||
"identity": "rim", | ||
"uri": "http://hl7.org/v3", | ||
"name": "RIM Mapping" | ||
} | ||
], | ||
"kind": "complex-type", | ||
"abstract": false, | ||
"context": [ | ||
{ | ||
"expression": "some.fhirpath", | ||
"type": "fhirpath" | ||
} | ||
], | ||
"type": "Extension", | ||
"baseDefinition": "http://hl7.org/fhir/StructureDefinition/Extension", | ||
"derivation": "constraint", | ||
"differential": { | ||
"element": [ | ||
{ | ||
"id": "Extension.url", | ||
"path": "Extension.url", | ||
"fixedUri": "http://hl7.org/fhir/sushi-test/StructureDefinition/ExtensionWithContext" | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.