@atomic-ehr/codegen 0.0.1-canary.20250924120719.44f2f7c → 0.0.1-canary.20250927094522.7f26cfe
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/builder.d.ts +7 -5
- package/dist/api/builder.js +8 -6
- package/dist/api/generators/base/BaseGenerator.d.ts +5 -5
- package/dist/api/generators/base/BaseGenerator.js +4 -4
- package/dist/api/generators/base/FileManager.d.ts +2 -2
- package/dist/api/generators/base/FileManager.js +1 -1
- package/dist/api/generators/base/PythonTypeMapper.d.ts +3 -3
- package/dist/api/generators/base/PythonTypeMapper.js +1 -1
- package/dist/api/generators/base/TemplateEngine.d.ts +1 -1
- package/dist/api/generators/base/TemplateEngine.js +1 -1
- package/dist/api/generators/base/TypeMapper.d.ts +2 -2
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +3 -3
- package/dist/api/generators/base/TypeScriptTypeMapper.js +1 -1
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +4 -4
- package/dist/api/generators/base/builders/FileBuilder.d.ts +2 -2
- package/dist/api/generators/base/builders/IndexBuilder.d.ts +2 -2
- package/dist/api/generators/base/enhanced-errors.d.ts +2 -2
- package/dist/api/generators/base/enhanced-errors.js +1 -1
- package/dist/api/generators/base/error-handler.d.ts +2 -2
- package/dist/api/generators/base/error-handler.js +1 -1
- package/dist/api/generators/base/errors.d.ts +2 -2
- package/dist/api/generators/base/index.d.ts +22 -22
- package/dist/api/generators/base/index.js +11 -11
- package/dist/api/generators/base/types.d.ts +4 -4
- package/dist/api/generators/typescript.d.ts +6 -6
- package/dist/api/generators/typescript.js +54 -46
- package/dist/api/index.d.ts +8 -8
- package/dist/api/index.js +3 -3
- package/dist/cli/commands/generate/typescript.d.ts +1 -1
- package/dist/cli/commands/generate/typescript.js +2 -2
- package/dist/cli/commands/generate.d.ts +1 -1
- package/dist/cli/commands/generate.js +4 -4
- package/dist/cli/commands/index.js +3 -3
- package/dist/cli/commands/typeschema/generate.js +3 -3
- package/dist/cli/commands/typeschema.js +2 -2
- package/dist/cli/index.js +55 -55
- package/dist/cli/utils/log.d.ts +2 -2
- package/dist/cli/utils/log.js +2 -2
- package/dist/config.d.ts +2 -2
- package/dist/config.js +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/typeschema/cache.d.ts +7 -7
- package/dist/typeschema/core/binding.d.ts +1 -1
- package/dist/typeschema/core/binding.js +6 -4
- package/dist/typeschema/core/field-builder.d.ts +3 -3
- package/dist/typeschema/core/field-builder.js +3 -3
- package/dist/typeschema/core/identifier.d.ts +5 -17
- package/dist/typeschema/core/identifier.js +15 -47
- package/dist/typeschema/core/nested-types.d.ts +2 -2
- package/dist/typeschema/core/nested-types.js +2 -2
- package/dist/typeschema/core/transformer.d.ts +3 -3
- package/dist/typeschema/core/transformer.js +20 -28
- package/dist/typeschema/generator.d.ts +3 -4
- package/dist/typeschema/generator.js +12 -14
- package/dist/typeschema/index.d.ts +4 -5
- package/dist/typeschema/index.js +4 -4
- package/dist/typeschema/parser.d.ts +5 -5
- package/dist/typeschema/profile/processor.d.ts +2 -3
- package/dist/typeschema/profile/processor.js +12 -10
- package/dist/typeschema/types.d.ts +66 -375
- package/dist/typeschema/types.js +14 -2
- package/dist/typeschema/value-set/processor.d.ts +1 -1
- package/dist/typeschema/value-set/processor.js +1 -1
- package/package.json +2 -2
- package/dist/typeschema/schema.d.ts +0 -485
- package/dist/typeschema/schema.js +0 -456
- package/dist/typeschema/type-schema.types.d.ts +0 -186
- package/dist/typeschema/type-schema.types.js +0 -39
- package/dist/typeschema/utils.d.ts +0 -6
- package/dist/typeschema/utils.js +0 -13
package/dist/cli/utils/log.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI Utilities - Re-exports from main utils with spinner support
|
|
3
3
|
*/
|
|
4
|
-
import { createSpinner } from "./spinner
|
|
5
|
-
export { type CodegenLogger, complete, configure, createLogger, debug, dim, error, header, info, type LogOptions, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger
|
|
4
|
+
import { createSpinner } from "./spinner";
|
|
5
|
+
export { type CodegenLogger, complete, configure, createLogger, debug, dim, error, header, info, type LogOptions, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
|
|
6
6
|
export { createSpinner };
|
|
7
7
|
/**
|
|
8
8
|
* Run a task with a spinner
|
package/dist/cli/utils/log.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI Utilities - Re-exports from main utils with spinner support
|
|
3
3
|
*/
|
|
4
|
-
import { createSpinner } from "./spinner
|
|
4
|
+
import { createSpinner } from "./spinner";
|
|
5
5
|
// Re-export all logger functions from the main utils
|
|
6
|
-
export { complete, configure, createLogger, debug, dim, error, header, info, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger
|
|
6
|
+
export { complete, configure, createLogger, debug, dim, error, header, info, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
|
|
7
7
|
// Export CLI-specific utilities
|
|
8
8
|
export { createSpinner };
|
|
9
9
|
/**
|
package/dist/config.d.ts
CHANGED
|
@@ -22,11 +22,11 @@ export interface TypeScriptGeneratorConfig {
|
|
|
22
22
|
/** Include helper validation functions in value set files (default: false) */
|
|
23
23
|
includeValueSetHelpers?: boolean;
|
|
24
24
|
/** Which binding strengths to generate value sets for (default: ['required']) */
|
|
25
|
-
valueSetStrengths?: (
|
|
25
|
+
valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
|
|
26
26
|
/** Directory name for value set files (relative to outputDir) (default: 'valuesets') */
|
|
27
27
|
valueSetDirectory?: string;
|
|
28
28
|
/** Value set generation mode (default: 'required-only') */
|
|
29
|
-
valueSetMode?:
|
|
29
|
+
valueSetMode?: "all" | "required-only" | "custom";
|
|
30
30
|
fhirVersion?: "R4" | "R5";
|
|
31
31
|
resourceTypes?: string[];
|
|
32
32
|
maxDepth?: number;
|
package/dist/config.js
CHANGED
|
@@ -27,9 +27,9 @@ export const DEFAULT_CONFIG = {
|
|
|
27
27
|
includeCodeSystems: false,
|
|
28
28
|
includeOperations: false,
|
|
29
29
|
generateValueSets: false,
|
|
30
|
-
valueSetDirectory:
|
|
31
|
-
valueSetMode:
|
|
32
|
-
valueSetStrengths: [
|
|
30
|
+
valueSetDirectory: "valuesets",
|
|
31
|
+
valueSetMode: "required-only",
|
|
32
|
+
valueSetStrengths: ["required"],
|
|
33
33
|
includeValueSetHelpers: false,
|
|
34
34
|
fhirVersion: "R4",
|
|
35
35
|
resourceTypes: [],
|
|
@@ -107,7 +107,7 @@ export const DEFAULT_CONFIG = {
|
|
|
107
107
|
*/
|
|
108
108
|
export const CONFIG_FILE_NAMES = [
|
|
109
109
|
"atomic-codegen.config.ts",
|
|
110
|
-
"atomic-codegen.config
|
|
110
|
+
"atomic-codegen.config",
|
|
111
111
|
"atomic-codegen.config.json",
|
|
112
112
|
".atomic-codegenrc",
|
|
113
113
|
"atomic-codegen.json",
|
|
@@ -504,7 +504,7 @@ export class ConfigLoader {
|
|
|
504
504
|
async loadFromFile(filePath) {
|
|
505
505
|
try {
|
|
506
506
|
let config;
|
|
507
|
-
if (filePath.endsWith(".ts") || filePath.endsWith("
|
|
507
|
+
if (filePath.endsWith(".ts") || filePath.endsWith("")) {
|
|
508
508
|
// Use dynamic import for TypeScript/JavaScript files
|
|
509
509
|
const absolutePath = resolve(filePath);
|
|
510
510
|
const importResult = await import(absolutePath);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Caching system for TypeSchema documents with both in-memory and persistent file-based storage.
|
|
5
5
|
*/
|
|
6
|
-
import type { TypeSchemaConfig } from "
|
|
7
|
-
import type { TypeSchema,
|
|
6
|
+
import type { TypeSchemaConfig } from "@root/config";
|
|
7
|
+
import type { TypeSchema, Identifier } from "@typeschema/types";
|
|
8
8
|
/**
|
|
9
9
|
* TypeSchema Cache with optional persistent storage
|
|
10
10
|
*/
|
|
@@ -20,7 +20,7 @@ export declare class TypeSchemaCache {
|
|
|
20
20
|
/**
|
|
21
21
|
* Retrieve a schema by identifier
|
|
22
22
|
*/
|
|
23
|
-
get(identifier:
|
|
23
|
+
get(identifier: Identifier): TypeSchema | null;
|
|
24
24
|
/**
|
|
25
25
|
* Retrieve a schema by URL
|
|
26
26
|
*/
|
|
@@ -28,7 +28,7 @@ export declare class TypeSchemaCache {
|
|
|
28
28
|
/**
|
|
29
29
|
* Check if a schema exists in cache
|
|
30
30
|
*/
|
|
31
|
-
has(identifier:
|
|
31
|
+
has(identifier: Identifier): boolean;
|
|
32
32
|
/**
|
|
33
33
|
* Check if a schema exists by URL
|
|
34
34
|
*/
|
|
@@ -36,7 +36,7 @@ export declare class TypeSchemaCache {
|
|
|
36
36
|
/**
|
|
37
37
|
* Delete a schema from cache
|
|
38
38
|
*/
|
|
39
|
-
delete(identifier:
|
|
39
|
+
delete(identifier: Identifier): boolean;
|
|
40
40
|
/**
|
|
41
41
|
* Delete a schema by URL
|
|
42
42
|
*/
|
|
@@ -97,8 +97,8 @@ export declare function cacheSchema(schema: TypeSchema): void;
|
|
|
97
97
|
/**
|
|
98
98
|
* Get cached schema using global cache
|
|
99
99
|
*/
|
|
100
|
-
export declare function getCachedSchema(identifier:
|
|
100
|
+
export declare function getCachedSchema(identifier: Identifier): TypeSchema | null;
|
|
101
101
|
/**
|
|
102
102
|
* Check if schema is cached using global cache
|
|
103
103
|
*/
|
|
104
|
-
export declare function isCached(identifier:
|
|
104
|
+
export declare function isCached(identifier: Identifier): boolean;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
7
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type { PackageInfo, TypeSchemaForBinding } from "../types
|
|
8
|
+
import type { PackageInfo, TypeSchemaForBinding } from "../types";
|
|
9
9
|
/**
|
|
10
10
|
* Extract concepts from a ValueSet
|
|
11
11
|
*/
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Functions for processing value set bindings and generating enums
|
|
6
6
|
*/
|
|
7
|
-
import { buildFieldType } from "./field-builder
|
|
8
|
-
import { buildBindingIdentifier, buildValueSetIdentifier, dropVersionFromUrl, } from "./identifier
|
|
7
|
+
import { buildFieldType } from "./field-builder";
|
|
8
|
+
import { buildBindingIdentifier, buildValueSetIdentifier, dropVersionFromUrl, } from "./identifier";
|
|
9
9
|
/**
|
|
10
10
|
* Extract concepts from a ValueSet
|
|
11
11
|
*/
|
|
@@ -86,8 +86,10 @@ export async function buildEnum(element, manager) {
|
|
|
86
86
|
// 3. Preferred bindings on code types (for common usage patterns)
|
|
87
87
|
// 4. Extensible bindings on Coding types (broader coverage)
|
|
88
88
|
const shouldGenerateEnum = strength === "required" ||
|
|
89
|
-
(strength === "extensible" &&
|
|
90
|
-
|
|
89
|
+
(strength === "extensible" &&
|
|
90
|
+
(element.type === "code" || element.type === "Coding")) ||
|
|
91
|
+
(strength === "preferred" &&
|
|
92
|
+
(element.type === "code" || element.type === "Coding"));
|
|
91
93
|
if (!shouldGenerateEnum) {
|
|
92
94
|
return undefined;
|
|
93
95
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
7
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type { PackageInfo, TypeSchemaField,
|
|
8
|
+
import type { PackageInfo, TypeSchemaField, Identifier } from "../types";
|
|
9
9
|
/**
|
|
10
10
|
* Get the full element hierarchy for a given path
|
|
11
11
|
*/
|
|
@@ -25,11 +25,11 @@ export declare function isExcluded(fhirSchema: FHIRSchema, path: string[], _mana
|
|
|
25
25
|
/**
|
|
26
26
|
* Build reference array from element refers
|
|
27
27
|
*/
|
|
28
|
-
export declare function buildReferences(element: FHIRSchemaElement, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Promise<
|
|
28
|
+
export declare function buildReferences(element: FHIRSchemaElement, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Promise<Identifier[] | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* Build field type identifier
|
|
31
31
|
*/
|
|
32
|
-
export declare function buildFieldType(fhirSchema: FHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo):
|
|
32
|
+
export declare function buildFieldType(fhirSchema: FHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Identifier | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Build a TypeSchema field from a FHIRSchema element
|
|
35
35
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import { buildEnum } from "./binding
|
|
3
|
-
import { buildBindingIdentifier, buildNestedIdentifier, buildSchemaIdentifier, } from "./identifier
|
|
2
|
+
import { buildEnum } from "./binding";
|
|
3
|
+
import { buildBindingIdentifier, buildNestedIdentifier, buildSchemaIdentifier, } from "./identifier";
|
|
4
4
|
/**
|
|
5
5
|
* Get the full element hierarchy for a given path
|
|
6
6
|
*/
|
|
@@ -134,7 +134,7 @@ export async function buildReferences(element, manager, packageInfo) {
|
|
|
134
134
|
try {
|
|
135
135
|
const resource = await manager.resolve(ref);
|
|
136
136
|
if (resource) {
|
|
137
|
-
references.push(buildSchemaIdentifier(resource
|
|
137
|
+
references.push(buildSchemaIdentifier(resource));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
catch { }
|
|
@@ -4,24 +4,12 @@
|
|
|
4
4
|
* Functions for creating TypeSchema identifiers from FHIRSchema entities
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchema } from "@atomic-ehr/fhirschema";
|
|
7
|
-
import type { PackageInfo, TypeSchemaForValueSet,
|
|
8
|
-
/**
|
|
9
|
-
* Drop version suffix from canonical URL (e.g., "http://example.com|1.0.0" -> "http://example.com")
|
|
10
|
-
*/
|
|
7
|
+
import type { PackageInfo, TypeSchemaForValueSet, Identifier, RichFHIRSchema } from "../types";
|
|
11
8
|
export declare function dropVersionFromUrl(url: string | undefined): string | undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare function buildSchemaIdentifier(fhirSchema: FHIRSchema, packageInfo?: PackageInfo): TypeSchemaIdentifier;
|
|
16
|
-
/**
|
|
17
|
-
* Build nested type identifier for BackboneElements
|
|
18
|
-
*/
|
|
19
|
-
export declare function buildNestedIdentifier(fhirSchema: FHIRSchema, path: string[], packageInfo?: PackageInfo): TypeSchemaIdentifier;
|
|
20
|
-
/**
|
|
21
|
-
* Build value set identifier
|
|
22
|
-
*/
|
|
23
|
-
export declare function buildValueSetIdentifier(valueSetUrl: string, valueSet?: any, packageInfo?: PackageInfo): TypeSchemaForValueSet["identifier"];
|
|
9
|
+
export declare function buildSchemaIdentifier(fhirSchema: RichFHIRSchema): Identifier;
|
|
10
|
+
export declare function buildNestedIdentifier(fhirSchema: FHIRSchema, path: string[], packageInfo?: PackageInfo): Identifier;
|
|
11
|
+
export declare function buildValueSetIdentifier(valueSetUrl: string, valueSet: any, packageInfo?: PackageInfo): TypeSchemaForValueSet["identifier"];
|
|
24
12
|
/**
|
|
25
13
|
* Build binding identifier for an element with value set binding
|
|
26
14
|
*/
|
|
27
|
-
export declare function buildBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, packageInfo?: PackageInfo):
|
|
15
|
+
export declare function buildBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, packageInfo?: PackageInfo): Identifier;
|
|
@@ -3,73 +3,41 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Functions for creating TypeSchema identifiers from FHIRSchema entities
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
* Drop version suffix from canonical URL (e.g., "http://example.com|1.0.0" -> "http://example.com")
|
|
8
|
-
*/
|
|
9
6
|
export function dropVersionFromUrl(url) {
|
|
10
7
|
if (!url)
|
|
11
8
|
return undefined;
|
|
12
9
|
return url.split("|")[0];
|
|
13
10
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Determine the kind of schema based on FHIRSchema properties
|
|
16
|
-
*/
|
|
17
11
|
function determineKind(fhirSchema) {
|
|
18
|
-
|
|
19
|
-
if (fhirSchema.derivation === "constraint") {
|
|
20
|
-
// Distinguish between profiles and other constraints
|
|
21
|
-
// Profiles typically constrain resources or complex types and have a base type
|
|
22
|
-
if (fhirSchema.base &&
|
|
23
|
-
(fhirSchema.type === "Resource" ||
|
|
24
|
-
fhirSchema.kind === "resource" ||
|
|
25
|
-
fhirSchema.kind === "complex-type")) {
|
|
26
|
-
return "profile";
|
|
27
|
-
}
|
|
12
|
+
if (fhirSchema.derivation === "constraint")
|
|
28
13
|
return "profile";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (fhirSchema.kind)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case "complex-type":
|
|
36
|
-
return "complex-type";
|
|
37
|
-
case "resource":
|
|
38
|
-
return "resource";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Default to resource
|
|
14
|
+
if (fhirSchema.kind === "primitive-type")
|
|
15
|
+
return "primitive-type";
|
|
16
|
+
if (fhirSchema.kind === "complex-type")
|
|
17
|
+
return "complex-type";
|
|
18
|
+
if (fhirSchema.kind === "resource")
|
|
19
|
+
return "resource";
|
|
42
20
|
return "resource";
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
* Build identifier for primitive-type, complex-type, resource, or constraint
|
|
46
|
-
*/
|
|
47
|
-
export function buildSchemaIdentifier(fhirSchema, packageInfo) {
|
|
48
|
-
const kind = determineKind(fhirSchema);
|
|
22
|
+
export function buildSchemaIdentifier(fhirSchema) {
|
|
49
23
|
return {
|
|
50
|
-
kind,
|
|
51
|
-
package:
|
|
52
|
-
version:
|
|
24
|
+
kind: determineKind(fhirSchema),
|
|
25
|
+
package: fhirSchema.package_meta.name,
|
|
26
|
+
version: fhirSchema.package_meta.version,
|
|
53
27
|
name: fhirSchema.name,
|
|
54
28
|
url: fhirSchema.url,
|
|
55
29
|
};
|
|
56
30
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Build nested type identifier for BackboneElements
|
|
59
|
-
*/
|
|
60
31
|
export function buildNestedIdentifier(fhirSchema, path, packageInfo) {
|
|
61
32
|
const nestedName = path.join(".");
|
|
62
33
|
return {
|
|
63
34
|
kind: "nested",
|
|
64
|
-
package: packageInfo?.name || fhirSchema.
|
|
65
|
-
version: packageInfo?.version || fhirSchema.
|
|
35
|
+
package: packageInfo?.name || fhirSchema.package_meta.name || "undefined",
|
|
36
|
+
version: packageInfo?.version || fhirSchema.package_meta.version || "undefined",
|
|
66
37
|
name: nestedName,
|
|
67
38
|
url: `${fhirSchema.url}#${nestedName}`,
|
|
68
39
|
};
|
|
69
40
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Build value set identifier
|
|
72
|
-
*/
|
|
73
41
|
export function buildValueSetIdentifier(valueSetUrl, valueSet, packageInfo) {
|
|
74
42
|
const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
|
|
75
43
|
// Generate a meaningful name from the URL instead of using potentially hash-like IDs
|
|
@@ -107,8 +75,8 @@ export function buildBindingIdentifier(fhirSchema, path, bindingName, packageInf
|
|
|
107
75
|
const name = bindingName || `${fhirSchema.name}.${pathStr}_binding`;
|
|
108
76
|
return {
|
|
109
77
|
kind: "binding",
|
|
110
|
-
package: packageInfo?.name || fhirSchema.
|
|
111
|
-
version: packageInfo?.version || fhirSchema.
|
|
78
|
+
package: packageInfo?.name || fhirSchema.package_meta.name || "undefined",
|
|
79
|
+
version: packageInfo?.version || fhirSchema.package_meta.version || "undefined",
|
|
112
80
|
name,
|
|
113
81
|
url: bindingName
|
|
114
82
|
? `urn:fhir:binding:${name}`
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
7
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type { PackageInfo, TypeSchemaField,
|
|
8
|
+
import type { PackageInfo, TypeSchemaField, Identifier } from "../types";
|
|
9
9
|
/**
|
|
10
10
|
* Collect all nested elements from a FHIRSchema
|
|
11
11
|
*/
|
|
@@ -21,4 +21,4 @@ export declare function buildNestedTypes(fhirSchema: FHIRSchema, manager: Return
|
|
|
21
21
|
/**
|
|
22
22
|
* Extract dependencies from nested types
|
|
23
23
|
*/
|
|
24
|
-
export declare function extractNestedDependencies(nestedTypes: TypeSchemaNestedType[]):
|
|
24
|
+
export declare function extractNestedDependencies(nestedTypes: TypeSchemaNestedType[]): Identifier[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import { buildField, buildNestedField, isNestedElement
|
|
3
|
-
import { buildNestedIdentifier } from "./identifier
|
|
2
|
+
import { buildField, buildNestedField, isNestedElement } from "./field-builder";
|
|
3
|
+
import { buildNestedIdentifier } from "./identifier";
|
|
4
4
|
/**
|
|
5
5
|
* Collect all nested elements from a FHIRSchema
|
|
6
6
|
*/
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
7
|
import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type { TypeSchema, TypeSchemaField } from "
|
|
9
|
-
import type { PackageInfo } from "../types
|
|
8
|
+
import type { TypeSchema, TypeSchemaField, RichFHIRSchema } from "@typeschema/types";
|
|
9
|
+
import type { PackageInfo } from "../types";
|
|
10
10
|
/**
|
|
11
11
|
* Transform elements into fields
|
|
12
12
|
*/
|
|
@@ -15,4 +15,4 @@ export declare function transformElements(fhirSchema: FHIRSchema, parentPath: st
|
|
|
15
15
|
* Transform a single FHIRSchema to TypeSchema(s) with enhanced categorization
|
|
16
16
|
* Returns the main schema plus any binding schemas
|
|
17
17
|
*/
|
|
18
|
-
export declare function transformFHIRSchema(manager: ReturnType<typeof CanonicalManager>, fhirSchema:
|
|
18
|
+
export declare function transformFHIRSchema(manager: ReturnType<typeof CanonicalManager>, fhirSchema: RichFHIRSchema): Promise<TypeSchema[]>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import { transformProfile } from "../profile/processor
|
|
3
|
-
import { collectBindingSchemas } from "./binding
|
|
4
|
-
import { buildField, buildNestedField, getElementHierarchy, isNestedElement, mergeElementHierarchy, } from "./field-builder
|
|
5
|
-
import { buildSchemaIdentifier } from "./identifier
|
|
6
|
-
import { buildNestedTypes, extractNestedDependencies } from "./nested-types
|
|
2
|
+
import { transformProfile } from "../profile/processor";
|
|
3
|
+
import { collectBindingSchemas } from "./binding";
|
|
4
|
+
import { buildField, buildNestedField, getElementHierarchy, isNestedElement, mergeElementHierarchy, } from "./field-builder";
|
|
5
|
+
import { buildSchemaIdentifier } from "./identifier";
|
|
6
|
+
import { buildNestedTypes, extractNestedDependencies } from "./nested-types";
|
|
7
7
|
/**
|
|
8
8
|
* Transform elements into fields
|
|
9
9
|
*/
|
|
@@ -86,7 +86,7 @@ function isExtensionSchema(fhirSchema, _identifier) {
|
|
|
86
86
|
*/
|
|
87
87
|
async function transformValueSet(fhirSchema, _manager, packageInfo) {
|
|
88
88
|
try {
|
|
89
|
-
const identifier = buildSchemaIdentifier(fhirSchema
|
|
89
|
+
const identifier = buildSchemaIdentifier(fhirSchema);
|
|
90
90
|
identifier.kind = "value-set"; // Ensure correct kind
|
|
91
91
|
const valueSetSchema = {
|
|
92
92
|
identifier,
|
|
@@ -123,7 +123,7 @@ async function transformValueSet(fhirSchema, _manager, packageInfo) {
|
|
|
123
123
|
*/
|
|
124
124
|
async function transformExtension(fhirSchema, manager, packageInfo) {
|
|
125
125
|
try {
|
|
126
|
-
const identifier = buildSchemaIdentifier(fhirSchema
|
|
126
|
+
const identifier = buildSchemaIdentifier(fhirSchema);
|
|
127
127
|
// Build base identifier if present
|
|
128
128
|
let base;
|
|
129
129
|
if (fhirSchema.base && fhirSchema.base !== "Extension") {
|
|
@@ -133,8 +133,8 @@ async function transformExtension(fhirSchema, manager, packageInfo) {
|
|
|
133
133
|
const baseName = fhirSchema.base.split("/").pop() || fhirSchema.base;
|
|
134
134
|
base = {
|
|
135
135
|
kind: "complex-type",
|
|
136
|
-
package:
|
|
137
|
-
version:
|
|
136
|
+
package: "hl7.fhir.r4.core",
|
|
137
|
+
version: "4.0.1",
|
|
138
138
|
name: baseName,
|
|
139
139
|
url: baseUrl,
|
|
140
140
|
};
|
|
@@ -191,29 +191,21 @@ async function transformExtension(fhirSchema, manager, packageInfo) {
|
|
|
191
191
|
* Transform a single FHIRSchema to TypeSchema(s) with enhanced categorization
|
|
192
192
|
* Returns the main schema plus any binding schemas
|
|
193
193
|
*/
|
|
194
|
-
export async function transformFHIRSchema(manager, fhirSchema
|
|
194
|
+
export async function transformFHIRSchema(manager, fhirSchema) {
|
|
195
195
|
const results = [];
|
|
196
|
-
|
|
197
|
-
if (!packageInfo && (fhirSchema.package_name || fhirSchema.package_id)) {
|
|
198
|
-
packageInfo = {
|
|
199
|
-
name: fhirSchema.package_name || fhirSchema.package_id || "undefined",
|
|
200
|
-
version: fhirSchema.package_version || "undefined",
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
// Build main identifier with enhanced categorization
|
|
204
|
-
const identifier = buildSchemaIdentifier(fhirSchema, packageInfo);
|
|
196
|
+
const identifier = buildSchemaIdentifier(fhirSchema);
|
|
205
197
|
// Handle profiles with specialized processor
|
|
206
198
|
if (identifier.kind === "profile") {
|
|
207
|
-
const profileSchema = await transformProfile(fhirSchema, manager,
|
|
199
|
+
const profileSchema = await transformProfile(fhirSchema, manager, fhirSchema.package_meta);
|
|
208
200
|
results.push(profileSchema);
|
|
209
201
|
// Collect binding schemas for profiles too
|
|
210
|
-
const bindingSchemas = await collectBindingSchemas(fhirSchema, manager,
|
|
202
|
+
const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, fhirSchema.package_meta);
|
|
211
203
|
results.push(...bindingSchemas);
|
|
212
204
|
return results;
|
|
213
205
|
}
|
|
214
206
|
// Handle value sets specially
|
|
215
207
|
if (identifier.kind === "value-set" || fhirSchema.kind === "value-set") {
|
|
216
|
-
const valueSetSchema = await transformValueSet(fhirSchema, manager,
|
|
208
|
+
const valueSetSchema = await transformValueSet(fhirSchema, manager, fhirSchema.package_meta);
|
|
217
209
|
if (valueSetSchema) {
|
|
218
210
|
results.push(valueSetSchema);
|
|
219
211
|
}
|
|
@@ -221,7 +213,7 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
|
|
|
221
213
|
}
|
|
222
214
|
// Handle extensions specially
|
|
223
215
|
if (isExtensionSchema(fhirSchema, identifier)) {
|
|
224
|
-
const extensionSchema = await transformExtension(fhirSchema, manager,
|
|
216
|
+
const extensionSchema = await transformExtension(fhirSchema, manager, fhirSchema.package_meta);
|
|
225
217
|
if (extensionSchema) {
|
|
226
218
|
results.push(extensionSchema);
|
|
227
219
|
}
|
|
@@ -279,10 +271,10 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
|
|
|
279
271
|
kind: kind,
|
|
280
272
|
package: isStandardFhir
|
|
281
273
|
? "hl7.fhir.r4.core"
|
|
282
|
-
:
|
|
274
|
+
: fhirSchema.package_meta.name || "undefined",
|
|
283
275
|
version: isStandardFhir
|
|
284
276
|
? "4.0.1"
|
|
285
|
-
:
|
|
277
|
+
: fhirSchema.package_meta.version || "undefined",
|
|
286
278
|
name: baseName,
|
|
287
279
|
url: baseUrl,
|
|
288
280
|
};
|
|
@@ -305,14 +297,14 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
|
|
|
305
297
|
}
|
|
306
298
|
// Transform elements into fields (for non-primitive types)
|
|
307
299
|
if (fhirSchema.kind !== "primitive-type" && fhirSchema.elements) {
|
|
308
|
-
const fields = await transformElements(fhirSchema, [], fhirSchema.elements, manager,
|
|
300
|
+
const fields = await transformElements(fhirSchema, [], fhirSchema.elements, manager, fhirSchema.package_meta);
|
|
309
301
|
if (Object.keys(fields).length > 0) {
|
|
310
302
|
mainSchema.fields = fields;
|
|
311
303
|
}
|
|
312
304
|
// Extract field dependencies (types and bindings)
|
|
313
305
|
allDependencies.push(...extractFieldDependencies(fields));
|
|
314
306
|
// Build nested types
|
|
315
|
-
const nestedTypes = await buildNestedTypes(fhirSchema, manager,
|
|
307
|
+
const nestedTypes = await buildNestedTypes(fhirSchema, manager, fhirSchema.package_meta);
|
|
316
308
|
if (nestedTypes.length > 0) {
|
|
317
309
|
mainSchema.nested = nestedTypes;
|
|
318
310
|
// Add nested type dependencies
|
|
@@ -328,7 +320,7 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
|
|
|
328
320
|
// Add main schema to results
|
|
329
321
|
results.push(mainSchema);
|
|
330
322
|
// Collect and add binding schemas
|
|
331
|
-
const bindingSchemas = await collectBindingSchemas(fhirSchema, manager,
|
|
323
|
+
const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, fhirSchema.package_meta);
|
|
332
324
|
results.push(...bindingSchemas);
|
|
333
325
|
return results;
|
|
334
326
|
}
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* Provides high-level API for converting FHIR Structure Definitions to TypeSchema format.
|
|
6
6
|
*/
|
|
7
7
|
import { type FHIRSchema, type StructureDefinition } from "@atomic-ehr/fhirschema";
|
|
8
|
-
import type { TypeSchemaConfig } from "
|
|
9
|
-
import type { TypeSchema } from "./
|
|
10
|
-
import type { PackageInfo, TypeschemaGeneratorOptions } from "./types.js";
|
|
8
|
+
import type { TypeSchemaConfig } from "@root/config";
|
|
9
|
+
import type { PackageInfo, RichFHIRSchema, TypeSchema, TypeschemaGeneratorOptions } from "./types";
|
|
11
10
|
/**
|
|
12
11
|
* TypeSchema Generator class
|
|
13
12
|
*
|
|
@@ -29,7 +28,7 @@ export declare class TypeSchemaGenerator {
|
|
|
29
28
|
generateFhirSchemas(structureDefinitions: StructureDefinition[]): FHIRSchema[];
|
|
30
29
|
generateValueSetSchemas(valueSets: any[], packageInfo: PackageInfo): Promise<TypeSchema[]>;
|
|
31
30
|
generateFromPackage(packageName: string, packageVersion?: string): Promise<TypeSchema[]>;
|
|
32
|
-
generateResourceTypeSchemas(fhirSchemas:
|
|
31
|
+
generateResourceTypeSchemas(fhirSchemas: RichFHIRSchema[]): Promise<TypeSchema[]>;
|
|
33
32
|
/**
|
|
34
33
|
* Apply treeshaking to StructureDefinitions before FHIR schema transformation
|
|
35
34
|
* This is more efficient and includes smart reference handling
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
8
8
|
import * as fhirschema from "@atomic-ehr/fhirschema";
|
|
9
|
-
import { createLogger } from "
|
|
10
|
-
import { TypeSchemaCache } from "./cache
|
|
11
|
-
import { transformFHIRSchema } from "./core/transformer
|
|
12
|
-
import {
|
|
9
|
+
import { createLogger } from "@root/utils/codegen-logger";
|
|
10
|
+
import { TypeSchemaCache } from "./cache";
|
|
11
|
+
import { transformFHIRSchema } from "./core/transformer";
|
|
12
|
+
import { enrichFHIRSchema } from "./types";
|
|
13
|
+
import { transformValueSet } from "./value-set/processor";
|
|
13
14
|
/**
|
|
14
15
|
* TypeSchema Generator class
|
|
15
16
|
*
|
|
@@ -24,7 +25,8 @@ export class TypeSchemaGenerator {
|
|
|
24
25
|
logger;
|
|
25
26
|
constructor(options = {}, cacheConfig) {
|
|
26
27
|
this.options = { verbose: false, ...options };
|
|
27
|
-
this.manager =
|
|
28
|
+
this.manager = options.manager ||
|
|
29
|
+
CanonicalManager({ packages: [], workingDir: "tmp/fhir" });
|
|
28
30
|
this.cacheConfig = cacheConfig;
|
|
29
31
|
this.logger =
|
|
30
32
|
options.logger ||
|
|
@@ -41,11 +43,7 @@ export class TypeSchemaGenerator {
|
|
|
41
43
|
}
|
|
42
44
|
async fetchPackage(packageName, packageVersion) {
|
|
43
45
|
this.logger.step(`Loading FHIR package: ${packageName}${packageVersion ? `@${packageVersion}` : ""}`);
|
|
44
|
-
this.manager
|
|
45
|
-
packages: [`${packageName}${packageVersion ? `@${packageVersion}` : ""}`],
|
|
46
|
-
workingDir: "tmp/fhir",
|
|
47
|
-
});
|
|
48
|
-
await this.manager.init();
|
|
46
|
+
await this.manager.addPackages(`${packageName}${packageVersion ? `@${packageVersion}` : ""}`);
|
|
49
47
|
const allResources = await this.manager.search({});
|
|
50
48
|
const structureDefinitions = allResources.filter((resource) => resource.resourceType === "StructureDefinition");
|
|
51
49
|
const valueSets = allResources.filter((resource) => resource.resourceType === "ValueSet");
|
|
@@ -116,9 +114,9 @@ export class TypeSchemaGenerator {
|
|
|
116
114
|
version: packageVersion || "latest",
|
|
117
115
|
};
|
|
118
116
|
const { valueSets, structureDefinitions } = await this.fetchPackage(packageName, packageVersion);
|
|
119
|
-
const fhirSchemas = this.generateFhirSchemas(structureDefinitions);
|
|
117
|
+
const fhirSchemas = this.generateFhirSchemas(structureDefinitions).map(enrichFHIRSchema);
|
|
120
118
|
const valueSetSchemas = await this.generateValueSetSchemas(valueSets, packageInfo);
|
|
121
|
-
const schemas = await this.generateResourceTypeSchemas(fhirSchemas
|
|
119
|
+
const schemas = await this.generateResourceTypeSchemas(fhirSchemas);
|
|
122
120
|
const allSchemas = [...schemas, ...valueSetSchemas];
|
|
123
121
|
if (this.cache) {
|
|
124
122
|
for (const schema of allSchemas) {
|
|
@@ -127,11 +125,11 @@ export class TypeSchemaGenerator {
|
|
|
127
125
|
}
|
|
128
126
|
return allSchemas;
|
|
129
127
|
}
|
|
130
|
-
async generateResourceTypeSchemas(fhirSchemas
|
|
128
|
+
async generateResourceTypeSchemas(fhirSchemas) {
|
|
131
129
|
this.logger.info(`Transforming ${fhirSchemas.length} FHIR schemas to Type Schema`);
|
|
132
130
|
const typeSchemas = [];
|
|
133
131
|
for (const fhirSchema of fhirSchemas) {
|
|
134
|
-
typeSchemas.push(...(await transformFHIRSchema(this.manager, fhirSchema
|
|
132
|
+
typeSchemas.push(...(await transformFHIRSchema(this.manager, fhirSchema)));
|
|
135
133
|
}
|
|
136
134
|
return typeSchemas;
|
|
137
135
|
}
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* - Reading TypeSchema documents
|
|
10
10
|
* - Validating TypeSchema documents
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export * from "./type-schema.types.js";
|
|
12
|
+
export { TypeSchemaCache } from "./cache";
|
|
13
|
+
export { TypeSchemaGenerator } from "./generator";
|
|
14
|
+
export { TypeSchemaParser } from "./parser";
|
|
15
|
+
export type { Identifier, TypeSchema } from "./types";
|
package/dist/typeschema/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - Reading TypeSchema documents
|
|
10
10
|
* - Validating TypeSchema documents
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export
|
|
12
|
+
// Re-export core dependencies
|
|
13
|
+
export { TypeSchemaCache } from "./cache";
|
|
14
|
+
export { TypeSchemaGenerator } from "./generator";
|
|
15
|
+
export { TypeSchemaParser } from "./parser";
|