@oystehr/sdk 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import { Address as AddressR4B, HumanName as HumanNameR4B } from 'fhir/r4b';
2
+ import { Address as AddressR5, HumanName as HumanNameR5 } from 'fhir/r5';
1
3
  import { BatchInput, Bundle, FhirCreateParams, FhirDeleteParams, FhirGetParams, FhirHistoryGetParams, FhirHistorySearchParams, FhirPatchParams, FhirResource, FhirSearchParams, FhirUpdateParams } from '../..';
2
4
  import { FhirFetcherResponse, OystehrClientRequest, SDKResource } from '../../client/client';
3
5
  /**
@@ -32,3 +34,14 @@ export declare function history<T extends FhirResource>(this: SDKResource, { res
32
34
  export declare function history<T extends FhirResource>(this: SDKResource, { resourceType, id, versionId }: FhirHistoryGetParams, request?: OystehrClientRequest): Promise<FhirFetcherResponse<T>>;
33
35
  export declare const batch: <BundleContentType extends FhirResource>(this: SDKResource, input: BatchInput<BundleContentType>, request?: OystehrClientRequest) => Promise<Bundle<BundleContentType>>;
34
36
  export declare const transaction: <BundleContentType extends FhirResource>(this: SDKResource, input: BatchInput<BundleContentType>, request?: OystehrClientRequest) => Promise<Bundle<BundleContentType>>;
37
+ export declare function formatAddress(address: AddressR4B | AddressR5, options?: {
38
+ all?: boolean;
39
+ use?: boolean;
40
+ lineSeparator?: string;
41
+ }): string;
42
+ export declare function formatHumanName(name: HumanNameR4B | HumanNameR5, options?: {
43
+ all?: boolean;
44
+ prefix?: boolean;
45
+ suffix?: boolean;
46
+ use?: boolean;
47
+ }): string;
@@ -22,7 +22,7 @@ function search(params, request) {
22
22
  }, {});
23
23
  }
24
24
  const requestBundle = yield this.fhirRequest(`/${resourceType}/_search`, 'POST')(paramMap, Object.assign(Object.assign({}, request), { contentType: 'application/x-www-form-urlencoded' }));
25
- const bundle = Object.assign(Object.assign({}, requestBundle), { unbundle: function () {
25
+ const bundle = Object.assign(Object.assign({}, requestBundle), { entry: requestBundle.entry, unbundle: function () {
26
26
  var _a, _b;
27
27
  return (_b = (_a = this.entry) === null || _a === void 0 ? void 0 : _a.map((entry) => entry.resource).filter((entry) => entry !== undefined)) !== null && _b !== void 0 ? _b : [];
28
28
  } });
@@ -126,6 +126,48 @@ function bundleRequest(type) {
126
126
  }
127
127
  const batch = bundleRequest('batch');
128
128
  const transaction = bundleRequest('transaction');
129
+ function formatAddress(address, options) {
130
+ const builder = [];
131
+ if (address.line) {
132
+ builder.push(...address.line);
133
+ }
134
+ if (address.city || address.state || address.postalCode) {
135
+ const cityStateZip = [];
136
+ if (address.city) {
137
+ cityStateZip.push(address.city);
138
+ }
139
+ if (address.state) {
140
+ cityStateZip.push(address.state);
141
+ }
142
+ if (address.postalCode) {
143
+ cityStateZip.push(address.postalCode);
144
+ }
145
+ builder.push(cityStateZip.join(', '));
146
+ }
147
+ if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
148
+ builder.push('[' + address.use + ']');
149
+ }
150
+ return builder.join((options === null || options === void 0 ? void 0 : options.lineSeparator) || ', ').trim();
151
+ }
152
+ function formatHumanName(name, options) {
153
+ const builder = [];
154
+ if (name.prefix && (options === null || options === void 0 ? void 0 : options.prefix) !== false) {
155
+ builder.push(...name.prefix);
156
+ }
157
+ if (name.given) {
158
+ builder.push(...name.given);
159
+ }
160
+ if (name.family) {
161
+ builder.push(name.family);
162
+ }
163
+ if (name.suffix && (options === null || options === void 0 ? void 0 : options.suffix) !== false) {
164
+ builder.push(...name.suffix);
165
+ }
166
+ if (name.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
167
+ builder.push('[' + name.use + ']');
168
+ }
169
+ return builder.join(' ').trim();
170
+ }
129
171
 
130
- export { batch, create, del as delete, get, history, patch, search, transaction, update };
172
+ export { batch, create, del as delete, formatAddress, formatHumanName, get, history, patch, search, transaction, update };
131
173
  //# sourceMappingURL=fhir-ext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fhir-ext.js","sources":["../../../../src/resources/classes/fhir-ext.ts"],"sourcesContent":["import {\n BatchInput,\n BatchInputRequest,\n Binary,\n Bundle,\n BundleEntry,\n FhirBundle,\n FhirCreateParams,\n FhirDeleteParams,\n FhirGetParams,\n FhirHistoryGetParams,\n FhirHistorySearchParams,\n FhirPatchParams,\n FhirResource,\n FhirSearchParams,\n FhirUpdateParams,\n} from '../..';\nimport { addParamsToSearch, FhirFetcherResponse, OystehrClientRequest, SDKResource } from '../../client/client';\n\n/**\n * Optional parameter that can be passed to the client methods. It allows\n * overriding the access token or project ID, and setting various headers,\n * such as 'Content-Type'. Also support enabling optimistic locking.\n */\nexport interface OystehrFHIRUpdateClientRequest extends OystehrClientRequest {\n /**\n * Enable optimistic locking for the request. If set to a version ID, the request will\n * include the 'If-Match' header with that value in the FHIR optimistic-locking format.\n * If the resource has been updated since the version provided, the request\n * will fail with a 412 Precondition Failed error.\n */\n optimisticLockingVersionId?: string;\n}\n\n/**\n * Performs a FHIR search and returns the results as a Bundle resource\n *\n * @param options FHIR resource type and FHIR search parameters\n * @param request optional OystehrClientRequest object\n * @returns FHIR Bundle resource\n */\nexport async function search<T extends FhirResource>(\n this: SDKResource,\n params: FhirSearchParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>>> {\n const { resourceType, params: searchParams } = params;\n let paramMap: Record<string, (string | number)[]> | undefined;\n if (searchParams) {\n paramMap = Object.entries(searchParams).reduce((acc, [_, param]) => {\n if (!acc[param.name]) {\n acc[param.name] = [];\n }\n acc[param.name].push(param.value);\n return acc;\n }, {} as Record<string, (string | number)[]>);\n }\n const requestBundle = await this.fhirRequest<FhirBundle<T>>(`/${resourceType}/_search`, 'POST')(paramMap, {\n ...request,\n contentType: 'application/x-www-form-urlencoded',\n });\n const bundle: Bundle<T> = {\n ...requestBundle,\n unbundle: function (this: Bundle<T>) {\n return this.entry?.map((entry) => entry.resource).filter((entry): entry is T => entry !== undefined) ?? [];\n },\n };\n return bundle;\n}\n\nexport async function create<T extends FhirResource>(\n this: SDKResource,\n params: FhirCreateParams<T>,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n const { resourceType } = params;\n return this.fhirRequest(`/${resourceType}`, 'POST')(params as unknown as Record<string, unknown>, request);\n}\n\nexport async function get<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirGetParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest<T>(`/${resourceType}/${id}`, 'GET')({}, request);\n}\n\nexport async function update<T extends FhirResource>(\n this: SDKResource,\n params: FhirUpdateParams<T>,\n request?: OystehrFHIRUpdateClientRequest\n): Promise<FhirFetcherResponse<T>> {\n const { id, resourceType } = params;\n return this.fhirRequest(`/${resourceType}/${id}`, 'PUT')(params as unknown as Record<string, unknown>, {\n ...request,\n ifMatch: request?.optimisticLockingVersionId ? `W/\"${request.optimisticLockingVersionId}\"` : undefined,\n });\n}\n\nexport async function patch<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, operations }: FhirPatchParams,\n request?: OystehrFHIRUpdateClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}`, 'PATCH')(operations, {\n ...request,\n contentType: 'application/json-patch+json',\n ifMatch: request?.optimisticLockingVersionId ? `W/\"${request.optimisticLockingVersionId}\"` : undefined,\n });\n}\n\nasync function del<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirDeleteParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}`, 'DELETE')({}, request);\n}\nexport { del as delete };\n\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirHistorySearchParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>>>;\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, versionId }: FhirHistoryGetParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>>;\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, versionId }: { resourceType: string; id: string; versionId?: string },\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>> | FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}/_history${versionId ? `/${versionId}` : ''}`, 'GET')({}, request);\n}\n\nfunction batchInputRequestToBundleEntryItem<T extends FhirResource>(\n request: BatchInputRequest<T>\n): BundleEntry<T | Binary<T>> {\n const { method, url } = request;\n const baseRequest = {\n request: {\n method,\n url,\n },\n };\n\n // Escape query string parameters in entry.request.url\n if (url.split('?').length > 1) {\n const [resource, query] = url.split('?');\n const params = query\n .split('&')\n .map((param) => {\n const [name, value] = param.split('=');\n return { name, value };\n })\n .reduce((acc, { name, value }) => {\n acc[name] = value;\n return acc;\n }, {} as Record<string, string>);\n const search = new URLSearchParams();\n addParamsToSearch(params, search);\n baseRequest.request.url = `${resource}?${search.toString()}`;\n }\n\n // GET, DELETE, and HEAD require no further parameters\n if (['GET', 'DELETE', 'HEAD'].includes(method)) {\n return baseRequest as BundleEntry<T>;\n }\n\n // PUT updates require a full resource\n if (method === 'PUT') {\n const { resource } = request;\n return {\n ...baseRequest,\n resource: resource as T,\n } as BundleEntry<T>;\n }\n\n // PATCH can be Binary resource or JSON patch\n if (method === 'PATCH') {\n if ('resource' in request) {\n return {\n ...baseRequest,\n resource: request.resource,\n } as BundleEntry<Binary<T>>;\n }\n return {\n ...baseRequest,\n resource: {\n resourceType: 'Binary',\n contentType: 'application/json-patch+json',\n data: Buffer.from(JSON.stringify(request.operations), 'utf8').toString('base64'),\n },\n } as BundleEntry<Binary<T>>;\n }\n\n // POST creates require a full resource\n if (method === 'POST') {\n const { resource, fullUrl } = request;\n return {\n ...baseRequest,\n resource: resource as T,\n fullUrl,\n } as BundleEntry<T>;\n }\n throw new Error('Unrecognized method');\n}\n\nfunction bundleRequest(type: 'batch' | 'transaction') {\n return async function <BundleContentType extends FhirResource>(\n this: SDKResource,\n input: BatchInput<BundleContentType>,\n request?: OystehrClientRequest\n ): Promise<FhirFetcherResponse<Bundle<BundleContentType>>> {\n return this.fhirRequest('/', 'POST')(\n {\n resourceType: 'Bundle',\n type,\n entry: input.requests.map(batchInputRequestToBundleEntryItem),\n },\n request\n );\n };\n}\n\nexport const batch = bundleRequest('batch');\nexport const transaction = bundleRequest('transaction');\n"],"names":[],"mappings":";;;AAkCA;;;;;;AAMG;AACmB,SAAA,MAAM,CAE1B,MAAwB,EACxB,OAA8B,EAAA;;QAE9B,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;AACtD,QAAA,IAAI,QAAyD,CAAC;AAC9D,QAAA,IAAI,YAAY,EAAE;AAChB,YAAA,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,KAAI;AACjE,gBAAA,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;AACpB,oBAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACtB,iBAAA;AACD,gBAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,CAAC;aACZ,EAAE,EAAyC,CAAC,CAAC;AAC/C,SAAA;QACD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAAgB,CAAI,CAAA,EAAA,YAAY,CAAU,QAAA,CAAA,EAAE,MAAM,CAAC,CAAC,QAAQ,EACnG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,OAAO,KACV,WAAW,EAAE,mCAAmC,EAAA,CAAA,CAChD,CAAC;AACH,QAAA,MAAM,MAA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OAAO,EAAA,CACU,CAAC;AACrB,KAAA;AACD,IAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,aAAa,CAAC,IAA6B,EAAA;IAClD,OAAO,UAEL,KAAoC,EACpC,OAA8B,EAAA;;YAE9B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAClC;AACE,gBAAA,YAAY,EAAE,QAAQ;gBACtB,IAAI;gBACJ,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,kCAAkC,CAAC;aAC9D,EACD,OAAO,CACR,CAAC;SACH,CAAA,CAAA;KAAA,CAAC;AACJ,CAAC;MAEY,KAAK,GAAG,aAAa,CAAC,OAAO,EAAE;MAC/B,WAAW,GAAG,aAAa,CAAC,aAAa;;;;"}
