babelfhir-ts 1.0.28 → 1.0.30

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.
Files changed (140) hide show
  1. package/LICENSE +15 -15
  2. package/README.md +226 -210
  3. package/bin/babelfhir-ts.js +28 -28
  4. package/out/generator/classGenerator.js +132 -216
  5. package/out/generator/fhirR4Rules.js +174 -0
  6. package/out/generator/importManager.js +64 -12
  7. package/out/generator/index.js +257 -70
  8. package/out/generator/interfaceGenerator.js +266 -540
  9. package/out/generator/packageManager.js +257 -0
  10. package/out/generator/packageParser.js +4 -3
  11. package/out/generator/postProcessExtensions.js +338 -0
  12. package/out/generator/randomSupportGenerator.js +279 -0
  13. package/out/generator/sdParser.js +213 -69
  14. package/out/generator/testGenerator.js +33 -32
  15. package/out/generator/utils.js +11 -4
  16. package/out/generator/validatorGenerator.js +621 -50
  17. package/out/main.js +64 -9
  18. package/package.json +96 -96
  19. package/out/generator/fhir-r4.d.ts +0 -676
  20. package/out/generator/fhirTypes.js +0 -12
  21. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionAppointment.ts +0 -94
  22. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionAppointmentClass.ts +0 -194
  23. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionCheckIn.ts +0 -29
  24. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionCheckInClass.ts +0 -194
  25. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionCheckInNoCode.ts +0 -29
  26. package/out/generator/temp/1761563744855-kptdikzwryj/generated/AdmissionCheckInNoCodeClass.ts +0 -194
  27. package/out/generator/temp/1761563744855-kptdikzwryj/generated/RandomSupport.ts +0 -26
  28. package/out/generator/temp/1761563744855-kptdikzwryj/generated/valuesets/ValueSet-AdmissionFlowIds.ts +0 -38
  29. package/out/generator/temp/1761563744855-kptdikzwryj/generated/valuesets/ValueSet-AdmissionReasonCodeGroup.ts +0 -42
  30. package/out/generator/temp/1761563744855-kptdikzwryj/generated/valuesets/index.ts +0 -18
  31. package/out/generator/temp/1761563744855-kptdikzwryj/package/.index.db +0 -0
  32. package/out/generator/temp/1761563744855-kptdikzwryj/package/.index.json +0 -234
  33. package/out/generator/temp/1761563744855-kptdikzwryj/package/CodeSystem-admission-flow-ids.json +0 -1
  34. package/out/generator/temp/1761563744855-kptdikzwryj/package/CodeSystem-admission-reason-codes.json +0 -1
  35. package/out/generator/temp/1761563744855-kptdikzwryj/package/ImplementationGuide-pink.admission.json +0 -1
  36. package/out/generator/temp/1761563744855-kptdikzwryj/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckIn.json +0 -1
  37. package/out/generator/temp/1761563744855-kptdikzwryj/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckInNoCode.json +0 -1
  38. package/out/generator/temp/1761563744855-kptdikzwryj/package/SearchParameter-SearchParameter-Appointment-AdmissionUrl.json +0 -1
  39. package/out/generator/temp/1761563744855-kptdikzwryj/package/SearchParameter-SearchParameter-Appointment-AdmissionUuid.json +0 -1
  40. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionAppointment.json +0 -1
  41. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionCheckIn.json +0 -1
  42. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionCheckInNoCode.json +0 -1
  43. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionDataFlow.json +0 -1
  44. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionDevice.json +0 -1
  45. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionDocumentMetadata.json +0 -1
  46. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionFormData.json +0 -1
  47. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionFormUrl.json +0 -1
  48. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionFormUuid.json +0 -1
  49. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionIntegrationPoints.json +0 -1
  50. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionPatient.json +0 -1
  51. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionPatientData.json +0 -1
  52. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-AdmissionRoutingRule.json +0 -1
  53. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-LocationTomlConfiguration.json +0 -1
  54. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-Pink-Location-With-Toml.json +0 -1
  55. package/out/generator/temp/1761563744855-kptdikzwryj/package/StructureDefinition-PinkLocation.json +0 -1
  56. package/out/generator/temp/1761563744855-kptdikzwryj/package/ValueSet-AdmissionFlowIdsValueSet.json +0 -1
  57. package/out/generator/temp/1761563744855-kptdikzwryj/package/ValueSet-AdmissionReasonCodeGroup.json +0 -1
  58. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/AllergyIntolerance-Example-PenicillinAllergy.json +0 -1
  59. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/Appointment-Example-AdmissionAppointment.json +0 -1
  60. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/Condition-Example-DiabetesCondition.json +0 -1
  61. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/Device-Example-Surgery-Room.json +0 -1
  62. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/DocumentReference-Example-PreOperativeEvaluation.json +0 -1
  63. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/Location-Example-Location-With-Toml.json +0 -1
  64. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/Patient-Example-Patient.json +0 -1
  65. package/out/generator/temp/1761563744855-kptdikzwryj/package/example/QuestionnaireResponse-Example-AdmissionFormResponse.json +0 -1
  66. package/out/generator/temp/1761563744855-kptdikzwryj/package/other/spec.internals +0 -313
  67. package/out/generator/temp/1761563744855-kptdikzwryj/package/other/validation-oo.json +0 -1
  68. package/out/generator/temp/1761563744855-kptdikzwryj/package/other/validation-summary.json +0 -1
  69. package/out/generator/temp/1761563744855-kptdikzwryj/package/package.json +0 -23
  70. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionAppointment.sch +0 -22
  71. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionCheckIn.sch +0 -18
  72. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionCheckInNoCode.sch +0 -18
  73. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionDevice.sch +0 -12
  74. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionFormUrl.sch +0 -18
  75. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionFormUuid.sch +0 -18
  76. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-AdmissionPatient.sch +0 -12
  77. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-Pink-Location-With-Toml.sch +0 -26
  78. package/out/generator/temp/1761563744855-kptdikzwryj/package/xml/StructureDefinition-PinkLocation.sch +0 -12
  79. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionAppointment.ts +0 -94
  80. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionAppointmentClass.ts +0 -194
  81. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckIn.ts +0 -29
  82. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInClass.ts +0 -194
  83. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInNoCode.ts +0 -29
  84. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInNoCodeClass.ts +0 -194
  85. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDataFlow.ts +0 -51
  86. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDataFlowClass.ts +0 -194
  87. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDevice.ts +0 -67
  88. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDeviceClass.ts +0 -199
  89. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/RandomSupport.ts +0 -26
  90. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/ValueSet-AdmissionFlowIds.ts +0 -38
  91. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/ValueSet-AdmissionReasonCodeGroup.ts +0 -42
  92. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/index.ts +0 -18
  93. package/out/generator/temp/1761673242558-4u3in1qziv2/package/.index.db +0 -0
  94. package/out/generator/temp/1761673242558-4u3in1qziv2/package/.index.json +0 -234
  95. package/out/generator/temp/1761673242558-4u3in1qziv2/package/CodeSystem-admission-flow-ids.json +0 -1
  96. package/out/generator/temp/1761673242558-4u3in1qziv2/package/CodeSystem-admission-reason-codes.json +0 -1
  97. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ImplementationGuide-pink.admission.json +0 -1
  98. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckIn.json +0 -1
  99. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckInNoCode.json +0 -1
  100. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionUrl.json +0 -1
  101. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionUuid.json +0 -1
  102. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionAppointment.json +0 -1
  103. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionCheckIn.json +0 -1
  104. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionCheckInNoCode.json +0 -1
  105. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDataFlow.json +0 -1
  106. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDevice.json +0 -1
  107. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDocumentMetadata.json +0 -1
  108. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormData.json +0 -1
  109. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormUrl.json +0 -1
  110. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormUuid.json +0 -1
  111. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionIntegrationPoints.json +0 -1
  112. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionPatient.json +0 -1
  113. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionPatientData.json +0 -1
  114. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionRoutingRule.json +0 -1
  115. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-LocationTomlConfiguration.json +0 -1
  116. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-Pink-Location-With-Toml.json +0 -1
  117. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-PinkLocation.json +0 -1
  118. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ValueSet-AdmissionFlowIdsValueSet.json +0 -1
  119. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ValueSet-AdmissionReasonCodeGroup.json +0 -1
  120. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/AllergyIntolerance-Example-PenicillinAllergy.json +0 -1
  121. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Appointment-Example-AdmissionAppointment.json +0 -1
  122. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Condition-Example-DiabetesCondition.json +0 -1
  123. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Device-Example-Surgery-Room.json +0 -1
  124. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/DocumentReference-Example-PreOperativeEvaluation.json +0 -1
  125. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Location-Example-Location-With-Toml.json +0 -1
  126. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Patient-Example-Patient.json +0 -1
  127. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/QuestionnaireResponse-Example-AdmissionFormResponse.json +0 -1
  128. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/spec.internals +0 -313
  129. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/validation-oo.json +0 -1
  130. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/validation-summary.json +0 -1
  131. package/out/generator/temp/1761673242558-4u3in1qziv2/package/package.json +0 -23
  132. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionAppointment.sch +0 -22
  133. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionCheckIn.sch +0 -18
  134. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionCheckInNoCode.sch +0 -18
  135. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionDevice.sch +0 -12
  136. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionFormUrl.sch +0 -18
  137. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionFormUuid.sch +0 -18
  138. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionPatient.sch +0 -12
  139. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-Pink-Location-With-Toml.sch +0 -26
  140. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-PinkLocation.sch +0 -12
