@tellescope/react-components 1.158.0 → 1.160.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.
Files changed (42) hide show
  1. package/lib/cjs/Forms/forms.js +1 -1
  2. package/lib/cjs/Forms/forms.js.map +1 -1
  3. package/lib/cjs/Forms/inputs.d.ts +2 -1
  4. package/lib/cjs/Forms/inputs.d.ts.map +1 -1
  5. package/lib/cjs/Forms/inputs.js +158 -33
  6. package/lib/cjs/Forms/inputs.js.map +1 -1
  7. package/lib/cjs/mui.d.ts +2 -1
  8. package/lib/cjs/mui.d.ts.map +1 -1
  9. package/lib/cjs/mui.js +2 -2
  10. package/lib/cjs/mui.js.map +1 -1
  11. package/lib/esm/CMS/components.d.ts +1 -0
  12. package/lib/esm/CMS/components.d.ts.map +1 -1
  13. package/lib/esm/Forms/form_responses.d.ts +1 -0
  14. package/lib/esm/Forms/form_responses.d.ts.map +1 -1
  15. package/lib/esm/Forms/forms.d.ts +3 -3
  16. package/lib/esm/Forms/forms.js +1 -1
  17. package/lib/esm/Forms/forms.js.map +1 -1
  18. package/lib/esm/Forms/hooks.d.ts +1 -0
  19. package/lib/esm/Forms/hooks.d.ts.map +1 -1
  20. package/lib/esm/Forms/inputs.d.ts +3 -2
  21. package/lib/esm/Forms/inputs.d.ts.map +1 -1
  22. package/lib/esm/Forms/inputs.js +156 -32
  23. package/lib/esm/Forms/inputs.js.map +1 -1
  24. package/lib/esm/Forms/inputs.native.d.ts +1 -0
  25. package/lib/esm/Forms/inputs.native.d.ts.map +1 -1
  26. package/lib/esm/controls.d.ts +2 -2
  27. package/lib/esm/inputs.d.ts +1 -1
  28. package/lib/esm/inputs.native.d.ts +1 -0
  29. package/lib/esm/inputs.native.d.ts.map +1 -1
  30. package/lib/esm/layout.d.ts +1 -1
  31. package/lib/esm/mui.d.ts +2 -1
  32. package/lib/esm/mui.d.ts.map +1 -1
  33. package/lib/esm/mui.js +2 -2
  34. package/lib/esm/mui.js.map +1 -1
  35. package/lib/esm/state.d.ts +52 -52
  36. package/lib/esm/theme.native.d.ts +1 -0
  37. package/lib/esm/theme.native.d.ts.map +1 -1
  38. package/lib/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +9 -9
  40. package/src/Forms/forms.tsx +1 -1
  41. package/src/Forms/inputs.tsx +278 -39
  42. package/src/mui.tsx +3 -2
@@ -291,10 +291,11 @@ export var NumberInput = function (_a) {
291
291
  } })));
292
292
  };
293
293
  export var InsuranceInput = function (_a) {
294
- var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
294
+ var _b, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
295
295
  var field = _a.field, value = _a.value, onChange = _a.onChange, form = _a.form, responses = _a.responses, enduser = _a.enduser, props = __rest(_a, ["field", "value", "onChange", "form", "responses", "enduser"]);
296
296
  var session = useResolvedSession();
297
- var _q = useState([]), payers = _q[0], setPayers = _q[1];
297
+ var _t = useState([]), payers = _t[0], setPayers = _t[1];
298
+ var _u = useState(''), query = _u[0], setQuery = _u[1];
298
299
  var addressQuestion = useMemo(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
299
300
  var _a;
300
301
  if (r.answer.type !== 'Address')
@@ -312,6 +313,9 @@ export var InsuranceInput = function (_a) {
312
313
  }, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion]);
313
314
  var loadRef = useRef(false); // so session changes don't cause
