Skip to content

Commit 454e420

Browse files
authored
🤖 Merge PR DefinitelyTyped#75041 Add resourceType to Resource, fix SimpleQuantity/MoneyQuantity by @bkaney
1 parent d88ae13 commit 454e420

11 files changed

Lines changed: 308 additions & 0 deletions

File tree

‎types/fhir/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Type definitions for non-npm package FHIR
22
// Project: http://hl7.org/fhir/index.html
3+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
34
//
45
// Generated with https://github.com/reason-healthcare/fhir-types-workspace/tree/main/packages/fhir-ts-codegen
56
/// <reference path="r2.d.ts" />

‎types/fhir/r2.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13190,6 +13190,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
1319013190
* Base StructureDefinition for Resource Resource
1319113191
*/
1319213192
export interface Resource {
13193+
/** Resource Type Name (for serialization) */
13194+
readonly resourceType: string;
1319313195
/**
1319413196
* Logical id of this artifact
1319513197
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.

‎types/fhir/r3.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14777,6 +14777,12 @@ export interface MedicationPackage extends BackboneElement {
1477714777
batch?: MedicationPackageBatch[] | undefined;
1477814778
}
1477914779

14780+
/**
14781+
* A fixed quantity (no comparator)
14782+
*/
14783+
export interface SimpleQuantity extends Quantity {
14784+
}
14785+
1478014786
/**
1478114787
* Base StructureDefinition for DiagnosticReport Resource
1478214788
*/
@@ -20780,6 +20786,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
2078020786
* Base StructureDefinition for Resource Resource
2078120787
*/
2078220788
export interface Resource {
20789+
/** Resource Type Name (for serialization) */
20790+
readonly resourceType: string;
2078320791
/**
2078420792
* Logical id of this artifact
2078520793
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.

‎types/fhir/r4.d.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18656,6 +18656,12 @@ export interface MedicationBatch extends BackboneElement {
1865618656
_expirationDate?: Element | undefined;
1865718657
}
1865818658

18659+
/**
18660+
* A fixed quantity (no comparator)
18661+
*/
18662+
export interface SimpleQuantity extends Quantity {
18663+
}
18664+
1865918665
/**
1866018666
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting and provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports.
1866118667
*/
@@ -28032,6 +28038,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
2803228038
* This is the base resource type for everything.
2803328039
*/
2803428040
export interface Resource {
28041+
/** Resource Type Name (for serialization) */
28042+
readonly resourceType: string;
2803528043
/**
2803628044
* Logical id of this artifact
2803728045
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -33334,6 +33342,12 @@ export interface MedicinalProductContraindicationOtherTherapy extends BackboneEl
3333433342
medicationReference?: Reference | undefined;
3333533343
}
3333633344

33345+
/**
33346+
* An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
33347+
*/
33348+
export interface MoneyQuantity extends Quantity {
33349+
}
33350+
3333733351
/**
3333833352
* Measurements and simple assertions made about a patient, device or other subject.
3333933353
*/

‎types/fhir/r4b.d.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19430,6 +19430,12 @@ export interface MedicationBatch extends BackboneElement {
1943019430
_expirationDate?: Element | undefined;
1943119431
}
1943219432

19433+
/**
19434+
* A fixed quantity (no comparator)
19435+
*/
19436+
export interface SimpleQuantity extends Quantity {
19437+
}
19438+
1943319439
/**
1943419440
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting and provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports.
1943519441
*/
@@ -28408,6 +28414,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
2840828414
* This is the base resource type for everything.
2840928415
*/
2841028416
export interface Resource {
28417+
/** Resource Type Name (for serialization) */
28418+
readonly resourceType: string;
2841128419
/**
2841228420
* Logical id of this artifact
2841328421
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -34413,6 +34421,12 @@ export interface Quantity extends Element {
3441334421
_code?: Element | undefined;
3441434422
}
3441534423

34424+
/**
34425+
* An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
34426+
*/
34427+
export interface MoneyQuantity extends Quantity {
34428+
}
34429+
3441634430
/**
3441734431
* An ingredient of a manufactured item or pharmaceutical product.
3441834432
*/

‎types/fhir/r5.d.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23450,6 +23450,12 @@ export interface MedicationBatch extends BackboneElement {
2345023450
_expirationDate?: Element | undefined;
2345123451
}
2345223452

23453+
/**
23454+
* A fixed quantity (no comparator)
23455+
*/
23456+
export interface SimpleQuantity extends Quantity {
23457+
}
23458+
2345323459
/**
2345423460
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, products, substances, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports. The report also includes non-clinical context such as batch analysis and stability reporting of products and substances.
2345523461
*/
@@ -34968,6 +34974,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
3496834974
* This is the base resource type for everything.
3496934975
*/
3497034976
export interface Resource extends Base {
34977+
/** Resource Type Name (for serialization) */
34978+
readonly resourceType: string;
3497134979
/**
3497234980
* Logical id of this artifact
3497334981
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -43000,6 +43008,12 @@ export interface Quantity extends DataType {
4300043008
_code?: Element | undefined;
4300143009
}
4300243010

43011+
/**
43012+
* An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
43013+
*/
43014+
export interface MoneyQuantity extends Quantity {
43015+
}
43016+
4300343017
/**
4300443018
* An ingredient of a manufactured item or pharmaceutical product.
4300543019
*/

‎types/fhir/test/r2-tests.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,54 @@ const r2Test5710: fhir2.ValueSet = {"resourceType":"ValueSet","id":"account-stat
265265
// VisionPrescription-33123.json
266266
const r2Test6726: fhir2.VisionPrescription = {"dateWritten":"2014-06-15","dispense":[{"add":2,"base":"down","eye":"right","prism":0.5,"product":{"code":"lens","system":"http://hl7.org/fhir/ex-visionprescriptionproduct"},"sphere":-2},{"add":2,"axis":180,"base":"up","cylinder":-0.5,"eye":"left","prism":0.5,"product":{"code":"lens","system":"http://hl7.org/fhir/ex-visionprescriptionproduct"},"sphere":-1}],"id":"33123","identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"patient":{"reference":"Patient/example"},"prescriber":{"reference":"Practitioner/example"},"resourceType":"VisionPrescription","text":{"div":"<div>\n\t <p>OD -2.00 SPH +2.00 add 0.5 p.d. BD</p>\n <p>OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU</p>\n </div>","status":"generated"}};
267267

268+
269+
// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
270+
// FhirResource must not circularly reference itself (TS2456).
271+
// The root cause was that DomainResource.contained (and similar fields) were typed as
272+
// FhirResource[] instead of Resource[], creating a cycle through every resource type.
273+
274+
// 1. FhirResource is assignable from any concrete resource type
275+
const r2FhirResourcePatient: fhir2.FhirResource = { resourceType: "Patient", id: "pt-1" };
276+
const r2FhirResourceObservation: fhir2.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
277+
278+
// 2. FhirResource discriminated union narrows correctly via resourceType
279+
function processR2FhirResource(resource: fhir2.FhirResource): string {
280+
if (resource.resourceType === "Patient") {
281+
const patient: fhir2.Patient = resource;
282+
return patient.resourceType;
283+
}
284+
if (resource.resourceType === "Observation") {
285+
const obs: fhir2.Observation = resource;
286+
return obs.resourceType;
287+
}
288+
return resource.resourceType;
289+
}
290+
processR2FhirResource(r2FhirResourcePatient);
291+
processR2FhirResource(r2FhirResourceObservation);
292+
293+
// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
294+
const r2InlineObs: fhir2.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
295+
const r2PatientWithContained: fhir2.Patient = {
296+
resourceType: "Patient",
297+
id: "pt-contained",
298+
contained: [r2InlineObs],
299+
};
300+
301+
// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
302+
const r2InlinePatient: fhir2.Patient = { resourceType: "Patient", id: "pt-1" };
303+
const r2Params: fhir2.Parameters = {
304+
resourceType: "Parameters",
305+
parameter: [{ name: "subject", resource: r2InlinePatient }],
306+
};
307+
308+
// 5. Resource.resourceType is accessible on base-typed fields
309+
// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
310+
// BundleEntry.resource is typed as Resource — resourceType must be reachable.
311+
const r2Bundle: fhir2.Bundle = {
312+
resourceType: "Bundle",
313+
type: "collection",
314+
entry: [{ resource: r2InlinePatient }],
315+
};
316+
const r2HasPatient = r2Bundle.entry?.some(
317+
(e) => e.resource?.resourceType === "Patient",
318+
);

‎types/fhir/test/r3-tests.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,54 @@ const r3Test7131: fhir3.ValueSet = {"resourceType":"ValueSet","id":"abstract-typ
337337
// VisionPrescription-33123.json
338338
const r3Test8285: fhir3.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n\t <p>OD -2.00 SPH +2.00 add 0.5 p.d. BD</p>\n <p>OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU</p>\n </div>"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"dispense":[{"product":{"coding":[{"system":"http://hl7.org/fhir/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":0.5,"base":"down","add":2},{"product":{"coding":[{"system":"http://hl7.org/fhir/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":0.5,"base":"up","add":2}]};
339339

340+
341+
// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
342+
// FhirResource must not circularly reference itself (TS2456).
343+
// The root cause was that DomainResource.contained (and similar fields) were typed as
344+
// FhirResource[] instead of Resource[], creating a cycle through every resource type.
345+
346+
// 1. FhirResource is assignable from any concrete resource type
347+
const r3FhirResourcePatient: fhir3.FhirResource = { resourceType: "Patient", id: "pt-1" };
348+
const r3FhirResourceObservation: fhir3.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
349+
350+
// 2. FhirResource discriminated union narrows correctly via resourceType
351+
function processR3FhirResource(resource: fhir3.FhirResource): string {
352+
if (resource.resourceType === "Patient") {
353+
const patient: fhir3.Patient = resource;
354+
return patient.resourceType;
355+
}
356+
if (resource.resourceType === "Observation") {
357+
const obs: fhir3.Observation = resource;
358+
return obs.resourceType;
359+
}
360+
return resource.resourceType;
361+
}
362+
processR3FhirResource(r3FhirResourcePatient);
363+
processR3FhirResource(r3FhirResourceObservation);
364+
365+
// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
366+
const r3InlineObs: fhir3.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
367+
const r3PatientWithContained: fhir3.Patient = {
368+
resourceType: "Patient",
369+
id: "pt-contained",
370+
contained: [r3InlineObs],
371+
};
372+
373+
// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
374+
const r3InlinePatient: fhir3.Patient = { resourceType: "Patient", id: "pt-1" };
375+
const r3Params: fhir3.Parameters = {
376+
resourceType: "Parameters",
377+
parameter: [{ name: "subject", resource: r3InlinePatient }],
378+
};
379+
380+
// 5. Resource.resourceType is accessible on base-typed fields
381+
// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
382+
// BundleEntry.resource is typed as Resource — resourceType must be reachable.
383+
const r3Bundle: fhir3.Bundle = {
384+
resourceType: "Bundle",
385+
type: "collection",
386+
entry: [{ resource: r3InlinePatient }],
387+
};
388+
const r3HasPatient = r3Bundle.entry?.some(
389+
(e) => e.resource?.resourceType === "Patient",
390+
);

‎types/fhir/test/r4-tests.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,54 @@ const r4Test5306: fhir4.VerificationResult = {"resourceType":"VerificationResult
409409
// VisionPrescription-33123.json
410410
const r4Test5307: fhir4.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n\t\t\t<p>OD -2.00 SPH +2.00 add 0.5 p.d. BD</p>\n\t\t\t<p>OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU</p>\n\t\t</div>"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","created":"2014-06-15","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"lensSpecification":[{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":[{"amount":0.5,"base":"down"}],"add":2},{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":[{"amount":0.5,"base":"up"}],"add":2}]};
411411

412+
413+
// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
414+
// FhirResource must not circularly reference itself (TS2456).
415+
// The root cause was that DomainResource.contained (and similar fields) were typed as
416+
// FhirResource[] instead of Resource[], creating a cycle through every resource type.
417+
418+
// 1. FhirResource is assignable from any concrete resource type
419+
const r4FhirResourcePatient: fhir4.FhirResource = { resourceType: "Patient", id: "pt-1" };
420+
const r4FhirResourceObservation: fhir4.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
421+
422+
// 2. FhirResource discriminated union narrows correctly via resourceType
423+
function processR4FhirResource(resource: fhir4.FhirResource): string {
424+
if (resource.resourceType === "Patient") {
425+
const patient: fhir4.Patient = resource;
426+
return patient.resourceType;
427+
}
428+
if (resource.resourceType === "Observation") {
429+
const obs: fhir4.Observation = resource;
430+
return obs.resourceType;
431+
}
432+
return resource.resourceType;
433+
}
434+
processR4FhirResource(r4FhirResourcePatient);
435+
processR4FhirResource(r4FhirResourceObservation);
436+
437+
// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
438+
const r4InlineObs: fhir4.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
439+
const r4PatientWithContained: fhir4.Patient = {
440+
resourceType: "Patient",
441+
id: "pt-contained",
442+
contained: [r4InlineObs],
443+
};
444+
445+
// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
446+
const r4InlinePatient: fhir4.Patient = { resourceType: "Patient", id: "pt-1" };
447+
const r4Params: fhir4.Parameters = {
448+
resourceType: "Parameters",
449+
parameter: [{ name: "subject", resource: r4InlinePatient }],
450+
};
451+
452+
// 5. Resource.resourceType is accessible on base-typed fields
453+
// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
454+
// BundleEntry.resource is typed as Resource — resourceType must be reachable.
455+
const r4Bundle: fhir4.Bundle = {
456+
resourceType: "Bundle",
457+
type: "collection",
458+
entry: [{ resource: r4InlinePatient }],
459+
};
460+
const r4HasPatient = r4Bundle.entry?.some(
461+
(e) => e.resource?.resourceType === "Patient",
462+
);

‎types/fhir/test/r4b-tests.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,54 @@ const r4bTest2838: fhir4b.VerificationResult = {"resourceType":"VerificationResu
403403
// VisionPrescription-33123.json
404404
const r4bTest2839: fhir4b.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n\t\t\t<p>OD -2.00 SPH +2.00 add 0.5 p.d. BD</p>\n\t\t\t<p>OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU</p>\n\t\t</div>"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","created":"2014-06-15","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"lensSpecification":[{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":[{"amount":0.5,"base":"down"}],"add":2},{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":[{"amount":0.5,"base":"up"}],"add":2}],"meta":{"tag":[{"system":"http://terminology.hl7.org/CodeSystem/v3-ActReason","code":"HTEST","display":"test health data"}]}};
405405

406+
407+
// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
408+
// FhirResource must not circularly reference itself (TS2456).
409+
// The root cause was that DomainResource.contained (and similar fields) were typed as
410+
// FhirResource[] instead of Resource[], creating a cycle through every resource type.
411+
412+
// 1. FhirResource is assignable from any concrete resource type
413+
const r4bFhirResourcePatient: fhir4b.FhirResource = { resourceType: "Patient", id: "pt-1" };
414+
const r4bFhirResourceObservation: fhir4b.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
415+
416+
// 2. FhirResource discriminated union narrows correctly via resourceType
417+
function processR4bFhirResource(resource: fhir4b.FhirResource): string {
418+
if (resource.resourceType === "Patient") {
419+
const patient: fhir4b.Patient = resource;
420+
return patient.resourceType;
421+
}
422+
if (resource.resourceType === "Observation") {
423+
const obs: fhir4b.Observation = resource;
424+
return obs.resourceType;
425+
}
426+
return resource.resourceType;
427+
}
428+
processR4bFhirResource(r4bFhirResourcePatient);
429+
processR4bFhirResource(r4bFhirResourceObservation);
430+
431+
// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
432+
const r4bInlineObs: fhir4b.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
433+
const r4bPatientWithContained: fhir4b.Patient = {
434+
resourceType: "Patient",
435+
id: "pt-contained",
436+
contained: [r4bInlineObs],
437+
};
438+
439+
// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
440+
const r4bInlinePatient: fhir4b.Patient = { resourceType: "Patient", id: "pt-1" };
441+
const r4bParams: fhir4b.Parameters = {
442+
resourceType: "Parameters",
443+
parameter: [{ name: "subject", resource: r4bInlinePatient }],
444+
};
445+
446+
// 5. Resource.resourceType is accessible on base-typed fields
447+
// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
448+
// BundleEntry.resource is typed as Resource — resourceType must be reachable.
449+
const r4bBundle: fhir4b.Bundle = {
450+
resourceType: "Bundle",
451+
type: "collection",
452+
entry: [{ resource: r4bInlinePatient }],
453+
};
454+
const r4bHasPatient = r4bBundle.entry?.some(
455+
(e) => e.resource?.resourceType === "Patient",
456+
);

0 commit comments

Comments
 (0)