UNPKG

@oystehr/sdk

Version:

Oystehr SDK

149 lines (126 loc) 4.71 kB
import type { Operation } from 'fast-json-patch'; import type { Binary as BinaryR4B, Bundle as BundleR4B, BundleEntry as BundleEntryR4B, FhirResource as FhirResourceR4B, OperationOutcome as OperationOutcomeR4B, } from 'fhir/r4b'; import type { Binary as BinaryR5, Bundle as BundleR5, BundleEntry as BundleEntryR5, FhirResource as FhirResourceR5, OperationOutcome as OperationOutcomeR5, } from 'fhir/r5'; export type FhirResource = FhirResourceR4B | FhirResourceR5; // We're doing this "Omit dance" with the Bundle types because TypeScript // produces incorrect BundleEntry<F> types when F is a union of multiple FHIR // types. The guess is it's something about the conditional generic typing, but // we haven't found a different way to resolve it. // // No "omit dance": // entry: BundleEntry<Patient>[] | BundleEntry<Practitioner>[] | undefined // With "omit dance": // entry: (BundleEntry<Patient> | BundleEntry<Practitioner>)[] | undefined // // The latter can be used with array functions like `.find()`. export type FhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? BundleR4B<F> : BundleR5<F>; export type EntrylessFhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? Omit<BundleR4B<F>, 'entry'> : Omit<BundleR5<F>, 'entry'>; export type Bundle<F extends FhirResource> = EntrylessFhirBundle<F> & { entry?: Array<BundleEntry<F>> | undefined; unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[]; }; export type BatchBundle<F extends FhirResource> = EntrylessFhirBundle<F> & { entry?: Array<BundleEntry<F>> | undefined; unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[]; errors: (this: { entry?: Array<BundleEntry<F>> }) => OperationOutcome[] | undefined; }; export type TransactionBundle<F extends FhirResource> = EntrylessFhirBundle<F> & { entry?: Array<BundleEntry<F>> | undefined; unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[]; }; export type BundleEntry<F extends FhirResource> = F extends FhirResourceR4B ? BundleEntryR4B<F> : BundleEntryR5<F>; export type Binary<F extends FhirResource> = F extends FhirResourceR4B ? BinaryR4B : BinaryR5; export type OperationOutcome = OperationOutcomeR4B | OperationOutcomeR5; export type SearchParam = { name: string; value: string | number }; export type FhirResourceReturnValue<T extends FhirResource> = T extends { id?: string | undefined } ? Omit<T, 'id'> & { id: string } : T; export interface FhirSearchParams<T extends FhirResource> { resourceType: T['resourceType']; params?: SearchParam[]; } export interface FhirGetParams<T extends FhirResource> { resourceType: T['resourceType']; id: string; } export type FhirCreateParams<T extends FhirResource> = T; export type FhirUpdateParams<T extends FhirResource> = T; export interface FhirPatchParams<T extends FhirResource> { resourceType: T['resourceType']; id: string; operations: Operation[]; } export interface FhirDeleteParams<T extends FhirResource> { resourceType: T['resourceType']; id: string; } export interface FhirHistorySearchParams<T extends FhirResource> { resourceType: T['resourceType']; id: string; count?: number; offset?: number; } export interface FhirHistoryGetParams<T extends FhirResource> { resourceType: T['resourceType']; id: string; versionId: string; } interface BatchInputBaseRequest { url: string; } export interface BatchInputGetRequest extends BatchInputBaseRequest { method: 'GET'; } export interface BatchInputHeadRequest extends BatchInputBaseRequest { method: 'HEAD'; } export interface BatchInputDeleteRequest extends BatchInputBaseRequest { method: 'DELETE'; } export interface BatchInputPutRequest<F extends FhirResource> extends BatchInputBaseRequest { method: 'PUT'; ifMatch?: string; resource: F; } export interface BatchInputPostRequest<F extends FhirResource> extends BatchInputBaseRequest { method: 'POST'; resource: F; fullUrl?: string; } export interface BatchInputBinaryPatchRequest<F extends FhirResource> extends BatchInputBaseRequest { method: 'PATCH'; ifMatch?: string; resource: Binary<F>; } export interface BatchInputJSONPatchRequest extends BatchInputBaseRequest { method: 'PATCH'; ifMatch?: string; operations: Operation[]; } export type BatchInputPatchRequest<F extends FhirResource> = | BatchInputBinaryPatchRequest<F> | BatchInputJSONPatchRequest; export type BatchInputRequest<F extends FhirResource> = | BatchInputGetRequest | BatchInputHeadRequest | BatchInputPutRequest<F> | BatchInputPatchRequest<F> | BatchInputPostRequest<F> | BatchInputDeleteRequest; export interface BatchInput<F extends FhirResource> { requests: BatchInputRequest<F>[]; }