babelfhir-ts 1.5.13 → 1.5.15

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.
@@ -416,7 +416,7 @@ function generateBundleParser(clientDir, resourceTypes) {
416
416
  const unionType = profiles.map(p => `GeneratedTypes.${p}`).join(' | ');
417
417
  return ` case '${baseType}':
418
418
  return entries
419
- .filter((e): e is BundleEntry<${unionType}> => e.resource?.resourceType === '${baseType}')
419
+ .filter((e): e is BundleEntry<${unionType}> => (e.resource as { resourceType?: string } | undefined)?.resourceType === '${baseType}')
420
420
  .map(e => e.resource!) as T[];`;
421
421
  })
422
422
  .join("\n");
@@ -463,7 +463,7 @@ export class BundleParser {
463
463
  /**
464
464
  * Get resources of a specific type
465
465
  */
466
- getResourcesByType<T extends FhirResource>(resourceType: T['resourceType']): T[] {
466
+ getResourcesByType<T extends FhirResource>(resourceType: string): T[] {
467
467
  const entries = this.getAllEntries();
468
468
  switch (resourceType) {
469
469
  ${parseByTypeCases}
@@ -475,7 +475,7 @@ ${parseByTypeCases}
475
475
  /**
476
476
  * Get the first resource of a specific type
477
477
  */
478
- getFirstResourceByType<T extends FhirResource>(resourceType: T['resourceType']): T | undefined {
478
+ getFirstResourceByType<T extends FhirResource>(resourceType: string): T | undefined {
479
479
  return this.getResourcesByType<T>(resourceType)[0];
480
480
  }
481
481
 
@@ -498,9 +498,9 @@ ${parseByTypeCases}
498
498
  /**
499
499
  * Get entries of a specific resource type
500
500
  */
501
- getEntriesByType<T extends FhirResource>(resourceType: T['resourceType']): BundleEntry<T>[] {
501
+ getEntriesByType<T extends FhirResource>(resourceType: string): BundleEntry<T>[] {
502
502
  return this.getAllEntries().filter(
503
- (e): e is BundleEntry<T> => e.resource?.resourceType === resourceType
503
+ (e): e is BundleEntry<T> => (e.resource as { resourceType?: string } | undefined)?.resourceType === resourceType
504
504
  );
505
505
  }
506
506
 
@@ -539,7 +539,7 @@ ${parseByTypeCases}
539
539
  const grouped = new Map<string, FhirResource[]>();
540
540
 
541
541
  for (const resource of this.getAllResources()) {
542
- const type = resource.resourceType;
542
+ const type = (resource as { resourceType: string }).resourceType;
543
543
  if (!grouped.has(type)) {
544
544
  grouped.set(type, []);
545
545
  }
@@ -456,9 +456,9 @@ function generatePatternCodingValidation(slice, relPath, errorPath, sliceLabel,
456
456
  if (isNestedInOptionalSlice) {
457
457
  out.push(`
458
458
  // Required slice validation for ${relPath}:${sliceLabel} (nested in array: ${arrayParentPath}, parent slice is optional)
459
- if (resource.${arrayParentPath} && Array.isArray(resource.${arrayParentPath}) && resource.${arrayParentPath}.length > 0) {
459
+ if ((resource as any).${arrayParentPath} && Array.isArray((resource as any).${arrayParentPath}) && (resource as any).${arrayParentPath}.length > 0) {
460
460
  const ${varName}Elements: Array<{ system?: string; code?: string }> = [];
461
- for (const item of resource.${arrayParentPath}) {
461
+ for (const item of (resource as any).${arrayParentPath}) {
462
462
  const nestedArray = item.${optionalPath};
463
463
  if (nestedArray && Array.isArray(nestedArray)) {
464
464
  for (const coding of nestedArray) { if (${matchExpr.replace(/item\./g, 'coding.')}) ${varName}Elements.push(coding); }
@@ -473,9 +473,9 @@ function generatePatternCodingValidation(slice, relPath, errorPath, sliceLabel,
473
473
  out.push(`
474
474
  // Required slice validation for ${relPath}:${sliceLabel} (nested in array: ${arrayParentPath})
475
475
  // Only check when parent array exists — parent absence is reported by separate required-field checks
476
- if (resource.${arrayParentPath} && Array.isArray(resource.${arrayParentPath})) {
476
+ if ((resource as any).${arrayParentPath} && Array.isArray((resource as any).${arrayParentPath})) {
477
477
  const ${varName}Elements: Array<{ system?: string; code?: string }> = [];
478
- for (const item of resource.${arrayParentPath}) {
478
+ for (const item of (resource as any).${arrayParentPath}) {
479
479
  const nestedArray = item.${optionalPath};
480
480
  if (nestedArray && Array.isArray(nestedArray)) {
481
481
  for (const coding of nestedArray) { if (${matchExpr.replace(/item\./g, 'coding.')}) ${varName}Elements.push(coding); }
@@ -496,9 +496,9 @@ function generatePatternCodingValidation(slice, relPath, errorPath, sliceLabel,
496
496
  out.push(`
497
497
  // Required slice validation for ${relPath}:${sliceLabel}
498
498
  // Only check nested slice if parent field exists (parent absence is already reported separately)
499
- if (resource.${parentPath}) {
500
- if (resource.${optionalPath} && Array.isArray(resource.${optionalPath})) {
501
- const ${varName}Elements = (resource.${optionalPath} as Array<{ system?: string; code?: string }>).filter((item) =>
499
+ if ((resource as any).${parentPath}) {
500
+ if ((resource as any).${optionalPath} && Array.isArray((resource as any).${optionalPath})) {
501
+ const ${varName}Elements = ((resource as any).${optionalPath} as Array<{ system?: string; code?: string }>).filter((item) =>
502
502
  ${matchExpr}
503
503
  );
504
504
  if (${varName}Elements.length < ${min}) {
@@ -512,8 +512,8 @@ function generatePatternCodingValidation(slice, relPath, errorPath, sliceLabel,
512
512
  else {
513
513
  out.push(`
514
514
  // Required slice validation for ${relPath}:${sliceLabel}
515
- if (resource.${optionalPath} && Array.isArray(resource.${optionalPath})) {
516
- const ${varName}Elements = (resource.${optionalPath} as Array<{ system?: string; code?: string }>).filter((item) =>
515
+ if ((resource as any).${optionalPath} && Array.isArray((resource as any).${optionalPath})) {
516
+ const ${varName}Elements = ((resource as any).${optionalPath} as Array<{ system?: string; code?: string }>).filter((item) =>
517
517
  ${matchExpr}
518
518
  );
519
519
  if (${varName}Elements.length < ${min}) {
@@ -627,8 +627,8 @@ function generateProfiledChildDelegation(slice, relPath, childFieldsWithFixedVal
627
627
  out.push(`
628
628
  // Profiled sub-resource delegation for ${relPath}:${sliceLabel}.${childRelPath} → ${delegateName}
629
629
  {
630
- if (resource.${arrayParentPath} && Array.isArray(resource.${arrayParentPath})) {
631
- for (const _parentItem of resource.${arrayParentPath}) {
630
+ if ((resource as any).${arrayParentPath} && Array.isArray((resource as any).${arrayParentPath})) {
631
+ for (const _parentItem of (resource as any).${arrayParentPath}) {
632
632
  const _pi: any = _parentItem;
633
633
  const _nestedArr = _pi?.${remainingPath};
634
634
  if (_nestedArr && Array.isArray(_nestedArr)) {
@@ -775,9 +775,9 @@ function generateProfileDiscriminatorValidation(slice, relPath, errorPath, slice
775
775
  const { resourceType, profileUrls } = match;
776
776
  const max = typeof slice.max === 'number' && slice.max !== Infinity ? slice.max : undefined;
777
777
  const parentPath = relPath.includes('.') ? relPath.split('.').slice(0, -1).join('.') : '';
778
- const accessor = parentPath ? `(resource as any)?.${parentPath.replace(/\./g, '?.')}` : `resource.${relPath}`;
778
+ const accessor = parentPath ? `(resource as any)?.${parentPath.replace(/\./g, '?.')}` : `(resource as any).${relPath}`;
779
779
  // For top-level entry slices, access resource.entry directly
780
- const arrayAccessor = relPath === 'entry' || !relPath.includes('.') ? `resource.${relPath}` : accessor;
780
+ const arrayAccessor = relPath === 'entry' || !relPath.includes('.') ? `(resource as any).${relPath}` : accessor;
781
781
  // Resolve profiled validator for delegation
782
782
  let delegateInterfaceName;
783
783
  if (ctx.profileUrlToName && ctx.validatorImports) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babelfhir-ts",
3
- "version": "1.5.13",
3
+ "version": "1.5.15",
4
4
  "description": "BabelFHIR-TS: generate TypeScript interfaces, validators, and helper classes from FHIR R4/R4B/R5 StructureDefinitions (profiles) directly inside package archives.",
5
5
  "type": "module",
6
6
  "main": "out/src/main.js",