314
315
  useEffect(function () {
316
+ var _a;
317
+ if (((_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.dataSource) === CANVAS_TITLE)
318
+ return; // instead, look-up while typing against Canvas Search API
315
319
  if (loadRef.current)
316
320
  return;
317
321
  loadRef.current = true;
@@ -332,33 +336,75 @@ export var InsuranceInput = function (_a) {
332
336
  .filter(function (c) { return !c.state || !state || (c.state === state); }));
333
337
  })
334
338
  .catch(console.error);
335
- }, [session, state]);
336
- return (_jsxs(Grid, __assign({ container: true, spacing: 2, sx: { mt: '0' } }, { children: [_jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(Autocomplete, { freeSolo: !((_b = field.options) === null || _b === void 0 ? void 0 : _b.requirePredefinedInsurer), options: payers.map(function (p) { return p.name; }), value: (value === null || value === void 0 ? void 0 : value.payerName) || '', onChange: function (e, v) {
337
- var _a, _b;
338
- return onChange(__assign(__assign({}, value), { payerName: v || '', payerId: ((_a = payers.find(function (p) { return p.name === v; })) === null || _a === void 0 ? void 0 : _a.id) || '', payerType: ((_b = payers.find(function (p) { return p.name === v; })) === null || _b === void 0 ? void 0 : _b.type) || '' }), field.id);
339
- }, onInputChange: ((_d = field.options) === null || _d === void 0 ? void 0 : _d.requirePredefinedInsurer) ? undefined : function (e, v) {
339
+ }, [session, state, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
340
+ var searchRef = useRef(query);
341
+ useEffect(function () {
342
+ var _a;
343
+ if (((_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.dataSource) !== CANVAS_TITLE) {
344
+ return;
345
+ }
346
+ if (!query)
347
+ return;
348
+ if (searchRef.current === query)
349
+ return;
350
+ searchRef.current = query;
351
+ session.api.integrations.proxy_read({
352
+ integration: CANVAS_TITLE,
353
+ query: query,
354
+ type: 'organizations',
355
+ })
356
+ .then(function (_a) {
357
+ var data = _a.data;
358
+ try {
359
+ setPayers(data.map(function (d) { return ({
360
+ id: d.resource.id,
361
+ name: d.resource.name,
362
+ }); }));
363
+ }
364
+ catch (err) {
365
+ console.error;
366
+ }
367
+ })
368
+ .catch(console.error);
369
+ }, [session, (_d = field === null || field === void 0 ? void 0 : field.options) === null || _d === void 0 ? void 0 : _d.dataSource, query]);
370
+ return (_jsxs(Grid, __assign({ container: true, spacing: 2, sx: { mt: '0' } }, { children: [_jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(Autocomplete, { freeSolo: !((_e = field.options) === null || _e === void 0 ? void 0 : _e.requirePredefinedInsurer), options: payers.map(function (p) { return p.name; }), value: (value === null || value === void 0 ? void 0 : value.payerName) || '', onChange: function (e, v) {
340
371
  var _a, _b;
341
372
  return onChange(__assign(__assign({}, value), { payerName: v || '', payerId: ((_a = payers.find(function (p) { return p.name === v; })) === null || _a === void 0 ? void 0 : _a.id) || '', payerType: ((_b = payers.find(function (p) { return p.name === v; })) === null || _b === void 0 ? void 0 : _b.type) || '' }), field.id);
342
- }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "Insurer" }))); } }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(TextField, { InputProps: defaultInputProps, required: !field.isOptional, fullWidth: true, value: (_e = value === null || value === void 0 ? void 0 : value.memberId) !== null && _e !== void 0 ? _e : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { memberId: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Member ID", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(TextField, { InputProps: defaultInputProps, required: false, fullWidth: true, value: (_f = value === null || value === void 0 ? void 0 : value.planName) !== null && _f !== void 0 ? _f : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { planName: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Plan Name", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(DateStringInput, { size: "small", label: "Plan Start Date", field: __assign(__assign({}, field), { isOptional: true }), value: (value === null || value === void 0 ? void 0 : value.startDate) || '', onChange: function (startDate) {
373
+ }, onInputChange: ((_f = field.options) === null || _f === void 0 ? void 0 : _f.requirePredefinedInsurer)
374
+ ? function (e, v) { if (v) {
375
+ setQuery(v);
376
+ } }
377
+ : function (e, v) {
378
+ var _a, _b;
379
+ if (v) {
380
+ setQuery(v);
381
+ }
382
+ onChange(__assign(__assign({}, value), { payerName: v || '', payerId: ((_a = payers.find(function (p) { return p.name === v; })) === null || _a === void 0 ? void 0 : _a.id) || '', payerType: ((_b = payers.find(function (p) { return p.name === v; })) === null || _b === void 0 ? void 0 : _b.type) || '' }), field.id);
383
+ }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "Insurer" }))); } }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(TextField, { InputProps: defaultInputProps, required: !field.isOptional, fullWidth: true, value: (_g = value === null || value === void 0 ? void 0 : value.memberId) !== null && _g !== void 0 ? _g : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { memberId: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Member ID", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(TextField, { InputProps: defaultInputProps, required: false, fullWidth: true, value: (_h = value === null || value === void 0 ? void 0 : value.planName) !== null && _h !== void 0 ? _h : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { planName: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Plan Name", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12, sm: 6 }, { children: _jsx(DateStringInput, { size: "small", label: "Plan Start Date", field: __assign(__assign({}, field), { isOptional: true }), value: (value === null || value === void 0 ? void 0 : value.startDate) || '', onChange: function (startDate) {
343
384
  return onChange(__assign(__assign({}, value), { startDate: startDate }), field.id);
344
- } }) })), ((_g = field.options) === null || _g === void 0 ? void 0 : _g.includeGroupNumber) &&
345
- _jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(TextField, { InputProps: defaultInputProps, fullWidth: true, value: (_h = value === null || value === void 0 ? void 0 : value.groupNumber) !== null && _h !== void 0 ? _h : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { groupNumber: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Group Number", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(StringSelector, { size: "small", label: "Relationship to Policy Owner", options: (((_j = field.options) === null || _j === void 0 ? void 0 : _j.billingProvider) === 'Canvas' ? INSURANCE_RELATIONSHIPS_CANVAS : INSURANCE_RELATIONSHIPS)
385
+ } }) })), ((_j = field.options) === null || _j === void 0 ? void 0 : _j.includeGroupNumber) &&
386
+ _jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(TextField, { InputProps: defaultInputProps, fullWidth: true, value: (_k = value === null || value === void 0 ? void 0 : value.groupNumber) !== null && _k !== void 0 ? _k : '', onChange: function (e) { return onChange(__assign(__assign({}, value), { groupNumber: e.target.value }), field.id); }, label: form_display_text_for_language(form, "Group Number", ''), size: "small" }) })), _jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(StringSelector, { size: "small", label: "Relationship to Policy Owner", options: ((((_l = field.options) === null || _l === void 0 ? void 0 : _l.billingProvider) === CANVAS_TITLE || ((_m = field.options) === null || _m === void 0 ? void 0 : _m.dataSource) === CANVAS_TITLE)
387
+ ? INSURANCE_RELATIONSHIPS_CANVAS
388
+ : INSURANCE_RELATIONSHIPS)
346
389
  .sort(function (x, y) { return x.localeCompare(y); }), value: (value === null || value === void 0 ? void 0 : value.relationship) || 'Self', onChange: function (relationship) {
347
390
  return onChange(__assign(__assign({}, value), { relationship: relationship || 'Self' }), field.id);
348
391
  } }) })), ((value === null || value === void 0 ? void 0 : value.relationship) || 'Self') !== 'Self' &&
