@medplum/core 0.10.1 → 0.10.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/cjs/index.js CHANGED
@@ -807,12 +807,7 @@
807
807
  * @returns True if the two numbers are equal to the given precision.
808
808
  */
809
809
  function preciseEquals(a, b, precision) {
810
- if (precision) {
811
- return Math.abs(a - b) < Math.pow(10, -precision);
812
- }
813
- else {
814
- return a === b;
815
- }
810
+ return toPreciseInteger(a, precision) === toPreciseInteger(b, precision);
816
811
  }
817
812
  /**
818
813
  * Returns true if the first number is less than the second number to the given precision.
@@ -822,12 +817,7 @@
822
817
  * @returns True if the first number is less than the second number to the given precision.
823
818
  */
824
819
  function preciseLessThan(a, b, precision) {
825
- if (precision) {
826
- return a < b && Math.abs(a - b) > Math.pow(10, -precision);
827
- }
828
- else {
829
- return a < b;
830
- }
820
+ return toPreciseInteger(a, precision) < toPreciseInteger(b, precision);
831
821
  }
832
822
  /**
833
823
  * Returns true if the first number is greater than the second number to the given precision.
@@ -837,12 +827,7 @@
837
827
  * @returns True if the first number is greater than the second number to the given precision.
838
828
  */
839
829
  function preciseGreaterThan(a, b, precision) {
840
- if (precision) {
841
- return a > b && Math.abs(a - b) > Math.pow(10, -precision);
842
- }
843
- else {
844
- return a > b;
845
- }
830
+ return toPreciseInteger(a, precision) > toPreciseInteger(b, precision);
846
831
  }
847
832
  /**
848
833
  * Returns true if the first number is less than or equal to the second number to the given precision.
@@ -852,7 +837,7 @@
852
837
  * @returns True if the first number is less than or equal to the second number to the given precision.
853
838
  */
854
839
  function preciseLessThanOrEquals(a, b, precision) {
855
- return preciseLessThan(a, b, precision) || preciseEquals(a, b, precision);
840
+ return toPreciseInteger(a, precision) <= toPreciseInteger(b, precision);
856
841
  }
857
842
  /**
858
843
  * Returns true if the first number is greater than or equal to the second number to the given precision.
@@ -862,7 +847,20 @@
862
847
  * @returns True if the first number is greater than or equal to the second number to the given precision.
863
848
  */
864
849
  function preciseGreaterThanOrEquals(a, b, precision) {
865
- return preciseGreaterThan(a, b, precision) || preciseEquals(a, b, precision);
850
+ return toPreciseInteger(a, precision) >= toPreciseInteger(b, precision);
851
+ }
852
+ /**
853
+ * Returns an integer representation of the number with the given precision.
854
+ * For example, if precision is 2, then 1.2345 will be returned as 123.
855
+ * @param a The number.
856
+ * @param precision Optional precision in number of digits.
857
+ * @returns The integer with the given precision.
858
+ */
859
+ function toPreciseInteger(a, precision) {
860
+ if (precision === undefined) {
861
+ return a;
862
+ }
863
+ return Math.round(a * Math.pow(10, precision));
866
864
  }
867
865
 
868
866
  /**
@@ -6082,6 +6080,7 @@
6082
6080
  /**
6083
6081
  * Indexes a bundle of StructureDefinitions for faster lookup.
6084
6082
  * @param bundle A FHIR bundle StructureDefinition resources.
6083
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6085
6084
  */
