Skip to content

TS: Fix profile apply/create, fix slice match arrays, rewrite example tests - #121

Merged
ryukzak merged 6 commits into
mainfrom
fix-profile-class-issues
Apr 2, 2026
Merged

TS: Fix profile apply/create, fix slice match arrays, rewrite example tests#121
ryukzak merged 6 commits into
mainfrom
fix-profile-class-issues

Conversation

@ryukzak

@ryukzak ryukzak commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Profile class fixes

  • apply() now sets fixed-value fields and auto-populates discriminator-only slice stubs, matching create() behavior
  • apply() no longer redundantly assigns resourceType
  • Only auto-populate slices where the discriminator stub is the complete content (e.g. category VSCat). Skip type discriminators (Bundle entry) and slices with required fields beyond match keys
  • Fixed-value fields get a getter but no setter
  • create() split into createResource + apply for readability
  • Extension apply() sets URL, uses upsert for single extensions

Slice match array fixes

Example test rewrite

  • Restructure all profile test files with demo-first pattern:
    • Demo tests on top — create (with validation flow), apply, from/read
    • Regression tests below — concise, focused on edge cases
  • Remove all as any / as never / as unknown casts
  • Add resource snapshots for fully populated profiles (bodyweight, BP, US Core Patient)
  • Add example test structure guidelines to CLAUDE.md

Before/After

apply() — now auto-populates fixed fields and discriminator-only slices:

// Before
static apply (resource: Observation) {
    ensureProfile(resource, canonicalUrl);
    Object.assign(resource, { resourceType: "Observation" })
    return new Profile(resource);
}

// After
static apply (resource: Observation) {
    ensureProfile(resource, canonicalUrl);
    Object.assign(resource, {
        code: {"coding":[{"code":"29463-7","system":"http://loinc.org"}]},
    })
    resource.category = ensureSliceDefaults(
        [...(resource.category ?? [])],
        Profile.VSCatSliceMatch,
    );
    return new Profile(resource);
}

Slice auto-population — only for discriminator-complete slices:

// category VSCat: auto-populated (discriminator IS the content)
resource.category = ensureSliceDefaults([...], VSCatSliceMatch);

// Bundle entry: NOT auto-populated (user must provide the Patient resource)
// BP component: auto-populated (valueQuantity is must-support, not required)

Slice match data — coding now correctly wrapped as array everywhere:

// Before (both fhirschema and computeMatchFromSchema paths)
{"coding":{"code":"vital-signs","system":"..."}}
{"code":{"coding":{"code":"8480-6","system":"http://loinc.org"}}}

// After
{"coding":[{"code":"vital-signs","system":"..."}]}
{"code":{"coding":[{"code":"8480-6","system":"http://loinc.org"}]}}

@ryukzak
ryukzak force-pushed the fix-profile-class-issues branch from 9f0af81 to 75a53b9 Compare April 1, 2026 13:57
@ryukzak ryukzak changed the title TS: Fix profile class apply URL, fixed-field setters, extension upsert TS: Fix profile class issues and rewrite example tests Apr 1, 2026
@ryukzak
ryukzak force-pushed the fix-profile-class-issues branch from 75a53b9 to 06938d0 Compare April 1, 2026 14:08
@ryukzak ryukzak changed the title TS: Fix profile class issues and rewrite example tests TS: Fix profile apply(), update fhirschema, rewrite example tests Apr 1, 2026
@ryukzak
ryukzak force-pushed the fix-profile-class-issues branch from 06938d0 to d51c12b Compare April 2, 2026 08:08
ryukzak added 5 commits April 2, 2026 12:04
… wrapping

- apply() sets fixed-value fields and auto-populates discriminator-only
  slice stubs, matching create() behavior
- apply() skips redundant resourceType assignment
- Only auto-populate slices where the stub is the complete content
  (e.g. category VSCat). Skip type discriminators (Bundle entry) and
  slices with required fields beyond match keys (BP component)
- Fix computeMatchFromSchema to wrap sliced elements in arrays
  (e.g. component code.coding), matching the fhirschema 0.0.10 fix
- Fixed-value fields get a getter but no setter
- create() split into createResource + apply for readability
- Extension apply() sets URL, uses upsert for single extensions
Slice match values now correctly wrap array elements (e.g. coding
is Coding[] not a plain object).
- Three demos on top: create (with validation flow), apply, from/read
- Concise regression tests below for edge cases
- Remove all as-any / as-never / as-unknown casts
- Add resource snapshots for fully populated profiles
@ryukzak
ryukzak force-pushed the fix-profile-class-issues branch from d51c12b to a3bf7f2 Compare April 2, 2026 10:04
Adds gender, birthDate, and toMatchSnapshot() to the patient demo test
to capture a fully valid US Core Patient with extensions.
@ryukzak ryukzak changed the title TS: Fix profile apply(), update fhirschema, rewrite example tests TS: Fix profile apply/create, fix slice match arrays, rewrite example tests Apr 2, 2026
@ryukzak
ryukzak merged commit a6ef301 into main Apr 2, 2026
31 checks passed
@ryukzak
ryukzak deleted the fix-profile-class-issues branch April 2, 2026 11:27
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