349
- _jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(Typography, __assign({ sx: { fontWeight: 'bold' } }, { children: "Policy Owner Details" })) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(TextField, { label: "First Name", size: "small", InputProps: defaultInputProps, fullWidth: true, value: ((_k = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _k === void 0 ? void 0 : _k.fname) || '', required: !field.isOptional, onChange: function (e) {
392
+ _jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true, xs: 12 }, { children: _jsx(Typography, __assign({ sx: { fontWeight: 'bold' } }, { children: "Policy Owner Details" })) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(TextField, { label: "First Name", size: "small", InputProps: defaultInputProps, fullWidth: true, value: ((_o = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _o === void 0 ? void 0 : _o.fname) || '', required: !field.isOptional, onChange: function (e) {
350
393
  return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { fname: e.target.value }) }), field.id);
351
- } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(TextField, { label: "Last Name", size: "small", InputProps: defaultInputProps, fullWidth: true, value: ((_l = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _l === void 0 ? void 0 : _l.lname) || '', required: !field.isOptional, onChange: function (e) {
394
+ } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(TextField, { label: "Last Name", size: "small", InputProps: defaultInputProps, fullWidth: true, value: ((_p = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _p === void 0 ? void 0 : _p.lname) || '', required: !field.isOptional, onChange: function (e) {
352
395
  return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { lname: e.target.value }) }), field.id);
353
- } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(StringSelector, { options: TELLESCOPE_GENDERS, size: "small", label: "Gender", value: ((_m = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _m === void 0 ? void 0 : _m.gender) || '', required: !field.isOptional, onChange: function (v) {
396
+ } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(StringSelector, { options: TELLESCOPE_GENDERS, size: "small", label: "Gender", value: ((_q = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _q === void 0 ? void 0 : _q.gender) || '', required: !field.isOptional, onChange: function (v) {
354
397
  return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { gender: v }) }), field.id);
355
- } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(DateStringInput, { size: "small", label: "Date of Birth", field: __assign(__assign({}, field), { isOptional: field.isOptional || ((_o = field.options) === null || _o === void 0 ? void 0 : _o.billingProvider) === 'Candid' }), value: ((_p = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _p === void 0 ? void 0 : _p.dateOfBirth) || '', onChange: function (dateOfBirth) {
398
+ } }) })), _jsx(Grid, __assign({ item: true, xs: 6 }, { children: _jsx(DateStringInput, { size: "small", label: "Date of Birth", field: __assign(__assign({}, field), { isOptional: field.isOptional || ((_r = field.options) === null || _r === void 0 ? void 0 : _r.billingProvider) === 'Candid' }), value: ((_s = value === null || value === void 0 ? void 0 : value.relationshipDetails) === null || _s === void 0 ? void 0 : _s.dateOfBirth) || '', onChange: function (dateOfBirth) {
356
399
  return onChange(__assign(__assign({}, value), { relationshipDetails: __assign(__assign({}, value === null || value === void 0 ? void 0 : value.relationshipDetails), { dateOfBirth: dateOfBirth }) }), field.id);
357
400
  } }) }))] })] })));
358
401
  };
359
402
  var StringSelector = function (_a) {
360
- var options = _a.options, value = _a.value, onChange = _a.onChange, required = _a.required, props = __rest(_a, ["options", "value", "onChange", "required"]);
361
- return (_jsxs(FormControl, __assign({ fullWidth: true, size: props.size, required: required }, { children: [_jsx(InputLabel, { children: props.label }), _jsx(Select, __assign({}, props, { value: value, onChange: function (e) { return onChange(e.target.value); }, fullWidth: true, sx: defaultInputProps.sx }, { children: options.map(function (o, i) { return (_jsx(MenuItem, __assign({ value: o }, { children: o }), o || i)); }) }))] })));
403
+ var options = _a.options, value = _a.value, onChange = _a.onChange, required = _a.required, getDisplayValue = _a.getDisplayValue, props = __rest(_a, ["options", "value", "onChange", "required", "getDisplayValue"]);
404
+ return (_jsxs(FormControl, __assign({ fullWidth: true, size: props.size, required: required }, { children: [_jsx(InputLabel, { children: props.label }), _jsx(Select, __assign({}, props, { value: value, onChange: function (e) { return onChange(e.target.value); }, fullWidth: true, sx: defaultInputProps.sx }, { children: options.map(function (o, i) {
405
+ var _a;
406
+ return (_jsx(MenuItem, __assign({ value: o }, { children: (_a = getDisplayValue === null || getDisplayValue === void 0 ? void 0 : getDisplayValue(o)) !== null && _a !== void 0 ? _a : o }), o || i));
407
+ }) }))] })));
362
408
  };
363
409
  var HourSelector = function (props) { return (_jsx(StringSelector, __assign({}, props, { options: Array(12).fill('').map(function (_, i) { return (i + 1) <= 9 ? "0".concat(i + 1) : (i + 1).toString(); }) }))); };
364
410
  var MinuteSelector = function (props) { return (_jsx(StringSelector, __assign({}, props, { options: Array(60).fill('').map(function (_, i) { return i <= 9 ? "0".concat(i) : i.toString(); }) }))); };
@@ -376,7 +422,10 @@ export var AddressInput = function (_a) {
376
422
  // state only
377
423
  ((_d = (_b = field.options) === null || _b === void 0 ? void 0 : _b.addressFields) === null || _d === void 0 ? void 0 : _d.includes('state'))
378
424
  ? (_jsx(Autocomplete, __assign({ value: value === null || value === void 0 ? void 0 : value.state, options: ((_f = (_e = field.options) === null || _e === void 0 ? void 0 : _e.validStates) === null || _f === void 0 ? void 0 : _f.length) ? field.options.validStates : VALID_STATES, disablePortal: true, onChange: function (e, v) { return v &&
379
- onChange(__assign(__assign({}, value), { state: v !== null && v !== void 0 ? v : '' }), field.id); }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), size: 'small', required: !field.isOptional, label: form_display_text_for_language(form, "State") }))); } }, props)))
425
+ onChange(__assign(__assign({}, value), { state: v !== null && v !== void 0 ? v : '' }), field.id); }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional,
426
+ // don't use 'small' so as to be consistent with other text fields, in case this is used in a group
427
+ // size={'small'}
428
+ label: form_display_text_for_language(form, "State") }))); } }, props)))
380
429
  : (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 2, sx: { mt: 0 } }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(AutoFocusTextField, __assign({}, props, { size: "small", required: !field.isOptional, fullWidth: true, value: (_g = value === null || value === void 0 ? void 0 : value.addressLineOne) !== null && _g !== void 0 ? _g : '', label: form_display_text_for_language(form, "Address Line 1"), placeholder: form_display_text_for_language(form, "Address Line 1"), onChange: function (e) {
381
430
  var _a;
382
431
  return onChange(__assign(__assign({}, value), { addressLineOne: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }), field.id);
@@ -937,10 +986,13 @@ var displayTermsCache = undefined;
937
986
  var DRUGS_FOR_DISPLAY_TERM = {};
938
987
  var RX_NORM_CODE_FOR_DRUG = {};
939
988
  var NDC_CODES_FOR_RX_NORM_CODE = {};
940
- var useMedications = function () {
941
- var _a = useState(displayTermsCache), displayTerms = _a[0], setDisplayTerms = _a[1];
989
+ var useMedications = function (_a) {
990
+ var dontFetch = _a.dontFetch;
991
+ var _b = useState(displayTermsCache), displayTerms = _b[0], setDisplayTerms = _b[1];
942
992
  var fetchRef = useRef(displayTerms !== undefined);
943
993
  useEffect(function () {
994
+ if (dontFetch)
995
+ return;
944
996
  if (fetchRef.current)
945
997
  return;
946
998
  fetchRef.current = true;
@@ -969,7 +1021,7 @@ var useMedications = function () {
969
1021
  });
970
1022
  })
971
1023
  .catch(console.error);
972
- }, []);
1024
+ }, [dontFetch]);
973
1025
  var getDrugsForDisplayTerm = useCallback(function (s) { return __awaiter(void 0, void 0, void 0, function () {
974
1026
  var drugs, _a;
975
1027
  var _b, _d, _e, _f;
@@ -1052,10 +1104,79 @@ var filterOptions = function (options, _a) {
1052
1104
  .slice(0, 100) // dramatic performance improvement (when not virtualized) to show a subset like this
1053
1105
  );
1054
1106
  };
1107
+ var FDB_URL = "http://www.fdbhealth.com/";
1108
+ export var CanvasMedicationsInput = function (_a) {
1109
+ var _b;
1110
+ var field = _a.field, _d = _a.value, value = _d === void 0 ? [] : _d, onChange = _a.onChange;
1111
+ var session = useResolvedSession();
1112
+ var _e = useState(''), query = _e[0], setQuery = _e[1];
1113
+ var _f = useState([]), results = _f[0], setResults = _f[1];
1114
+ // if two Medications questions shown in a row, reset state
1115
+ useEffect(function () {
1116
+ setQuery('');
1117
+ setResults([]);
1118
+ }, [field.id]);
1119
+ var fetchRef = useRef(query);
1120
+ useEffect(function () {
1121
+ if (fetchRef.current === query)
1122
+ return;
1123
+ fetchRef.current = query;
1124
+ if (!query)
1125
+ return;
1126
+ var t = setTimeout(function () {
1127
+ session.api.integrations
1128
+ .proxy_read({
1129
+ integration: CANVAS_TITLE,
1130
+ type: 'medications',
1131
+ query: query,
1132
+ })
1133
+ .then(function (r) {
1134
+ var _a;
1135
+ setResults((((_a = r.data) === null || _a === void 0 ? void 0 : _a.entry) || [])
1136
+ .map(function (v) {
1137
+ var fdbCode = v.resource.code.coding.find(function (c) { return c.system === FDB_URL; });
1138
+ return {
1139
+ displayTerm: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.display) || '',
1140
+ drugName: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.display) || '',
1141
+ fdbCode: (fdbCode === null || fdbCode === void 0 ? void 0 : fdbCode.code) || '',
1142
+ };
1143
+ }));
1144
+ });
1145
+ }, 200);
1146
+ return function () { clearTimeout(t); };
1147
+ }, [session, query, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
1148
+ return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Autocomplete, { multiple: true, value: value, options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
1149
+ if (!v) {
1150
+ return;
1151
+ }
1152
+ onChange(v, field.id);
1153
+ setResults([]);
1154
+ }, getOptionLabel: function (v) { return first_letter_capitalized(v.displayTerm); }, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search medications..." }))); }, renderTags: function (value, getTagProps) {
1155
+ return value.map(function (value, index) { return (_jsx(Chip, __assign({ label: _jsx(Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: value.displayTerm })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
1156
+ } }) })), (value || []).map(function (medication, i) {
1157
+ var _a, _b, _d, _e;
1158
+ return (_jsx(Grid, __assign({ item: true }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", spacing: 0.75 }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, __assign({ noWrap: true, sx: { fontSize: 14 } }, { children: medication.drugName })) })), _jsx(Grid, __assign({ item: true }, { children: _jsxs(Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", columnGap: 0.5, justifyContent: "space-between" }, { children: [_jsx(Grid, __assign({ item: true, sx: { width: '50%', mr: 1 } }, { children: _jsx(TextField, { type: "number", InputProps: { sx: defaultInputProps.sx }, fullWidth: true, size: "small", label: "Units (e.g. capsule, table, puff) per dose?", value: ((_a = medication.dosage) === null || _a === void 0 ? void 0 : _a.quantity) || '', onChange: function (e) { return (onChange((value || []).map(function (v, _i) {
1159
+ return i === _i
1160
+ ? __assign(__assign({}, v), { dosage: __assign(__assign({}, v.dosage), { quantity: e.target.value }) }) : v;
1161
+ }), field.id)); } }) })), _jsx(Grid, __assign({ item: true, sx: { width: '30%' } }, { children: _jsx(StringSelector, { size: "small", label: "How many times?", options: ["1", "2", "3", "4", "5", "6", "As Needed"], value: (_d = (_b = medication.dosage) === null || _b === void 0 ? void 0 : _b.frequency) !== null && _d !== void 0 ? _d : '', onChange: function (frequency) { return __awaiter(void 0, void 0, void 0, function () {
1162
+ return __generator(this, function (_a) {
1163
+ onChange((value !== null && value !== void 0 ? value : []).map(function (_v, _i) { return (i === _i
1164
+ ? __assign(__assign({}, _v), { dosage: __assign(__assign({}, _v.dosage), { frequency: frequency || '' }) }) : _v); }), field.id);
1165
+ return [2 /*return*/];
1166
+ });
1167
+ }); } }) })), _jsx(Grid, __assign({ item: true, sx: { width: '20%' } }, { children: _jsx(StringSelector, { options: ['Day', 'Week', 'Month', "Year"], size: "small", label: "Per", value: ((_e = medication.dosage) === null || _e === void 0 ? void 0 : _e.frequencyDescriptor) || 'Day', onChange: function (frequencyDescriptor) { return (onChange((value || []).map(function (v, _i) {
1168
+ return i === _i
1169
+ ? __assign(__assign({}, v), { dosage: __assign(__assign({}, v.dosage), { frequencyDescriptor: frequencyDescriptor }) }) : v;
1170
+ }), field.id)); }, getDisplayValue: first_letter_capitalized }) }))] })) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(TextField, { InputProps: { sx: defaultInputProps.sx }, fullWidth: true, size: "small", label: "Reason for taking medication", value: medication.reasonForTaking || '', onChange: function (e) { return onChange((value || []).map(function (v, _i) { return i === _i ? __assign(__assign({}, v), { reasonForTaking: e.target.value }) : v; }), field.id); } }) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(Divider, { flexItem: true, sx: { my: 0.5 } }) }))] })) }), i));
1171
+ })] })));
1172
+ };
1055
1173
  export var MedicationsInput = function (_a) {
1056
- var field = _a.field, value = _a.value, onChange = _a.onChange;
1057
- var _b = useMedications(), displayTerms = _b.displayTerms, doneLoading = _b.doneLoading, getCodesForDrug = _b.getCodesForDrug, getDrugsForDisplayTerm = _b.getDrugsForDisplayTerm;
1058
- var _d = useState({}), drugs = _d[0], setDrugs = _d[1];
1174
+ var _b, _d;
1175
+ var field = _a.field, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["field", "value", "onChange"]);
1176
+ var _e = useMedications({
1177
+ dontFetch: ((_b = field.options) === null || _b === void 0 ? void 0 : _b.dataSource) === CANVAS_TITLE
1178
+ }), displayTerms = _e.displayTerms, doneLoading = _e.doneLoading, getCodesForDrug = _e.getCodesForDrug, getDrugsForDisplayTerm = _e.getDrugsForDisplayTerm;
1179
+ var _f = useState({}), drugs = _f[0], setDrugs = _f[1];
1059
1180
  // uncomment to load data after initial typing