6086
6085
  function indexStructureDefinitionBundle(bundle) {
6087
6086
  for (const entry of bundle.entry) {
@@ -6093,8 +6092,8 @@
6093
6092
  }
6094
6093
  /**
6095
6094
  * Indexes a StructureDefinition for fast lookup.
6096
- * See comments on IndexedStructureDefinition for more details.
6097
6095
  * @param structureDefinition The original StructureDefinition.
6096
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6098
6097
  */
6099
6098
  function indexStructureDefinition(structureDefinition) {
6100
6099
  var _a;
@@ -6114,8 +6113,9 @@
6114
6113
  * Indexes TypeSchema from an ElementDefinition.
6115
6114
  * In the common case, there will be many ElementDefinition instances per TypeSchema.
6116
6115
  * Only the first occurrence is saved.
6117
- * @param schema The output IndexedStructureDefinition.
6118
- * @param element The input ElementDefinition.
6116
+ * @param structureDefinition The parent type structure definition.
6117
+ * @param elementDefinition The element definition.
6118
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6119
6119
  */
6120
6120
  function indexType(structureDefinition, elementDefinition) {
6121
6121
  var _a, _b;
@@ -6131,8 +6131,8 @@
6131
6131
  }
6132
6132
  /**
6133
6133
  * Indexes PropertySchema from an ElementDefinition.
6134
- * @param schema The output IndexedStructureDefinition.
6135
6134
  * @param element The input ElementDefinition.
6135
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6136
6136
  */
6137
6137
  function indexProperty(element) {
6138
6138
  const path = element.path;
@@ -6148,11 +6148,24 @@
6148
6148
  const key = parts[parts.length - 1];
6149
6149
  typeSchema.properties[key] = element;
6150
6150
  }
6151
+ /**
6152
+ * Indexes a bundle of SearchParameter resources for faster lookup.
6153
+ * @param bundle A FHIR bundle SearchParameter resources.
6154
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6155
+ */
6156
+ function indexSearchParameterBundle(bundle) {
6157
+ for (const entry of bundle.entry) {
6158
+ const resource = entry.resource;
6159
+ if (resource.resourceType === 'SearchParameter') {
6160
+ indexSearchParameter(resource);
6161
+ }
6162
+ }
6163
+ }
6151
6164
  /**
6152
6165
  * Indexes a SearchParameter resource for fast lookup.
6153
6166
  * Indexes by SearchParameter.code, which is the query string parameter name.
6154
- * @param schema The output IndexedStructureDefinition.
6155
6167
  * @param searchParam The SearchParameter resource.
6168
+ * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6156
6169
  */
6157
6170
  function indexSearchParameter(searchParam) {
6158
6171
  if (!searchParam.base) {
@@ -6177,6 +6190,12 @@
6177
6190
  type: 'date',
6178
6191
  expression: resourceType + '.meta.lastUpdated',
6179
6192
  },
6193
+ _compartment: {
6194
+ base: [resourceType],
6195
+ code: '_compartment',
6196
+ type: 'reference',
6197
+ expression: resourceType + '.meta.compartment',
6198
+ },
6180
6199
  };
6181
6200
  }
6182
6201
  typeSchema.searchParams[searchParam.code] = searchParam;
@@ -6245,7 +6264,7 @@
6245
6264
  // PKCE auth based on:
6246
6265
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6247
6266
  var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6248
- const MEDPLUM_VERSION = "0.10.1-221e9b95";
6267
+ const MEDPLUM_VERSION = "0.10.2-f713edf5";
6249
6268
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6250
6269
  const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
6251
6270
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
@@ -10502,211 +10521,6 @@
10502
10521
  }
10503
10522
  }
10504
10523
 
