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.
Files changed (75) hide show
  1. package/README.md +3 -3
  2. package/out/src/generator/{constants.js → core/constants.js} +6 -7
  3. package/out/src/generator/core/sdTypes.js +5 -0
  4. package/out/src/generator/{utils.js → core/utils.js} +3 -3
  5. package/out/src/generator/emitters/class/classGenerator.js +714 -0
  6. package/out/src/generator/emitters/class/classHeuristics.js +326 -0
  7. package/out/src/generator/emitters/class/enrichResourceHandlers.js +721 -0
  8. package/out/src/generator/emitters/class/enrichResourceTemplate.js +713 -0
  9. package/out/src/generator/emitters/class/fieldPatternExtractor.js +331 -0
  10. package/out/src/generator/emitters/class/randomSupportGenerator.js +10 -0
  11. package/out/src/generator/emitters/class/randomUtilitiesTemplate.js +122 -0
  12. package/out/src/generator/emitters/class/sliceElementGenerator.js +586 -0
  13. package/out/src/generator/emitters/client/clientGenerator.js +652 -0
  14. package/out/src/generator/emitters/client/clientReadmeGenerator.js +263 -0
  15. package/out/src/generator/emitters/client/smartAuthGenerator.js +605 -0
  16. package/out/src/generator/{importManager.js → emitters/interface/importManager.js} +17 -17
  17. package/out/src/generator/emitters/interface/interfaceFieldProcessor.js +631 -0
  18. package/out/src/generator/emitters/interface/interfaceGenerator.js +225 -0
  19. package/out/src/generator/{postProcessExtensions.js → emitters/interface/postProcessExtensions.js} +4 -4
  20. package/out/src/generator/emitters/interface/processFlatField.js +512 -0
  21. package/out/src/generator/emitters/interface/processNestedField.js +509 -0
  22. package/out/src/generator/emitters/validator/sliceValidatorGenerator.js +381 -0
  23. package/out/src/generator/emitters/validator/validatorGenerator.js +565 -0
  24. package/out/src/generator/emitters/zod/zodSchemaGenerator.js +552 -0
  25. package/out/src/generator/emitters/zod/zodStubInstaller.js +77 -0
  26. package/out/src/generator/emitters/zod/zodTypes.js +27 -0
  27. package/out/src/generator/fhir/r4/context.js +21 -0
  28. package/out/src/generator/fhir/r4/context.ts +24 -0
  29. package/out/src/generator/fhir/r4/dataTypes.json +858 -0
  30. package/out/src/generator/fhir/r4/interfaces.json +664 -0
  31. package/out/src/generator/fhir/r4/resources.json +150 -0
  32. package/out/src/generator/{fhirR4Rules.js → fhir/r4/rules.js} +3 -3
  33. package/out/src/generator/fhir/r4/rules.ts +226 -0
  34. package/out/src/generator/fhir/r4b/context.js +21 -0
  35. package/out/src/generator/fhir/r4b/context.ts +24 -0
  36. package/out/src/generator/fhir/r4b/dataTypes.json +860 -0
  37. package/out/src/generator/fhir/r4b/interfaces.json +684 -0
  38. package/out/src/generator/fhir/r4b/resources.json +145 -0
  39. package/out/src/generator/fhir/r4b/rules.js +171 -0
  40. package/out/src/generator/fhir/r4b/rules.ts +190 -0
  41. package/out/src/generator/fhir/types.js +27 -0
  42. package/out/src/generator/fhir/types.ts +80 -0
  43. package/out/src/generator/fhir/versionContext.js +52 -0
  44. package/out/src/generator/fhir/versionContext.ts +66 -0
  45. package/out/src/generator/index.js +80 -933
  46. package/out/src/generator/{packageManager.js → parser/packageManager.js} +2 -2
  47. package/out/src/generator/{packageParser.js → parser/packageParser.js} +10 -6
  48. package/out/src/generator/parser/sdFetcher.js +356 -0
  49. package/out/src/generator/parser/sdParser.js +402 -0
  50. package/out/src/generator/parser/sliceAggregator.js +420 -0
  51. package/out/src/generator/{txClient.js → parser/txClient.js} +9 -4
  52. package/out/src/generator/{vsParser.js → parser/vsParser.js} +4 -4
  53. package/out/src/generator/sdProcessor.js +605 -0
  54. package/out/src/main.js +40 -11
  55. package/package.json +7 -4
  56. package/out/src/generator/classGenerator.js +0 -1513
  57. package/out/src/generator/clientGenerator.js +0 -1503
  58. package/out/src/generator/fhirDataTypes.json +0 -858
  59. package/out/src/generator/fhirInterfaces.json +0 -665
  60. package/out/src/generator/fhirResources.json +0 -157
  61. package/out/src/generator/interfaceGenerator.js +0 -1802
  62. package/out/src/generator/randomSupportGenerator.js +0 -1518
  63. package/out/src/generator/sdParser.js +0 -1073
  64. package/out/src/generator/validatorGenerator.js +0 -907
  65. /package/out/src/generator/{cacheConfig.js → core/cacheConfig.js} +0 -0
  66. /package/out/src/generator/{fetchUtils.js → core/fetchUtils.js} +0 -0
  67. /package/out/src/generator/{valueSetGenerator.js → emitters/valueset/valueSetGenerator.js} +0 -0
  68. /package/out/src/generator/{base-r4 → fhir/r4/base}/Bundle.json +0 -0
  69. /package/out/src/generator/{base-r4 → fhir/r4/base}/Composition.json +0 -0
  70. /package/out/src/generator/{base-r4 → fhir/r4/base}/Endpoint.json +0 -0
  71. /package/out/src/generator/{base-r4 → fhir/r4/base}/README.md +0 -0
  72. /package/out/src/generator/{base-r4 → fhir/r4/base}/Subscription.json +0 -0
  73. /package/out/src/generator/{base-r4 → fhir/r4/base}/ValueSet.json +0 -0
  74. /package/out/src/generator/{base-r4 → fhir/r4/base}/backport-subscription.json +0 -0
  75. /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 145 base R4 resource accessors
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
  ![CH Core 5.0.0](https://img.shields.io/endpoint?url=https://max-health-inc.github.io/BabelFHIR-TS/badges/badge-ch-core.json)
58
58
  ![DaVinci PAS 2.0.1](https://img.shields.io/endpoint?url=https://max-health-inc.github.io/BabelFHIR-TS/badges/badge-davinci-pas.json)
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 both src/generator/ (dev) and out/src/generator/ (compiled)
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
- 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: [{ title: 'Section', text: { status: 'generated', div: '<div xmlns="http://www.w3.org/1999/xhtml">Content</div>' } }] }`;
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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Core data types shared across the generator pipeline.
3
+ * Extracted from sdParser.ts for maintainability (issue #37).
4
+ */
5
+ export {};
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { logger } from "../logger.js";
4
- import fhirResourceNames from "./fhirResources.json" with { type: "json" };
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 (fhirResourceNames.includes(baseType)) {
85
+ if (ctx().resourceNames.includes(baseType)) {
86
86
  resourceTypes.set(profileName, baseType);
87
87
  }
88
88
  }