@atomic-ehr/codegen 0.0.1-canary.20251001075906.44a8bb9 → 0.0.1-canary.20251001124254.ddbda7d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +1 -1
- package/dist/cli/index.js +11 -11
- package/dist/typeschema/core/field-builder.d.ts +5 -11
- package/dist/typeschema/core/field-builder.js +18 -26
- package/dist/typeschema/core/nested-types.d.ts +4 -13
- package/dist/typeschema/core/nested-types.js +9 -25
- package/dist/typeschema/core/transformer.d.ts +2 -2
- package/dist/typeschema/core/transformer.js +24 -12
- package/dist/typeschema/profile/processor.js +6 -4
- package/dist/typeschema/register.js +7 -4
- package/dist/typeschema/types.d.ts +7 -14
- package/package.json +1 -1
|
@@ -6,20 +6,14 @@
|
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
7
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
8
|
import type { Register } from "@root/typeschema/register";
|
|
9
|
-
import type { Identifier, PackageMeta,
|
|
10
|
-
export declare function isRequired(fhirSchema: FHIRSchema, path: string[]
|
|
11
|
-
|
|
12
|
-
* Check if a field is excluded
|
|
13
|
-
*/
|
|
14
|
-
export declare function isExcluded(fhirSchema: FHIRSchema, path: string[], _manager: ReturnType<typeof CanonicalManager>): boolean;
|
|
9
|
+
import type { Field, Identifier, PackageMeta, RegularField, RichFHIRSchema } from "../types";
|
|
10
|
+
export declare function isRequired(fhirSchema: FHIRSchema, path: string[]): boolean;
|
|
11
|
+
export declare function isExcluded(fhirSchema: FHIRSchema, path: string[]): boolean;
|
|
15
12
|
export declare const buildReferences: (element: FHIRSchemaElement, register: Register, _packageInfo?: PackageMeta) => Identifier[] | undefined;
|
|
16
13
|
/**
|
|
17
14
|
* Build field type identifier
|
|
18
15
|
*/
|
|
19
16
|
export declare function buildFieldType(fhirSchema: RichFHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageMeta): Identifier | undefined;
|
|
20
|
-
export declare const buildField: (fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement, register: Register, packageInfo?: PackageMeta) =>
|
|
21
|
-
/**
|
|
22
|
-
* Check if an element represents a nested type (BackboneElement)
|
|
23
|
-
*/
|
|
17
|
+
export declare const buildField: (fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement, register: Register, packageInfo?: PackageMeta) => Field;
|
|
24
18
|
export declare function isNestedElement(element: FHIRSchemaElement): boolean;
|
|
25
|
-
export declare function mkNestedField(fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement
|
|
19
|
+
export declare function mkNestedField(_register: Register, fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement): RegularField;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { buildEnum } from "./binding";
|
|
7
7
|
import { mkBindingIdentifier, mkIdentifier, mkNestedIdentifier } from "./identifier";
|
|
8
|
-
export function isRequired(fhirSchema, path
|
|
8
|
+
export function isRequired(fhirSchema, path) {
|
|
9
9
|
if (path.length === 0)
|
|
10
10
|
return false;
|
|
11
11
|
const fieldName = path[path.length - 1];
|
|
@@ -27,10 +27,7 @@ export function isRequired(fhirSchema, path, _manager) {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
* Check if a field is excluded
|
|
32
|
-
*/
|
|
33
|
-
export function isExcluded(fhirSchema, path, _manager) {
|
|
30
|
+
export function isExcluded(fhirSchema, path) {
|
|
34
31
|
if (path.length === 0)
|
|
35
32
|
return false;
|
|
36
33
|
const fieldName = path[path.length - 1];
|
|
@@ -105,8 +102,8 @@ export const buildField = (fhirSchema, path, element, register, packageInfo) =>
|
|
|
105
102
|
}
|
|
106
103
|
return {
|
|
107
104
|
type: buildFieldType(fhirSchema, path, element, register, packageInfo),
|
|
108
|
-
required: isRequired(fhirSchema, path
|
|
109
|
-
excluded: isExcluded(fhirSchema, path
|
|
105
|
+
required: isRequired(fhirSchema, path),
|
|
106
|
+
excluded: isExcluded(fhirSchema, path),
|
|
110
107
|
reference: buildReferences(element, register, packageInfo),
|
|
111
108
|
array: element.array || false,
|
|
112
109
|
min: element.min,
|
|
@@ -116,29 +113,24 @@ export const buildField = (fhirSchema, path, element, register, packageInfo) =>
|
|
|
116
113
|
binding: binding,
|
|
117
114
|
};
|
|
118
115
|
};
|
|
119
|
-
function _removeEmptyValues(obj) {
|
|
120
|
-
const result = {};
|
|
121
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
122
|
-
if (value !== undefined && value !== null) {
|
|
123
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
result[key] = value;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Check if an element represents a nested type (BackboneElement)
|
|
133
|
-
*/
|
|
134
116
|
export function isNestedElement(element) {
|
|
135
|
-
|
|
117
|
+
const isBackbone = element.type === "BackboneElement";
|
|
118
|
+
const isElement = element.type === "Element" && element.elements !== undefined && Object.keys(element.elements).length > 0;
|
|
119
|
+
// ;; TODO: Observation <- vitalsigns <- bodyweight
|
|
120
|
+
// ;; In Observation we have value[x] with choices
|
|
121
|
+
// ;; In bodyweight we have valueQuantity with additional constaraints on it's elements
|
|
122
|
+
// ;; So we need to build nested type from Quantity for here, but don't do that right now.
|
|
123
|
+
const elementsWithoutType = element.type === undefined &&
|
|
124
|
+
element.choiceOf === undefined &&
|
|
125
|
+
element.elements !== undefined &&
|
|
126
|
+
Object.keys(element.elements).length > 0;
|
|
127
|
+
return isBackbone || isElement || elementsWithoutType;
|
|
136
128
|
}
|
|
137
|
-
export function mkNestedField(fhirSchema, path, element
|
|
129
|
+
export function mkNestedField(_register, fhirSchema, path, element) {
|
|
138
130
|
return {
|
|
139
131
|
type: mkNestedIdentifier(fhirSchema, path),
|
|
140
132
|
array: element.array || false,
|
|
141
|
-
required: isRequired(fhirSchema, path
|
|
142
|
-
excluded: isExcluded(fhirSchema, path
|
|
133
|
+
required: isRequired(fhirSchema, path),
|
|
134
|
+
excluded: isExcluded(fhirSchema, path),
|
|
143
135
|
};
|
|
144
136
|
}
|
|
@@ -5,17 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
7
7
|
import type { Register } from "@root/typeschema/register";
|
|
8
|
-
import type {
|
|
9
|
-
/**
|
|
10
|
-
* Collect all nested elements from a FHIRSchema
|
|
11
|
-
*/
|
|
8
|
+
import type { Field, Identifier, NestedType, PackageMeta, RichFHIRSchema } from "../types";
|
|
12
9
|
export declare function collectNestedElements(fhirSchema: FHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>): Array<[string[], FHIRSchemaElement]>;
|
|
13
|
-
export declare function transformNestedElements(fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>, register: Register, packageInfo?: PackageMeta): Promise<Record<string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
export declare function buildNestedTypes(fhirSchema: RichFHIRSchema, register: Register, packageInfo?: PackageMeta): Promise<any[] | undefined>;
|
|
18
|
-
/**
|
|
19
|
-
* Extract dependencies from nested types
|
|
20
|
-
*/
|
|
21
|
-
export declare function extractNestedDependencies(nestedTypes: TypeSchemaNestedType[]): Identifier[];
|
|
10
|
+
export declare function transformNestedElements(fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>, register: Register, packageInfo?: PackageMeta): Promise<Record<string, Field>>;
|
|
11
|
+
export declare function mkNestedTypes(register: Register, fhirSchema: RichFHIRSchema): Promise<NestedType[] | undefined>;
|
|
12
|
+
export declare function extractNestedDependencies(nestedTypes: NestedType[]): Identifier[];
|
|
@@ -5,18 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { buildField, isNestedElement, mkNestedField } from "./field-builder";
|
|
7
7
|
import { mkNestedIdentifier } from "./identifier";
|
|
8
|
-
/**
|
|
9
|
-
* Collect all nested elements from a FHIRSchema
|
|
10
|
-
*/
|
|
11
8
|
export function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
12
9
|
const nested = [];
|
|
13
10
|
for (const [key, element] of Object.entries(elements)) {
|
|
14
11
|
const path = [...parentPath, key];
|
|
15
|
-
// Add this element if it's nested (BackboneElement or has elements)
|
|
16
12
|
if (isNestedElement(element)) {
|
|
17
13
|
nested.push([path, element]);
|
|
18
14
|
}
|
|
19
|
-
// Recursively collect from child elements
|
|
20
15
|
if (element.elements) {
|
|
21
16
|
nested.push(...collectNestedElements(fhirSchema, path, element.elements));
|
|
22
17
|
}
|
|
@@ -29,7 +24,7 @@ export async function transformNestedElements(fhirSchema, parentPath, elements,
|
|
|
29
24
|
const path = [...parentPath, key];
|
|
30
25
|
if (isNestedElement(element)) {
|
|
31
26
|
// Reference to another nested type
|
|
32
|
-
fields[key] = mkNestedField(fhirSchema, path, element
|
|
27
|
+
fields[key] = mkNestedField(register, fhirSchema, path, element);
|
|
33
28
|
}
|
|
34
29
|
else {
|
|
35
30
|
// Regular field
|
|
@@ -38,16 +33,12 @@ export async function transformNestedElements(fhirSchema, parentPath, elements,
|
|
|
38
33
|
}
|
|
39
34
|
return fields;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
|
-
* Build TypeSchema for all nested types in a FHIRSchema
|
|
43
|
-
*/
|
|
44
|
-
export async function buildNestedTypes(fhirSchema, register, packageInfo) {
|
|
36
|
+
export async function mkNestedTypes(register, fhirSchema) {
|
|
45
37
|
if (!fhirSchema.elements)
|
|
46
38
|
return undefined;
|
|
47
|
-
const nestedTypes = [];
|
|
48
39
|
const nestedElements = collectNestedElements(fhirSchema, [], fhirSchema.elements);
|
|
49
|
-
// Filter to only include elements that have sub-elements (actual nested types)
|
|
50
40
|
const actualNested = nestedElements.filter(([_, element]) => element.elements && Object.keys(element.elements).length > 0);
|
|
41
|
+
const nestedTypes = [];
|
|
51
42
|
for (const [path, element] of actualNested) {
|
|
52
43
|
const identifier = mkNestedIdentifier(fhirSchema, path);
|
|
53
44
|
// Base is usually BackboneElement - ensure all nested types have a base
|
|
@@ -57,8 +48,8 @@ export async function buildNestedTypes(fhirSchema, register, packageInfo) {
|
|
|
57
48
|
// For BackboneElement or undefined type, always use BackboneElement as base
|
|
58
49
|
base = {
|
|
59
50
|
kind: "complex-type",
|
|
60
|
-
package:
|
|
61
|
-
version:
|
|
51
|
+
package: fhirSchema.package_meta.name,
|
|
52
|
+
version: fhirSchema.package_meta.version,
|
|
62
53
|
name: "BackboneElement",
|
|
63
54
|
url: "http://hl7.org/fhir/StructureDefinition/BackboneElement",
|
|
64
55
|
};
|
|
@@ -67,17 +58,17 @@ export async function buildNestedTypes(fhirSchema, register, packageInfo) {
|
|
|
67
58
|
// Use the specified type as base
|
|
68
59
|
base = {
|
|
69
60
|
kind: "complex-type",
|
|
70
|
-
package:
|
|
71
|
-
version:
|
|
61
|
+
package: fhirSchema.package_meta.name,
|
|
62
|
+
version: fhirSchema.package_meta.version,
|
|
72
63
|
name: element.type,
|
|
73
64
|
url: `http://hl7.org/fhir/StructureDefinition/${element.type}`,
|
|
74
65
|
};
|
|
75
66
|
}
|
|
76
67
|
// Transform sub-elements into fields
|
|
77
|
-
const fields = await transformNestedElements(fhirSchema, path, element.elements, register,
|
|
68
|
+
const fields = await transformNestedElements(fhirSchema, path, element.elements, register, fhirSchema.package_meta);
|
|
78
69
|
const nestedType = {
|
|
79
70
|
identifier,
|
|
80
|
-
base,
|
|
71
|
+
base,
|
|
81
72
|
fields,
|
|
82
73
|
};
|
|
83
74
|
nestedTypes.push(nestedType);
|
|
@@ -86,19 +77,12 @@ export async function buildNestedTypes(fhirSchema, register, packageInfo) {
|
|
|
86
77
|
nestedTypes.sort((a, b) => a.identifier.url.localeCompare(b.identifier.url));
|
|
87
78
|
return nestedTypes;
|
|
88
79
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Extract dependencies from nested types
|
|
91
|
-
*/
|
|
92
80
|
export function extractNestedDependencies(nestedTypes) {
|
|
93
81
|
const deps = [];
|
|
94
82
|
for (const nested of nestedTypes) {
|
|
95
|
-
// Add the nested type itself as a dependency
|
|
96
|
-
deps.push(nested.identifier);
|
|
97
|
-
// Add base dependency
|
|
98
83
|
if (nested.base) {
|
|
99
84
|
deps.push(nested.base);
|
|
100
85
|
}
|
|
101
|
-
// Add field type dependencies
|
|
102
86
|
for (const field of Object.values(nested.fields || {})) {
|
|
103
87
|
if ("type" in field && field.type) {
|
|
104
88
|
deps.push(field.type);
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
7
7
|
import { type Register } from "@typeschema/register";
|
|
8
|
-
import type { RichFHIRSchema, TypeSchema
|
|
9
|
-
export declare function
|
|
8
|
+
import type { Field, RichFHIRSchema, TypeSchema } from "@typeschema/types";
|
|
9
|
+
export declare function mkFields(register: Register, fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement> | undefined): Promise<Record<string, Field> | undefined>;
|
|
10
10
|
export declare function transformFHIRSchema(register: Register, fhirSchema: RichFHIRSchema): Promise<TypeSchema[]>;
|
|
@@ -8,8 +8,8 @@ import { transformProfile } from "../profile/processor";
|
|
|
8
8
|
import { collectBindingSchemas } from "./binding";
|
|
9
9
|
import { buildField, isNestedElement, mkNestedField } from "./field-builder";
|
|
10
10
|
import { mkIdentifier } from "./identifier";
|
|
11
|
-
import {
|
|
12
|
-
export async function
|
|
11
|
+
import { extractNestedDependencies, mkNestedTypes } from "./nested-types";
|
|
12
|
+
export async function mkFields(register, fhirSchema, parentPath, elements) {
|
|
13
13
|
if (!elements)
|
|
14
14
|
return undefined;
|
|
15
15
|
const geneology = register.resolveFsGenealogy(fhirSchema.url);
|
|
@@ -17,12 +17,12 @@ export async function transformElements(register, fhirSchema, parentPath, elemen
|
|
|
17
17
|
for (const [key, _element] of Object.entries(elements)) {
|
|
18
18
|
const path = [...parentPath, key];
|
|
19
19
|
const elemGeneology = resolveFsElementGenealogy(geneology, path);
|
|
20
|
-
const
|
|
21
|
-
if (isNestedElement(
|
|
22
|
-
fields[key] = mkNestedField(fhirSchema, path,
|
|
20
|
+
const elemSnapshot = fsElementSnapshot(elemGeneology);
|
|
21
|
+
if (isNestedElement(elemSnapshot)) {
|
|
22
|
+
fields[key] = mkNestedField(register, fhirSchema, path, elemSnapshot);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
fields[key] = buildField(fhirSchema, path,
|
|
25
|
+
fields[key] = buildField(fhirSchema, path, elemSnapshot, register, fhirSchema.package_meta);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
return fields;
|
|
@@ -115,7 +115,7 @@ async function transformValueSet(fhirSchema, _register, _packageInfo) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Transform an Extension FHIRSchema to TypeSchema with extension metadata
|
|
117
117
|
*/
|
|
118
|
-
async function transformExtension(fhirSchema, register,
|
|
118
|
+
async function transformExtension(fhirSchema, register, _packageInfo) {
|
|
119
119
|
try {
|
|
120
120
|
const identifier = mkIdentifier(fhirSchema);
|
|
121
121
|
// Build base identifier if present
|
|
@@ -158,14 +158,14 @@ async function transformExtension(fhirSchema, register, packageInfo) {
|
|
|
158
158
|
}
|
|
159
159
|
// Transform elements into fields if present
|
|
160
160
|
if (fhirSchema.elements) {
|
|
161
|
-
const fields = await
|
|
161
|
+
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements);
|
|
162
162
|
if (fields && Object.keys(fields).length > 0) {
|
|
163
163
|
extensionSchema.fields = fields;
|
|
164
164
|
extensionSchema.dependencies.push(...extractFieldDependencies(fields));
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
// Build nested types
|
|
168
|
-
const nestedTypes = await
|
|
168
|
+
const nestedTypes = await mkNestedTypes(register, fhirSchema);
|
|
169
169
|
if (nestedTypes && nestedTypes.length > 0) {
|
|
170
170
|
extensionSchema.nested = nestedTypes;
|
|
171
171
|
extensionSchema.dependencies.push(...extractNestedDependencies(nestedTypes));
|
|
@@ -195,18 +195,29 @@ function extractDependencies(identifier, base, fields, nestedTypes) {
|
|
|
195
195
|
continue;
|
|
196
196
|
uniqDeps[dep.url] = dep;
|
|
197
197
|
}
|
|
198
|
-
const
|
|
198
|
+
const localNestedTypeUrls = new Set(nestedTypes?.map((nt) => nt.identifier.url));
|
|
199
|
+
console.log(1, Object.values(uniqDeps));
|
|
200
|
+
console.log(2, localNestedTypeUrls);
|
|
201
|
+
const result = Object.values(uniqDeps)
|
|
202
|
+
.filter((e) => !(e.kind === "nested" && localNestedTypeUrls.has(e.url)))
|
|
203
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
204
|
+
console.log(3, result);
|
|
199
205
|
return result.length > 0 ? result : undefined;
|
|
200
206
|
}
|
|
201
207
|
async function transformResource(register, fhirSchema) {
|
|
202
208
|
const identifier = mkIdentifier(fhirSchema);
|
|
209
|
+
console.log(6, fhirSchema.name);
|
|
203
210
|
let base;
|
|
204
211
|
if (fhirSchema.base && fhirSchema.type !== "Element") {
|
|
205
212
|
const baseFs = register.resolveFs(register.ensureCanonicalUrl(fhirSchema.base));
|
|
213
|
+
if (!baseFs) {
|
|
214
|
+
throw new Error(`Base resource not found '${fhirSchema.base}' for '${fhirSchema.url}'`);
|
|
215
|
+
}
|
|
206
216
|
base = mkIdentifier(baseFs);
|
|
207
217
|
}
|
|
208
|
-
const fields = await
|
|
209
|
-
|
|
218
|
+
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements);
|
|
219
|
+
console.log(0, fields);
|
|
220
|
+
const nested = await mkNestedTypes(register, fhirSchema);
|
|
210
221
|
const dependencies = extractDependencies(identifier, base, fields, nested);
|
|
211
222
|
const typeSchema = {
|
|
212
223
|
identifier,
|
|
@@ -222,6 +233,7 @@ async function transformResource(register, fhirSchema) {
|
|
|
222
233
|
export async function transformFHIRSchema(register, fhirSchema) {
|
|
223
234
|
const results = [];
|
|
224
235
|
const identifier = mkIdentifier(fhirSchema);
|
|
236
|
+
console.log(5, fhirSchema.name);
|
|
225
237
|
// Handle profiles with specialized processor
|
|
226
238
|
if (identifier.kind === "profile") {
|
|
227
239
|
const profileSchema = await transformProfile(register, fhirSchema);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This file is deprecated as profiles are not part of the core TypeSchema specification
|
|
6
6
|
*/
|
|
7
7
|
import { mkIdentifier } from "../core/identifier";
|
|
8
|
-
import {
|
|
8
|
+
import { mkFields } from "../core/transformer";
|
|
9
9
|
/**
|
|
10
10
|
* Transform a FHIR profile to TypeSchema format
|
|
11
11
|
* Profiles are treated as specialized resources that extend base resources
|
|
@@ -54,7 +54,7 @@ export async function transformProfile(register, fhirSchema) {
|
|
|
54
54
|
}
|
|
55
55
|
// Process profile fields from differential elements
|
|
56
56
|
if (fhirSchema.elements) {
|
|
57
|
-
const fields = await
|
|
57
|
+
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements);
|
|
58
58
|
if (fields && Object.keys(fields).length > 0) {
|
|
59
59
|
profileSchema.fields = fields;
|
|
60
60
|
}
|
|
@@ -79,10 +79,12 @@ export async function transformProfile(register, fhirSchema) {
|
|
|
79
79
|
/**
|
|
80
80
|
* Determine the kind of the base type for a profile
|
|
81
81
|
*/
|
|
82
|
-
async function determineBaseKind(baseUrl,
|
|
82
|
+
async function determineBaseKind(baseUrl, register) {
|
|
83
83
|
try {
|
|
84
84
|
// Try to resolve the base schema
|
|
85
|
-
const baseSchema =
|
|
85
|
+
const baseSchema = register.resolveFs(baseUrl);
|
|
86
|
+
if (!baseSchema)
|
|
87
|
+
return "resource";
|
|
86
88
|
if (baseSchema) {
|
|
87
89
|
// If it's also a constraint, it's likely another profile
|
|
88
90
|
if (baseSchema.derivation === "constraint") {
|
|
@@ -41,14 +41,13 @@ export const registerFromManager = async (manager, logger, packageInfo) => {
|
|
|
41
41
|
const resolveFsGenealogy = (canonicalUrl) => {
|
|
42
42
|
let fs = fhirSchemas[canonicalUrl];
|
|
43
43
|
if (fs === undefined)
|
|
44
|
-
throw new Error(`Failed to resolve FHIR Schema genealogy for ${canonicalUrl}`);
|
|
44
|
+
throw new Error(`Failed to resolve FHIR Schema genealogy for '${canonicalUrl}'`);
|
|
45
45
|
const genealogy = [fs];
|
|
46
46
|
while (fs?.base) {
|
|
47
|
-
console.log(1, fs.base);
|
|
48
47
|
fs = fhirSchemas[fs.base] || fhirSchemas[nameDict[fs.base]];
|
|
49
48
|
genealogy.push(fs);
|
|
50
49
|
if (fs === undefined)
|
|
51
|
-
throw new Error(`Failed to resolve FHIR Schema genealogy for ${canonicalUrl}`);
|
|
50
|
+
throw new Error(`Failed to resolve FHIR Schema genealogy for '${canonicalUrl}'`);
|
|
52
51
|
}
|
|
53
52
|
return genealogy;
|
|
54
53
|
};
|
|
@@ -57,6 +56,7 @@ export const registerFromManager = async (manager, logger, packageInfo) => {
|
|
|
57
56
|
appendFs(fs) {
|
|
58
57
|
const rfs = enrichFHIRSchema(fs);
|
|
59
58
|
fhirSchemas[rfs.url] = rfs;
|
|
59
|
+
nameDict[rfs.name] = rfs.url;
|
|
60
60
|
},
|
|
61
61
|
resolveFs: (canonicalUrl) => fhirSchemas[canonicalUrl],
|
|
62
62
|
resolveFsGenealogy: resolveFsGenealogy,
|
|
@@ -97,5 +97,8 @@ export const resolveFsElementGenealogy = (genealogy, path) => {
|
|
|
97
97
|
};
|
|
98
98
|
export function fsElementSnapshot(genealogy) {
|
|
99
99
|
// FIXME: nested elements will break it
|
|
100
|
-
|
|
100
|
+
const snapshot = genealogy.reverse().reduce((snapshot, elem) => ({ ...snapshot, ...elem }), {});
|
|
101
|
+
// NOTE: to avoid regeneration nested types
|
|
102
|
+
snapshot.elements = undefined;
|
|
103
|
+
return snapshot;
|
|
101
104
|
}
|
|
@@ -62,13 +62,13 @@ interface TypeSchemaForPrimitiveType {
|
|
|
62
62
|
export interface NestedType {
|
|
63
63
|
identifier: NestedIdentifier;
|
|
64
64
|
base: Identifier;
|
|
65
|
-
fields: Record<string,
|
|
65
|
+
fields: Record<string, Field>;
|
|
66
66
|
}
|
|
67
67
|
export interface TypeSchemaForProfile {
|
|
68
68
|
identifier: ProfileIdentifier;
|
|
69
69
|
base: Identifier;
|
|
70
70
|
description?: string;
|
|
71
|
-
fields?: Record<string,
|
|
71
|
+
fields?: Record<string, Field>;
|
|
72
72
|
constraints?: Record<string, ProfileConstraint>;
|
|
73
73
|
extensions?: ProfileExtension[];
|
|
74
74
|
validation?: ValidationRule[];
|
|
@@ -121,21 +121,14 @@ export interface ProfileMetadata {
|
|
|
121
121
|
jurisdiction?: any[];
|
|
122
122
|
package?: string;
|
|
123
123
|
}
|
|
124
|
-
export interface TypeSchemaNestedType {
|
|
125
|
-
identifier: NestedIdentifier;
|
|
126
|
-
base: Identifier;
|
|
127
|
-
fields?: {
|
|
128
|
-
[k: string]: RegularField | PolymorphicValueXFieldDeclaration | PolymorphicValueXFieldInstance;
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
124
|
export interface TypeSchemaForResourceComplexTypeLogical {
|
|
132
125
|
identifier: Identifier;
|
|
133
126
|
base?: Identifier;
|
|
134
127
|
description?: string;
|
|
135
128
|
fields?: {
|
|
136
|
-
[k: string]:
|
|
129
|
+
[k: string]: Field;
|
|
137
130
|
};
|
|
138
|
-
nested?:
|
|
131
|
+
nested?: NestedType[];
|
|
139
132
|
dependencies?: Identifier[];
|
|
140
133
|
}
|
|
141
134
|
export interface RegularField {
|
|
@@ -149,7 +142,7 @@ export interface RegularField {
|
|
|
149
142
|
min?: number;
|
|
150
143
|
max?: number;
|
|
151
144
|
}
|
|
152
|
-
export interface
|
|
145
|
+
export interface PolymorphicDeclarationField {
|
|
153
146
|
choices: string[];
|
|
154
147
|
required?: boolean;
|
|
155
148
|
excluded?: boolean;
|
|
@@ -157,7 +150,7 @@ export interface PolymorphicValueXFieldDeclaration {
|
|
|
157
150
|
min?: number;
|
|
158
151
|
max?: number;
|
|
159
152
|
}
|
|
160
|
-
export interface
|
|
153
|
+
export interface PolymorphicInstanceField {
|
|
161
154
|
choiceOf: string;
|
|
162
155
|
type: Identifier;
|
|
163
156
|
required?: boolean;
|
|
@@ -190,7 +183,7 @@ export interface TypeSchemaForBinding {
|
|
|
190
183
|
valueset?: ValueSetIdentifier;
|
|
191
184
|
dependencies?: Identifier[];
|
|
192
185
|
}
|
|
193
|
-
export type
|
|
186
|
+
export type Field = RegularField | PolymorphicDeclarationField | PolymorphicInstanceField;
|
|
194
187
|
export interface TypeschemaGeneratorOptions {
|
|
195
188
|
verbose?: boolean;
|
|
196
189
|
logger?: import("../utils/codegen-logger").CodegenLogger;
|
package/package.json
CHANGED