@atomic-ehr/codegen 0.0.1-canary.20250930151649.b68ce8a → 0.0.1-canary.20251001075906.44a8bb9
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 +16 -16
- package/dist/typeschema/core/field-builder.d.ts +0 -11
- package/dist/typeschema/core/field-builder.js +0 -69
- package/dist/typeschema/core/identifier.d.ts +1 -1
- package/dist/typeschema/core/identifier.js +1 -1
- package/dist/typeschema/core/transformer.d.ts +1 -1
- package/dist/typeschema/core/transformer.js +6 -4
- package/dist/typeschema/profile/processor.js +1 -1
- package/dist/typeschema/register.d.ts +1 -1
- package/dist/typeschema/register.js +7 -4
- package/package.json +1 -1
|
@@ -7,17 +7,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
9
|
import type { Identifier, PackageMeta, RichFHIRSchema, TypeSchemaField } from "../types";
|
|
10
|
-
/**
|
|
11
|
-
* Get the full element hierarchy for a given path
|
|
12
|
-
*/
|
|
13
|
-
export declare function getElementHierarchy(fhirSchema: FHIRSchema, path: string[], _manager: ReturnType<typeof CanonicalManager>): FHIRSchemaElement[];
|
|
14
|
-
/**
|
|
15
|
-
* Merge element hierarchy into a snapshot
|
|
16
|
-
*/
|
|
17
|
-
export declare function mergeElementHierarchy(hierarchy: FHIRSchemaElement[]): FHIRSchemaElement;
|
|
18
|
-
/**
|
|
19
|
-
* Check if a field is required based on parent required arrays
|
|
20
|
-
*/
|
|
21
10
|
export declare function isRequired(fhirSchema: FHIRSchema, path: string[], _manager: ReturnType<typeof CanonicalManager>): boolean;
|
|
22
11
|
/**
|
|
23
12
|
* Check if a field is excluded
|
|
@@ -5,75 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { buildEnum } from "./binding";
|
|
7
7
|
import { mkBindingIdentifier, mkIdentifier, mkNestedIdentifier } from "./identifier";
|
|
8
|
-
/**
|
|
9
|
-
* Get the full element hierarchy for a given path
|
|
10
|
-
*/
|
|
11
|
-
export function getElementHierarchy(fhirSchema, path, _manager) {
|
|
12
|
-
const hierarchy = [];
|
|
13
|
-
// Get element at path from current schema
|
|
14
|
-
let element = fhirSchema.elements;
|
|
15
|
-
for (const key of path) {
|
|
16
|
-
element = element?.[key];
|
|
17
|
-
if (!element)
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (element) {
|
|
21
|
-
hierarchy.push(element);
|
|
22
|
-
}
|
|
23
|
-
// For now, we only use the current schema's element
|
|
24
|
-
// TODO: Implement base schema traversal when we have proper schema loading
|
|
25
|
-
return hierarchy;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Merge element hierarchy into a snapshot
|
|
29
|
-
*/
|
|
30
|
-
export function mergeElementHierarchy(hierarchy) {
|
|
31
|
-
// Handle empty hierarchy
|
|
32
|
-
if (hierarchy.length === 0) {
|
|
33
|
-
return {};
|
|
34
|
-
}
|
|
35
|
-
// Start with the most specific (first) element
|
|
36
|
-
const snapshot = { ...hierarchy[0] };
|
|
37
|
-
// Merge properties from base elements (reverse order to apply from base to specific)
|
|
38
|
-
for (let i = hierarchy.length - 1; i >= 0; i--) {
|
|
39
|
-
const element = hierarchy[i];
|
|
40
|
-
// Properties that should be taken from the most specific element
|
|
41
|
-
const specificProps = [
|
|
42
|
-
"choices",
|
|
43
|
-
"short",
|
|
44
|
-
"index",
|
|
45
|
-
"elements",
|
|
46
|
-
"required",
|
|
47
|
-
"excluded",
|
|
48
|
-
"binding",
|
|
49
|
-
"refers",
|
|
50
|
-
"elementReference",
|
|
51
|
-
"mustSupport",
|
|
52
|
-
"slices",
|
|
53
|
-
"slicing",
|
|
54
|
-
"url",
|
|
55
|
-
"extensions",
|
|
56
|
-
];
|
|
57
|
-
// Merge non-specific properties
|
|
58
|
-
for (const [key, value] of Object.entries(element)) {
|
|
59
|
-
if (!specificProps.includes(key) && value !== undefined) {
|
|
60
|
-
snapshot[key] = value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Override with specific properties from the first element
|
|
65
|
-
for (const prop of ["choices", "binding", "refers", "elementReference"]) {
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
if (hierarchy[0] && hierarchy[0][prop] !== undefined) {
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
snapshot[prop] = hierarchy[0][prop];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return snapshot;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if a field is required based on parent required arrays
|
|
76
|
-
*/
|
|
77
8
|
export function isRequired(fhirSchema, path, _manager) {
|
|
78
9
|
if (path.length === 0)
|
|
79
10
|
return false;
|
|
@@ -9,4 +9,4 @@ export declare function dropVersionFromUrl(url: string | undefined): string | un
|
|
|
9
9
|
export declare function mkIdentifier(fhirSchema: RichFHIRSchema): Identifier;
|
|
10
10
|
export declare function mkNestedIdentifier(fhirSchema: RichFHIRSchema, path: string[]): NestedIdentifier;
|
|
11
11
|
export declare function mkValueSetIdentifier(valueSetUrl: string, valueSet: any, packageInfo?: PackageMeta): TypeSchemaForValueSet["identifier"];
|
|
12
|
-
export declare function mkBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string,
|
|
12
|
+
export declare function mkBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, _packageInfo?: PackageMeta): BindingIdentifier;
|
|
@@ -65,7 +65,7 @@ export function mkValueSetIdentifier(valueSetUrl, valueSet, packageInfo) {
|
|
|
65
65
|
url: cleanUrl,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
export function mkBindingIdentifier(fhirSchema, path, bindingName,
|
|
68
|
+
export function mkBindingIdentifier(fhirSchema, path, bindingName, _packageInfo) {
|
|
69
69
|
const pathStr = path.join(".");
|
|
70
70
|
const [name, url] = bindingName
|
|
71
71
|
? [bindingName, `urn:fhir:binding:${bindingName}`]
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Core transformation logic for converting FHIRSchema to TypeSchema format
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
7
|
-
import type
|
|
7
|
+
import { type Register } from "@typeschema/register";
|
|
8
8
|
import type { RichFHIRSchema, TypeSchema, TypeSchemaField } from "@typeschema/types";
|
|
9
9
|
export declare function transformElements(register: Register, fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement> | undefined): Promise<Record<string, TypeSchemaField> | undefined>;
|
|
10
10
|
export declare function transformFHIRSchema(register: Register, fhirSchema: RichFHIRSchema): Promise<TypeSchema[]>;
|
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core transformation logic for converting FHIRSchema to TypeSchema format
|
|
5
5
|
*/
|
|
6
|
+
import { fsElementSnapshot, resolveFsElementGenealogy } from "@typeschema/register";
|
|
6
7
|
import { transformProfile } from "../profile/processor";
|
|
7
8
|
import { collectBindingSchemas } from "./binding";
|
|
8
|
-
import { buildField,
|
|
9
|
+
import { buildField, isNestedElement, mkNestedField } from "./field-builder";
|
|
9
10
|
import { mkIdentifier } from "./identifier";
|
|
10
11
|
import { buildNestedTypes, extractNestedDependencies } from "./nested-types";
|
|
11
12
|
export async function transformElements(register, fhirSchema, parentPath, elements) {
|
|
12
13
|
if (!elements)
|
|
13
14
|
return undefined;
|
|
15
|
+
const geneology = register.resolveFsGenealogy(fhirSchema.url);
|
|
14
16
|
const fields = {};
|
|
15
|
-
for (const [key,
|
|
17
|
+
for (const [key, _element] of Object.entries(elements)) {
|
|
16
18
|
const path = [...parentPath, key];
|
|
17
|
-
const
|
|
18
|
-
const snapshot =
|
|
19
|
+
const elemGeneology = resolveFsElementGenealogy(geneology, path);
|
|
20
|
+
const snapshot = fsElementSnapshot(elemGeneology);
|
|
19
21
|
if (isNestedElement(snapshot)) {
|
|
20
22
|
fields[key] = mkNestedField(fhirSchema, path, snapshot, register, fhirSchema.package_meta);
|
|
21
23
|
}
|
|
@@ -13,7 +13,7 @@ import { transformElements } from "../core/transformer";
|
|
|
13
13
|
export async function transformProfile(register, fhirSchema) {
|
|
14
14
|
// Build profile identifier
|
|
15
15
|
const identifier = mkIdentifier(fhirSchema);
|
|
16
|
-
const
|
|
16
|
+
const _packageInfo = fhirSchema.package_meta;
|
|
17
17
|
// Ensure this is recognized as a profile
|
|
18
18
|
if (identifier.kind !== "profile") {
|
|
19
19
|
throw new Error(`Expected profile, got ${identifier.kind} for ${fhirSchema.name}`);
|
|
@@ -7,7 +7,7 @@ export type Register = {
|
|
|
7
7
|
ensureCanonicalUrl(name: Name | CanonicalUrl): CanonicalUrl;
|
|
8
8
|
resolveSd(canonicalUrl: CanonicalUrl): StructureDefinition | undefined;
|
|
9
9
|
resolveFs(canonicalUrl: CanonicalUrl): RichFHIRSchema | undefined;
|
|
10
|
-
resolveFsGenealogy(canonicalUrl: CanonicalUrl): RichFHIRSchema[]
|
|
10
|
+
resolveFsGenealogy(canonicalUrl: CanonicalUrl): RichFHIRSchema[];
|
|
11
11
|
allSd(): StructureDefinition[];
|
|
12
12
|
allFs(): RichFHIRSchema[];
|
|
13
13
|
allVs(): any[];
|
|
@@ -40,12 +40,15 @@ export const registerFromManager = async (manager, logger, packageInfo) => {
|
|
|
40
40
|
}
|
|
41
41
|
const resolveFsGenealogy = (canonicalUrl) => {
|
|
42
42
|
let fs = fhirSchemas[canonicalUrl];
|
|
43
|
-
if (
|
|
44
|
-
|
|
43
|
+
if (fs === undefined)
|
|
44
|
+
throw new Error(`Failed to resolve FHIR Schema genealogy for ${canonicalUrl}`);
|
|
45
45
|
const genealogy = [fs];
|
|
46
|
-
while (fs
|
|
47
|
-
|
|
46
|
+
while (fs?.base) {
|
|
47
|
+
console.log(1, fs.base);
|
|
48
|
+
fs = fhirSchemas[fs.base] || fhirSchemas[nameDict[fs.base]];
|
|
48
49
|
genealogy.push(fs);
|
|
50
|
+
if (fs === undefined)
|
|
51
|
+
throw new Error(`Failed to resolve FHIR Schema genealogy for ${canonicalUrl}`);
|
|
49
52
|
}
|
|
50
53
|
return genealogy;
|
|
51
54
|
};
|
package/package.json
CHANGED