From 2ceb616a9c8f5b00f986f7af0f682f7287011291 Mon Sep 17 00:00:00 2001 From: Aleksandr Penskoi Date: Tue, 21 Apr 2026 16:56:47 +0200 Subject: [PATCH 1/3] TS: widen Reference.reference to accept all FHIR literal forms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #141. The generated Reference type narrowed reference to `${T}/${string}`, which rejected other forms allowed by the FHIR spec (urn:uuid, urn:oid, absolute URLs, fragments). The field type is now a union covering: relative `${T}/${string}`, absolute `http://…` / `https://…`, Bundle placeholder `urn:uuid:…`, OID `urn:oid:…`, and contained fragment `#…`. --- src/api/writer-generator/typescript/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/writer-generator/typescript/utils.ts b/src/api/writer-generator/typescript/utils.ts index 2f9414e5..a14f9b2c 100644 --- a/src/api/writer-generator/typescript/utils.ts +++ b/src/api/writer-generator/typescript/utils.ts @@ -54,7 +54,10 @@ export const tsEnumType = (enumDef: EnumDefinition) => { const rewriteFieldTypeDefs: Record string>> = { Coding: { code: () => "T" }, // biome-ignore lint: that is exactly string what we want - Reference: { reference: () => "`${T}/${string}`" }, + Reference: { + reference: () => + "`${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`", + }, CodeableConcept: { coding: () => "Coding" }, }; From 644477ef89a79faa9fdc34ce15950cf94f26ce28 Mon Sep 17 00:00:00 2001 From: Aleksandr Penskoi Date: Tue, 21 Apr 2026 17:00:45 +0200 Subject: [PATCH 2/3] test: cover FHIR literal reference forms in Reference Add a demo in examples/typescript-r4/resource.test.ts that assigns each of the six allowed literal forms (relative, urn:uuid, urn:oid, http, https, fragment) to a typed Reference field, so the widened template-literal union is exercised by tsc. --- examples/typescript-r4/resource.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/typescript-r4/resource.test.ts b/examples/typescript-r4/resource.test.ts index 08f864e5..10b655f2 100644 --- a/examples/typescript-r4/resource.test.ts +++ b/examples/typescript-r4/resource.test.ts @@ -120,3 +120,18 @@ test("Bundle with resources", () => { expect(bundle.entry).toHaveLength(2); expect(bundle).toMatchSnapshot(); }); + +test("Reference accepts all FHIR literal reference forms", () => { + // Relative reference — still narrowed to the typed form + const relative: Observation["subject"] = { reference: "Patient/123" }; + // Bundle placeholder — common in transaction bundles + const urnUuid: Observation["subject"] = { reference: "urn:uuid:a1b2c3d4-e5f6-7890-abcd-ef0123456789" }; + // OID reference + const urnOid: Observation["subject"] = { reference: "urn:oid:2.16.840.1.113883.2.4.6.3" }; + // Absolute URL + const absolute: Observation["subject"] = { reference: "https://example.org/fhir/Patient/123" }; + // Fragment reference to a contained resource + const fragment: Observation["subject"] = { reference: "#contained-1" }; + + expect([relative, urnUuid, urnOid, absolute, fragment]).toHaveLength(5); +}); From 18dd954f42704dec4e6a50749978e667a6457a0a Mon Sep 17 00:00:00 2001 From: Aleksandr Penskoi Date: Tue, 21 Apr 2026 17:00:49 +0200 Subject: [PATCH 3/3] TS: regenerate Reference.ts with widened reference field Regenerate src/fhir-types and the typescript-r4/typescript-us-core example fhir-types to reflect the widened Reference.reference union. --- examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts | 2 +- .../typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts | 2 +- src/fhir-types/hl7-fhir-r4-core/Reference.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts b/examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts index f59d6fed..a3e6da73 100644 --- a/examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts +++ b/examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts @@ -13,7 +13,7 @@ export interface Reference extends Element { display?: string; _display?: Element; identifier?: Identifier; - reference?: `${T}/${string}`; + reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`; _reference?: Element; type?: string; _type?: Element; diff --git a/examples/typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts b/examples/typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts index f59d6fed..a3e6da73 100644 --- a/examples/typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts +++ b/examples/typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts @@ -13,7 +13,7 @@ export interface Reference extends Element { display?: string; _display?: Element; identifier?: Identifier; - reference?: `${T}/${string}`; + reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`; _reference?: Element; type?: string; _type?: Element; diff --git a/src/fhir-types/hl7-fhir-r4-core/Reference.ts b/src/fhir-types/hl7-fhir-r4-core/Reference.ts index 1ee03e7c..119ee2a0 100644 --- a/src/fhir-types/hl7-fhir-r4-core/Reference.ts +++ b/src/fhir-types/hl7-fhir-r4-core/Reference.ts @@ -12,6 +12,6 @@ export type { Identifier } from "../hl7-fhir-r4-core/Identifier"; export interface Reference extends Element { display?: string; identifier?: Identifier; - reference?: `${T}/${string}`; + reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`; type?: string; }