Skip to content

TS: Enhance profile code generation with factory methods, extensions, and pattern values#81

Merged
ryukzak merged 16 commits intomainfrom
wip5
Feb 26, 2026
Merged

TS: Enhance profile code generation with factory methods, extensions, and pattern values#81
ryukzak merged 16 commits intomainfrom
wip5

Conversation

@ryukzak
Copy link
Collaborator

@ryukzak ryukzak commented Feb 26, 2026

  • Add static factory methods (from, createResource, create) and getter/setter methods to generated profile classes, enabling fluent construction and manipulation of profiled FHIR resources
  • Add support for generating extension profile classes (e.g., birthPlace, nationality) with proper value type resolution via slicing fallback
  • Capture pattern/fixed values from FHIR StructureDefinitions into TypeSchema fields, enabling auto-population in factory methods
  • Fix cross-version type resolution fallback in TypeSchemaIndex.resolveByUrl and improve extension deduplication to prefer canonical URLs
  • Use identifier.name instead of URL-extracted names for profile class and module naming

Add PatternValue type that preserves the kind (pattern vs fixed) alongside
the type and value from FHIR element definitions.
…classes

Profile classes now generate three static methods:
- from(resource) — wraps an existing resource in the profile class
- createResource(args) — creates a plain resource with auto-set fields
  (resourceType for resources, url from patternValue for extensions)
  and required fields as a typed params object
- create(args) — shorthand that returns the resource wrapped in the profile

Required fields are collected into a separate exported Params type.
Extension profiles auto-set their url and accept required values as params.
Resource profiles auto-set resourceType and accept required fields.

Also adds R4 extension profile examples and tests covering all four
extension profiles (patient-birthPlace, patient-birthTime,
patient-nationality, humanname-own-prefix).
…traction

Profile classes now generate getter/setter methods for required fields
(e.g., getValueAddress/setValueAddress for extension profiles,
getStatus/setStatus for resource profiles). Setters return `this` for
chaining.

Fix transformer to extract sub-extension URLs and value types from
slicing data when the extensions object entries lack a url field. This
enables complex extension profiles like patient-nationality to generate
proper getter/setter methods for their sub-extensions (code, period).
Derive profile class names and file names from schema.identifier.name
instead of extractNameFromCanonical(url). This produces cleaner names
for extensions by dropping redundant prefixes (e.g., birthPlaceProfile
instead of patient_birthPlaceProfile).
- Replace non-null assertion with null guard for choice field access
- Extract generateExtensionSetterMethods to reduce cognitive complexity
- Use resolveFieldTsType for factory params to include enum/reference types
- Add casts in getter/setter for narrowed profile types
- Use 'as unknown as' in createResource for cross-version compatibility
- Wrap pattern values in arrays for array fields
- Cast extension value fields for cross-version type compatibility
- Add fallback in resolveByUrl to search across all packages when type
  is not found in the specified package (fixes CodeableReference imports)
- Change extension dedup key from path|name|url to path|name, preferring
  entries with full canonical URLs to prevent duplicate method generation
- Fix profile.test.ts import to use new naming (Observation_observation_bodyweight)
- Regenerate profile files with corrected types and casts
Add rollup override to force >=4.59.0 for all transitive dependencies,
resolving the arbitrary file write via path traversal vulnerability.
@ryukzak ryukzak merged commit 62be08f into main Feb 26, 2026
29 checks passed
@ryukzak ryukzak deleted the wip5 branch February 26, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant