@atomic-ehr/codegen 0.0.1-canary.20251003085147.a5c0084 → 0.0.1-canary.20251003142740.59082f8
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 +45 -45
- package/dist/typeschema/core/binding.d.ts +4 -7
- package/dist/typeschema/core/binding.js +51 -59
- package/dist/typeschema/core/field-builder.js +1 -1
- package/dist/typeschema/core/identifier.d.ts +3 -2
- package/dist/typeschema/core/identifier.js +26 -15
- package/dist/typeschema/core/transformer.d.ts +2 -1
- package/dist/typeschema/core/transformer.js +13 -49
- package/dist/typeschema/generator.d.ts +1 -1
- package/dist/typeschema/generator.js +4 -5
- package/dist/typeschema/register.d.ts +3 -3
- package/dist/typeschema/types.d.ts +49 -8
- package/package.json +1 -1
- package/dist/typeschema/value-set/processor.d.ts +0 -20
- package/dist/typeschema/value-set/processor.js +0 -168
|
@@ -5,12 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
7
7
|
import type { Register } from "@typeschema/register";
|
|
8
|
-
import type { BindingTypeSchema, CanonicalUrl, RichFHIRSchema } from "@typeschema/types";
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
display?: string;
|
|
13
|
-
}[] | undefined;
|
|
14
|
-
export declare function buildEnum(element: FHIRSchemaElement, register: Register): string[] | undefined;
|
|
8
|
+
import type { BindingTypeSchema, CanonicalUrl, Concept, RichFHIRSchema, RichValueSet } from "@typeschema/types";
|
|
9
|
+
export declare function extractValueSetConceptsByUrl(register: Register, valueSetUrl: CanonicalUrl): Concept[] | undefined;
|
|
10
|
+
export declare function extractValueSetConcepts(register: Register, valueSet: RichValueSet): Concept[] | undefined;
|
|
11
|
+
export declare function buildEnum(register: Register, element: FHIRSchemaElement): string[] | undefined;
|
|
15
12
|
export declare function generateBindingSchema(register: Register, fhirSchema: RichFHIRSchema, path: string[], element: FHIRSchemaElement): Promise<BindingTypeSchema | undefined>;
|
|
16
13
|
export declare function collectBindingSchemas(register: Register, fhirSchema: RichFHIRSchema): Promise<BindingTypeSchema[]>;
|
|
@@ -4,70 +4,63 @@
|
|
|
4
4
|
* Functions for processing value set bindings and generating enums
|
|
5
5
|
*/
|
|
6
6
|
import { buildFieldType } from "./field-builder";
|
|
7
|
-
import { dropVersionFromUrl, mkBindingIdentifier,
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
code: concept.code,
|
|
29
|
-
display: concept.display,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
7
|
+
import { dropVersionFromUrl, mkBindingIdentifier, mkValueSetIdentifierByUrl } from "./identifier";
|
|
8
|
+
export function extractValueSetConceptsByUrl(register, valueSetUrl) {
|
|
9
|
+
const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
|
|
10
|
+
const valueSet = register.resolveVs(cleanUrl);
|
|
11
|
+
if (!valueSet)
|
|
12
|
+
return undefined;
|
|
13
|
+
return extractValueSetConcepts(register, valueSet);
|
|
14
|
+
}
|
|
15
|
+
export function extractValueSetConcepts(register, valueSet) {
|
|
16
|
+
if (valueSet.expansion?.contains)
|
|
17
|
+
return valueSet.expansion.contains;
|
|
18
|
+
const concepts = [];
|
|
19
|
+
if (valueSet.compose?.include) {
|
|
20
|
+
for (const include of valueSet.compose.include) {
|
|
21
|
+
if (include.concept) {
|
|
22
|
+
for (const concept of include.concept) {
|
|
23
|
+
concepts.push({
|
|
24
|
+
system: include.system,
|
|
25
|
+
code: concept.code,
|
|
26
|
+
display: concept.display,
|
|
27
|
+
});
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
29
|
+
}
|
|
30
|
+
else if (include.system && !include.filter) {
|
|
31
|
+
try {
|
|
32
|
+
const codeSystem = register.resolveAny(include.system);
|
|
33
|
+
if (codeSystem?.concept) {
|
|
34
|
+
const extractConcepts = (conceptList, system) => {
|
|
35
|
+
for (const concept of conceptList) {
|
|
36
|
+
concepts.push({
|
|
37
|
+
system,
|
|
38
|
+
code: concept.code,
|
|
39
|
+
display: concept.display,
|
|
40
|
+
});
|
|
41
|
+
if (concept.concept) {
|
|
42
|
+
extractConcepts(concept.concept, system);
|
|
48
43
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// Ignore if we can't resolve the CodeSystem
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
extractConcepts(codeSystem.concept, include.system);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
49
|
+
catch {
|
|
50
|
+
// Ignore if we can't resolve the CodeSystem
|
|
51
|
+
}
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
|
-
return concepts.length > 0 ? concepts : undefined;
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return undefined;
|
|
63
54
|
}
|
|
55
|
+
return concepts.length > 0 ? concepts : undefined;
|
|
64
56
|
}
|
|
65
57
|
const MAX_ENUM_LENGTH = 100;
|
|
66
|
-
export function buildEnum(
|
|
58
|
+
export function buildEnum(register, element) {
|
|
67
59
|
if (!element.binding)
|
|
68
60
|
return undefined;
|
|
69
|
-
const
|
|
70
|
-
|
|
61
|
+
const strength = element.binding.strength;
|
|
62
|
+
const valueSetUrl = element.binding.valueSet;
|
|
63
|
+
if (!valueSetUrl)
|
|
71
64
|
return undefined;
|
|
72
65
|
// Enhanced support for more binding strengths and types
|
|
73
66
|
// Generate enum for:
|
|
@@ -78,17 +71,16 @@ export function buildEnum(element, register) {
|
|
|
78
71
|
const shouldGenerateEnum = strength === "required" ||
|
|
79
72
|
(strength === "extensible" && (element.type === "code" || element.type === "Coding")) ||
|
|
80
73
|
(strength === "preferred" && (element.type === "code" || element.type === "Coding"));
|
|
81
|
-
if (!shouldGenerateEnum)
|
|
74
|
+
if (!shouldGenerateEnum)
|
|
82
75
|
return undefined;
|
|
83
|
-
|
|
84
|
-
const concepts = extractValueSetConcepts(valueSet, register);
|
|
76
|
+
const concepts = extractValueSetConceptsByUrl(register, valueSetUrl);
|
|
85
77
|
if (!concepts || concepts.length === 0)
|
|
86
78
|
return undefined;
|
|
87
79
|
const codes = concepts
|
|
88
80
|
.map((c) => c.code)
|
|
89
81
|
.filter((code) => code && typeof code === "string" && code.trim().length > 0);
|
|
90
82
|
if (codes.length > MAX_ENUM_LENGTH) {
|
|
91
|
-
console.warn(`Value set ${
|
|
83
|
+
console.warn(`Value set ${valueSetUrl} has more than ${MAX_ENUM_LENGTH} codes, which may cause issues with code generation.`);
|
|
92
84
|
return undefined;
|
|
93
85
|
}
|
|
94
86
|
return codes.length > 0 ? codes : undefined;
|
|
@@ -98,13 +90,13 @@ export async function generateBindingSchema(register, fhirSchema, path, element)
|
|
|
98
90
|
return undefined;
|
|
99
91
|
const identifier = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
100
92
|
const fieldType = buildFieldType(register, fhirSchema, element);
|
|
101
|
-
const valueSetIdentifier =
|
|
93
|
+
const valueSetIdentifier = mkValueSetIdentifierByUrl(register, element.binding.valueSet);
|
|
102
94
|
const dependencies = [];
|
|
103
95
|
if (fieldType) {
|
|
104
96
|
dependencies.push(fieldType);
|
|
105
97
|
}
|
|
106
98
|
dependencies.push(valueSetIdentifier);
|
|
107
|
-
const enumValues = buildEnum(
|
|
99
|
+
const enumValues = buildEnum(register, element);
|
|
108
100
|
return {
|
|
109
101
|
identifier,
|
|
110
102
|
type: fieldType,
|
|
@@ -83,7 +83,7 @@ export const mkField = (register, fhirSchema, path, element) => {
|
|
|
83
83
|
if (element.binding) {
|
|
84
84
|
binding = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
85
85
|
if (element.binding.strength === "required" && element.type === "code") {
|
|
86
|
-
enumValues = buildEnum(
|
|
86
|
+
enumValues = buildEnum(register, element);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
return {
|
|
@@ -4,10 +4,11 @@
|
|
|
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, RichFHIRSchema,
|
|
7
|
+
import type { BindingIdentifier, CanonicalUrl, Identifier, NestedIdentifier, RichFHIRSchema, ValueSetIdentifier } from "@typeschema/types";
|
|
8
8
|
import type { Register } from "../register";
|
|
9
9
|
export declare function dropVersionFromUrl(url: CanonicalUrl): CanonicalUrl;
|
|
10
|
+
export declare function getVersionFromUrl(url: CanonicalUrl): string | undefined;
|
|
10
11
|
export declare function mkIdentifier(fhirSchema: RichFHIRSchema): Identifier;
|
|
11
12
|
export declare function mkNestedIdentifier(fhirSchema: RichFHIRSchema, path: string[]): NestedIdentifier;
|
|
12
|
-
export declare function
|
|
13
|
+
export declare function mkValueSetIdentifierByUrl(register: Register, fullValueSetUrl: CanonicalUrl): ValueSetIdentifier;
|
|
13
14
|
export declare function mkBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string): BindingIdentifier;
|
|
@@ -7,6 +7,10 @@ export function dropVersionFromUrl(url) {
|
|
|
7
7
|
const baseUrl = url.split("|")[0];
|
|
8
8
|
return baseUrl ? baseUrl : url;
|
|
9
9
|
}
|
|
10
|
+
export function getVersionFromUrl(url) {
|
|
11
|
+
const version = url.split("|")[1];
|
|
12
|
+
return version;
|
|
13
|
+
}
|
|
10
14
|
function determineKind(fhirSchema) {
|
|
11
15
|
if (fhirSchema.derivation === "constraint")
|
|
12
16
|
return "profile";
|
|
@@ -37,31 +41,38 @@ export function mkNestedIdentifier(fhirSchema, path) {
|
|
|
37
41
|
url: `${fhirSchema.url}#${nestedName}`,
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const valueSet = register.resolveVs(valueSetUrl);
|
|
43
|
-
// Generate a meaningful name from the URL instead of using potentially hash-like IDs
|
|
44
|
-
let name = "unknown";
|
|
45
|
-
// First try to get the last segment of the URL path
|
|
46
|
-
const urlParts = valueSetUrl.split("/");
|
|
44
|
+
const getValueSetName = (url) => {
|
|
45
|
+
const urlParts = url.split("/");
|
|
47
46
|
const lastSegment = urlParts[urlParts.length - 1];
|
|
48
47
|
if (lastSegment && lastSegment.length > 0) {
|
|
49
|
-
|
|
50
|
-
name = lastSegment
|
|
48
|
+
return lastSegment
|
|
51
49
|
.split(/[-_]/)
|
|
52
50
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
53
51
|
.join("");
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
return url;
|
|
54
|
+
};
|
|
55
|
+
export function mkValueSetIdentifierByUrl(register, fullValueSetUrl) {
|
|
56
|
+
const valueSetUrl = dropVersionFromUrl(fullValueSetUrl);
|
|
57
|
+
const valueSetNameFallback = getValueSetName(valueSetUrl);
|
|
58
|
+
const valuesSetFallback = {
|
|
59
|
+
resourceType: "ValueSet",
|
|
60
|
+
package_meta: {
|
|
61
|
+
name: "missing_valuesets",
|
|
62
|
+
version: getVersionFromUrl(valueSetUrl) || "0.0.0",
|
|
63
|
+
},
|
|
64
|
+
name: valueSetNameFallback,
|
|
65
|
+
id: fullValueSetUrl,
|
|
66
|
+
url: valueSetUrl,
|
|
67
|
+
};
|
|
68
|
+
const valueSet = register.resolveVs(valueSetUrl) || valuesSetFallback;
|
|
69
|
+
// NOTE: ignore valueSet.name due to human name
|
|
70
|
+
const valueSetName = valueSet?.id && !/^[a-zA-Z0-9_-]{20,}$/.test(valueSet.id) ? valueSet.id : valueSetNameFallback;
|
|
60
71
|
return {
|
|
61
72
|
kind: "value-set",
|
|
62
73
|
package: valueSet?.package_meta.name,
|
|
63
74
|
version: valueSet?.package_meta.version,
|
|
64
|
-
name:
|
|
75
|
+
name: valueSetName,
|
|
65
76
|
url: valueSetUrl,
|
|
66
77
|
};
|
|
67
78
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
|
|
7
7
|
import { type Register } from "@typeschema/register";
|
|
8
|
-
import type { Field, RichFHIRSchema, TypeSchema } from "@typeschema/types";
|
|
8
|
+
import type { Field, RichFHIRSchema, RichValueSet, TypeSchema, ValueSetTypeSchema } from "@typeschema/types";
|
|
9
9
|
export declare function mkFields(register: Register, fhirSchema: RichFHIRSchema, parentPath: string[], elements: Record<string, FHIRSchemaElement> | undefined): Promise<Record<string, Field> | undefined>;
|
|
10
|
+
export declare function transformValueSet(register: Register, valueSet: RichValueSet): Promise<ValueSetTypeSchema>;
|
|
10
11
|
export declare function transformFHIRSchema(register: Register, fhirSchema: RichFHIRSchema): Promise<TypeSchema[]>;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { fsElementSnapshot, resolveFsElementGenealogy } from "@typeschema/register";
|
|
7
7
|
import { transformProfile } from "../profile/processor";
|
|
8
|
-
import { collectBindingSchemas } from "./binding";
|
|
8
|
+
import { collectBindingSchemas, extractValueSetConceptsByUrl } from "./binding";
|
|
9
9
|
import { isNestedElement, mkField, mkNestedField } from "./field-builder";
|
|
10
|
-
import { mkIdentifier } from "./identifier";
|
|
10
|
+
import { mkIdentifier, mkValueSetIdentifierByUrl } from "./identifier";
|
|
11
11
|
import { extractNestedDependencies, mkNestedTypes } from "./nested-types";
|
|
12
12
|
export async function mkFields(register, fhirSchema, parentPath, elements) {
|
|
13
13
|
if (!elements)
|
|
@@ -89,42 +89,17 @@ function isExtensionSchema(fhirSchema, _identifier) {
|
|
|
89
89
|
}
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
identifier
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// If there are elements that represent concepts
|
|
104
|
-
if (fhirSchema.elements) {
|
|
105
|
-
const concepts = [];
|
|
106
|
-
// Extract concepts from elements (simplified approach)
|
|
107
|
-
for (const [_key, element] of Object.entries(fhirSchema.elements)) {
|
|
108
|
-
if ("code" in element && element.code) {
|
|
109
|
-
concepts.push({
|
|
110
|
-
code: element.code,
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
display: element.short || element.definition,
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
system: element.system,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (concepts.length > 0) {
|
|
119
|
-
valueSetSchema.concept = concepts;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return valueSetSchema;
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
console.warn(`Failed to transform value set ${fhirSchema.name}: ${error}`);
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
92
|
+
export async function transformValueSet(register, valueSet) {
|
|
93
|
+
if (!valueSet.url)
|
|
94
|
+
throw new Error("ValueSet URL is required");
|
|
95
|
+
const identifier = mkValueSetIdentifierByUrl(register, valueSet.url);
|
|
96
|
+
const concept = extractValueSetConceptsByUrl(register, valueSet.url);
|
|
97
|
+
return {
|
|
98
|
+
identifier: identifier,
|
|
99
|
+
description: valueSet.description,
|
|
100
|
+
concept: concept,
|
|
101
|
+
compose: !concept ? valueSet.compose : undefined,
|
|
102
|
+
};
|
|
128
103
|
}
|
|
129
104
|
/**
|
|
130
105
|
* Transform an Extension FHIRSchema to TypeSchema with extension metadata
|
|
@@ -242,24 +217,13 @@ async function transformResource(register, fhirSchema) {
|
|
|
242
217
|
export async function transformFHIRSchema(register, fhirSchema) {
|
|
243
218
|
const results = [];
|
|
244
219
|
const identifier = mkIdentifier(fhirSchema);
|
|
245
|
-
// Handle profiles with specialized processor
|
|
246
220
|
if (identifier.kind === "profile") {
|
|
247
221
|
const profileSchema = await transformProfile(register, fhirSchema);
|
|
248
222
|
results.push(profileSchema);
|
|
249
|
-
// Collect binding schemas for profiles too
|
|
250
223
|
const bindingSchemas = await collectBindingSchemas(register, fhirSchema);
|
|
251
224
|
results.push(...bindingSchemas);
|
|
252
225
|
return results;
|
|
253
226
|
}
|
|
254
|
-
// Handle value sets specially
|
|
255
|
-
if (identifier.kind === "value-set" || fhirSchema.kind === "value-set") {
|
|
256
|
-
const valueSetSchema = await transformValueSet(fhirSchema, register, fhirSchema.package_meta);
|
|
257
|
-
if (valueSetSchema) {
|
|
258
|
-
results.push(valueSetSchema);
|
|
259
|
-
}
|
|
260
|
-
return results;
|
|
261
|
-
}
|
|
262
|
-
// Handle extensions specially
|
|
263
227
|
if (isExtensionSchema(fhirSchema, identifier)) {
|
|
264
228
|
const extensionSchema = await transformExtension(fhirSchema, register, fhirSchema.package_meta);
|
|
265
229
|
if (extensionSchema) {
|
|
@@ -24,7 +24,7 @@ export declare class TypeSchemaGenerator {
|
|
|
24
24
|
private initializeCache;
|
|
25
25
|
registerFromPackageMetas(packageMetas: PackageMeta[]): Promise<Register>;
|
|
26
26
|
generateFhirSchemas(structureDefinitions: StructureDefinition[]): FHIRSchema[];
|
|
27
|
-
generateValueSetSchemas(valueSets: any[],
|
|
27
|
+
generateValueSetSchemas(valueSets: any[], _packageInfo: PackageMeta): Promise<TypeSchema[]>;
|
|
28
28
|
generateFromPackage(packageName: string, packageVersion?: string): Promise<TypeSchema[]>;
|
|
29
29
|
/**
|
|
30
30
|
* Apply treeshaking to StructureDefinitions before FHIR schema transformation
|
|
@@ -9,8 +9,7 @@ import * as fhirschema from "@atomic-ehr/fhirschema";
|
|
|
9
9
|
import { createLogger } from "@root/utils/codegen-logger";
|
|
10
10
|
import { registerFromManager } from "@typeschema/register";
|
|
11
11
|
import { TypeSchemaCache } from "./cache";
|
|
12
|
-
import { transformFHIRSchema } from "./core/transformer";
|
|
13
|
-
import { transformValueSet } from "./value-set/processor";
|
|
12
|
+
import { transformFHIRSchema, transformValueSet } from "./core/transformer";
|
|
14
13
|
/**
|
|
15
14
|
* TypeSchema Generator class
|
|
16
15
|
*
|
|
@@ -48,7 +47,7 @@ export class TypeSchemaGenerator {
|
|
|
48
47
|
}
|
|
49
48
|
generateFhirSchemas(structureDefinitions) {
|
|
50
49
|
this.logger.progress(`Converting ${structureDefinitions.length} StructureDefinitions to FHIRSchemas`);
|
|
51
|
-
// TODO: do it on the TypeSchema
|
|
50
|
+
// TODO: do it on the TypeSchema?
|
|
52
51
|
const filteredStructureDefinitions = this.applyStructureDefinitionTreeshaking(structureDefinitions);
|
|
53
52
|
const fhirSchemas = [];
|
|
54
53
|
let convertedCount = 0;
|
|
@@ -68,7 +67,7 @@ export class TypeSchemaGenerator {
|
|
|
68
67
|
this.logger.success(`FHIR Schema conversion completed: ${convertedCount}/${filteredStructureDefinitions.length} successful, ${failedCount} failed`);
|
|
69
68
|
return fhirSchemas;
|
|
70
69
|
}
|
|
71
|
-
async generateValueSetSchemas(valueSets,
|
|
70
|
+
async generateValueSetSchemas(valueSets, _packageInfo) {
|
|
72
71
|
if (valueSets.length > 0) {
|
|
73
72
|
this.logger.debug(`${valueSets.length} ValueSets available for enum extraction`);
|
|
74
73
|
}
|
|
@@ -80,7 +79,7 @@ export class TypeSchemaGenerator {
|
|
|
80
79
|
let valueSetFailedCount = 0;
|
|
81
80
|
for (const vs of valueSets) {
|
|
82
81
|
try {
|
|
83
|
-
const valueSetSchema = await transformValueSet(
|
|
82
|
+
const valueSetSchema = await transformValueSet(await registerFromManager(this.manager), vs);
|
|
84
83
|
if (valueSetSchema) {
|
|
85
84
|
valueSetSchemas.push(valueSetSchema);
|
|
86
85
|
valueSetConvertedCount++;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
2
2
|
import type { FHIRSchema, FHIRSchemaElement, StructureDefinition } from "@atomic-ehr/fhirschema";
|
|
3
3
|
import type { CodegenLogger } from "@root/utils/codegen-logger";
|
|
4
|
-
import type { CanonicalUrl, Name, PackageMeta, RichFHIRSchema } from "@typeschema/types";
|
|
4
|
+
import type { CanonicalUrl, Name, PackageMeta, RichFHIRSchema, RichValueSet } from "@typeschema/types";
|
|
5
5
|
export type Register = {
|
|
6
6
|
appendFs(fs: FHIRSchema): void;
|
|
7
7
|
ensureCanonicalUrl(name: string | Name | CanonicalUrl): CanonicalUrl;
|
|
@@ -10,8 +10,8 @@ export type Register = {
|
|
|
10
10
|
resolveFsGenealogy(canonicalUrl: CanonicalUrl): RichFHIRSchema[];
|
|
11
11
|
allSd(): StructureDefinition[];
|
|
12
12
|
allFs(): RichFHIRSchema[];
|
|
13
|
-
allVs():
|
|
14
|
-
resolveVs(canonicalUrl: CanonicalUrl):
|
|
13
|
+
allVs(): RichValueSet[];
|
|
14
|
+
resolveVs(canonicalUrl: CanonicalUrl): RichValueSet | undefined;
|
|
15
15
|
complexTypeDict(): Record<string, RichFHIRSchema>;
|
|
16
16
|
resolveAny(canonicalUrl: CanonicalUrl): any | undefined;
|
|
17
17
|
} & ReturnType<typeof CanonicalManager>;
|
|
@@ -162,17 +162,16 @@ export interface ChoiceFieldInstance {
|
|
|
162
162
|
min?: number;
|
|
163
163
|
max?: number;
|
|
164
164
|
}
|
|
165
|
+
export type Concept = {
|
|
166
|
+
code: string;
|
|
167
|
+
display?: string;
|
|
168
|
+
system?: string;
|
|
169
|
+
};
|
|
165
170
|
export interface ValueSetTypeSchema {
|
|
166
171
|
identifier: ValueSetIdentifier;
|
|
167
172
|
description?: string;
|
|
168
|
-
concept?:
|
|
169
|
-
|
|
170
|
-
display?: string;
|
|
171
|
-
system?: string;
|
|
172
|
-
}[];
|
|
173
|
-
compose?: {
|
|
174
|
-
[k: string]: unknown;
|
|
175
|
-
};
|
|
173
|
+
concept?: Concept[];
|
|
174
|
+
compose?: ValueSetCompose;
|
|
176
175
|
}
|
|
177
176
|
export interface BindingTypeSchema {
|
|
178
177
|
identifier: BindingIdentifier;
|
|
@@ -196,4 +195,46 @@ export type TypeschemaParserOptions = {
|
|
|
196
195
|
validate?: boolean;
|
|
197
196
|
strict?: boolean;
|
|
198
197
|
};
|
|
198
|
+
export type ValueSet = {
|
|
199
|
+
resourceType: "ValueSet";
|
|
200
|
+
id: string;
|
|
201
|
+
name?: string;
|
|
202
|
+
url?: string;
|
|
203
|
+
description?: string;
|
|
204
|
+
compose?: ValueSetCompose;
|
|
205
|
+
expansion?: {
|
|
206
|
+
contains: Concept[];
|
|
207
|
+
};
|
|
208
|
+
experimental?: boolean;
|
|
209
|
+
immutable?: boolean;
|
|
210
|
+
extension?: any[];
|
|
211
|
+
status?: string;
|
|
212
|
+
identifier?: any[];
|
|
213
|
+
title?: string;
|
|
214
|
+
publisher?: string;
|
|
215
|
+
version?: string;
|
|
216
|
+
meta?: any;
|
|
217
|
+
date?: string;
|
|
218
|
+
contact?: any;
|
|
219
|
+
};
|
|
220
|
+
export type ValueSetCompose = {
|
|
221
|
+
include: {
|
|
222
|
+
concept?: Concept[];
|
|
223
|
+
system?: string;
|
|
224
|
+
filter?: {}[];
|
|
225
|
+
}[];
|
|
226
|
+
};
|
|
227
|
+
export type CodeSystem = {
|
|
228
|
+
concept: CodeSystemConcept[];
|
|
229
|
+
};
|
|
230
|
+
export type CodeSystemConcept = {
|
|
231
|
+
concept: CodeSystemConcept[];
|
|
232
|
+
code: string;
|
|
233
|
+
display: string;
|
|
234
|
+
};
|
|
235
|
+
export type RichValueSet = Omit<ValueSet, "name" | "url"> & {
|
|
236
|
+
package_meta: PackageMeta;
|
|
237
|
+
name?: Name;
|
|
238
|
+
url?: CanonicalUrl;
|
|
239
|
+
};
|
|
199
240
|
export {};
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Value Set Processing
|
|
3
|
-
*
|
|
4
|
-
* Functions for transforming FHIR ValueSets into TypeSchema format
|
|
5
|
-
*/
|
|
6
|
-
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
7
|
-
import type { Register } from "../register";
|
|
8
|
-
import type { PackageMeta, ValueSetTypeSchema } from "../types";
|
|
9
|
-
/**
|
|
10
|
-
* Extract all concepts from a ValueSet
|
|
11
|
-
*/
|
|
12
|
-
export declare function extractValueSetConcepts(valueSet: any, manager: ReturnType<typeof CanonicalManager>): Promise<Array<{
|
|
13
|
-
system: string;
|
|
14
|
-
code: string;
|
|
15
|
-
display?: string;
|
|
16
|
-
}> | undefined>;
|
|
17
|
-
/**
|
|
18
|
-
* Transform a FHIR ValueSet to TypeSchema format
|
|
19
|
-
*/
|
|
20
|
-
export declare function transformValueSet(valueSet: any, register: Register, packageInfo?: PackageMeta): Promise<ValueSetTypeSchema>;
|