@oystehr/sdk 3.0.1 → 3.0.3

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.
Files changed (47) hide show
  1. package/dist/cjs/client/client.d.ts +2 -1
  2. package/dist/cjs/index.cjs +106 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.min.cjs +1 -1
  5. package/dist/cjs/index.min.cjs.map +1 -1
  6. package/dist/cjs/resources/classes/fhir-ext.d.ts +13 -0
  7. package/dist/cjs/resources/classes/fhir.d.ts +2 -0
  8. package/dist/cjs/resources/classes/z3-ext.d.ts +22 -0
  9. package/dist/cjs/resources/classes/z3.d.ts +15 -0
  10. package/dist/cjs/resources/types/ZambdaCreateParams.d.ts +1 -1
  11. package/dist/cjs/resources/types/fhir.d.ts +6 -3
  12. package/dist/esm/client/client.d.ts +2 -1
  13. package/dist/esm/client/client.js +1 -1
  14. package/dist/esm/client/client.js.map +1 -1
  15. package/dist/esm/index.min.js +1 -1
  16. package/dist/esm/index.min.js.map +1 -1
  17. package/dist/esm/resources/classes/fhir-ext.d.ts +13 -0
  18. package/dist/esm/resources/classes/fhir-ext.js +44 -2
  19. package/dist/esm/resources/classes/fhir-ext.js.map +1 -1
  20. package/dist/esm/resources/classes/fhir.d.ts +2 -0
  21. package/dist/esm/resources/classes/fhir.js +3 -1
  22. package/dist/esm/resources/classes/fhir.js.map +1 -1
  23. package/dist/esm/resources/classes/z3-ext.d.ts +22 -0
  24. package/dist/esm/resources/classes/z3-ext.js +49 -1
  25. package/dist/esm/resources/classes/z3-ext.js.map +1 -1
  26. package/dist/esm/resources/classes/z3.d.ts +15 -0
  27. package/dist/esm/resources/classes/z3.js +16 -1
  28. package/dist/esm/resources/classes/z3.js.map +1 -1
  29. package/dist/esm/resources/types/ZambdaCreateParams.d.ts +1 -1
  30. package/dist/esm/resources/types/fhir.d.ts +6 -3
  31. package/package.json +1 -1
  32. package/src/client/client.ts +2 -2
  33. package/src/resources/classes/fhir-ext.ts +69 -1
  34. package/src/resources/classes/fhir.ts +2 -0
  35. package/src/resources/classes/z3-ext.ts +48 -1
  36. package/src/resources/classes/z3.ts +15 -0
  37. package/src/resources/types/ZambdaCreateParams.ts +1 -1
  38. package/src/resources/types/fhir.ts +4 -3
  39. package/dist/cjs/fhir/fhir-types.d.ts +0 -9
  40. package/dist/cjs/fhir/index.d.ts +0 -2
  41. package/dist/cjs/fhir/utils.d.ts +0 -14
  42. package/dist/esm/fhir/fhir-types.d.ts +0 -9
  43. package/dist/esm/fhir/index.d.ts +0 -2
  44. package/dist/esm/fhir/utils.d.ts +0 -14
  45. package/src/fhir/fhir-types.ts +0 -15
  46. package/src/fhir/index.ts +0 -2
  47. package/src/fhir/utils.ts +0 -68
@@ -1,5 +1,6 @@
1
1
  import { OystehrConfig } from '../config';
2
2
  import { FhirBundle, FhirResource } from '../resources/types';
