babelfhir-ts 1.0.18 → 1.0.26

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 (70) hide show
  1. package/README.md +27 -92
  2. package/out/fhir-r4.d.ts +676 -0
  3. package/out/generator/fhir-r4.d.ts +676 -0
  4. package/out/generator/index.js +24 -17
  5. package/out/generator/interfaceGenerator.js +1 -29
  6. package/out/generator/sdParser.js +71 -5
  7. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionAppointment.ts +94 -0
  8. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionAppointmentClass.ts +194 -0
  9. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckIn.ts +29 -0
  10. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInClass.ts +194 -0
  11. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInNoCode.ts +29 -0
  12. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionCheckInNoCodeClass.ts +194 -0
  13. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDataFlow.ts +51 -0
  14. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDataFlowClass.ts +194 -0
  15. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDevice.ts +67 -0
  16. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/AdmissionDeviceClass.ts +199 -0
  17. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/RandomSupport.ts +26 -0
  18. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/ValueSet-AdmissionFlowIds.ts +38 -0
  19. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/ValueSet-AdmissionReasonCodeGroup.ts +42 -0
  20. package/out/generator/temp/1761673242558-4u3in1qziv2/generated/valuesets/index.ts +18 -0
  21. package/out/generator/temp/1761673242558-4u3in1qziv2/package/.index.db +0 -0
  22. package/out/generator/temp/1761673242558-4u3in1qziv2/package/.index.json +234 -0
  23. package/out/generator/temp/1761673242558-4u3in1qziv2/package/CodeSystem-admission-flow-ids.json +1 -0
  24. package/out/generator/temp/1761673242558-4u3in1qziv2/package/CodeSystem-admission-reason-codes.json +1 -0
  25. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ImplementationGuide-pink.admission.json +1 -0
  26. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckIn.json +1 -0
  27. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionCheckInNoCode.json +1 -0
  28. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionUrl.json +1 -0
  29. package/out/generator/temp/1761673242558-4u3in1qziv2/package/SearchParameter-SearchParameter-Appointment-AdmissionUuid.json +1 -0
  30. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionAppointment.json +1 -0
  31. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionCheckIn.json +1 -0
  32. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionCheckInNoCode.json +1 -0
  33. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDataFlow.json +1 -0
  34. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDevice.json +1 -0
  35. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionDocumentMetadata.json +1 -0
  36. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormData.json +1 -0
  37. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormUrl.json +1 -0
  38. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionFormUuid.json +1 -0
  39. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionIntegrationPoints.json +1 -0
  40. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionPatient.json +1 -0
  41. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionPatientData.json +1 -0
  42. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-AdmissionRoutingRule.json +1 -0
  43. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-LocationTomlConfiguration.json +1 -0
  44. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-Pink-Location-With-Toml.json +1 -0
  45. package/out/generator/temp/1761673242558-4u3in1qziv2/package/StructureDefinition-PinkLocation.json +1 -0
  46. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ValueSet-AdmissionFlowIdsValueSet.json +1 -0
  47. package/out/generator/temp/1761673242558-4u3in1qziv2/package/ValueSet-AdmissionReasonCodeGroup.json +1 -0
  48. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/AllergyIntolerance-Example-PenicillinAllergy.json +1 -0
  49. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Appointment-Example-AdmissionAppointment.json +1 -0
  50. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Condition-Example-DiabetesCondition.json +1 -0
  51. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Device-Example-Surgery-Room.json +1 -0
  52. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/DocumentReference-Example-PreOperativeEvaluation.json +1 -0
  53. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Location-Example-Location-With-Toml.json +1 -0
  54. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/Patient-Example-Patient.json +1 -0
  55. package/out/generator/temp/1761673242558-4u3in1qziv2/package/example/QuestionnaireResponse-Example-AdmissionFormResponse.json +1 -0
  56. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/spec.internals +313 -0
  57. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/validation-oo.json +1 -0
  58. package/out/generator/temp/1761673242558-4u3in1qziv2/package/other/validation-summary.json +1 -0
  59. package/out/generator/temp/1761673242558-4u3in1qziv2/package/package.json +23 -0
  60. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionAppointment.sch +22 -0
  61. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionCheckIn.sch +18 -0
  62. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionCheckInNoCode.sch +18 -0
  63. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionDevice.sch +12 -0
  64. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionFormUrl.sch +18 -0
  65. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionFormUuid.sch +18 -0
  66. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-AdmissionPatient.sch +12 -0
  67. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-Pink-Location-With-Toml.sch +26 -0
  68. package/out/generator/temp/1761673242558-4u3in1qziv2/package/xml/StructureDefinition-PinkLocation.sch +12 -0
  69. package/out/main.js +8 -3
  70. package/package.json +6 -4
