@atomic-ehr/codegen 0.0.14 → 0.0.15-canary.20260604110458.894c975
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/assets/api/writer-generator/python/resource_preprocessor.py +41 -0
- package/assets/api/writer-generator/typescript/profile-helpers.ts +36 -0
- package/dist/cli/index.js +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +361 -278
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/assets/api/writer-generator/python/resource_family_validator.py +0 -92
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomic-ehr/codegen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15-canary.20260604110458.894c975",
|
|
4
4
|
"description": "Code generation tools for FHIR resources and TypeSchema definitions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fhir",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"minimatch": ">=10.2.3",
|
|
69
69
|
"rollup": ">=4.59.0",
|
|
70
70
|
"smol-toml": ">=1.6.1",
|
|
71
|
-
"brace-expansion": ">=5.0.
|
|
71
|
+
"brace-expansion": ">=5.0.6",
|
|
72
72
|
"picomatch": ">=4.0.4"
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import importlib
|
|
3
|
-
import importlib.util
|
|
4
|
-
from typing import Any, Annotated, List
|
|
5
|
-
|
|
6
|
-
from pydantic import BeforeValidator, BaseModel, ValidationError
|
|
7
|
-
from pydantic_core import ValidationError as PydanticCoreValidationError
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def to_snake_case(name: str) -> str:
|
|
11
|
-
s = re.sub(r"(?<!^)(?=[A-Z])", "_", name)
|
|
12
|
-
return s.lower()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def module_exists(name: str) -> bool:
|
|
16
|
-
"""Checks if a module exists without importing it"""
|
|
17
|
-
return importlib.util.find_spec(name) is not None
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def import_and_create_module(module_name: str, class_name: str) -> Any:
|
|
21
|
-
"""
|
|
22
|
-
Dynamically import a module and create an instance of a specified class.
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
module_name: String name of the module (e.g., 'aidbox.hl7_fhir_r4_core.patient')
|
|
26
|
-
class_name: String name of the class (e.g., 'Patient')
|
|
27
|
-
|
|
28
|
-
Returns:
|
|
29
|
-
Instance of the specified class
|
|
30
|
-
"""
|
|
31
|
-
try:
|
|
32
|
-
module = importlib.import_module(module_name)
|
|
33
|
-
class_obj = getattr(module, class_name)
|
|
34
|
-
return class_obj
|
|
35
|
-
|
|
36
|
-
except (ImportError, AttributeError) as e:
|
|
37
|
-
raise ImportError(f"Could not import {class_name} from {module_name}: {e}")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def import_and_create_module_if_exists(package: str, class_name: str) -> Any:
|
|
41
|
-
"""
|
|
42
|
-
Dynamically import a module and create an instance of a specified class if the module exists.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
package: String name of the package (e.g., 'aidbox.hl7_fhir_r4_core')
|
|
46
|
-
class_name: String name of the class (e.g., 'Patient')
|
|
47
|
-
|
|
48
|
-
Returns:
|
|
49
|
-
Instance of the specified class or None if the module does not exist
|
|
50
|
-
"""
|
|
51
|
-
module_name = package + "." + to_snake_case(class_name)
|
|
52
|
-
if module_exists(module_name):
|
|
53
|
-
return import_and_create_module(module_name, class_name)
|
|
54
|
-
else:
|
|
55
|
-
return None
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def validate_and_downcast(
|
|
59
|
-
resource_data: dict[str, Any], package_list: List[str], family: List[str]
|
|
60
|
-
) -> Any:
|
|
61
|
-
"""
|
|
62
|
-
Validates and downcasts ResourceFamily to the appropriate FHIR resource class
|
|
63
|
-
|
|
64
|
-
Args:
|
|
65
|
-
resource_data: Input value (dict)
|
|
66
|
-
package_list: List of package names to search for resource classes (e.g., ['aidbox.hl7_fhir_r4_core', 'aidbox.hl7_fhir_r4_extras'])
|
|
67
|
-
family: List of valid resource types (e.g., 'Group' or 'Patient')
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
Instance of the appropriate FHIR resource class
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
# Extract and validate resource type
|
|
74
|
-
resource_type = resource_data.get("resourceType")
|
|
75
|
-
if not resource_type:
|
|
76
|
-
raise ValueError("Missing 'resourceType' field in resource")
|
|
77
|
-
|
|
78
|
-
if resource_type not in family:
|
|
79
|
-
raise ValueError(f"Invalid resourceType '{resource_type}'. ")
|
|
80
|
-
|
|
81
|
-
# Dynamically import and instantiate the appropriate class
|
|
82
|
-
target_class = None
|
|
83
|
-
for package in package_list:
|
|
84
|
-
target_class = import_and_create_module_if_exists(package, resource_type)
|
|
85
|
-
if target_class is not None:
|
|
86
|
-
break
|
|
87
|
-
if target_class is None:
|
|
88
|
-
raise ImportError(
|
|
89
|
-
f"Could not find class for resourceType '{resource_type}' in packages {package_list}"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
return target_class.model_validate(resource_data)
|