@atomic-ehr/codegen 0.0.1-canary.20251001154933.613f6c7 → 0.0.1-canary.20251002082521.96cb084

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.
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
7
7
  import type { Register } from "@typeschema/register";
8
- import type { CanonicalUrl, PackageMeta, RichFHIRSchema, TypeSchemaForBinding } from "@typeschema/types";
8
+ import type { BindingTypeSchema, CanonicalUrl, PackageMeta, RichFHIRSchema } from "@typeschema/types";
9
9
  /**
10
10
  * Extract concepts from a ValueSet
11
11
  */
@@ -18,8 +18,8 @@ export declare function extractValueSetConcepts(valueSetUrl: CanonicalUrl, regis
18
18
  * Build enum values from binding if applicable
19
19
  */
20
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>;
21
+ export declare function generateBindingSchema(fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement, register: Register, packageInfo?: PackageMeta): Promise<BindingTypeSchema | undefined>;
22
22
  /**
23
23
  * Collect all binding schemas from a FHIRSchema
24
24
  */
25
- export declare function collectBindingSchemas(fhirSchema: RichFHIRSchema, register: Register): Promise<TypeSchemaForBinding[]>;
25
+ export declare function collectBindingSchemas(fhirSchema: RichFHIRSchema, register: Register): Promise<BindingTypeSchema[]>;
@@ -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 { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
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: FHIRSchema, path: string[]): boolean;
11
- export declare function isExcluded(fhirSchema: FHIRSchema, path: string[]): boolean;
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(_register: Register, fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement): RegularField;
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
- // Navigate to parent element
14
- let parentElement = fhirSchema;
15
- for (const key of parentPath) {
16
- parentElement = parentElement.elements?.[key];
17
- if (!parentElement)
18
- break;
19
- }
20
- // Check if field is in required array
21
- if (parentElement?.required?.includes(fieldName)) {
22
- return true;
23
- }
24
- // Also check at root level
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
- // Navigate to parent element
36
- let parentElement = fhirSchema;
37
- for (const key of parentPath) {
38
- parentElement = parentElement.elements?.[key];
39
- if (!parentElement)
40
- break;
41
- }
42
- // Check if field is in excluded array
43
- if (parentElement?.excluded?.includes(fieldName)) {
44
- return true;
45
- }
46
- // Also check at root level
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(_register, fhirSchema, path, element) {
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
  }
@@ -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, CanonicalUrl, Identifier, NestedIdentifier, PackageMeta, RichFHIRSchema, TypeSchemaForValueSet } from "@typeschema/types";
7
+ import type { BindingIdentifier, CanonicalUrl, Identifier, NestedIdentifier, PackageMeta, RichFHIRSchema, ValueSetTypeSchema } from "@typeschema/types";
8
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: CanonicalUrl, valueSet: any, packageInfo?: PackageMeta): TypeSchemaForValueSet["identifier"];
11
+ export declare function mkValueSetIdentifier(valueSetUrl: CanonicalUrl, valueSet: any, packageInfo?: PackageMeta): ValueSetTypeSchema["identifier"];
12
12
  export declare function mkBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, _packageInfo?: PackageMeta): BindingIdentifier;
@@ -6,9 +6,9 @@
6
6
  */
7
7
  import type { Register } from "@root/typeschema/register";
8
8
  import type { RichFHIRSchema } from "@typeschema/types";
9
- import type { TypeSchemaForProfile } from "../types";
9
+ import type { ProfileTypeSchema } from "../types";
10
10
  /**
11
11
  * Transform a FHIR profile to TypeSchema format
12
12
  * Profiles are treated as specialized resources that extend base resources
13
13
  */
14
- export declare function transformProfile(register: Register, fhirSchema: RichFHIRSchema): Promise<TypeSchemaForProfile>;
14
+ export declare function transformProfile(register: Register, fhirSchema: RichFHIRSchema): Promise<ProfileTypeSchema>;
@@ -52,8 +52,8 @@ type LogicalIdentifier = {
52
52
  kind: "logical";
53
53
  } & IdentifierBase;
54
54
  export type Identifier = PrimitiveIdentifier | ComplexTypeIdentifier | ResourceIdentifier | NestedIdentifier | BindingIdentifier | ValueSetIdentifier | ProfileIdentifier | LogicalIdentifier;
