@medplum/core 0.9.0 → 0.9.1

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 (48) hide show
  1. package/dist/cjs/index.js +174 -3
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/index.min.js +1 -15
  4. package/dist/cjs/index.min.js.map +1 -1
  5. package/dist/esm/index.js +165 -4
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/index.min.js +1 -15
  8. package/dist/esm/index.min.js.map +1 -1
  9. package/dist/types/client.d.ts +1 -1
  10. package/dist/types/hl7.d.ts +43 -0
  11. package/dist/types/index.d.ts +1 -0
  12. package/dist/types/utils.d.ts +26 -1
  13. package/package.json +2 -2
  14. package/docs/.nojekyll +0 -1
  15. package/docs/assets/highlight.css +0 -92
  16. package/docs/assets/icons.css +0 -1043
  17. package/docs/assets/icons.png +0 -0
  18. package/docs/assets/icons@2x.png +0 -0
  19. package/docs/assets/main.js +0 -52
  20. package/docs/assets/search.js +0 -1
  21. package/docs/assets/style.css +0 -1414
  22. package/docs/assets/widgets.png +0 -0
  23. package/docs/assets/widgets@2x.png +0 -0
  24. package/docs/classes/LegacyRepositoryClient.html +0 -71
  25. package/docs/classes/MedplumClient.html +0 -324
  26. package/docs/classes/OperationOutcomeError.html +0 -6
  27. package/docs/enums/Operator.html +0 -5
  28. package/docs/enums/PropertyType.html +0 -5
  29. package/docs/enums/SearchParameterType.html +0 -1
  30. package/docs/index.html +0 -89
  31. package/docs/interfaces/AddressFormatOptions.html +0 -1
  32. package/docs/interfaces/FetchLike.html +0 -1
  33. package/docs/interfaces/Filter.html +0 -1
  34. package/docs/interfaces/GoogleCredentialResponse.html +0 -1
  35. package/docs/interfaces/HumanNameFormatOptions.html +0 -1
  36. package/docs/interfaces/IndexedStructureDefinition.html +0 -19
  37. package/docs/interfaces/LoginAuthenticationResponse.html +0 -1
  38. package/docs/interfaces/LoginProfileResponse.html +0 -1
  39. package/docs/interfaces/LoginScopeResponse.html +0 -1
  40. package/docs/interfaces/LoginState.html +0 -1
  41. package/docs/interfaces/MedplumClientOptions.html +0 -33
  42. package/docs/interfaces/RegisterRequest.html +0 -1
  43. package/docs/interfaces/SearchParameterDetails.html +0 -1
  44. package/docs/interfaces/SearchRequest.html +0 -1
  45. package/docs/interfaces/SortRule.html +0 -1
  46. package/docs/interfaces/TokenResponse.html +0 -1
  47. package/docs/interfaces/TypeSchema.html +0 -10
  48. package/docs/modules.html +0 -138
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! *****************************************************************************
1
+ /******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -309,6 +309,47 @@ function calculateAgeString(birthDateStr, endDateStr) {
309
309
  return days.toString().padStart(3, '0') + 'D';
310
310
  }
311
311
  }
312
+ /**
313
+ * Returns all questionnaire answers as a map by link ID.
314
+ * @param response The questionnaire response resource.
315
+ * @returns Questionnaire answers mapped by link ID.
316
+ */
317
+ function getQuestionnaireAnswers(response) {
318
+ const result = {};
319
+ buildQuestionnaireAnswerItems(response.item, result);
320
+ return result;
321
+ }
322
+ /**
323
+ * Recursively builds the questionnaire answer items map.
324
+ * @param item The current questionnaire response item.
325
+ * @param result The cumulative result map.
326
+ */
327
+ function buildQuestionnaireAnswerItems(items, result) {
328
+ if (items) {
329
+ for (const item of items) {
330
+ if (item.linkId && item.answer && item.answer.length > 0) {
331
+ result[item.linkId] = item.answer[0];
332
+ }
333
+ buildQuestionnaireAnswerItems(item.item, result);
334
+ }
335
+ }
336
+ }
337
+ /**
338
+ * Returns an extension value by extension URLs.
339
+ * @param resource The base resource.
340
+ * @param urls Array of extension URLs. Each entry represents a nested extension.
341
+ * @returns The extension value if found; undefined otherwise.
342
+ */
343
+ function getExtensionValue(resource, ...urls) {
344
+ var _a;
345
+ // Let curr be the current resource or extension. Extensions can be nested.
346
+ let curr = resource;
347
+ // For each of the urls, try to find a matching nested extension.
348
+ for (let i = 0; i < urls.length && curr; i++) {
349
+ curr = (_a = curr === null || curr === void 0 ? void 0 : curr.extension) === null || _a === void 0 ? void 0 : _a.find((e) => e.url === urls[i]);
350
+ }
351
+ return curr === null || curr === void 0 ? void 0 : curr.valueString;
352
+ }
312
353
  /**
313
354
  * FHIR JSON stringify.
314
355
  * Removes properties with empty string values.
@@ -385,8 +426,21 @@ function deepEquals(object1, object2, path) {
385
426
  }
386
427
  return true;
387
428
  }
388
- function isObject(object) {
389
- return object !== null && typeof object === 'object';
429
+ /**
430
+ * Returns true if the input is an object.
431
+ * @param object The candidate object.
432
+ * @returns True if the input is a non-null non-undefined object.
433
+ */
434
+ function isObject(obj) {
435
+ return obj !== null && typeof obj === 'object';
436
+ }
437
+ /**
438
+ * Returns true if the input array is an array of strings.
439
+ * @param arr Input array.
440
+ * @returns True if the input array is an array of strings.
441
+ */
442
+ function isStringArray(arr) {
443
+ return arr.every((e) => typeof e === 'string');
390
444
  }
