Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"yaml": ">=2.8.3",
"picomatch": ">=4.0.4",
"file-type": ">=21.3.2",
"brace-expansion": ">=2.0.3 <3",
"defu": ">=6.1.5",
"vite": "^8.1.5",
"esbuild@>=0.27.3 <0.28.1": "0.28.1",
Expand All @@ -25,7 +24,8 @@
"@xhmikosr/decompress@<10.2.1": "10.2.1",
"ws@>=8.0.0 <8.21.0": "8.21.1",
"@babel/core@<=7.29.0": "7.29.7",
"brace-expansion": "^5.0.7"
"brace-expansion@>=2.0.0 <2.1.4": "2.1.4",
"brace-expansion@>=3.0.0 <5.0.9": "5.0.9"
}
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ async function resolveElements(

let currentPath = resourceType;
let currentElements = result.elements;
// Whether the element the path currently points into is a BackboneElement
// (or a resource, at the root). BackboneElements and resources allow
// `modifierExtension`; plain complex datatypes (e.g. HumanName) do not.
let isBackbone = path.length === 0;

for (const key of path) {
if (key === "resourceType") return [];
Expand All @@ -324,6 +328,7 @@ async function resolveElements(

if (el.contentReference) {
currentPath = el.contentReference.replace(/^#/, "");
isBackbone = true;
continue;
}

Expand All @@ -332,13 +337,15 @@ async function resolveElements(

if (typeCode === "BackboneElement") {
currentPath = el.path;
isBackbone = true;
continue;
}

const typeResult = await collectAllElements(typeCode, getSDs);
if (!typeResult) return [];
currentPath = typeResult.basePath;
currentElements = typeResult.elements;
isBackbone = false;
}

const children = directChildren(currentElements, currentPath);
Expand All @@ -362,9 +369,36 @@ async function resolveElements(
}
}

// Every FHIR element allows `id` and `extension`; BackboneElements and
// resources additionally allow `modifierExtension`. StructureDefinition
// differentials don't repeat these inherited base-type elements for nested
// backbone/complex elements, so add them here (unless already present) so
// both autocomplete and validation see them.
appendUniversalElements(expanded, currentPath, isBackbone);

return expanded;
}

function appendUniversalElements(
elements: FhirElement[],
basePath: string,
isBackbone: boolean,
): void {
const present = new Set(elements.map((el) => fieldName(el)));
const universal: { name: string; type: string }[] = [
{ name: "id", type: "string" },
{ name: "extension", type: "Extension" },
];
if (isBackbone) {
universal.push({ name: "modifierExtension", type: "Extension" });
}
for (const { name, type } of universal) {
if (!present.has(name)) {
elements.push({ path: `${basePath}.${name}`, type: [{ code: type }] });
}
}
}

async function findResourceBoundary(
path: string[],
resourceType: string,
Expand Down
27 changes: 20 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading