Skip to content

Commit

Permalink
Fix slices on backbone (#88)
Browse files Browse the repository at this point in the history
* fix: treat contentReference as base type
  • Loading branch information
mechanik-daniel authored Jun 27, 2024
1 parent 1388474 commit 2f7bcf3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/helpers/jsonataFunctions/getStructureDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@ export const getStructureDefinitionPath = (definitionId: string): any => {
};

export const getStructureDefinition = (definitionId: string): any => {
// First check if this is a BackboneElement referenced by contentRefernce (strats with #)
try {
if (definitionId.startsWith('#')) {
// Take the base type name
const elementId: string = definitionId.substring(1);
const baseType: string = elementId.split('.')[0];
const baseSnapshot = getStructureDefinition(baseType);
const allElements: any[] = baseSnapshot?.snapshot?.element;
const backboneElements = allElements.filter((e) => e?.id === elementId || String(e?.id).startsWith(elementId + '.'));
return {
derivation: 'specialization',
differential: { element: backboneElements },
snapshot: { element: backboneElements }
};
};
const path: string = getStructureDefinitionPath(definitionId);
if (path) {
const fullDef = JSON.parse(fs.readFileSync(path).toString()); // load file
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/parser/getSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
import fs from 'fs-extra';
import path from 'path';

import { getStructureDefinitionPath } from '../jsonataFunctions/getStructureDefinition';
import { getStructureDefinition, getStructureDefinitionPath } from '../jsonataFunctions/getStructureDefinition';
import { generateSnapshot } from '../snapshotBuilder';
import * as stringFuncs from '../stringFunctions';

const diskCachePath: string = path.join('.', 'snapshots');
fs.ensureDirSync(diskCachePath);

export const getSnapshot = async (rootType: string) => {
if (rootType.startsWith('#')) {
return getStructureDefinition(rootType);
}
// fetch a snapshot from disk cache or build it and save to cache

const originalDefinitionPath: string | undefined = getStructureDefinitionPath(rootType);
if (originalDefinitionPath) {
// found the definition path in index, turn it into a hashkey
Expand Down
11 changes: 6 additions & 5 deletions src/helpers/snapshotBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ const expressions = {
$thisDiff := $inputObject.wipDifferential[id=$this.id];
$thisProfileUrl := $count($thisDiff.type) = 1 and $exists($thisDiff.type.profile) ? $thisDiff.type[0].profile[0];
$thisProfileDef := $exists($thisProfileDef) ? $getStructureDefinition($thisProfileUrl);
$thisProfileDiff := $exists($thisProfileDef) ? $thisProfileDef.differential.element;
Expand Down Expand Up @@ -412,10 +411,12 @@ const expressions = {
/* poly */
'Element'
) : (
/* mono */
$exists($this.type[0].profile) ? (
$this.type[0].profile[0]
) : $this.type[0].code
/* mono or contentReference */
$exists($this.contentReference) ? $this.contentReference : (
$exists($this.type[0].profile) ? (
$this.type[0].profile[0]
) : $this.type[0].code
)
)
);
Expand Down

0 comments on commit 2f7bcf3

Please sign in to comment.