391
445
  // Precompute hex octets
392
446
  // See: https://stackoverflow.com/a/55200387
@@ -2215,6 +2269,113 @@ function getBaseUrl() {
2215
2269
  return window.location.protocol + '//' + window.location.host + '/';
2216
2270
  }
2217
2271
 
2272
+ const SEGMENT_SEPARATOR = '\r';
2273
+ const FIELD_SEPARATOR = '|';
2274
+ const COMPONENT_SEPARATOR = '^';
2275
+ /**
2276
+ * The Hl7Message class represents one HL7 message.
2277
+ * A message is a collection of segments.
2278
+ * Note that we do not strictly parse messages, and only use default delimeters.
2279
+ */
2280
+ class Hl7Message {
2281
+ constructor(segments) {
2282
+ this.segments = segments;
2283
+ }
2284
+ get(index) {
2285
+ if (typeof index === 'number') {
2286
+ return this.segments[index];
2287
+ }
2288
+ return this.segments.find((s) => s.name === index);
2289
+ }
2290
+ getAll(name) {
2291
+ return this.segments.filter((s) => s.name === name);
2292
+ }
2293
+ toString() {
2294
+ return this.segments.map((s) => s.toString()).join(SEGMENT_SEPARATOR);
2295
+ }
2296
+ buildAck() {
2297
+ var _a, _b, _c, _d, _e, _f;
2298
+ const now = new Date();
2299
+ const msh = this.get('MSH');
2300
+ const sendingApp = ((_a = msh === null || msh === void 0 ? void 0 : msh.get(2)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
2301
+ const sendingFacility = ((_b = msh === null || msh === void 0 ? void 0 : msh.get(3)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
2302
+ const receivingApp = ((_c = msh === null || msh === void 0 ? void 0 : msh.get(4)) === null || _c === void 0 ? void 0 : _c.toString()) || '';
2303
+ const receivingFacility = ((_d = msh === null || msh === void 0 ? void 0 : msh.get(5)) === null || _d === void 0 ? void 0 : _d.toString()) || '';
2304
+ const controlId = ((_e = msh === null || msh === void 0 ? void 0 : msh.get(9)) === null || _e === void 0 ? void 0 : _e.toString()) || '';
2305
+ const versionId = ((_f = msh === null || msh === void 0 ? void 0 : msh.get(12)) === null || _f === void 0 ? void 0 : _f.toString()) || '2.5.1';
2306
+ return new Hl7Message([
2307
+ new Hl7Segment([
2308
+ 'MSH',
2309
+ '^~\\&',
2310
+ receivingApp,
2311
+ receivingFacility,
2312
+ sendingApp,
2313
+ sendingFacility,
2314
+ now.toISOString(),
2315
+ '',
2316
+ 'ACK',
2317
+ now.getTime().toString(),
2318
+ 'P',
2319
+ versionId,
2320
+ ]),
2321
+ new Hl7Segment(['MSA', 'AA', controlId, 'OK']),
2322
+ ]);
2323
+ }
2324
+ static parse(text) {
2325
+ if (!text.startsWith('MSH|^~\\&')) {
2326
+ const err = new Error('Invalid HL7 message');
2327
+ err.type = 'entity.parse.failed';
2328
+ throw err;
2329
+ }
2330
+ return new Hl7Message(text.split(/[\r\n]+/).map((line) => Hl7Segment.parse(line)));
2331
+ }
2332
+ }
2333
+ /**
2334
+ * The Hl7Segment class represents one HL7 segment.
2335
+ * A segment is a collection of fields.
2336
+ * The name field is the first field.
2337
+ * Note that we do not strictly parse messages, and only use default delimeters.
2338
+ */
2339
+ class Hl7Segment {
2340
+ constructor(fields) {
2341
+ if (isStringArray(fields)) {
2342
+ this.fields = fields.map((f) => Hl7Field.parse(f));
2343
+ }
2344
+ else {
2345
+ this.fields = fields;
2346
+ }
2347
+ this.name = this.fields[0].components[0];
2348
+ }
2349
+ get(index) {
2350
+ return this.fields[index];
2351
+ }
2352
+ toString() {
2353
+ return this.fields.map((f) => f.toString()).join(FIELD_SEPARATOR);
2354
+ }
2355
+ static parse(text) {
2356
+ return new Hl7Segment(text.split(FIELD_SEPARATOR).map((f) => Hl7Field.parse(f)));
2357
+ }
2358
+ }
2359
+ /**
2360
+ * The Hl7Field class represents one HL7 field.
2361
+ * A field is a collection of components.
2362
+ * Note that we do not strictly parse messages, and only use default delimeters.
2363
+ */
2364
+ class Hl7Field {
2365
+ constructor(components) {
2366
+ this.components = components;
2367
+ }
2368
+ get(index) {
2369
+ return this.components[index];
2370
+ }
2371
+ toString() {
2372
+ return this.components.join(COMPONENT_SEPARATOR);
2373
+ }
2374
+ static parse(text) {
2375
+ return new Hl7Field(text.split(COMPONENT_SEPARATOR));
2376
+ }
2377
+ }
2378
+
2218
2379
  var _LegacyRepositoryClient_client;
2219
2380
  /**
2220
2381
  * The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
@@ -2544,5 +2705,5 @@ function simplifyExpression(input) {
2544
2705
  return result;
2545
2706
  }
2546
2707
 
2547
- export { LegacyRepositoryClient, MedplumClient, OperationOutcomeError, Operator, PropertyType, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getImageSrc, getPropertyDisplayName, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isOk, isProfileResource, notFound, notModified, parseSearchDefinition, resolveId, stringify };
2708
+ export { COMPONENT_SEPARATOR, FIELD_SEPARATOR, Hl7Field, Hl7Message, Hl7Segment, LegacyRepositoryClient, MedplumClient, OperationOutcomeError, Operator, PropertyType, SEGMENT_SEPARATOR, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getExtensionValue, getImageSrc, getPropertyDisplayName, getQuestionnaireAnswers, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isObject, isOk, isProfileResource, isStringArray, notFound, notModified, parseSearchDefinition, resolveId, stringify };
2548
2709
  //# sourceMappingURL=index.js.map