Skip to content

TS: Slice setters for max:* slices should accept arrays, not single elements #125

@ryukzak

Description

@ryukzak

Currently, slice setters like setOrganizationEntry() accept a single element and use setArraySlice() which replaces by discriminator match. For slices with max: * (unbounded), this means:

bundle
    .setOrganizationEntry({ resource: org1 })
    .setOrganizationEntry({ resource: org2 });
// Result: only org2 — the second call replaces the first

This is wrong for unbounded slices. The setter should accept an array:

// Desired API for max:* slices
bundle.setOrganizationEntry([
    { resource: org1 },
    { resource: org2 },
]);

The getter should also return an array for max:* slices.

For updating, the pattern should support spread:

bundle.setOrganizationEntry([
    ...bundle.getOrganizationEntry(),
    { resource: newOrg },
]);

Current behavior

  • setOrganizationEntry(entry) — replaces the single matched slice element (upsert by discriminator)
  • getOrganizationEntry() — returns the first matched element

Expected behavior

For slices with max: 1 (e.g. PatientEntry): current single-element API is correct.

For slices with max: * (e.g. OrganizationEntry):

  • setOrganizationEntry(entries[]) — replaces all matched slice elements with the provided array
  • getOrganizationEntry() — returns all matched elements as an array

Scope

  • Affects src/api/writer-generator/typescript/profile-slices.ts (setter/getter generation)
  • Needs to branch on sliceDef.array / max cardinality when generating the setter signature and implementation
  • Affects profile-helpers.ts — may need a setArraySliceAll / getArraySliceAll helper

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions