@tellescope/utilities 1.172.0 → 1.174.0

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/lib/esm/utils.js CHANGED
@@ -344,13 +344,15 @@ export var get_time_values = function (date, options) {
344
344
  var month = ((options === null || options === void 0 ? void 0 : options.fullMonth) ? MONTHS_FULL : MONTHS)[monthNumber - 1];
345
345
  var hours = date.getHours();
346
346
  var minutesRaw = date.getMinutes();
347
+ var secondsRaw = date.getSeconds();
348
+ var seconds = secondsRaw >= 10 ? secondsRaw : "0".concat(secondsRaw);
347
349
  var minutes = minutesRaw >= 10 ? minutesRaw : "0".concat(minutesRaw);
348
350
  var year = date.getFullYear();
349
351
  var amPm = hours < 12 ? 'am' : 'pm';
350
352
  var hoursAmPm = (hours === 0
351
353
  ? 12
352
354
  : hours <= 12 ? hours : hours - 12);
353
- return { dayOfMonth: dayOfMonth, monthNumber: monthNumber, month: month, hours: hours, hoursAmPm: hoursAmPm, amPm: amPm, minutes: minutes, year: year, };
355
+ return { dayOfMonth: dayOfMonth, monthNumber: monthNumber, month: month, hours: hours, hoursAmPm: hoursAmPm, amPm: amPm, minutes: minutes, year: year, seconds: seconds };
354
356
  };
355
357
  export var formatted_date = function (date) {
356
358
  var _a = get_time_values(date), dayOfMonth = _a.dayOfMonth, month = _a.month, year = _a.year, hoursAmPm = _a.hoursAmPm, amPm = _a.amPm, minutes = _a.minutes;
@@ -812,7 +814,8 @@ export var get_enduser_field_value_for_key = function (enduser, key) {
812
814
  }
813
815
  return enduser === null || enduser === void 0 ? void 0 : enduser[key];
814
816
  };
815
- export var evaluate_conditional_logic_for_enduser_fields = function (enduser, conditions) { return (evaluate_conditional_logic(conditions, function (key, value) {
817
+ export var UPCOMING_EVENT_COUNT_KEY = '__upcomingEvents__';
818
+ export var evaluate_conditional_logic_for_enduser_fields = function (enduser, conditions, o) { return (evaluate_conditional_logic(conditions, function (key, value) {
816
819
  var _a, _b, _d, _e, _f;
817
820
  return ((key === 'Age' && typeof value === 'object')
818
821
  ? (function () {
@@ -840,80 +843,142 @@ export var evaluate_conditional_logic_for_enduser_fields = function (enduser, co
840
843
  // : !!enduser.tags?.find(t => (value as ListOfStringsWithQualifier)?.values?.includes(t))
841
844
  // )
842
845
  // })()
843
- : key === 'relationships' && typeof value === 'string'
844
- ? (!!((_a = enduser === null || enduser === void 0 ? void 0 : enduser.relationships) === null || _a === void 0 ? void 0 : _a.find(function (r) { return r.type === get_inverse_relationship_type(value); })))
845
- : typeof value === 'object'
846
+ : (key === UPCOMING_EVENT_COUNT_KEY && typeof value === 'object')
847
+ ? (function () {
848
+ var _a, _b;
849
+ if (o === null || o === void 0 ? void 0 : o.ignoreUpcomingEvents)
850
+ return true;
851
+ var upcomingEventCount = (_b = (_a = enduser._upcomingEvents) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
852
+ var result = ((value === null || value === void 0 ? void 0 : value['$lt']) !== undefined
853
+ ? (upcomingEventCount < parseInt(value['$lt']))
854
+ : (value === null || value === void 0 ? void 0 : value['$gt']) !== undefined
855
+ ? (upcomingEventCount > parseInt(value['$gt']))
856
+ : false);
857
+ return result;
858
+ })()
859
+ : key === 'BMI' && typeof value === 'object'
846
860
  ? (function () {
847
- var _a, _b, _d, _e, _f, _g, _h, _j, _k, _l;
848
- var k = Object.keys(value)[0];
849
- var v = Object.values(value)[0];
850
- if (key === 'Journeys' && (k === '$in' || k === '$nin')) {
851
- var isInJourney = ((_a = enduser === null || enduser === void 0 ? void 0 : enduser.journeys) === null || _a === void 0 ? void 0 : _a[v]) !== undefined;
852
- return ((k === '$in' && isInJourney)
853
- || (k === "$nin" && !isInJourney));
854
- }
855
- if (k === '$before' || k === '$after') {
856
- var vDate = v === '$now' ? new Date() : new Date(v);
857
- if (isNaN(vDate.getTime()))
858
- return false;
859
- var eDateField = (_d = (_b = enduser.fields) === null || _b === void 0 ? void 0 : _b[key]) !== null && _d !== void 0 ? _d : get_enduser_field_value_for_key(enduser, key);
860
- if (!eDateField)
861
- return false;
862
- if (typeof eDateField !== 'string')
863
- return false;
864
- var eDate = ((eDateField.includes('-') && eDateField.length === 10)
865
- ? new Date(MM_DD_YYYY_to_YYYY_MM_DD(eDateField))
866
- : new Date(eDateField));
867
- if (isNaN(eDate.getTime()))
868
- return false;
869
- return ((k === '$before' && eDate.getTime() < vDate.getTime())
870
- || (k === '$after' && eDate.getTime() > vDate.getTime()));
871
- }
872
- if (k === '$lt' || k === '$gt') {
873
- var enduserValue = (_e = enduser.fields) === null || _e === void 0 ? void 0 : _e[key];
874
- if (typeof enduserValue !== 'number')
875
- return false;
876
- var _v = (typeof v === 'number'
877
- ? v
878
- : parseInt(v));
879
- if (isNaN(_v))
880
- return false;
881
- return ((k === '$lt' && enduserValue < _v)
882
- || (k === '$gt' && enduserValue > _v));
883
- }
884
- if (k === '$contains' || k === '$doesNotContain') {
885
- var enduserValue = ((_g = (_f = enduser.fields) === null || _f === void 0 ? void 0 : _f[key]) !== null && _g !== void 0 ? _g : get_enduser_field_value_for_key(enduser, key));
886
- var contains = (Array.isArray(enduserValue)
887
- ? !!enduserValue.find(function (ev) { return typeof ev === 'string' && ev.includes(v); })
888
- : typeof enduserValue === 'string'
889
- ? enduserValue.includes(v)
890
- : enduserValue === v);
891
- return ((k === '$contains' && contains)
892
- || (k === '$doesNotContain' && !contains));
893
- }
894
- if (k === '$isSet' || k === '$isNotSet') {
895
- var enduserValue = ((_j = (_h = enduser.fields) === null || _h === void 0 ? void 0 : _h[key]) !== null && _j !== void 0 ? _j : get_enduser_field_value_for_key(enduser, key));
896
- var isSet = (Array.isArray(enduserValue)
897
- ? enduserValue.length > 0
898
- : !!enduserValue);
899
- return (k === "$isSet" && isSet) || (k === '$isNotSet' && !isSet);
900
- }
901
- // should negate the typeof value === 'string' (defaults to $equals) condition
902
- if (k === '$ne') {
903
- var enduserValue = ((_l = (_k = enduser.fields) === null || _k === void 0 ? void 0 : _k[key]) !== null && _l !== void 0 ? _l : get_enduser_field_value_for_key(enduser, key));
904
- return !(enduserValue === v
905
- || (Array.isArray(enduserValue) && (enduserValue).includes(v)));
906
- }
907
- return false;
861
+ var _a, _b, _d, _e;
862
+ var height = parseInt(((_b = (_a = enduser.height) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString()) || '0');
863
+ var weight = parseInt(((_e = (_d = enduser.weight) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.toString()) || '0');
864
+ if (!(height && weight))
865
+ return false;
866
+ var bmi = 703 * weight / (height * height);
867
+ var result = ((value === null || value === void 0 ? void 0 : value['$lt']) !== undefined
868
+ ? (bmi < parseInt(value['$lt']))
869
+ : (value === null || value === void 0 ? void 0 : value['$gt']) !== undefined
870
+ ? (bmi > parseInt(value['$gt']))
871
+ : false);
872
+ return result;
908
873
  })()
909
- : typeof value === 'string'
910
- ? (((_d = (_b = enduser.fields) === null || _b === void 0 ? void 0 : _b[key]) !== null && _d !== void 0 ? _d : get_enduser_field_value_for_key(enduser, key)) === value
911
- || (Array.isArray((_e = enduser.fields) === null || _e === void 0 ? void 0 : _e[key])
912
- && ((_f = enduser === null || enduser === void 0 ? void 0 : enduser.fields) === null || _f === void 0 ? void 0 : _f[key]).includes(value))
913
- || (Array.isArray(get_enduser_field_value_for_key(enduser, key))
914
- && enduser[key].includes(value)))
915
- : false);
874
+ : key === 'relationships' && typeof value === 'string'
875
+ ? (!!((_a = enduser === null || enduser === void 0 ? void 0 : enduser.relationships) === null || _a === void 0 ? void 0 : _a.find(function (r) { return r.type === get_inverse_relationship_type(value); })))
876
+ : typeof value === 'object'
877
+ ? (function () {
878
+ var _a, _b, _d, _e, _f, _g, _h, _j, _k, _l;
879
+ var k = Object.keys(value)[0];
880
+ var v = Object.values(value)[0];
881
+ if (key === 'Journeys' && (k === '$in' || k === '$nin')) {
882
+ var isInJourney = ((_a = enduser === null || enduser === void 0 ? void 0 : enduser.journeys) === null || _a === void 0 ? void 0 : _a[v]) !== undefined;
883
+ return ((k === '$in' && isInJourney)
884
+ || (k === "$nin" && !isInJourney));
885
+ }
886
+ if (k === '$before' || k === '$after') {
887
+ var vDate = v === '$now' ? new Date() : new Date(v);
888
+ if (isNaN(vDate.getTime()))
889
+ return false;
890
+ var eDateField = (_d = (_b = enduser.fields) === null || _b === void 0 ? void 0 : _b[key]) !== null && _d !== void 0 ? _d : get_enduser_field_value_for_key(enduser, key);
891
+ if (!eDateField)
892
+ return false;
893
+ if (typeof eDateField !== 'string')
894
+ return false;
895
+ var eDate = ((eDateField.includes('-') && eDateField.length === 10)
896
+ ? new Date(MM_DD_YYYY_to_YYYY_MM_DD(eDateField))
897
+ : new Date(eDateField));
898
+ if (isNaN(eDate.getTime()))
899
+ return false;
900
+ return ((k === '$before' && eDate.getTime() < vDate.getTime())
901
+ || (k === '$after' && eDate.getTime() > vDate.getTime()));
902
+ }
903
+ if (k === '$lt' || k === '$gt') {
904
+ var enduserValue = (_e = enduser.fields) === null || _e === void 0 ? void 0 : _e[key];
905
+ if (typeof enduserValue !== 'number')
906
+ return false;
907
+ var _v = (typeof v === 'number'
908
+ ? v
909
+ : parseInt(v));
910
+ if (isNaN(_v))
911
+ return false;
912
+ return ((k === '$lt' && enduserValue < _v)
913
+ || (k === '$gt' && enduserValue > _v));
914
+ }
915
+ if (k === '$contains' || k === '$doesNotContain') {
916
+ var enduserValue = ((_g = (_f = enduser.fields) === null || _f === void 0 ? void 0 : _f[key]) !== null && _g !== void 0 ? _g : get_enduser_field_value_for_key(enduser, key));
917
+ var contains = (Array.isArray(enduserValue)
918
+ ? !!enduserValue.find(function (ev) { return typeof ev === 'string' && ev.includes(v); })
919
+ : typeof enduserValue === 'string'
920
+ ? enduserValue.includes(v)
921
+ : enduserValue === v);
922
+ return ((k === '$contains' && contains)
923
+ || (k === '$doesNotContain' && !contains));
924
+ }
925
+ if (k === '$isSet' || k === '$isNotSet') {
926
+ var enduserValue = ((_j = (_h = enduser.fields) === null || _h === void 0 ? void 0 : _h[key]) !== null && _j !== void 0 ? _j : get_enduser_field_value_for_key(enduser, key));
927
+ var isSet = (Array.isArray(enduserValue)
928
+ ? enduserValue.length > 0
929
+ : !!enduserValue);
930
+ return (k === "$isSet" && isSet) || (k === '$isNotSet' && !isSet);
931
+ }
932
+ // should negate the typeof value === 'string' (defaults to $equals) condition
933
+ if (k === '$ne') {
934
+ var enduserValue = ((_l = (_k = enduser.fields) === null || _k === void 0 ? void 0 : _k[key]) !== null && _l !== void 0 ? _l : get_enduser_field_value_for_key(enduser, key));
935
+ return !(enduserValue === v
936
+ || (Array.isArray(enduserValue) && (enduserValue).includes(v)));
937
+ }
938
+ return false;
939
+ })()
940
+ : typeof value === 'string'
941
+ ? (((_d = (_b = enduser.fields) === null || _b === void 0 ? void 0 : _b[key]) !== null && _d !== void 0 ? _d : get_enduser_field_value_for_key(enduser, key)) === value
942
+ || (Array.isArray((_e = enduser.fields) === null || _e === void 0 ? void 0 : _e[key])
943
+ && ((_f = enduser === null || enduser === void 0 ? void 0 : enduser.fields) === null || _f === void 0 ? void 0 : _f[key]).includes(value))
944
+ || (Array.isArray(get_enduser_field_value_for_key(enduser, key))
945
+ && enduser[key].includes(value)))
946
+ : false);
916
947
  })); };
948
+ export var string_matches_key_or_value = function (value, match) {
949
+ if (typeof value === 'string') {
950
+ return value === match;
951
+ }
952
+ if (Array.isArray(value)) {
953
+ return value.find(function (v) { return string_matches_key_or_value(v, match); }) !== undefined;
954
+ }
955
+ if (value && typeof value === 'object') {
956
+ for (var k in value) {
957
+ if (k === match)
958
+ return true;
959
+ if (string_matches_key_or_value(value[k], match))
960
+ return true;
961
+ }
962
+ }
963
+ return false;
964
+ };
965
+ // console.log(
966
+ // 'string match test case',
967
+ // string_matches_key_or_value(
968
+ // {
969
+ // $and: [
970
+ // {
971
+ // condition: {
972
+ // __upcomingEvents__: {
973
+ // $gt: 0,
974
+ // }
975
+ // }
976
+ // }
977
+ // ]
978
+ // },
979
+ // UPCOMING_EVENT_COUNT_KEY,
980
+ // )
981
+ // )
917
982
  export var getLocalTimezone = function () { return Intl.DateTimeFormat().resolvedOptions().timeZone; };
918
983
  export var YYYY_MM_DD_to_MM_DD_YYYY = function (yyyyMmDd, delimiter) {
919
984
  if (delimiter === void 0) { delimiter = '-'; }
@@ -2175,7 +2240,7 @@ export var INVALID_PREPOPULATION_TYPES = [
2175
2240
  // now supported
2176
2241
  // "Address", // split into different patient fields and non-trivial to pre-load
2177
2242
  ];
2178
- export var get_prepopulated_responses = function (fields, enduser) { return (fields
2243
+ export var get_prepopulated_responses = function (fields, enduser, existingResponses) { return (fields
2179
2244
  .filter(function (v) {
2180
2245
  var _a;
2181
2246
  return (v.prepopulateFromFields && !INVALID_PREPOPULATION_TYPES.includes(v.type) && v.intakeField
@@ -2194,6 +2259,7 @@ export var get_prepopulated_responses = function (fields, enduser) { return (fie
2194
2259
  fieldDescription: v.description,
2195
2260
  fieldHtmlDescription: v.htmlDescription,
2196
2261
  sharedWithEnduser: v.sharedWithEnduser,
2262
+ isPrepopulatedFromEnduserField: true,
2197
2263
  answer: (v.type === 'Address' && v.intakeField === 'Address')
2198
2264
  ? {
2199
2265
  type: 'Address',