@medplum/core 0.9.1 → 0.9.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.
package/dist/esm/index.js CHANGED
@@ -395,33 +395,59 @@ function isEmpty(v) {
395
395
  /**
396
396
  * Resource equality.
397
397
  * Ignores meta.versionId and meta.lastUpdated.
398
- * See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality
399
398
  * @param object1 The first object.
400
399
  * @param object2 The second object.
401
400
  * @returns True if the objects are equal.
402
401
  */
403
402
  function deepEquals(object1, object2, path) {
404
- let keys1 = Object.keys(object1);
405
- let keys2 = Object.keys(object2);
406
- if (path === 'meta') {
407
- keys1 = keys1.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
408
- keys2 = keys2.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
403
+ if (object1 === object2) {
404
+ return true;
405
+ }
406
+ if (isEmpty(object1) && isEmpty(object2)) {
407
+ return true;
408
+ }
409
+ if (isEmpty(object1) || isEmpty(object2)) {
410
+ return false;
409
411
  }
410
- if (keys1.length !== keys2.length) {
412
+ if (Array.isArray(object1) && Array.isArray(object2)) {
413
+ return deepEqualsArray(object1, object2);
414
+ }
415
+ if (Array.isArray(object1) || Array.isArray(object2)) {
416
+ return false;
417
+ }
418
+ if (isObject(object1) && isObject(object2)) {
419
+ return deepEqualsObject(object1, object2, path);
420
+ }
421
+ if (isObject(object1) || isObject(object2)) {
411
422
  return false;
412
423
  }
413
- for (const key of keys1) {
424
+ return false;
425
+ }
426
+ function deepEqualsArray(array1, array2) {
427
+ if (array1.length !== array2.length) {
428
+ return false;
429
+ }
430
+ for (let i = 0; i < array1.length; i++) {
431
+ if (!deepEquals(array1[i], array2[i])) {
432
+ return false;
433
+ }
434
+ }
435
+ return true;
436
+ }
437
+ function deepEqualsObject(object1, object2, path) {
438
+ const keySet = new Set();
439
+ Object.keys(object1).forEach((k) => keySet.add(k));
440
+ Object.keys(object2).forEach((k) => keySet.add(k));
441
+ if (path === 'meta') {
442
+ keySet.delete('versionId');
443
+ keySet.delete('lastUpdated');
444
+ keySet.delete('author');
445
+ }
446
+ for (const key of keySet) {
414
447
  const val1 = object1[key];
415
448
  const val2 = object2[key];
416
- if (isObject(val1) && isObject(val2)) {
417
- if (!deepEquals(val1, val2, key)) {
418
- return false;
419
- }
420
- }
421
- else {
422
- if (val1 !== val2) {
423
- return false;
424
- }
449
+ if (!deepEquals(val1, val2, key)) {
450
+ return false;
425
451
  }
426
452
  }
427
453
  return true;
@@ -719,6 +745,7 @@ class OperationOutcomeError extends Error {
719
745
  }
720
746
  }
721
747
 
748
+ const DEFAULT_SEARCH_COUNT = 20;
722
749
  /**
723
750
  * Search operators.
724
751
  * These operators represent "modifiers" and "prefixes" in FHIR search.
@@ -786,15 +813,15 @@ function parseSearchDefinition(url) {
786
813
  let filters = undefined;
787
814
  let sortRules = undefined;
788
815
  let fields = undefined;
789
- let page = undefined;
816
+ let offset = undefined;
790
817
  let count = undefined;
791
818
  let total = undefined;
792
819
  params.forEach((value, key) => {
793
820
  if (key === '_fields') {
794
821
  fields = value.split(',');
795
822
  }
796
- else if (key === '_page') {
797
- page = parseInt(value);
823
+ else if (key === '_offset') {
824
+ offset = parseInt(value);
798
825
  }
799
826
  else if (key === '_count') {
800
827
  count = parseInt(value);
@@ -815,7 +842,7 @@ function parseSearchDefinition(url) {
815
842
  resourceType,
816
843
  filters,
817
844
  fields,
818
- page,
845
+ offset,
819
846
  count,
820
847
  total,
821
848
  sortRules,
@@ -891,13 +918,13 @@ function formatSearchQuery(definition) {
891
918
  if (definition.sortRules && definition.sortRules.length > 0) {
892
919
  params.push(formatSortRules(definition.sortRules));
893
920
  }
894
- if (definition.page && definition.page > 0) {
895
- params.push('_page=' + definition.page);
921
+ if (definition.offset !== undefined) {
922
+ params.push('_offset=' + definition.offset);
896
923
  }
897
- if (definition.count && definition.count > 0) {
924
+ if (definition.count !== undefined) {
898
925
  params.push('_count=' + definition.count);
899
926
  }
900
- if (definition.total) {
927
+ if (definition.total !== undefined) {
901
928
  params.push('_total=' + encodeURIComponent(definition.total));
902
929
  }
903
930
  if (params.length === 0) {
@@ -2114,7 +2141,7 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
2114
2141
  return undefined;
2115
2142
  }
2116
2143
  const obj = yield response.json();
2117
- if (obj.resourceType === 'OperationOutcome' && !isOk(obj)) {
2144
+ if ((obj === null || obj === void 0 ? void 0 : obj.resourceType) === 'OperationOutcome' && !isOk(obj)) {
2118
2145
  return Promise.reject(obj);
2119
2146
  }
2120
2147
  return obj;
@@ -2705,5 +2732,5 @@ function simplifyExpression(input) {
2705
2732
  return result;
2706
2733
  }
2707
2734
 
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 };
2735
+ export { COMPONENT_SEPARATOR, DEFAULT_SEARCH_COUNT, 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 };
2709
2736
  //# sourceMappingURL=index.js.map