Skip to content

Commit

Permalink
Merge branch 'master' into developing-sushi
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoesel authored Aug 26, 2024
2 parents 8d63945 + e91f68e commit e539fad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/fhirdefs/FHIRDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export class FHIRDefinitions extends BaseFHIRDefinitions implements Fishable {
return flatten(Array.from(this.supplementalFHIRDefinitions.keys()));
}

allPredefinedResources(): any[] {
return Array.from(this.predefinedResources.values()).map(v => cloneDeep(v));
allPredefinedResources(makeClone = true): any[] {
if (makeClone) {
return Array.from(this.predefinedResources.values()).map(v => cloneDeep(v));
} else {
return Array.from(this.predefinedResources.values());
}
}

add(definition: any): void {
Expand Down Expand Up @@ -81,7 +85,7 @@ export class FHIRDefinitions extends BaseFHIRDefinitions implements Fishable {
const resource = this.fishForFHIR(item, ...types);
if (
resource &&
this.allPredefinedResources().find(
this.allPredefinedResources(false).find(
predefResource =>
predefResource.id === resource.id &&
predefResource.resourceType === resource.resourceType &&
Expand Down
26 changes: 16 additions & 10 deletions src/fhirtypes/ElementDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,12 @@ export class ElementDefinition {

getSlices() {
if (this.sliceName) {
return this.structDef.elements.filter(
// this.parent() should never be undefined if this element has a sliceName, but code defensively just in case
return (this.parent()?.children(true) ?? this.structDef.elements).filter(
e => e.id !== this.id && e.path === this.path && e.id.startsWith(`${this.id}/`)
);
} else {
return this.structDef.elements.filter(
return (this.parent()?.children(true) ?? this.structDef.elements).filter(
e => e.id !== this.id && e.path === this.path && e.id.startsWith(`${this.id}:`)
);
}
Expand Down Expand Up @@ -879,12 +880,14 @@ export class ElementDefinition {
const slicedElement = this.slicedElement();
if (slicedElement) {
const parentSlice = this.findParentSlice();
const sliceSiblings = this.structDef.elements.filter(
el =>
this !== el &&
slicedElement === el.slicedElement() &&
parentSlice === el.findParentSlice()
);
const sliceSiblings = this.parent()
.children(true)
.filter(
el =>
this !== el &&
slicedElement === el.slicedElement() &&
parentSlice === el.findParentSlice()
);
const newParentMin = min + sliceSiblings.reduce((sum, el) => sum + el.min, 0);
// if this is a reslice, the parent element will also be a slice of the sliced element.
// if this is not a reslice, the parent element is the sliced element.
Expand Down Expand Up @@ -966,8 +969,9 @@ export class ElementDefinition {
return parentNameParts.slice(0, i + 1).join('/');
})
.reverse();
const elementsToSearch = this.parent()?.children(true) ?? this.structDef.elements;
for (const parentName of potentialParentNames) {
const potentialParent = this.structDef.elements.find(el => {
const potentialParent = elementsToSearch.find(el => {
return el.sliceName === parentName && el.slicedElement() === slicedElement;
});
if (potentialParent) {
Expand Down Expand Up @@ -2567,7 +2571,9 @@ export class ElementDefinition {
*/
slicedElement(): ElementDefinition | undefined {
if (this.sliceName) {
return this.structDef.elements.find(e => e.id === this.id.slice(0, this.id.lastIndexOf(':')));
return (this.parent()?.children(true) ?? this.structDef.elements).find(
e => e.id === this.id.slice(0, this.id.lastIndexOf(':'))
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export function writeFHIRResources(
logger.info('Exporting FHIR resources as JSON...');
let count = 0;
const skippedResources: string[] = [];
const predefinedResources = defs.allPredefinedResources();
const predefinedResources = defs.allPredefinedResources(false);
const writeResources = (
resources: {
getFileName: () => string;
Expand Down

0 comments on commit e539fad

Please sign in to comment.