Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -13,7 +13,7 @@ export interface Reference<T extends string = string> 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;
Expand Down
15 changes: 15 additions & 0 deletions examples/typescript-r4/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Reference<T extends string = string> 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;
Expand Down
5 changes: 4 additions & 1 deletion src/api/writer-generator/typescript/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export const tsEnumType = (enumDef: EnumDefinition) => {
const rewriteFieldTypeDefs: Record<string, Record<string, () => 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<T>" },
};

Expand Down
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export type { Identifier } from "../hl7-fhir-r4-core/Identifier";
export interface Reference<T extends string = string> 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;
}
Loading