babelfhir-ts 1.5.12 → 1.5.14

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
  }
@@ -451,10 +451,18 @@ export function handleFlatField(args) {
451
451
  addTypeImport(fieldType);
452
452
  }
453
453
  }
454
+ // Capture primitiveness BEFORE applyBindingConstraint rewrites CodeableConcept
455
+ // fields into an intersection string like `CodeableConcept & { coding: Array<{
456
+ // code: X; system: "..." }> }`. That string contains quotes, so the post-
457
+ // constraint isPrimitiveType() heuristic (/['"]/ in createRules) misfires and
458
+ // the code-union path below would clobber the CodeableConcept with a bare code
459
+ // union (regression from bae9e64). Only genuine primitive `code` fields should
460
+ // take that path, so gate it on the pre-constraint type.
461
+ const isPrimitiveCodeField = isPrimitiveType(fieldType);
454
462
  // Apply ValueSet binding constraints for CodeableConcept types
455
463
  fieldType = applyBindingConstraint(fieldType, field, fields);
456
464
  // Apply ValueSet binding constraints for primitive code fields (generates union literal type)
457
- if (isPrimitiveType(fieldType) && hasNarrowingBinding && field.binding?.codes) {
465
+ if (isPrimitiveCodeField && hasNarrowingBinding && field.binding?.codes) {
458
466
  const vsUri = field.binding.uri?.split('|')[0];
459
467
  const vs = vsUri && valueSets ? (valueSets.get(vsUri) || valueSets.get(field.binding.uri)) : undefined;
460
468
  if (vs && vs.isSmall && vs.concepts.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babelfhir-ts",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
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",