package/README.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  **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.
4
4
 
5
- ## Why BabelFHIR-TS?
6
-
7
- **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.
8
-
9
- **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.
10
-
11
5
  ### What you get
12
6
 
13
7
  - **Strongly typed interfaces** that merge profile constraints with base FHIR types (types come from `@types/fhir`)
@@ -19,8 +13,6 @@
19
13
  - **Fast and lightweight**—minimal runtime deps; only `fhirpath` is required for validators
20
14
  - **Install any FHIR profile as a node module**—use `babelfhir-ts install` to add Implementation Guides directly to your project
21
15
 
22
- Use it to build FHIR-compliant APIs, validate incoming resources against profiles, or generate type-safe client SDKs from Implementation Guides.
23
-
24
16
  ## Installation
25
17
 
26
18
  Install globally (recommended when using the CLI frequently):
@@ -82,31 +74,32 @@ Generated profile packages installed via `babelfhir-ts install` are published as
82
74
  - `@types/fhir` is included as a dependency of the generated package (no extra setup in your app)
83
75
  - `fhirpath` is a peer dependency (required only if you use the generated validators/classes)
84
76
 
85
- Install `fhirpath` in your app if you plan to call `.validate()` or use the generated classes:
77
+ Install `fhirpath` in your app if you plan to call `.validate()` or use the generated classes.
86
78
 
87
- ```bash
88
- npm install fhirpath
79
+ ### Module resolution
80
+
81
+ Generated packages work with all modern TypeScript setups:
82
+
83
+ - **Node.js 18+** with `"type": "module"` in `package.json`
84
+ - **Bundlers** (Vite, esbuild, Webpack) with ESM output
85
+ - **TypeScript 5.0+** with any module resolution (`node16`, `nodenext`, or `bundler`)
86
+
87
+ #### FHIR type imports
88
+
89
+ Generated code imports base FHIR types from `"fhir/r4"`:
90
+
91
+ ```ts
92
+ import { Appointment, Extension, CodeableConcept } from "fhir/r4";
89
93
  ```
90
94
 
91
- Import and use:
95
+ 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:
92
96
 
93
97
  ```ts
94
- // TypeScript or JavaScript
95
- import { AdmissionAppointment, AdmissionAppointmentClass } from "pink.admission-generated";
96
-
97
- // Types are available automatically via .d.ts
98
- const appt: AdmissionAppointment = {
99
- resourceType: "Appointment",
100
- status: "booked",
101
- start: "2025-10-23T14:00:00Z",
102
- };
103
-
104
- // Optional helper class + validation
105
- const instance = AdmissionAppointmentClass.random();
106
- const result = await new AdmissionAppointmentClass(appt).validate();
107
- console.log(result.errors, result.warnings);
98
+ /// <reference path="./fhir-r4.d.ts" />
108
99
  ```
109
100
 
101
+ This ensures TypeScript can resolve `fhir/r4` imports automatically without any configuration in your project's `tsconfig.json`.
102
+
110
103
  ## CLI reference
111
104
 
112
105
  ```
@@ -130,72 +123,7 @@ babelfhir-ts [options] [<input> [output]]
130
123
 