1060
1181
  // const [query, setQuery] = useState('')
1061
1182
  // useEffect(() => {
@@ -1078,6 +1199,9 @@ export var MedicationsInput = function (_a) {
1078
1199
  // })
1079
1200
  // .catch(console.error)
1080
1201
  // }, [value, getDrugsForDisplayTerm])
1202
+ if (((_d = field.options) === null || _d === void 0 ? void 0 : _d.dataSource) === CANVAS_TITLE) {
1203
+ return _jsx(CanvasMedicationsInput, __assign({ field: field, value: value, onChange: onChange }, props));
1204
+ }
1081
1205
  return (_jsxs(Grid, __assign({ container: true, direction: "column", sx: { mt: 2 } }, { children: [(value !== null && value !== void 0 ? value : []).map(function (v, i) {
1082
1206
  var _a, _b, _d, _e, _f, _g, _h, _j, _k, _l;
1083
1207
  return (_jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap" }, { children: _jsx(Grid, __assign({ item: true, sx: { width: '100%' } }, { children: _jsxs(Grid, __assign({ container: true, direction: "column" }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Autocomplete, { freeSolo: false, multiple: false, loading: !doneLoading, options:
@@ -1617,15 +1741,15 @@ export var AllergiesInput = function (_a) {
1617
1741
  }, 200);
1618
1742
  return function () { clearTimeout(t); };
1619
1743
  }, [session, query, (_b = field === null || field === void 0 ? void 0 : field.options) === null || _b === void 0 ? void 0 : _b.dataSource]);
1620
- return (_jsx(Autocomplete, { multiple: true, value: value || [], options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
1621
- if (!v) {
1622
- return;
1623
- }
1624
- onChange(v, field.id);
1625
- setResults([]);
1626
- }, getOptionLabel: function (v) { return first_letter_capitalized(v.display); }, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search allergies..." }))); }, renderTags: function (value, getTagProps) {
1627
- return value.map(function (value, index) { return (_jsx(Chip, __assign({ label: _jsx(Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: value.display })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
1628
- } }));
1744
+ return (_jsxs(Grid, __assign({ container: true, direction: "column", spacing: 1 }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Autocomplete, { multiple: true, value: value || [], options: results, style: { marginTop: 5 }, noOptionsText: query.length ? 'No results found' : 'Type to start search', onChange: function (e, v) {
1745
+ if (!v) {
1746
+ return;
1747
+ }
1748
+ onChange(v, field.id);
1749
+ setResults([]);
1750
+ }, getOptionLabel: function (v) { return first_letter_capitalized(v.display); }, filterOptions: function (o) { return o; }, inputValue: query, onInputChange: function (e, v) { return e && setQuery(v); }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: defaultInputProps.sx }), required: !field.isOptional, size: "small", label: "", placeholder: "Search allergies..." }))); }, renderTags: function (value, getTagProps) {
1751
+ return value.map(function (value, index) { return (_jsx(Chip, __assign({ label: _jsx(Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: value.display })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
1752
+ } }) })), (value || []).map(function (allergy, i) { return (_jsx(Grid, __assign({ item: true }, { children: _jsxs(Grid, __assign({ container: true, alignItems: "center", wrap: "nowrap", columnGap: 0.5, justifyContent: "space-between" }, { children: [_jsx(Grid, __assign({ item: true }, { children: _jsx(Typography, __assign({ noWrap: true, sx: { width: 85, fontSize: 14 } }, { children: allergy.display })) })), _jsx(Grid, __assign({ item: true, sx: { width: 140 } }, { children: _jsx(StringSelector, { options: ['mild', 'moderate', 'severe'], size: "small", label: "Severity", value: allergy.severity || '', onChange: function (severity) { return onChange((value || []).map(function (v, _i) { return i === _i ? __assign(__assign({}, v), { severity: severity }) : v; }), field.id); }, getDisplayValue: first_letter_capitalized }) })), _jsx(Grid, __assign({ item: true, sx: { width: "50%" } }, { children: _jsx(TextField, { InputProps: { sx: defaultInputProps.sx }, fullWidth: true, size: "small", label: "Note", value: allergy.note || '', onChange: function (e) { return onChange((value || []).map(function (v, _i) { return i === _i ? __assign(__assign({}, v), { note: e.target.value }) : v; }), field.id); } }) }))] })) }), i)); })] })));
1629
1753
  };
1630
1754
  var display_with_code = function (v) { return "".concat(v.code, ": ").concat(first_letter_capitalized(v.display)); };
1631
1755
  export var ConditionsInput = function (_a) {