1
+ {"version":3,"file":"fhir-ext.js","sources":["../../../../src/resources/classes/fhir-ext.ts"],"sourcesContent":["import { Address as AddressR4B, HumanName as HumanNameR4B } from 'fhir/r4b';\nimport { Address as AddressR5, HumanName as HumanNameR5 } from 'fhir/r5';\nimport {\n BatchInput,\n BatchInputRequest,\n Binary,\n Bundle,\n BundleEntry,\n FhirBundle,\n FhirCreateParams,\n FhirDeleteParams,\n FhirGetParams,\n FhirHistoryGetParams,\n FhirHistorySearchParams,\n FhirPatchParams,\n FhirResource,\n FhirSearchParams,\n FhirUpdateParams,\n} from '../..';\nimport { addParamsToSearch, FhirFetcherResponse, OystehrClientRequest, SDKResource } from '../../client/client';\n\n/**\n * Optional parameter that can be passed to the client methods. It allows\n * overriding the access token or project ID, and setting various headers,\n * such as 'Content-Type'. Also support enabling optimistic locking.\n */\nexport interface OystehrFHIRUpdateClientRequest extends OystehrClientRequest {\n /**\n * Enable optimistic locking for the request. If set to a version ID, the request will\n * include the 'If-Match' header with that value in the FHIR optimistic-locking format.\n * If the resource has been updated since the version provided, the request\n * will fail with a 412 Precondition Failed error.\n */\n optimisticLockingVersionId?: string;\n}\n\n/**\n * Performs a FHIR search and returns the results as a Bundle resource\n *\n * @param options FHIR resource type and FHIR search parameters\n * @param request optional OystehrClientRequest object\n * @returns FHIR Bundle resource\n */\nexport async function search<T extends FhirResource>(\n this: SDKResource,\n params: FhirSearchParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>>> {\n const { resourceType, params: searchParams } = params;\n let paramMap: Record<string, (string | number)[]> | undefined;\n if (searchParams) {\n paramMap = Object.entries(searchParams).reduce((acc, [_, param]) => {\n if (!acc[param.name]) {\n acc[param.name] = [];\n }\n acc[param.name].push(param.value);\n return acc;\n }, {} as Record<string, (string | number)[]>);\n }\n const requestBundle = await this.fhirRequest<FhirBundle<T>>(`/${resourceType}/_search`, 'POST')(paramMap, {\n ...request,\n contentType: 'application/x-www-form-urlencoded',\n });\n const bundle: Bundle<T> = {\n ...requestBundle,\n entry: requestBundle.entry as Array<BundleEntry<T>> | undefined,\n unbundle: function (this: { entry?: Array<BundleEntry<T>> | undefined }) {\n return this.entry?.map((entry) => entry.resource).filter((entry): entry is T => entry !== undefined) ?? [];\n },\n };\n return bundle;\n}\n\nexport async function create<T extends FhirResource>(\n this: SDKResource,\n params: FhirCreateParams<T>,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n const { resourceType } = params;\n return this.fhirRequest(`/${resourceType}`, 'POST')(params as unknown as Record<string, unknown>, request);\n}\n\nexport async function get<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirGetParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest<T>(`/${resourceType}/${id}`, 'GET')({}, request);\n}\n\nexport async function update<T extends FhirResource>(\n this: SDKResource,\n params: FhirUpdateParams<T>,\n request?: OystehrFHIRUpdateClientRequest\n): Promise<FhirFetcherResponse<T>> {\n const { id, resourceType } = params;\n return this.fhirRequest(`/${resourceType}/${id}`, 'PUT')(params as unknown as Record<string, unknown>, {\n ...request,\n ifMatch: request?.optimisticLockingVersionId ? `W/\"${request.optimisticLockingVersionId}\"` : undefined,\n });\n}\n\nexport async function patch<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, operations }: FhirPatchParams,\n request?: OystehrFHIRUpdateClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}`, 'PATCH')(operations, {\n ...request,\n contentType: 'application/json-patch+json',\n ifMatch: request?.optimisticLockingVersionId ? `W/\"${request.optimisticLockingVersionId}\"` : undefined,\n });\n}\n\nasync function del<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirDeleteParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}`, 'DELETE')({}, request);\n}\nexport { del as delete };\n\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id }: FhirHistorySearchParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>>>;\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, versionId }: FhirHistoryGetParams,\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<T>>;\nexport async function history<T extends FhirResource>(\n this: SDKResource,\n { resourceType, id, versionId }: { resourceType: string; id: string; versionId?: string },\n request?: OystehrClientRequest\n): Promise<FhirFetcherResponse<Bundle<T>> | FhirFetcherResponse<T>> {\n return this.fhirRequest(`/${resourceType}/${id}/_history${versionId ? `/${versionId}` : ''}`, 'GET')({}, request);\n}\n\nfunction batchInputRequestToBundleEntryItem<T extends FhirResource>(\n request: BatchInputRequest<T>\n): BundleEntry<T | Binary<T>> {\n const { method, url } = request;\n const baseRequest = {\n request: {\n method,\n url,\n },\n };\n\n // Escape query string parameters in entry.request.url\n if (url.split('?').length > 1) {\n const [resource, query] = url.split('?');\n const params = query\n .split('&')\n .map((param) => {\n const [name, value] = param.split('=');\n return { name, value };\n })\n .reduce((acc, { name, value }) => {\n acc[name] = value;\n return acc;\n }, {} as Record<string, string>);\n const search = new URLSearchParams();\n addParamsToSearch(params, search);\n baseRequest.request.url = `${resource}?${search.toString()}`;\n }\n\n // GET, DELETE, and HEAD require no further parameters\n if (['GET', 'DELETE', 'HEAD'].includes(method)) {\n return baseRequest as BundleEntry<T>;\n }\n\n // PUT updates require a full resource\n if (method === 'PUT') {\n const { resource } = request;\n return {\n ...baseRequest,\n resource: resource as T,\n } as BundleEntry<T>;\n }\n\n // PATCH can be Binary resource or JSON patch\n if (method === 'PATCH') {\n if ('resource' in request) {\n return {\n ...baseRequest,\n resource: request.resource,\n } as BundleEntry<Binary<T>>;\n }\n return {\n ...baseRequest,\n resource: {\n resourceType: 'Binary',\n contentType: 'application/json-patch+json',\n data: Buffer.from(JSON.stringify(request.operations), 'utf8').toString('base64'),\n },\n } as BundleEntry<Binary<T>>;\n }\n\n // POST creates require a full resource\n if (method === 'POST') {\n const { resource, fullUrl } = request;\n return {\n ...baseRequest,\n resource: resource as T,\n fullUrl,\n } as BundleEntry<T>;\n }\n throw new Error('Unrecognized method');\n}\n\nfunction bundleRequest(type: 'batch' | 'transaction') {\n return async function <BundleContentType extends FhirResource>(\n this: SDKResource,\n input: BatchInput<BundleContentType>,\n request?: OystehrClientRequest\n ): Promise<FhirFetcherResponse<Bundle<BundleContentType>>> {\n return this.fhirRequest('/', 'POST')(\n {\n resourceType: 'Bundle',\n type,\n entry: input.requests.map(batchInputRequestToBundleEntryItem),\n },\n request\n );\n };\n}\n\nexport const batch = bundleRequest('batch');\nexport const transaction = bundleRequest('transaction');\n\nexport function formatAddress(\n address: AddressR4B | AddressR5,\n options?: { all?: boolean; use?: boolean; lineSeparator?: string }\n): string {\n const builder = [];\n\n if (address.line) {\n builder.push(...address.line);\n }\n\n if (address.city || address.state || address.postalCode) {\n const cityStateZip = [];\n if (address.city) {\n cityStateZip.push(address.city);\n }\n if (address.state) {\n cityStateZip.push(address.state);\n }\n if (address.postalCode) {\n cityStateZip.push(address.postalCode);\n }\n builder.push(cityStateZip.join(', '));\n }\n\n if (address.use && (options?.all || options?.use)) {\n builder.push('[' + address.use + ']');\n }\n\n return builder.join(options?.lineSeparator || ', ').trim();\n}\n\nexport function formatHumanName(\n name: HumanNameR4B | HumanNameR5,\n options?: {\n all?: boolean;\n prefix?: boolean;\n suffix?: boolean;\n use?: boolean;\n }\n): string {\n const builder = [];\n\n if (name.prefix && options?.prefix !== false) {\n builder.push(...name.prefix);\n }\n\n if (name.given) {\n builder.push(...name.given);\n }\n\n if (name.family) {\n builder.push(name.family);\n }\n\n if (name.suffix && options?.suffix !== false) {\n builder.push(...name.suffix);\n }\n\n if (name.use && (options?.all || options?.use)) {\n builder.push('[' + name.use + ']');\n }\n\n return builder.join(' ').trim();\n}\n"],"names":[],"mappings":";;;AAoCA;;;;;;AAMG;AACmB,SAAA,MAAM,CAE1B,MAAwB,EACxB,OAA8B,EAAA;;QAE9B,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;AACtD,QAAA,IAAI,QAAyD,CAAC;AAC9D,QAAA,IAAI,YAAY,EAAE;AAChB,YAAA,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,KAAI;AACjE,gBAAA,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;AACpB,oBAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACtB,iBAAA;AACD,gBAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,CAAC;aACZ,EAAE,EAAyC,CAAC,CAAC;AAC/C,SAAA;QACD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAAgB,CAAI,CAAA,EAAA,YAAY,CAAU,QAAA,CAAA,EAAE,MAAM,CAAC,CAAC,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AAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,KAAA;AAED,IAAA,IAAI,IAAI,CAAC,MAAM,IAAI,CAAA,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAP,OAAO,CAAE,MAAM,MAAK,KAAK,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,KAAA;IAED,IAAI,IAAI,CAAC,GAAG,KAAK,CAAA,OAAO,KAAP,IAAA,IAAA,OAAO,KAAP,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,OAAO,CAAE,GAAG,MAAI,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAP,OAAO,CAAE,GAAG,CAAA,CAAC,EAAE;QAC9C,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AACpC,KAAA;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAClC;;;;"}
@@ -18,4 +18,6 @@ export declare class Fhir extends SDKResource {
18
18
  history: typeof ext.history;
19
19
  batch: <BundleContentType extends import("..").FhirResource>(this: SDKResource, input: import("..").BatchInput<BundleContentType>, request?: import("../../client/client").OystehrClientRequest | undefined) => Promise<import("..").Bundle<BundleContentType>>;
20
20
  transaction: <BundleContentType extends import("..").FhirResource>(this: SDKResource, input: import("..").BatchInput<BundleContentType>, request?: import("../../client/client").OystehrClientRequest | undefined) => Promise<import("..").Bundle<BundleContentType>>;
21
+ formatAddress: typeof ext.formatAddress;
22
+ formatHumanName: typeof ext.formatHumanName;
21
23
  }