55
- export type TypeSchema = TypeSchemaForPrimitiveType | TypeSchemaForResourceComplexTypeLogical | TypeSchemaForValueSet | TypeSchemaForBinding | TypeSchemaForProfile;
56
- interface TypeSchemaForPrimitiveType {
55
+ export type TypeSchema = RegularTypeSchema | PrimitiveTypeSchema | ValueSetTypeSchema | BindingTypeSchema | ProfileTypeSchema;
56
+ interface PrimitiveTypeSchema {
57
57
  identifier: PrimitiveIdentifier;
58
58
  description?: string;
59
59
  base: Identifier;
@@ -64,7 +64,7 @@ export interface NestedType {
64
64
  base: Identifier;
65
65
  fields: Record<string, Field>;
66
66
  }
67
- export interface TypeSchemaForProfile {
67
+ export interface ProfileTypeSchema {
68
68
  identifier: ProfileIdentifier;
69
69
  base: Identifier;
70
70
  description?: string;
@@ -121,7 +121,7 @@ export interface ProfileMetadata {
121
121
  jurisdiction?: any[];
122
122
  package?: string;
123
123
  }
124
- export interface TypeSchemaForResourceComplexTypeLogical {
124
+ export interface RegularTypeSchema {
125
125
  identifier: Identifier;
126
126
  base?: Identifier;
127
127
  description?: string;
@@ -142,7 +142,7 @@ export interface RegularField {
142
142
  min?: number;
143
143
  max?: number;
144
144
  }
145
- export interface PolymorphicDeclarationField {
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 PolymorphicInstanceField {
153
+ export interface ChoiceFieldInstance {
154
154
  choiceOf: string;
155
155
  type: Identifier;
156
156
  required?: boolean;
@@ -162,7 +162,7 @@ export interface PolymorphicInstanceField {
162
162
  min?: number;
163
163
  max?: number;
164
164
  }
165
- export interface TypeSchemaForValueSet {
165
+ export interface ValueSetTypeSchema {
166
166
  identifier: ValueSetIdentifier;
167
167
  description?: string;
168
168
  concept?: {
@@ -174,7 +174,7 @@ export interface TypeSchemaForValueSet {
174
174
  [k: string]: unknown;
175
175
  };
176
176
  }
177
- export interface TypeSchemaForBinding {
177
+ export interface BindingTypeSchema {
178
178
  identifier: BindingIdentifier;
179
179
  description?: string;
180
180
  type?: Identifier;
@@ -183,14 +183,14 @@ export interface TypeSchemaForBinding {
183
183
  valueset?: ValueSetIdentifier;
184
184
  dependencies?: Identifier[];
185
185
  }
186
- export type Field = RegularField | PolymorphicDeclarationField | PolymorphicInstanceField;
186
+ export type Field = RegularField | ChoiceFieldDeclaration | ChoiceFieldInstance;
187
187
  export interface TypeschemaGeneratorOptions {
188
188
  verbose?: boolean;
189
189
  logger?: import("../utils/codegen-logger").CodegenLogger;
190
190
  treeshake?: string[];
191
191
  manager?: ReturnType<typeof CanonicalManager> | null;
192
192
  }
193
- export declare function isBindingSchema(schema: TypeSchema): schema is TypeSchemaForBinding;
193
+ export declare function isBindingSchema(schema: TypeSchema): schema is BindingTypeSchema;
194
194
  export type TypeschemaParserOptions = {
195
195
  format?: "auto" | "ndjson" | "json";
196
196
  validate?: boolean;
@@ -4,7 +4,7 @@
4
4
  * Functions for transforming FHIR ValueSets into TypeSchema format
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
- import type { PackageMeta, TypeSchemaForValueSet } from "../types";
7
+ import type { PackageMeta, ValueSetTypeSchema } from "../types";
8
8
  /**
9
9
  * Extract all concepts from a ValueSet
10
10
  */
@@ -16,4 +16,4 @@ export declare function extractValueSetConcepts(valueSet: any, manager: ReturnTy
16
16
  /**
17
17
  * Transform a FHIR ValueSet to TypeSchema format
18
18
  */
19
- export declare function transformValueSet(valueSet: any, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageMeta): Promise<TypeSchemaForValueSet>;
19
+ export declare function transformValueSet(valueSet: any, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageMeta): Promise<ValueSetTypeSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomic-ehr/codegen",
3
- "version": "0.0.1-canary.20251001154933.613f6c7",
3
+ "version": "0.0.1-canary.20251002082521.96cb084",
4
4
  "description": "Code generation tools for FHIR resources and TypeSchema definitions",
5
5
  "keywords": [
6
6
  "fhir",