TS: Remove buildResource, fix profile type safety#126
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
buildResource<T>()helper — profilecreateResourcenow uses plain object literals (const resource: T = { ... })buildResourceexport fromprofile-helpers.tsReference<string /* Resource */>for family type references (e.g.Resource,DomainResource) in both base types and profiles, so narrower profile references likeReference<"Patient">are assignableBefore:
After:
Other fixes
tryPromoteChoiceto resolve reference targets viafieldTsTypeinstead oftsTypeFromIdentifier(was losing generic params on choice fields likemedicationReference)bundle-typeCodeSystem with missing"bundle"and"subscription-notification"codesCarePlanActprofile to reuse base ActmoodCodebinding (external NLM ValueSet unavailable)GdRelatedPersonto dropPersontargets frompatientreference (base R4 only allowsPatient)