10505
- const OK_ID = 'ok';
10506
- const CREATED_ID = 'created';
10507
- const GONE_ID = 'gone';
10508
- const NOT_MODIFIED_ID = 'not-modified';
10509
- const NOT_FOUND_ID = 'not-found';
10510
- const UNAUTHORIZED_ID = 'unauthorized';
10511
- const FORBIDDEN_ID = 'forbidden';
10512
- const TOO_MANY_REQUESTS_ID = 'too-many-requests';
10513
- const allOk = {
10514
- resourceType: 'OperationOutcome',
10515
- id: OK_ID,
10516
- issue: [
10517
- {
10518
- severity: 'information',
10519
- code: 'informational',
10520
- details: {
10521
- text: 'All OK',
10522
- },
10523
- },
10524
- ],
10525
- };
10526
- const created = {
10527
- resourceType: 'OperationOutcome',
10528
- id: CREATED_ID,
10529
- issue: [
10530
- {
10531
- severity: 'information',
10532
- code: 'informational',
10533
- details: {
10534
- text: 'Created',
10535
- },
10536
- },
10537
- ],
10538
- };
10539
- const notModified = {
10540
- resourceType: 'OperationOutcome',
10541
- id: NOT_MODIFIED_ID,
10542
- issue: [
10543
- {
10544
- severity: 'information',
10545
- code: 'informational',
10546
- details: {
10547
- text: 'Not Modified',
10548
- },
10549
- },
10550
- ],
10551
- };
10552
- const notFound = {
10553
- resourceType: 'OperationOutcome',
10554
- id: NOT_FOUND_ID,
10555
- issue: [
10556
- {
10557
- severity: 'error',
10558
- code: 'not-found',
10559
- details: {
10560
- text: 'Not found',
10561
- },
10562
- },
10563
- ],
10564
- };
10565
- const unauthorized = {
10566
- resourceType: 'OperationOutcome',
10567
- id: UNAUTHORIZED_ID,
10568
- issue: [
10569
- {
10570
- severity: 'error',
10571
- code: 'login',
10572
- details: {
10573
- text: 'Unauthorized',
10574
- },
10575
- },
10576
- ],
10577
- };
10578
- const forbidden = {
10579
- resourceType: 'OperationOutcome',
10580
- id: FORBIDDEN_ID,
10581
- issue: [
10582
- {
10583
- severity: 'error',
10584
- code: 'forbidden',
10585
- details: {
10586
- text: 'Forbidden',
10587
- },
10588
- },
10589
- ],
10590
- };
10591
- const gone = {
10592
- resourceType: 'OperationOutcome',
10593
- id: GONE_ID,
10594
- issue: [
10595
- {
10596
- severity: 'error',
10597
- code: 'deleted',
10598
- details: {
10599
- text: 'Gone',
10600
- },
10601
- },
10602
- ],
10603
- };
10604
- const tooManyRequests = {
10605
- resourceType: 'OperationOutcome',
10606
- id: TOO_MANY_REQUESTS_ID,
10607
- issue: [
10608
- {
10609
- severity: 'error',
10610
- code: 'throttled',
10611
- details: {
10612
- text: 'Too Many Requests',
10613
- },
10614
- },
10615
- ],
10616
- };
10617
- function badRequest(details, expression) {
10618
- return {
10619
- resourceType: 'OperationOutcome',
10620
- issue: [
10621
- {
10622
- severity: 'error',
10623
- code: 'invalid',
10624
- details: {
10625
- text: details,
10626
- },
10627
- expression: expression ? [expression] : undefined,
10628
- },
10629
- ],
10630
- };
10631
- }
10632
- function isOk(outcome) {
10633
- return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
10634
- }
10635
- function isNotFound(outcome) {
10636
- return outcome.id === NOT_FOUND_ID;
10637
- }
10638
- function isGone(outcome) {
10639
- return outcome.id === GONE_ID;
10640
- }
10641
- function getStatus(outcome) {
10642
- if (outcome.id === OK_ID) {
10643
- return 200;
10644
- }
10645
- else if (outcome.id === CREATED_ID) {
10646
- return 201;
10647
- }
10648
- else if (outcome.id === NOT_MODIFIED_ID) {
10649
- return 304;
10650
- }
10651
- else if (outcome.id === UNAUTHORIZED_ID) {
10652
- return 401;
10653
- }
10654
- else if (outcome.id === FORBIDDEN_ID) {
10655
- return 403;
10656
- }
10657
- else if (outcome.id === NOT_FOUND_ID) {
10658
- return 404;
10659
- }
10660
- else if (outcome.id === GONE_ID) {
10661
- return 410;
10662
- }
10663
- else if (outcome.id === TOO_MANY_REQUESTS_ID) {
10664
- return 429;
10665
- }
10666
- else {
10667
- return 400;
10668
- }
10669
- }
10670
- /**
10671
- * Asserts that the operation completed successfully and that the resource is defined.
10672
- * @param outcome The operation outcome.
10673
- * @param resource The resource that may or may not have been returned.
10674
- */
10675
- function assertOk(outcome, resource) {
10676
- if (!isOk(outcome) || resource === undefined) {
10677
- throw new OperationOutcomeError(outcome);
10678
- }
10679
- }
10680
- class OperationOutcomeError extends Error {
10681
- constructor(outcome) {
10682
- var _a, _b;
10683
- super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
10684
- this.outcome = outcome;
10685
- }
10686
- }
10687
- /**
10688
- * Normalizes an error object into a displayable error string.
10689
- * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
10690
- * @returns A display string for the error.
10691
- */
10692
- function normalizeErrorString(error) {
10693
- var _a, _b, _c, _d;
10694
- if (!error) {
10695
- return 'Unknown error';
10696
- }
10697
- if (typeof error === 'string') {
10698
- return error;
10699
- }
10700
- if (error instanceof Error) {
10701
- return error.message;
10702
- }
10703
- if (typeof error === 'object' && 'resourceType' in error) {
10704
- const outcome = error;
10705
- return (_d = (_c = (_b = (_a = outcome.issue) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'Unknown error';
10706
- }
10707
- return JSON.stringify(error);
10708
- }
10709
-
10710
10524
  const DEFAULT_SEARCH_COUNT = 20;
10711
10525
  /**
10712
10526
  * Search operators.
@@ -11069,6 +10883,370 @@
11069
10883
  return result;
11070
10884
  }
11071
10885
 
10886
+ /**
10887
+ * Determines if the resource matches the search request.
10888
+ * @param resource The resource that was created or updated.
10889
+ * @param searchRequest The subscription criteria as a search request.
10890
+ * @returns True if the resource satisfies the search request.
10891
+ */
10892
+ function matchesSearchRequest(resource, searchRequest) {
10893
+ if (searchRequest.resourceType !== resource.resourceType) {
10894
+ return false;
10895
+ }
10896
+ if (searchRequest.filters) {
10897
+ for (const filter of searchRequest.filters) {
10898
+ if (!matchesSearchFilter(resource, searchRequest, filter)) {
10899
+ return false;
10900
+ }
10901
+ }
10902
+ }
10903
+ return true;
10904
+ }
10905
+ /**
10906
+ * Determines if the resource matches the search filter.
10907
+ * @param resource The resource that was created or updated.
10908
+ * @param filter One of the filters of a subscription criteria.
10909
+ * @returns True if the resource satisfies the search filter.
10910
+ */
10911
+ function matchesSearchFilter(resource, searchRequest, filter) {
10912
+ var _a, _b;
10913
+ const searchParam = (_b = (_a = globalSchema.types[searchRequest.resourceType]) === null || _a === void 0 ? void 0 : _a.searchParams) === null || _b === void 0 ? void 0 : _b[filter.code];
10914
+ switch (searchParam === null || searchParam === void 0 ? void 0 : searchParam.type) {
10915
+ case 'reference':
10916
+ return matchesReferenceFilter(resource, filter, searchParam);
10917
+ case 'string':
10918
+ return matchesStringFilter(resource, filter, searchParam);
10919
+ case 'token':
10920
+ return matchesTokenFilter(resource, filter, searchParam);
10921
+ case 'date':
10922
+ return matchesDateFilter(resource, filter, searchParam);
10923
+ }
10924
+ // Unknown search parameter or search parameter type
10925
+ // Default fail the check
10926
+ return false;
10927
+ }
10928
+ function matchesReferenceFilter(resource, filter, searchParam) {
10929
+ const values = evalFhirPath(searchParam.expression, resource);
10930
+ const negated = isNegated(filter.operator);
10931
+ if (filter.value === '' && values.length === 0) {
10932
+ // If the filter operator is "equals", then the filter matches.
10933
+ // If the filter operator is "not equals", then the filter does not match.
10934
+ return filter.operator === exports.Operator.EQUALS;
10935
+ }
10936
+ // Normalize the values array into reference strings
10937
+ const references = values.map((value) => (typeof value === 'string' ? value : value.reference));
10938
+ for (const filterValue of filter.value.split(',')) {
10939
+ let match = references.includes(filterValue);
10940
+ if (!match && filter.code === '_compartment') {
10941
+ // Backwards compability for compartment search parameter
10942
+ // In previous versions, the resource type was not required in compartment values
10943
+ // So, "123" would match "Patient/123"
10944
+ // We need to maintain this behavior for backwards compatibility
10945
+ match = references.some((reference) => reference === null || reference === void 0 ? void 0 : reference.endsWith('/' + filterValue));
10946
+ }
10947
+ if (match && !negated) {
10948
+ return true;
10949
+ }
10950
+ if (match && negated) {
10951
+ return false;
10952
+ }
10953
+ }
10954
+ // If "not equals" and no matches, then return true
10955
+ // If "equals" and no matches, then return false
10956
+ return negated;
10957
+ }
10958
+ function matchesTokenFilter(resource, filter, searchParam) {
10959
+ const details = getSearchParameterDetails(resource.resourceType, searchParam);
10960
+ if (details.type === exports.SearchParameterType.BOOLEAN) {
10961
+ return matchesBooleanFilter(resource, filter, searchParam);
10962
+ }
10963
+ else {
10964
+ return matchesStringFilter(resource, filter, searchParam);
10965
+ }
10966
+ }
10967
+ function matchesBooleanFilter(resource, filter, searchParam) {
10968
+ const values = evalFhirPath(searchParam.expression, resource);
10969
+ const expected = filter.value === 'true';
10970
+ const result = values.includes(expected);
10971
+ return isNegated(filter.operator) ? !result : result;
10972
+ }
10973
+ function matchesStringFilter(resource, filter, searchParam) {
10974
+ const resourceValues = evalFhirPath(searchParam.expression, resource);
10975
+ const filterValues = filter.value.split(',');
10976
+ const negated = isNegated(filter.operator);
10977
+ for (const resourceValue of resourceValues) {
10978
+ for (const filterValue of filterValues) {
10979
+ const match = matchesStringValue(resourceValue, filter.operator, filterValue);
10980
+ if (match && !negated) {
10981
+ return true;
10982
+ }
10983
+ if (match && negated) {
10984
+ return false;
10985
+ }
10986
+ }
10987
+ }
10988
+ // If "not equals" and no matches, then return true
10989
+ // If "equals" and no matches, then return false
10990
+ return negated;
10991
+ }
10992
+ function matchesStringValue(resourceValue, operator, filterValue) {
10993
+ let str = '';
10994
+ if (resourceValue) {
10995
+ if (typeof resourceValue === 'string') {
10996
+ str = resourceValue;
10997
+ }
10998
+ else if (typeof resourceValue === 'object') {
10999
+ str = JSON.stringify(resourceValue);
11000
+ }
11001
+ }
11002
+ return str.toLowerCase().includes(filterValue.toLowerCase());
11003
+ }
11004
+ function matchesDateFilter(resource, filter, searchParam) {
11005
+ const resourceValues = evalFhirPath(searchParam.expression, resource);
11006
+ const filterValues = filter.value.split(',');
11007
+ const negated = isNegated(filter.operator);
11008
+ for (const resourceValue of resourceValues) {
11009
+ for (const filterValue of filterValues) {
11010
+ const match = matchesDateValue(resourceValue, filter.operator, filterValue);
11011
+ if (match && !negated) {
11012
+ return true;
11013
+ }
11014
+ if (match && negated) {
11015
+ return false;
11016
+ }
11017
+ }
11018
+ }
11019
+ // If "not equals" and no matches, then return true
11020
+ // If "equals" and no matches, then return false
11021
+ return negated;
11022
+ }
11023
+ function matchesDateValue(resourceValue, operator, filterValue) {
11024
+ switch (operator) {
11025
+ case exports.Operator.STARTS_AFTER:
11026
+ case exports.Operator.GREATER_THAN:
11027
+ return resourceValue > filterValue;
11028
+ case exports.Operator.GREATER_THAN_OR_EQUALS:
11029
+ return resourceValue >= filterValue;
11030
+ case exports.Operator.ENDS_BEFORE:
11031
+ case exports.Operator.LESS_THAN:
11032
+ return resourceValue < filterValue;
11033
+ case exports.Operator.LESS_THAN_OR_EQUALS:
11034
+ return resourceValue <= filterValue;
11035
+ case exports.Operator.EQUALS:
11036
+ case exports.Operator.NOT_EQUALS:
11037
+ return resourceValue === filterValue;
11038
+ }
11039
+ return false;
11040
+ }
11041
+ function isNegated(operator) {
11042
+ return operator === exports.Operator.NOT_EQUALS || operator === exports.Operator.NOT;
11043
+ }
11044
+
11045
+ const OK_ID = 'ok';
11046
+ const CREATED_ID = 'created';
11047
+ const GONE_ID = 'gone';
11048
+ const NOT_MODIFIED_ID = 'not-modified';
11049
+ const NOT_FOUND_ID = 'not-found';
11050
+ const UNAUTHORIZED_ID = 'unauthorized';
11051
+ const FORBIDDEN_ID = 'forbidden';
11052
+ const TOO_MANY_REQUESTS_ID = 'too-many-requests';
11053
+ const allOk = {
11054
+ resourceType: 'OperationOutcome',
11055
+ id: OK_ID,
11056
+ issue: [
11057
+ {
11058
+ severity: 'information',
11059
+ code: 'informational',
11060
+ details: {
11061
+ text: 'All OK',
11062
+ },
11063
+ },
11064
+ ],
11065
+ };
11066
+ const created = {
11067
+ resourceType: 'OperationOutcome',
11068
+ id: CREATED_ID,
11069
+ issue: [
11070
+ {
11071
+ severity: 'information',
11072
+ code: 'informational',
11073
+ details: {
11074
+ text: 'Created',
11075
+ },
11076
+ },
11077
+ ],
11078
+ };
11079
+ const notModified = {
11080
+ resourceType: 'OperationOutcome',
11081
+ id: NOT_MODIFIED_ID,
11082
+ issue: [
11083
+ {
11084
+ severity: 'information',
11085
+ code: 'informational',
11086
+ details: {
11087
+ text: 'Not Modified',
11088
+ },
11089
+ },
11090
+ ],
11091
+ };
11092
+ const notFound = {
11093
+ resourceType: 'OperationOutcome',
11094
+ id: NOT_FOUND_ID,
11095
+ issue: [
11096
+ {
11097
+ severity: 'error',
11098
+ code: 'not-found',
11099
+ details: {
11100
+ text: 'Not found',
11101
+ },
11102
+ },
11103
+ ],
11104
+ };
11105
+ const unauthorized = {
11106
+ resourceType: 'OperationOutcome',
11107
+ id: UNAUTHORIZED_ID,
11108
+ issue: [
11109
+ {
11110
+ severity: 'error',
11111
+ code: 'login',
11112
+ details: {
11113
+ text: 'Unauthorized',
11114
+ },
11115
+ },
11116
+ ],
11117
+ };
11118
+ const forbidden = {
11119
+ resourceType: 'OperationOutcome',
11120
+ id: FORBIDDEN_ID,
11121
+ issue: [
11122
+ {
11123
+ severity: 'error',
11124
+ code: 'forbidden',
11125
+ details: {
11126
+ text: 'Forbidden',
11127
+ },
11128
+ },
11129
+ ],
11130
+ };
11131
+ const gone = {
11132
+ resourceType: 'OperationOutcome',
11133
+ id: GONE_ID,
11134
+ issue: [
11135
+ {
11136
+ severity: 'error',
11137
+ code: 'deleted',
11138
+ details: {
11139
+ text: 'Gone',
11140
+ },
11141
+ },
11142
+ ],
11143
+ };
11144
+ const tooManyRequests = {
11145
+ resourceType: 'OperationOutcome',
11146
+ id: TOO_MANY_REQUESTS_ID,
11147
+ issue: [
11148
+ {
11149
+ severity: 'error',
11150
+ code: 'throttled',
11151
+ details: {
11152
+ text: 'Too Many Requests',
11153
+ },
11154
+ },
11155
+ ],
11156
+ };
11157
+ function badRequest(details, expression) {
11158
+ return {
11159
+ resourceType: 'OperationOutcome',
11160
+ issue: [
11161
+ {
11162
+ severity: 'error',
11163
+ code: 'invalid',
11164
+ details: {
11165
+ text: details,
11166
+ },
11167
+ expression: expression ? [expression] : undefined,
11168
+ },
11169
+ ],
11170
+ };
11171
+ }
11172
+ function isOk(outcome) {
11173
+ return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
11174
+ }
11175
+ function isNotFound(outcome) {
11176
+ return outcome.id === NOT_FOUND_ID;
11177
+ }
11178
+ function isGone(outcome) {
11179
+ return outcome.id === GONE_ID;
11180
+ }
11181
+ function getStatus(outcome) {
11182
+ if (outcome.id === OK_ID) {
11183
+ return 200;
11184
+ }
11185
+ else if (outcome.id === CREATED_ID) {
11186
+ return 201;
11187
+ }
11188
+ else if (outcome.id === NOT_MODIFIED_ID) {
11189
+ return 304;
11190
+ }
11191
+ else if (outcome.id === UNAUTHORIZED_ID) {
11192
+ return 401;
11193
+ }
11194
+ else if (outcome.id === FORBIDDEN_ID) {
11195
+ return 403;
11196
+ }
11197
+ else if (outcome.id === NOT_FOUND_ID) {
11198
+ return 404;
11199
+ }
11200
+ else if (outcome.id === GONE_ID) {
11201
+ return 410;
11202
+ }
11203
+ else if (outcome.id === TOO_MANY_REQUESTS_ID) {
11204
+ return 429;
11205
+ }
11206
+ else {
11207
+ return 400;
11208
+ }
11209
+ }
11210
+ /**
11211
+ * Asserts that the operation completed successfully and that the resource is defined.
11212
+ * @param outcome The operation outcome.
11213
+ * @param resource The resource that may or may not have been returned.
11214
+ */
11215
+ function assertOk(outcome, resource) {
11216
+ if (!isOk(outcome) || resource === undefined) {
11217
+ throw new OperationOutcomeError(outcome);
11218
+ }
11219
+ }
11220
+ class OperationOutcomeError extends Error {
11221
+ constructor(outcome) {
11222
+ var _a, _b;
11223
+ super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
11224
+ this.outcome = outcome;
11225
+ }
11226
+ }
11227
+ /**
11228
+ * Normalizes an error object into a displayable error string.
11229
+ * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
11230
+ * @returns A display string for the error.
11231
+ */
11232
+ function normalizeErrorString(error) {
11233
+ var _a, _b, _c, _d;
11234
+ if (!error) {
11235
+ return 'Unknown error';
11236
+ }
11237
+ if (typeof error === 'string') {
11238
+ return error;
11239
+ }
11240
+ if (error instanceof Error) {
11241
+ return error.message;
11242
+ }
11243
+ if (typeof error === 'object' && 'resourceType' in error) {
11244
+ const outcome = error;
11245
+ return (_d = (_c = (_b = (_a = outcome.issue) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'Unknown error';
11246
+ }
11247
+ return JSON.stringify(error);
11248
+ }
11249
+
11072
11250
  exports.AndAtom = AndAtom;
11073
11251
  exports.ArithemticOperatorAtom = ArithemticOperatorAtom;
11074
11252
  exports.AsAtom = AsAtom;
@@ -11158,6 +11336,7 @@
11158
11336
  exports.globalSchema = globalSchema;
11159
11337
  exports.gone = gone;
11160
11338
  exports.indexSearchParameter = indexSearchParameter;
11339
+ exports.indexSearchParameterBundle = indexSearchParameterBundle;
11161
11340
  exports.indexStructureDefinition = indexStructureDefinition;
11162
11341
  exports.indexStructureDefinitionBundle = indexStructureDefinitionBundle;
11163
11342
  exports.initFhirPathParserBuilder = initFhirPathParserBuilder;
@@ -11175,6 +11354,7 @@
11175
11354
  exports.isUUID = isUUID;
11176
11355
  exports.isValidDate = isValidDate;
11177
11356
  exports.matchesRange = matchesRange;
11357
+ exports.matchesSearchRequest = matchesSearchRequest;
11178
11358
  exports.normalizeErrorString = normalizeErrorString;
11179
11359
  exports.notFound = notFound;
11180
11360
  exports.notModified = notModified;