131
124
  - **Directory** – scan all `.tgz`, `.zip`, or `.json` files inside the folder
132
125
  - **Archive** – process a FHIR NPM package in `.tgz` or `.zip` format
133
- - **StructureDefinition JSON** – generate code for a single profile definition
134
-
135
- ## Generated output
136
-
137
- For each StructureDefinition the generator produces:
138
-
139
- - `*.ts` interface definitions (extending the canonical FHIR types)
140
- - `*Class.ts` companions that offer:
141
- - constructor helpers (`empty`, `random`, `randomClass`)
142
- - deterministic field filling for required and must-support elements
143
- - `validate()` that evaluates FHIR invariant expressions via `fhirpath`
144
- - optional validation parity artefacts when you run the test suite (`npm test validatorParity`)
145
-
146
- The validator relies on `fhirpath.evaluate(...)` to enforce profile invariants (including min cardinalities, slices, and custom expressions) without requiring a full FHIR server. It intentionally performs **high-level** checks only: terminology expansion, reference resolution, and other server-backed logic are out of scope, so keep a downstream validator (e.g. the HL7 Java validator CLI) in your QA pipeline for full conformance.
147
-
148
- ### Example: Generated US Core Encounter Profile
149
-
150
- Given the US Core Encounter profile, BabelFHIR-TS generates TypeScript interfaces that capture all must-support elements and profile extensions:
151
-
152
- ```typescript
153
- import { Encounter, Meta, Extension, Identifier, Coding, CodeableConcept,
154
- Reference, EncounterParticipant, Period, EncounterHospitalization,
155
- EncounterLocation } from "fhir/r4";
156
-
157
- // Extension interface with type-safe URL
158
- export interface UsCoreInterpreterNeeded extends Extension {
159
- url: 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-interpreter-needed'
160
- }
161
-
162
- // Profile interface extending base Encounter with must-support constraints
163
- export interface USCoreEncounterProfile extends Encounter {
164
- /** Must Support */
165
- meta?: Meta;
166
- /** Must Support */
167
- identifier?: Identifier[];
168
- /** Must Support */
169
- class: Coding;
170
- /** Must Support */
171
- type: CodeableConcept[];
172
- /** Must Support */
173
- subject: Reference;
174
- /** Must Support */
175
- participant?: EncounterParticipant[];
176
- /** Must Support */
177
- period?: Period;
178
- /** Must Support */
179
- reasonCode?: CodeableConcept[];
180
- /** Must Support */
181
- reasonReference?: Reference[];
182
- /** Must Support */
183
- hospitalization?: EncounterHospitalization;
184
- /** Must Support */
185
- location?: EncounterLocation[];
186
- /** Must Support */
187
- serviceProvider?: Reference;
188
-
189
- // Typed extension slicing
190
- extension?: (Extension | UsCoreInterpreterNeeded)[];
191
- }
192
-
193
- // Generated validator function
194
- export async function validateUSCoreEncounterProfile(
195
- resource: USCoreEncounterProfile
196
- ): Promise<{ errors: string[], warnings: string[] }>;
197
-
198
- ```
126
+ - **StructureDefinition JSON** – generate code for a single profile definitio
199
127
 
200
128
  ## Scripts for contributors
201
129
 
@@ -210,6 +138,12 @@ export async function validateUSCoreEncounterProfile(
210
138
 
211
139
  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.
212
140
 
141
+ ## Why BabelFHIR-TS?
142
+
143
+ **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.
144
+
145
+ **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.
146
+
213
147
  ## Limitations
214
148
 
215
149
  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:
@@ -243,6 +177,7 @@ BabelFHIR-TS is a code generation tool that parses FHIR StructureDefinitions and
243
177
  ### Reporting Issues
244
178
 
245
179
  If you encounter an Implementation Guide that doesn't generate correctly, please [open an issue](https://github.com/quotentiroler/BabelFHIR-ts/issues) with:
180
+
246
181
  - The package name and version
247
182
  - The specific StructureDefinition URL
248
183
  - Expected vs. actual generated output