@atomic-ehr/codegen 0.0.1-canary.20251001124254.ddbda7d → 0.0.1-canary.20251002074252.e71a294
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/cli/index.js +34 -34
- package/dist/typeschema/core/binding.d.ts +7 -7
- package/dist/typeschema/core/binding.js +10 -14
- package/dist/typeschema/core/field-builder.d.ts +5 -8
- package/dist/typeschema/core/field-builder.js +42 -56
- package/dist/typeschema/core/identifier.d.ts +3 -3
- package/dist/typeschema/core/nested-types.d.ts +1 -1
- package/dist/typeschema/core/nested-types.js +4 -6
- package/dist/typeschema/core/transformer.js +18 -10
- package/dist/typeschema/register.d.ts +2 -0
- package/dist/typeschema/register.js +9 -0
- package/dist/typeschema/types.d.ts +3 -3
- package/package.json +1 -1
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Functions for processing value set bindings and generating enums
|
|
5
5
|
*/
|
|
6
|
-
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
6
|
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type {
|
|
7
|
+
import type { Register } from "@typeschema/register";
|
|
8
|
+
import type { CanonicalUrl, PackageMeta, RichFHIRSchema, TypeSchemaForBinding } from "@typeschema/types";
|
|
9
9
|
/**
|
|
10
10
|
* Extract concepts from a ValueSet
|
|
11
11
|
*/
|
|
12
|
-
export declare function extractValueSetConcepts(valueSetUrl:
|
|
12
|
+
export declare function extractValueSetConcepts(valueSetUrl: CanonicalUrl, register: Register): {
|
|
13
13
|
system: string;
|
|
14
14
|
code: string;
|
|
15
15
|
display?: string;
|
|
16
|
-
}
|
|
16
|
+
}[] | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* Build enum values from binding if applicable
|
|
19
19
|
*/
|
|
20
|
-
export declare function buildEnum(element: FHIRSchemaElement,
|
|
21
|
-
export declare function generateBindingSchema(fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement,
|
|
20
|
+
export declare function buildEnum(element: FHIRSchemaElement, register: Register): string[] | undefined;
|
|
21
|
+
export declare function generateBindingSchema(fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement, register: Register, packageInfo?: PackageMeta): Promise<TypeSchemaForBinding | undefined>;
|
|
22
22
|
/**
|
|
23
23
|
* Collect all binding schemas from a FHIRSchema
|
|
24
24
|
*/
|
|
25
|
-
export declare function collectBindingSchemas(fhirSchema: RichFHIRSchema,
|
|
25
|
+
export declare function collectBindingSchemas(fhirSchema: RichFHIRSchema, register: Register): Promise<TypeSchemaForBinding[]>;
|
|
@@ -8,10 +8,10 @@ import { dropVersionFromUrl, mkBindingIdentifier, mkValueSetIdentifier } from ".
|
|
|
8
8
|
/**
|
|
9
9
|
* Extract concepts from a ValueSet
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export function extractValueSetConcepts(valueSetUrl, register) {
|
|
12
12
|
try {
|
|
13
13
|
const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
|
|
14
|
-
const valueSet =
|
|
14
|
+
const valueSet = register.resolveVs(cleanUrl);
|
|
15
15
|
if (!valueSet)
|
|
16
16
|
return undefined;
|
|
17
17
|
// If expansion is available, use it
|
|
@@ -39,7 +39,7 @@ export async function extractValueSetConcepts(valueSetUrl, manager) {
|
|
|
39
39
|
else if (include.system && !include.filter) {
|
|
40
40
|
// Include all from CodeSystem
|
|
41
41
|
try {
|
|
42
|
-
const codeSystem =
|
|
42
|
+
const codeSystem = register.resolveAny(include.system);
|
|
43
43
|
if (codeSystem?.concept) {
|
|
44
44
|
const extractConcepts = (conceptList, system) => {
|
|
45
45
|
for (const concept of conceptList) {
|
|
@@ -72,7 +72,7 @@ export async function extractValueSetConcepts(valueSetUrl, manager) {
|
|
|
72
72
|
/**
|
|
73
73
|
* Build enum values from binding if applicable
|
|
74
74
|
*/
|
|
75
|
-
export
|
|
75
|
+
export function buildEnum(element, register) {
|
|
76
76
|
if (!element.binding)
|
|
77
77
|
return undefined;
|
|
78
78
|
const { strength, valueSet } = element.binding;
|
|
@@ -90,12 +90,8 @@ export async function buildEnum(element, manager) {
|
|
|
90
90
|
if (!shouldGenerateEnum) {
|
|
91
91
|
return undefined;
|
|
92
92
|
}
|
|
93
|
-
// Check if manager is available and functional
|
|
94
|
-
if (!manager.resolve) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
93
|
try {
|
|
98
|
-
const concepts =
|
|
94
|
+
const concepts = extractValueSetConcepts(valueSet, register);
|
|
99
95
|
if (!concepts || concepts.length === 0)
|
|
100
96
|
return undefined;
|
|
101
97
|
// Extract just the codes and filter out any empty/invalid ones
|
|
@@ -112,18 +108,18 @@ export async function buildEnum(element, manager) {
|
|
|
112
108
|
return undefined;
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
|
-
export async function generateBindingSchema(fhirSchema, path, element,
|
|
111
|
+
export async function generateBindingSchema(fhirSchema, path, element, register, packageInfo) {
|
|
116
112
|
if (!element.binding?.valueSet)
|
|
117
113
|
return undefined;
|
|
118
114
|
const identifier = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName, packageInfo);
|
|
119
|
-
const fieldType = buildFieldType(fhirSchema, path, element,
|
|
115
|
+
const fieldType = buildFieldType(fhirSchema, path, element, register, packageInfo);
|
|
120
116
|
const valueSetIdentifier = mkValueSetIdentifier(element.binding.valueSet, undefined, packageInfo);
|
|
121
117
|
const dependencies = [];
|
|
122
118
|
if (fieldType) {
|
|
123
119
|
dependencies.push(fieldType);
|
|
124
120
|
}
|
|
125
121
|
dependencies.push(valueSetIdentifier);
|
|
126
|
-
const enumValues = await buildEnum(element,
|
|
122
|
+
const enumValues = await buildEnum(element, register);
|
|
127
123
|
return {
|
|
128
124
|
identifier,
|
|
129
125
|
type: fieldType,
|
|
@@ -136,7 +132,7 @@ export async function generateBindingSchema(fhirSchema, path, element, manager,
|
|
|
136
132
|
/**
|
|
137
133
|
* Collect all binding schemas from a FHIRSchema
|
|
138
134
|
*/
|
|
139
|
-
export async function collectBindingSchemas(fhirSchema,
|
|
135
|
+
export async function collectBindingSchemas(fhirSchema, register) {
|
|
140
136
|
const packageInfo = fhirSchema.package_meta;
|
|
141
137
|
const bindings = [];
|
|
142
138
|
const processedPaths = new Set();
|
|
@@ -151,7 +147,7 @@ export async function collectBindingSchemas(fhirSchema, manager) {
|
|
|
151
147
|
processedPaths.add(pathKey);
|
|
152
148
|
// Generate binding if present
|
|
153
149
|
if (element.binding) {
|
|
154
|
-
const binding = await generateBindingSchema(fhirSchema, path, element,
|
|
150
|
+
const binding = await generateBindingSchema(fhirSchema, path, element, register, packageInfo);
|
|
155
151
|
if (binding) {
|
|
156
152
|
bindings.push(binding);
|
|
157
153
|
}
|
|
@@ -4,16 +4,13 @@
|
|
|
4
4
|
* Functions for transforming FHIRSchema elements into TypeSchema fields
|
|
5
5
|
*/
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
|
-
import type {
|
|
7
|
+
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
8
|
import type { Register } from "@root/typeschema/register";
|
|
9
9
|
import type { Field, Identifier, PackageMeta, RegularField, RichFHIRSchema } from "../types";
|
|
10
|
-
export declare function isRequired(fhirSchema:
|
|
11
|
-
export declare function isExcluded(fhirSchema:
|
|
10
|
+
export declare function isRequired(register: Register, fhirSchema: RichFHIRSchema, path: string[]): boolean;
|
|
11
|
+
export declare function isExcluded(register: Register, fhirSchema: RichFHIRSchema, path: string[]): boolean;
|
|
12
12
|
export declare const buildReferences: (element: FHIRSchemaElement, register: Register, _packageInfo?: PackageMeta) => Identifier[] | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* Build field type identifier
|
|
15
|
-
*/
|
|
16
13
|
export declare function buildFieldType(fhirSchema: RichFHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageMeta): Identifier | undefined;
|
|
17
|
-
export declare const
|
|
14
|
+
export declare const mkField: (register: Register, fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement) => Field;
|
|
18
15
|
export declare function isNestedElement(element: FHIRSchemaElement): boolean;
|
|
19
|
-
export declare function mkNestedField(
|
|
16
|
+
export declare function mkNestedField(register: Register, fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement): RegularField;
|
|
@@ -5,49 +5,37 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { buildEnum } from "./binding";
|
|
7
7
|
import { mkBindingIdentifier, mkIdentifier, mkNestedIdentifier } from "./identifier";
|
|
8
|
-
export function isRequired(fhirSchema, path) {
|
|
9
|
-
if (path.length === 0)
|
|
10
|
-
return false;
|
|
8
|
+
export function isRequired(register, fhirSchema, path) {
|
|
11
9
|
const fieldName = path[path.length - 1];
|
|
12
10
|
const parentPath = path.slice(0, -1);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (parentPath.length === 0 && fieldName && fhirSchema.required?.includes(fieldName)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
11
|
+
const requires = register.resolveFsGenealogy(fhirSchema.url).flatMap((fs) => {
|
|
12
|
+
if (parentPath.length === 0)
|
|
13
|
+
return fs.required || [];
|
|
14
|
+
if (!fs.elements)
|
|
15
|
+
return [];
|
|
16
|
+
let elem = fs;
|
|
17
|
+
for (const k of parentPath) {
|
|
18
|
+
elem = elem?.elements?.[k];
|
|
19
|
+
}
|
|
20
|
+
return elem?.required || [];
|
|
21
|
+
});
|
|
22
|
+
return new Set(requires).has(fieldName);
|
|
29
23
|
}
|
|
30
|
-
export function isExcluded(fhirSchema, path) {
|
|
31
|
-
if (path.length === 0)
|
|
32
|
-
return false;
|
|
24
|
+
export function isExcluded(register, fhirSchema, path) {
|
|
33
25
|
const fieldName = path[path.length - 1];
|
|
34
26
|
const parentPath = path.slice(0, -1);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (parentPath.length === 0 && fieldName && fhirSchema.excluded?.includes(fieldName)) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
27
|
+
const requires = register.resolveFsGenealogy(fhirSchema.url).flatMap((fs) => {
|
|
28
|
+
if (parentPath.length === 0)
|
|
29
|
+
return fs.excluded || [];
|
|
30
|
+
if (!fs.elements)
|
|
31
|
+
return [];
|
|
32
|
+
let elem = fs;
|
|
33
|
+
for (const k of parentPath) {
|
|
34
|
+
elem = elem?.elements?.[k];
|
|
35
|
+
}
|
|
36
|
+
return elem?.excluded || [];
|
|
37
|
+
});
|
|
38
|
+
return new Set(requires).has(fieldName);
|
|
51
39
|
}
|
|
52
40
|
export const buildReferences = (element, register, _packageInfo) => {
|
|
53
41
|
if (!element.refers)
|
|
@@ -58,9 +46,6 @@ export const buildReferences = (element, register, _packageInfo) => {
|
|
|
58
46
|
return mkIdentifier(fs);
|
|
59
47
|
});
|
|
60
48
|
};
|
|
61
|
-
/**
|
|
62
|
-
* Build field type identifier
|
|
63
|
-
*/
|
|
64
49
|
export function buildFieldType(fhirSchema, _path, element, _manager, packageInfo) {
|
|
65
50
|
// Handle element reference (for slicing)
|
|
66
51
|
if (element.elementReference) {
|
|
@@ -91,46 +76,47 @@ export function buildFieldType(fhirSchema, _path, element, _manager, packageInfo
|
|
|
91
76
|
}
|
|
92
77
|
return undefined;
|
|
93
78
|
}
|
|
94
|
-
export const
|
|
79
|
+
export const mkField = (register, fhirSchema, path, element) => {
|
|
95
80
|
let binding;
|
|
96
|
-
let
|
|
81
|
+
let enumValues;
|
|
97
82
|
if (element.binding) {
|
|
98
|
-
binding = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName,
|
|
83
|
+
binding = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName, fhirSchema.package_meta);
|
|
99
84
|
if (element.binding.strength === "required" && element.type === "code") {
|
|
100
|
-
|
|
85
|
+
enumValues = buildEnum(element, register);
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
88
|
return {
|
|
104
|
-
type: buildFieldType(fhirSchema, path, element, register,
|
|
105
|
-
required: isRequired(fhirSchema, path),
|
|
106
|
-
excluded: isExcluded(fhirSchema, path),
|
|
107
|
-
reference: buildReferences(element, register,
|
|
89
|
+
type: buildFieldType(fhirSchema, path, element, register, fhirSchema.package_meta),
|
|
90
|
+
required: isRequired(register, fhirSchema, path),
|
|
91
|
+
excluded: isExcluded(register, fhirSchema, path),
|
|
92
|
+
reference: buildReferences(element, register, fhirSchema.package_meta),
|
|
108
93
|
array: element.array || false,
|
|
109
94
|
min: element.min,
|
|
110
95
|
max: element.max,
|
|
111
96
|
choices: element.choices,
|
|
112
97
|
choiceOf: element.choiceOf,
|
|
113
98
|
binding: binding,
|
|
99
|
+
enum: enumValues,
|
|
114
100
|
};
|
|
115
101
|
};
|
|
116
102
|
export function isNestedElement(element) {
|
|
117
103
|
const isBackbone = element.type === "BackboneElement";
|
|
118
104
|
const isElement = element.type === "Element" && element.elements !== undefined && Object.keys(element.elements).length > 0;
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
105
|
+
// TODO: Observation <- vitalsigns <- bodyweight
|
|
106
|
+
// In Observation we have value[x] with choices
|
|
107
|
+
// In bodyweight we have valueQuantity with additional constaraints on it's elements
|
|
108
|
+
// So we need to build nested type from Quantity for here, but don't do that right now.
|
|
123
109
|
const elementsWithoutType = element.type === undefined &&
|
|
124
110
|
element.choiceOf === undefined &&
|
|
125
111
|
element.elements !== undefined &&
|
|
126
112
|
Object.keys(element.elements).length > 0;
|
|
127
113
|
return isBackbone || isElement || elementsWithoutType;
|
|
128
114
|
}
|
|
129
|
-
export function mkNestedField(
|
|
115
|
+
export function mkNestedField(register, fhirSchema, path, element) {
|
|
130
116
|
return {
|
|
131
117
|
type: mkNestedIdentifier(fhirSchema, path),
|
|
132
118
|
array: element.array || false,
|
|
133
|
-
required: isRequired(fhirSchema, path),
|
|
134
|
-
excluded: isExcluded(fhirSchema, path),
|
|
119
|
+
required: isRequired(register, fhirSchema, path),
|
|
120
|
+
excluded: isExcluded(register, fhirSchema, path),
|
|
135
121
|
};
|
|
136
122
|
}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Functions for creating TypeSchema identifiers from FHIRSchema entities
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchema } from "@atomic-ehr/fhirschema";
|
|
7
|
-
import type { BindingIdentifier, Identifier, NestedIdentifier, PackageMeta, RichFHIRSchema, TypeSchemaForValueSet } from "@typeschema/types";
|
|
8
|
-
export declare function dropVersionFromUrl(url:
|
|
7
|
+
import type { BindingIdentifier, CanonicalUrl, Identifier, NestedIdentifier, PackageMeta, RichFHIRSchema, TypeSchemaForValueSet } from "@typeschema/types";
|
|
8
|
+
export declare function dropVersionFromUrl(url: CanonicalUrl | undefined): CanonicalUrl | undefined;
|
|
9
9
|
export declare function mkIdentifier(fhirSchema: RichFHIRSchema): Identifier;
|
|
10
10
|
export declare function mkNestedIdentifier(fhirSchema: RichFHIRSchema, path: string[]): NestedIdentifier;
|
|
11
|
-
export declare function mkValueSetIdentifier(valueSetUrl:
|
|
11
|
+
export declare function mkValueSetIdentifier(valueSetUrl: CanonicalUrl, valueSet: any, packageInfo?: PackageMeta): TypeSchemaForValueSet["identifier"];
|
|
12
12
|
export declare function mkBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, _packageInfo?: PackageMeta): BindingIdentifier;
|
|
@@ -7,6 +7,6 @@ import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
|
7
7
|
import type { Register } from "@root/typeschema/register";
|
|
8
8
|
import type { Field, Identifier, NestedType, PackageMeta, RichFHIRSchema } from "../types";
|
|
9
9
|
export declare function collectNestedElements(fhirSchema: FHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>): Array<[string[], FHIRSchemaElement]>;
|
|
10
|
-
export declare function transformNestedElements(fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>, register: Register,
|
|
10
|
+
export declare function transformNestedElements(fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement>, register: Register, _packageInfo?: PackageMeta): Promise<Record<string, Field>>;
|
|
11
11
|
export declare function mkNestedTypes(register: Register, fhirSchema: RichFHIRSchema): Promise<NestedType[] | undefined>;
|
|
12
12
|
export declare function extractNestedDependencies(nestedTypes: NestedType[]): Identifier[];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Functions for extracting and transforming nested types from FHIRSchema
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { isNestedElement, mkField, mkNestedField } from "./field-builder";
|
|
7
7
|
import { mkNestedIdentifier } from "./identifier";
|
|
8
8
|
export function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
9
9
|
const nested = [];
|
|
@@ -18,17 +18,15 @@ export function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
|
18
18
|
}
|
|
19
19
|
return nested;
|
|
20
20
|
}
|
|
21
|
-
export async function transformNestedElements(fhirSchema, parentPath, elements, register,
|
|
21
|
+
export async function transformNestedElements(fhirSchema, parentPath, elements, register, _packageInfo) {
|
|
22
22
|
const fields = {};
|
|
23
23
|
for (const [key, element] of Object.entries(elements)) {
|
|
24
24
|
const path = [...parentPath, key];
|
|
25
25
|
if (isNestedElement(element)) {
|
|
26
|
-
// Reference to another nested type
|
|
27
26
|
fields[key] = mkNestedField(register, fhirSchema, path, element);
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
|
|
31
|
-
fields[key] = await buildField(fhirSchema, path, element, register, packageInfo);
|
|
29
|
+
fields[key] = mkField(register, fhirSchema, path, element);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
return fields;
|
|
@@ -75,7 +73,7 @@ export async function mkNestedTypes(register, fhirSchema) {
|
|
|
75
73
|
}
|
|
76
74
|
// Sort by URL for consistent output
|
|
77
75
|
nestedTypes.sort((a, b) => a.identifier.url.localeCompare(b.identifier.url));
|
|
78
|
-
return nestedTypes;
|
|
76
|
+
return nestedTypes.length === 0 ? undefined : nestedTypes;
|
|
79
77
|
}
|
|
80
78
|
export function extractNestedDependencies(nestedTypes) {
|
|
81
79
|
const deps = [];
|
|
@@ -6,23 +6,37 @@
|
|
|
6
6
|
import { fsElementSnapshot, resolveFsElementGenealogy } from "@typeschema/register";
|
|
7
7
|
import { transformProfile } from "../profile/processor";
|
|
8
8
|
import { collectBindingSchemas } from "./binding";
|
|
9
|
-
import {
|
|
9
|
+
import { isNestedElement, mkField, mkNestedField } from "./field-builder";
|
|
10
10
|
import { mkIdentifier } from "./identifier";
|
|
11
11
|
import { extractNestedDependencies, mkNestedTypes } from "./nested-types";
|
|
12
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);
|
|
16
|
-
const
|
|
17
|
-
for (const [key,
|
|
16
|
+
const elems = {};
|
|
17
|
+
for (const [key, elem] of Object.entries(elements)) {
|
|
18
18
|
const path = [...parentPath, key];
|
|
19
19
|
const elemGeneology = resolveFsElementGenealogy(geneology, path);
|
|
20
20
|
const elemSnapshot = fsElementSnapshot(elemGeneology);
|
|
21
|
+
elems[key] = { elem, elemSnapshot, path };
|
|
22
|
+
}
|
|
23
|
+
for (const [_key, { elem, elemSnapshot, path }] of Object.entries(elems)) {
|
|
24
|
+
for (const choiceKey of elem?.choices || []) {
|
|
25
|
+
if (!elems[choiceKey]) {
|
|
26
|
+
const path = [...parentPath, choiceKey];
|
|
27
|
+
const elemGeneology = resolveFsElementGenealogy(geneology, path);
|
|
28
|
+
const elemSnapshot = fsElementSnapshot(elemGeneology);
|
|
29
|
+
elems[choiceKey] = { elem: undefined, elemSnapshot, path };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const fields = {};
|
|
34
|
+
for (const [key, { elem, elemSnapshot, path }] of Object.entries(elems)) {
|
|
21
35
|
if (isNestedElement(elemSnapshot)) {
|
|
22
36
|
fields[key] = mkNestedField(register, fhirSchema, path, elemSnapshot);
|
|
23
37
|
}
|
|
24
38
|
else {
|
|
25
|
-
fields[key] =
|
|
39
|
+
fields[key] = mkField(register, fhirSchema, path, elemSnapshot);
|
|
26
40
|
}
|
|
27
41
|
}
|
|
28
42
|
return fields;
|
|
@@ -196,17 +210,13 @@ function extractDependencies(identifier, base, fields, nestedTypes) {
|
|
|
196
210
|
uniqDeps[dep.url] = dep;
|
|
197
211
|
}
|
|
198
212
|
const localNestedTypeUrls = new Set(nestedTypes?.map((nt) => nt.identifier.url));
|
|
199
|
-
console.log(1, Object.values(uniqDeps));
|
|
200
|
-
console.log(2, localNestedTypeUrls);
|
|
201
213
|
const result = Object.values(uniqDeps)
|
|
202
214
|
.filter((e) => !(e.kind === "nested" && localNestedTypeUrls.has(e.url)))
|
|
203
215
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
204
|
-
console.log(3, result);
|
|
205
216
|
return result.length > 0 ? result : undefined;
|
|
206
217
|
}
|
|
207
218
|
async function transformResource(register, fhirSchema) {
|
|
208
219
|
const identifier = mkIdentifier(fhirSchema);
|
|
209
|
-
console.log(6, fhirSchema.name);
|
|
210
220
|
let base;
|
|
211
221
|
if (fhirSchema.base && fhirSchema.type !== "Element") {
|
|
212
222
|
const baseFs = register.resolveFs(register.ensureCanonicalUrl(fhirSchema.base));
|
|
@@ -216,7 +226,6 @@ async function transformResource(register, fhirSchema) {
|
|
|
216
226
|
base = mkIdentifier(baseFs);
|
|
217
227
|
}
|
|
218
228
|
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements);
|
|
219
|
-
console.log(0, fields);
|
|
220
229
|
const nested = await mkNestedTypes(register, fhirSchema);
|
|
221
230
|
const dependencies = extractDependencies(identifier, base, fields, nested);
|
|
222
231
|
const typeSchema = {
|
|
@@ -233,7 +242,6 @@ async function transformResource(register, fhirSchema) {
|
|
|
233
242
|
export async function transformFHIRSchema(register, fhirSchema) {
|
|
234
243
|
const results = [];
|
|
235
244
|
const identifier = mkIdentifier(fhirSchema);
|
|
236
|
-
console.log(5, fhirSchema.name);
|
|
237
245
|
// Handle profiles with specialized processor
|
|
238
246
|
if (identifier.kind === "profile") {
|
|
239
247
|
const profileSchema = await transformProfile(register, fhirSchema);
|
|
@@ -11,7 +11,9 @@ export type Register = {
|
|
|
11
11
|
allSd(): StructureDefinition[];
|
|
12
12
|
allFs(): RichFHIRSchema[];
|
|
13
13
|
allVs(): any[];
|
|
14
|
+
resolveVs(canonicalUrl: CanonicalUrl): any | undefined;
|
|
14
15
|
complexTypeDict(): Record<string, RichFHIRSchema>;
|
|
16
|
+
resolveAny(canonicalUrl: CanonicalUrl): any | undefined;
|
|
15
17
|
} & ReturnType<typeof CanonicalManager>;
|
|
16
18
|
export declare const registerFromManager: (manager: ReturnType<typeof CanonicalManager>, logger?: CodegenLogger, packageInfo?: PackageMeta) => Promise<Register>;
|
|
17
19
|
export declare const registerFromPackageMetas: (packageMetas: PackageMeta[], logger?: CodegenLogger) => Promise<Register>;
|
|
@@ -3,6 +3,13 @@ import * as fhirschema from "@atomic-ehr/fhirschema";
|
|
|
3
3
|
import { enrichFHIRSchema } from "@typeschema/types";
|
|
4
4
|
export const registerFromManager = async (manager, logger, packageInfo) => {
|
|
5
5
|
const resources = await manager.search({});
|
|
6
|
+
const any = {};
|
|
7
|
+
for (const resource of resources) {
|
|
8
|
+
const url = resource.url;
|
|
9
|
+
if (!url)
|
|
10
|
+
continue;
|
|
11
|
+
any[url] = resource;
|
|
12
|
+
}
|
|
6
13
|
const structureDefinitions = {};
|
|
7
14
|
for (const resource of resources) {
|
|
8
15
|
if (resource.resourceType === "StructureDefinition") {
|
|
@@ -65,7 +72,9 @@ export const registerFromManager = async (manager, logger, packageInfo) => {
|
|
|
65
72
|
resolveSd: (canonicalUrl) => structureDefinitions[canonicalUrl],
|
|
66
73
|
allFs: () => Object.values(fhirSchemas),
|
|
67
74
|
allVs: () => Object.values(valueSets),
|
|
75
|
+
resolveVs: (canonicalUrl) => valueSets[canonicalUrl],
|
|
68
76
|
complexTypeDict: () => complexTypes,
|
|
77
|
+
resolveAny: (canonicalUrl) => any[canonicalUrl],
|
|
69
78
|
};
|
|
70
79
|
};
|
|
71
80
|
export const registerFromPackageMetas = async (packageMetas, logger) => {
|
|
@@ -142,7 +142,7 @@ export interface RegularField {
|
|
|
142
142
|
min?: number;
|
|
143
143
|
max?: number;
|
|
144
144
|
}
|
|
145
|
-
export interface
|
|
145
|
+
export interface ChoiceFieldDeclaration {
|
|
146
146
|
choices: string[];
|
|
147
147
|
required?: boolean;
|
|
148
148
|
excluded?: boolean;
|
|
@@ -150,7 +150,7 @@ export interface PolymorphicDeclarationField {
|
|
|
150
150
|
min?: number;
|
|
151
151
|
max?: number;
|
|
152
152
|
}
|
|
153
|
-
export interface
|
|
153
|
+
export interface ChoiceFieldInstance {
|
|
154
154
|
choiceOf: string;
|
|
155
155
|
type: Identifier;
|
|
156
156
|
required?: boolean;
|
|
@@ -183,7 +183,7 @@ export interface TypeSchemaForBinding {
|
|
|
183
183
|
valueset?: ValueSetIdentifier;
|
|
184
184
|
dependencies?: Identifier[];
|
|
185
185
|
}
|
|
186
|
-
export type Field = RegularField |
|
|
186
|
+
export type Field = RegularField | ChoiceFieldDeclaration | ChoiceFieldInstance;
|
|
187
187
|
export interface TypeschemaGeneratorOptions {
|
|
188
188
|
verbose?: boolean;
|
|
189
189
|
logger?: import("../utils/codegen-logger").CodegenLogger;
|
package/package.json
CHANGED