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-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); +}); 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/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" }, }; 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; }