@@ -1,5 +1,5 @@
1
1
  import { SDKResource } from '../../client/client.js';
2
- import { search, create, get, update, patch, delete as del, history, batch, transaction } from './fhir-ext.js';
2
+ import { search, create, get, update, patch, delete as del, history, batch, transaction, formatAddress, formatHumanName } from './fhir-ext.js';
3
3
 
4
4
  // AUTOGENERATED -- DO NOT EDIT
5
5
  class Fhir extends SDKResource {
@@ -20,6 +20,8 @@ class Fhir extends SDKResource {
20
20
  this.history = history;
21
21
  this.batch = batch;
22
22
  this.transaction = transaction;
23
+ this.formatAddress = formatAddress;
24
+ this.formatHumanName = formatHumanName;
23
25
  }
24
26
  }
25
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"fhir.js","sources":["../../../../src/resources/classes/fhir.ts"],"sourcesContent":["// AUTOGENERATED -- DO NOT EDIT\n\nimport { SDKResource } from '../../client/client';\nimport { OystehrConfig } from '../../config';\nimport * as ext from './fhir-ext';\n\nexport class Fhir extends SDKResource {\n constructor(config: OystehrConfig) {\n super(config);\n }\n /**\n * Performs a FHIR search and returns the results as a Bundle resource\n * @param options FHIR resource type and FHIR search parameters\n * @param request optional OystehrClientRequest object\n * @returns FHIR Bundle resource\n */\n search = ext.search;\n create = ext.create;\n get = ext.get;\n update = ext.update;\n patch = ext.patch;\n delete = ext.delete;\n history = ext.history;\n batch = ext.batch;\n transaction = ext.transaction;\n}\n"],"names":["ext.search","ext.create","ext.get","ext.update","ext.patch","ext.delete","ext.history","ext.batch","ext.transaction"],"mappings":";;;AAAA;AAMM,MAAO,IAAK,SAAQ,WAAW,CAAA;AACnC,IAAA,WAAA,CAAY,MAAqB,EAAA;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;AAKG;AACH,QAAA,IAAA,CAAA,MAAM,GAAGA,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,MAAM,GAAGC,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,GAAG,GAAGC,GAAO,CAAC;AACd,QAAA,IAAA,CAAA,MAAM,GAAGC,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,KAAK,GAAGC,KAAS,CAAC;AAClB,QAAA,IAAA,CAAA,MAAM,GAAGC,GAAU,CAAC;AACpB,QAAA,IAAA,CAAA,OAAO,GAAGC,OAAW,CAAC;AACtB,QAAA,IAAA,CAAA,KAAK,GAAGC,KAAS,CAAC;AAClB,QAAA,IAAA,CAAA,WAAW,GAAGC,WAAe,CAAC;KAf7B;AAgBF;;;;"}
1
+ {"version":3,"file":"fhir.js","sources":["../../../../src/resources/classes/fhir.ts"],"sourcesContent":["// AUTOGENERATED -- DO NOT EDIT\n\nimport { SDKResource } from '../../client/client';\nimport { OystehrConfig } from '../../config';\nimport * as ext from './fhir-ext';\n\nexport class Fhir extends SDKResource {\n constructor(config: OystehrConfig) {\n super(config);\n }\n /**\n * Performs a FHIR search and returns the results as a Bundle resource\n * @param options FHIR resource type and FHIR search parameters\n * @param request optional OystehrClientRequest object\n * @returns FHIR Bundle resource\n */\n search = ext.search;\n create = ext.create;\n get = ext.get;\n update = ext.update;\n patch = ext.patch;\n delete = ext.delete;\n history = ext.history;\n batch = ext.batch;\n transaction = ext.transaction;\n formatAddress = ext.formatAddress;\n formatHumanName = ext.formatHumanName;\n}\n"],"names":["ext.search","ext.create","ext.get","ext.update","ext.patch","ext.delete","ext.history","ext.batch","ext.transaction","ext.formatAddress","ext.formatHumanName"],"mappings":";;;AAAA;AAMM,MAAO,IAAK,SAAQ,WAAW,CAAA;AACnC,IAAA,WAAA,CAAY,MAAqB,EAAA;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;AAKG;AACH,QAAA,IAAA,CAAA,MAAM,GAAGA,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,MAAM,GAAGC,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,GAAG,GAAGC,GAAO,CAAC;AACd,QAAA,IAAA,CAAA,MAAM,GAAGC,MAAU,CAAC;AACpB,QAAA,IAAA,CAAA,KAAK,GAAGC,KAAS,CAAC;AAClB,QAAA,IAAA,CAAA,MAAM,GAAGC,GAAU,CAAC;AACpB,QAAA,IAAA,CAAA,OAAO,GAAGC,OAAW,CAAC;AACtB,QAAA,IAAA,CAAA,KAAK,GAAGC,KAAS,CAAC;AAClB,QAAA,IAAA,CAAA,WAAW,GAAGC,WAAe,CAAC;AAC9B,QAAA,IAAA,CAAA,aAAa,GAAGC,aAAiB,CAAC;AAClC,QAAA,IAAA,CAAA,eAAe,GAAGC,eAAmB,CAAC;KAjBrC;AAkBF;;;;"}
@@ -7,6 +7,6 @@ export interface ZambdaCreateParams {
7
7
  /**
8
8
  * The trigger method for the Zambda Function determines how the Function is invoked. Learn more about the different types here, https://docs.oystehr.com/services/zambda/#types-of-zambdas.
9
9
  */
10
- triggerMethod: 'http_auth' | 'http_open' | 'subscription' | 'cron';
10
+ triggerMethod?: 'http_auth' | 'http_open' | 'subscription' | 'cron';
11
11
  schedule?: ZambdaSchedule;
12
12
  }