3
+ export declare const defaultProjectApiUrl = "https://project-api.zapehr.com/v1";
3
4
  /**
4
5
  * Optional parameter that can be passed to the client methods. It allows
5
6
  * overriding the access token or project ID, and setting various headers,
@@ -29,7 +30,7 @@ interface InternalClientRequest extends OystehrClientRequest {
29
30
  type FhirData<T extends FhirResource> = T | T[] | FhirBundle<T>;
30
31
  export type FhirFetcherResponse<T extends FhirData<FhirResource> = any> = T;
31
32
  export declare class SDKResource {
32
- private readonly config;
33
+ protected readonly config: OystehrConfig;
33
34
  constructor(config: OystehrConfig);
34
35
  protected request(path: string, method: string): FetcherFunction;
35
36
  protected fhirRequest<T extends FhirResource = any>(path: string, method: string): (params: any, request?: InternalClientRequest) => Promise<FhirFetcherResponse<T>>;
@@ -590,7 +590,7 @@ function search(params, request) {
590
590
  }, {});
591
591
  }
592
592
  const requestBundle = yield this.fhirRequest(`/${resourceType}/_search`, 'POST')(paramMap, Object.assign(Object.assign({}, request), { contentType: 'application/x-www-form-urlencoded' }));
593
- const bundle = Object.assign(Object.assign({}, requestBundle), { unbundle: function () {
593
+ const bundle = Object.assign(Object.assign({}, requestBundle), { entry: requestBundle.entry, unbundle: function () {
594
594
  var _a, _b;
595
595
  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 : [];
596
596
  } });
@@ -694,6 +694,48 @@ function bundleRequest(type) {
694
694
  }
695
695
  const batch = bundleRequest('batch');
696
696
  const transaction = bundleRequest('transaction');
697
+ function formatAddress(address, options) {
698
+ const builder = [];
699
+ if (address.line) {
700
+ builder.push(...address.line);
701
+ }
702
+ if (address.city || address.state || address.postalCode) {
703
+ const cityStateZip = [];
704
+ if (address.city) {
705
+ cityStateZip.push(address.city);
706
+ }
707
+ if (address.state) {
708
+ cityStateZip.push(address.state);
709
+ }
710
+ if (address.postalCode) {
711
+ cityStateZip.push(address.postalCode);
712
+ }
713
+ builder.push(cityStateZip.join(', '));
714
+ }
715
+ if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
716
+ builder.push('[' + address.use + ']');
717
+ }
718
+ return builder.join((options === null || options === void 0 ? void 0 : options.lineSeparator) || ', ').trim();
719
+ }
720
+ function formatHumanName(name, options) {
721
+ const builder = [];
722
+ if (name.prefix && (options === null || options === void 0 ? void 0 : options.prefix) !== false) {
723
+ builder.push(...name.prefix);
724
+ }
725
+ if (name.given) {
726
+ builder.push(...name.given);
727
+ }
728
+ if (name.family) {
729
+ builder.push(name.family);
730
+ }
731
+ if (name.suffix && (options === null || options === void 0 ? void 0 : options.suffix) !== false) {
732
+ builder.push(...name.suffix);
733
+ }
734
+ if (name.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
735
+ builder.push('[' + name.use + ']');
736
+ }
737
+ return builder.join(' ').trim();
738
+ }
697
739
 
698
740
  // AUTOGENERATED -- DO NOT EDIT
699
741
  class Fhir extends SDKResource {
@@ -714,6 +756,8 @@ class Fhir extends SDKResource {
714
756
  this.history = history;
715
757
  this.batch = batch;
716
758
  this.transaction = transaction;
759
+ this.formatAddress = formatAddress;
760
+ this.formatHumanName = formatHumanName;
717
761
  }
718
762
  }
719
763
 
@@ -1117,6 +1161,11 @@ class Version extends SDKResource {
1117
1161
  }
1118
1162
  }
1119
1163
 
1164
+ /**
1165
+ * Uploads a file to the bucket and key. Files should be Blobs.
1166
+ *
1167
+ * @param params upload file params
1168
+ */
1120
1169
  function uploadFile$1({ bucketName, 'objectPath+': key, file, }) {
1121
1170
  return __awaiter(this, void 0, void 0, function* () {
1122
1171
  const uploadUrl = yield this.request('/z3/{bucketName}/{objectPath+}', 'post')({
@@ -1130,6 +1179,11 @@ function uploadFile$1({ bucketName, 'objectPath+': key, file, }) {
1130
1179
  });
1131
1180
  });
1132
1181
  }
1182
+ /**
1183
+ * Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
1184
+ *
1185
+ * @param params download file params
1186
+ */
1133
1187
  function downloadFile({ bucketName, 'objectPath+': key, }) {
1134
1188
  return __awaiter(this, void 0, void 0, function* () {
1135
1189
  const uploadUrl = yield this.request('/z3/{bucketName}/{objectPath+}', 'post')({
@@ -1146,13 +1200,64 @@ function downloadFile({ bucketName, 'objectPath+': key, }) {
1146
1200
  return resp.arrayBuffer();
1147
1201
  });
1148
1202
  }
1203
+ /**
1204
+ * This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
1205
+ * `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` or `z3://<bucket>/<key>`
1206
+ * instead of the standard SDK `Z3GetPresignedUrlParams`.
1207
+ *
1208
+ * @param params url and action
1209
+ */
1210
+ function getPresignedUrlForZ3Url(params) {
1211
+ var _a;
1212
+ return __awaiter(this, void 0, void 0, function* () {
1213
+ let bucket;
1214
+ let key;
1215
+ const url = new URL(params.url);
1216
+ if (url.protocol === 'z3:') {
1217
+ // remove leading forward slash
1218
+ const z3PathParts = url.pathname.split('/').slice(1);
1219
+ bucket = url.hostname;
1220
+ key = z3PathParts.join('/');
1221
+ }
1222
+ else if (url.href.startsWith((_a = this.config.projectApiUrl) !== null && _a !== void 0 ? _a : defaultProjectApiUrl)) {
1223
+ // remove leading `/v1/z3`
1224
+ const httpsPathParts = url.pathname.split('/').slice(3);
1225
+ bucket = httpsPathParts[0];
1226
+ key = httpsPathParts.slice(1).join('/');
1227
+ }
1228
+ else {
1229
+ throw new OystehrSdkError({ message: 'Invalid Z3 URL', code: 400 });
1230
+ }
1231
+ const requestParams = {
1232
+ action: 'upload',
1233
+ bucketName: bucket,
1234
+ 'objectPath+': key,
1235
+ };
1236
+ return this.request('/z3/{bucketName}/{objectPath+}', 'post')(requestParams);
1237
+ });
1238
+ }
1149
1239
 
1150
1240
  // AUTOGENERATED -- DO NOT EDIT
1151
1241
  class Z3 extends SDKResource {
1152
1242
  constructor(config) {
1153
1243
  super(config);
1244
+ /**
1245
+ * Uploads a file to the bucket and key. Files should be Blobs.
1246
+ * @param params upload file params
1247
+ */
1154
1248
  this.uploadFile = uploadFile$1;
1249
+ /**
1250
+ * Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
1251
+ * @param params download file params
1252
+ */
1155
1253
  this.downloadFile = downloadFile;
1254
+ /**
1255
+ * This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
1256
+ * `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` * or `z3://<bucket>/<key>`
1257
+ * instead of the standard SDK `Z3GetPresignedUrlParams`.
1258
+ * @param params url and action
1259
+ */
1260
+ this.getPresignedUrlForZ3Url = getPresignedUrlForZ3Url;
1156
1261
  /**
1157
1262
  * List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.
1158
1263
  *