package/LICENSE CHANGED
@@ -1,15 +1,15 @@
1
- ISC License
2
-
3
- Copyright (c) 2025 Maximilian Nussbaumer
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1
+ ISC License
2
+
3
+ Copyright (c) 2025 Maximilian Nussbaumer
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,210 +1,226 @@
1
- # BabelFHIR-TS
2
-
3
- [![npm version](https://img.shields.io/npm/v/babelfhir-ts.svg)](https://www.npmjs.com/package/babelfhir-ts)
4
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue)](https://www.typescriptlang.org/)
6
- [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)](https://nodejs.org/)
7
-
8
- **BabelFHIR-TS** transforms FHIR® StructureDefinitions into production-ready TypeScript code with full type safety and built-in validation. Unlike generic FHIR type definitions, BabelFHIR-TS generates **profile-aware** interfaces that understand your Implementation Guide's constraints, extensions, and slicing rules.
9
-
10
- ### What you get
11
-
12
- - **Strongly typed interfaces** that merge profile constraints with base FHIR types (types come from `@types/fhir`)
13
- - **Compiled output by default** — packages ship JavaScript (`.js`) plus TypeScript declarations (`.d.ts`)
14
- - **Runtime validation** using FHIRPath expressions from the profile—no external validator required for basic checks
15
- - **Type-safe extension handling** with proper slicing and nested extension support
16
- - **Random data builders** for testing and development (when class generation is enabled)
17
- - **Zero manual mapping**—consume any FHIR package or Implementation Guide directly from registries
18
- - **Fast and lightweight**—minimal runtime deps; only `fhirpath` is required for validators
19
- - **Install any FHIR profile as a node module**—use `babelfhir-ts install` to add Implementation Guides directly to your project
20
-
21
- ## Installation
22
-
23
- Install globally (recommended when using the CLI frequently):
24
-
25
- ```bash
26
- npm install -g babelfhir-ts
27
- ```
28
-
29
- Or invoke on-demand without a global install:
30
-
31
- ```bash
32
- npx babelfhir-ts --help
33
- ```
34
-
35
- > **Requirements:** Node.js 18+ (ESM support) and an internet connection when downloading packages from remote registries.
36
-
37
- ## Quick start
38
-
39
- Generate code from a local folder that contains FHIR packages:
40
-
41
- ```bash
42
- babelfhir-ts input/ output/
43
- ```
44
-
45
- Process a single package archive and write the generated interfaces back into a new `.tgz` file:
46
-
47
- ```bash
48
- babelfhir-ts hl7.fhir.us.core-8.0.0.tgz us-core-generated.tgz
49
- ```
50
-
51
- Download and process a package directly from a registry (defaults to `https://packages.simplifier.net`):
52
-
53
- ```bash
54
- babelfhir-ts --package hl7.fhir.us.core@8.0.0
55
- ```
56
-
57
- Download, pocess and install a processed package into your current project:
58
-
59
- ```bash
60
- babelfhir-ts install hl7.fhir.us.core@8.0.0
61
- ```
62
-
63
- After generation you can import the emitted classes:
64
-
65
- ```ts
66
- import { USCorePatientClass } from "./output/USCorePatientClass";
67
-
68
- const patient = USCorePatientClass.random();
69
- const { errors, warnings } = await patient.validate();
70
- ```
71
-
72
- ## Using the generated code in your project
73
-
74
- Generated profile packages installed via `babelfhir-ts install` are published as **compiled JavaScript with TypeScript declarations**:
75
-
76
- - JavaScript for runtime: `index.js`, `*.js`
77
- - Type declarations for IDE/TS: `index.d.ts`, `*.d.ts`
78
- - Dependencies:
79
- - `@types/fhir` is included as a dependency of the generated package (no extra setup in your app)
80
- - `fhirpath` is a peer dependency (required only if you use the generated validators/classes)
81
-
82
- Install `fhirpath` in your app if you plan to call `.validate()` or use the generated classes.
83
-
84
- ### Module resolution
85
-
86
- Generated packages work with all modern TypeScript setups:
87
-
88
- - **Node.js 18+** with `"type": "module"` in `package.json`
89
- - **Bundlers** (Vite, esbuild, Webpack) with ESM output
90
- - **TypeScript 5.0+** with any module resolution (`node16`, `nodenext`, or `bundler`)
91
-
92
- #### FHIR type imports
93
-
94
- Generated code imports base FHIR types from `"fhir/r4"`:
95
-
96
- ```ts
97
- import { Appointment, Extension, CodeableConcept } from "fhir/r4";
98
- ```
99
-
100
- Since `@types/fhir` doesn't provide a `package.json` `exports` field, BabelFHIR-TS includes an **ambient module declaration** (`fhir-r4.d.ts`) in every generated package. The generated `index.d.ts` references this file:
101
-
102
- ```ts
103
- /// <reference path="./fhir-r4.d.ts" />
104
- ```
105
-
106
- This ensures TypeScript can resolve `fhir/r4` imports automatically without any configuration in your project's `tsconfig.json`.
107
-
108
- ## CLI reference
109
-
110
- ```
111
- babelfhir-ts [options] [<input> [output]]
112
- ```
113
-
114
- | Argument / option | Description |
115
- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
116
- | `<input>` | Directory of FHIR packages/StructureDefinitions, single package (`.tgz`/`.zip`), or single StructureDefinition `.json`. Defaults to `./input` when omitted. |
117
- | `<output>` | Destination directory or archive. Defaults to `./output` when omitted. |
118
- | `install` | Downloads, processes, and installs a package as a project dependency. |
119
- | `--package <pkg@version>` | Fetch a package from a registry and process it without manual download. |
120
- | `--registry <url>` | Custom registry base URL (default:`https://packages.simplifier.net`). |
121
- | `--log <level>` | Control logging output:`none` (default), `console`, or `file`. |
122
- | `--no-cache` | Remove the `.cache` directory once generation completes. |
123
- | `--no-classes` | Skip emitting helper classes (interfaces & validators only). |
124
- | `-h, --help` | Print usage help. |
125
- | `-v, --version` | Print the BabelFHIR-TS version. |
126
-
127
- ### Supported inputs
128
-
129
- - **Directory** – scan all `.tgz`, `.zip`, or `.json` files inside the folder
130
- - **Archive** – process a FHIR NPM package in `.tgz` or `.zip` format
131
- - **StructureDefinition JSON** – generate code for a single profile definitio
132
-
133
- ## Scripts for contributors
134
-
135
- | Script | Purpose |
136
- | ------------------------------ | ---------------------------------------------------------------------------- |
137
- | `npm run generate` | Execute the CLI against the local `input/` folder and refresh `output/`. |
138
- | `npm run generate:check` | End-to-end check: generate, type-check, and lint the emitted output. |
139
- | `npm test` | Type-check and run all Vitest suites (coverage enabled). |
140
- | `npm run download-validator` | Fetch the official HL7 validation jar used for parity testing. |
141
-
142
- ## Caching notes
143
-
144
- The generator caches downloaded StructureDefinitions and packages inside `.cache/`. When you need a clean run, pass `--no-cache` or manually remove the folder. Temporary downloads land in `.temp-*` directories and are cleaned up automatically.
145
-
146
- ## Why BabelFHIR-TS?
147
-
148
- **The FHIR Challenge**: Implementation Guides define strict profiles that constrain base FHIR resources with required or must-support elements, custom extensions, value set bindings, and cardinality rules. Existing TypeScript libraries can't capture these requirements when you need profile-specific types, leading to an overhead when using TypeScript to build apps that interact with FHIR servers.
149
-
150
- **The BabelFHIR-TS Solution**: Automatically generates TypeScript interfaces and validation logic directly from StructureDefinition JSON. Your IDE autocompletes required fields, flags missing extensions at compile-time, and validates FHIRPath invariants at runtime.
151
-
152
- ## Limitations
153
-
154
- BabelFHIR-TS is a code generation tool that parses FHIR StructureDefinitions and produces TypeScript interfaces and validators. While it handles many common FHIR profiling patterns, there are important limitations to be aware of:
155
-
156
- ### Profile Mapping Accuracy
157
-
158
- - **Not guaranteed for all IGs**: The generator uses heuristics to interpret StructureDefinition constraints, slicing rules, and extensions. Complex or unusual profiling patterns may not map correctly to TypeScript.
159
- - **Test before production**: Always validate the generated code against your specific Implementation Guide's examples and test cases. We recommend running the official FHIR validator alongside BabelFHIR-TS in your QA pipeline.
160
- - **Edge cases**: Rare profiling constructs (deeply nested slicing, conditional constraints, complex discriminators) may generate suboptimal or incomplete types.
161
-
162
- ### Validation Scope
163
-
164
- - **High-level checks only**: The generated `validate()` functions execute FHIRPath expressions from profile invariants but do **not** perform:
165
- - Terminology expansion or ValueSet validation
166
- - Reference resolution (checking that referenced resources exist)
167
- - Full cardinality enforcement for complex slicing scenarios
168
- - Server-side business logic or workflow rules
169
- - **Use the official validator**: For production conformance testing, use the [HL7 FHIR Validator](https://github.com/hapifhir/org.hl7.fhir.core) alongside BabelFHIR-TS.
170
-
171
- ### TypeScript Limitations
172
-
173
- - **Runtime type checking is limited**: TypeScript types are erased at compile time. The generated interfaces provide compile-time safety but cannot enforce constraints at runtime without the validator functions.
174
- - **Extension slicing**: While the generator creates typed extension interfaces, TypeScript cannot enforce that extension arrays contain exactly the required slices at compile time (this is validated at runtime).
175
- - **Choice types**: FHIR's `[x]` choice types (e.g., `value[x]`) are represented as union types in TypeScript, which may require runtime type narrowing.
176
-
177
- ### FHIR Version Support
178
-
179
- - **R4 only**: The current version targets FHIR R4. Support for R5, DSTU2, or STU3 is not yet available.
180
- - **Dependencies**: Generated code depends on `@types/fhir` (R4 definitions) and `fhirpath` (R4 compatible).
181
-
182
- ### Reporting Issues
183
-
184
- If you encounter an Implementation Guide that doesn't generate correctly, please [open an issue](https://github.com/quotentiroler/BabelFHIR-ts/issues) with:
185
-
186
- - The package name and version
187
- - The specific StructureDefinition URL
188
- - Expected vs. actual generated output
189
- - Any validation errors or type mismatches
190
-
191
- We continuously improve the generator based on real-world IG usage, and your feedback helps make BabelFHIR-TS more robust.
192
-
193
- ## License
194
-
195
- ISC © Maximilian Nussbaumer
196
-
197
- ## Contributing
198
-
199
- Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute to this project.
200
-
201
- ## Security
202
-
203
- For security issues, please see [SECURITY.md](SECURITY.md) for our security policy and how to report vulnerabilities.
204
-
205
- ## Links
206
-
207
- - [npm package](https://www.npmjs.com/package/babelfhir-ts)
208
- - [GitHub repository](https://github.com/quotentiroler/BabelFHIR-ts)
209
- - [Issue tracker](https://github.com/quotentiroler/BabelFHIR-ts/issues)
210
- - [Changelog](CHANGELOG.md)
1
+ <div align="center">
2
+ <img src="./logo.png" alt="BabelFHIR-TS Logo" width="200"/>
3
+ </div>
4
+
5
+ # BabelFHIR-TS
6
+
7
+ [![npm version](https://img.shields.io/npm/v/babelfhir-ts.svg)](https://www.npmjs.com/package/babelfhir-ts)
8
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue)](https://www.typescriptlang.org/)
10
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)](https://nodejs.org/)
11
+
12
+ **BabelFHIR-TS** transforms FHIR® StructureDefinitions into production-ready TypeScript code with full type safety and built-in validation. Unlike generic FHIR type definitions, BabelFHIR-TS generates **profile-aware** interfaces that understand your Implementation Guide's constraints, extensions, and slicing rules.
13
+
14
+ ### What you get
15
+
16
+ - **Strongly typed interfaces** that merge profile constraints with base FHIR types (types come from `@types/fhir`)
17
+ - **Compiled output by default** packages ship JavaScript (`.js`) plus TypeScript declarations (`.d.ts`)
18
+ - **Runtime validation** using FHIRPath expressions from the profile—no external validator required for basic checks
19
+ - **Type-safe extension handling** with proper slicing and nested extension support
20
+ - **Random data builders** for testing and development (when class generation is enabled)
21
+ - **Zero manual mapping**—consume any FHIR package or Implementation Guide directly from registries
22
+ - **Fast and lightweight**—minimal runtime deps; only `fhirpath` is required for validators
23
+ - **Install any FHIR profile as a node module**—use `babelfhir-ts install` to add Implementation Guides directly to your project
24
+
25
+ ## Installation
26
+
27
+ Install globally (recommended when using the CLI frequently):
28
+
29
+ ```bash
30
+ npm install -g babelfhir-ts
31
+ ```
32
+
33
+ Or invoke on-demand without a global install:
34
+
35
+ ```bash
36
+ npx babelfhir-ts --help
37
+ ```
38
+
39
+ > **Requirements:** Node.js 18+ (ESM support) and an internet connection when downloading packages from remote registries.
40
+
41
+ ## Quick start
42
+
43
+ Generate code from a local folder that contains FHIR packages:
44
+
45
+ ```bash
46
+ babelfhir-ts input/ output/
47
+ ```
48
+
49
+ Process a single package archive and write the generated interfaces back into a new `.tgz` file:
50
+
51
+ ```bash
52
+ babelfhir-ts hl7.fhir.us.core-8.0.0.tgz us-core-generated.tgz
53
+ ```
54
+
55
+ Download and process a package directly from a registry (defaults to `https://packages.simplifier.net`):
56
+
57
+ ```bash
58
+ babelfhir-ts --package hl7.fhir.us.core@8.0.0
59
+ ```
60
+
61
+ Download, pocess and install a processed package into your current project:
62
+
63
+ ```bash
64
+ babelfhir-ts install hl7.fhir.us.core@8.0.0
65
+ ```
66
+
67
+ After generation you can import the emitted classes:
68
+
69
+ ```ts
70
+ import { USCorePatientClass } from "./output/USCorePatientClass";
71
+
72
+ const patient = USCorePatientClass.random();
73
+ const { errors, warnings } = await patient.validate();
74
+ ```
75
+
76
+ ## Using the generated code in your project
77
+
78
+ Generated profile packages installed via `babelfhir-ts install` are published as **compiled JavaScript with TypeScript declarations**:
79
+
80
+ - JavaScript for runtime: `index.js`, `*.js`
81
+ - Type declarations for IDE/TS: `index.d.ts`, `*.d.ts`
82
+ - Dependencies:
83
+ - `@types/fhir` is included as a dependency of the generated package (no extra setup in your app)
84
+ - `fhirpath` is a peer dependency (required only if you use the generated validators/classes)
85
+
86
+ Install `fhirpath` in your app if you plan to call `.validate()` or use the generated classes.
87
+
88
+ ### Module resolution
89
+
90
+ Generated packages work with all modern TypeScript setups:
91
+
92
+ - **Node.js 18+** with `"type": "module"` in `package.json`
93
+ - **Bundlers** (Vite, esbuild, Webpack) with ESM output
94
+ - **TypeScript 5.0+** with any module resolution (`node16`, `nodenext`, or `bundler`)
95
+
96
+ #### FHIR type imports
97
+
98
+ Generated code imports base FHIR types from `"fhir/r4"`:
99
+
100
+ ```ts
101
+ import { Appointment, Extension, CodeableConcept } from "fhir/r4";
102
+ ```
103
+
104
+ Since `@types/fhir` doesn't provide a `package.json` `exports` field, BabelFHIR-TS includes an **ambient module declaration** (`fhir-r4.d.ts`) in every generated package. The generated `index.d.ts` references this file:
105
+
106
+ ```ts
107
+ /// <reference path="./fhir-r4.d.ts" />
108
+ ```
109
+
110
+ This ensures TypeScript can resolve `fhir/r4` imports automatically without any configuration in your project's `tsconfig.json`.
111
+
112
+ ## CLI reference
113
+
114
+ ```
115
+ babelfhir-ts [options] [<input> [output]]
116
+ ```
117
+
118
+ | Argument / option | Description |
119
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
+ | `<input>` | Directory of FHIR packages/StructureDefinitions, single package (`.tgz`/`.zip`), or single StructureDefinition `.json`. Defaults to `./input` when omitted. |
121
+ | `<output>` | Destination directory or archive. Defaults to `./output` when omitted. |
122
+ | `install` | Downloads, processes, and installs a package as a project dependency. |
123
+ | `--package <pkg@version>` | Fetch a package from a registry and process it without manual download. |
124
+ | `--registry <url>` | Custom registry base URL (default:`https://packages.simplifier.net`). |
125
+ | `--log <level>` | Control logging output:`none` (default), `console`, or `file`. |
126
+ | `--no-cache` | Remove the `.cache` directory once generation completes. |
127
+ | `--no-classes` | Skip emitting helper classes (interfaces & validators only). |
128
+ | `-h, --help` | Print usage help. |
129
+ | `-v, --version` | Print the BabelFHIR-TS version. |
130
+
131
+ ### Supported inputs
132
+
133
+ - **Directory** scan all `.tgz`, `.zip`, or `.json` files inside the folder
134
+ - **Archive** – process a FHIR NPM package in `.tgz` or `.zip` format
135
+ - **StructureDefinition JSON** – generate code for a single profile definitio
136
+
137
+ ## Scripts for contributors
138
+
139
+ | Script | Purpose |
140
+ | ------------------------------ | ---------------------------------------------------------------------------- |
141
+ | `npm run generate` | Execute the CLI against the local `input/` folder and refresh `output/`. |
142
+ | `npm run generate:check` | End-to-end check: generate, type-check, and lint the emitted output. |
143
+ | `npm test` | Type-check and run all Vitest suites (coverage enabled). |
144
+ | `npm run download-validator` | Fetch the official HL7 validation jar used for parity testing. |
145
+
146
+ ## Caching notes
147
+
148
+ The generator caches downloaded StructureDefinitions and packages inside `.cache/`. When you need a clean run, pass `--no-cache` or manually remove the folder. Temporary downloads land in `.temp-*` directories and are cleaned up automatically.
149
+
150
+ ## Why BabelFHIR-TS?
151
+
152
+ **The FHIR Challenge**: Implementation Guides define strict profiles that constrain base FHIR resources with required or must-support elements, custom extensions, value set bindings, and cardinality rules. Existing TypeScript libraries can't capture these requirements when you need profile-specific types, leading to an overhead when using TypeScript to build apps that interact with FHIR servers.
153
+
154
+ **The BabelFHIR-TS Solution**: Automatically generates TypeScript interfaces and validation logic directly from StructureDefinition JSON. Your IDE autocompletes required fields, flags missing extensions at compile-time, and validates FHIRPath invariants at runtime.
155
+
156
+ ## Limitations
157
+
158
+ BabelFHIR-TS is a code generation tool that parses FHIR StructureDefinitions and produces TypeScript interfaces and validators. While it handles many common FHIR profiling patterns, there are important limitations to be aware of:
159
+
160
+ ### Profile Mapping Accuracy
161
+
162
+ - **Not guaranteed for all IGs**: The generator uses heuristics to interpret StructureDefinition constraints, slicing rules, and extensions. Complex or unusual profiling patterns may not map correctly to TypeScript.
163
+ - **Test before production**: Always validate the generated code against your specific Implementation Guide's examples and test cases. We recommend running the official FHIR validator alongside BabelFHIR-TS in your QA pipeline.
164
+ - **Edge cases**: Rare profiling constructs (deeply nested slicing, conditional constraints, complex discriminators) may generate suboptimal or incomplete types.
165
+
166
+ ### Validation Scope
167
+
168
+ - **High-level checks only**: The generated `validate()` functions execute FHIRPath expressions from profile invariants but do **not** perform:
169
+ - Terminology expansion or ValueSet validation
170
+ - Reference resolution (checking that referenced resources exist)
171
+ - Full cardinality enforcement for complex slicing scenarios
172
+ - Server-side business logic or workflow rules
173
+ - **Use the official validator**: For production conformance testing, use the [HL7 FHIR Validator](https://github.com/hapifhir/org.hl7.fhir.core) alongside BabelFHIR-TS.
174
+
175
+ ### TypeScript Limitations
176
+
177
+ - **Runtime type checking is limited**: TypeScript types are erased at compile time. The generated interfaces provide compile-time safety but cannot enforce constraints at runtime without the validator functions.
178
+ - **Extension slicing**: While the generator creates typed extension interfaces, TypeScript cannot enforce that extension arrays contain exactly the required slices at compile time (this is validated at runtime).
179
+ - **Choice types**: FHIR's `[x]` choice types (e.g., `value[x]`) are represented as union types in TypeScript, which may require runtime type narrowing.
180
+
181
+ ### Generated Helper Methods
182
+
183
+ - **`random()` is not fully conformant**: The generated `.random()` methods create test data that satisfies TypeScript types and basic cardinality, but **do not guarantee** fully valid FHIR resources. Random data may violate:
184
+ - Complex FHIRPath invariants
185
+ - ValueSet bindings (codes are randomly chosen from required bindings but not guaranteed to be semantically correct)
186
+ - Profile-specific business rules
187
+ - Reference integrity constraints
188
+
189
+ Use `random()` for development, testing, and prototyping, but always validate production data on the FHIR server side.
190
+
191
+ - **`validate()` parity**: The generated validation methods execute FHIRPath expressions and check constraints from StructureDefinitions, but are **only guaranteed to match** the Firely .NET SDK validator for scenarios covered by our test suite (see GitHub actions). Edge cases, complex slicing patterns, or profiles not in our test pipeline may produce different results. For production conformance testing, use the [HL7 FHIR Validator](https://github.com/hapifhir/org.hl7.fhir.core) or [Firely .NET SDK](https://fire.ly/products/firely-net-sdk/) as the source of truth.
192
+
193
+ ### FHIR Version Support
194
+
195
+ - **R4 only**: The current version targets FHIR R4. Support for R5, DSTU2, or STU3 is not yet available.
196
+ - **Dependencies**: Generated code depends on `@types/fhir` (R4 definitions) and `fhirpath` (R4 compatible).
197
+
198
+ ### Reporting Issues
199
+
200
+ If you encounter an Implementation Guide that doesn't generate correctly, please [open an issue](https://github.com/quotentiroler/BabelFHIR-ts/issues) with:
201
+
202
+ - The package name and version
203
+ - The specific StructureDefinition URL
204
+ - Expected vs. actual generated output
205
+ - Any validation errors or type mismatches
206
+
207
+ We continuously improve the generator based on real-world IG usage, and your feedback helps make BabelFHIR-TS more robust.
208
+
209
+ ## License
210
+
211
+ ISC © Maximilian Nussbaumer
212
+
213
+ ## Contributing
214
+
215
+ Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute to this project.
216
+
217
+ ## Security
218
+
219
+ For security issues, please see [SECURITY.md](SECURITY.md) for our security policy and how to report vulnerabilities.
220
+
221
+ ## Links
222
+
223
+ - [npm package](https://www.npmjs.com/package/babelfhir-ts)
224
+ - [GitHub repository](https://github.com/quotentiroler/BabelFHIR-ts)
225
+ - [Issue tracker](https://github.com/quotentiroler/BabelFHIR-ts/issues)
226
+ - [Changelog](CHANGELOG.md)
@@ -1,29 +1,29 @@
1
- #!/usr/bin/env node
2
-
3
- import { spawn } from 'child_process';
4
- import { fileURLToPath } from 'url';
5
- import { dirname, join } from 'path';
6
- import process from 'process';
7
- import fs from 'fs';
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- // Use node directly to run the compiled JavaScript
13
- const mainJsPath = join(__dirname, '..', 'out', 'main.js');
14
-
15
- // Check if the compiled file exists
16
- if (!fs.existsSync(mainJsPath)) {
17
- console.error('Compiled main.js not found. Please ensure the package was built correctly.');
18
- process.exit(1);
19
- }
20
-
21
- const child = spawn('node', [mainJsPath, ...process.argv.slice(2)], {
22
- stdio: 'inherit',
23
- cwd: process.cwd(), // Use the current working directory where the command was invoked
24
- shell: process.platform === 'win32'
25
- });
26
-
27
- child.on('exit', (code) => {
28
- process.exit(code || 0);
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'child_process';
4
+ import { fileURLToPath } from 'url';
5
+ import { dirname, join } from 'path';
6
+ import process from 'process';
7
+ import fs from 'fs';
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+
12
+ // Use node directly to run the compiled JavaScript
13
+ const mainJsPath = join(__dirname, '..', 'out', 'main.js');
14
+
15
+ // Check if the compiled file exists
16
+ if (!fs.existsSync(mainJsPath)) {
17
+ console.error('Compiled main.js not found. Please ensure the package was built correctly.');
18
+ process.exit(1);
19
+ }
20
+
21
+ const child = spawn('node', [mainJsPath, ...process.argv.slice(2)], {
22
+ stdio: 'inherit',
23
+ cwd: process.cwd(), // Use the current working directory where the command was invoked
24
+ shell: process.platform === 'win32'
25
+ });
26
+
27
+ child.on('exit', (code) => {
28
+ process.exit(code || 0);
29
29
  });