@@ -2,10 +2,13 @@ import type { Operation } from 'fast-json-patch';
2
2
  import type { Binary as BinaryR4B, Bundle as BundleR4B, BundleEntry as BundleEntryR4B, FhirResource as FhirResourceR4B, OperationOutcome as OperationOutcomeR4B } from 'fhir/r4b';
3
3
  import type { Binary as BinaryR5, Bundle as BundleR5, BundleEntry as BundleEntryR5, FhirResource as FhirResourceR5, OperationOutcome as OperationOutcomeR5 } from 'fhir/r5';
4
4
  export type FhirResource = FhirResourceR4B | FhirResourceR5;
5
- export type FhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? Omit<BundleR4B<F>, 'entry'> : Omit<BundleR5<F>, 'entry'>;
6
- export type Bundle<F extends FhirResource> = FhirBundle<F> & {
5
+ export type FhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? BundleR4B<F> : BundleR5<F>;
6
+ export type EntrylessFhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? Omit<BundleR4B<F>, 'entry'> : Omit<BundleR5<F>, 'entry'>;
7
+ export type Bundle<F extends FhirResource> = EntrylessFhirBundle<F> & {
7
8
  entry?: Array<BundleEntry<F>> | undefined;
8
- unbundle: (this: Bundle<F>) => F[];
9
+ unbundle: (this: {
10
+ entry?: Array<BundleEntry<F>>;
11
+ }) => F[];
9
12
  };
10
13
  export type BundleEntry<F extends FhirResource> = F extends FhirResourceR4B ? BundleEntryR4B<F> : BundleEntryR5<F>;
11
14
  export type Binary<F extends FhirResource> = F extends FhirResourceR4B ? BinaryR4B : BinaryR5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oystehr/sdk",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Oystehr SDK",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -1,3 +1,5 @@
1
+ import { Address as AddressR4B, HumanName as HumanNameR4B } from 'fhir/r4b';
2
+ import { Address as AddressR5, HumanName as HumanNameR5 } from 'fhir/r5';
1
3
  import {
2
4
  BatchInput,
3
5
  BatchInputRequest,
@@ -61,7 +63,8 @@ export async function search<T extends FhirResource>(
61
63
  });
62
64
  const bundle: Bundle<T> = {
63
65
  ...requestBundle,
64
- unbundle: function (this: Bundle<T>) {
66
+ entry: requestBundle.entry as Array<BundleEntry<T>> | undefined,
67
+ unbundle: function (this: { entry?: Array<BundleEntry<T>> | undefined }) {
65
68
  return this.entry?.map((entry) => entry.resource).filter((entry): entry is T => entry !== undefined) ?? [];
66
69
  },
67
70
  };
@@ -228,3 +231,68 @@ function bundleRequest(type: 'batch' | 'transaction') {
228
231
 
229
232
  export const batch = bundleRequest('batch');
230
233
  export const transaction = bundleRequest('transaction');
234
+
235
+ export function formatAddress(
236
+ address: AddressR4B | AddressR5,
237
+ options?: { all?: boolean; use?: boolean; lineSeparator?: string }
238
+ ): string {
239
+ const builder = [];
240
+
241
+ if (address.line) {
242
+ builder.push(...address.line);
243
+ }
244
+
245
+ if (address.city || address.state || address.postalCode) {
246
+ const cityStateZip = [];
247
+ if (address.city) {
248
+ cityStateZip.push(address.city);
249
+ }
250
+ if (address.state) {
251
+ cityStateZip.push(address.state);
252
+ }
253
+ if (address.postalCode) {
254
+ cityStateZip.push(address.postalCode);
255
+ }
256
+ builder.push(cityStateZip.join(', '));
257
+ }
258
+
259
+ if (address.use && (options?.all || options?.use)) {
260
+ builder.push('[' + address.use + ']');
261
+ }
262
+
263
+ return builder.join(options?.lineSeparator || ', ').trim();
264
+ }
265
+
266
+ export function formatHumanName(
267
+ name: HumanNameR4B | HumanNameR5,
268
+ options?: {
269
+ all?: boolean;
270
+ prefix?: boolean;
271
+ suffix?: boolean;
272
+ use?: boolean;
273
+ }
274
+ ): string {
275
+ const builder = [];
276
+
277
+ if (name.prefix && options?.prefix !== false) {
278
+ builder.push(...name.prefix);
279
+ }
280
+
281
+ if (name.given) {
282
+ builder.push(...name.given);
283
+ }
284
+
285
+ if (name.family) {
286
+ builder.push(name.family);
287
+ }
288
+
289
+ if (name.suffix && options?.suffix !== false) {
290
+ builder.push(...name.suffix);
291
+ }
292
+
293
+ if (name.use && (options?.all || options?.use)) {
294
+ builder.push('[' + name.use + ']');
295
+ }
296
+
297
+ return builder.join(' ').trim();
298
+ }
@@ -23,4 +23,6 @@ export class Fhir extends SDKResource {
23
23
  history = ext.history;
24
24
  batch = ext.batch;
25
25
  transaction = ext.transaction;
26
+ formatAddress = ext.formatAddress;
27
+ formatHumanName = ext.formatHumanName;
26
28
  }
@@ -10,6 +10,6 @@ export interface ZambdaCreateParams {
10
10
  /**
11
11
  * The trigger method for the Zambda Function determines how the Function is invoked. Learn more about the different types here, https://docs.oystehr.com/services/zambda/#types-of-zambdas.
12
12
  */
13
- triggerMethod: 'http_auth' | 'http_open' | 'subscription' | 'cron';
13
+ triggerMethod?: 'http_auth' | 'http_open' | 'subscription' | 'cron';
14
14
  schedule?: ZambdaSchedule;
15
15
  }
@@ -26,12 +26,13 @@ export type FhirResource = FhirResourceR4B | FhirResourceR5;
26
26
  // entry: (BundleEntry<Patient> | BundleEntry<Practitioner>)[] | undefined
27
27
  //
28
28
  // The latter can be used with array functions like `.find()`.
29
- export type FhirBundle<F extends FhirResource> = F extends FhirResourceR4B
29
+ export type FhirBundle<F extends FhirResource> = F extends FhirResourceR4B ? BundleR4B<F> : BundleR5<F>;
30
+ export type EntrylessFhirBundle<F extends FhirResource> = F extends FhirResourceR4B
30
31
  ? Omit<BundleR4B<F>, 'entry'>
31
32
  : Omit<BundleR5<F>, 'entry'>;
32
- export type Bundle<F extends FhirResource> = FhirBundle<F> & {
33
+ export type Bundle<F extends FhirResource> = EntrylessFhirBundle<F> & {
33
34
  entry?: Array<BundleEntry<F>> | undefined;
34
- unbundle: (this: Bundle<F>) => F[];
35
+ unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[];
35
36
  };
36
37
  export type BundleEntry<F extends FhirResource> = F extends FhirResourceR4B ? BundleEntryR4B<F> : BundleEntryR5<F>;
37
38
  export type Binary<F extends FhirResource> = F extends FhirResourceR4B ? BinaryR4B : BinaryR5;
@@ -1,9 +0,0 @@
1
- import * as R4B from 'fhir/r4b';
2
- import * as R5 from 'fhir/r5';
3
- export type Binary = R4B.Binary | R5.Binary;
4
- export type FhirResource = R4B.FhirResource | R5.FhirResource;
5
- export type Resource = R4B.Resource | R5.Resource;
6
- export type Bundle<BundleContentType = FhirResource> = R4B.Bundle<BundleContentType> | R5.Bundle<BundleContentType>;
7
- export type BundleEntry<BundleContentType = FhirResource> = R4B.BundleEntry<BundleContentType> | R5.BundleEntry<BundleContentType>;
8
- export type Address = R4B.Address | R5.Address;
9
- export type HumanName = R4B.HumanName | R5.HumanName;
@@ -1,2 +0,0 @@
1
- export * from './utils';
2
- export * from './fhir-types';
@@ -1,14 +0,0 @@
1
- import { Address, HumanName } from './fhir-types';
2
- export interface AddressFormatOptions {
3
- all?: boolean;
4
- use?: boolean;
5
- lineSeparator?: string;
6
- }
7
- export interface HumanNameFormatOptions {
8
- all?: boolean;
9
- prefix?: boolean;
10
- suffix?: boolean;
11
- use?: boolean;
12
- }
13
- export declare function formatAddress(address: Address, options?: AddressFormatOptions): string;
14
- export declare function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string;
@@ -1,9 +0,0 @@
1
- import * as R4B from 'fhir/r4b';
2
- import * as R5 from 'fhir/r5';
3
- export type Binary = R4B.Binary | R5.Binary;
4
- export type FhirResource = R4B.FhirResource | R5.FhirResource;
5
- export type Resource = R4B.Resource | R5.Resource;
6
- export type Bundle<BundleContentType = FhirResource> = R4B.Bundle<BundleContentType> | R5.Bundle<BundleContentType>;
7
- export type BundleEntry<BundleContentType = FhirResource> = R4B.BundleEntry<BundleContentType> | R5.BundleEntry<BundleContentType>;
8
- export type Address = R4B.Address | R5.Address;
9
- export type HumanName = R4B.HumanName | R5.HumanName;
@@ -1,2 +0,0 @@
1
- export * from './utils';
2
- export * from './fhir-types';
@@ -1,14 +0,0 @@
1
- import { Address, HumanName } from './fhir-types';
2
- export interface AddressFormatOptions {
3
- all?: boolean;
4
- use?: boolean;
5
- lineSeparator?: string;
6
- }
7
- export interface HumanNameFormatOptions {
8
- all?: boolean;
9
- prefix?: boolean;
10
- suffix?: boolean;
11
- use?: boolean;
12
- }
13
- export declare function formatAddress(address: Address, options?: AddressFormatOptions): string;
14
- export declare function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string;
@@ -1,15 +0,0 @@
1
- import * as R4B from 'fhir/r4b';
2
- import * as R5 from 'fhir/r5';
3
-
4
- // Resources
5
- export type Binary = R4B.Binary | R5.Binary;
6
- export type FhirResource = R4B.FhirResource | R5.FhirResource;
7
- export type Resource = R4B.Resource | R5.Resource;
8
- export type Bundle<BundleContentType = FhirResource> = R4B.Bundle<BundleContentType> | R5.Bundle<BundleContentType>;
9
- export type BundleEntry<BundleContentType = FhirResource> =
10
- | R4B.BundleEntry<BundleContentType>
11
- | R5.BundleEntry<BundleContentType>;
12
-
13
- // DataTypes
14
- export type Address = R4B.Address | R5.Address;
15
- export type HumanName = R4B.HumanName | R5.HumanName;
package/src/fhir/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './utils';
2
- export * from './fhir-types';
package/src/fhir/utils.ts DELETED
@@ -1,68 +0,0 @@
1
- import { Address, HumanName } from './fhir-types';
2
-
3
- export interface AddressFormatOptions {
4
- all?: boolean;
5
- use?: boolean;
6
- lineSeparator?: string;
7
- }
8
-
9
- export interface HumanNameFormatOptions {
10
- all?: boolean;
11
- prefix?: boolean;
12
- suffix?: boolean;
13
- use?: boolean;
14
- }
15
-
16
- export function formatAddress(address: Address, options?: AddressFormatOptions): string {
17
- const builder = [];
18
-
19
- if (address.line) {
20
- builder.push(...address.line);
21
- }
22
-
23
- if (address.city || address.state || address.postalCode) {
24
- const cityStateZip = [];
25
- if (address.city) {
26
- cityStateZip.push(address.city);
27
- }
28
- if (address.state) {
29
- cityStateZip.push(address.state);
30
- }
31
- if (address.postalCode) {
32
- cityStateZip.push(address.postalCode);
33
- }
34
- builder.push(cityStateZip.join(', '));
35
- }
36
-
37
- if (address.use && (options?.all || options?.use)) {
38
- builder.push('[' + address.use + ']');
39
- }
40
-
41
- return builder.join(options?.lineSeparator || ', ').trim();
42
- }
43
-
44
- export function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string {
45
- const builder = [];
46
-
47
- if (name.prefix && options?.prefix !== false) {
48
- builder.push(...name.prefix);
49
- }
50
-
51
- if (name.given) {
52
- builder.push(...name.given);
53
- }
54
-
55
- if (name.family) {
56
- builder.push(name.family);
57
- }
58
-
59
- if (name.suffix && options?.suffix !== false) {
60
- builder.push(...name.suffix);
61
- }
62
-
63
- if (name.use && (options?.all || options?.use)) {
64
- builder.push('[' + name.use + ']');
65
- }
66
-
67
- return builder.join(' ').trim();
68
- }