Skip to content

TS: Remove buildResource, fix profile type safety#126

Merged
ryukzak merged 9 commits intomainfrom
fix-profile-type-safety
Apr 3, 2026
Merged

TS: Remove buildResource, fix profile type safety#126
ryukzak merged 9 commits intomainfrom
fix-profile-type-safety

Conversation

@ryukzak
Copy link
Copy Markdown
Collaborator

@ryukzak ryukzak commented Apr 3, 2026

Summary

  • Remove buildResource<T>() helper — profile createResource now uses plain object literals (const resource: T = { ... })
  • Remove buildResource export from profile-helpers.ts
  • Generate Reference<string /* Resource */> for family type references (e.g. Resource, DomainResource) in both base types and profiles, so narrower profile references like Reference<"Patient"> are assignable

Before:

// profile-helpers.ts
export const buildResource = <T>(obj: object): T => obj as unknown as T;

// profile createResource
const resource = buildResource<Observation>({ resourceType: "Observation", ... })

// base type
subject?: Reference<"Resource">;

After:

// profile createResource
const resource: Observation = { resourceType: "Observation", ... }

// base type
subject?: Reference<string /* Resource */>;

Other fixes

  • Fix tryPromoteChoice to resolve reference targets via fieldTsType instead of tsTypeFromIdentifier (was losing generic params on choice fields like medicationReference)
  • Align extension setter value types with extension profile factory params
  • Patch CCDA bundle-type CodeSystem with missing "bundle" and "subscription-notification" codes
  • Patch CCDA CarePlanAct profile to reuse base Act moodCode binding (external NLM ValueSet unavailable)
  • Patch Norge GdRelatedPerson to drop Person targets from patient reference (base R4 only allows Patient)

ryukzak added 9 commits April 3, 2026 12:04
…e createResource

Replace `buildResource<T>({...})` calls with `const resource: T = {...}` in
generated profile classes. Remove the now-unused `buildResource` export from
profile-helpers.ts.
The bundle-type CodeSystem across FHIR packages is missing "bundle" and
"subscription-notification" codes used by BatchBundle and
SubscriptionNotificationBundle profiles. Patch all instances at load time
via preprocessPackage.
The CarePlanAct profile binds moodCode to an external NLM ValueSet
(2.16.840.1.113762.1.4.1267.37) that isn't available in any loaded
package, causing the enum to fall back to string. Reuse the base Act
binding (v3-xDocumentActMood) instead.
The GdRelatedPerson profile widens RelatedPerson.patient to include
Person targets, but the base R4 type only allows Patient. Replace
Person profile references with Patient to match the base constraint.
… base types

When a reference target is a family type (e.g. Resource, DomainResource),
generate Reference<string /* Resource */> instead of Reference<"Resource">.
This makes narrower profile references like Reference<"Patient"> assignable
to the base type field.

Also fix tryPromoteChoice to resolve reference targets for promoted choice
fields via fieldTsType instead of tsTypeFromIdentifier, and align extension
setter value types with the extension profile's factory params.
@ryukzak ryukzak merged commit 57eb30c into main Apr 3, 2026
31 checks passed
@ryukzak ryukzak deleted the fix-profile-type-safety branch April 3, 2026 13:52
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