Skip to content

Commit cc8f05b

Browse files
authored
Merge pull request #144 from atomic-ehr/fix/reference-literal-forms
TS: accept all FHIR literal reference forms in Reference<T>
2 parents a7a8dcf + 18dd954 commit cc8f05b

5 files changed

Lines changed: 22 additions & 4 deletions

File tree

examples/typescript-r4/fhir-types/hl7-fhir-r4-core/Reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Reference<T extends string = string> extends Element {
1313
display?: string;
1414
_display?: Element;
1515
identifier?: Identifier;
16-
reference?: `${T}/${string}`;
16+
reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`;
1717
_reference?: Element;
1818
type?: string;
1919
_type?: Element;

examples/typescript-r4/resource.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,18 @@ test("Bundle with resources", () => {
120120
expect(bundle.entry).toHaveLength(2);
121121
expect(bundle).toMatchSnapshot();
122122
});
123+
124+
test("Reference accepts all FHIR literal reference forms", () => {
125+
// Relative reference — still narrowed to the typed form
126+
const relative: Observation["subject"] = { reference: "Patient/123" };
127+
// Bundle placeholder — common in transaction bundles
128+
const urnUuid: Observation["subject"] = { reference: "urn:uuid:a1b2c3d4-e5f6-7890-abcd-ef0123456789" };
129+
// OID reference
130+
const urnOid: Observation["subject"] = { reference: "urn:oid:2.16.840.1.113883.2.4.6.3" };
131+
// Absolute URL
132+
const absolute: Observation["subject"] = { reference: "https://example.org/fhir/Patient/123" };
133+
// Fragment reference to a contained resource
134+
const fragment: Observation["subject"] = { reference: "#contained-1" };
135+
136+
expect([relative, urnUuid, urnOid, absolute, fragment]).toHaveLength(5);
137+
});

examples/typescript-us-core/fhir-types/hl7-fhir-r4-core/Reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Reference<T extends string = string> extends Element {
1313
display?: string;
1414
_display?: Element;
1515
identifier?: Identifier;
16-
reference?: `${T}/${string}`;
16+
reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`;
1717
_reference?: Element;
1818
type?: string;
1919
_type?: Element;

src/api/writer-generator/typescript/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export const tsEnumType = (enumDef: EnumDefinition) => {
5454
const rewriteFieldTypeDefs: Record<string, Record<string, () => string>> = {
5555
Coding: { code: () => "T" },
5656
// biome-ignore lint: that is exactly string what we want
57-
Reference: { reference: () => "`${T}/${string}`" },
57+
Reference: {
58+
reference: () =>
59+
"`${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`",
60+
},
5861
CodeableConcept: { coding: () => "Coding<T>" },
5962
};
6063

src/fhir-types/hl7-fhir-r4-core/Reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export type { Identifier } from "../hl7-fhir-r4-core/Identifier";
1212
export interface Reference<T extends string = string> extends Element {
1313
display?: string;
1414
identifier?: Identifier;
15-
reference?: `${T}/${string}`;
15+
reference?: `${T}/${string}` | `http://${string}` | `https://${string}` | `urn:uuid:${string}` | `urn:oid:${string}` | `#${string}`;
1616
type?: string;
1717
}

0 commit comments

Comments
 (0)