@@ -17,6 +17,7 @@ import {
1717 CodeableReference ,
1818 Coding ,
1919 Element ,
20+ Extension ,
2021 Quantity ,
2122 Ratio ,
2223 Reference
@@ -67,7 +68,8 @@ import {
6768 splitOnPathPeriods ,
6869 isReferenceType ,
6970 isModifierExtension ,
70- getArrayIndex
71+ getArrayIndex ,
72+ removeMatchingExtensions
7173} from './common' ;
7274import {
7375 Fishable ,
@@ -81,6 +83,54 @@ import { InstanceDefinition } from './InstanceDefinition';
8183import { idRegex } from './primitiveTypes' ;
8284import sax from 'sax' ;
8385
86+ // ED extensions that should not be inherited by derived profiles
87+ // See: https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java
88+ const UNINHERITED_ED_EXTENSIONS = [
89+ 'http://hl7.org/fhir/tools/StructureDefinition/binding-definition' ,
90+ 'http://hl7.org/fhir/tools/StructureDefinition/no-binding' ,
91+ 'http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding' ,
92+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status' ,
93+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-category' ,
94+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm' ,
95+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-implements' ,
96+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name' ,
97+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category' ,
98+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-wg' ,
99+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-normative-version' ,
100+ 'http://hl7.org/fhir/tools/StructureDefinition/obligation-profile' ,
101+ 'http://hl7.org/fhir/StructureDefinition/obligation-profile' ,
102+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status-reason' ,
103+ 'http://hl7.org/fhir/StructureDefinition/structuredefinition-summary'
104+ ] ;
105+
106+ // ED.type extensions that should not be inherited by derived profiles
107+ // See: https://chat.fhir.org/#narrow/channel/179239-tooling/topic/Forge.20added.20extension.20explicit-type-name/near/328203575
108+ // NOTE: Commented out until the extension list and approach are confirmed (IG Publisher does not seem to do this yet)
109+ // const UNINHERITED_ED_TYPE_EXTENSIONS = [
110+ // 'http://hl7.org/fhir/StructureDefinition/elementdefinition-pattern',
111+ // 'http://hl7.org/fhir/StructureDefinition/regex',
112+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-hierarchy'
113+ // ];
114+
115+ // ED.binding extensions that should not be inherited by derived profiles
116+ // See: https://chat.fhir.org/#narrow/channel/179239-tooling/topic/Forge.20added.20extension.20explicit-type-name/near/328203575
117+ // NOTE: Commented out until the extension list and approach are confirmed (IG Publisher does not seem to do this yet)
118+ // const UNINHERITED_ED_BINDING_EXTENSIONS = [
119+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-category',
120+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-wg',
121+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-normative-version',
122+ // 'http://hl7.org/fhir/build/StructureDefinition/summary',
123+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status',
124+ // 'http://hl7.org/fhir/build/StructureDefinition/notes',
125+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm',
126+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-summary',
127+ // 'http://hl7.org/fhir/build/StructureDefinition/introduction',
128+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-type-characteristics',
129+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category',
130+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-implements',
131+ // 'http://hl7.org/fhir/StructureDefinition/structuredefinition-interface'
132+ // ];
133+
84134const PROFILE_ELEMENT_EXTENSION =
85135 'http://hl7.org/fhir/StructureDefinition/elementdefinition-profile-element' ;
86136
@@ -2739,6 +2789,7 @@ export class ElementDefinition {
27392789 const eClone = e . clone ( ) ;
27402790 eClone . id = eClone . id . replace ( def . pathType , `${ this . id } ` ) ;
27412791 eClone . structDef = this . structDef ;
2792+ eClone . removeUninheritedExtensions ( ) ;
27422793 // Capture the original so that diffs only show what changed *after* unfolding
27432794 eClone . captureOriginal ( ) ;
27442795 return eClone ;
@@ -2772,6 +2823,7 @@ export class ElementDefinition {
27722823 const eClone = e . clone ( shouldCaptureOriginal ) ;
27732824 eClone . id = eClone . id . replace ( targetElement . id , this . id ) ;
27742825 eClone . structDef = this . structDef ;
2826+ eClone . removeUninheritedExtensions ( ) ;
27752827 if ( shouldCaptureOriginal ) {
27762828 eClone . captureOriginal ( ) ;
27772829 }
@@ -2868,6 +2920,7 @@ export class ElementDefinition {
28682920 const eClone = e . clone ( ) ;
28692921 eClone . id = eClone . id . replace ( commonAncestor . pathType , `${ this . id } ` ) ;
28702922 eClone . structDef = this . structDef ;
2923+ eClone . removeUninheritedExtensions ( ) ;
28712924 // Capture the original so that diffs only show what changed *after* unfolding
28722925 eClone . captureOriginal ( ) ;
28732926 return eClone ;
@@ -2881,6 +2934,20 @@ export class ElementDefinition {
28812934 return [ ] ;
28822935 }
28832936
2937+ removeUninheritedExtensions ( ) : void {
2938+ removeMatchingExtensions ( this , UNINHERITED_ED_EXTENSIONS , true ) ;
2939+
2940+ // NOTE: Commented out until the type and binding extensions list -- as well as this approach -- are confirmed
2941+ // removeMatchingExtensions(this.binding ?? {}, UNINHERITED_ED_BINDING_EXTENSIONS, false);
2942+ // this.type?.forEach(t => {
2943+ // removeMatchingExtensions(t, UNINHERITED_ED_TYPE_EXTENSIONS, false);
2944+ // t?._profile?.forEach(p => removeMatchingExtensions(p, UNINHERITED_ED_TYPE_EXTENSIONS, false));
2945+ // t?._targetProfile?.forEach(tp =>
2946+ // removeMatchingExtensions(tp, UNINHERITED_ED_TYPE_EXTENSIONS, false)
2947+ // );
2948+ // });
2949+ }
2950+
28842951 /**
28852952 * Sets up slicings on an element by adding or modifying the element's `slicing`. If a matching slicing discriminator
28862953 * already exists, it will be used
@@ -3175,6 +3242,7 @@ export type ElementDefinitionConstraint = {
31753242} ;
31763243
31773244export type ElementDefinitionBinding = {
3245+ extension ?: Extension [ ] ;
31783246 strength : ElementDefinitionBindingStrength ;
31793247 description ?: string ;
31803248 valueSet ?: string ;
0 commit comments