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
Currently, slice setters like
setOrganizationEntry()accept a single element and usesetArraySlice()which replaces by discriminator match. For slices withmax: *(unbounded), this means:This is wrong for unbounded slices. The setter should accept an array:
The getter should also return an array for max:* slices.
For updating, the pattern should support spread:
Current behavior
setOrganizationEntry(entry)— replaces the single matched slice element (upsert by discriminator)getOrganizationEntry()— returns the first matched elementExpected 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 arraygetOrganizationEntry()— returns all matched elements as an arrayScope
src/api/writer-generator/typescript/profile-slices.ts(setter/getter generation)sliceDef.array/ max cardinality when generating the setter signature and implementationprofile-helpers.ts— may need asetArraySliceAll/getArraySliceAllhelper