Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
506e609
feat: Include fixed discriminator values in slice flat types
ryukzak Apr 3, 2026
fb94f3e
test: Update snapshots for slice flat discriminator types
ryukzak Apr 3, 2026
b294a73
chore: Regenerate examples for slice flat discriminator types
ryukzak Apr 3, 2026
7d3ca4c
test: Add examples for slice flat type discriminator values
ryukzak Apr 3, 2026
0643f90
ref: Split slice types into SliceInput (setter) and SliceFlat (docume…
ryukzak Apr 3, 2026
d9fc209
test: Update snapshots for SliceInput/SliceFlat split
ryukzak Apr 3, 2026
332e7b2
chore: Regenerate examples and update tests for SliceInput/SliceFlat …
ryukzak Apr 3, 2026
14905f5
ref: Rename SliceInput to SliceFlatInput
ryukzak Apr 6, 2026
25a64ea
test: Update snapshots for SliceFlatInput rename
ryukzak Apr 6, 2026
832ac02
chore: Regenerate examples for SliceFlatInput rename
ryukzak Apr 6, 2026
c9ae07e
fix: Add blank line between generated slice type pairs
ryukzak Apr 6, 2026
fdc19ed
chore: Regenerate examples
ryukzak Apr 6, 2026
9070abb
fix: Getter returns SliceFlat (with discriminator types) instead of S…
ryukzak Apr 6, 2026
fb4e868
test: Update snapshots for SliceFlat getter return
ryukzak Apr 6, 2026
34c5d93
chore: Update example tests for SliceFlat getter return
ryukzak Apr 6, 2026
3db477b
fix: Split long SliceFlat type lines using curlyBlock
ryukzak Apr 6, 2026
fb224fd
test: Update snapshots for multiline SliceFlat
ryukzak Apr 6, 2026
e96b635
chore: Regenerate examples for multiline SliceFlat
ryukzak Apr 6, 2026
0540757
fix: Split long SliceMatch static fields across multiple lines
ryukzak Apr 6, 2026
0ceb98d
chore: Regenerate snapshots and examples for multiline SliceMatch
ryukzak Apr 6, 2026
97823bf
test: Use SliceFlatInput and SliceFlat types explicitly in demo tests
ryukzak Apr 6, 2026
3223d42
fix: Flat getter returns full element with discriminators instead of …
ryukzak Apr 6, 2026
9e23bab
chore: Update snapshots and tests for flat getter with discriminators
ryukzak Apr 6, 2026
a2a2c02
test: Use toEqual for flat slice getter assertions in demo tests
ryukzak Apr 6, 2026
52d9732
ref: Rename SliceFlat to SliceFlatFull
ryukzak Apr 6, 2026
e3638b7
chore: Update snapshots, examples and tests for SliceFlatFull rename
ryukzak Apr 6, 2026
18cd01f
ref: Rename SliceFlatInput to SliceFlat, SliceFlatFull to SliceFlatAll
ryukzak Apr 6, 2026
f7a41b8
chore: Update snapshots, examples and tests for SliceFlat/SliceFlatAl…
ryukzak Apr 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type { Quantity } from "../../hl7-fhir-r4-core/Quantity";
import type { Reference } from "../../hl7-fhir-r4-core/Reference";

export type Observation_bodyweight_Category_VSCatSliceFlat = Omit<CodeableConcept, "coding">;
export type Observation_bodyweight_Category_VSCatSliceFlatAll = Observation_bodyweight_Category_VSCatSliceFlat & {
readonly coding: [{ code: "vital-signs"; system: "http://terminology.hl7.org/CodeSystem/observation-category" }];
}

import {
ensureProfile,
Expand All @@ -17,7 +20,6 @@ import {
setArraySlice,
getArraySlice,
ensureSliceDefaults,
stripMatchKeys,
validateRequired,
validateExcluded,
validateFixedValue,
Expand All @@ -38,7 +40,9 @@ export type observation_bodyweightProfileRaw = {
export class observation_bodyweightProfile {
static readonly canonicalUrl = "http://hl7.org/fhir/StructureDefinition/bodyweight";

private static readonly VSCatSliceMatch: Record<string, unknown> = {"coding":[{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}]};
private static readonly VSCatSliceMatch: Record<string, unknown> = {
"coding": [{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}],
}

private resource: Observation;

Expand Down Expand Up @@ -166,15 +170,15 @@ export class observation_bodyweightProfile {
return this
}

public getVSCat(mode: 'flat'): Observation_bodyweight_Category_VSCatSliceFlat | undefined;
public getVSCat(mode: 'flat'): Observation_bodyweight_Category_VSCatSliceFlatAll | undefined;
public getVSCat(mode: 'raw'): CodeableConcept | undefined;
public getVSCat(): Observation_bodyweight_Category_VSCatSliceFlat | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_bodyweight_Category_VSCatSliceFlat | CodeableConcept | undefined {
public getVSCat(): Observation_bodyweight_Category_VSCatSliceFlatAll | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_bodyweight_Category_VSCatSliceFlatAll | CodeableConcept | undefined {
const match = observation_bodyweightProfile.VSCatSliceMatch
const item = getArraySlice(this.resource.category, match)
if (!item) return undefined
if (mode === 'raw') return item
return stripMatchKeys<Observation_bodyweight_Category_VSCatSliceFlat>(item, ["coding"])
return item as unknown as Observation_bodyweight_Category_VSCatSliceFlatAll
}

// Validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import type { Quantity } from "../../hl7-fhir-r4-core/Quantity";
import type { Reference } from "../../hl7-fhir-r4-core/Reference";

export type Observation_bp_Category_VSCatSliceFlat = Omit<CodeableConcept, "coding">;
export type Observation_bp_Category_VSCatSliceFlatAll = Observation_bp_Category_VSCatSliceFlat & {
readonly coding: [{ code: "vital-signs"; system: "http://terminology.hl7.org/CodeSystem/observation-category" }];
}

export type Observation_bp_Component_SystolicBPSliceFlat = Omit<ObservationComponent, "code" | "value" | "valueQuantity" | "valueCodeableConcept" | "valueString" | "valueBoolean" | "valueInteger" | "valueRange" | "valueRatio" | "valueSampledData" | "valueTime" | "valueDateTime" | "valuePeriod"> & Quantity;
export type Observation_bp_Component_SystolicBPSliceFlatAll = Observation_bp_Component_SystolicBPSliceFlat;

export type Observation_bp_Component_DiastolicBPSliceFlat = Omit<ObservationComponent, "code" | "value" | "valueQuantity" | "valueCodeableConcept" | "valueString" | "valueBoolean" | "valueInteger" | "valueRange" | "valueRatio" | "valueSampledData" | "valueTime" | "valueDateTime" | "valuePeriod"> & Quantity;
export type Observation_bp_Component_DiastolicBPSliceFlatAll = Observation_bp_Component_DiastolicBPSliceFlat;

import {
ensureProfile,
Expand All @@ -19,7 +26,6 @@ import {
setArraySlice,
getArraySlice,
ensureSliceDefaults,
stripMatchKeys,
wrapSliceChoice,
unwrapSliceChoice,
validateRequired,
Expand All @@ -43,9 +49,15 @@ export type observation_bpProfileRaw = {
export class observation_bpProfile {
static readonly canonicalUrl = "http://hl7.org/fhir/StructureDefinition/bp";

private static readonly VSCatSliceMatch: Record<string, unknown> = {"coding":[{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}]};
private static readonly SystolicBPSliceMatch: Record<string, unknown> = {"code":{"coding":[{"code":"8480-6","system":"http://loinc.org"}]}};
private static readonly DiastolicBPSliceMatch: Record<string, unknown> = {"code":{"coding":[{"code":"8462-4","system":"http://loinc.org"}]}};
private static readonly VSCatSliceMatch: Record<string, unknown> = {
"coding": [{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}],
}
private static readonly SystolicBPSliceMatch: Record<string, unknown> = {
"code": {"coding":[{"code":"8480-6","system":"http://loinc.org"}]},
}
private static readonly DiastolicBPSliceMatch: Record<string, unknown> = {
"code": {"coding":[{"code":"8462-4","system":"http://loinc.org"}]},
}

private resource: Observation;

Expand Down Expand Up @@ -217,37 +229,37 @@ export class observation_bpProfile {
return this
}

public getVSCat(mode: 'flat'): Observation_bp_Category_VSCatSliceFlat | undefined;
public getVSCat(mode: 'flat'): Observation_bp_Category_VSCatSliceFlatAll | undefined;
public getVSCat(mode: 'raw'): CodeableConcept | undefined;
public getVSCat(): Observation_bp_Category_VSCatSliceFlat | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Category_VSCatSliceFlat | CodeableConcept | undefined {
public getVSCat(): Observation_bp_Category_VSCatSliceFlatAll | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Category_VSCatSliceFlatAll | CodeableConcept | undefined {
const match = observation_bpProfile.VSCatSliceMatch
const item = getArraySlice(this.resource.category, match)
if (!item) return undefined
if (mode === 'raw') return item
return stripMatchKeys<Observation_bp_Category_VSCatSliceFlat>(item, ["coding"])
return item as unknown as Observation_bp_Category_VSCatSliceFlatAll
}

public getSystolicBP(mode: 'flat'): Observation_bp_Component_SystolicBPSliceFlat | undefined;
public getSystolicBP(mode: 'flat'): Observation_bp_Component_SystolicBPSliceFlatAll | undefined;
public getSystolicBP(mode: 'raw'): ObservationComponent | undefined;
public getSystolicBP(): Observation_bp_Component_SystolicBPSliceFlat | undefined;
public getSystolicBP (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Component_SystolicBPSliceFlat | ObservationComponent | undefined {
public getSystolicBP(): Observation_bp_Component_SystolicBPSliceFlatAll | undefined;
public getSystolicBP (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Component_SystolicBPSliceFlatAll | ObservationComponent | undefined {
const match = observation_bpProfile.SystolicBPSliceMatch
const item = getArraySlice(this.resource.component, match)
if (!item) return undefined
if (mode === 'raw') return item
return unwrapSliceChoice<Observation_bp_Component_SystolicBPSliceFlat>(item, ["code"], "valueQuantity")
return unwrapSliceChoice<Observation_bp_Component_SystolicBPSliceFlatAll>(item, ["code"], "valueQuantity")
}

public getDiastolicBP(mode: 'flat'): Observation_bp_Component_DiastolicBPSliceFlat | undefined;
public getDiastolicBP(mode: 'flat'): Observation_bp_Component_DiastolicBPSliceFlatAll | undefined;
public getDiastolicBP(mode: 'raw'): ObservationComponent | undefined;
public getDiastolicBP(): Observation_bp_Component_DiastolicBPSliceFlat | undefined;
public getDiastolicBP (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Component_DiastolicBPSliceFlat | ObservationComponent | undefined {
public getDiastolicBP(): Observation_bp_Component_DiastolicBPSliceFlatAll | undefined;
public getDiastolicBP (mode: 'flat' | 'raw' = 'flat'): Observation_bp_Component_DiastolicBPSliceFlatAll | ObservationComponent | undefined {
const match = observation_bpProfile.DiastolicBPSliceMatch
const item = getArraySlice(this.resource.component, match)
if (!item) return undefined
if (mode === 'raw') return item
return unwrapSliceChoice<Observation_bp_Component_DiastolicBPSliceFlat>(item, ["code"], "valueQuantity")
return unwrapSliceChoice<Observation_bp_Component_DiastolicBPSliceFlatAll>(item, ["code"], "valueQuantity")
}

// Validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { Period } from "../../hl7-fhir-r4-core/Period";
import type { Reference } from "../../hl7-fhir-r4-core/Reference";

export type Observation_vitalsigns_Category_VSCatSliceFlat = Omit<CodeableConcept, "coding">;
export type Observation_vitalsigns_Category_VSCatSliceFlatAll = Observation_vitalsigns_Category_VSCatSliceFlat & {
readonly coding: [{ code: "vital-signs"; system: "http://terminology.hl7.org/CodeSystem/observation-category" }];
}

import {
ensureProfile,
Expand All @@ -16,7 +19,6 @@ import {
setArraySlice,
getArraySlice,
ensureSliceDefaults,
stripMatchKeys,
validateRequired,
validateExcluded,
validateFixedValue,
Expand All @@ -38,7 +40,9 @@ export type observation_vitalsignsProfileRaw = {
export class observation_vitalsignsProfile {
static readonly canonicalUrl = "http://hl7.org/fhir/StructureDefinition/vitalsigns";

private static readonly VSCatSliceMatch: Record<string, unknown> = {"coding":[{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}]};
private static readonly VSCatSliceMatch: Record<string, unknown> = {
"coding": [{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}],
}

private resource: Observation;

Expand Down Expand Up @@ -159,15 +163,15 @@ export class observation_vitalsignsProfile {
return this
}

public getVSCat(mode: 'flat'): Observation_vitalsigns_Category_VSCatSliceFlat | undefined;
public getVSCat(mode: 'flat'): Observation_vitalsigns_Category_VSCatSliceFlatAll | undefined;
public getVSCat(mode: 'raw'): CodeableConcept | undefined;
public getVSCat(): Observation_vitalsigns_Category_VSCatSliceFlat | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_vitalsigns_Category_VSCatSliceFlat | CodeableConcept | undefined {
public getVSCat(): Observation_vitalsigns_Category_VSCatSliceFlatAll | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_vitalsigns_Category_VSCatSliceFlatAll | CodeableConcept | undefined {
const match = observation_vitalsignsProfile.VSCatSliceMatch
const item = getArraySlice(this.resource.category, match)
if (!item) return undefined
if (mode === 'raw') return item
return stripMatchKeys<Observation_vitalsigns_Category_VSCatSliceFlat>(item, ["coding"])
return item as unknown as Observation_vitalsigns_Category_VSCatSliceFlatAll
}

// Validation
Expand Down
35 changes: 22 additions & 13 deletions examples/typescript-r4/profile-bodyweight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import { describe, expect, test } from "bun:test";
import type { Observation } from "./fhir-types/hl7-fhir-r4-core/Observation";
import { observation_bodyweightProfile as bodyweightProfile } from "./fhir-types/hl7-fhir-r4-core/profiles/Observation_observation_bodyweight";
import {
observation_bodyweightProfile as bodyweightProfile,
type Observation_bodyweight_Category_VSCatSliceFlat as VSCatFlat,
type Observation_bodyweight_Category_VSCatSliceFlatAll as VSCatFlatAll,
} from "./fhir-types/hl7-fhir-r4-core/profiles/Observation_observation_bodyweight";

describe("demo: create a bodyweight observation", () => {
test("build a valid bodyweight resource step by step", () => {
Expand Down Expand Up @@ -95,13 +99,12 @@ describe("demo: read a bodyweight observation from JSON", () => {
// Code is a fixed value — auto-set by the profile, read-only (no setter)
expect(profile.getCode()!.coding![0]!.code).toBe("29463-7");

// Slice accessor strips discriminator keys (coding) by default — only user data remains
expect(profile.getVSCat()).toEqual({ text: "Vital Signs" });
// Use "raw" mode to see the full element including discriminator
expect(profile.getVSCat("raw")!.coding).toEqual([
{ code: "vital-signs", system: "http://terminology.hl7.org/CodeSystem/observation-category" },
]);
expect(profile.getVSCat("raw")!.text).toBe("Vital Signs");
// Slice getter returns SliceFlat — includes both user data and discriminator values
const vsCat = profile.getVSCat()!;
expect(vsCat).toEqual({
text: "Vital Signs",
coding: [{ code: "vital-signs", system: "http://terminology.hl7.org/CodeSystem/observation-category" }],
});
});
});

Expand All @@ -123,13 +126,19 @@ describe("factory method equivalence", () => {
});

describe("slice accessors", () => {
test("setVSCat merges discriminator and strips it in flat mode", () => {
test("setVSCat accepts SliceFlatInput, getVSCat returns SliceFlat", () => {
const profile = bodyweightProfile.create({ status: "final", subject: { reference: "Patient/pt-1" } });
profile.setVSCat({ text: "Vital Signs" });

expect(profile.getVSCat()).toEqual({ text: "Vital Signs" });
expect(profile.getVSCat("raw")!.coding).toBeDefined();
expect(profile.getVSCat("raw")!.text).toBe("Vital Signs");
// Setter accepts SliceFlatInput — only user-supplied fields, no discriminators
const input: VSCatFlat = { text: "Vital Signs" };
profile.setVSCat(input);

// Getter returns SliceFlatAll — includes discriminator values + user data
const flat: VSCatFlatAll = profile.getVSCat()!;
expect(flat).toEqual({
text: "Vital Signs",
coding: [{ code: "vital-signs", system: "http://terminology.hl7.org/CodeSystem/observation-category" }],
});
});

test("setVSCat replaces existing slice element", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { Period } from "../../hl7-fhir-r4-core/Period";
import type { Reference } from "../../hl7-fhir-r4-core/Reference";

export type Observation_vitalsigns_Category_VSCatSliceFlat = Omit<CodeableConcept, "coding">;
export type Observation_vitalsigns_Category_VSCatSliceFlatAll = Observation_vitalsigns_Category_VSCatSliceFlat & {
readonly coding: [{ code: "vital-signs"; system: "http://terminology.hl7.org/CodeSystem/observation-category" }];
}

import {
ensureProfile,
Expand All @@ -16,7 +19,6 @@ import {
setArraySlice,
getArraySlice,
ensureSliceDefaults,
stripMatchKeys,
validateRequired,
validateExcluded,
validateFixedValue,
Expand All @@ -38,7 +40,9 @@ export type observation_vitalsignsProfileRaw = {
export class observation_vitalsignsProfile {
static readonly canonicalUrl = "http://hl7.org/fhir/StructureDefinition/vitalsigns";

private static readonly VSCatSliceMatch: Record<string, unknown> = {"coding":[{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}]};
private static readonly VSCatSliceMatch: Record<string, unknown> = {
"coding": [{"code":"vital-signs","system":"http://terminology.hl7.org/CodeSystem/observation-category"}],
}

private resource: Observation;

Expand Down Expand Up @@ -159,15 +163,15 @@ export class observation_vitalsignsProfile {
return this
}

public getVSCat(mode: 'flat'): Observation_vitalsigns_Category_VSCatSliceFlat | undefined;
public getVSCat(mode: 'flat'): Observation_vitalsigns_Category_VSCatSliceFlatAll | undefined;
public getVSCat(mode: 'raw'): CodeableConcept | undefined;
public getVSCat(): Observation_vitalsigns_Category_VSCatSliceFlat | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_vitalsigns_Category_VSCatSliceFlat | CodeableConcept | undefined {
public getVSCat(): Observation_vitalsigns_Category_VSCatSliceFlatAll | undefined;
public getVSCat (mode: 'flat' | 'raw' = 'flat'): Observation_vitalsigns_Category_VSCatSliceFlatAll | CodeableConcept | undefined {
const match = observation_vitalsignsProfile.VSCatSliceMatch
const item = getArraySlice(this.resource.category, match)
if (!item) return undefined
if (mode === 'raw') return item
return stripMatchKeys<Observation_vitalsigns_Category_VSCatSliceFlat>(item, ["coding"])
return item as unknown as Observation_vitalsigns_Category_VSCatSliceFlatAll
}

// Validation
Expand Down
Loading
Loading