babelfhir-ts 1.0.43 → 1.1.3
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/README.md +3 -3
- package/out/src/generator/{constants.js → core/constants.js} +6 -7
- package/out/src/generator/core/sdTypes.js +5 -0
- package/out/src/generator/{utils.js → core/utils.js} +3 -3
- package/out/src/generator/emitters/class/classGenerator.js +714 -0
- package/out/src/generator/emitters/class/classHeuristics.js +326 -0
- package/out/src/generator/emitters/class/enrichResourceHandlers.js +721 -0
- package/out/src/generator/emitters/class/enrichResourceTemplate.js +713 -0
- package/out/src/generator/emitters/class/fieldPatternExtractor.js +331 -0
- package/out/src/generator/emitters/class/randomSupportGenerator.js +10 -0
- package/out/src/generator/emitters/class/randomUtilitiesTemplate.js +122 -0
- package/out/src/generator/emitters/class/sliceElementGenerator.js +586 -0
- package/out/src/generator/emitters/client/clientGenerator.js +652 -0
- package/out/src/generator/emitters/client/clientReadmeGenerator.js +263 -0
- package/out/src/generator/emitters/client/smartAuthGenerator.js +605 -0
- package/out/src/generator/{importManager.js → emitters/interface/importManager.js} +17 -17
- package/out/src/generator/emitters/interface/interfaceFieldProcessor.js +631 -0
- package/out/src/generator/emitters/interface/interfaceGenerator.js +225 -0
- package/out/src/generator/{postProcessExtensions.js → emitters/interface/postProcessExtensions.js} +4 -4
- package/out/src/generator/emitters/interface/processFlatField.js +512 -0
- package/out/src/generator/emitters/interface/processNestedField.js +509 -0
- package/out/src/generator/emitters/validator/sliceValidatorGenerator.js +381 -0
- package/out/src/generator/emitters/validator/validatorGenerator.js +565 -0
- package/out/src/generator/emitters/zod/zodSchemaGenerator.js +552 -0
- package/out/src/generator/emitters/zod/zodStubInstaller.js +77 -0
- package/out/src/generator/emitters/zod/zodTypes.js +27 -0
- package/out/src/generator/fhir/r4/context.js +21 -0
- package/out/src/generator/fhir/r4/context.ts +24 -0
- package/out/src/generator/fhir/r4/dataTypes.json +858 -0
- package/out/src/generator/fhir/r4/interfaces.json +664 -0
- package/out/src/generator/fhir/r4/resources.json +150 -0
- package/out/src/generator/{fhirR4Rules.js → fhir/r4/rules.js} +3 -3
- package/out/src/generator/fhir/r4/rules.ts +226 -0
- package/out/src/generator/fhir/r4b/context.js +21 -0
- package/out/src/generator/fhir/r4b/context.ts +24 -0
- package/out/src/generator/fhir/r4b/dataTypes.json +860 -0
- package/out/src/generator/fhir/r4b/interfaces.json +684 -0
- package/out/src/generator/fhir/r4b/resources.json +145 -0
- package/out/src/generator/fhir/r4b/rules.js +171 -0
- package/out/src/generator/fhir/r4b/rules.ts +190 -0
- package/out/src/generator/fhir/types.js +27 -0
- package/out/src/generator/fhir/types.ts +80 -0
- package/out/src/generator/fhir/versionContext.js +52 -0
- package/out/src/generator/fhir/versionContext.ts +66 -0
- package/out/src/generator/index.js +80 -933
- package/out/src/generator/{packageManager.js → parser/packageManager.js} +2 -2
- package/out/src/generator/{packageParser.js → parser/packageParser.js} +10 -6
- package/out/src/generator/parser/sdFetcher.js +356 -0
- package/out/src/generator/parser/sdParser.js +402 -0
- package/out/src/generator/parser/sliceAggregator.js +420 -0
- package/out/src/generator/{txClient.js → parser/txClient.js} +9 -4
- package/out/src/generator/{vsParser.js → parser/vsParser.js} +4 -4
- package/out/src/generator/sdProcessor.js +605 -0
- package/out/src/main.js +40 -11
- package/package.json +7 -4
- package/out/src/generator/classGenerator.js +0 -1513
- package/out/src/generator/clientGenerator.js +0 -1503
- package/out/src/generator/fhirDataTypes.json +0 -858
- package/out/src/generator/fhirInterfaces.json +0 -665
- package/out/src/generator/fhirResources.json +0 -157
- package/out/src/generator/interfaceGenerator.js +0 -1802
- package/out/src/generator/randomSupportGenerator.js +0 -1518
- package/out/src/generator/sdParser.js +0 -1073
- package/out/src/generator/validatorGenerator.js +0 -907
- /package/out/src/generator/{cacheConfig.js → core/cacheConfig.js} +0 -0
- /package/out/src/generator/{fetchUtils.js → core/fetchUtils.js} +0 -0
- /package/out/src/generator/{valueSetGenerator.js → emitters/valueset/valueSetGenerator.js} +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/Bundle.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/Composition.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/Endpoint.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/README.md +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/Subscription.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/ValueSet.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/backport-subscription.json +0 -0
- /package/out/src/generator/{base-r4 → fhir/r4/base}/well-known-system-codes.json +0 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- **Random data builders** for testing and development (when class generation is enabled)
|
|
22
22
|
- **Zero manual mapping**—consume any FHIR package or Implementation Guide directly from registries
|
|
23
23
|
- **Fast and lightweight**—minimal runtime deps; only `fhirpath` is required for validators
|
|
24
|
-
- **Type-safe FHIR client** — generated client extends [`@babelfhir-ts/client-r4`](https://www.npmjs.com/package/@babelfhir-ts/client-r4) with profile-specific methods (e.g., `.usCorePatient()`, `.pASClaim()`) on top of
|
|
24
|
+
- **Type-safe FHIR client** — generated client extends [`@babelfhir-ts/client-r4`](https://www.npmjs.com/package/@babelfhir-ts/client-r4) with profile-specific methods (e.g., `.usCorePatient()`, `.pASClaim()`) on top of base R4 resource accessors
|
|
25
25
|
- **Install any FHIR profile as a node module**—use `babelfhir-ts install` to add Implementation Guides directly to your project
|
|
26
26
|
|
|
27
27
|
<!-- PARITY-BADGES:START - Do not remove or modify this section -->
|
|
@@ -57,8 +57,6 @@ The first pipeline validates generated resources using the [Firely .NET SDK vali
|
|
|
57
57
|

|
|
58
58
|

|
|
59
59
|
|
|
60
|
-
> 11 profiles are excluded from this pipeline due to schema loading issues in the Firely SDK. These profiles validate successfully with the HL7 Java Validator below. Details in [docs/FIRELY-VALIDATOR-BUGS.md](./docs/FIRELY-VALIDATOR-BUGS.md).
|
|
61
|
-
|
|
62
60
|
### Validation with HL7 Java Validator
|
|
63
61
|
|
|
64
62
|
The second pipeline validates using the [official HL7 FHIR Validator](https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator) (v6.9.1), the reference implementation for FHIR conformance checking:
|
|
@@ -137,6 +135,8 @@ Options:
|
|
|
137
135
|
--no-cache Delete .cache folder after generation
|
|
138
136
|
--no-classes Only generate interfaces and types (skip class generation)
|
|
139
137
|
--no-client Skip FHIR client generation (client generated by default)
|
|
138
|
+
--schema <format> Generate schema files alongside outputs (supported: zod)
|
|
139
|
+
--fhir-version <ver> FHIR version to target: r4 (default) or r4b
|
|
140
140
|
--package <pkg@version> Download FHIR package from registry and process it
|
|
141
141
|
--registry <url> FHIR package registry URL (default: https://packages.simplifier.net)
|
|
142
142
|
--tx-server <url> Terminology server URL for ValueSet expansion (e.g., https://tx.fhir.org/r4)
|
|
@@ -10,10 +10,11 @@ import { fileURLToPath } from 'url';
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
const require = createRequire(import.meta.url);
|
|
12
12
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
// Resolve package.json — works from
|
|
13
|
+
// Resolve package.json — works from src/generator/core (dev) and out/src/generator/core (compiled)
|
|
14
14
|
const _pkgPath = [
|
|
15
15
|
path.resolve(__dirname, '../../package.json'),
|
|
16
16
|
path.resolve(__dirname, '../../../package.json'),
|
|
17
|
+
path.resolve(__dirname, '../../../../package.json'),
|
|
17
18
|
].find(p => {
|
|
18
19
|
try {
|
|
19
20
|
return JSON.parse(require('fs').readFileSync(p, 'utf8')).name === 'babelfhir-ts';
|
|
@@ -254,15 +255,13 @@ const procedure = (mp) => `{ resourceType: 'Procedure', id: randomId()${mp}, sta
|
|
|
254
255
|
const device = (mp) => `{ resourceType: 'Device', id: randomId()${mp}, type: { coding: [{ system: '${TS.SNOMED}', code: '49062001', display: 'Device' }] } }`;
|
|
255
256
|
const claimResponse = (mp) => `{ resourceType: 'ClaimResponse', id: randomId()${mp}, status: 'active', type: { coding: [{ system: '${TS.CLAIM_TYPE}', code: 'professional' }] }, use: 'preauthorization', patient: { reference: 'Patient/' + randomId() }, created: new Date().toISOString().split('T')[0], insurer: { reference: 'Organization/' + randomId() }, outcome: 'complete' }`;
|
|
256
257
|
const claim = (mp) => `{ resourceType: 'Claim', id: randomId()${mp}, status: 'active', type: { coding: [{ system: '${TS.CLAIM_TYPE}', code: 'professional' }] }, use: 'preauthorization', patient: { reference: 'Patient/' + randomId() }, created: new Date().toISOString().split('T')[0], provider: { reference: 'Practitioner/' + randomId() }, priority: { coding: [{ system: '${TS.PROCESS_PRIORITY}', code: 'normal' }] }, insurance: [{ sequence: 1, focal: true, coverage: { reference: 'Coverage/' + randomId() } }] }`;
|
|
257
|
-
/**
|
|
258
|
-
* Build a Composition skeleton. The factory accepts an optional LOINC code
|
|
259
|
-
* and textStatus override for profile-specific requirements
|
|
260
|
-
* (e.g. ISiKBerichtSubSysteme needs text.status='extensions' and code '55112-7').
|
|
261
|
-
*/
|
|
262
258
|
export function compositionSkeleton(metaProfile, opts = {}) {
|
|
263
259
|
const loincCode = opts.loincCode ?? '60591-5';
|
|
264
260
|
const textStatus = opts.textStatus ?? 'generated';
|
|
265
|
-
|
|
261
|
+
const sectionExpr = opts.sections && opts.sections.length > 0
|
|
262
|
+
? opts.sections.map(s => `{ title: '${s.title}', code: { coding: [{ system: '${TS.LOINC}', code: '${s.loincCode}' }] }, text: { status: 'generated', div: '<div xmlns="http://www.w3.org/1999/xhtml">${s.title}</div>' }, emptyReason: { coding: [{ system: 'http://terminology.hl7.org/CodeSystem/list-empty-reason', code: 'unavailable', display: 'Unavailable' }] } }`).join(', ')
|
|
263
|
+
: `{ title: 'Section', text: { status: 'generated', div: '<div xmlns="http://www.w3.org/1999/xhtml">Content</div>' } }`;
|
|
264
|
+
return `{ resourceType: 'Composition', id: 'comp-' + randomId()${metaProfile}, text: { status: '${textStatus}', div: '<div xmlns="http://www.w3.org/1999/xhtml">Composition Narrative</div>' }, status: 'final', type: { coding: [{ system: '${TS.LOINC}', code: '${loincCode}' }], text: '${loincCode}' }, subject: { reference: 'Patient/' + randomId(), display: 'Example Patient' }, date: new Date().toISOString(), author: [{ reference: 'Practitioner/' + randomId(), display: 'Example Practitioner' }], title: 'Document Title', section: [${sectionExpr}] }`;
|
|
266
265
|
}
|
|
267
266
|
/**
|
|
268
267
|
* Registry of resource skeletons indexed by resource type.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { logger } from "
|
|
4
|
-
import
|
|
3
|
+
import { logger } from "../../logger.js";
|
|
4
|
+
import { ctx } from '../fhir/versionContext.js';
|
|
5
5
|
/**
|
|
6
6
|
* Strips the version suffix from a FHIR canonical URL.
|
|
7
7
|
* FHIR canonical URLs use '|' to separate the URL from the version.
|
|
@@ -82,7 +82,7 @@ export function getResourceTypes(options) {
|
|
|
82
82
|
if (extendsMatch) {
|
|
83
83
|
const baseType = extendsMatch[1];
|
|
84
84
|
// Check if it's a known FHIR resource type
|
|
85
|
-
if (
|
|
85
|
+
if (ctx().resourceNames.includes(baseType)) {
|
|
86
86
|
resourceTypes.set(profileName, baseType);
|
|
87
87
|
}
|
|
88
88
|
}
|