@atomic-ehr/codegen 0.0.1-canary.20251001154933.613f6c7 → 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.
|
@@ -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
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) {
|
|
@@ -102,8 +87,8 @@ export const mkField = (register, fhirSchema, path, element) => {
|
|
|
102
87
|
}
|
|
103
88
|
return {
|
|
104
89
|
type: buildFieldType(fhirSchema, path, element, register, fhirSchema.package_meta),
|
|
105
|
-
required: isRequired(fhirSchema, path),
|
|
106
|
-
excluded: isExcluded(fhirSchema, path),
|
|
90
|
+
required: isRequired(register, fhirSchema, path),
|
|
91
|
+
excluded: isExcluded(register, fhirSchema, path),
|
|
107
92
|
reference: buildReferences(element, register, fhirSchema.package_meta),
|
|
108
93
|
array: element.array || false,
|
|
109
94
|
min: element.min,
|
|
@@ -127,11 +112,11 @@ export function isNestedElement(element) {
|
|
|
127
112
|
Object.keys(element.elements).length > 0;
|
|
128
113
|
return isBackbone || isElement || elementsWithoutType;
|
|
129
114
|
}
|
|
130
|
-
export function mkNestedField(
|
|
115
|
+
export function mkNestedField(register, fhirSchema, path, element) {
|
|
131
116
|
return {
|
|
132
117
|
type: mkNestedIdentifier(fhirSchema, path),
|
|
133
118
|
array: element.array || false,
|
|
134
|
-
required: isRequired(fhirSchema, path),
|
|
135
|
-
excluded: isExcluded(fhirSchema, path),
|
|
119
|
+
required: isRequired(register, fhirSchema, path),
|
|
120
|
+
excluded: isExcluded(register, fhirSchema, path),
|
|
136
121
|
};
|
|
137
122
|
}
|
|
@@ -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