@medplum/app 5.1.25 → 5.1.26
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/assets/{index-DPaJat07.js → index-1nVihVx3.js} +6 -6
- package/dist/assets/index-1nVihVx3.js.map +1 -0
- package/dist/assets/{index-36idBdlk.css → index-BRO5p_Nl.css} +1 -1
- package/dist/assets/{jsQR-DtKuncVr.js → jsQR-BHcLbI6s.js} +2 -2
- package/dist/assets/{jsQR-DtKuncVr.js.map → jsQR-BHcLbI6s.js.map} +1 -1
- package/dist/index.html +3 -3
- package/package.json +6 -6
- package/dist/assets/index-DPaJat07.js.map +0 -1
|
@@ -53,7 +53,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function ar({color:e,theme:t,autoContrast:n}){ret
|
|
|
53
53
|
`),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}function d_(e){e=u_(e),e.decimalSeparator,e.allowedDecimalSeparators,e.thousandsGroupStyle;var t=e.suffix,n=e.allowNegative,r=e.allowLeadingZeros,i=e.onKeyDown;i===void 0&&(i=Eg);var a=e.onBlur;a===void 0&&(a=Eg);var o=e.thousandSeparator,s=e.decimalScale,c=e.fixedDecimalScale,l=e.prefix;l===void 0&&(l=``);var u=e.defaultValue,d=e.value,f=e.valueIsNumericString,p=e.onValueChange,m=wg(e,[`decimalSeparator`,`allowedDecimalSeparators`,`thousandsGroupStyle`,`suffix`,`allowNegative`,`allowLeadingZeros`,`onKeyDown`,`onBlur`,`thousandSeparator`,`decimalScale`,`fixedDecimalScale`,`prefix`,`defaultValue`,`value`,`valueIsNumericString`,`onValueChange`]),h=i_(e),g=h.decimalSeparator,_=h.allowedDecimalSeparators,v=function(t){return r_(t,e)},y=function(t,n){return c_(t,n,e)},b=kg(d)?u:d,x=f??s_(b,l,t);kg(d)?kg(u)||(x||=typeof u==`number`):x||=typeof d==`number`;var S=function(e){return jg(e)?e:(typeof e==`number`&&(e=Bg(e)),x&&typeof s==`number`?Vg(e,s,!!c):e)},C=$g(S(d),S(u),!!x,v,y,p),w=C[0],T=w.numAsString,E=w.formattedValue,D=C[1];return Object.assign(Object.assign({},m),{value:E,valueIsNumericString:!1,isValidInputCharacter:function(e){return e===g?!0:Og(e)},isCharacterSame:function(e){var t=e.currentValue,n=e.lastValue,r=e.formattedValue,i=e.currentValueIndex,a=e.formattedValueIndex,o=t[i],u=r[a],f=Ug(n,t).to,p=function(e){return y(e).indexOf(`.`)+l.length};return d===0&&c&&s&&t[f.start]===g&&p(t)<i&&p(r)>a?!1:i>=f.start&&i<f.end&&_&&_.includes(o)&&u===g?!0:o===u},onValueChange:D,format:v,removeFormatting:y,getCaretBoundary:function(t){return l_(t,e)},onKeyDown:function(e){var t=e.target,r=e.key,a=t.selectionStart,u=t.selectionEnd,d=t.value;if(d===void 0&&(d=``),(r===`Backspace`||r===`Delete`)&&u<l.length&&d!==`-`){e.preventDefault();return}if(a!==u){i(e);return}r===`Backspace`&&d[0]===`-`&&a===l.length+1&&n&&Hg(t,1),s&&c&&(r===`Backspace`&&d[a-1]===g?(Hg(t,a-1),e.preventDefault()):r===`Delete`&&d[a]===g&&e.preventDefault()),_?.includes(r)&&d[a]===g&&Hg(t,a+1);var f=o===!0?`,`:o;r===`Backspace`&&d[a-1]===f&&Hg(t,a-1),r===`Delete`&&d[a]===f&&Hg(t,a+1),i(e)},onBlur:function(t){var n=T;n.match(/\d/g)||(n=``),r||(n=Lg(n)),c&&s&&(n=Vg(n,s,c)),n!==T&&D({formattedValue:r_(n,e),value:n,floatValue:parseFloat(n)},{event:t,source:Tg.event}),a(t)}})}function f_(e){var t=d_(e);return b.createElement(n_,Object.assign({},t))}var p_={root:`m_e2f5cd4e`,controls:`m_95e17d22`,control:`m_80b4b171`};function m_({direction:e,style:t,...n}){return(0,I.jsx)(`svg`,{style:{width:`var(--ni-chevron-size)`,height:`var(--ni-chevron-size)`,transform:e===`up`?`rotate(180deg)`:void 0,...t},viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...n,children:(0,I.jsx)(`path`,{d:`M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})}var h_=/^(0\.0*|-0(\.0*)?)$/,g_=/^-?0\d+(\.\d+)?\.?$/,__=/\.\d*0$/,v_=/^-?\d+\.$/;function y_(e){return typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))}function b_(e){return typeof e==`number`?e<2**53-1:e===``||y_(e)&&Number(e)<2**53-1}function x_(e){return e.toString().replace(`.`,``).length}function S_(e,t){return(typeof e==`number`?e<2**53-1:!Number.isNaN(Number(e)))&&!Number.isNaN(e)&&x_(t)<14&&t!==``}function C_(e,t,n){return e===void 0?!0:(t===void 0||e>=t)&&(n===void 0||e<=n)}var w_={step:1,clampBehavior:`blur`,allowDecimal:!0,allowNegative:!0,withKeyboardEvents:!0,allowLeadingZeros:!0,trimLeadingZeroesOnBlur:!0,startValue:0,allowedDecimalSeparators:[`.`,`,`]},T_=nt((e,{size:t})=>({controls:{"--ni-chevron-size":Xe(t,`ni-chevron-size`)}}));function E_(e,t,n){let r=e.toString(),i=v_.test(r),a=r.replace(/^0+(?=\d)/,``),o=parseFloat(a);if(Number.isNaN(o))return a;if(o>2**53-1)return t===void 0?a:t;let s=lt(o,n,t);return i?`${s.toString().replace(/^0+(?=\d)/,``)}.`:s}var D_=B((e,t)=>{let n=R(`NumberInput`,w_,e),{className:r,classNames:i,styles:a,unstyled:o,vars:s,onChange:c,onValueChange:l,value:u,defaultValue:d,max:f,min:p,step:m,hideControls:h,rightSection:g,isAllowed:_,clampBehavior:v,onBlur:y,allowDecimal:x,decimalScale:S,onKeyDown:C,onKeyDownCapture:w,handlersRef:T,startValue:E,disabled:D,rightSectionPointerEvents:O,allowNegative:k,readOnly:A,size:j,rightSectionWidth:M,stepHoldInterval:ee,stepHoldDelay:N,allowLeadingZeros:P,withKeyboardEvents:te,trimLeadingZeroesOnBlur:ne,allowedDecimalSeparators:re,attributes:ie,...ae}=n,oe=L({name:`NumberInput`,classes:p_,props:n,classNames:i,styles:a,unstyled:o,attributes:ie,vars:s,varsResolver:T_}),{resolvedClassNames:se,resolvedStyles:ce}=xr({classNames:i,styles:a,props:n}),[le,ue]=Ht({value:u,defaultValue:d,finalValue:``,onChange:c}),de=N!==void 0&&ee!==void 0,fe=(0,b.useRef)(null),pe=(0,b.useRef)(null),me=(0,b.useRef)(0),he=(e,t)=>{t.source===`event`&&ue(S_(e.floatValue,e.value)&&!h_.test(e.value)&&!(P&&g_.test(e.value))&&!__.test(e.value)&&!v_.test(e.value)?e.floatValue:e.value),l?.(e,t)},ge=e=>{let t=String(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0},_e=e=>{fe.current&&e!==void 0&&fe.current.setSelectionRange(e,e)},ve=(0,b.useRef)(zr);ve.current=()=>{if(!b_(le))return;let e,t=ge(le),n=ge(m),r=Math.max(t,n),i=10**r;if(!y_(le)&&(typeof le!=`number`||Number.isNaN(le)))e=lt(E,p,f);else if(f!==void 0){let t=(Math.round(Number(le)*i)+Math.round(m*i))/i;e=t<=f?t:f}else e=(Math.round(Number(le)*i)+Math.round(m*i))/i;let a=e.toFixed(r);ue(parseFloat(a)),l?.({floatValue:parseFloat(a),formattedValue:a,value:a},{source:`increment`}),setTimeout(()=>_e(fe.current?.value.length),0)};let ye=(0,b.useRef)(zr);ye.current=()=>{if(!b_(le))return;let e,t=p===void 0?k?-(2**53-1):0:p,n=ge(le),r=ge(m),i=Math.max(n,r),a=10**i;if(!y_(le)&&typeof le!=`number`||Number.isNaN(le))e=lt(E,t,f);else{let n=(Math.round(Number(le)*a)-Math.round(m*a))/a;e=t!==void 0&&n<t?t:n}let o=e.toFixed(i);ue(parseFloat(o)),l?.({floatValue:parseFloat(o),formattedValue:o,value:o},{source:`decrement`}),setTimeout(()=>_e(fe.current?.value.length),0)};let be=e=>{let t=e.clipboardData.getData(`text`),n=ae.decimalSeparator||`.`,r=(re||[`.`,`,`]).filter(e=>e!==n);if(r.some(e=>t.includes(e))){e.preventDefault();let i=t;r.forEach(e=>{i=i.split(e).join(n)});let a=fe.current;if(a){let e=a.selectionStart??0,t=a.selectionEnd??0,n=a.value,r=n.substring(0,e)+i+n.substring(t);(Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set)?.call(a,r),a.dispatchEvent(new Event(`change`,{bubbles:!0}));let o=e+i.length;setTimeout(()=>_e(o),0)}}ae.onPaste?.(e)},xe=e=>{C?.(e),!(A||!te)&&(e.key===`ArrowUp`&&(e.preventDefault(),ve.current?.()),e.key===`ArrowDown`&&(e.preventDefault(),ye.current?.()))},Se=e=>{if(w?.(e),e.key===`Backspace`){let t=fe.current;t&&t.selectionStart===0&&t.selectionStart===t.selectionEnd&&(e.preventDefault(),window.setTimeout(()=>_e(0),0))}},Ce=e=>{let t=le;v===`blur`&&typeof t==`number`&&(t=lt(t,p,f)),ne&&typeof t==`string`&&ge(t)<15&&(t=E_(t,f,p)),le!==t&&ue(t),y?.(e)};zt(T,{increment:ve.current,decrement:ye.current});let we=e=>{e?ve.current?.():ye.current?.(),me.current+=1},Te=e=>{if(we(e),de){let t=typeof ee==`number`?ee:ee(me.current);pe.current=window.setTimeout(()=>Te(e),t)}},Ee=(e,t)=>{e.preventDefault(),fe.current?.focus(),we(t),de&&(pe.current=window.setTimeout(()=>Te(t),N))},De=()=>{pe.current&&window.clearTimeout(pe.current),pe.current=null,me.current=0},Oe=(0,I.jsxs)(`div`,{...oe(`controls`),children:[(0,I.jsx)(qc,{...oe(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof le==`number`&&f!==void 0&&le>=f,mod:{direction:`up`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{Ee(e,!0)},onPointerUp:De,onPointerLeave:De,children:(0,I.jsx)(m_,{direction:`up`})}),(0,I.jsx)(qc,{...oe(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof le==`number`&&p!==void 0&&le<=p,mod:{direction:`down`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{Ee(e,!1)},onPointerUp:De,onPointerLeave:De,children:(0,I.jsx)(m_,{direction:`down`})})]});return(0,I.jsx)(eu,{component:f_,allowNegative:k,className:it(p_.root,r),size:j,inputMode:`decimal`,...ae,readOnly:A,disabled:D,value:le,getInputRef:Vt(t,fe),onValueChange:he,rightSection:h||A||!b_(le)?g:g||Oe,classNames:se,styles:ce,unstyled:o,__staticSelector:`NumberInput`,decimalScale:x?S:0,onPaste:be,onKeyDown:xe,onKeyDownCapture:Se,rightSectionPointerEvents:O??(D?`none`:void 0),rightSectionWidth:M??`var(--ni-right-section-width-${j||`sm`})`,allowLeadingZeros:P,allowedDecimalSeparators:re,onBlur:Ce,attributes:ie,isAllowed:e=>v===`strict`?_?_(e)&&C_(e.floatValue,p,f):C_(e.floatValue,p,f):_?_(e):!0})});D_.classes={...eu.classes,...p_},D_.displayName=`@mantine/core/NumberInput`;var O_={root:`m_4addd315`,control:`m_326d024a`,dots:`m_4ad7767d`},[k_,A_]=Ke(`Pagination.Root component was not found in tree`),j_={withPadding:!0},M_=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,active:s,disabled:c,withPadding:l,mod:u,...d}=R(`PaginationControl`,j_,e),f=A_(),p=c||f.disabled;return(0,I.jsx)(qc,{ref:t,disabled:p,mod:[{active:s,disabled:p,"with-padding":l},u],...f.getStyles(`control`,{className:r,style:i,classNames:n,styles:a,active:!p}),...d})});M_.classes=O_,M_.displayName=`@mantine/core/PaginationControl`;function N_({style:e,children:t,path:n,...r}){return(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,xmlns:`http://www.w3.org/2000/svg`,style:{width:`calc(var(--pagination-control-size) / 1.8)`,height:`calc(var(--pagination-control-size) / 1.8)`,...e},...r,children:(0,I.jsx)(`path`,{d:n,fill:`currentColor`})})}var P_=e=>(0,I.jsx)(N_,{...e,path:`M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z`}),F_=e=>(0,I.jsx)(N_,{...e,path:`M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z`}),I_=e=>(0,I.jsx)(N_,{...e,path:`M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z`}),L_=e=>(0,I.jsx)(N_,{...e,path:`M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z`}),R_={icon:e=>(0,I.jsx)(N_,{...e,path:`M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z`})},z_=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,icon:s,...c}=R(`PaginationDots`,R_,e);return(0,I.jsx)(z,{ref:t,...A_().getStyles(`dots`,{className:r,style:i,styles:a,classNames:n}),...c,children:(0,I.jsx)(s,{style:{width:`calc(var(--pagination-control-size) / 1.8)`,height:`calc(var(--pagination-control-size) / 1.8)`}})})});z_.classes=O_,z_.displayName=`@mantine/core/PaginationDots`;function B_({icon:e,name:t,action:n,type:r}){let i={icon:e},a=(0,b.forwardRef)((e,a)=>{let{icon:o,...s}=R(t,i,e),c=A_(),l=r===`next`?c.active===c.total:c.active===1;return(0,I.jsx)(M_,{disabled:c.disabled||l,ref:a,onClick:c[n],withPadding:!1,...s,children:(0,I.jsx)(o,{className:`mantine-rotate-rtl`,style:{width:`calc(var(--pagination-control-size) / 1.8)`,height:`calc(var(--pagination-control-size) / 1.8)`}})})});return a.displayName=`@mantine/core/${t}`,Ur(a)}var V_=B_({icon:P_,name:`PaginationNext`,action:`onNext`,type:`next`}),H_=B_({icon:F_,name:`PaginationPrevious`,action:`onPrevious`,type:`previous`}),U_=B_({icon:I_,name:`PaginationFirst`,action:`onFirst`,type:`previous`}),W_=B_({icon:L_,name:`PaginationLast`,action:`onLast`,type:`next`});function G_({dotsIcon:e}){let t=A_();return(0,I.jsx)(I.Fragment,{children:t.range.map((n,r)=>n===`dots`?(0,I.jsx)(z_,{icon:e},r):(0,I.jsx)(M_,{active:n===t.active,"aria-current":n===t.active?`page`:void 0,onClick:()=>t.onChange(n),disabled:t.disabled,...t.getItemProps?.(n),children:t.getItemProps?.(n)?.children??n},r))})}G_.displayName=`@mantine/core/PaginationItems`;var K_={siblings:1,boundaries:1},q_=nt((e,{size:t,radius:n,color:r,autoContrast:i})=>({root:{"--pagination-control-radius":n===void 0?void 0:Qe(n),"--pagination-control-size":Xe(t,`pagination-control-size`),"--pagination-control-fz":$e(t),"--pagination-active-bg":r?Mn(r,e):void 0,"--pagination-active-color":gd(i,e)?ar({color:r,theme:e,autoContrast:i}):void 0}})),J_=B((e,t)=>{let n=R(`PaginationRoot`,K_,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,total:l,value:u,defaultValue:d,onChange:f,disabled:p,siblings:m,boundaries:h,color:g,radius:_,onNextPage:v,onPreviousPage:y,onFirstPage:b,onLastPage:x,getItemProps:S,autoContrast:C,attributes:w,...T}=n,E=L({name:`Pagination`,classes:O_,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:w,vars:c,varsResolver:q_}),{range:D,setPage:O,next:k,previous:A,active:j,first:M,last:ee}=Gt({page:u,initialPage:d,onChange:f,total:l,siblings:m,boundaries:h});return(0,I.jsx)(k_,{value:{total:l,range:D,active:j,disabled:p,getItemProps:S,onChange:O,onNext:Hm(v,k),onPrevious:Hm(y,A),onFirst:Hm(b,M),onLast:Hm(x,ee),getStyles:E},children:(0,I.jsx)(z,{ref:t,...E(`root`),...T})})});J_.classes=O_,J_.displayName=`@mantine/core/PaginationRoot`;var Y_={withControls:!0,withPages:!0,siblings:1,boundaries:1,gap:8},X_=B((e,t)=>{let{withEdges:n,withControls:r,getControlProps:i,nextIcon:a,previousIcon:o,lastIcon:s,firstIcon:c,dotsIcon:l,total:u,gap:d,hideWithOnePage:f,withPages:p,...m}=R(`Pagination`,Y_,e);return u<=0||f&&u===1?null:(0,I.jsx)(J_,{ref:t,total:u,...m,children:(0,I.jsxs)(V,{gap:d,children:[n&&(0,I.jsx)(U_,{icon:c,...i?.(`first`)}),r&&(0,I.jsx)(H_,{icon:o,...i?.(`previous`)}),p&&(0,I.jsx)(G_,{dotsIcon:l}),r&&(0,I.jsx)(V_,{icon:a,...i?.(`next`)}),n&&(0,I.jsx)(W_,{icon:s,...i?.(`last`)})]})})});X_.classes=O_,X_.displayName=`@mantine/core/Pagination`,X_.Root=J_,X_.Control=M_,X_.Dots=z_,X_.First=U_,X_.Last=W_,X_.Next=V_,X_.Previous=H_,X_.Items=G_;var Z_={root:`m_f61ca620`,input:`m_ccf8da4c`,innerInput:`m_f2d85dd2`,visibilityToggle:`m_b1072d44`},Q_={visibilityToggleIcon:({reveal:e})=>(0,I.jsx)(`svg`,{viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,style:{width:`var(--psi-icon-size)`,height:`var(--psi-icon-size)`},children:(0,I.jsx)(`path`,{d:e?`M13.3536 2.35355C13.5488 2.15829 13.5488 1.84171 13.3536 1.64645C13.1583 1.45118 12.8417 1.45118 12.6464 1.64645L10.6828 3.61012C9.70652 3.21671 8.63759 3 7.5 3C4.30786 3 1.65639 4.70638 0.0760002 7.23501C-0.0253338 7.39715 -0.0253334 7.60288 0.0760014 7.76501C0.902945 9.08812 2.02314 10.1861 3.36061 10.9323L1.64645 12.6464C1.45118 12.8417 1.45118 13.1583 1.64645 13.3536C1.84171 13.5488 2.15829 13.5488 2.35355 13.3536L4.31723 11.3899C5.29348 11.7833 6.36241 12 7.5 12C10.6921 12 13.3436 10.2936 14.924 7.76501C15.0253 7.60288 15.0253 7.39715 14.924 7.23501C14.0971 5.9119 12.9769 4.81391 11.6394 4.06771L13.3536 2.35355ZM9.90428 4.38861C9.15332 4.1361 8.34759 4 7.5 4C4.80285 4 2.52952 5.37816 1.09622 7.50001C1.87284 8.6497 2.89609 9.58106 4.09974 10.1931L9.90428 4.38861ZM5.09572 10.6114L10.9003 4.80685C12.1039 5.41894 13.1272 6.35031 13.9038 7.50001C12.4705 9.62183 10.1971 11 7.5 11C6.65241 11 5.84668 10.8639 5.09572 10.6114Z`:`M7.5 11C4.80285 11 2.52952 9.62184 1.09622 7.50001C2.52952 5.37816 4.80285 4 7.5 4C10.1971 4 12.4705 5.37816 13.9038 7.50001C12.4705 9.62183 10.1971 11 7.5 11ZM7.5 3C4.30786 3 1.65639 4.70638 0.0760002 7.23501C-0.0253338 7.39715 -0.0253334 7.60288 0.0760014 7.76501C1.65639 10.2936 4.30786 12 7.5 12C10.6921 12 13.3436 10.2936 14.924 7.76501C15.0253 7.60288 15.0253 7.39715 14.924 7.23501C13.3436 4.70638 10.6921 3 7.5 3ZM7.5 9.5C8.60457 9.5 9.5 8.60457 9.5 7.5C9.5 6.39543 8.60457 5.5 7.5 5.5C6.39543 5.5 5.5 6.39543 5.5 7.5C5.5 8.60457 6.39543 9.5 7.5 9.5Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})},$_=nt((e,{size:t})=>({root:{"--psi-icon-size":Xe(t,`psi-icon-size`),"--psi-button-size":Xe(t,`psi-button-size`)}})),ev=B((e,t)=>{let n=R(`PasswordInput`,Q_,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,required:l,error:u,leftSection:d,disabled:f,id:p,variant:m,inputContainer:h,description:g,label:_,size:v,errorProps:y,descriptionProps:b,labelProps:x,withAsterisk:S,inputWrapperOrder:C,wrapperProps:w,radius:T,rightSection:E,rightSectionWidth:D,rightSectionPointerEvents:O,leftSectionWidth:k,visible:A,defaultVisible:j,onVisibilityChange:M,visibilityToggleIcon:ee,visibilityToggleButtonProps:N,rightSectionProps:P,leftSectionProps:te,leftSectionPointerEvents:ne,withErrorStyles:re,mod:ie,attributes:ae,...oe}=n,se=Rt(p),[ce,le]=Ht({value:A,defaultValue:j,finalValue:!1,onChange:M}),ue=()=>le(!ce),de=L({name:`PasswordInput`,classes:Z_,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:ae,vars:c,varsResolver:$_}),{resolvedClassNames:fe,resolvedStyles:pe}=xr({classNames:r,styles:o,props:n}),{styleProps:me,rest:he}=$r(oe),ge=y?.id||`${se}-error`,_e=b?.id||`${se}-description`,ve=`${u&&typeof u!=`boolean`?ge:``} ${g?_e:``}`,ye=ve.trim().length>0?ve.trim():void 0,be=(0,I.jsx)(vl,{...de(`visibilityToggle`),disabled:f,radius:T,"aria-hidden":!N,"aria-pressed":ce,tabIndex:-1,...N,variant:N?.variant??`subtle`,color:`gray`,unstyled:s,onTouchEnd:e=>{e.preventDefault(),N?.onTouchEnd?.(e),ue()},onMouseDown:e=>{e.preventDefault(),N?.onMouseDown?.(e),ue()},onKeyDown:e=>{N?.onKeyDown?.(e),e.key===` `&&(e.preventDefault(),ue())},children:(0,I.jsx)(ee,{reveal:ce})});return(0,I.jsx)(Zl.Wrapper,{required:l,id:se,label:_,error:u,description:g,size:v,classNames:fe,styles:pe,__staticSelector:`PasswordInput`,__stylesApiProps:n,unstyled:s,withAsterisk:S,inputWrapperOrder:C,inputContainer:h,variant:m,labelProps:{...x,htmlFor:se},descriptionProps:{...b,id:_e},errorProps:{...y,id:ge},mod:ie,attributes:ae,...de(`root`),...me,...w,children:(0,I.jsx)(Zl,{component:`div`,error:u,leftSection:d,size:v,classNames:{...fe,input:it(Z_.input,fe.input)},styles:pe,radius:T,disabled:f,__staticSelector:`PasswordInput`,__stylesApiProps:n,rightSectionWidth:D,rightSection:E??be,variant:m,unstyled:s,leftSectionWidth:k,rightSectionPointerEvents:O||`all`,rightSectionProps:P,leftSectionProps:te,leftSectionPointerEvents:ne,withAria:!1,withErrorStyles:re,attributes:ae,children:(0,I.jsx)(`input`,{required:l,"data-invalid":!!u||void 0,"data-with-left-section":!!d||void 0,...de(`innerInput`),disabled:f,id:se,ref:t,...he,"aria-describedby":ye,autoComplete:he.autoComplete||`off`,type:ce?`text`:`password`})})})});ev.classes={...eu.classes,...Z_},ev.displayName=`@mantine/core/PasswordInput`;var tv={root:`m_db6d6462`,section:`m_2242eb65`,"stripes-animation":`m_81a374bd`,"stripes-animation-vertical":`m_e0fb7a86`,label:`m_91e40b74`},[nv,rv]=Ke(`Progress.Root component was not found in tree`),iv=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,...s}=R(`ProgressLabel`,null,e);return(0,I.jsx)(z,{ref:t,...rv().getStyles(`label`,{className:r,style:i,classNames:n,styles:a}),...s})});iv.classes=tv,iv.displayName=`@mantine/core/ProgressLabel`;var av=nt((e,{size:t,radius:n,transitionDuration:r})=>({root:{"--progress-size":Xe(t,`progress-size`),"--progress-radius":n===void 0?void 0:Qe(n),"--progress-transition-duration":typeof r==`number`?`${r}ms`:void 0}})),ov=B((e,t)=>{let n=R(`ProgressRoot`,null,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,autoContrast:l,transitionDuration:u,orientation:d,attributes:f,mod:p,...m}=n,h=L({name:`Progress`,classes:tv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:f,vars:c,varsResolver:av});return(0,I.jsx)(nv,{value:{getStyles:h,autoContrast:l},children:(0,I.jsx)(z,{ref:t,mod:[{orientation:d},p],...h(`root`),...m})})});ov.classes=tv,ov.displayName=`@mantine/core/ProgressRoot`;var sv={withAria:!0},cv=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,value:s,withAria:c,color:l,striped:u,animated:d,mod:f,...p}=R(`ProgressSection`,sv,e),m=rv(),h=er(),g=c?{role:`progressbar`,"aria-valuemax":100,"aria-valuemin":0,"aria-valuenow":s,"aria-valuetext":`${s}%`}:{};return(0,I.jsx)(z,{ref:t,...m.getStyles(`section`,{className:r,classNames:n,styles:a,style:i}),...p,...g,mod:[{striped:u||d,animated:d},f],__vars:{"--progress-section-size":`${s}%`,"--progress-section-color":Mn(l,h),"--progress-label-color":gd(m.autoContrast,h)?ar({color:l,theme:h,autoContrast:m.autoContrast}):void 0}})});cv.classes=tv,cv.displayName=`@mantine/core/ProgressSection`;var lv=B((e,t)=>{let n=R(`Progress`,null,e),{value:r,classNames:i,styles:a,vars:o,color:s,striped:c,animated:l,"aria-label":u,...d}=n,{resolvedClassNames:f,resolvedStyles:p}=xr({classNames:i,styles:a,props:n});return(0,I.jsx)(ov,{ref:t,classNames:f,styles:p,vars:o,...d,children:(0,I.jsx)(cv,{value:r,color:s,striped:c,animated:l,"aria-label":u})})});lv.classes=tv,lv.displayName=`@mantine/core/Progress`,lv.Section=cv,lv.Root=ov,lv.Label=iv;var uv={root:`m_f3f1af94`,inner:`m_89c4f5e4`,icon:`m_f3ed6b2b`,radio:`m_8a3dbb89`,"radio--outline":`m_1bfe9d39`},[dv,fv]=Ol(),[pv,mv]=Ol(),hv={card:`m_9dc8ae12`},gv={withBorder:!0},_v=nt((e,{radius:t})=>({card:{"--card-radius":Qe(t)}})),vv=B((e,t)=>{let n=R(`RadioCard`,gv,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,checked:l,mod:u,withBorder:d,value:f,onClick:p,name:m,onKeyDown:h,attributes:g,..._}=n,v=L({name:`RadioCard`,classes:hv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:_v,rootSelector:`card`}),{dir:y}=cc(),b=fv(),x=typeof l==`boolean`?l:b?.value===f||!1,S=m||b?.name,C=e=>{if(h?.(e),[`ArrowDown`,`ArrowUp`,`ArrowLeft`,`ArrowRight`].includes(e.nativeEvent.code)){e.preventDefault();let t=Array.from(document.querySelectorAll(`[role="radio"][name="${S||`__mantine`}"]`)),n=t.findIndex(t=>t===e.target),r=n+1>=t.length?0:n+1,i=n-1<0?t.length-1:n-1;e.nativeEvent.code===`ArrowDown`&&(t[r].focus(),t[r].click()),e.nativeEvent.code===`ArrowUp`&&(t[i].focus(),t[i].click()),e.nativeEvent.code===`ArrowLeft`&&(t[y===`ltr`?i:r].focus(),t[y===`ltr`?i:r].click()),e.nativeEvent.code===`ArrowRight`&&(t[y===`ltr`?r:i].focus(),t[y===`ltr`?r:i].click())}};return(0,I.jsx)(pv,{value:{checked:x},children:(0,I.jsx)(qc,{ref:t,mod:[{"with-border":d,checked:x},u],...v(`card`),..._,role:`radio`,"aria-checked":x,name:S,onClick:e=>{p?.(e),b?.onChange(f||``)},onKeyDown:C})})});vv.displayName=`@mantine/core/RadioCard`,vv.classes=hv;var yv=B((e,t)=>{let{value:n,defaultValue:r,onChange:i,size:a,wrapperProps:o,children:s,name:c,readOnly:l,disabled:u,...d}=R(`RadioGroup`,null,e),f=Rt(c),[p,m]=Ht({value:n,defaultValue:r,finalValue:``,onChange:i});return(0,I.jsx)(dv,{value:{value:p,onChange:e=>!l&&m(typeof e==`string`?e:e.currentTarget.value),size:a,name:f,disabled:u},children:(0,I.jsx)(Zl.Wrapper,{size:a,ref:t,...o,...d,labelElement:`div`,__staticSelector:`RadioGroup`,children:(0,I.jsx)(Ad,{role:`radiogroup`,children:s})})})});yv.classes=Zl.Wrapper.classes,yv.displayName=`@mantine/core/RadioGroup`;function bv({size:e,style:t,...n}){return(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 5 5`,style:{width:F(e),height:F(e),...t},"aria-hidden":!0,...n,children:(0,I.jsx)(`circle`,{cx:`2.5`,cy:`2.5`,r:`2.5`,fill:`currentColor`})})}var xv={indicator:`m_717d7ff6`,icon:`m_3e4da632`,"indicator--outline":`m_2980836c`},Sv={icon:bv},Cv=nt((e,{radius:t,color:n,size:r,iconColor:i,variant:a,autoContrast:o})=>{let s=jn({color:n||e.primaryColor,theme:e}),c=s.isThemeColor&&s.shade===void 0?`var(--mantine-color-${s.color}-outline)`:s.color;return{indicator:{"--radio-size":Xe(r,`radio-size`),"--radio-radius":t===void 0?void 0:Qe(t),"--radio-color":a===`outline`?c:Mn(n,e),"--radio-icon-size":Xe(r,`radio-icon-size`),"--radio-icon-color":i?Mn(i,e):gd(o,e)?ar({color:n,theme:e,autoContrast:o}):void 0}}}),wv=B((e,t)=>{let n=R(`RadioIndicator`,Sv,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,icon:l,radius:u,color:d,iconColor:f,autoContrast:p,checked:m,mod:h,variant:g,disabled:_,attributes:v,...y}=n,b=L({name:`RadioIndicator`,classes:xv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:v,vars:c,varsResolver:Cv,rootSelector:`indicator`}),x=mv(),S=typeof m==`boolean`?m:x?.checked||!1;return(0,I.jsx)(z,{ref:t,...b(`indicator`,{variant:g}),variant:g,mod:[{checked:S,disabled:_},h],...y,children:(0,I.jsx)(l,{...b(`icon`)})})});wv.displayName=`@mantine/core/RadioIndicator`,wv.classes=xv;var Tv={labelPosition:`right`},Ev=nt((e,{size:t,radius:n,color:r,iconColor:i,variant:a,autoContrast:o})=>{let s=jn({color:r||e.primaryColor,theme:e}),c=s.isThemeColor&&s.shade===void 0?`var(--mantine-color-${s.color}-outline)`:s.color;return{root:{"--radio-size":Xe(t,`radio-size`),"--radio-radius":n===void 0?void 0:Qe(n),"--radio-color":a===`outline`?c:Mn(r,e),"--radio-icon-color":i?Mn(i,e):gd(o,e)?ar({color:r,theme:e,autoContrast:o}):void 0,"--radio-icon-size":Xe(t,`radio-icon-size`)}}}),Dv=B((e,t)=>{let n=R(`Radio`,Tv,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,id:l,size:u,label:d,labelPosition:f,description:p,error:m,radius:h,color:g,variant:_,disabled:v,wrapperProps:y,icon:b=bv,rootRef:x,iconColor:S,onChange:C,mod:w,attributes:T,checked:E,...D}=n,O=L({name:`Radio`,classes:uv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:T,vars:c,varsResolver:Ev}),k=fv(),A=k?.size??u,j=n.size?u:A,{styleProps:M,rest:ee}=$r(D),N=Rt(l),P=k?k.value===ee.value:void 0,te={checked:P??E,name:k?.name??ee.name,onChange:e=>{k?.onChange(e),C?.(e)},disabled:k?.disabled??v};return(0,I.jsx)(yd,{...O(`root`),__staticSelector:`Radio`,__stylesApiProps:n,id:N,size:j,labelPosition:f,label:d,description:p,error:m,disabled:te.disabled,classNames:r,styles:o,unstyled:s,"data-checked":(P??E)||void 0,variant:_,ref:x,mod:w,...M,...y,children:(0,I.jsxs)(z,{...O(`inner`),mod:{"label-position":f},children:[(0,I.jsx)(z,{...O(`radio`,{focusable:!0,variant:_}),...ee,...te,component:`input`,mod:{error:!!m},ref:t,id:N,type:`radio`}),(0,I.jsx)(b,{...O(`icon`),"aria-hidden":!0})]})})});Dv.classes=uv,Dv.displayName=`@mantine/core/Radio`,Dv.Group=yv,Dv.Card=vv,Dv.Indicator=wv;var Ov={duration:100,transition:`fade`};function kv(e,t){return{...Ov,...t,...e}}var Av={tooltip:`m_1b3c8819`,arrow:`m_f898399f`};function jv(e,t){return Array.isArray(e)?[...e].reduce((e,n)=>({...e,...jv(n,t)}),{}):typeof e==`function`?e(t):e??{}}function Mv({offset:e,position:t,defaultOpened:n}){let[r,i]=(0,b.useState)(n),a=(0,b.useRef)(null),{x:o,y:s,elements:c,refs:l,update:u,placement:d}=ec({placement:t,middleware:[us({crossAxis:!0,padding:5,rootBoundary:`document`})]}),f=d.includes(`right`)?e:t.includes(`left`)?e*-1:0,p=d.includes(`bottom`)?e:t.includes(`top`)?e*-1:0,m=(0,b.useCallback)(({clientX:e,clientY:t})=>{l.setPositionReference({getBoundingClientRect(){return{width:0,height:0,x:e,y:t,left:e+f,top:t+p,right:e,bottom:t}}})},[c.reference]);return(0,b.useEffect)(()=>{if(l.floating.current){let e=a.current;e.addEventListener(`mousemove`,m);let t=Yi(l.floating.current);return t.forEach(e=>{e.addEventListener(`scroll`,u)}),()=>{e.removeEventListener(`mousemove`,m),t.forEach(e=>{e.removeEventListener(`scroll`,u)})}}},[c.reference,l.floating.current,u,m,r]),{handleMouseMove:m,x:o,y:s,opened:r,setOpened:i,boundaryRef:a,floating:l.setFloating}}var Nv={refProp:`ref`,withinPortal:!0,offset:10,position:`right`,zIndex:Je(`popover`)},Pv=nt((e,{radius:t,color:n})=>({tooltip:{"--tooltip-radius":t===void 0?void 0:Qe(t),"--tooltip-bg":n?Mn(n,e):void 0,"--tooltip-color":n?`var(--mantine-color-white)`:void 0}})),Fv=B((e,t)=>{let n=R(`TooltipFloating`,Nv,e),{children:r,refProp:i,withinPortal:a,style:o,className:s,classNames:c,styles:l,unstyled:u,radius:d,color:f,label:p,offset:m,position:h,multiline:g,zIndex:_,disabled:v,defaultOpened:y,variant:x,vars:S,portalProps:C,attributes:w,...T}=n,E=er(),D=L({name:`TooltipFloating`,props:n,classes:Av,className:s,style:o,classNames:c,styles:l,unstyled:u,attributes:w,rootSelector:`tooltip`,vars:S,varsResolver:Pv}),{handleMouseMove:O,x:k,y:A,opened:j,boundaryRef:M,floating:ee,setOpened:N}=Mv({offset:m,position:h,defaultOpened:y}),P=_f(r);if(!P)throw Error(`[@mantine/core] Tooltip.Floating component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);let te=Vt(M,Cf(P),t),ne=P.props,re=e=>{ne.onMouseEnter?.(e),O(e),N(!0)},ie=e=>{ne.onMouseLeave?.(e),N(!1)};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ff,{...C,withinPortal:a,children:(0,I.jsx)(z,{...T,...D(`tooltip`,{style:{...jv(o,E),zIndex:_,display:!v&&j?`block`:`none`,top:(A&&Math.round(A))??``,left:(k&&Math.round(k))??``}}),variant:x,ref:ee,mod:{multiline:g},children:p})}),(0,b.cloneElement)(P,{...ne,[i]:te,onMouseEnter:re,onMouseLeave:ie})]})});Fv.classes=Av,Fv.displayName=`@mantine/core/TooltipFloating`;var Iv=(0,b.createContext)(!1),Lv=Iv.Provider,Rv=()=>(0,b.useContext)(Iv),zv={openDelay:0,closeDelay:0};function Bv(e){let{openDelay:t,closeDelay:n,children:r}=R(`TooltipGroup`,zv,e);return(0,I.jsx)(Lv,{value:!0,children:(0,I.jsx)(qs,{delay:{open:t,close:n},children:r})})}Bv.displayName=`@mantine/core/TooltipGroup`,Bv.extend=e=>e;function Vv(e){if(e===void 0)return{shift:!0,flip:!0};let t={...e};return e.shift===void 0&&(t.shift=!0),e.flip===void 0&&(t.flip=!0),t}function Hv(e){let t=Vv(e.middlewares),n=[ls(e.offset)];return t.shift&&n.push(us(typeof t.shift==`boolean`?{padding:8}:{padding:8,...t.shift})),t.flip&&n.push(typeof t.flip==`boolean`?fs():fs(t.flip)),n.push(gs({element:e.arrowRef,padding:e.arrowOffset})),t.inline?n.push(typeof t.inline==`boolean`?hs():hs(t.inline)):e.inline&&n.push(hs()),n}function Uv(e){let[t,n]=(0,b.useState)(e.defaultOpened),r=typeof e.opened==`boolean`?e.opened:t,i=Rv(),a=Rt(),o=(0,b.useCallback)(e=>{n(e),e&&g(a)},[a]),{x:s,y:c,context:l,refs:u,placement:d,middlewareData:{arrow:{x:f,y:p}={}}}=ec({strategy:e.strategy,placement:e.position,open:r,onOpenChange:o,middleware:Hv(e),whileElementsMounted:Go}),{delay:m,currentId:h,setCurrentId:g}=Js(l,{id:a}),{getReferenceProps:_,getFloatingProps:v}=ic([Us(l,{enabled:e.events?.hover,delay:i?m:{open:e.openDelay,close:e.closeDelay},mouseOnly:!e.events?.touch}),nc(l,{enabled:e.events?.focus,visibleOnly:!0}),oc(l,{role:`tooltip`}),Qs(l,{enabled:e.opened===void 0})]);xt(()=>{e.onPositionChange?.(d)},[d]);let y=r&&h&&h!==a;return{x:s,y:c,arrowX:f,arrowY:p,reference:u.setReference,floating:u.setFloating,getFloatingProps:v,getReferenceProps:_,isGroupPhase:y,opened:r,placement:d}}var Wv={position:`top`,refProp:`ref`,withinPortal:!0,arrowSize:4,arrowOffset:5,arrowRadius:0,arrowPosition:`side`,offset:5,transitionProps:{duration:100,transition:`fade`},events:{hover:!0,focus:!1,touch:!1},zIndex:Je(`popover`),positionDependencies:[],middlewares:{flip:!0,shift:!0,inline:!1}},Gv=nt((e,{radius:t,color:n,variant:r,autoContrast:i})=>{let a=e.variantColorResolver({theme:e,color:n||e.primaryColor,autoContrast:i,variant:r||`filled`});return{tooltip:{"--tooltip-radius":t===void 0?void 0:Qe(t),"--tooltip-bg":n?a.background:void 0,"--tooltip-color":n?a.color:void 0}}}),Kv=B((e,t)=>{let n=R(`Tooltip`,Wv,e),{children:r,position:i,refProp:a,label:o,openDelay:s,closeDelay:c,onPositionChange:l,opened:u,defaultOpened:d,withinPortal:f,radius:p,color:m,classNames:h,styles:g,unstyled:_,style:v,className:y,withArrow:x,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,offset:E,transitionProps:D,multiline:O,events:k,zIndex:A,disabled:j,positionDependencies:M,onClick:ee,onMouseEnter:N,onMouseLeave:P,inline:te,variant:ne,keepMounted:re,vars:ie,portalProps:ae,mod:oe,floatingStrategy:se,middlewares:ce,autoContrast:le,attributes:ue,target:de,...fe}=R(`Tooltip`,Wv,n),{dir:pe}=cc(),me=(0,b.useRef)(null),he=Uv({position:nf(pe,i),closeDelay:c,openDelay:s,onPositionChange:l,opened:u,defaultOpened:d,events:k,arrowRef:me,arrowOffset:C,offset:typeof E==`number`?E+(x?S/2:0):E,positionDependencies:[...M,de??r],inline:te,strategy:se,middlewares:ce});(0,b.useEffect)(()=>{let e=de instanceof HTMLElement?de:typeof de==`string`?document.querySelector(de):de?.current||null;e&&he.reference(e)},[de,he]);let ge=L({name:`Tooltip`,props:n,classes:Av,className:y,style:v,classNames:h,styles:g,unstyled:_,attributes:ue,rootSelector:`tooltip`,vars:ie,varsResolver:Gv}),_e=_f(r);if(!de&&!_e)throw Error(`[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);if(de){let e=kv(D,{duration:100,transition:`fade`});return(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(ff,{...ae,withinPortal:f,children:(0,I.jsx)(ul,{...e,keepMounted:re,mounted:!j&&!!he.opened,duration:he.isGroupPhase?10:e.duration,children:e=>(0,I.jsxs)(z,{...fe,"data-fixed":se===`fixed`||void 0,variant:ne,mod:[{multiline:O},oe],...he.getFloatingProps({ref:he.floating,className:ge(`tooltip`).className,style:{...ge(`tooltip`).style,...e,zIndex:A,top:he.y??0,left:he.x??0}}),children:[o,(0,I.jsx)(tf,{ref:me,arrowX:he.arrowX,arrowY:he.arrowY,visible:x,position:he.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ge(`arrow`)})]})})})})}let ve=_e.props,ye=Vt(he.reference,Cf(_e),t),be=kv(D,{duration:100,transition:`fade`});return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ff,{...ae,withinPortal:f,children:(0,I.jsx)(ul,{...be,keepMounted:re,mounted:!j&&!!he.opened,duration:he.isGroupPhase?10:be.duration,children:e=>(0,I.jsxs)(z,{...fe,"data-fixed":se===`fixed`||void 0,variant:ne,mod:[{multiline:O},oe],...he.getFloatingProps({ref:he.floating,className:ge(`tooltip`).className,style:{...ge(`tooltip`).style,...e,zIndex:A,top:he.y??0,left:he.x??0}}),children:[o,(0,I.jsx)(tf,{ref:me,arrowX:he.arrowX,arrowY:he.arrowY,visible:x,position:he.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ge(`arrow`)})]})})}),(0,b.cloneElement)(_e,he.getReferenceProps({onClick:ee,onMouseEnter:N,onMouseLeave:P,onMouseMove:n.onMouseMove,onPointerDown:n.onPointerDown,onPointerEnter:n.onPointerEnter,...ve,className:it(y,ve.className),[a]:ye}))]})});Kv.classes=Av,Kv.displayName=`@mantine/core/Tooltip`,Kv.Floating=Fv,Kv.Group=Bv;function qv({size:e,thickness:t,sum:n,value:r,root:i,offset:a}){let o=(e*.9-t*2)/2,s=Math.PI*o*2/100,c=i||r===void 0?`${(100-n)*s}, ${n*s}`:`${r*s}, ${(100-r)*s}`;return{strokeWidth:Number.isNaN(t)?12:t,cx:e/2||0,cy:e/2||0,r:o||0,transform:i?`scale(1, -1) translate(0, -${e})`:void 0,strokeDasharray:c,strokeDashoffset:i?0:a||0}}function Jv({size:e,value:t,offset:n,sum:r,thickness:i,root:a,color:o,lineRoundCaps:s,tooltip:c,getStyles:l,display:u,...d}){let f=er();return(0,I.jsx)(Kv.Floating,{disabled:!c,label:c,children:(0,I.jsx)(z,{component:`circle`,...d,...l(`curve`),__vars:{"--curve-color":o?Mn(o,f):void 0},fill:`none`,strokeLinecap:s?`round`:`butt`,...qv({sum:r,size:e,thickness:i,value:t,offset:n,root:a})})})}Jv.displayName=`@mantine/core/Curve`;function Yv({size:e,thickness:t,sections:n,renderRoundedLineCaps:r,rootColor:i}){let a=n.reduce((e,t)=>e+t.value,0),o=Math.PI*((e*.9-t*2)/2)*2,s=o,c=[],l=[];for(let e=0;e<n.length;e+=1)c.push({sum:a,offset:s,data:n[e],root:!1}),s-=n[e].value/100*o;if(c.push({sum:a,offset:s,data:{color:i},root:!0}),l.push({...c[c.length-1],lineRoundCaps:!1}),c.length>2){l.push({...c[0],lineRoundCaps:r}),l.push({...c[c.length-2],lineRoundCaps:r});for(let e=1;e<=c.length-3;e+=1)l.push({...c[e],lineRoundCaps:!1})}else l.push({...c[0],lineRoundCaps:r});return l}var Xv={root:`m_b32e4812`,svg:`m_d43b5134`,curve:`m_b1ca1fbf`,label:`m_b23f9dc4`};function Zv(e,t){return Math.min(e||12,(t||120)/4)}var Qv={size:120,thickness:12},$v=nt((e,{size:t,thickness:n,transitionDuration:r})=>({root:{"--rp-size":F(t),"--rp-label-offset":F(n*2),"--rp-transition-duration":r?`${r}ms`:void 0}})),ey=B((e,t)=>{let n=R(`RingProgress`,Qv,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,label:l,sections:u,size:d,thickness:f,roundCaps:p,rootColor:m,transitionDuration:h,attributes:g,..._}=n,v=L({name:`RingProgress`,classes:Xv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:$v}),y=Zv(f,d),x=Yv({size:d,thickness:y,sections:u,renderRoundedLineCaps:p,rootColor:m}).map(({data:e,sum:t,root:n,lineRoundCaps:r,offset:i},a)=>(0,b.createElement)(Jv,{...e,key:a,size:d,thickness:y,sum:t,offset:i,color:e?.color,root:n,lineRoundCaps:r,getStyles:v}));return(0,I.jsxs)(z,{...v(`root`),size:d,ref:t,..._,children:[(0,I.jsx)(`svg`,{...v(`svg`),children:x}),l&&(0,I.jsx)(`div`,{...v(`label`),children:l})]})});ey.classes=Xv,ey.displayName=`@mantine/core/RingProgress`;var ty={root:`m_96b553a6`};function ny(e,t){if(!t||!e)return!1;let n=t.parentNode;for(;n!=null;){if(n===e)return!0;n=n.parentNode}return!1}function ry({target:e,parent:t,ref:n,displayAfterTransitionEnd:r}){let i=(0,b.useRef)(-1),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(typeof r==`boolean`?r:!1),l=()=>{if(!e||!t||!n.current)return;let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=window.getComputedStyle(e),o=window.getComputedStyle(t),s=wc(a.borderTopWidth)+wc(o.borderTopWidth),c=wc(a.borderLeftWidth)+wc(o.borderLeftWidth),l={top:r.top-i.top-s,left:r.left-i.left-c,width:r.width,height:r.height};n.current.style.transform=`translateY(${l.top}px) translateX(${l.left}px)`,n.current.style.width=`${l.width}px`,n.current.style.height=`${l.height}px`},u=()=>{window.clearTimeout(i.current),n.current&&(n.current.style.transitionDuration=`0ms`),l(),i.current=window.setTimeout(()=>{n.current&&(n.current.style.transitionDuration=``)},30)},d=(0,b.useRef)(null),f=(0,b.useRef)(null);return(0,b.useEffect)(()=>{if(l(),e)return d.current=new ResizeObserver(u),d.current.observe(e),t&&(f.current=new ResizeObserver(u),f.current.observe(t)),()=>{d.current?.disconnect(),f.current?.disconnect()}},[t,e]),(0,b.useEffect)(()=>{if(t){let e=e=>{ny(e.target,t)&&(u(),c(!1))};return t.addEventListener(`transitionend`,e),()=>{t.removeEventListener(`transitionend`,e)}}},[t]),sn(()=>{hm()!==`test`&&o(!0)},20,{autoInvoke:!0}),cn(e=>{e.forEach(e=>{e.type===`attributes`&&e.attributeName===`dir`&&u()})},{attributes:!0,attributeFilter:[`dir`]},()=>document.documentElement),{initialized:a,hidden:s}}var iy=nt((e,{transitionDuration:t})=>({root:{"--transition-duration":typeof t==`number`?`${t}ms`:t}})),ay=B((e,t)=>{let n=R(`FloatingIndicator`,null,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,target:l,parent:u,transitionDuration:d,mod:f,displayAfterTransitionEnd:p,attributes:m,...h}=n,g=L({name:`FloatingIndicator`,classes:ty,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:m,vars:c,varsResolver:iy}),_=(0,b.useRef)(null),{initialized:v,hidden:y}=ry({target:l,parent:u,ref:_,displayAfterTransitionEnd:p}),x=Vt(t,_);return!l||!u?null:(0,I.jsx)(z,{ref:x,mod:[{initialized:v,hidden:y},f],...g(`root`),...h})});ay.displayName=`@mantine/core/FloatingIndicator`,ay.classes=ty;var oy={root:`m_cf365364`,indicator:`m_9e182ccd`,label:`m_1738fcb2`,input:`m_1714d588`,control:`m_69686b9b`,innerLabel:`m_78882f40`},sy={withItemsBorders:!0},cy=nt((e,{radius:t,color:n,transitionDuration:r,size:i,transitionTimingFunction:a})=>({root:{"--sc-radius":t===void 0?void 0:Qe(t),"--sc-color":n?Mn(n,e):void 0,"--sc-shadow":n?void 0:`var(--mantine-shadow-xs)`,"--sc-transition-duration":r===void 0?void 0:`${r}ms`,"--sc-transition-timing-function":a,"--sc-padding":Xe(i,`sc-padding`),"--sc-font-size":$e(i)}})),ly=B((e,t)=>{let n=R(`SegmentedControl`,sy,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,data:l,value:u,defaultValue:d,onChange:f,size:p,name:m,disabled:h,readOnly:g,fullWidth:_,orientation:v,radius:y,color:x,transitionDuration:S,transitionTimingFunction:C,variant:w,autoContrast:T,withItemsBorders:E,mod:D,attributes:O,...k}=n,A=L({name:`SegmentedControl`,props:n,classes:oy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:O,vars:c,varsResolver:cy}),j=er(),M=l.map(e=>typeof e==`string`?{label:e,value:e}:e),ee=ln(),[N,P]=(0,b.useState)(ut()),[te,ne]=(0,b.useState)(null),[re,ie]=(0,b.useState)({}),ae=(e,t)=>{re[t]=e,ie(re)},[oe,se]=Ht({value:u,defaultValue:d,finalValue:Array.isArray(l)?M.find(e=>!e.disabled)?.value??l[0]?.value??null:null,onChange:f}),ce=Rt(m),le=M.map(e=>(0,b.createElement)(z,{...A(`control`),mod:{active:oe===e.value,orientation:v},key:e.value},(0,b.createElement)(`input`,{...A(`input`),disabled:h||e.disabled,type:`radio`,name:ce,value:e.value,id:`${ce}-${e.value}`,checked:oe===e.value,onChange:()=>!g&&se(e.value),"data-focus-ring":j.focusRing,key:`${e.value}-input`}),(0,b.createElement)(z,{component:`label`,...A(`label`),mod:{active:oe===e.value&&!(h||e.disabled),disabled:h||e.disabled,"read-only":g},htmlFor:`${ce}-${e.value}`,ref:t=>ae(t,e.value),__vars:{"--sc-label-color":x===void 0?void 0:ar({color:x,theme:j,autoContrast:T})},key:`${e.value}-label`},(0,I.jsx)(`span`,{...A(`innerLabel`),children:e.label})))),ue=Vt(t,e=>ne(e));return Xt(()=>{P(ut())},[l.length]),l.length===0?null:(0,I.jsxs)(z,{...A(`root`),variant:w,size:p,ref:ue,mod:[{"full-width":_,orientation:v,initialized:ee,"with-items-borders":E},D],...k,role:`radiogroup`,"data-disabled":h,children:[typeof oe==`string`&&(0,I.jsx)(ay,{target:re[oe],parent:te,component:`span`,transitionDuration:`var(--sc-transition-duration)`,...A(`indicator`)},N),le]})});ly.classes=oy,ly.displayName=`@mantine/core/SegmentedControl`;var uy={container:`m_925c2d2c`,root:`m_2415a157`};function dy({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=er(),a=t===void 0?e:t,o=Pr({"--sg-spacing-x":Ze(wp(e)),"--sg-spacing-y":Ze(wp(a)),"--sg-cols":wp(n)?.toString()}),s=Hn(i.breakpoints).reduce((t,r)=>(t[r]||(t[r]={}),typeof e==`object`&&e[r]!==void 0&&(t[r][`--sg-spacing-x`]=Ze(e[r])),typeof a==`object`&&a[r]!==void 0&&(t[r][`--sg-spacing-y`]=Ze(a[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{});return(0,I.jsx)(qr,{styles:o,media:Su(Hn(s),i.breakpoints).filter(e=>Hn(s[e.value]).length>0).map(e=>({query:`(min-width: ${i.breakpoints[e.value]})`,styles:s[e.value]})),selector:r})}function fy(e){return typeof e==`object`&&e?Hn(e):[]}function py(e){return e.sort((e,t)=>Wn(e)-Wn(t))}function my({spacing:e,verticalSpacing:t,cols:n}){return py(Array.from(new Set([...fy(e),...fy(t),...fy(n)])))}function hy({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=t===void 0?e:t,a=Pr({"--sg-spacing-x":Ze(wp(e)),"--sg-spacing-y":Ze(wp(i)),"--sg-cols":wp(n)?.toString()}),o=my({spacing:e,verticalSpacing:t,cols:n}),s=o.reduce((t,r)=>(t[r]||(t[r]={}),typeof e==`object`&&e[r]!==void 0&&(t[r][`--sg-spacing-x`]=Ze(e[r])),typeof i==`object`&&i[r]!==void 0&&(t[r][`--sg-spacing-y`]=Ze(i[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{});return(0,I.jsx)(qr,{styles:a,container:o.map(e=>({query:`simple-grid (min-width: ${e})`,styles:s[e]})),selector:r})}var gy={cols:1,spacing:`md`,type:`media`},_y=B((e,t)=>{let n=R(`SimpleGrid`,gy,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,cols:l,verticalSpacing:u,spacing:d,type:f,attributes:p,...m}=n,h=L({name:`SimpleGrid`,classes:uy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c}),g=Si();return f===`container`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(hy,{...n,selector:`.${g}`}),(0,I.jsx)(`div`,{...h(`container`),children:(0,I.jsx)(z,{ref:t,...h(`root`,{className:g}),...m})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(dy,{...n,selector:`.${g}`}),(0,I.jsx)(z,{ref:t,...h(`root`,{className:g}),...m})]})});_y.classes=uy,_y.displayName=`@mantine/core/SimpleGrid`;var vy={root:`m_18320242`,"skeleton-fade":`m_299c329c`},yy={visible:!0,animate:!0},by=nt((e,{width:t,height:n,radius:r,circle:i})=>({root:{"--skeleton-height":F(n),"--skeleton-width":F(i?n:t),"--skeleton-radius":i?`1000px`:r===void 0?void 0:Qe(r)}})),xy=B((e,t)=>{let n=R(`Skeleton`,yy,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,width:l,height:u,circle:d,visible:f,radius:p,animate:m,mod:h,attributes:g,..._}=n;return(0,I.jsx)(z,{ref:t,...L({name:`Skeleton`,classes:vy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:by})(`root`),mod:[{visible:f,animate:m},h],..._})});xy.classes=vy,xy.displayName=`@mantine/core/Skeleton`;var Sy=B((e,t)=>{let{w:n,h:r,miw:i,mih:a,...o}=R(`Space`,null,e);return(0,I.jsx)(z,{ref:t,...o,w:n,miw:i??n,h:r,mih:a??r})});Sy.displayName=`@mantine/core/Space`;var Cy={root:`m_6d731127`},wy={gap:`md`,align:`stretch`,justify:`flex-start`},Ty=nt((e,{gap:t,align:n,justify:r})=>({root:{"--stack-gap":Ze(t),"--stack-align":n,"--stack-justify":r}})),G=B((e,t)=>{let n=R(`Stack`,wy,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,align:l,justify:u,gap:d,variant:f,attributes:p,...m}=n;return(0,I.jsx)(z,{ref:t,...L({name:`Stack`,props:n,classes:Cy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c,varsResolver:Ty})(`root`),variant:f,...m})});G.classes=Cy,G.displayName=`@mantine/core/Stack`;var[Ey,Dy]=Ke(`Stepper component was not found in tree`),Oy={root:`m_cbb4ea7e`,steps:`m_aaf89d0b`,separator:`m_2a371ac9`,content:`m_78da155d`,step:`m_cbb57068`,"step--horizontal":`m_f56b1e2c`,"step--vertical":`m_833edb7e`,verticalSeparator:`m_6496b3f3`,stepWrapper:`m_818e70b`,stepIcon:`m_1959ad01`,stepCompletedIcon:`m_a79331dc`,stepBody:`m_1956aa2a`,stepLabel:`m_12051f6c`,stepDescription:`m_164eea74`},ky=()=>null;ky.displayName=`@mantine/core/StepperCompleted`;var Ay=(e,t)=>typeof e==`function`?(0,I.jsx)(e,{step:t||0}):e,jy={withIcon:!0,allowStepClick:!0,iconPosition:`left`},My=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,step:s,state:c,color:l,icon:u,completedIcon:d,progressIcon:f,label:p,description:m,withIcon:h,iconSize:g,loading:_,allowStepClick:v,allowStepSelect:y,iconPosition:b,orientation:x,mod:S,...C}=R(`StepperStep`,jy,e),w=Dy(),T=er(),E={classNames:n,styles:a},D=c===`stepCompleted`?null:c===`stepProgress`?f:u,O={"data-progress":c===`stepProgress`||void 0,"data-completed":c===`stepCompleted`||void 0};return(0,I.jsxs)(qc,{...w.getStyles(`step`,{className:r,style:i,variant:w.orientation,...E}),mod:[{"icon-position":b||w.iconPosition,"allow-click":v},S],ref:t,...O,...C,__vars:{"--step-color":l?Mn(l,T):void 0},tabIndex:v?0:-1,children:[h&&(0,I.jsxs)(`span`,{...w.getStyles(`stepWrapper`,E),children:[(0,I.jsxs)(`span`,{...w.getStyles(`stepIcon`,E),...O,children:[(0,I.jsx)(ul,{mounted:c===`stepCompleted`,transition:`pop`,duration:200,children:e=>(0,I.jsx)(`span`,{...w.getStyles(`stepCompletedIcon`,{style:e,...E}),children:_?(0,I.jsx)(il,{color:`var(--mantine-color-white)`,size:`calc(var(--stepper-icon-size) / 2)`,...w.getStyles(`stepLoader`,E)}):Ay(d,s)||(0,I.jsx)(Md,{size:`60%`})})}),c===`stepCompleted`?null:(0,I.jsx)(`span`,{children:_?(0,I.jsx)(il,{...w.getStyles(`stepLoader`,E),size:`calc(var(--stepper-icon-size) / 2)`,color:l}):Ay(D||u,s)})]}),x===`vertical`&&(0,I.jsx)(`span`,{...w.getStyles(`verticalSeparator`,E),"data-active":c===`stepCompleted`||void 0})]}),(p||m)&&(0,I.jsxs)(`span`,{...w.getStyles(`stepBody`,E),"data-orientation":w.orientation,"data-icon-position":b||w.iconPosition,children:[p&&(0,I.jsx)(`span`,{...w.getStyles(`stepLabel`,E),children:Ay(p,s)}),m&&(0,I.jsx)(`span`,{...w.getStyles(`stepDescription`,E),children:Ay(m,s)})]})]})});My.classes=Oy,My.displayName=`@mantine/core/StepperStep`;var Ny={orientation:`horizontal`,iconPosition:`left`,allowNextStepsSelect:!0,wrap:!0},Py=nt((e,{color:t,iconSize:n,size:r,contentPadding:i,radius:a,autoContrast:o})=>({root:{"--stepper-color":t?Mn(t,e):void 0,"--stepper-icon-color":gd(o,e)?ar({color:t,theme:e,autoContrast:o}):void 0,"--stepper-icon-size":n===void 0?Xe(r,`stepper-icon-size`):F(n),"--stepper-content-padding":Ze(i),"--stepper-radius":a===void 0?void 0:Qe(a),"--stepper-fz":$e(r),"--stepper-spacing":Ze(r)}})),Fy=B((e,t)=>{let n=R(`Stepper`,Ny,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,children:l,onStepClick:u,active:d,icon:f,completedIcon:p,progressIcon:m,color:h,iconSize:g,contentPadding:_,orientation:v,iconPosition:y,size:x,radius:S,allowNextStepsSelect:C,wrap:w,autoContrast:T,attributes:E,...D}=n,O=L({name:`Stepper`,classes:Oy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:E,vars:c,varsResolver:Py}),k=b.Children.toArray(l),A=k.filter(e=>e.type!==ky),j=k.find(e=>e.type===ky),M=A.reduce((e,t,n)=>{let r=d===n?`stepProgress`:d>n?`stepCompleted`:`stepInactive`,i=typeof u==`function`?typeof t.props.allowStepSelect==`boolean`?t.props.allowStepSelect:r===`stepCompleted`||C:!1;return e.push((0,b.cloneElement)(t,{icon:t.props.icon||f||n+1,key:n,step:n,state:r,onClick:()=>i&&u?.(n),allowStepClick:i,completedIcon:t.props.completedIcon||p,progressIcon:t.props.progressIcon||m,color:t.props.color||h,iconSize:g,iconPosition:t.props.iconPosition||y,orientation:v})),v===`horizontal`&&n!==A.length-1&&e.push((0,b.createElement)(`div`,{...O(`separator`),"data-active":n<d||void 0,"data-orientation":v,key:`separator-${n}`})),e},[]),ee=A[d]?.props?.children,N=j?.props?.children,P=d>A.length-1?N:ee;return(0,I.jsx)(Ey,{value:{getStyles:O,orientation:v,iconPosition:y},children:(0,I.jsxs)(z,{...O(`root`),ref:t,size:x,...D,children:[(0,I.jsx)(z,{...O(`steps`),mod:{orientation:v,"icon-position":y,wrap:w&&v!==`vertical`},children:M}),P&&(0,I.jsx)(`div`,{...O(`content`),children:P})]})})});Fy.classes=Oy,Fy.displayName=`@mantine/core/Stepper`,Fy.Completed=ky,Fy.Step=My;var Iy={root:`m_5f93f3bb`,input:`m_926b4011`,track:`m_9307d992`,thumb:`m_93039a1d`,trackLabel:`m_8277e082`},Ly=(0,b.createContext)(null),Ry=Ly.Provider,zy=()=>(0,b.useContext)(Ly),By=B((e,t)=>{let{value:n,defaultValue:r,onChange:i,size:a,wrapperProps:o,children:s,readOnly:c,disabled:l,...u}=R(`SwitchGroup`,null,e),[d,f]=Ht({value:n,defaultValue:r,finalValue:[],onChange:i});return(0,I.jsx)(Ry,{value:{value:d,onChange:e=>{let t=e.currentTarget.value;!c&&f(d.includes(t)?d.filter(e=>e!==t):[...d,t])},size:a,disabled:l},children:(0,I.jsx)(Zl.Wrapper,{size:a,ref:t,...o,...u,labelElement:`div`,__staticSelector:`SwitchGroup`,children:(0,I.jsx)(Ad,{role:`group`,children:s})})})});By.classes=Zl.Wrapper.classes,By.displayName=`@mantine/core/SwitchGroup`;var Vy={labelPosition:`right`,withThumbIndicator:!0},Hy=nt((e,{radius:t,color:n,size:r})=>({root:{"--switch-radius":t===void 0?void 0:Qe(t),"--switch-height":Xe(r,`switch-height`),"--switch-width":Xe(r,`switch-width`),"--switch-thumb-size":Xe(r,`switch-thumb-size`),"--switch-label-font-size":Xe(r,`switch-label-font-size`),"--switch-track-label-padding":Xe(r,`switch-track-label-padding`),"--switch-color":n?Mn(n,e):void 0}})),Uy=B((e,t)=>{let n=R(`Switch`,Vy,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,color:l,label:u,offLabel:d,onLabel:f,id:p,size:m,radius:h,wrapperProps:g,thumbIcon:_,checked:v,defaultChecked:y,onChange:b,labelPosition:x,description:S,error:C,disabled:w,variant:T,rootRef:E,mod:D,withThumbIndicator:O,attributes:k,...A}=n,j=zy(),M=m||j?.size,ee=L({name:`Switch`,props:n,classes:Iy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:k,vars:c,varsResolver:Hy}),{styleProps:N,rest:P}=$r(A),te=Rt(p),ne={checked:j?.value.includes(P.value)??v,onChange:e=>{j?.onChange(e),b?.(e)},disabled:j?.disabled??w},[re,ie]=Ht({value:ne.checked??v,defaultValue:y,finalValue:!1});return(0,I.jsxs)(yd,{...ee(`root`),__staticSelector:`Switch`,__stylesApiProps:n,id:te,size:M,labelPosition:x,label:u,description:S,error:C,disabled:ne.disabled,bodyElement:`label`,labelElement:`span`,classNames:r,styles:o,unstyled:s,"data-checked":ne.checked,variant:T,ref:E,mod:D,inert:P.inert,...N,...g,children:[(0,I.jsx)(`input`,{...P,...ne,checked:re,"data-checked":ne.checked,onChange:e=>{ne.onChange?.(e),ie(e.currentTarget.checked)},id:te,ref:t,type:`checkbox`,role:`switch`,inert:P.inert,...ee(`input`)}),(0,I.jsxs)(z,{"aria-hidden":`true`,component:`span`,mod:{error:C,"label-position":x,"without-labels":!f&&!d},...ee(`track`),children:[(0,I.jsx)(z,{component:`span`,mod:{"reduce-motion":!0,"with-thumb-indicator":O&&!_},...ee(`thumb`),children:_}),(0,I.jsx)(`span`,{...ee(`trackLabel`),children:re?f:d})]})]})});Uy.classes={...Iy,...vd},Uy.displayName=`@mantine/core/Switch`,Uy.Group=By;var[Wy,Gy]=Ke(`Table component was not found in the tree`),Ky={table:`m_b23fa0ef`,th:`m_4e7aa4f3`,tr:`m_4e7aa4fd`,td:`m_4e7aa4ef`,tbody:`m_b2404537`,thead:`m_b242d975`,caption:`m_9e5a3ac7`,scrollContainer:`m_a100c15`,scrollContainerInner:`m_62259741`};function qy(e,t){if(!t)return;let n={};return t.columnBorder&&e.withColumnBorders&&(n[`data-with-column-border`]=!0),t.rowBorder&&e.withRowBorders&&(n[`data-with-row-border`]=!0),t.striped&&e.striped&&(n[`data-striped`]=e.striped),t.highlightOnHover&&e.highlightOnHover&&(n[`data-hover`]=!0),t.captionSide&&e.captionSide&&(n[`data-side`]=e.captionSide),t.stickyHeader&&e.stickyHeader&&(n[`data-sticky`]=!0),n}function Jy(e,t){let n=`Table${e.charAt(0).toUpperCase()}${e.slice(1)}`,r=B((r,i)=>{let a=R(n,{},r),{classNames:o,className:s,style:c,styles:l,...u}=a,d=Gy();return(0,I.jsx)(z,{component:e,ref:i,...qy(d,t),...d.getStyles(e,{className:s,classNames:o,style:c,styles:l,props:a}),...u})});return r.displayName=`@mantine/core/${n}`,r.classes=Ky,r}var Yy=Jy(`th`,{columnBorder:!0}),Xy=Jy(`td`,{columnBorder:!0}),Zy=Jy(`tr`,{rowBorder:!0,striped:!0,highlightOnHover:!0}),Qy=Jy(`thead`,{stickyHeader:!0}),$y=Jy(`tbody`),eb=Jy(`tfoot`),tb=Jy(`caption`,{captionSide:!0});function nb({data:e}){return(0,I.jsxs)(I.Fragment,{children:[e.caption&&(0,I.jsx)(tb,{children:e.caption}),e.head&&(0,I.jsx)(Qy,{children:(0,I.jsx)(Zy,{children:e.head.map((e,t)=>(0,I.jsx)(Yy,{children:e},t))})}),e.body&&(0,I.jsx)($y,{children:e.body.map((e,t)=>(0,I.jsx)(Zy,{children:e.map((e,t)=>(0,I.jsx)(Xy,{children:e},t))},t))}),e.foot&&(0,I.jsx)(eb,{children:(0,I.jsx)(Zy,{children:e.foot.map((e,t)=>(0,I.jsx)(Yy,{children:e},t))})})]})}nb.displayName=`@mantine/core/TableDataRenderer`;var rb={type:`scrollarea`},ib=nt((e,{minWidth:t,maxHeight:n,type:r})=>({scrollContainer:{"--table-min-width":F(t),"--table-max-height":F(n),"--table-overflow":r===`native`?`auto`:void 0}})),ab=B((e,t)=>{let n=R(`TableScrollContainer`,rb,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,children:l,minWidth:u,maxHeight:d,type:f,scrollAreaProps:p,attributes:m,...h}=n,g=L({name:`TableScrollContainer`,classes:Ky,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:m,vars:c,varsResolver:ib,rootSelector:`scrollContainer`});return(0,I.jsx)(z,{component:f===`scrollarea`?Hc:`div`,...f===`scrollarea`?d?{offsetScrollbars:`xy`,...p}:{offsetScrollbars:`x`,...p}:{},ref:t,...g(`scrollContainer`),...h,children:(0,I.jsx)(`div`,{...g(`scrollContainerInner`),children:l})})});ab.classes=Ky,ab.displayName=`@mantine/core/TableScrollContainer`;var ob={withRowBorders:!0,verticalSpacing:7},sb=nt((e,{layout:t,captionSide:n,horizontalSpacing:r,verticalSpacing:i,borderColor:a,stripedColor:o,highlightOnHoverColor:s,striped:c,highlightOnHover:l,stickyHeaderOffset:u,stickyHeader:d})=>({table:{"--table-layout":t,"--table-caption-side":n,"--table-horizontal-spacing":Ze(r),"--table-vertical-spacing":Ze(i),"--table-border-color":a?Mn(a,e):void 0,"--table-striped-color":c&&o?Mn(o,e):void 0,"--table-highlight-on-hover-color":l&&s?Mn(s,e):void 0,"--table-sticky-header-offset":d?F(u):void 0}})),K=B((e,t)=>{let n=R(`Table`,ob,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,horizontalSpacing:l,verticalSpacing:u,captionSide:d,stripedColor:f,highlightOnHoverColor:p,striped:m,highlightOnHover:h,withColumnBorders:g,withRowBorders:_,withTableBorder:v,borderColor:y,layout:b,variant:x,data:S,children:C,stickyHeader:w,stickyHeaderOffset:T,mod:E,tabularNums:D,attributes:O,...k}=n,A=L({name:`Table`,props:n,className:i,style:a,classes:Ky,classNames:r,styles:o,unstyled:s,attributes:O,rootSelector:`table`,vars:c,varsResolver:sb});return(0,I.jsx)(Wy,{value:{getStyles:A,stickyHeader:w,striped:m===!0?`odd`:m||void 0,highlightOnHover:h,withColumnBorders:g,withRowBorders:_,captionSide:d||`bottom`},children:(0,I.jsx)(z,{component:`table`,variant:x,ref:t,mod:[{"data-with-table-border":v,"data-tabular-nums":D},E],...A(`table`),...k,children:C||!!S&&(0,I.jsx)(nb,{data:S})})})});K.classes=Ky,K.displayName=`@mantine/core/Table`,K.Td=Xy,K.Th=Yy,K.Tr=Zy,K.Thead=Qy,K.Tbody=$y,K.Tfoot=eb,K.Caption=tb,K.ScrollContainer=ab,K.DataRenderer=nb;function cb(e,t){return n=>{if(typeof n!=`string`||n.trim().length===0)throw Error(t);return`${e}-${n}`}}var[lb,ub]=Ke(`Tabs component was not found in the tree`),db={root:`m_89d60db1`,"list--default":`m_576c9d4`,list:`m_89d33d6d`,tab:`m_4ec4dce6`,panel:`m_b0c91715`,tabSection:`m_fc420b1f`,tabLabel:`m_42bbd1ae`,"tab--default":`m_539e827b`,"list--outline":`m_6772fbd5`,"tab--outline":`m_b59ab47c`,"tab--pills":`m_c3381914`},fb=B((e,t)=>{let n=R(`TabsList`,null,e),{children:r,className:i,grow:a,justify:o,classNames:s,styles:c,style:l,mod:u,...d}=n,f=ub();return(0,I.jsx)(z,{...d,...f.getStyles(`list`,{className:i,style:l,classNames:s,styles:c,props:n,variant:f.variant}),ref:t,role:`tablist`,variant:f.variant,mod:[{grow:a,orientation:f.orientation,placement:f.orientation===`vertical`&&f.placement,inverted:f.inverted},u],"aria-orientation":f.orientation,__vars:{"--tabs-justify":o},children:r})});fb.classes=db,fb.displayName=`@mantine/core/TabsList`;var pb=B((e,t)=>{let n=R(`TabsPanel`,null,e),{children:r,className:i,value:a,classNames:o,styles:s,style:c,mod:l,keepMounted:u,...d}=n,f=ub(),p=f.value===a,m=f.keepMounted||u||p?r:null;return(0,I.jsx)(z,{...f.getStyles(`panel`,{className:i,classNames:o,styles:s,style:[c,p?void 0:{display:`none`}],props:n}),ref:t,mod:[{orientation:f.orientation},l],role:`tabpanel`,id:f.getPanelId(a),"aria-labelledby":f.getTabId(a),...d,children:m})});pb.classes=db,pb.displayName=`@mantine/core/TabsPanel`;var mb=B((e,t)=>{let n=R(`TabsTab`,null,e),{className:r,children:i,rightSection:a,leftSection:o,value:s,onClick:c,onKeyDown:l,disabled:u,color:d,style:f,classNames:p,styles:m,vars:h,mod:g,tabIndex:_,...v}=n,y=er(),{dir:b}=cc(),x=ub(),S=s===x.value,C=e=>{x.onChange(x.allowTabDeactivation&&s===x.value?null:s),c?.(e)},w={classNames:p,styles:m,props:n};return(0,I.jsxs)(qc,{...x.getStyles(`tab`,{className:r,style:f,variant:x.variant,...w}),disabled:u,unstyled:x.unstyled,variant:x.variant,mod:[{active:S,disabled:u,orientation:x.orientation,inverted:x.inverted,placement:x.orientation===`vertical`&&x.placement},g],ref:t,role:`tab`,id:x.getTabId(s),"aria-selected":S,tabIndex:_===void 0?S||x.value===null?0:-1:_,"aria-controls":x.getPanelId(s),onClick:C,__vars:{"--tabs-color":d?Mn(d,y):void 0},onKeyDown:qm({siblingSelector:`[role="tab"]`,parentSelector:`[role="tablist"]`,activateOnFocus:x.activateTabWithKeyboard,loop:x.loop,orientation:x.orientation||`horizontal`,dir:b,onKeyDown:l}),...v,children:[o&&(0,I.jsx)(`span`,{...x.getStyles(`tabSection`,w),"data-position":`left`,children:o}),i&&(0,I.jsx)(`span`,{...x.getStyles(`tabLabel`,w),children:i}),a&&(0,I.jsx)(`span`,{...x.getStyles(`tabSection`,w),"data-position":`right`,children:a})]})});mb.classes=db,mb.displayName=`@mantine/core/TabsTab`;var hb=`Tabs.Tab or Tabs.Panel component was rendered with invalid value or without value`,gb={keepMounted:!0,orientation:`horizontal`,loop:!0,activateTabWithKeyboard:!0,variant:`default`,placement:`left`},_b=nt((e,{radius:t,color:n,autoContrast:r})=>({root:{"--tabs-radius":Qe(t),"--tabs-color":Mn(n,e),"--tabs-text-color":gd(r,e)?ar({color:n,theme:e,autoContrast:r}):void 0}})),vb=B((e,t)=>{let n=R(`Tabs`,gb,e),{defaultValue:r,value:i,onChange:a,orientation:o,children:s,loop:c,id:l,activateTabWithKeyboard:u,allowTabDeactivation:d,variant:f,color:p,radius:m,inverted:h,placement:g,keepMounted:_,classNames:v,styles:y,unstyled:b,className:x,style:S,vars:C,autoContrast:w,mod:T,attributes:E,...D}=n,O=Rt(l),[k,A]=Ht({value:i,defaultValue:r,finalValue:null,onChange:a}),j=L({name:`Tabs`,props:n,classes:db,className:x,style:S,classNames:v,styles:y,unstyled:b,attributes:E,vars:C,varsResolver:_b});return(0,I.jsx)(lb,{value:{placement:g,value:k,orientation:o,id:O,loop:c,activateTabWithKeyboard:u,getTabId:cb(`${O}-tab`,hb),getPanelId:cb(`${O}-panel`,hb),onChange:A,allowTabDeactivation:d,variant:f,color:p,radius:m,inverted:h,keepMounted:_,unstyled:b,getStyles:j},children:(0,I.jsx)(z,{ref:t,id:O,variant:f,mod:[{orientation:o,inverted:o===`horizontal`&&h,placement:o===`vertical`&&g},T],...j(`root`),...D,children:s})})});vb.classes=db,vb.displayName=`@mantine/core/Tabs`,vb.Tab=mb,vb.Panel=pb,vb.List=fb;var yb=B((e,t)=>(0,I.jsx)(eu,{component:`input`,ref:t,...R(`TextInput`,null,e),__staticSelector:`TextInput`}));yb.classes=eu.classes,yb.displayName=`@mantine/core/TextInput`;var bb={root:`m_7341320d`},xb=nt((e,{size:t,radius:n,variant:r,gradient:i,color:a,autoContrast:o})=>{let s=e.variantColorResolver({color:a||e.primaryColor,theme:e,gradient:i,variant:r||`filled`,autoContrast:o});return{root:{"--ti-size":Xe(t,`ti-size`),"--ti-radius":n===void 0?void 0:Qe(n),"--ti-bg":a||r?s.background:void 0,"--ti-color":a||r?s.color:void 0,"--ti-bd":a||r?s.border:void 0}}}),Sb=B((e,t)=>{let n=R(`ThemeIcon`,null,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,autoContrast:l,attributes:u,...d}=n;return(0,I.jsx)(z,{ref:t,...L({name:`ThemeIcon`,classes:bb,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:u,vars:c,varsResolver:xb})(`root`),...d})});Sb.classes=bb,Sb.displayName=`@mantine/core/ThemeIcon`;var Cb=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],wb=[`xs`,`sm`,`md`,`lg`,`xl`];function Tb(e,t){let n=t===void 0?`h${e}`:t;return Cb.includes(n)?{fontSize:`var(--mantine-${n}-font-size)`,fontWeight:`var(--mantine-${n}-font-weight)`,lineHeight:`var(--mantine-${n}-line-height)`}:wb.includes(n)?{fontSize:`var(--mantine-font-size-${n})`,fontWeight:`var(--mantine-h${e}-font-weight)`,lineHeight:`var(--mantine-h${e}-line-height)`}:{fontSize:F(n),fontWeight:`var(--mantine-h${e}-font-weight)`,lineHeight:`var(--mantine-h${e}-line-height)`}}var Eb={root:`m_8a5d1357`},Db={order:1},Ob=nt((e,{order:t,size:n,lineClamp:r,textWrap:i})=>{let a=Tb(t||1,n);return{root:{"--title-fw":a.fontWeight,"--title-lh":a.lineHeight,"--title-fz":a.fontSize,"--title-line-clamp":typeof r==`number`?r.toString():void 0,"--title-text-wrap":i}}}),q=B((e,t)=>{let n=R(`Title`,Db,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,order:c,vars:l,size:u,variant:d,lineClamp:f,textWrap:p,mod:m,attributes:h,...g}=n,_=L({name:`Title`,props:n,classes:Eb,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:h,vars:l,varsResolver:Ob});return[1,2,3,4,5,6].includes(c)?(0,I.jsx)(z,{..._(`root`),component:`h${c}`,variant:d,ref:t,mod:[{order:c,"data-line-clamp":typeof f==`number`},m],size:u,...g}):null});q.classes=Eb,q.displayName=`@mantine/core/Title`;function kb(e){let t=e,n=!1,r=new Set;return{getState(){return t},updateState(e){t=typeof e==`function`?e(t):e},setState(e){this.updateState(e),r.forEach(e=>e(t))},initialize(e){n||=(t=e,!0)},subscribe(e){return r.add(e),()=>r.delete(e)}}}function Ab(e){return(0,b.useSyncExternalStore)(e.subscribe,()=>e.getState(),()=>e.getState())}function jb(e,t,n){let r=[],i=[],a={};for(let o of e){let e=o.position||t;a[e]=a[e]||0,a[e]+=1,a[e]<=n?i.push(o):r.push(o)}return{notifications:i,queue:r}}var Mb=kb({notifications:[],queue:[],defaultPosition:`bottom-right`,limit:5}),Nb=(e=Mb)=>Ab(e);function Pb(e,t){let n=e.getState(),r=jb(t([...n.notifications,...n.queue]),n.defaultPosition,n.limit);e.setState({notifications:r.notifications,queue:r.queue,limit:n.limit,defaultPosition:n.defaultPosition})}function J(e,t=Mb){let n=e.id||ut();return Pb(t,t=>e.id&&t.some(t=>t.id===e.id)?t:[...t,{...e,id:n}]),n}function Fb(e,t=Mb){return Pb(t,t=>t.filter(t=>t.id===e?(t.onClose?.(t),!1):!0)),e}function Ib(e,t=Mb){return Pb(t,t=>t.map(t=>t.id===e.id?{...t,...e}:t)),e.id}function Lb(e=Mb){Pb(e,()=>[])}function Rb(e=Mb){Pb(e,t=>t.slice(0,e.getState().limit))}var zb={show:J,hide:Fb,update:Ib,clean:Lb,cleanQueue:Rb,updateState:Pb};function Bb(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function Vb(e,t){return Vb=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Vb(e,t)}function Hb(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,Vb(e,t)}var Ub=o(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Wb=o(((e,t)=>{var n=Ub();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),Gb=o(((e,t)=>{t.exports=Wb()()})),Kb=b.createContext(null);function qb(e,t){var n=function(e){return t&&(0,b.isValidElement)(e)?t(e):e},r=Object.create(null);return e&&b.Children.map(e,function(e){return e}).forEach(function(e){r[e.key]=n(e)}),r}function Jb(e,t){e||={},t||={};function n(n){return n in t?t[n]:e[n]}var r=Object.create(null),i=[];for(var a in e)a in t?i.length&&(r[a]=i,i=[]):i.push(a);var o,s={};for(var c in t){if(r[c])for(o=0;o<r[c].length;o++){var l=r[c][o];s[r[c][o]]=n(l)}s[c]=n(c)}for(o=0;o<i.length;o++)s[i[o]]=n(i[o]);return s}function Yb(e,t,n){return n[t]==null?e.props[t]:n[t]}function Xb(e,t){return qb(e.children,function(n){return(0,b.cloneElement)(n,{onExited:t.bind(null,n),in:!0,appear:Yb(n,`appear`,e),enter:Yb(n,`enter`,e),exit:Yb(n,`exit`,e)})})}function Zb(e,t,n){var r=qb(e.children),i=Jb(t,r);return Object.keys(i).forEach(function(a){var o=i[a];if((0,b.isValidElement)(o)){var s=a in t,c=a in r,l=t[a],u=(0,b.isValidElement)(l)&&!l.props.in;c&&(!s||u)?i[a]=(0,b.cloneElement)(o,{onExited:n.bind(null,o),in:!0,exit:Yb(o,`exit`,e),enter:Yb(o,`enter`,e)}):!c&&s&&!u?i[a]=(0,b.cloneElement)(o,{in:!1}):c&&s&&(0,b.isValidElement)(l)&&(i[a]=(0,b.cloneElement)(o,{onExited:n.bind(null,o),in:l.props.in,exit:Yb(o,`exit`,e),enter:Yb(o,`enter`,e)}))}}),i}var Qb=Object.values||function(e){return Object.keys(e).map(function(t){return e[t]})},$b={component:`div`,childFactory:function(e){return e}},ex=function(e){Hb(t,e);function t(t,n){var r=e.call(this,t,n)||this;return r.state={contextValue:{isMounting:!0},handleExited:r.handleExited.bind(Bb(r)),firstRender:!0},r}var n=t.prototype;return n.componentDidMount=function(){this.mounted=!0,this.setState({contextValue:{isMounting:!1}})},n.componentWillUnmount=function(){this.mounted=!1},t.getDerivedStateFromProps=function(e,t){var n=t.children,r=t.handleExited;return{children:t.firstRender?Xb(e,r):Zb(e,n,r),firstRender:!1}},n.handleExited=function(e,t){var n=qb(this.props.children);e.key in n||(e.props.onExited&&e.props.onExited(t),this.mounted&&this.setState(function(t){var n=qp({},t.children);return delete n[e.key],{children:n}}))},n.render=function(){var e=this.props,t=e.component,n=e.childFactory,r=Jp(e,[`component`,`childFactory`]),i=this.state.contextValue,a=Qb(this.state.children).map(n);return delete r.appear,delete r.enter,delete r.exit,t===null?b.createElement(Kb.Provider,{value:i},a):b.createElement(Kb.Provider,{value:i},b.createElement(t,r,a))},t}(b.Component);ex.propTypes={},ex.defaultProps=$b;var tx={disabled:!1},nx=function(e){return e.scrollTop},rx=`unmounted`,ix=`exited`,ax=`entering`,ox=`entered`,sx=`exiting`,cx=function(e){Hb(t,e);function t(t,n){var r=e.call(this,t,n)||this,i=n,a=i&&!i.isMounting?t.enter:t.appear,o;return r.appearStatus=null,t.in?a?(o=ix,r.appearStatus=ax):o=ox:o=t.unmountOnExit||t.mountOnEnter?rx:ix,r.state={status:o},r.nextCallback=null,r}t.getDerivedStateFromProps=function(e,t){return e.in&&t.status===`unmounted`?{status:ix}:null};var n=t.prototype;return n.componentDidMount=function(){this.updateStatus(!0,this.appearStatus)},n.componentDidUpdate=function(e){var t=null;if(e!==this.props){var n=this.state.status;this.props.in?n!==`entering`&&n!==`entered`&&(t=ax):(n===`entering`||n===`entered`)&&(t=sx)}this.updateStatus(!1,t)},n.componentWillUnmount=function(){this.cancelNextCallback()},n.getTimeouts=function(){var e=this.props.timeout,t=n=r=e,n,r;return e!=null&&typeof e!=`number`&&(t=e.exit,n=e.enter,r=e.appear===void 0?n:e.appear),{exit:t,enter:n,appear:r}},n.updateStatus=function(e,t){if(e===void 0&&(e=!1),t!==null)if(this.cancelNextCallback(),t===`entering`){if(this.props.unmountOnExit||this.props.mountOnEnter){var n=this.props.nodeRef?this.props.nodeRef.current:ts.default.findDOMNode(this);n&&nx(n)}this.performEnter(e)}else this.performExit();else this.props.unmountOnExit&&this.state.status===`exited`&&this.setState({status:rx})},n.performEnter=function(e){var t=this,n=this.props.enter,r=this.context?this.context.isMounting:e,i=this.props.nodeRef?[r]:[ts.default.findDOMNode(this),r],a=i[0],o=i[1],s=this.getTimeouts(),c=r?s.appear:s.enter;if(!e&&!n||tx.disabled){this.safeSetState({status:ox},function(){t.props.onEntered(a)});return}this.props.onEnter(a,o),this.safeSetState({status:ax},function(){t.props.onEntering(a,o),t.onTransitionEnd(c,function(){t.safeSetState({status:ox},function(){t.props.onEntered(a,o)})})})},n.performExit=function(){var e=this,t=this.props.exit,n=this.getTimeouts(),r=this.props.nodeRef?void 0:ts.default.findDOMNode(this);if(!t||tx.disabled){this.safeSetState({status:ix},function(){e.props.onExited(r)});return}this.props.onExit(r),this.safeSetState({status:sx},function(){e.props.onExiting(r),e.onTransitionEnd(n.exit,function(){e.safeSetState({status:ix},function(){e.props.onExited(r)})})})},n.cancelNextCallback=function(){this.nextCallback!==null&&(this.nextCallback.cancel(),this.nextCallback=null)},n.safeSetState=function(e,t){t=this.setNextCallback(t),this.setState(e,t)},n.setNextCallback=function(e){var t=this,n=!0;return this.nextCallback=function(r){n&&(n=!1,t.nextCallback=null,e(r))},this.nextCallback.cancel=function(){n=!1},this.nextCallback},n.onTransitionEnd=function(e,t){this.setNextCallback(t);var n=this.props.nodeRef?this.props.nodeRef.current:ts.default.findDOMNode(this),r=e==null&&!this.props.addEndListener;if(!n||r){setTimeout(this.nextCallback,0);return}if(this.props.addEndListener){var i=this.props.nodeRef?[this.nextCallback]:[n,this.nextCallback],a=i[0],o=i[1];this.props.addEndListener(a,o)}e!=null&&setTimeout(this.nextCallback,e)},n.render=function(){var e=this.state.status;if(e===`unmounted`)return null;var t=this.props,n=t.children;t.in,t.mountOnEnter,t.unmountOnExit,t.appear,t.enter,t.exit,t.timeout,t.addEndListener,t.onEnter,t.onEntering,t.onEntered,t.onExit,t.onExiting,t.onExited,t.nodeRef;var r=Jp(t,[`children`,`in`,`mountOnEnter`,`unmountOnExit`,`appear`,`enter`,`exit`,`timeout`,`addEndListener`,`onEnter`,`onEntering`,`onEntered`,`onExit`,`onExiting`,`onExited`,`nodeRef`]);return b.createElement(Kb.Provider,{value:null},typeof n==`function`?n(e,r):b.cloneElement(b.Children.only(n),r))},t}(b.Component);cx.contextType=Kb,cx.propTypes={};function lx(){}cx.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:lx,onEntering:lx,onEntered:lx,onExit:lx,onExiting:lx,onExited:lx},cx.UNMOUNTED=rx,cx.EXITED=ix,cx.ENTERING=ax,cx.ENTERED=ox,cx.EXITING=sx;var ux=[`bottom-center`,`bottom-left`,`bottom-right`,`top-center`,`top-left`,`top-right`];function dx(e,t){return e.reduce((e,n)=>(e[n.position||t].push(n),e),ux.reduce((e,t)=>(e[t]=[],e),{}))}var fx={left:`translateX(-100%)`,right:`translateX(100%)`,"top-center":`translateY(-100%)`,"bottom-center":`translateY(100%)`},px={left:`translateX(0)`,right:`translateX(0)`,"top-center":`translateY(0)`,"bottom-center":`translateY(0)`};function mx({state:e,maxHeight:t,position:n,transitionDuration:r}){let[i,a]=n.split(`-`),o=a===`center`?`${i}-center`:a,s={opacity:0,maxHeight:t,transform:fx[o],transitionDuration:`${r}ms, ${r}ms, ${r}ms`,transitionTimingFunction:`cubic-bezier(.51,.3,0,1.21), cubic-bezier(.51,.3,0,1.21), linear`,transitionProperty:`opacity, transform, max-height`},c={opacity:1,transform:px[o]},l={opacity:0,maxHeight:0,transform:fx[o]},u={entering:c,entered:c,exiting:l,exited:l};return{...s,...u[e]}}function hx(e,t){return typeof t==`number`?t:t===!1||e===!1?!1:e}var gx=(0,b.forwardRef)(({data:e,onHide:t,autoClose:n,...r},i)=>{let{autoClose:a,message:o,...s}=e,c=hx(n,e.autoClose),l=(0,b.useRef)(-1),u=()=>window.clearTimeout(l.current),d=()=>{t(e.id),u()},f=()=>{typeof c==`number`&&(l.current=window.setTimeout(d,c))};return(0,b.useEffect)(()=>{e.onOpen?.(e)},[]),(0,b.useEffect)(()=>(f(),u),[c]),(0,I.jsx)(Cg,{...r,...s,onClose:d,ref:i,onMouseEnter:u,onMouseLeave:f,children:o})});gx.displayName=`@mantine/notifications/NotificationContainer`;var _x={root:`m_b37d9ac7`,notification:`m_5ed0edd0`},vx=cx,yx={position:`bottom-right`,autoClose:4e3,transitionDuration:250,containerWidth:440,notificationMaxHeight:200,limit:5,zIndex:Je(`overlay`),store:Mb,withinPortal:!0},bx=nt((e,{zIndex:t,containerWidth:n})=>({root:{"--notifications-z-index":t?.toString(),"--notifications-container-width":F(n)}})),xx=B((e,t)=>{let n=R(`Notifications`,yx,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,position:l,autoClose:u,transitionDuration:d,containerWidth:f,notificationMaxHeight:p,limit:m,zIndex:h,store:g,portalProps:_,withinPortal:v,...y}=n,x=er(),S=Nb(g),C=Pt(),w=Kt(),T=(0,b.useRef)({}),E=(0,b.useRef)(0),D=x.respectReducedMotion&&w?1:d,O=L({name:`Notifications`,classes:_x,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,vars:c,varsResolver:bx});(0,b.useEffect)(()=>{g?.updateState(e=>({...e,limit:m||5,defaultPosition:l}))},[m,l]),xt(()=>{S.notifications.length>E.current&&setTimeout(()=>C(),0),E.current=S.notifications.length},[S.notifications]);let k=dx(S.notifications,l),A=ux.reduce((e,t)=>(e[t]=k[t].map(({style:e,...n})=>(0,I.jsx)(vx,{timeout:D,onEnter:()=>T.current[n.id].offsetHeight,nodeRef:{current:T.current[n.id]},children:r=>(0,I.jsx)(gx,{ref:e=>{e&&(T.current[n.id]=e)},data:n,onHide:e=>Fb(e,g),autoClose:u,...O(`notification`,{style:{...mx({state:r,position:t,transitionDuration:D,maxHeight:p}),...e}})})},n.id)),e),{});return(0,I.jsxs)(ff,{withinPortal:v,..._,children:[(0,I.jsx)(z,{...O(`root`),"data-position":`top-center`,ref:t,...y,children:(0,I.jsx)(ex,{children:A[`top-center`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`top-left`,...y,children:(0,I.jsx)(ex,{children:A[`top-left`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`top-right`,...y,children:(0,I.jsx)(ex,{children:A[`top-right`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`bottom-right`,...y,children:(0,I.jsx)(ex,{children:A[`bottom-right`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-left`,...y,children:(0,I.jsx)(ex,{children:A[`bottom-left`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-center`,...y,children:(0,I.jsx)(ex,{children:A[`bottom-center`]})})]})});xx.classes=_x,xx.displayName=`@mantine/notifications/Notifications`,xx.show=zb.show,xx.hide=zb.hide,xx.update=zb.update,xx.clean=zb.clean,xx.cleanQueue=zb.cleanQueue,xx.updateState=zb.updateState;var Sx=class{max;cache;constructor(e=10){this.max=e,this.cache=new Map}clear(){this.cache.clear()}get(e){let t=this.cache.get(e);return t&&(this.cache.delete(e),this.cache.set(e,t)),t}set(e,t){this.cache.has(e)?this.cache.delete(e):this.cache.size>=this.max&&this.cache.delete(this.first()),this.cache.set(e,t)}delete(e){this.cache.delete(e)}keys(){return this.cache.keys()}first(){return this.cache.keys().next().value}},Cx=class{operator;child;constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}},wx=class{operator;left;right;constructor(e,t,n){this.operator=e,this.left=t,this.right=n}toString(){return`(${this.left.toString()} ${this.operator} ${this.right.toString()})`}},Tx=class{prefixParselets={};infixParselets={};registerInfix(e,t){return this.infixParselets[e]=t,this}registerPrefix(e,t){return this.prefixParselets[e]=t,this}prefix(e,t,n){return this.registerPrefix(e,{parse(e,r){return n(r,e.consumeAndParse(t))}})}infixLeft(e,t,n){return this.registerInfix(e,{parse(e,r,i){return n(r,i,e.consumeAndParse(t))},precedence:t})}construct(e){return new Ex(e,this.prefixParselets,this.infixParselets)}},Ex=class{tokens;prefixParselets;infixParselets;constructor(e,t,n){this.tokens=e,this.prefixParselets=t,this.infixParselets=n}hasMore(){return this.tokens.length>0}match(e){return this.peek()?.id===e?(this.consume(),!0):!1}consumeAndParse(e=1/0){let t=this.consume(),n=this.prefixParselets[t.id];if(!n)throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);let r=n.parse(this,t);for(;e>this.getPrecedence();){let e=this.consume();r=this.getInfixParselet(e).parse(this,r,e)}return r}getPrecedence(){let e=this.peek();if(!e)return 1/0;let t=this.getInfixParselet(e);return t?t.precedence:1/0}consume(e,t){if(!this.tokens.length)throw Error(`Cant consume unknown more tokens.`);if(e&&this.peek()?.id!==e){let t=this.peek();throw Error(`Expected ${e} but got "${t.id}" (${t.value}) at line ${t.line} column ${t.column}.`)}if(t&&this.peek()?.value!==t){let e=this.peek();throw Error(`Expected "${t}" but got "${e.value}" at line ${e.line} column ${e.column}.`)}return this.tokens.shift()}peek(){return this.tokens.length>0?this.tokens[0]:void 0}removeComments(){this.tokens=this.tokens.filter(e=>e.id!==`Comment`)}getInfixParselet(e){return this.infixParselets[e.id===`Symbol`?e.value:e.id]}};function Dx(e){if(e!==void 0)return Array.isArray(e)?e:[e]}var Ox=`http://hl7.org`,kx=`ok`,Ax=`created`,jx=`gone`,Mx=`not-modified`,Nx=`not-found`,Px=`unauthorized`,Fx=`forbidden`,Ix=`accepted`,Lx={resourceType:`OperationOutcome`,id:kx,issue:[{severity:`information`,code:`informational`,details:{text:`All OK`}}]},Rx={resourceType:`OperationOutcome`,id:Nx,issue:[{severity:`error`,code:`not-found`,details:{text:`Not found`}}]},zx={resourceType:`OperationOutcome`,id:Px,issue:[{severity:`error`,code:`login`,details:{text:`Unauthorized`}}]},Bx={...zx,issue:[...zx.issue,{severity:`error`,code:`expired`,details:{text:`Token expired`}}]},Vx={...zx,issue:[...zx.issue,{severity:`error`,code:`invalid`,details:{text:`Token not issued for this audience`}}]},Hx={resourceType:`OperationOutcome`,id:Fx,issue:[{severity:`error`,code:`forbidden`,details:{text:`Forbidden`}}]};function Ux(e,t){return{resourceType:`OperationOutcome`,issue:[{severity:`error`,code:`invalid`,details:{text:e},...t?{expression:Dx(t)}:void 0}]}}function Wx(e,t,n,r){return{resourceType:`OperationOutcome`,issue:[{severity:`error`,code:n??`structure`,details:{text:e},...t?{expression:t}:void 0,...r?{diagnostics:r}:void 0}]}}function Gx(e){return e?.issue?.[0]?.details?.coding?.find(e=>e.system===`urn:ietf:rfc:3986`)?.code}function Kx(e){return!e||typeof e!=`object`?!1:e instanceof Error||typeof DOMException<`u`&&e instanceof DOMException?!0:Object.prototype.toString.call(e)===`[object Error]`}function qx(e){return typeof e==`object`&&!!e&&e.resourceType===`OperationOutcome`}function Jx(e){return e.id===kx||e.id===Ax||e.id===Mx||e.id===Ix}function Yx(e){return e.id===jx}var Xx=class extends Error{outcome;constructor(e,t){super(Qx(e),t),this.name=`OperationOutcomeError`,this.outcome=e}};function Zx(e){return e instanceof Xx?e.outcome:qx(e)?e:Ux(Y(e))}function Y(e){return e?typeof e==`string`?e:Kx(e)?e.message:qx(e)?Qx(e):typeof e==`object`&&`code`in e&&typeof e.code==`string`?e.code:JSON.stringify(e):`Unknown error`}function Qx(e){let t=e.issue?.map($x)??[];return t.length>0?t.join(`; `):`Unknown error`}function $x(e){let t;return t=e.details?.text?e.diagnostics?`${e.details.text} (${e.diagnostics})`:e.details.text:e.diagnostics?e.diagnostics:`Unknown error`,e.expression?.length&&(t+=` (${e.expression.join(`, `)})`),t}function eS(e,t){let n=t.max&&t.max===2**53-1?1/0:t.max;return{path:e,description:``,type:t.type??[],min:t.min??0,max:n??1,isArray:!!n&&n>1,constraints:[]}}function tS(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))t[n]={name:n,type:n,path:n,elements:Object.fromEntries(Object.entries(r.elements).map(([e,t])=>[e,eS(e,t)])),constraints:[],innerTypes:[]};return t}var nS={Element:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]}}},BackboneElement:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]}}},Address:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},use:{type:[{code:`code`}]},type:{type:[{code:`code`}]},text:{type:[{code:`string`}]},line:{max:9007199254740991,type:[{code:`string`}]},city:{type:[{code:`string`}]},district:{type:[{code:`string`}]},state:{type:[{code:`string`}]},postalCode:{type:[{code:`string`}]},country:{type:[{code:`string`}]},period:{type:[{code:`Period`}]}}},Age:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},Annotation:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},"author[x]":{type:[{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Practitioner`,`http://hl7.org/fhir/StructureDefinition/Patient`,`http://hl7.org/fhir/StructureDefinition/RelatedPerson`,`http://hl7.org/fhir/StructureDefinition/Organization`]},{code:`string`}]},time:{type:[{code:`dateTime`}]},text:{min:1,type:[{code:`markdown`}]}}},Attachment:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},contentType:{type:[{code:`code`}]},language:{type:[{code:`code`}]},data:{type:[{code:`base64Binary`}]},url:{type:[{code:`url`}]},size:{type:[{code:`unsignedInt`}]},hash:{type:[{code:`base64Binary`}]},title:{type:[{code:`string`}]},creation:{type:[{code:`dateTime`}]}}},CodeableConcept:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},coding:{max:9007199254740991,type:[{code:`Coding`}]},text:{type:[{code:`string`}]}}},Coding:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},system:{type:[{code:`uri`}]},version:{type:[{code:`string`}]},code:{type:[{code:`code`}]},display:{type:[{code:`string`}]},userSelected:{type:[{code:`boolean`}]}}},ContactDetail:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},name:{type:[{code:`string`}]},telecom:{max:9007199254740991,type:[{code:`ContactPoint`}]}}},ContactPoint:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},system:{type:[{code:`code`}]},value:{type:[{code:`string`}]},use:{type:[{code:`code`}]},rank:{type:[{code:`positiveInt`}]},period:{type:[{code:`Period`}]}}},Contributor:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,type:[{code:`code`}]},name:{min:1,type:[{code:`string`}]},contact:{max:9007199254740991,type:[{code:`ContactDetail`}]}}},Count:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},DataRequirement:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,type:[{code:`code`}]},profile:{max:9007199254740991,type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`]}]},"subject[x]":{type:[{code:`CodeableConcept`},{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Group`]}]},mustSupport:{max:9007199254740991,type:[{code:`string`}]},codeFilter:{max:9007199254740991,type:[{code:`DataRequirementCodeFilter`}]},dateFilter:{max:9007199254740991,type:[{code:`DataRequirementDateFilter`}]},limit:{type:[{code:`positiveInt`}]},sort:{max:9007199254740991,type:[{code:`DataRequirementSort`}]}}},DataRequirementCodeFilter:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},path:{type:[{code:`string`}]},searchParam:{type:[{code:`string`}]},valueSet:{type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/ValueSet`]}]},code:{max:9007199254740991,type:[{code:`Coding`}]}}},DataRequirementDateFilter:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},path:{type:[{code:`string`}]},searchParam:{type:[{code:`string`}]},"value[x]":{type:[{code:`dateTime`},{code:`Period`},{code:`Duration`}]}}},DataRequirementSort:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},path:{min:1,type:[{code:`string`}]},direction:{min:1,type:[{code:`code`}]}}},Distance:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},Dosage:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},sequence:{type:[{code:`integer`}]},text:{type:[{code:`string`}]},additionalInstruction:{max:9007199254740991,type:[{code:`CodeableConcept`}]},patientInstruction:{type:[{code:`string`}]},timing:{type:[{code:`Timing`}]},"asNeeded[x]":{type:[{code:`boolean`},{code:`CodeableConcept`}]},site:{type:[{code:`CodeableConcept`}]},route:{type:[{code:`CodeableConcept`}]},method:{type:[{code:`CodeableConcept`}]},doseAndRate:{max:9007199254740991,type:[{code:`DosageDoseAndRate`}]},maxDosePerPeriod:{type:[{code:`Ratio`}]},maxDosePerAdministration:{type:[{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]},maxDosePerLifetime:{type:[{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]}}},DosageDoseAndRate:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{type:[{code:`CodeableConcept`}]},"dose[x]":{type:[{code:`Range`},{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]},"rate[x]":{type:[{code:`Ratio`},{code:`Range`},{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]}}},Duration:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},ElementDefinition:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},path:{min:1,type:[{code:`string`}]},representation:{max:9007199254740991,type:[{code:`code`}]},sliceName:{type:[{code:`string`}]},sliceIsConstraining:{type:[{code:`boolean`}]},label:{type:[{code:`string`}]},code:{max:9007199254740991,type:[{code:`Coding`}]},slicing:{type:[{code:`ElementDefinitionSlicing`}]},short:{type:[{code:`string`}]},definition:{type:[{code:`markdown`}]},comment:{type:[{code:`markdown`}]},requirements:{type:[{code:`markdown`}]},alias:{max:9007199254740991,type:[{code:`string`}]},min:{type:[{code:`unsignedInt`}]},max:{type:[{code:`string`}]},base:{type:[{code:`ElementDefinitionBase`}]},contentReference:{type:[{code:`uri`}]},type:{max:9007199254740991,type:[{code:`ElementDefinitionType`}]},"defaultValue[x]":{type:[{code:`base64Binary`},{code:`boolean`},{code:`canonical`},{code:`code`},{code:`date`},{code:`dateTime`},{code:`decimal`},{code:`id`},{code:`instant`},{code:`integer`},{code:`markdown`},{code:`oid`},{code:`positiveInt`},{code:`string`},{code:`time`},{code:`unsignedInt`},{code:`uri`},{code:`url`},{code:`uuid`},{code:`Address`},{code:`Age`},{code:`Annotation`},{code:`Attachment`},{code:`CodeableConcept`},{code:`Coding`},{code:`ContactPoint`},{code:`Count`},{code:`Distance`},{code:`Duration`},{code:`HumanName`},{code:`Identifier`},{code:`Money`},{code:`Period`},{code:`Quantity`},{code:`Range`},{code:`Ratio`},{code:`Reference`},{code:`SampledData`},{code:`Signature`},{code:`Timing`},{code:`ContactDetail`},{code:`Contributor`},{code:`DataRequirement`},{code:`Expression`},{code:`ParameterDefinition`},{code:`RelatedArtifact`},{code:`TriggerDefinition`},{code:`UsageContext`},{code:`Dosage`},{code:`Meta`}]},meaningWhenMissing:{type:[{code:`markdown`}]},orderMeaning:{type:[{code:`string`}]},"fixed[x]":{type:[{code:`base64Binary`},{code:`boolean`},{code:`canonical`},{code:`code`},{code:`date`},{code:`dateTime`},{code:`decimal`},{code:`id`},{code:`instant`},{code:`integer`},{code:`markdown`},{code:`oid`},{code:`positiveInt`},{code:`string`},{code:`time`},{code:`unsignedInt`},{code:`uri`},{code:`url`},{code:`uuid`},{code:`Address`},{code:`Age`},{code:`Annotation`},{code:`Attachment`},{code:`CodeableConcept`},{code:`Coding`},{code:`ContactPoint`},{code:`Count`},{code:`Distance`},{code:`Duration`},{code:`HumanName`},{code:`Identifier`},{code:`Money`},{code:`Period`},{code:`Quantity`},{code:`Range`},{code:`Ratio`},{code:`Reference`},{code:`SampledData`},{code:`Signature`},{code:`Timing`},{code:`ContactDetail`},{code:`Contributor`},{code:`DataRequirement`},{code:`Expression`},{code:`ParameterDefinition`},{code:`RelatedArtifact`},{code:`TriggerDefinition`},{code:`UsageContext`},{code:`Dosage`},{code:`Meta`}]},"pattern[x]":{type:[{code:`base64Binary`},{code:`boolean`},{code:`canonical`},{code:`code`},{code:`date`},{code:`dateTime`},{code:`decimal`},{code:`id`},{code:`instant`},{code:`integer`},{code:`markdown`},{code:`oid`},{code:`positiveInt`},{code:`string`},{code:`time`},{code:`unsignedInt`},{code:`uri`},{code:`url`},{code:`uuid`},{code:`Address`},{code:`Age`},{code:`Annotation`},{code:`Attachment`},{code:`CodeableConcept`},{code:`Coding`},{code:`ContactPoint`},{code:`Count`},{code:`Distance`},{code:`Duration`},{code:`HumanName`},{code:`Identifier`},{code:`Money`},{code:`Period`},{code:`Quantity`},{code:`Range`},{code:`Ratio`},{code:`Reference`},{code:`SampledData`},{code:`Signature`},{code:`Timing`},{code:`ContactDetail`},{code:`Contributor`},{code:`DataRequirement`},{code:`Expression`},{code:`ParameterDefinition`},{code:`RelatedArtifact`},{code:`TriggerDefinition`},{code:`UsageContext`},{code:`Dosage`},{code:`Meta`}]},example:{max:9007199254740991,type:[{code:`ElementDefinitionExample`}]},"minValue[x]":{type:[{code:`date`},{code:`dateTime`},{code:`instant`},{code:`time`},{code:`decimal`},{code:`integer`},{code:`positiveInt`},{code:`unsignedInt`},{code:`Quantity`}]},"maxValue[x]":{type:[{code:`date`},{code:`dateTime`},{code:`instant`},{code:`time`},{code:`decimal`},{code:`integer`},{code:`positiveInt`},{code:`unsignedInt`},{code:`Quantity`}]},maxLength:{type:[{code:`integer`}]},condition:{max:9007199254740991,type:[{code:`id`}]},constraint:{max:9007199254740991,type:[{code:`ElementDefinitionConstraint`}]},mustSupport:{type:[{code:`boolean`}]},isModifier:{type:[{code:`boolean`}]},isModifierReason:{type:[{code:`string`}]},isSummary:{type:[{code:`boolean`}]},binding:{type:[{code:`ElementDefinitionBinding`}]},mapping:{max:9007199254740991,type:[{code:`ElementDefinitionMapping`}]}}},ElementDefinitionSlicingDiscriminator:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,type:[{code:`code`}]},path:{min:1,type:[{code:`string`}]}}},ElementDefinitionSlicing:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},discriminator:{max:9007199254740991,type:[{code:`ElementDefinitionSlicingDiscriminator`}]},description:{type:[{code:`string`}]},ordered:{type:[{code:`boolean`}]},rules:{min:1,type:[{code:`code`}]}}},ElementDefinitionBase:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},path:{min:1,type:[{code:`string`}]},min:{min:1,type:[{code:`unsignedInt`}]},max:{min:1,type:[{code:`string`}]}}},ElementDefinitionType:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},code:{min:1,type:[{code:`uri`}]},profile:{max:9007199254740991,type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`,`http://hl7.org/fhir/StructureDefinition/ImplementationGuide`]}]},targetProfile:{max:9007199254740991,type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`,`http://hl7.org/fhir/StructureDefinition/ImplementationGuide`]}]},aggregation:{max:9007199254740991,type:[{code:`code`}]},versioning:{type:[{code:`code`}]}}},ElementDefinitionExample:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},label:{min:1,type:[{code:`string`}]},"value[x]":{min:1,type:[{code:`base64Binary`},{code:`boolean`},{code:`canonical`},{code:`code`},{code:`date`},{code:`dateTime`},{code:`decimal`},{code:`id`},{code:`instant`},{code:`integer`},{code:`markdown`},{code:`oid`},{code:`positiveInt`},{code:`string`},{code:`time`},{code:`unsignedInt`},{code:`uri`},{code:`url`},{code:`uuid`},{code:`Address`},{code:`Age`},{code:`Annotation`},{code:`Attachment`},{code:`CodeableConcept`},{code:`Coding`},{code:`ContactPoint`},{code:`Count`},{code:`Distance`},{code:`Duration`},{code:`HumanName`},{code:`Identifier`},{code:`Money`},{code:`Period`},{code:`Quantity`},{code:`Range`},{code:`Ratio`},{code:`Reference`},{code:`SampledData`},{code:`Signature`},{code:`Timing`},{code:`ContactDetail`},{code:`Contributor`},{code:`DataRequirement`},{code:`Expression`},{code:`ParameterDefinition`},{code:`RelatedArtifact`},{code:`TriggerDefinition`},{code:`UsageContext`},{code:`Dosage`},{code:`Meta`}]}}},ElementDefinitionConstraint:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},key:{min:1,type:[{code:`id`}]},requirements:{type:[{code:`string`}]},severity:{min:1,type:[{code:`code`}]},human:{min:1,type:[{code:`string`}]},expression:{type:[{code:`string`}]},xpath:{type:[{code:`string`}]},source:{type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`]}]}}},ElementDefinitionBinding:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},strength:{min:1,type:[{code:`code`}]},description:{type:[{code:`string`}]},valueSet:{type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/ValueSet`]}]}}},ElementDefinitionMapping:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},identity:{min:1,type:[{code:`id`}]},language:{type:[{code:`code`}]},map:{min:1,type:[{code:`string`}]},comment:{type:[{code:`string`}]}}},Expression:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},description:{type:[{code:`string`}]},name:{type:[{code:`id`}]},language:{min:1,type:[{code:`code`}]},expression:{type:[{code:`string`}]},reference:{type:[{code:`uri`}]}}},Extension:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},url:{min:1,type:[{code:`uri`}]},"value[x]":{type:[{code:`base64Binary`},{code:`boolean`},{code:`canonical`},{code:`code`},{code:`date`},{code:`dateTime`},{code:`decimal`},{code:`id`},{code:`instant`},{code:`integer`},{code:`markdown`},{code:`oid`},{code:`positiveInt`},{code:`string`},{code:`time`},{code:`unsignedInt`},{code:`uri`},{code:`url`},{code:`uuid`},{code:`Address`},{code:`Age`},{code:`Annotation`},{code:`Attachment`},{code:`CodeableConcept`},{code:`Coding`},{code:`ContactPoint`},{code:`Count`},{code:`Distance`},{code:`Duration`},{code:`HumanName`},{code:`Identifier`},{code:`Money`},{code:`Period`},{code:`Quantity`},{code:`Range`},{code:`Ratio`},{code:`Reference`},{code:`SampledData`},{code:`Signature`},{code:`Timing`},{code:`ContactDetail`},{code:`Contributor`},{code:`DataRequirement`},{code:`Expression`},{code:`ParameterDefinition`},{code:`RelatedArtifact`},{code:`TriggerDefinition`},{code:`UsageContext`},{code:`Dosage`},{code:`Meta`}]}}},HumanName:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},use:{type:[{code:`code`}]},text:{type:[{code:`string`}]},family:{type:[{code:`string`}]},given:{max:9007199254740991,type:[{code:`string`}]},prefix:{max:9007199254740991,type:[{code:`string`}]},suffix:{max:9007199254740991,type:[{code:`string`}]},period:{type:[{code:`Period`}]}}},Identifier:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},use:{type:[{code:`code`}]},type:{type:[{code:`CodeableConcept`}]},system:{type:[{code:`uri`}]},value:{type:[{code:`string`}]},period:{type:[{code:`Period`}]},assigner:{type:[{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Organization`]}]}}},MarketingStatus:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},country:{min:1,type:[{code:`CodeableConcept`}]},jurisdiction:{type:[{code:`CodeableConcept`}]},status:{min:1,type:[{code:`CodeableConcept`}]},dateRange:{min:1,type:[{code:`Period`}]},restoreDate:{type:[{code:`dateTime`}]}}},Meta:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},versionId:{type:[{code:`id`}]},lastUpdated:{type:[{code:`instant`}]},source:{type:[{code:`uri`}]},profile:{max:9007199254740991,type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`]}]},security:{max:9007199254740991,type:[{code:`Coding`}]},tag:{max:9007199254740991,type:[{code:`Coding`}]},project:{type:[{code:`uri`}]},author:{type:[{code:`Reference`}]},onBehalfOf:{type:[{code:`Reference`}]},account:{type:[{code:`Reference`}]},accounts:{max:9007199254740991,type:[{code:`Reference`}]},compartment:{max:9007199254740991,type:[{code:`Reference`}]}}},Money:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},currency:{type:[{code:`code`}]}}},Narrative:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},status:{min:1,type:[{code:`code`}]},div:{min:1,type:[{code:`xhtml`}]}}},ParameterDefinition:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},name:{type:[{code:`code`}]},use:{min:1,type:[{code:`code`}]},min:{type:[{code:`integer`}]},max:{type:[{code:`string`}]},documentation:{type:[{code:`string`}]},type:{min:1,type:[{code:`code`}]},profile:{type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/StructureDefinition`]}]}}},Period:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},start:{type:[{code:`dateTime`}]},end:{type:[{code:`dateTime`}]}}},Population:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},"age[x]":{type:[{code:`Range`},{code:`CodeableConcept`}]},gender:{type:[{code:`CodeableConcept`}]},race:{type:[{code:`CodeableConcept`}]},physiologicalCondition:{type:[{code:`CodeableConcept`}]}}},ProdCharacteristic:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},height:{type:[{code:`Quantity`}]},width:{type:[{code:`Quantity`}]},depth:{type:[{code:`Quantity`}]},weight:{type:[{code:`Quantity`}]},nominalVolume:{type:[{code:`Quantity`}]},externalDiameter:{type:[{code:`Quantity`}]},shape:{type:[{code:`string`}]},color:{max:9007199254740991,type:[{code:`string`}]},imprint:{max:9007199254740991,type:[{code:`string`}]},image:{max:9007199254740991,type:[{code:`Attachment`}]},scoring:{type:[{code:`CodeableConcept`}]}}},ProductShelfLife:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},identifier:{type:[{code:`Identifier`}]},type:{min:1,type:[{code:`CodeableConcept`}]},period:{min:1,type:[{code:`Quantity`}]},specialPrecautionsForStorage:{max:9007199254740991,type:[{code:`CodeableConcept`}]}}},Quantity:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},Range:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},low:{type:[{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]},high:{type:[{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]}}},Ratio:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},numerator:{type:[{code:`Quantity`}]},denominator:{type:[{code:`Quantity`}]}}},Reference:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},reference:{type:[{code:`string`}]},type:{type:[{code:`uri`}]},identifier:{type:[{code:`Identifier`}]},display:{type:[{code:`string`}]}}},RelatedArtifact:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,type:[{code:`code`}]},label:{type:[{code:`string`}]},display:{type:[{code:`string`}]},citation:{type:[{code:`markdown`}]},url:{type:[{code:`url`}]},document:{type:[{code:`Attachment`}]},resource:{type:[{code:`canonical`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Resource`]}]}}},SampledData:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},origin:{min:1,type:[{code:`Quantity`,profile:[`http://hl7.org/fhir/StructureDefinition/SimpleQuantity`]}]},period:{min:1,type:[{code:`decimal`}]},factor:{type:[{code:`decimal`}]},lowerLimit:{type:[{code:`decimal`}]},upperLimit:{type:[{code:`decimal`}]},dimensions:{min:1,type:[{code:`positiveInt`}]},data:{type:[{code:`string`}]}}},Signature:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,max:9007199254740991,type:[{code:`Coding`}]},when:{min:1,type:[{code:`instant`}]},who:{min:1,type:[{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Practitioner`,`http://hl7.org/fhir/StructureDefinition/PractitionerRole`,`http://hl7.org/fhir/StructureDefinition/RelatedPerson`,`http://hl7.org/fhir/StructureDefinition/Patient`,`http://hl7.org/fhir/StructureDefinition/Device`,`http://hl7.org/fhir/StructureDefinition/Organization`]}]},onBehalfOf:{type:[{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Practitioner`,`http://hl7.org/fhir/StructureDefinition/PractitionerRole`,`http://hl7.org/fhir/StructureDefinition/RelatedPerson`,`http://hl7.org/fhir/StructureDefinition/Patient`,`http://hl7.org/fhir/StructureDefinition/Device`,`http://hl7.org/fhir/StructureDefinition/Organization`]}]},targetFormat:{type:[{code:`code`}]},sigFormat:{type:[{code:`code`}]},data:{type:[{code:`base64Binary`}]}}},SubstanceAmount:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},"amount[x]":{type:[{code:`Quantity`},{code:`Range`},{code:`string`}]},amountType:{type:[{code:`CodeableConcept`}]},amountText:{type:[{code:`string`}]},referenceRange:{type:[{code:`SubstanceAmountReferenceRange`}]}}},SubstanceAmountReferenceRange:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},lowLimit:{type:[{code:`Quantity`}]},highLimit:{type:[{code:`Quantity`}]}}},Timing:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},modifierExtension:{max:9007199254740991,type:[{code:`Extension`}]},event:{max:9007199254740991,type:[{code:`dateTime`}]},repeat:{type:[{code:`TimingRepeat`}]},code:{type:[{code:`CodeableConcept`}]}}},TimingRepeat:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},"bounds[x]":{type:[{code:`Duration`},{code:`Range`},{code:`Period`}]},count:{type:[{code:`positiveInt`}]},countMax:{type:[{code:`positiveInt`}]},duration:{type:[{code:`decimal`}]},durationMax:{type:[{code:`decimal`}]},durationUnit:{type:[{code:`code`}]},frequency:{type:[{code:`positiveInt`}]},frequencyMax:{type:[{code:`positiveInt`}]},period:{type:[{code:`decimal`}]},periodMax:{type:[{code:`decimal`}]},periodUnit:{type:[{code:`code`}]},dayOfWeek:{max:9007199254740991,type:[{code:`code`}]},timeOfDay:{max:9007199254740991,type:[{code:`time`}]},when:{max:9007199254740991,type:[{code:`code`}]},offset:{type:[{code:`unsignedInt`}]}}},TriggerDefinition:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},type:{min:1,type:[{code:`code`}]},name:{type:[{code:`string`}]},"timing[x]":{type:[{code:`Timing`},{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/Schedule`]},{code:`date`},{code:`dateTime`}]},data:{max:9007199254740991,type:[{code:`DataRequirement`}]},condition:{type:[{code:`Expression`}]}}},UsageContext:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},code:{min:1,type:[{code:`Coding`}]},"value[x]":{min:1,type:[{code:`CodeableConcept`},{code:`Quantity`},{code:`Range`},{code:`Reference`,targetProfile:[`http://hl7.org/fhir/StructureDefinition/PlanDefinition`,`http://hl7.org/fhir/StructureDefinition/ResearchStudy`,`http://hl7.org/fhir/StructureDefinition/InsurancePlan`,`http://hl7.org/fhir/StructureDefinition/HealthcareService`,`http://hl7.org/fhir/StructureDefinition/Group`,`http://hl7.org/fhir/StructureDefinition/Location`,`http://hl7.org/fhir/StructureDefinition/Organization`]}]}}},MoneyQuantity:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},SimpleQuantity:{elements:{id:{type:[{code:`string`}]},extension:{max:9007199254740991,type:[{code:`Extension`}]},value:{type:[{code:`decimal`}]},comparator:{max:0,type:[{code:`code`}]},unit:{type:[{code:`string`}]},system:{type:[{code:`uri`}]},code:{type:[{code:`code`}]}}},IdentityProvider:{elements:{authorizeUrl:{min:1,type:[{code:`string`}]},tokenUrl:{min:1,type:[{code:`string`}]},tokenAuthMethod:{type:[{code:`code`}]},userInfoUrl:{min:1,type:[{code:`string`}]},userInfoMode:{type:[{code:`code`}]},userInfoApiKey:{type:[{code:`string`}]},clientId:{min:1,type:[{code:`string`}]},clientSecret:{min:1,type:[{code:`string`}]},usePkce:{type:[{code:`boolean`}]},useSubject:{type:[{code:`boolean`}]},identitySource:{type:[{code:`code`}]},identityMappingMode:{type:[{code:`code`}]}}}};function rS(e){return new gS(e).parse()}var iS=tS(nS),aS=Object.create(null),oS=Object.create(null),sS={"http://hl7.org/fhir/StructureDefinition/MoneyQuantity":`MoneyQuantity`,"http://hl7.org/fhir/StructureDefinition/SimpleQuantity":`SimpleQuantity`,"http://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition":`ViewDefinition`};function cS(e){let t;return t=oS[e],t||=oS[e]=Object.create(null),t}function lS(e){let t=(Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[]).filter(e=>e?.resourceType===`StructureDefinition`);Ow(t);for(let e of t)uS(e)}function uS(e){if(!e?.name)throw Error(`Failed loading StructureDefinition from bundle`);if(e.resourceType!==`StructureDefinition`)return;let t=rS(e),n=sS[e.url],r,i;n?(r=iS,i=n):e.url===`http://hl7.org/fhir/StructureDefinition/${e.type}`||e.url===`https://medplum.com/fhir/StructureDefinition/${e.type}`||e.type?.startsWith(`http://`)||e.type?.startsWith(`https://`)?(r=iS,i=e.type):(r=cS(e.url),i=e.type),r[i]=t;for(let e of t.innerTypes)e.parentType=t,r[e.name]=e;aS[e.url]=t}function dS(e){return!!iS[e]}function fS(e,t){if(t){let n=cS(t)[e];if(n)return n}return iS[e]}function pS(e,t){let n=fS(e,t);if(!n)throw new Xx(Ux(`Unknown data type: `+e));return n}function mS(e){return!!aS[e]}function hS(e){return aS[e]}var gS=class{root;elements;elementIndex;index;resourceSchema;slicingContext;innerTypes;backboneContext;constructor(e){if(!e.snapshot?.element||e.snapshot.element.length===0)throw Error(`No snapshot defined for StructureDefinition '${e.name}'`);this.root=e.snapshot.element[0],this.elements=e.snapshot.element.slice(1),this.elementIndex=Object.create(null),this.index=0,this.resourceSchema={name:e.name,path:this.root.path,title:e.title,type:e.type,url:e.url,version:e.version,kind:e.kind,description:CS(e),elements:{},constraints:this.parseElementDefinition(this.root).constraints,innerTypes:[],summaryProperties:new Set,mandatoryProperties:new Set},this.innerTypes=[]}parse(){let e=this.next();for(;e;){if(e.sliceName)this.parseSliceStart(e);else if(e.id?.includes(`:`)){if(this.slicingContext?.current){let t=vS(e,this.slicingContext.path);this.slicingContext.current.elements[t]=this.parseElementDefinition(e)}}else{let t=this.parseElementDefinition(e);this.checkFieldEnter(e,t);let n=this.backboneContext;for(;n;){if(e.path?.startsWith(n.path+`.`)){n.type.elements[vS(e,n.path)]=t;break}n=n.parent}if(!n){let n=vS(e,this.root.path);e.isSummary&&this.resourceSchema.summaryProperties?.add(n.replace(`[x]`,``)),t.min>0&&this.resourceSchema.mandatoryProperties?.add(n.replace(`[x]`,``)),this.resourceSchema.elements[n]=t}this.checkFieldExit(e)}e=this.next()}return this.checkFieldExit(),this.innerTypes.length>0&&(this.resourceSchema.innerTypes=this.innerTypes),this.resourceSchema}checkFieldEnter(e,t){this.isInnerType(e)&&this.enterInnerType(e),this.slicingContext&&!bS(this.slicingContext.path,e?.path)&&(this.slicingContext=void 0),e.slicing&&!this.slicingContext&&this.enterSlice(e,t)}enterInnerType(e){for(;this.backboneContext&&!bS(this.backboneContext?.path,e.path);)this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;let t=jw(e);this.backboneContext={type:{name:t,type:t,path:e.path,title:e.label,description:e.definition,elements:{},constraints:this.parseElementDefinition(e).constraints,innerTypes:[]},path:e.path,parent:bS(this.backboneContext?.path,e.path)?this.backboneContext:this.backboneContext?.parent}}enterSlice(e,t){SS(e)&&!this.peek()?.sliceName||(t.slicing={discriminator:(e.slicing?.discriminator??[]).map(e=>{if(e.type!==`value`&&e.type!==`pattern`&&e.type!==`type`)throw Error(`Unsupported slicing discriminator type: ${e.type}`);return{path:e.path,type:e.type}}),slices:[],ordered:e.slicing?.ordered??!1,rule:e.slicing?.rules},this.slicingContext={field:t.slicing,path:e.path??``})}checkFieldExit(e=void 0){if(this.backboneContext&&!bS(this.backboneContext.path,e?.path))if(this.backboneContext.parent)do this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;while(this.backboneContext&&!bS(this.backboneContext.path,e?.path));else this.innerTypes.push(this.backboneContext.type),this.backboneContext=void 0}next(){let e=this.peek();if(e)return this.index++,e}peek(){let e=this.elements[this.index];if(e){if(this.elementIndex[e.path??``]=e,e.contentReference){let t=e.contentReference.slice(e.contentReference.indexOf(`#`)+1),n=this.elementIndex[t];return n?{...n,id:e.id,path:e.path,min:e.min??n.min,max:e.max??n.max,base:{path:n.base?.path??t,min:e.base?.min??n.base?.min??n.min,max:e.base?.max??n.base?.max??n.max},contentReference:e.contentReference,definition:e.definition}:void 0}return e}}isInnerType(e){let t=this.peek();return!!(bS(e?.path,t?.path)&&e.type?.some(e=>[`BackboneElement`,`Element`].includes(e.code)))}parseSliceStart(e){if(!this.slicingContext)throw Error(`Invalid slice start before discriminator: ${e.sliceName} (${e.id})`);this.slicingContext.current={...this.parseElementDefinition(e),name:e.sliceName??``,definition:e.definition,elements:{}},this.slicingContext.field.slices.push(this.slicingContext.current)}parseElementDefinitionType(e){return(e.type??[]).map(t=>{let n;return(t.code===`BackboneElement`||t.code===`Element`)&&(n=jw(e)),n||=_C(t,`http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type`)?.valueUrl,n||=t.code??``,{code:n,targetProfile:t.targetProfile,profile:t.profile}})}parseElementDefinition(e){let t=_S(e.max),n=e.base?.max?_S(e.base.max):t,r={type:`ElementDefinition`,value:e};return{description:e.definition||``,path:e.path||e.base?.path||``,min:e.min??0,max:t,isArray:n>1,constraints:(e.constraint??[]).map(e=>({key:e.key??``,severity:e.severity??`error`,expression:e.expression??``,description:e.human??``})),type:this.parseElementDefinitionType(e),fixed:xS(NS(r,`fixed[x]`)),pattern:xS(NS(r,`pattern[x]`)),binding:e.binding}}};function _S(e){return e===`*`?1/0:Number.parseInt(e,10)}function vS(e,t=``){return yS(e.path,t)}function yS(e,t){return e?t&&e.startsWith(t)?e.substring(t.length+1):e:``}function bS(e,t){return!e||!t?!1:t.startsWith(e+`.`)||t===e}function xS(e){return Array.isArray(e)&&e.length>0?e[0]:SC(e)?void 0:e}function SS(e){let t=e.slicing?.discriminator;return!!(e.type?.some(e=>e.code===`Extension`)&&t?.length===1&&t[0].type===`value`&&t[0].path===`url`)}function CS(e){let t=e.description;return t?.startsWith(`Base StructureDefinition for ${e.name} Type: `)&&(t=t.substring(`Base StructureDefinition for ${e.name} Type: `.length)),t}function wS(e,t,n){if(e===void 0)return[void 0];if(t===`$this`)return[e];let r=n?.withPath?TS:NS,[i,...a]=t.split(`.`),o=[r(e,i,n)];for(let e of a){let t=[];for(let i of o)if(Array.isArray(i))for(let a of i)t.push(r(a,e,n));else(n?.withPath&&i?.value!==void 0||!n?.withPath&&i!==void 0)&&t.push(r(i,e,n));o=t}return o}function TS(e,t,n){let r=e.path;return ES(NS(e,t,n),r,t)}function ES(e,t,n){let r=t?t+`.`:``;return e===void 0?{type:`undefined`,value:void 0,path:`${r}${n}`}:Array.isArray(e)?e.map((e,t)=>({...e,path:`${r}${n}[${t}]`})):{...e,path:`${r}${n}`}}new Sx(1e3);var DS={canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function OS(e,t,n,r){if(Array.isArray(e))return!1;let i;i=t.path===`$this`?n:(r??n.elements)[t.path];let a=n.type;switch(t.type){case`value`:case`pattern`:if(!e||!i)return!1;if(i.pattern)return OC(e,i.pattern);if(i.fixed)return TC(e,i.fixed);if(i.binding?.strength===`required`&&i.binding.valueSet)return!0;break;case`type`:return!e||!a?.length?!1:a.some(t=>t.code===e.type)}return!1}function kS(e){return[{type:X.boolean,value:e}]}function AS(e){return e==null?{type:`undefined`,value:void 0}:Number.isSafeInteger(e)?{type:X.integer,value:e}:typeof e==`number`?{type:X.decimal,value:e}:typeof e==`boolean`?{type:X.boolean,value:e}:typeof e==`string`?{type:X.string,value:e}:ZS(e)?{type:X.Quantity,value:e}:Vw(e)?{type:e.resourceType,value:e}:IC(e)?{type:X.CodeableConcept,value:e}:FC(e)?{type:X.Coding,value:e}:{type:X.BackboneElement,value:e}}function jS(e){return e.length===0?!1:!!e[0].value}function MS(e,t){if(e.length!==0){if(e.length===1&&(!t||e[0].type===t))return e[0];{let n=t?` of type ${t}`:``;throw Error(`Expected singleton${n}, but found ${JSON.stringify(e)}`)}}}function NS(e,t,n){if(!e.value)return;let r=zw(e.type,t,n?.profileUrl);return r?PS(e,t,r):IS(e,t)}function PS(e,t,n){let r=e.value,i=n.type;if(!i||i.length===0)return;let a,o=`undefined`,s,c=n.path.lastIndexOf(`.`),l=n.path.substring(c+1),u=l,d=!1;l.endsWith(`[x]`)&&(u=l.substring(0,l.length-3),d=!0);for(let e of i){let t=u;if(d&&(t+=HC(e.code)),a=r[t],s=r[`_`+t],a!==void 0||s!==void 0){o=e.code;break}}if(s)if(Array.isArray(a)){a=a.slice();for(let e=0;e<Math.max(a.length,s.length);e++)a[e]=tC(a[e],s[e])}else if(!a&&Array.isArray(s)){a=s.slice();for(let e=0;e<s.length;e++)a[e]=tC(void 0,s[e])}else a=tC(a,s);if(!SC(a))return(o===`Element`||o===`BackboneElement`)&&(o=n.type[0].code),Array.isArray(a)?a.map(e=>FS(e,o)):FS(a,o)}function FS(e,t){return t===`Resource`&&Vw(e)&&(t=e.resourceType),{type:t,value:e}}function IS(e,t){let n=e.value;if(!n||typeof n!=`object`)return;let r;if(t in n){let e=n[t];r=Array.isArray(e)?e.map(AS):AS(e)}else{let e=t.endsWith(`[x]`)?t.substring(0,t.length-3):t;for(let t of Object.values(X)){let i=e+HC(t);if(i in n){let e=n[i];r=Array.isArray(e)?e.map(e=>({type:t,value:e})):{type:t,value:e};break}}}if(Array.isArray(r)){if(r.length===0||SC(r[0]))return}else if(SC(r))return;return r}function LS(e){let t=[];for(let n of e){let e=!1;for(let r of t)if(jS(VS(n,r))){e=!0;break}e||t.push(n)}return t}function RS(e){return kS(!jS(e))}function zS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?kS(e.every((e,n)=>jS(VS(e,t[n])))):kS(!1)}function BS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?kS(e.some((e,n)=>!jS(VS(e,t[n])))):kS(!0)}function VS(e,t){let n=e.value?.valueOf(),r=t.value?.valueOf();return typeof n==`number`&&typeof r==`number`?kS(Math.abs(n-r)<1e-8):ZS(n)&&ZS(r)?kS(QS(n,r)):kS(typeof n==`object`&&typeof r==`object`?$S(e,t):n===r)}function HS(e,t){return e.length===0&&t.length===0?kS(!0):e.length===t.length?(e.sort(WS),t.sort(WS),kS(e.every((e,n)=>jS(US(e,t[n]))))):kS(!1)}function US(e,t){let{type:n,value:r}=e,{type:i,value:a}=t,o=r?.valueOf(),s=a?.valueOf();return typeof o==`number`&&typeof s==`number`?kS(Math.abs(o-s)<.01):ZS(o)&&ZS(s)?kS(QS(o,s)):kS(n===`Coding`&&i===`Coding`?typeof o!=`object`||typeof s!=`object`?!1:o.code===s.code&&o.system===s.system:typeof o==`object`&&typeof s==`object`?$S({...o,id:void 0},{...s,id:void 0}):typeof o==`string`&&typeof s==`string`?o.toLowerCase()===s.toLowerCase():o===s)}function WS(e,t){let n=e.value?.valueOf(),r=t.value?.valueOf();return typeof n==`number`&&typeof r==`number`?n-r:typeof n==`string`&&typeof r==`string`?n.localeCompare(r):0}function GS(e,t){let{value:n}=e;if(n==null)return!1;let r=t;switch(r.startsWith(`System.`)&&(r=r.substring(7)),r.startsWith(`FHIR.`)&&(r=r.substring(5)),r){case`Boolean`:return typeof n==`boolean`;case`Decimal`:case`Integer`:return typeof n==`number`;case`Date`:return KS(n);case`DateTime`:return qS(n);case`Time`:return typeof n==`string`&&!!/^T\d/.exec(n);case`Period`:return JS(n);case`Quantity`:return ZS(n);default:return e.type===r||typeof n==`object`&&n?.resourceType===r}}function KS(e){return typeof e==`string`&&!!DS.date.exec(e)}function qS(e){return typeof e==`string`&&!!DS.dateTime.exec(e)}function JS(e){return!!(e&&typeof e==`object`&&(`start`in e&&qS(e.start)||`end`in e&&qS(e.end)))}function YS(e){if(KS(e)||qS(e))return{start:XS(e,`0000-01-01T00:00:00.000`),end:XS(e,`xxxx-12-31T23:59:59.999`)};if(JS(e))return{start:e.start?XS(e.start,`0000-01-01T00:00:00.000`):void 0,end:e.end?XS(e.end,`xxxx-12-31T23:59:59.999`):void 0}}function XS(e,t){let n=`Z`,r=Math.max(e.indexOf(`+`,10),e.indexOf(`-`,10));r>-1?(n=e.substring(r),e=e.substring(0,r)):e.endsWith(`Z`)&&(e=e.substring(0,e.length-1));let i=e+t.substring(e.length)+n;return new Date(i).toISOString()}function ZS(e){return!!(e&&typeof e==`object`&&`value`in e&&typeof e.value==`number`)}function QS(e,t){return Math.abs(e.value-t.value)<.01&&(e.unit===t.unit||e.code===t.code||e.unit===t.code||e.code===t.unit)}function $S(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(eC(n)&&eC(i)){if(!$S(n,i))return!1}else if(n!==i)return!1}return!0}function eC(e){return typeof e==`object`&&!!e}function tC(e,t){if(t){if(typeof t!=`object`)throw Error(`Primitive extension must be an object`);return nC(e??{},t)}return e}function nC(e,t){return delete t.__proto__,delete t.constructor,Object.assign(e,t)}function rC(e,t){return Vw(e,t)&&`id`in e&&typeof e.id==`string`}function iC(e){let t=aC(e)??`undefined/undefined`,n=lC(e);return n===t?{reference:t}:{reference:t,display:n}}function aC(e){if(Hw(e))return e.reference;if(rC(e))return`${e.resourceType}/${e.id}`}function oC(e){if(e)return Hw(e)?e.reference.split(`/`)[1]:e.id}function sC(e){if(e)if(e.accounts&&e.account){let t=e.accounts;return t.some(t=>t.reference===e.account?.reference)?t:[e.account,...t]}else return Dx(e.accounts??e.account)}function cC(e){return e.resourceType===`Patient`||e.resourceType===`Practitioner`||e.resourceType===`RelatedPerson`}function lC(e){if(cC(e)){let t=uC(e);if(t)return t}if(e.resourceType===`Appointment`&&e.serviceType?.[0])return xw(e.serviceType[0]);if(e.resourceType===`Device`){let t=dC(e);if(t)return t}if(e.resourceType===`DocumentReference`){if(e.description)return e.description;if(e.type)return xw(e.type)}if(e.resourceType===`MedicationRequest`&&e.medicationCodeableConcept||e.resourceType===`MedicationStatement`&&e.medicationCodeableConcept)return xw(e.medicationCodeableConcept);if(e.resourceType===`Slot`&&(e.start||e.end))return`${dw(e.start)} - ${dw(e.end)}`;if(e.resourceType===`Subscription`&&e.criteria)return e.criteria;if(e.resourceType===`User`&&e.email)return e.email;if(`name`in e&&e.name&&typeof e.name==`string`)return e.name;if(`code`in e&&e.code){let t=e.code;if(Array.isArray(t)&&(t=t[0]),IC(t))return xw(t);if(LC(t))return t.text}return aC(e)??``}function uC(e){let t=e.name;if(t&&t.length>0)return cw(t[0])}function dC(e){let t=e.deviceName;if(t&&t.length>0)return t[0].name}function fC(e){if(!(`photo`in e))return;let t=e.photo;if(t)if(Array.isArray(t))for(let e of t){let t=pC(e);if(t)return t}else return pC(t)}function pC(e){if(e.url&&e.contentType?.startsWith(`image/`))return e.url}function mC(e,t){let n=new Date(e);n.setUTCHours(0,0,0,0);let r=t?new Date(t):new Date;r.setUTCHours(0,0,0,0);let i=n.getUTCFullYear(),a=n.getUTCMonth(),o=n.getUTCDate(),s=r.getUTCFullYear(),c=r.getUTCMonth(),l=r.getUTCDate(),u=s-i;(c<a||c===a&&l<o)&&u--;let d=s*12+c-(i*12+a);l<o&&d--;let f=Math.floor((r.getTime()-n.getTime())/(1e3*60*60*24));return{years:u,months:d,days:f}}function hC(e,t){let{years:n,months:r,days:i}=mC(e,t);return n>=2?n.toString().padStart(3,`0`)+`Y`:r>=1?r.toString().padStart(3,`0`)+`M`:i.toString().padStart(3,`0`)+`D`}function gC(e,t){let n=e.identifier;if(!n)return;let r=Array.isArray(n)?n:[n];for(let e of r)if(e.system===t)return e.value}function _C(e,...t){let n=e;for(let e=0;e<t.length&&n;e++)n=(n?.extension)?.find(n=>n.url===t[e]);return n}function vC(e,t){let n=yC(e);return JSON.stringify(n,null,t?2:void 0)??``}function yC(e){if(!(e==null||e===``))return typeof e==`object`?Array.isArray(e)?bC(e):xC(e):e}function bC(e){let t=e.length;if(t===0)return;let n,r=0;for(let i=0;i<t;i++){let t=e[i],a=yC(t);a!==t&&!n&&(n=Array.from(e)),a===void 0?n&&(n[i]=null):(n&&(n[i]=a),r++)}if(r!==0)return n??e}function xC(e){let t,n=0;for(let r in e){let i=e[r],a=yC(i);a!==i&&!t&&(t={...e}),a===void 0?t&&delete t[r]:(t&&(t[r]=a),n++)}if(n!==0)return t??e}function SC(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`object`?!CC(e):!1}function CC(e){if(e==null)return!1;let t=typeof e;return t===`string`&&e!==``||t===`object`&&(`length`in e&&e.length>0||Object.keys(e).length>0)}function wC(e){if(!e)return;let t=e.length-1;for(;t>=0&&SC(e[t]);)t--;return t>=0?e.slice(0,t+1):void 0}function TC(e,t,n){return e===t||SC(e)&&SC(t)?!0:SC(e)||SC(t)?!1:Array.isArray(e)&&Array.isArray(t)?EC(e,t):Array.isArray(e)||Array.isArray(t)?!1:NC(e)&&NC(t)?DC(e,t,n):!1}function EC(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!TC(e[n],t[n]))return!1;return!0}function DC(e,t,n){let r=new Set;for(let t of Object.keys(e))r.add(t);for(let e of Object.keys(t))r.add(e);n===`meta`&&(r.delete(`versionId`),r.delete(`lastUpdated`),r.delete(`author`));for(let n of r){let r=e[n],i=t[n];if(!TC(r,i,n))return!1}return!0}function OC(e,t){return SC(e)?!0:SC(t)?!1:Array.isArray(e)&&Array.isArray(t)?kC(e,t):Array.isArray(e)||Array.isArray(t)?!1:NC(e)&&NC(t)?AC(e,t):NC(e)||NC(t)?!1:e===t}function kC(e,t){return t.every(t=>e.some(e=>OC(e,t)))}function AC(e,t){return Object.entries(t).every(([t,n])=>t in e&&OC(e[t],n))}function jC(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function MC(e){return/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i.test(e)}function NC(e){return typeof e==`object`&&!!e}function PC(e){return typeof e==`string`}function FC(e){return NC(e)&&`code`in e&&typeof e.code==`string`}function IC(e){return NC(e)&&`coding`in e&&Array.isArray(e.coding)&&e.coding.every(FC)}function LC(e){return NC(e)&&`text`in e&&typeof e.text==`string`}var RC=[];for(let e=0;e<256;e++)RC.push(e.toString(16).padStart(2,`0`));function zC(e){let t=VC(e),n=new Uint8Array(t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=RC[n[e]];return r.join(``)}function BC(e){let t=VC(e),n=new Uint8Array(t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=String.fromCodePoint(n[e]);return window.btoa(r.join(``))}function VC(e){return ArrayBuffer.isView(e)?e.buffer:e}function HC(e){return e?e.charAt(0).toUpperCase()+e.substring(1):``}function UC(e){return e.length>0&&e.startsWith(e[0].toUpperCase())}function WC(e,t){let n=e+`.`;if(t.startsWith(n))return t.slice(n.length)}function GC(e,t){return e.coding?.find(e=>e.system===t)?.code}var KC=(e,t)=>new Promise((n,r)=>{t?.signal?.throwIfAborted();let i=setTimeout(n,e);t?.signal?.addEventListener(`abort`,()=>{clearTimeout(i),r(t.signal?.reason)},{once:!0})});function qC(e,t,n){let r=[];for(let i=0;i<n-1;i++){let n=e.indexOf(t);if(n<0)break;r.push(e.slice(0,n)),e=e.slice(n+t.length)}return r.push(e),r}function JC(e){let t,n=!1;return function(){return n||=(t=e(),!0),t}}function YC(e,t){return e?(e.push(t),e):[t]}function XC(e){return e.sort((e,t)=>e.localeCompare(t))}function ZC(e){return e.endsWith(`/`)?e:e+`/`}function QC(e){return e.startsWith(`/`)?e.slice(1):e}function $C(e,t){return new URL(QC(t),ZC(e.toString())).toString()}function ew(e,t){return $C(e,t).toString().replace(`http://`,`ws://`).replace(`https://`,`wss://`)}function tw(e){return typeof e==`object`&&!Array.isArray(e)&&!(e instanceof URLSearchParams)&&(e=Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))),new URLSearchParams(e).toString()}function nw(e,t){return e?.meta?.profile?.includes(t)||(e.meta=e.meta??{},e.meta.profile=e.meta.profile??[],e.meta.profile.push(t)),e}function rw(e,t){if(e?.meta?.profile?.includes(t)){let n=e.meta.profile.indexOf(t);e.meta.profile.splice(n,1)}return e}var iw=Object.freeze([]);function aw(e){if(!e)return``;switch(e.type){case`Address`:return sw(e.value);case`CodeableConcept`:return xw(e.value);case`Coding`:return Sw(e.value);case`ContactPoint`:return e.value.value;case`HumanName`:return cw(e.value);case`Quantity`:return yw(e.value);case`Reference`:return ow(e.value);default:return e.value?.toString()??``}}function ow(e){return e?e.display??e.reference??vC(e):``}function sw(e,t){if(!e)return``;let n=[];if(e.line&&n.push(...e.line),e.city||e.state||e.postalCode){let t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),n.push(t.join(`, `))}return e.use&&(t?.all||t?.use)&&n.push(`[`+e.use+`]`),n.join(t?.lineSeparator??`, `).trim()}function cw(e,t){if(!e)return``;let n=[];if(e.prefix&&t?.prefix!==!1&&n.push(...e.prefix),e.given&&n.push(...e.given),e.family&&n.push(e.family),e.suffix&&t?.suffix!==!1&&n.push(...e.suffix),e.use&&(t?.all||t?.use)&&n.push(`[`+e.use+`]`),n.length===0){let t=ww(e.text);if(t)return t}return n.join(` `).trim()}function lw(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function uw(e,t,n){if(!e)return``;let[r=0,i=0,a=0]=e.split(`:`).map(Number),o=new Date(Date.UTC(1970,0,1,r,i,a));return lw(o)?new Intl.DateTimeFormat(t,{hour:`numeric`,minute:`2-digit`,second:a===0?void 0:`numeric`,...n,timeZone:`UTC`}).format(o):``}function dw(e,t,n){if(!e)return``;let r=new Date(e);return lw(r)?r.toLocaleString(t,n):``}function fw(e,t,n){return!e||!e.start&&!e.end?``:dw(e.start,t,n)+` - `+dw(e.end,t,n)}var pw={s:`every second`,min:`every minute`,h:`hourly`,d:`daily`,wk:`weekly`,mo:`monthly`,a:`annually`},mw={s:`second`,min:`minute`,h:`hour`,d:`day`,wk:`week`,mo:`month`,a:`year`},hw={s:`seconds`,min:`minutes`,h:`hours`,d:`days`,wk:`weeks`,mo:`months`,a:`years`};function gw(e){if(!e)return``;let t=[];return _w(t,e.repeat),e.event&&t.push(e.event.map(e=>dw(e)).join(`, `)),HC(t.join(` `).trim())}function _w(e,t){if(!t?.periodUnit)return;let n=t.frequency??1,r=t.period??1,i=t.periodUnit;n===1&&r===1?e.push(pw[i]):(n===1?e.push(`once`):e.push(n+` times`),r===1?e.push(`per `+mw[i]):e.push(`per `+r+` `+hw[i])),t.dayOfWeek&&e.push(`on `+t.dayOfWeek.map(HC).join(`, `)),t.timeOfDay&&e.push(`at `+t.timeOfDay.map(e=>uw(e)).join(`, `))}function vw(e,t,n=!1){if(n&&t===void 0)throw Error(`Precision must be specified for exclusive ranges`);let r=e?.low&&{...e.low,comparator:void 0},i=e?.high&&{...e.high,comparator:void 0};return r?.value===void 0&&i?.value===void 0?``:r?.value!==void 0&&i?.value===void 0?n&&t!==void 0?(r.value=Ew(r.value,t),`> ${yw(r,t)}`):`>= ${yw(r,t)}`:r?.value===void 0&&i?.value!==void 0?n&&t!==void 0?(i.value=Tw(i.value,t),`< ${yw(i,t)}`):`<= ${yw(i,t)}`:(r?.unit===i?.unit&&delete r?.unit,`${yw(r,t)} - ${yw(i,t)}`)}function yw(e,t){if(!e)return``;let n=[];return e.comparator&&(n.push(e.comparator),n.push(` `)),e.value!==void 0&&(t===void 0?n.push(e.value):n.push(e.value.toFixed(t))),e.unit&&(e.unit!==`%`&&n.at(-1)!==` `&&n.push(` `),n.push(e.unit)),n.join(``).trim()}function bw(e){return e?.value===void 0?``:e.value.toLocaleString(void 0,{style:`currency`,currency:e.currency??`USD`,currencyDisplay:`narrowSymbol`})}function xw(e){return e?ww(e.text)||(e.coding?e.coding.map(e=>Sw(e)).join(`, `):``):``}function Sw(e,t){let n=ww(e?.display);if(n){let r=t?ww(e?.code):void 0;return`${n}${r?` (`+r+`)`:``}`}return ww(e?.code)??``}function Cw(e){if(!e)return``;let t=[];if(e.valueQuantity)t.push(yw(e.valueQuantity));else if(e.valueCodeableConcept)t.push(xw(e.valueCodeableConcept));else{let n=ww(e.valueString);n&&t.push(n)}return`component`in e&&t.push(e.component.map(e=>Cw(e)).join(` / `)),t.join(` / `).trim()}function ww(e){return typeof e==`string`?e:void 0}function Tw(e,t,n=1){return(Dw(e,t)+n)*10**-t}function Ew(e,t,n=1){return(Dw(e,t)-n)*10**-t}function Dw(e,t){return t===void 0?e:Math.round(e*10**t)}var X={Address:`Address`,Age:`Age`,Annotation:`Annotation`,Attachment:`Attachment`,BackboneElement:`BackboneElement`,CodeableConcept:`CodeableConcept`,Coding:`Coding`,ContactDetail:`ContactDetail`,ContactPoint:`ContactPoint`,Contributor:`Contributor`,Count:`Count`,DataRequirement:`DataRequirement`,Distance:`Distance`,Dosage:`Dosage`,Duration:`Duration`,Element:`Element`,ElementDefinition:`ElementDefinition`,Expression:`Expression`,Extension:`Extension`,HumanName:`HumanName`,Identifier:`Identifier`,MarketingStatus:`MarketingStatus`,Meta:`Meta`,Money:`Money`,MoneyQuantity:`MoneyQuantity`,Narrative:`Narrative`,ParameterDefinition:`ParameterDefinition`,Period:`Period`,Population:`Population`,ProdCharacteristic:`ProdCharacteristic`,ProductShelfLife:`ProductShelfLife`,Quantity:`Quantity`,Range:`Range`,Ratio:`Ratio`,Reference:`Reference`,RelatedArtifact:`RelatedArtifact`,SampledData:`SampledData`,Signature:`Signature`,SimpleQuantity:`SimpleQuantity`,SubstanceAmount:`SubstanceAmount`,SystemString:`http://hl7.org/fhirpath/System.String`,Timing:`Timing`,TriggerDefinition:`TriggerDefinition`,UsageContext:`UsageContext`,base64Binary:`base64Binary`,boolean:`boolean`,canonical:`canonical`,code:`code`,date:`date`,dateTime:`dateTime`,decimal:`decimal`,id:`id`,instant:`instant`,integer:`integer`,markdown:`markdown`,oid:`oid`,positiveInt:`positiveInt`,string:`string`,time:`time`,unsignedInt:`unsignedInt`,uri:`uri`,url:`url`,uuid:`uuid`,xhtml:`xhtml`};function Ow(e){let t=Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[];for(let e of t)e?.resourceType===`StructureDefinition`&&e.kind===`resource`&&kw(e.type)}function kw(e){let t=Uw.types[e];return t||(t={searchParamsDetails:{}},Uw.types[e]=t),!t.searchParams&&e!==`Binary`&&(t.searchParams={_id:{base:[e],code:`_id`,type:`token`,expression:e+`.id`},_lastUpdated:{base:[e],code:`_lastUpdated`,type:`date`,expression:e+`.meta.lastUpdated`},_compartment:{base:[e],code:`_compartment`,type:`reference`,expression:e+`.meta.compartment`},_profile:{base:[e],code:`_profile`,type:`uri`,expression:e+`.meta.profile`},_security:{base:[e],code:`_security`,type:`token`,expression:e+`.meta.security`},_source:{base:[e],code:`_source`,type:`uri`,expression:e+`.meta.source`},_tag:{base:[e],code:`_tag`,type:`token`,expression:e+`.meta.tag`},_project:{base:[e],code:`_project`,type:`token`,expression:e+`.meta.project`}}),t}function Aw(e){for(let t of e.base??iw){let n=kw(t);n.searchParams||={},n.searchParams[e.code]=e}}function jw(e){let t=e.type?.[0]?.code;return t===`BackboneElement`||t===`Element`?Mw((e.base?.path??e.path)?.split(`.`)):t}function Mw(e){return e.length===1?e[0]:e.map(HC).join(``)}function Nw(e){return Uw.types[e]?.searchParams}function Pw(e,t){return Uw.types[e]?.searchParams?.[t]}function Fw(e){return Iw(e.replaceAll(`[x]`,``).split(`.`).pop())}function Iw(e){let t;return t=e.length<100?e.match(/[A-Z]+(?![a-z])|[A-Z]?[a-z]+|\d+/g)??[]:e.split(/(?=[A-Z])/),t.map(Rw).join(` `).replace(`_`,` `).replaceAll(/\s+/g,` `)}var Lw=new Set([`CDS`,`ID`,`IP`,`PKCE`,`JWKS`,`URI`,`URL`,`OMB`,`UDI`]);function Rw(e){let t=e.toUpperCase();return e===t?e:Lw.has(t)?t:t.charAt(0)+e.slice(1)}function zw(e,t,n){let r=fS(e,n);if(r)return Bw(r.elements,t)}function Bw(e,t){let n=e[t]??e[t+`[x]`];if(n)return n;for(let n=0;n<t.length;n++){let r=t[n];if(r>=`A`&&r<=`Z`){let r=e[t.slice(0,n)+`[x]`];if(r)return r}}}function Vw(e,t){return!(!e||typeof e!=`object`||!(`resourceType`in e)||t&&e.resourceType!==t)}function Hw(e,t){return e&&typeof e==`object`&&`reference`in e&&typeof e.reference==`string`?t?e.reference.match(RegExp(`^${t}(/|\\?)`))!==null:!0:!1}var Uw={types:{}};function Ww(e){if(e.startsWith(`T`))return e+`T00:00:00.000Z`.substring(e.length);if(e.length<=10)return e;try{return new Date(e).toISOString()}catch{return e}}var Gw=()=>[];function Kw(e){return e instanceof eT?e.name:e instanceof lT&&e.left instanceof eT&&e.right instanceof eT?e.left.name+`.`+e.right.name:``}var qw={empty:(e,t)=>kS(t.every(e=>SC(e.value))),hasValue:(e,t)=>kS(t.length!==0),exists:(e,t,n)=>kS(n?t.some(t=>jS(n.eval(e,[t]))):t.length>0&&t.every(e=>!SC(e.value))),all:(e,t,n)=>kS(t.every(t=>jS(n.eval(e,[t])))),allTrue:(e,t)=>{for(let e of t)if(!e.value)return kS(!1);return kS(!0)},anyTrue:(e,t)=>{for(let e of t)if(e.value)return kS(!0);return kS(!1)},allFalse:(e,t)=>{for(let e of t)if(e.value)return kS(!1);return kS(!0)},anyFalse:(e,t)=>{for(let e of t)if(!e.value)return kS(!0);return kS(!1)},subsetOf:(e,t,n)=>{if(t.length===0)return kS(!0);let r=n.eval(e,Zw(e));return r.length===0?kS(!1):kS(t.every(e=>r.some(t=>t.value===e.value)))},supersetOf:(e,t,n)=>{let r=n.eval(e,Zw(e));return r.length===0?kS(!0):t.length===0?kS(!1):kS(r.every(e=>t.some(t=>t.value===e.value)))},count:(e,t)=>[{type:X.integer,value:t.length}],distinct:(e,t)=>{let n=[];for(let e of t)n.some(t=>t.value===e.value)||n.push(e);return n},isDistinct:(e,t)=>kS(t.length===qw.distinct(e,t).length),where:(e,t,n)=>t.filter(t=>jS(n.eval(e,[t]))),select:(e,t,n)=>t.flatMap(t=>n.eval({parent:e,variables:{$this:t}},[t])),repeat:Gw,ofType:(e,t,n)=>{let r=Kw(n);return r?t.filter(e=>GS(e,r)):[]},single:(e,t)=>{if(t.length>1)throw Error(`Expected input length one for single()`);return t.length===0?[]:t.slice(0,1)},first:(e,t)=>t.length===0?[]:t.slice(0,1),last:(e,t)=>t.length===0?[]:t.slice(-1,t.length),tail:(e,t)=>t.length===0?[]:t.slice(1,t.length),skip:(e,t,n)=>{let r=n.eval(e,t)[0]?.value;if(typeof r!=`number`)throw TypeError(`Expected a number for skip(num)`);return r>=t.length?[]:r<=0?t:t.slice(r,t.length)},take:(e,t,n)=>{let r=n.eval(e,t)[0]?.value;if(typeof r!=`number`)throw TypeError(`Expected a number for take(num)`);return r<=0?[]:t.slice(0,r)},intersect:(e,t,n)=>{if(!n)return t;let r=n.eval(e,Zw(e)),i=[];for(let e of t)!i.some(t=>t.value===e.value)&&r.some(t=>t.value===e.value)&&i.push(e);return i},exclude:(e,t,n)=>{if(!n)return t;let r=n.eval(e,Zw(e)),i=[];for(let e of t)r.some(t=>t.value===e.value)||i.push(e);return i},union:(e,t,n)=>{if(!n)return t;let r=n.eval(e,Zw(e));return LS([...t,...r])},combine:(e,t,n)=>{if(!n)return t;let r=n.eval(e,Zw(e));return[...t,...r]},htmlChecks:(e,t,n)=>[AS(!0)],iif:(e,t,n,r,i)=>{let a=n.eval(e,t);if(a.length>1||a.length===1&&typeof a[0].value!=`boolean`)throw Error(`Expected criterion to evaluate to a Boolean`);return jS(a)?r.eval(e,t):i?i.eval(e,t):[]},toBoolean:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);if(typeof n==`boolean`)return[{type:X.boolean,value:n}];if(typeof n==`number`&&(n===0||n===1))return kS(!!n);if(typeof n==`string`){let e=n.toLowerCase();if([`true`,`t`,`yes`,`y`,`1`,`1.0`].includes(e))return kS(!0);if([`false`,`f`,`no`,`n`,`0`,`0.0`].includes(e))return kS(!1)}return[]},convertsToBoolean:(e,t)=>t.length===0?[]:kS(qw.toBoolean(e,t).length===1),toInteger:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return typeof n==`number`?[{type:X.integer,value:n}]:typeof n==`string`&&/^[+-]?\d+$/.exec(n)?[{type:X.integer,value:Number.parseInt(n,10)}]:typeof n==`boolean`?[{type:X.integer,value:+!!n}]:[]},convertsToInteger:(e,t)=>t.length===0?[]:kS(qw.toInteger(e,t).length===1),toDate:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.date,value:Ww(n)}]:[]},convertsToDate:(e,t)=>t.length===0?[]:kS(qw.toDate(e,t).length===1),toDateTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.dateTime,value:Ww(n)}]:[]},convertsToDateTime:(e,t)=>t.length===0?[]:kS(qw.toDateTime(e,t).length===1),toDecimal:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return typeof n==`number`?[{type:X.decimal,value:n}]:typeof n==`string`&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(n)?[{type:X.decimal,value:Number.parseFloat(n)}]:typeof n==`boolean`?[{type:X.decimal,value:+!!n}]:[]},convertsToDecimal:(e,t)=>t.length===0?[]:kS(qw.toDecimal(e,t).length===1),toQuantity:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return ZS(n)?[{type:X.Quantity,value:n}]:typeof n==`number`?[{type:X.Quantity,value:{value:n,unit:`1`}}]:typeof n==`string`&&/^-?\d{1,9}(\.\d{1,9})?/.exec(n)?[{type:X.Quantity,value:{value:Number.parseFloat(n),unit:`1`}}]:typeof n==`boolean`?[{type:X.Quantity,value:{value:+!!n,unit:`1`}}]:[]},convertsToQuantity:(e,t)=>t.length===0?[]:kS(qw.toQuantity(e,t).length===1),toString:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);return n==null?[]:ZS(n)?[{type:X.string,value:`${n.value} '${n.unit}'`}]:[{type:X.string,value:n.toString()}]},convertsToString:(e,t)=>t.length===0?[]:kS(qw.toString(e,t).length===1),toTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=Xw(t,1);if(typeof n==`string`){let e=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(n);if(e)return[{type:X.time,value:Ww(`T`+e[1])}]}return[]},convertsToTime:(e,t)=>t.length===0?[]:kS(qw.toTime(e,t).length===1),indexOf:(e,t,n)=>Jw((e,t)=>e.indexOf(t),e,t,n),substring:(e,t,n,r)=>Jw((e,t,n)=>{let r=t,i=n?r+n:e.length;return r<0||r>=e.length?void 0:e.substring(r,i)},e,t,n,r),startsWith:(e,t,n)=>Jw((e,t)=>e.startsWith(t),e,t,n),endsWith:(e,t,n)=>Jw((e,t)=>e.endsWith(t),e,t,n),contains:(e,t,n)=>Jw((e,t)=>e.includes(t),e,t,n),upper:(e,t)=>Jw(e=>e.toUpperCase(),e,t),lower:(e,t)=>Jw(e=>e.toLowerCase(),e,t),replace:(e,t,n,r)=>Jw((e,t,n)=>e.replaceAll(t,n),e,t,n,r),matches:(e,t,n)=>Jw((e,t)=>!!new RegExp(t).exec(e),e,t,n),replaceMatches:(e,t,n,r)=>Jw((e,t,n)=>e.replaceAll(new RegExp(t,`g`),n.replaceAll(/\$\{(\w+)\}/g,`$<$1>`)),e,t,n,r),length:(e,t)=>Jw(e=>e.length,e,t),toChars:(e,t)=>Jw(e=>e?e.split(``):void 0,e,t),encode:Gw,decode:Gw,escape:Gw,unescape:Gw,trim:Gw,split:Gw,join:(e,t,n)=>{let r=n?.eval(e,Zw(e))[0]?.value??``;if(typeof r!=`string`)throw TypeError(`Separator must be a string.`);return[{type:X.string,value:t.map(e=>e.value?.toString()??``).join(r)}]},abs:(e,t)=>Yw(Math.abs,e,t),ceiling:(e,t)=>Yw(Math.ceil,e,t),exp:(e,t)=>Yw(Math.exp,e,t),floor:(e,t)=>Yw(Math.floor,e,t),ln:(e,t)=>Yw(Math.log,e,t),log:(e,t,n)=>Yw((e,t)=>Math.log(e)/Math.log(t),e,t,n),power:(e,t,n)=>Yw(Math.pow,e,t,n),round:(e,t,...n)=>Yw((e,t=0)=>{if(typeof t!=`number`||t<0)throw Error(`Invalid precision provided to round()`);let n=10**t;return Math.round(e*n)/n},e,t,...n),sqrt:(e,t)=>Yw(Math.sqrt,e,t),truncate:(e,t)=>Yw(e=>Math.trunc(e),e,t),children:Gw,descendants:Gw,trace:(e,t,n)=>t,now:()=>[{type:X.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:X.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:X.date,value:new Date().toISOString().substring(0,10)}],between:(e,t,n,r,i)=>{let a=qw.toDateTime(e,n.eval(e,t));if(a.length===0)throw Error(`Invalid start date`);let o=qw.toDateTime(e,r.eval(e,t));if(o.length===0)throw Error(`Invalid end date`);let s=i.eval(e,t)[0]?.value;if(s!==`years`&&s!==`months`&&s!==`days`)throw Error(`Invalid units`);let c=mC(a[0].value,o[0].value);return[{type:X.Quantity,value:{value:c[s],unit:s}}]},is:(e,t,n)=>{let r=Kw(n);return r?t.map(e=>({type:X.boolean,value:GS(e,r)})):[]},not:(e,t)=>qw.toBoolean(e,t).map(e=>({type:X.boolean,value:!e.value})),resolve:(e,t)=>t.map(e=>{let t=e.value,n;if(typeof t==`string`)n=t;else if(typeof t==`object`){let e=t;if(e.resource)return AS(e.resource);e.reference?n=e.reference:e.type&&e.identifier&&(n=`${e.type}?identifier=${e.identifier.system}|${e.identifier.value}`)}if(n?.includes(`?`)){let[e]=n.split(`?`);return{type:e,value:{resourceType:e}}}if(n?.includes(`/`)){let[e,t]=n.split(`/`);return{type:e,value:{resourceType:e,id:t}}}return{type:X.BackboneElement,value:void 0}}).filter(e=>!!e.value),as:(e,t,n)=>{let r=Kw(n);if(!r)throw Error(`Expected a valid type identifier as the right operand of 'as', but found ${n.toString()}`);let i=MS(t);return i&&GS(i,r)?[i]:[]},type:(e,t)=>t.map(({value:e})=>typeof e==`boolean`?{type:X.BackboneElement,value:{namespace:`System`,name:`Boolean`}}:typeof e==`number`?{type:X.BackboneElement,value:{namespace:`System`,name:`Integer`}}:Vw(e)?{type:X.BackboneElement,value:{namespace:`FHIR`,name:e.resourceType}}:{type:X.BackboneElement,value:null}),conformsTo:(e,t,n)=>{let r=n.eval(e,t)[0].value;if(!r.startsWith(`http://hl7.org/fhir/StructureDefinition/`))throw Error(`Expected a StructureDefinition URL`);let i=r.replace(`http://hl7.org/fhir/StructureDefinition/`,``);return t.map(e=>({type:X.boolean,value:e.value?.resourceType===i}))},getResourceKey:(e,t)=>{let n=t[0].value;return n?.id?[{type:X.id,value:n.id}]:[]},getReferenceKey:(e,t,n)=>{let r=t[0].value;if(!r?.reference)return[];let i=``;return n instanceof eT&&(i=n.name),i&&!r.reference.startsWith(i+`/`)?[]:[{type:X.id,value:oC(r)}]},extension:(e,t,n)=>{let r=n.eval(e,t)[0].value,i=t?.[0]?.value;if(i){let e=_C(i,r);if(e)return[{type:X.Extension,value:e}]}return[]}};function Jw(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=Xw(n,1);if(typeof i!=`string`)throw TypeError(`String function cannot be called with non-string`);let a=e(i,...r.map(e=>e?.eval(t,n)[0]?.value));return a===void 0?[]:Array.isArray(a)?a.map(AS):[AS(a)]}function Yw(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=Xw(n,1),a=ZS(i),o=a?i.value:i;if(typeof o!=`number`)throw TypeError(`Math function cannot be called with non-number`);let s=e(o,...r.map(e=>e.eval(t,n)[0]?.value));return[{type:a?X.Quantity:n[0].type,value:a?{...i,value:s}:s}]}function Xw(e,t){if(e.length!==t)throw Error(`Expected ${t} arguments`);for(let t of e)if(t==null)throw Error(`Expected non-null argument`);return e}function Zw(e){let t=e;for(;t.parent?.variables.$this;)t=t.parent;return[t.variables.$this]}var Qw=class{original;child;constructor(e,t){this.original=e,this.child=t}eval(e,t){try{if(t.length>0){let n=[];for(let r of t)n.push(this.child.eval({parent:e,variables:{$this:r}},[r]));return n.flat()}else return this.child.eval(e,[])}catch(e){throw Error(`FhirPathError on "${this.original}": ${e}`,{cause:e})}}toString(){return this.child.toString()}},$w=class{value;constructor(e){this.value=e}eval(){return[this.value]}toString(){let e=this.value.value;return typeof e==`string`?`'${e}'`:e.toString()}},eT=class{name;constructor(e){this.name=e}eval(e,t){if(this.name===`$this`)return t;let n=this.getVariable(e);if(n)return[n];if(this.name.startsWith(`%`))throw Error(`Undefined variable ${this.name}`);return t.flatMap(e=>this.evalValue(e)).filter(e=>e?.value!==void 0)}getVariable(e){let t=e.variables[this.name];if(t!==void 0)return t;if(e.parent)return this.getVariable(e.parent)}evalValue(e){let t=e.value;if(!(!t||typeof t!=`object`))return Vw(t,this.name)?(`path`in e||(e.path=t.resourceType),e):TS(e,this.name)}toString(){return this.name}},tT=class{eval(){return[]}toString(){return`{}`}},nT=class extends Cx{impl;constructor(e,t,n){super(e,t),this.impl=n}eval(e,t){return this.impl(this.child.eval(e,t))}toString(){return this.operator+this.child.toString()}},rT=class extends wx{constructor(e,t){super(`as`,e,t)}eval(e,t){return qw.as(e,this.left.eval(e,t),this.right)}},iT=class extends wx{impl;constructor(e,t,n,r){super(e,t,n),this.impl=r}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);if(n.length<1||r.length<1)return[];let i=MS(n)?.value,a=MS(r)?.value,o=ZS(i)?i.value:i,s=ZS(a)?a.value:a,c=this.impl(o,s);return typeof c==`boolean`?kS(c):ZS(i)?[{type:X.Quantity,value:{...i,value:c}}]:[AS(c)]}},aT=Object.freeze({type:`string`,value:``}),oT=class extends wx{constructor(e,t){super(`&`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t))??aT,r=MS(this.right.eval(e,t))??aT;if(typeof n.value!=`string`)throw Error(`Expected string operand for &, but got ${n.type}`);if(typeof r.value!=`string`)throw Error(`Expected string operand for &, but got ${r.type}`);return[{type:X.string,value:n.value+r.value}]}},sT=class extends wx{constructor(e,t){super(`contains`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return kS(n.some(e=>e.value===r[0].value))}},cT=class extends wx{constructor(e,t){super(`in`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t)),r=this.right.eval(e,t);return n?kS(r.some(e=>VS(n,e)[0].value)):[]}},lT=class extends wx{constructor(e,t){super(`.`,e,t)}eval(e,t){return this.right.eval(e,this.left.eval(e,t))}toString(){return`${this.left.toString()}.${this.right.toString()}`}},uT=class extends wx{constructor(e,t){super(`|`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return LS([...n,...r])}},dT=class extends wx{constructor(e,t){super(`=`,e,t)}eval(e,t){return zS(this.left.eval(e,t),this.right.eval(e,t))}},fT=class extends wx{constructor(e,t){super(`!=`,e,t)}eval(e,t){return BS(this.left.eval(e,t),this.right.eval(e,t))}},pT=class extends wx{constructor(e,t){super(`~`,e,t)}eval(e,t){return HS(this.left.eval(e,t),this.right.eval(e,t))}},mT=class extends wx{constructor(e,t){super(`!~`,e,t)}eval(e,t){return RS(HS(this.left.eval(e,t),this.right.eval(e,t)))}},hT=class extends wx{constructor(e,t){super(`is`,e,t)}eval(e,t){let n=this.left.eval(e,t);if(n.length!==1)return[];let r=Kw(this.right);return r?kS(GS(n[0],r)):[]}},gT=class extends wx{constructor(e,t){super(`and`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t),`boolean`),r=MS(this.right.eval(e,t),`boolean`);return n?.value===!0&&r?.value===!0?kS(!0):n?.value===!1||r?.value===!1?kS(!1):[]}},_T=class extends wx{constructor(e,t){super(`or`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t),`boolean`),r=MS(this.right.eval(e,t),`boolean`);return n?.value===!1&&r?.value===!1?kS(!1):n?.value||r?.value?kS(!0):[]}},vT=class extends wx{constructor(e,t){super(`xor`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t),`boolean`),r=MS(this.right.eval(e,t),`boolean`);return!n||!r?[]:kS(n.value!==r.value)}},yT=class extends wx{constructor(e,t){super(`implies`,e,t)}eval(e,t){let n=MS(this.left.eval(e,t),`boolean`),r=MS(this.right.eval(e,t),`boolean`);return r?.value===!0||n?.value===!1?kS(!0):!n||!r?[]:kS(!1)}},bT=class{name;args;constructor(e,t){this.name=e,this.args=t}eval(e,t){let n=qw[this.name];if(!n)throw Error(`Unrecognized function: `+this.name);return n(e,t,...this.args)}toString(){return`${this.name}(${this.args.map(e=>e.toString()).join(`, `)})`}},xT=class{left;expr;constructor(e,t){this.left=e,this.expr=t}eval(e,t){let n=this.expr.eval(e,t);if(n.length!==1)return[];let r=n[0].value;if(typeof r!=`number`)throw Error(`Invalid indexer expression: should return integer}`);let i=this.left.eval(e,t);return r in i?[i[r]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}},ST=[`year`,`years`,`month`,`months`,`week`,`weeks`,`day`,`days`,`hour`,`hours`,`minute`,`minutes`,`second`,`seconds`,`millisecond`,`milliseconds`],CT={"'":`'`,'"':`"`,"`":"`",r:`\r`,n:`
|
|
54
54
|
`,t:` `,f:`\f`,"\\":`\\`},wT=class{str;keywords;operators;dateTimeLiterals;symbolRegex;result=[];pos={index:0,line:1,column:0};markStack=[];constructor(e,t,n,r){this.str=e,this.keywords=t,this.operators=n,this.dateTimeLiterals=!!r?.dateTimeLiterals,this.symbolRegex=r?.symbolRegex??/[$\w%]/}tokenize(){for(;this.pos.index<this.str.length;){let e=this.consumeToken();e&&this.result.push(e)}return this.result}prevToken(){return this.result.slice(-1)[0]}peekToken(){this.mark();let e=this.consumeToken();return this.reset(),e}consumeToken(){this.consumeWhitespace();let e=this.curr();if(!e)return;this.mark();let t=this.peek();return e===`/`&&t===`*`?this.consumeMultiLineComment():e===`/`&&t===`/`?this.consumeSingleLineComment():e===`'`||e===`"`||e==="`"?this.consumeString(e):e===`@`?this.consumeDateTime():/\d/.exec(e)?this.consumeNumber():/\w/.exec(e)||(e===`$`||e===`%`)&&/\w/.exec(t)?this.consumeSymbol():(e===`$`||e===`%`)&&(t===`'`||t===`"`||t==="`")?this.consumeQuotedSymbol(t):this.consumeOperator()}consumeWhitespace(){this.consumeWhile(()=>/\s/.exec(this.curr()))}consumeMultiLineComment(){let e=this.pos.index;return this.consumeWhile(()=>this.curr()!==`*`||this.peek()!==`/`),this.advance(),this.advance(),this.buildToken(`Comment`,this.str.substring(e,this.pos.index))}consumeSingleLineComment(){return this.buildToken(`Comment`,this.consumeWhile(()=>this.curr()!==`
|
|
55
55
|
`))}consumeString(e){this.advance();let t=``,n;for(;n=this.consumeChar(e);)t+=n;let r=this.buildToken(e==="`"?`Symbol`:`String`,t);return this.advance(),r}consumeChar(e){let t=this.curr();if(t===`\\`){this.advance();let t=this.curr(),n=CT[t];if(n!==void 0)return this.advance(),n;if(t===`u`){this.advance();let e=/^[0-9a-fA-F]{4}$/.exec(this.str.substring(this.pos.index,this.pos.index+4))?.[0];return e?(this.advance(),this.advance(),this.advance(),this.advance(),String.fromCodePoint(Number.parseInt(e,16))):`u`}return this.consumeChar(e)}return t===e||!t?``:(this.advance(),t)}consumeQuotedSymbol(e){this.mark();let t=this.pos.index;this.advance(),this.consumeString(e);let n=this.str.substring(t,this.pos.index);return this.buildToken(`Symbol`,n)}consumeDateTime(){this.advance();let e=this.pos.index;this.consumeWhile(()=>/[\d-]/.exec(this.curr()));let t=!1,n=!1;if(this.curr()===`T`&&(t=!0,this.advance(),this.consumeWhile(()=>/[\d:]/.exec(this.curr())),this.curr()===`.`&&/\d/.exec(this.peek())&&(this.advance(),this.consumeWhile(()=>/\d/.exec(this.curr()))),this.curr()===`Z`?(n=!0,this.advance()):(this.curr()===`+`||this.curr()===`-`)&&(n=!0,this.advance(),this.consumeWhile(()=>/[\d:]/.exec(this.curr())))),this.pos.index===e)throw Error(`Invalid DateTime literal`);let r=this.str.substring(e,this.pos.index);return r.endsWith(`T`)?r=r.substring(0,r.length-1):!r.startsWith(`T`)&&t&&!n&&(r+=`Z`),this.buildToken(`DateTime`,r)}consumeNumber(){let e=this.pos.index,t=`Number`;this.consumeWhile(()=>/\d/.exec(this.curr())),this.curr()===`.`&&/\d/.exec(this.peek())&&(this.advance(),this.consumeWhile(()=>/\d/.exec(this.curr())));let n=this.curr();if(n===`-`&&this.dateTimeLiterals)return this.pos.index=e-1,this.consumeDateTime();if(n===` `)TT(this.peekToken())&&(t=`Quantity`,this.consumeToken());else if(n&&/[a-zA-Z_$]/.exec(n))return this.pos.index=e-1,this.consumeString(` `);return this.buildToken(t,this.str.substring(e,this.pos.index))}consumeSymbol(){let e=this.consumeWhile(()=>this.symbolRegex.exec(this.curr()));return this.prevToken()?.value!==`.`&&this.keywords.includes(e)?this.buildToken(e,e):this.buildToken(`Symbol`,e)}consumeOperator(){let e=this.curr(),t=e+this.peek();return this.operators.includes(t)?(this.advance(),this.advance(),this.buildToken(t,t)):(this.advance(),this.buildToken(e,e))}consumeWhile(e){let t=this.pos.index;for(;this.pos.index<this.str.length&&e();)this.advance();return this.str.substring(t,this.pos.index)}curr(){return this.str[this.pos.index]}peek(){return this.str[this.pos.index+1]??``}mark(){this.markStack.push({...this.pos})}reset(){let e=this.markStack.pop();if(!e)throw Error(`No mark to reset to`);this.pos.index=e.index,this.pos.line=e.line,this.pos.column=e.column}advance(){this.pos.index++,this.curr()===`
|
|
56
|
-
`?(this.pos.line++,this.pos.column=0):this.pos.column++}buildToken(e,t){let n=this.markStack.pop();if(!n)throw Error(`No mark for token`);return{id:e,value:t,...n}}};function TT(e){return!!(e&&(e.id===`String`||e.id===`Symbol`&&ST.includes(e.value)))}var ET=[`true`,`false`],DT=[`!=`,`!~`,`<=`,`>=`,`{}`,`->`];function OT(e){return new wT(e,ET,DT).tokenize()}var kT={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},AT={parse(e){let t=e.consumeAndParse();if(!e.match(`)`))throw Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},jT={parse(e,t){let n=e.consumeAndParse();if(!e.match(`]`))throw Error("Parse error: expected `]`");return new xT(t,n)},precedence:kT.Indexer},MT={parse(e,t){if(!(t instanceof eT))throw Error(`Unexpected parentheses`);let n=[];for(;!e.match(`)`);)n.push(e.consumeAndParse()),e.match(`,`);return new bT(t.name,n)},precedence:kT.FunctionCall};function NT(e){let t=e.split(` `),n=Number.parseFloat(t[0]),r=t[1];return r=r?.startsWith(`'`)&&r.endsWith(`'`)?r.substring(1,r.length-1):`{`+r+`}`,{value:n,unit:r}}function PT(){return new Tx().registerPrefix(`String`,{parse:(e,t)=>new $w({type:X.string,value:t.value})}).registerPrefix(`DateTime`,{parse:(e,t)=>new $w({type:X.dateTime,value:Ww(t.value)})}).registerPrefix(`Quantity`,{parse:(e,t)=>new $w({type:X.Quantity,value:NT(t.value)})}).registerPrefix(`Number`,{parse:(e,t)=>new $w({type:t.value.includes(`.`)?X.decimal:X.integer,value:Number.parseFloat(t.value)})}).registerPrefix(`true`,{parse:()=>new $w({type:X.boolean,value:!0})}).registerPrefix(`false`,{parse:()=>new $w({type:X.boolean,value:!1})}).registerPrefix(`Symbol`,{parse:(e,t)=>new eT(t.value)}).registerPrefix(`{}`,{parse:()=>new tT}).registerPrefix(`(`,AT).registerInfix(`[`,jT).registerInfix(`(`,MT).prefix(`+`,kT.UnaryAdd,(e,t)=>new nT(`+`,t,e=>e)).prefix(`-`,kT.UnarySubtract,(e,t)=>new iT(`-`,t,t,(e,t)=>-t)).infixLeft(`.`,kT.Dot,(e,t,n)=>new lT(e,n)).infixLeft(`/`,kT.Divide,(e,t,n)=>new iT(`/`,e,n,(e,t)=>e/t)).infixLeft(`*`,kT.Multiply,(e,t,n)=>new iT(`*`,e,n,(e,t)=>e*t)).infixLeft(`+`,kT.Add,(e,t,n)=>new iT(`+`,e,n,(e,t)=>e+t)).infixLeft(`-`,kT.Subtract,(e,t,n)=>new iT(`-`,e,n,(e,t)=>e-t)).infixLeft(`|`,kT.Union,(e,t,n)=>new uT(e,n)).infixLeft(`=`,kT.Equals,(e,t,n)=>new dT(e,n)).infixLeft(`!=`,kT.NotEquals,(e,t,n)=>new fT(e,n)).infixLeft(`~`,kT.Equivalent,(e,t,n)=>new pT(e,n)).infixLeft(`!~`,kT.NotEquivalent,(e,t,n)=>new mT(e,n)).infixLeft(`<`,kT.LessThan,(e,t,n)=>new iT(`<`,e,n,(e,t)=>e<t)).infixLeft(`<=`,kT.LessThanOrEquals,(e,t,n)=>new iT(`<=`,e,n,(e,t)=>e<=t)).infixLeft(`>`,kT.GreaterThan,(e,t,n)=>new iT(`>`,e,n,(e,t)=>e>t)).infixLeft(`>=`,kT.GreaterThanOrEquals,(e,t,n)=>new iT(`>=`,e,n,(e,t)=>e>=t)).infixLeft(`&`,kT.Ampersand,(e,t,n)=>new oT(e,n)).infixLeft(`and`,kT.And,(e,t,n)=>new gT(e,n)).infixLeft(`as`,kT.As,(e,t,n)=>new rT(e,n)).infixLeft(`contains`,kT.Contains,(e,t,n)=>new sT(e,n)).infixLeft(`div`,kT.Divide,(e,t,n)=>new iT(`div`,e,n,(e,t)=>Math.trunc(e/t))).infixLeft(`in`,kT.In,(e,t,n)=>new cT(e,n)).infixLeft(`is`,kT.Is,(e,t,n)=>new hT(e,n)).infixLeft(`mod`,kT.Modulo,(e,t,n)=>new iT(`mod`,e,n,(e,t)=>e%t)).infixLeft(`or`,kT.Or,(e,t,n)=>new _T(e,n)).infixLeft(`xor`,kT.Xor,(e,t,n)=>new vT(e,n)).infixLeft(`implies`,kT.Implies,(e,t,n)=>new yT(e,n))}var FT=PT();function IT(e){return new Qw(e,FT.construct(OT(e)).consumeAndParse())}function LT(e,t,n={},r=void 0){let i=Array.isArray(t)?t:[t];for(let e=0;e<i.length;e++){let t=i[e];typeof t==`object`&&`type`in t&&`value`in t||(i[e]=AS(i[e]))}return RT(e,i,n,r).map(e=>e.value)}function RT(e,t,n={},r=void 0){let i;if(typeof e==`string`){let t=r?.get(e);i=t??IT(e),r&&!t&&r.set(e,i)}else i=e;return i.eval({variables:n},t).map(e=>{let t={type:e.type,value:e.value?.valueOf()};return`path`in e&&(t.path=e.path),t})}function zT(e){let t=[];for(let n of e){let e=YS(n.value);e&&t.push(e)}return t}function BT(e){let t=new Set;for(let n of e){let e=aw(n);e&&t.add(e)}return Array.from(t)}function VT(e){let t=new Set;for(let n of e){let{value:e}=n;e&&(PC(e)?t.add(e):Hw(e)?t.add(e.reference):rC(e)?t.add(aC(e)):typeof e.identifier==`object`&&t.add(`identifier:${e.identifier.system}|${e.identifier.value}`))}return Array.from(t)}function HT(e,t={}){let n=[];for(let r of e)UT(t,n,r);return n}function UT(e,t,n){let{type:r,value:i}=n;switch(r){case X.Identifier:WT(t,e,i);break;case X.CodeableConcept:GT(t,e,i);break;case X.Coding:KT(t,e,i);break;case X.ContactPoint:qT(t,e,i);break;default:JT(t,e,void 0,i?.toString())}}function WT(e,t,n){n?.type?.text&&JT(e,t,t.textSearchSystem,n.type.text),JT(e,t,n?.system,n?.value)}function GT(e,t,n){n?.text&&JT(e,t,t.textSearchSystem,n.text);for(let r of n?.coding??iw)KT(e,t,r)}function KT(e,t,n){n&&(n.display&&JT(e,t,t.textSearchSystem,n.display),JT(e,t,n.system,n.code))}function qT(e,t,n){n&&JT(e,t,n.system,n.value?.toLocaleLowerCase())}function JT(e,t,n,r){(n||r)&&!e.some(e=>e.system===n&&e.value===r)&&e.push({system:n,value:r&&t.caseInsensitive?r.toLocaleLowerCase():r})}var Z={EQUALS:`eq`,NOT_EQUALS:`ne`,GREATER_THAN:`gt`,LESS_THAN:`lt`,GREATER_THAN_OR_EQUALS:`ge`,LESS_THAN_OR_EQUALS:`le`,STARTS_AFTER:`sa`,ENDS_BEFORE:`eb`,APPROXIMATELY:`ap`,CONTAINS:`contains`,STARTS_WITH:`sw`,EXACT:`exact`,TEXT:`text`,NOT:`not`,ABOVE:`above`,BELOW:`below`,IN:`in`,NOT_IN:`not-in`,OF_TYPE:`of-type`,MISSING:`missing`,PRESENT:`present`,IDENTIFIER:`identifier`,ITERATE:`iterate`},YT={contains:Z.CONTAINS,exact:Z.EXACT,above:Z.ABOVE,below:Z.BELOW,text:Z.TEXT,not:Z.NOT,in:Z.IN,"not-in":Z.NOT_IN,"of-type":Z.OF_TYPE,missing:Z.MISSING,identifier:Z.IDENTIFIER,iterate:Z.ITERATE},XT={eq:Z.EQUALS,ne:Z.NOT_EQUALS,lt:Z.LESS_THAN,le:Z.LESS_THAN_OR_EQUALS,gt:Z.GREATER_THAN,ge:Z.GREATER_THAN_OR_EQUALS,sa:Z.STARTS_AFTER,eb:Z.ENDS_BEFORE,ap:Z.APPROXIMATELY,sw:Z.STARTS_WITH};function ZT(e,t){if(!e)throw Error(`Invalid search URL`);let n=``,r;if(typeof e==`string`)if(e.includes(`?`)){let[t,i]=e.split(`?`);n=t,r=new URLSearchParams(i)}else n=e;else typeof e==`object`&&(n=e.pathname,r=e.searchParams);let i;i=n.includes(`/`)?n.split(`/`).filter(Boolean).pop():n;let a=[];if(r&&a.push(...r.entries()),t)for(let[e,n]of Object.entries(t))if(Array.isArray(n))for(let t of n)a.push([e,t]);else a.push([e,n??``]);return QT(i,a)}function QT(e,t){let n={resourceType:e};for(let[e,r]of t)$T(n,e,r);return n}function $T(e,t,n){let r,i,a=t.indexOf(`:`);if(a>=0?(r=t.substring(0,a),i=t.substring(a+1)):(r=t,i=``),r!==`_`){if(r===`_has`||t.includes(`.`)){e.filters=YC(e.filters,{code:t,operator:Z.EQUALS,value:n});return}switch(r){case`_sort`:eE(e,n);break;case`_cursor`:e.cursor=n;break;case`_count`:e.count=Number.parseInt(n,10);break;case`_offset`:e.offset=Number.parseInt(n,10);break;case`_total`:e.total=n;break;case`_summary`:n===`count`?(e.total=`accurate`,e.count=0):(n===`true`||n===`data`||n===`text`)&&(e.summary=n);break;case`_include`:{let t=oE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.include=YC(e.include,t);break}case`_revinclude`:{let t=oE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.revInclude=YC(e.revInclude,t);break}case`_fields`:case`_elements`:e.fields=n.split(`,`);break;case`_type`:e.types=n.split(`,`);break;case`_format`:e.format=n;break;case`_pretty`:e.pretty=n===`true`;break;default:{let t=Uw.types[e.resourceType]?.searchParams?.[r];t?e.filters=YC(e.filters,nE(t,Z.EQUALS,i,n)):e.filters=YC(e.filters,rE(r,i,n))}}}}function eE(e,t){for(let n of t.split(`,`)){let t,r=!1;n.startsWith(`-`)?(t=n.substring(1),r=!0):t=n,e.sortRules||=[],e.sortRules.push({code:t,descending:r})}}var tE=[Z.MISSING,Z.PRESENT];function nE(e,t,n,r){if(tE.includes(n||t))return{code:e.code,operator:n||t,value:r};switch(e.type){case`number`:case`date`:case`quantity`:{let{operator:t,value:i}=iE(r,n||Z.EQUALS);if(!sE(e,i))throw new Xx(Ux(`Invalid format for ${e.type} search parameter: ${i}`));return{code:e.code,operator:t,value:i}}case`reference`:case`string`:case`token`:case`uri`:if(!sE(e,r))throw new Xx(Ux(`Invalid format for ${e.type} search parameter: ${r}`));return{code:e.code,operator:aE(n)??t,value:r};default:throw Error(`Unrecognized search parameter type: `+e.type)}}function rE(e,t,n){let r=Z.EQUALS;if(t)r=t;else if(n.length>=2){let e=n.substring(0,2);e in XT&&(n.length===2||n.at(2)?.match(/\d/))&&(r=e,n=n.substring(e.length))}return{code:e,operator:r,value:n}}function iE(e,t){let n=XT[e.substring(0,2)];return n?{operator:n,value:e.substring(2)}:{operator:t,value:e}}function aE(e){return YT[e]}function oE(e){let t=e.split(`:`);if(t.includes(`*`))throw new Xx(Ux(`'*' is not supported as a value for search inclusion parameters`));if(t.length===1)throw new Xx(Ux(`Invalid include value '${e}': must be of the form ResourceType:search-parameter`));if(t.length===2)return{resourceType:t[0],searchParam:t[1]};if(t.length===3)return{resourceType:t[0],searchParam:t[1],targetType:t[2]};throw new Xx(Ux(`Invalid include value '${e}'`))}function sE(e,t){switch(e.type){case`date`:return qS(t);default:return!0}}function cE(e){let t=[];e.fields&&t.push(`_fields=`+e.fields.join(`,`));for(let n of e.filters??iw)t.push(lE(n));e.sortRules&&e.sortRules.length>0&&t.push(uE(e.sortRules)),e.cursor!==void 0&&t.push(`_cursor=`+encodeURIComponent(e.cursor)),e.offset!==void 0&&e.offset!==0&&t.push(`_offset=`+e.offset),e.count!==void 0&&t.push(`_count=`+e.count),e.total!==void 0&&t.push(`_total=`+e.total),e.types&&e.types.length>0&&t.push(`_type=`+e.types.join(`,`));for(let n of e.include??iw)t.push(dE(`_include`,n));for(let n of e.revInclude??iw)t.push(dE(`_revinclude`,n));return t.length===0?``:(XC(t),`?`+t.join(`&`))}function lE(e){let t=e.operator in YT?`:`+e.operator:``,n=e.operator!==Z.EQUALS&&e.operator in XT?e.operator:``;return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}function uE(e){return`_sort=`+e.map(e=>e.descending?`-`+e.code:e.code).join(`,`)}function dE(e,t){return e+(t.modifier?`:`+t.modifier:``)+`=`+t.resourceType+`:`+t.searchParam+(t.targetType?`:`+t.targetType:``)}function fE(e){let t=[],n=``,r=!1;for(let i of e)r?(n+=i,r=!1):i===`\\`?r=!0:i===`,`?(t.push(n),n=``):n+=i;return t.push(n),t}function pE(e,t){if(t.resourceType!==e.resourceType)return!1;for(let n of t.filters??iw)if(!hE(e,t,n))return!1;return!0}var mE=new Sx(1e3);function hE(e,t,n){let r=Uw.types[t.resourceType]?.searchParams?.[n.code];if(!r)return!1;let i=RT(r.expression,[AS(e)],void 0,mE);if(n.operator===Z.MISSING||n.operator===Z.PRESENT)return gE(i,n);switch(r.type){case`reference`:return _E(r,i,n);case`string`:case`uri`:return bE(i,n);case`token`:return vE(i,n);case`date`:return SE(i,n);default:return!1}}function gE(e,t){let n=e.length>0;return(t.operator===Z.MISSING&&t.value===`false`||t.operator===Z.PRESENT&&t.value===`true`)===n}function _E(e,t,n){let r=wE(n.operator);if(n.value===``&&t.length===0)return n.operator===Z.EQUALS;let i=VT(t);for(let t of fE(n.value)){let a=!1;if(t.includes(`/`)?a=i.includes(t):(e.target?.length===1||n.code===`_compartment`)&&(a=i.some(e=>e?.endsWith(`/`+t))),a)return!r}return r}function vE(e,t){let n=HT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let t of r)if(yE(e,t))return!i;return i}function yE(e,t){if(t.includes(`|`)){let[n,r]=t.split(`|`).map(e=>e.toLowerCase());return!n&&!r?!1:n?e.system?.toLowerCase()===n&&(!r||e.value?.toLowerCase()===r):!e.system&&e.value?.toLowerCase()===r}return e.value?.toLowerCase()===t.toLowerCase()}function bE(e,t){let n=BT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let t of r)if(xE(e,t))return!i;return i}function xE(e,t){return e.toLowerCase().includes(t.toLowerCase())}function SE(e,t){let n=zT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let n of r)if(CE(e,t.operator,n))return!i;return i}function CE(e,t,n){if(!e)return!1;let r=YS(n);if(!r)return!1;let i=e.start??`0000`,a=e.end??`9999`,o=r.start,s=r.end;switch(t){case Z.APPROXIMATELY:case Z.EQUALS:case Z.NOT_EQUALS:return i<s&&a>o;case Z.LESS_THAN:return i<o;case Z.GREATER_THAN:return a>s;case Z.LESS_THAN_OR_EQUALS:return i<=s;case Z.GREATER_THAN_OR_EQUALS:return a>=o;case Z.STARTS_AFTER:return i>s;case Z.ENDS_BEFORE:return a<o;default:return!1}}function wE(e){return e===Z.NOT_EQUALS||e===Z.NOT}var TE={resourceType:`*`},EE=[`DomainConfiguration`,`JsonWebKey`,`Login`],DE=[`Package`,`PackageRelease`,`PackageInstallation`,`Project`,`ProjectMembership`,`User`,`UserSecurityRequest`],OE={READ:`read`,VREAD:`vread`,UPDATE:`update`,DELETE:`delete`,HISTORY:`history`,CREATE:`create`,SEARCH:`search`},kE=[OE.READ,OE.VREAD,OE.HISTORY,OE.SEARCH];function AE(e,t){return EE.includes(t)?!1:jE(e,OE.UPDATE,t)}function jE(e,t,n){return!!e.resource?.some(e=>PE(e,n,t))}function ME(e,t,n){return n?n.resource?.find(n=>NE(e,t,n)):TE}function NE(e,t,n){let r=e.resourceType;return PE(n,r,t)?r===`Binary`?!0:!(n.compartment&&!e.meta?.compartment?.some(e=>e.reference===n.compartment?.reference)||n.criteria&&!pE(e,ZT(n.criteria))):!1}function PE(e,t,n){return e.resourceType!==t&&(e.resourceType!==`*`||DE.includes(t))?!1:e.interaction?e.interaction.includes(n):!e.readonly||kE.includes(n)}function FE(){return typeof window<`u`}function IE(){return typeof Buffer<`u`?Buffer:void 0}var LE={assign(e){FE()&&globalThis.location.assign(e)},reload(){FE()&&globalThis.location.reload()},getSearch(){return FE()?globalThis.location.search:``},getPathname(){return FE()?globalThis.location.pathname:``},getLocation(){return FE()?globalThis.location.toString():``},getOrigin(){return FE()?globalThis.location.protocol+`//`+globalThis.location.host+`/`:``}};function RE(e){if(FE()){let t=window.atob(e),n=Uint8Array.from(t,e=>e.codePointAt(0));return new window.TextDecoder().decode(n)}let t=IE();if(t)return t.from(e,`base64`).toString(`utf-8`);throw Error(`Unable to decode base64`)}function zE(e){if(FE()){let t=new window.TextEncoder().encode(e),n=String.fromCodePoint.apply(null,t);return window.btoa(n)}let t=IE();if(t)return t.from(e,`utf8`).toString(`base64`);throw Error(`Unable to encode base64`)}function BE(e){return e=e.padEnd(e.length+(4-e.length%4)%4,`=`),RE(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`))}function VE(){let e=new Uint32Array(28);return crypto.getRandomValues(e),zC(e.buffer)}async function HE(e){return crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))}function UE(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replaceAll(/[xy]/g,e=>{let t=Math.trunc(Math.random()*16);return(e===`x`?t:t&3|8).toString(16)})}function WE(e){let t={};e=jC(e);for(let n of e.entry??iw){let e=n.resource;if(!e)continue;e.meta!==void 0&&(delete e.meta.author,delete e.meta.compartment,delete e.meta.lastUpdated,delete e.meta.project,delete e.meta.versionId,Object.keys(e.meta).length===0&&delete e.meta);let r=e?.id;if(r)t[r]=UE(),n.fullUrl=`urn:uuid:`+t[r],delete n.resource?.id;else if(n.fullUrl?.startsWith(`resource:`)){let e=n.fullUrl.slice(9);t[e]=UE(),n.fullUrl=`urn:uuid:`+t[e]}}let n=e.entry,r=JSON.stringify({resourceType:`Bundle`,type:`transaction`,entry:n?.map(e=>({fullUrl:e.fullUrl,request:{method:`POST`,url:e.resource?.resourceType},resource:e.resource}))},(e,n)=>GE(e,n,t),2);return KE(JSON.parse(r))}function GE(e,t,n){if((e===`reference`||e===`url`)&&typeof t==`string`){let e;if(t.includes(`/`)?e=t.split(`/`)[1]:t.startsWith(`urn:uuid:`)||t.startsWith(`resource:`)?e=t.slice(9):t.startsWith(`#`)&&(e=t.slice(1)),e){let t=n[e];if(t)return`urn:uuid:`+t}}return t}function KE(e){let{sorted:t,cycles:n}=JE(XE(e)),r={},i=[];for(let t of e.entry??iw)t.fullUrl?r[t.fullUrl]=t:i.push(t);let a=t.map(e=>r[e]);for(let e of n)for(let t of e){let e=r[t],n={...e,request:{...e.request,method:`PUT`}};a.push(n)}return a.push(...i),{...e,entry:a}}var qE={NotVisited:`NotVisited`,Visiting:`Visiting`,Visited:`Visited`};function JE(e){let t=[],n={},r=[];for(let t of Object.keys(e))n[t]=qE.NotVisited;function i(a,o){if(n[a]===qE.Visited)return!0;if(n[a]===qE.Visiting){let e=o.lastIndexOf(a);return e!==-1&&r.push(o.slice(e)),!0}n[a]=qE.Visiting,o.push(a);let s=!1;for(let t of e[a]??iw)i(t,o)||(s=!0);return n[a]=qE.Visited,o.pop(),t.unshift(a),!s}for(let t in e)n[t]===qE.NotVisited&&i(t,[]);return{sorted:t,cycles:r}}function YE(e,t){for(let n in e)if(e[n]&&typeof e[n]==`object`){let r=e[n];if(Hw(r)){let e=r.reference;(e.startsWith(`urn:uuid:`)||e.startsWith(`resource:`))&&t(e)}else YE(r,t)}}function XE(e){let t={};for(let n of e.entry??iw)n.fullUrl&&(t[n.fullUrl]=[]);for(let n of e.entry??iw){let e=n.fullUrl;e&&n.resource&&YE(n.resource,n=>{n!==e&&t[n]&&t[n].push(e)})}return t}var ZE={CSS:`text/css`,DICOM:`application/dicom`,FAVICON:`image/vnd.microsoft.icon`,FHIR_JSON:`application/fhir+json`,FORM_URL_ENCODED:`application/x-www-form-urlencoded`,HL7_V2:`x-application/hl7-v2+er7`,HTML:`text/html`,JAVASCRIPT:`text/javascript`,JOSE:`application/jose`,JSON:`application/json`,JSON_PATCH:`application/json-patch+json`,JWT:`application/jwt`,MULTIPART_FORM_DATA:`multipart/form-data`,PNG:`image/png`,SCIM_JSON:`application/scim+json`,SVG:`image/svg+xml`,TEXT:`text/plain`,TYPESCRIPT:`text/typescript`,PING:`x-application/ping`,XML:`text/xml`,CDA_XML:`application/cda+xml`,OCTET_STREAM:`application/octet-stream`},QE=class{listeners;constructor(){this.listeners={}}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeEventListener(e,t){let n=this.listeners[e];if(n){for(let e=0;e<n.length;e++)if(n[e]===t){n.splice(e,1);return}}}dispatchEvent(e){let t=this.listeners[e.type];for(let n of t??iw)n.call(this,e);return!e.defaultPrevented}removeAllListeners(){this.listeners={}}listenerCount(e){return this.listeners[e]?.length??0}},$E=class{emitter=new QE;dispatchEvent(e){this.emitter.dispatchEvent(e)}addEventListener(e,t){this.emitter.addEventListener(e,t)}removeEventListener(e,t){this.emitter.removeEventListener(e,t)}removeAllListeners(){this.emitter.removeAllListeners()}listenerCount(e){return this.emitter.listenerCount(e)}},eD={"Patient-open":`Patient-open`,"Patient-close":`Patient-close`,"ImagingStudy-open":`ImagingStudy-open`,"ImagingStudy-close":`ImagingStudy-close`,"Encounter-open":`Encounter-open`,"Encounter-close":`Encounter-close`,"DiagnosticReport-open":`DiagnosticReport-open`,"DiagnosticReport-close":`DiagnosticReport-close`,"DiagnosticReport-select":`DiagnosticReport-select`,"DiagnosticReport-update":`DiagnosticReport-update`,syncerror:`syncerror`},tD=[`Patient`,`Encounter`,`ImagingStudy`,`DiagnosticReport`,`OperationOutcome`,`Bundle`],nD=[`DiagnosticReport-update`];function rD(e){return nD.includes(e)}function iD(e){if(nD.includes(e))throw new Xx(Wx(`'context.version' is required for '${e}'.`))}var aD={"Patient-open":{patient:{resourceType:`Patient`},encounter:{resourceType:`Encounter`,optional:!0}},"Patient-close":{patient:{resourceType:`Patient`},encounter:{resourceType:`Encounter`,optional:!0}},"ImagingStudy-open":{study:{resourceType:`ImagingStudy`},encounter:{resourceType:`Encounter`,optional:!0},patient:{resourceType:`Patient`,optional:!0}},"ImagingStudy-close":{study:{resourceType:`ImagingStudy`},encounter:{resourceType:`Encounter`,optional:!0},patient:{resourceType:`Patient`,optional:!0}},"Encounter-open":{encounter:{resourceType:`Encounter`},patient:{resourceType:`Patient`}},"Encounter-close":{encounter:{resourceType:`Encounter`},patient:{resourceType:`Patient`}},"DiagnosticReport-open":{report:{resourceType:`DiagnosticReport`},encounter:{resourceType:`Encounter`,optional:!0},study:{resourceType:`ImagingStudy`,optional:!0,manyAllowed:!0},patient:{resourceType:`Patient`}},"DiagnosticReport-close":{report:{resourceType:`DiagnosticReport`},encounter:{resourceType:`Encounter`,optional:!0},study:{resourceType:`ImagingStudy`,optional:!0,manyAllowed:!0},patient:{resourceType:`Patient`}},"DiagnosticReport-select":{report:{resourceType:`DiagnosticReport`,reference:!0},patient:{resourceType:`Patient`,optional:!0,reference:!0},select:{resourceType:`*`,reference:!0,manyAllowed:!0}},"DiagnosticReport-update":{report:{resourceType:`DiagnosticReport`,reference:!0},patient:{resourceType:`Patient`,optional:!0,reference:!0},updates:{resourceType:`Bundle`}},syncerror:{operationoutcome:{resourceType:`OperationOutcome`}}};function oD(e){return tD.includes(e)}function sD(e){return!!e.endpoint}function cD(e){if(!lD(e))throw new Xx(Wx(`subscriptionRequest must be an object conforming to SubscriptionRequest type.`));let{channelType:t,mode:n,topic:r,events:i}=e,a={"hub.channel.type":t,"hub.mode":n,"hub.topic":r,"hub.events":i.join(`,`)};return sD(e)&&(a.endpoint=e.endpoint),new URLSearchParams(a).toString()}function lD(e){if(typeof e!=`object`)return!1;let{channelType:t,mode:n,topic:r,events:i}=e;if(!(t&&n&&r&&i)||typeof r!=`string`||typeof i!=`object`||!Array.isArray(i)||i.length<1||t!==`websocket`||n!==`subscribe`&&n!==`unsubscribe`)return!1;for(let e of i)if(!eD[e])return!1;return!(sD(e)&&!(typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))}function uD(e,t,n,r){if(typeof t!=`object`)throw new Xx(Wx(`context[${n}] is invalid. Context must contain a single valid FHIR resource! Resource is not an object.`));if(!(t.id&&typeof t.id==`string`))throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a valid string ID.`));if(!t.resourceType)throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a resource type. No resource type found.`));let i=r.resourceType;if(i!==`*`){if(!oD(t.resourceType))throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a valid FHIRcast resource type. Resource type is not a known resource type.`));if(i&&t.resourceType!==i)throw new Xx(Wx(`context[${n}] is invalid. context[${n}] for the '${e}' event should contain resource of type ${i}.`))}}function dD(e,t,n,r,i){if(i.set(t.key,(i.get(t.key)??0)+1),r.reference){if(!Hw(t.reference))throw new Xx(Wx(`context[${n}] is invalid. Expected key '${t.key}' to be a reference.`))}else uD(e,t.resource,n,r)}function fD(e,t){let n=new Map,r=aD[e];for(let i=0;i<t.length;i++){let a=t[i].key;if(!r[a])throw new Xx(Wx(`Key '${a}' not found for event '${e}'. Make sure to add only valid keys.`));dD(e,t[i],i,r[a],n)}for(let[t,i]of Object.entries(r)){if(!(i.optional||n.has(t)))throw new Xx(Wx(`Missing required key '${t}' on context for '${e}' event.`));if(!i.manyAllowed&&(n.get(t)??0)>1)throw new Xx(Wx(`${n.get(t)} context entries with key '${t}' found for the '${e}' event when schema only allows for 1.`))}}function pD(e,t,n,r){if(!(e&&typeof e==`string`))throw new Xx(Wx(`Must provide a topic.`));if(!eD[t])throw new Xx(Wx(`Must provide a valid FHIRcast event name. Supported events: ${Object.keys(eD).join(`, `)}`));if(typeof n!=`object`)throw new Xx(Wx(`context must be a context object or array of context objects.`));if(nD.includes(t)&&!r)throw new Xx(Wx(`The '${t}' event must contain a 'context.versionId'.`));let i=Array.isArray(n)?n:[n];return fD(t,i),{timestamp:new Date().toISOString(),id:UE(),event:{"hub.topic":e,"hub.event":t,context:i,...r?{"context.versionId":r}:{}}}}var mD=class extends $E{subRequest;websocket;constructor(e){if(super(),this.subRequest=e,!e.endpoint)throw new Xx(Wx(`Subscription request should contain an endpoint.`));if(!lD(e))throw new Xx(Wx(`Subscription request failed validation.`));let t=new WebSocket(e.endpoint);t.addEventListener(`open`,()=>{this.dispatchEvent({type:`connect`}),t.addEventListener(`message`,e=>{let n=JSON.parse(e.data);if(n[`hub.topic`])return;let r=n;r.event[`hub.event`]!==`heartbeat`&&(this.dispatchEvent({type:`message`,payload:r}),t.send(JSON.stringify({id:n?.id,timestamp:new Date().toISOString()})))}),t.addEventListener(`close`,()=>{this.dispatchEvent({type:`disconnect`})})}),this.websocket=t}disconnect(){this.websocket.close()}};function hD(e){return JSON.parse(BE(e))}function gD(e){return e.split(`.`).length===3}function _D(e){let[t,n,r]=e.split(`.`);return hD(n)}function vD(e){try{return typeof _D(e).login_id==`string`}catch{return!1}}function yD(e){try{let t=_D(e).exp;return typeof t==`number`?t*1e3:void 0}catch{return}}var bD=class{medplum;constructor(e){this.medplum=e}async get(e){return this.medplum.get(`keyvalue/v1/${e}`)}async set(e,t){await this.medplum.put(`keyvalue/v1/${e}`,t,ZE.TEXT)}async delete(e){await this.medplum.delete(`keyvalue/v1/${e}`)}},xD=class{[Symbol.toStringTag]=`ReadablePromise`;suspender;status=`pending`;response;error;constructor(e){this.suspender=e.then(e=>(this.status=`success`,this.response=e,e),e=>{throw this.status=`error`,this.error=e,e})}isPending(){return this.status===`pending`}isOk(){return this.status===`success`}read(){switch(this.status){case`pending`:throw this.suspender;case`error`:throw this.error;default:return this.response}}then(e,t){return this.suspender.then(e,t)}catch(e){return this.suspender.catch(e)}finally(e){return this.suspender.finally(e)}},SD=class{storage;prefix=``;constructor(e,t=``){this.storage=e??globalThis.localStorage??new CD,this.prefix=t}makeKey(e){return this.prefix+e}clear(){this.storage===globalThis.localStorage&&this.prefix?Object.keys(this.storage).filter(e=>e.startsWith(this.prefix)).forEach(e=>{this.storage.removeItem(e)}):this.storage.clear()}getString(e){return this.storage.getItem(this.makeKey(e))??void 0}setString(e,t){t?this.storage.setItem(this.makeKey(e),t):this.storage.removeItem(this.makeKey(e))}getObject(e){let t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?vC(t):void 0)}},CD=class{data;constructor(){this.data=new Map}get length(){return this.data.size}clear(){this.data.clear()}getItem(e){return this.data.get(e)??null}setItem(e,t){t?this.data.set(e,t):this.data.delete(e)}removeItem(e){this.data.delete(e)}key(e){return Array.from(this.data.keys())[e]}},wD={Event:globalThis.Event===void 0?void 0:globalThis.Event,ErrorEvent:void 0,CloseEvent:void 0},TD=!1;function ED(){if(globalThis.Event===void 0)throw Error(`Unable to lazy init events for ReconnectingWebSocket. globalThis.Event is not defined yet`);wD.Event=globalThis.Event,wD.ErrorEvent=class extends Event{message;error;constructor(e,t){super(`error`,t),this.message=e.message,this.error=e}},wD.CloseEvent=class extends Event{code;reason;wasClean=!0;constructor(e=1e3,t=``,n){super(`close`,n),this.code=e,this.reason=t}}}function DD(e,t){if(!e)throw Error(t)}function OD(){}function kD(e){if(e instanceof wD.CloseEvent){let t=e;return new wD.CloseEvent(t.code,t.reason,void 0)}if(e instanceof wD.ErrorEvent){let t=e;return new wD.ErrorEvent(t.error??Error(t.message),void 0)}return new e.constructor(e.type,e)}function AD(e,t){let n=e;return n.error instanceof Error?new wD.ErrorEvent(n.error,t):new wD.ErrorEvent(Error(n.message||`WebSocket error`),t)}var jD={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},MD=!1,ND=class e extends $E{_ws;_retryCount=-1;_uptimeTimeout;_connectTimeout;_shouldReconnect=!0;_connectLock=!1;_binaryType;_closeCalled=!1;_messageQueue=[];_debugLogger=console.log.bind(console);_url;_protocols;_options;constructor(e,t,n={}){TD||=(ED(),!0),super(),this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._options.binaryType?this._binaryType=this._options.binaryType:this._binaryType=`blob`,this._options.debugLogger&&(this._debugLogger=this._options.debugLogger),this._connect()}static get CONNECTING(){return 0}static get OPEN(){return 1}static get CLOSING(){return 2}static get CLOSED(){return 3}get CONNECTING(){return e.CONNECTING}get OPEN(){return e.OPEN}get CLOSING(){return e.CLOSING}get CLOSED(){return e.CLOSED}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((e,t)=>(typeof t==`string`?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e),0)+(this._ws?.bufferedAmount??0)}get extensions(){return this._ws?.extensions??``}get protocol(){return this._ws?.protocol??``}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING}get url(){return this._ws?this._ws.url:``}get shouldReconnect(){return this._shouldReconnect}onclose=null;onerror=null;onmessage=null;onopen=null;close(e=1e3,t){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug(`close enqueued: no ws instance`);return}if(this._ws.readyState===this.CLOSED){this._debug(`close: already closed`);return}this._ws.close(e,t)}reconnect(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED||this._disconnect(e,t),this._connect()}send(e){if(this._ws?.readyState===this.OPEN)this._debug(`send`,e),this._ws.send(e);else{let{maxEnqueuedMessages:t=jD.maxEnqueuedMessages}=this._options;this._messageQueue.length<t&&(this._debug(`enqueue`,e),this._messageQueue.push(e))}}_debug(...e){this._options.debug&&this._debugLogger(`RWS>`,...e)}_getNextDelay(){let{reconnectionDelayGrowFactor:e=jD.reconnectionDelayGrowFactor,minReconnectionDelay:t=jD.minReconnectionDelay,maxReconnectionDelay:n=jD.maxReconnectionDelay}=this._options,r=0;return this._retryCount>0&&(r=t*e**(this._retryCount-1),r>n&&(r=n)),this._debug(`next delay`,r),r}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_connect(){if(this._connectLock||!this._shouldReconnect)return;this._connectLock=!0;let{maxRetries:e=jD.maxRetries,connectionTimeout:t=jD.connectionTimeout}=this._options;if(this._retryCount>=e){this._connectLock=!1,this._debug(`max retries reached`,this._retryCount,`>=`,e);return}this._retryCount++,this._debug(`connect`,this._retryCount),this._removeListeners(),this._wait().then(()=>{if(this._closeCalled){this._connectLock=!1;return}!this._options.WebSocket&&typeof WebSocket>`u`&&!MD&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket.`),MD=!0);let e=this._options.WebSocket||WebSocket;this._debug(`connect`,{url:this._url,protocols:this._protocols}),this._ws=this._protocols?new e(this._url,this._protocols):new e(this._url),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t)}).catch(e=>{this._connectLock=!1,this._handleError(new wD.ErrorEvent(Error(e.message),this))})}_handleTimeout(){this._debug(`timeout event`),this._handleError(new wD.ErrorEvent(Error(`TIMEOUT`),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),!this._ws)return;let n=this._ws;this._removeListeners(),n.addEventListener(`error`,OD);try{n.close(e,t),this._handleClose(new wD.CloseEvent(e,t,this))}catch{}}_acceptOpen(){this._debug(`accept open`),this._retryCount=0}_handleOpen=e=>{this._debug(`open event`);let{minUptime:t=jD.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),DD(this._ws,`WebSocket is not defined`),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(e=>this._ws?.send(e)),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent(kD(e))};_handleMessage=e=>{this._debug(`message event`),this.onmessage&&this.onmessage(e),this.dispatchEvent(kD(e))};_handleError=e=>{let t=AD(e,this);this._debug(`error event`,t.message),this._disconnect(void 0,t.message===`TIMEOUT`?`timeout`:void 0),this.onerror&&this.onerror(t),this._debug(`exec error listeners`),this.dispatchEvent(kD(t)),this._connect()};_handleClose=e=>{this._debug(`close event`),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(kD(e))};_removeListeners(){this._ws&&(this._debug(`removeListeners`),this._ws.removeEventListener(`open`,this._handleOpen),this._ws.removeEventListener(`close`,this._handleClose),this._ws.removeEventListener(`message`,this._handleMessage),this._ws.removeEventListener(`error`,this._handleError))}_addListeners(){this._ws&&(this._debug(`addListeners`),this._ws.addEventListener(`open`,this._handleOpen),this._ws.addEventListener(`close`,this._handleClose),this._ws.addEventListener(`message`,this._handleMessage),this._ws.addEventListener(`error`,this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}},PD=6e4,FD=[WebSocket.CLOSING,WebSocket.CLOSED],ID=class extends $E{criteria;constructor(...e){super(),this.criteria=new Set(e)}getCriteria(){return this.criteria}_addCriteria(e){this.criteria.add(e)}_removeCriteria(e){this.criteria.delete(e)}},LD=class{criteria;emitter;refCount;subscriptionProps;subscriptionId;token;tokenExpiry;state=`idle`;generation=0;lastUnrefTime;constructor(e,t){this.criteria=e,this.emitter=new ID(e),this.refCount=1,this.subscriptionProps=t?{...t}:void 0}nextGeneration(){return++this.generation}},RD=class{medplum;ws;masterSubEmitter;criteriaEntries;criteriaEntriesBySubscriptionId;wsClosed;pingTimer=void 0;tokenRefreshTimer=void 0;pingIntervalMs;waitingForPong=!1;currentProfile;constructor(e,t,n){if(!(e instanceof $D))throw new Xx(Wx("First arg of constructor should be a `MedplumClient`"));let r;try{r=new URL(t).toString()}catch{throw new Xx(Wx(`Not a valid URL`))}let i=n?.ReconnectingWebSocket?new n.ReconnectingWebSocket(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger}):new ND(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger});this.medplum=e,this.ws=i,this.masterSubEmitter=new ID,this.criteriaEntries=new Map,this.criteriaEntriesBySubscriptionId=new Map,this.wsClosed=!1,this.pingIntervalMs=n?.pingIntervalMs??5e3,this.currentProfile=e.getProfile(),this.setupListeners()}setupListeners(){let e=this.ws;e.addEventListener(`message`,e=>{try{let t=JSON.parse(e.data);if(t.type===`pong`){this.waitingForPong=!1;return}let n=t,r=n?.entry?.[0]?.resource;if(r.type===`heartbeat`){this.masterSubEmitter?.dispatchEvent({type:`heartbeat`,payload:n});return}if(r.type===`handshake`){let e=oC(r.subscription),t={type:`connect`,payload:{subscriptionId:e}};this.masterSubEmitter?.dispatchEvent(t);let n=this.criteriaEntriesBySubscriptionId.get(e);if(!n){console.warn(`Received handshake for criteria the SubscriptionManager is not listening for yet`);return}(n.state===`connecting`||n.state===`refreshing`)&&(n.state=`active`),n.emitter.dispatchEvent({...t});return}this.masterSubEmitter?.dispatchEvent({type:`message`,payload:n});let i=this.criteriaEntriesBySubscriptionId.get(oC(r.subscription));if(!i){console.warn(`Received notification for criteria the SubscriptionManager is not listening for`);return}i.emitter.dispatchEvent({type:`message`,payload:n})}catch(e){console.error(e);let t={type:`error`,payload:e};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t})}}),e.addEventListener(`error`,e=>{let t={type:`error`,payload:new Xx({resourceType:`OperationOutcome`,issue:[{severity:`error`,code:`exception`,details:{text:`WebSocket connection closed due to an error`},diagnostics:e.error?Y(e.error):e.message}]})};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t})}),e.addEventListener(`close`,()=>{let e={type:`close`};this.masterSubEmitter?.dispatchEvent(e);for(let t of this.getAllCriteriaEmitters())t.dispatchEvent({...e});this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=void 0,this.waitingForPong=!1),this.tokenRefreshTimer&&=(clearInterval(this.tokenRefreshTimer),void 0),this.wsClosed&&(this.criteriaEntries.clear(),this.criteriaEntriesBySubscriptionId.clear(),this.masterSubEmitter?.removeAllListeners())}),e.addEventListener(`open`,()=>{let t={type:`open`};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t});this.refreshAllSubscriptions().catch(console.error),this.pingTimer??=setInterval(()=>{this.waitingForPong?(this.waitingForPong=!1,e.reconnect()):(e.send(JSON.stringify({type:`ping`})),this.waitingForPong=!0),this.gcUnrefEntries()},this.pingIntervalMs),this.tokenRefreshTimer??=setInterval(()=>{this.checkTokenExpirations(),this.gcUnrefEntries()},PD)}),this.medplum.addEventListener(`change`,()=>{let e=this.medplum.getProfile();this.currentProfile&&e===void 0?this.ws.close():e&&this.currentProfile?.id!==e.id&&this.ws.reconnect(),this.currentProfile=e})}sendBind(e){this.ws.send(JSON.stringify({type:`bind-with-token`,payload:{token:e}}))}sendUnbind(e){this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:`unbind-from-token`,payload:{token:e}}))}emitError(e,t){let n={type:`error`,payload:t};this.masterSubEmitter?.dispatchEvent(n),e.emitter.dispatchEvent({...n})}maybeEmitDisconnect(e){let{subscriptionId:t}=e;if(t){let n={type:`disconnect`,payload:{subscriptionId:t}};this.masterSubEmitter?.dispatchEvent(n),e.emitter.dispatchEvent({...n})}else console.warn("Called disconnect for `CriteriaEntry` before `subscriptionId` was present.")}isStale(e,t){return this.isEntryGettingRemoved(e)||e.generation!==t}maybeGetCriteriaEntry(e,t){let n=this.criteriaEntries.get(e);if(n){if(!t)return n.bareCriteria;for(let e of n.criteriaWithProps)if(TC(t,e.subscriptionProps))return e}}getAllCriteriaEmitters(){let e=[];for(let t of this.criteriaEntries.values())for(let n of zD(t))n.refCount>0&&e.push(n.emitter);return e}addCriteriaEntry(e){let{criteria:t,subscriptionProps:n}=e,r;this.criteriaEntries.has(t)?r=this.criteriaEntries.get(t):(r={criteriaWithProps:[]},this.criteriaEntries.set(t,r)),n?r.criteriaWithProps.push(e):r.bareCriteria=e}removeCriteriaEntry(e){e.state=`removed`,e.generation++;let{criteria:t,subscriptionProps:n,subscriptionId:r,token:i}=e;if(!this.criteriaEntries.has(t))return;let a=this.criteriaEntries.get(t);n?a.criteriaWithProps=a.criteriaWithProps.filter(e=>{let t=e.subscriptionProps;return!TC(n,t)}):a.bareCriteria=void 0,!a.bareCriteria&&a.criteriaWithProps.length===0&&(this.criteriaEntries.delete(t),this.masterSubEmitter?._removeCriteria(t)),r&&this.criteriaEntriesBySubscriptionId.delete(r),i&&this.sendUnbind(i)}async subscribeToCriteria(e){this.wsClosed&&await this.reconnectIfNeeded(),this.ws.readyState===WebSocket.OPEN&&this.medplum.getProfile()&&e.state===`idle`&&(e.state=`connecting`,await this.rebindCriteriaEntry(e))}async refreshAllSubscriptions(){this.criteriaEntriesBySubscriptionId.clear();let e=[],t=[];for(let n of this.criteriaEntries.values())for(let r of zD(n))r.refCount===0?t.push(r):e.push(r);for(let e of t)this.removeCriteriaEntry(e);for(let t of e)t.token&&this.sendUnbind(t.token),t.token=void 0,t.tokenExpiry=void 0,t.subscriptionId=void 0,t.state=`idle`,t.generation++,await this.subscribeToCriteria(t)}async rebindCriteriaEntry(e){let t=e.nextGeneration();try{if(!e.subscriptionId){let n=await this.medplum.createResource({...e.subscriptionProps,resourceType:`Subscription`,status:`active`,reason:`WebSocket subscription for ${aC(this.medplum.getProfile())}`,channel:{type:`websocket`},criteria:e.criteria});if(e.subscriptionId??=n.id,this.isStale(e,t))return}let{parameter:n}=await this.medplum.get(`fhir/R4/Subscription/${e.subscriptionId}/$get-ws-binding-token`,{cache:`no-cache`}),r=n?.find(e=>e.name===`token`)?.valueString,i=n?.find(e=>e.name===`websocket-url`)?.valueUrl,a=n?.find(e=>e.name===`expiration`)?.valueDateTime;if(!r)throw new Xx(Wx(`Failed to get token`));if(!i)throw new Xx(Wx(`Failed to get URL from $get-ws-binding-token`));if(!a)throw new Xx(Wx(`Failed to get expiration from $get-ws-binding-token`));if(this.isStale(e,t))return;e.token=r,e.tokenExpiry=new Date(a).getTime(),this.criteriaEntriesBySubscriptionId.set(e.subscriptionId,e),this.sendBind(r)}catch(n){console.error(Y(n)),e.generation===t&&!this.isEntryGettingRemoved(e)&&(e.state=e.state===`refreshing`?`active`:`idle`),this.emitError(e,n)}}checkTokenExpirations(){if(!this.medplum.getProfile())return;let e=Date.now();for(let t of this.criteriaEntries.values())for(let n of zD(t))n.refCount===0||!n.tokenExpiry||n.tokenExpiry-e<=3e5&&n.state===`active`&&this.ws.readyState===WebSocket.OPEN&&(n.state=`refreshing`,this.rebindCriteriaEntry(n).catch(e=>{this.masterSubEmitter?.dispatchEvent({type:`error`,payload:e})}))}addCriteria(e,t){this.masterSubEmitter&&this.masterSubEmitter._addCriteria(e);let n=this.maybeGetCriteriaEntry(e,t);if(n)return n.refCount===0&&(n.lastUnrefTime=void 0,n.generation++,n.state!==`active`&&(n.state=n.token?`active`:`idle`)),n.refCount+=1,n.state===`idle`&&this.subscribeToCriteria(n).catch(console.error),n.emitter;let r=new LD(e,t);return this.addCriteriaEntry(r),this.subscribeToCriteria(r).catch(console.error),r.emitter}removeCriteria(e,t){let n=this.maybeGetCriteriaEntry(e,t);if(!n||this.isEntryGettingRemoved(n)){console.warn("Criteria not known to `SubscriptionManager`. Possibly called remove too many times.");return}--n.refCount,n.refCount===0&&(n.lastUnrefTime=Date.now(),n.generation++)}gcUnrefEntries(){let e=Date.now(),t=[];for(let n of this.criteriaEntries.values())for(let r of zD(n))r.refCount===0&&r.lastUnrefTime!==void 0&&e-r.lastUnrefTime>=1e4&&t.push(r);for(let e of t)this.maybeEmitDisconnect(e),this.removeCriteriaEntry(e);t.length>0&&this.criteriaEntries.size===0&&this.closeWebSocket()}isEntryGettingRemoved(e){return e.refCount===0||e.state===`removed`}getWebSocket(){return this.ws}closeWebSocket(){if(!this.wsClosed){if(this.ws.readyState===WebSocket.OPEN)for(let e of this.criteriaEntries.values())for(let t of zD(e))t.token&&this.sendUnbind(t.token);this.wsClosed=!0,this.ws.close()}}reconnectWebSocket(){this.ws.reconnect(),this.wsClosed=!1}getCriteriaCount(){return this.getAllCriteriaEmitters().length}getMasterEmitter(){return this.masterSubEmitter||=new ID(...Array.from(this.criteriaEntries.keys())),this.masterSubEmitter}async reconnectIfNeeded(){FD.includes(this.getWebSocket().readyState)&&await new Promise(e=>{let t=()=>{this.getWebSocket().removeEventListener(`open`,t),e()};this.getWebSocket().addEventListener(`open`,t),this.reconnectWebSocket()})}};function zD(e){return e.bareCriteria?[e.bareCriteria,...e.criteriaWithProps]:e.criteriaWithProps}new Sx(1e3);var BD=`5.1.25-68648ed`,VD=ZE.FHIR_JSON+`, */*; q=0.1`,HD=`https://api.medplum.com/`,UD=1e3,WD=6e4,GD=0,KD=3e5,qD=`Binary/`,JD={resourceType:`Device`,id:`system`,deviceName:[{type:`model-name`,name:`System`}]},YD=2,XD={ClientCredentials:`client_credentials`,AuthorizationCode:`authorization_code`,RefreshToken:`refresh_token`,JwtBearer:`urn:ietf:params:oauth:grant-type:jwt-bearer`,TokenExchange:`urn:ietf:params:oauth:grant-type:token-exchange`,PreAuthorizedCode:`urn:ietf:params:oauth:grant-type:pre-authorized_code`},ZD={AccessToken:`urn:ietf:params:oauth:token-type:access_token`,RefreshToken:`urn:ietf:params:oauth:token-type:refresh_token`,IdToken:`urn:ietf:params:oauth:token-type:id_token`,Saml1Token:`urn:ietf:params:oauth:token-type:saml1`,Saml2Token:`urn:ietf:params:oauth:token-type:saml2`},QD={JwtBearer:`urn:ietf:params:oauth:client-assertion-type:jwt-bearer`},$D=class extends $E{options;fetch;createPdfImpl;storage;requestCache;cacheTime;baseUrl;fhirBaseUrl;authorizeUrl;tokenUrl;logoutUrl;fhircastHubUrl;cdsServicesUrl;defaultHeaders;onUnauthenticated;autoBatchTime;autoBatchQueue;maxRetries;maxRetryTime;refreshGracePeriod;subscriptionManager;medplumServer;clientId;clientSecret;credentialsInHeader;autoBatchTimerId;accessToken;accessTokenExpires;refreshToken;refreshPromise;profilePromise;sessionDetails;currentRateLimits;basicAuth;initPromise;initComplete=!0;keyValueClient;logLevel;constructor(e){if(super(),e?.baseUrl&&!e.baseUrl.startsWith(`http`))throw Error(`Base URL must start with http or https`);this.options=e??{},this.fetch=e?.fetch??eO(),this.storage=e?.storage??new SD(void 0,e?.storagePrefix),this.createPdfImpl=e?.createPdf,this.baseUrl=ZC(e?.baseUrl??HD),this.fhirBaseUrl=$C(this.baseUrl,e?.fhirUrlPath??`fhir/R4`),this.authorizeUrl=$C(this.baseUrl,e?.authorizeUrl??`oauth2/authorize`),this.tokenUrl=$C(this.baseUrl,e?.tokenUrl??`oauth2/token`),this.logoutUrl=$C(this.baseUrl,e?.logoutUrl??`oauth2/logout`),this.fhircastHubUrl=$C(this.baseUrl,e?.fhircastHubUrl??`fhircast/STU3`),this.cdsServicesUrl=$C(this.baseUrl,e?.cdsServicesUrl??`cds-services`),this.clientId=e?.clientId??``,this.clientSecret=e?.clientSecret??``,this.credentialsInHeader=e?.authCredentialsMethod===`header`,this.defaultHeaders=e?.defaultHeaders??{},this.onUnauthenticated=e?.onUnauthenticated,this.refreshGracePeriod=e?.refreshGracePeriod??KD,this.logLevel=this.initializeLogLevel(e),this.maxRetries=e?.maxRetries??2,this.maxRetryTime=e?.maxRetryTime??2e3,this.cacheTime=e?.cacheTime??(FE()?WD:GD),this.cacheTime>0?this.requestCache=new Sx(e?.resourceCacheSize??UD):this.requestCache=void 0,e?.autoBatchTime?(this.autoBatchTime=e.autoBatchTime,this.autoBatchQueue=[]):(this.autoBatchTime=0,this.autoBatchQueue=void 0),e?.accessToken&&this.setAccessToken(e.accessToken),this.storage.getInitPromise===void 0?(e?.accessToken||this.attemptResumeActiveLogin().catch(console.error),this.initPromise=Promise.resolve(),this.dispatchEvent({type:`storageInitialized`})):(this.initComplete=!1,this.initPromise=this.storage.getInitPromise(),this.initPromise.then(()=>{e?.accessToken||this.attemptResumeActiveLogin().catch(console.error),this.initComplete=!0,this.dispatchEvent({type:`storageInitialized`})}).catch(e=>{console.error(e),this.initComplete=!0,this.dispatchEvent({type:`storageInitFailed`,payload:{error:e}})})),this.setupStorageListener()}get isInitialized(){return this.initComplete}getInitPromise(){return this.initPromise}initializeLogLevel(e){return e?.logLevel?e.logLevel:e?.verbose===void 0?`none`:e.verbose?`verbose`:`none`}async attemptResumeActiveLogin(){let e=this.getActiveLogin();e&&(this.setAccessToken(e.accessToken,e.refreshToken),await this.refreshProfile())}getBaseUrl(){return this.baseUrl}getAuthorizeUrl(){return this.authorizeUrl}getTokenUrl(){return this.tokenUrl}getLogoutUrl(){return this.logoutUrl}getFhircastHubUrl(){return this.fhircastHubUrl}getCdsServicesUrl(){return this.cdsServicesUrl}getDefaultHeaders(){return this.defaultHeaders}clear(){this.storage.clear(),this.clearActiveLogin()}clearActiveLogin(){this.storage.setString(`activeLogin`,void 0),this.requestCache?.clear(),this.accessToken=void 0,this.refreshToken=void 0,this.refreshPromise=void 0,this.accessTokenExpires=void 0,this.sessionDetails=void 0,this.medplumServer=void 0,this.dispatchEvent({type:`change`})}invalidateUrl(e){e=e.toString(),this.requestCache?.delete(e)}invalidateAll(){this.requestCache?.clear()}invalidateSearches(e){let t=$C(this.fhirBaseUrl,e);for(let e of this.requestCache?.keys()??iw)(e.endsWith(t)||e.includes(t+`?`))&&this.requestCache?.delete(e)}get(e,t={}){e=e.toString();let n=this.getCacheEntry(e,t);if(n)return n.value;let r;e.startsWith(this.fhirBaseUrl)&&this.autoBatchQueue&&!t.disableAutoBatch?r=new Promise((n,r)=>{this.autoBatchQueue.push({method:`GET`,url:e.replace(this.fhirBaseUrl,``),options:t,resolve:n,reject:r}),this.autoBatchTimerId||=setTimeout(()=>this.executeAutoBatch(),this.autoBatchTime)}):(t.method=`GET`,r=this.request(e,t));let i=new xD(r);return this.setCacheEntry(e,i,t),i}post(e,t,n,r={}){return e=e.toString(),this.setRequestBody(r,t),n&&this.setRequestContentType(r,n),this.invalidateUrl(e),r.method=`POST`,this.request(e,r)}put(e,t,n,r={}){return e=e.toString(),this.setRequestBody(r,t),n&&this.setRequestContentType(r,n),this.invalidateUrl(e),r.method=`PUT`,this.request(e,r)}patch(e,t,n={}){return e=e.toString(),this.setRequestBody(n,t),this.setRequestContentType(n,ZE.JSON_PATCH),this.invalidateUrl(e),n.method=`PATCH`,this.request(e,n)}delete(e,t={}){return e=e.toString(),this.invalidateUrl(e),t.method=`DELETE`,this.request(e,t)}async startNewUser(e,t){let{codeChallengeMethod:n,codeChallenge:r}=await this.startPkce();return this.post(`auth/newuser`,{...e,clientId:e.clientId??this.clientId,codeChallengeMethod:n,codeChallenge:r},void 0,t)}async startNewProject(e,t){return this.post(`auth/newproject`,e,void 0,t)}async startNewPatient(e,t){return this.post(`auth/newpatient`,e,void 0,t)}async startLogin(e,t){return this.post(`auth/login`,{...await this.ensureCodeChallenge(e),clientId:e.clientId??this.clientId,scope:e.scope},void 0,t)}async startGoogleLogin(e,t){return this.post(`auth/google`,{...await this.ensureCodeChallenge(e),clientId:e.clientId??this.clientId,scope:e.scope},void 0,t)}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(this.logoutUrl,{}),this.clear()}async signInWithRedirect(e){let t=new URLSearchParams(LE.getSearch()).get(`code`);if(!t){await this.requestAuthorization(e);return}return this.processCode(t)}signOutWithRedirect(){LE.assign(this.logoutUrl)}async signInWithExternalAuth(e,t,n,r,i=!0){let a=r;i&&(a=await this.ensureCodeChallenge(r)),LE.assign(this.getExternalAuthRedirectUri(e,t,n,a,i))}async exchangeExternalAccessToken(e,t,n){if(t??=this.clientId,!t)throw Error(`MedplumClient is missing clientId`);let r={grant_type:XD.TokenExchange,subject_token_type:ZD.AccessToken,client_id:t,subject_token:e};return n&&(r.membership_id=n),this.fetchTokens(r)}getExternalAuthRedirectUri(e,t,n,r,i=!0){let a=new URL(e);if(a.searchParams.set(`response_type`,`code`),a.searchParams.set(`client_id`,t),a.searchParams.set(`redirect_uri`,n),a.searchParams.set(`scope`,r.scope??`openid profile email`),a.searchParams.set(`state`,JSON.stringify(r)),i){let{codeChallenge:e,codeChallengeMethod:t}=r;if(!t)throw Error("`LoginRequest` for external auth must include a `codeChallengeMethod`.");if(!e)throw Error("`LoginRequest` for external auth must include a `codeChallenge`.");a.searchParams.set(`code_challenge_method`,t),a.searchParams.set(`code_challenge`,e)}return a.toString()}fhirUrl(...e){return new URL($C(this.fhirBaseUrl,e.join(`/`)))}fhirSearchUrl(e,t){let n=this.fhirUrl(e);return t&&(n.search=tw(t)),n}search(e,t,n){let r=this.fhirSearchUrl(e,t),i=`search-`+r.toString(),a=this.getCacheEntry(i,n);if(a)return a.value;let o=this.getBundle(r,n);return this.setCacheEntry(i,o,n),o}searchOne(e,t,n){let r=this.fhirSearchUrl(e,t);r.searchParams.set(`_count`,`1`),r.searchParams.sort();let i=`searchOne-`+r.toString(),a=this.getCacheEntry(i,n);if(a)return a.value;let o=new xD(this.search(e,r.searchParams,n).then(e=>e.entry?.[0]?.resource));return this.setCacheEntry(i,o,n),o}searchResources(e,t,n){let r=`searchResources-`+this.fhirSearchUrl(e,t).toString(),i=this.getCacheEntry(r,n);if(i)return i.value;let a=new xD(this.search(e,t,n).then(nO));return this.setCacheEntry(r,a,n),a}async*searchResourcePages(e,t,n){let r=this.fhirSearchUrl(e,t);for(;r;){let t=new URL(r).searchParams;t.has(`_count`)||t.set(`_count`,`1000`);let i=await this.search(e,t,n),a=i.link?.find(e=>e.relation===`next`);if(!i.entry?.length&&!a)break;yield nO(i),r=a?.url?new URL(a.url):void 0}}valueSetExpand(e,t){let n=this.fhirUrl(`ValueSet`,`$expand`);return n.search=new URLSearchParams(e).toString(),this.get(n.toString(),t)}getCached(e,t){let n=this.requestCache?.get(this.fhirUrl(e,t).toString())?.value;return n?.isOk()?n.read():void 0}getCachedReference(e){let t=e.reference;if(!t)return;if(t===`system`)return JD;let[n,r]=t.split(`/`);if(!(!n||!r))return this.getCached(n,r)}readResource(e,t,n){if(!t)throw Error(`The "id" parameter cannot be null, undefined, or an empty string.`);return this.get(this.fhirUrl(e,t),n)}readReference(e,t){let n=e.reference;if(!n)return new xD(Promise.reject(Error(`Missing reference`)));if(n===`system`)return new xD(Promise.resolve(JD));let[r,i]=n.split(`/`);return!r||!i?new xD(Promise.reject(Error(`Invalid reference`))):this.readResource(r,i,t)}readCanonical(e,t,n){return Array.isArray(e)?this.searchOne(``,{_type:e.join(`,`),url:t},n):this.searchOne(e,`url=`+t,n)}requestSchema(e,t){if(dS(e))return Promise.resolve();let n=e+`-requestSchema`,r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new xD((async()=>{let t=`{
|
|
56
|
+
`?(this.pos.line++,this.pos.column=0):this.pos.column++}buildToken(e,t){let n=this.markStack.pop();if(!n)throw Error(`No mark for token`);return{id:e,value:t,...n}}};function TT(e){return!!(e&&(e.id===`String`||e.id===`Symbol`&&ST.includes(e.value)))}var ET=[`true`,`false`],DT=[`!=`,`!~`,`<=`,`>=`,`{}`,`->`];function OT(e){return new wT(e,ET,DT).tokenize()}var kT={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},AT={parse(e){let t=e.consumeAndParse();if(!e.match(`)`))throw Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},jT={parse(e,t){let n=e.consumeAndParse();if(!e.match(`]`))throw Error("Parse error: expected `]`");return new xT(t,n)},precedence:kT.Indexer},MT={parse(e,t){if(!(t instanceof eT))throw Error(`Unexpected parentheses`);let n=[];for(;!e.match(`)`);)n.push(e.consumeAndParse()),e.match(`,`);return new bT(t.name,n)},precedence:kT.FunctionCall};function NT(e){let t=e.split(` `),n=Number.parseFloat(t[0]),r=t[1];return r=r?.startsWith(`'`)&&r.endsWith(`'`)?r.substring(1,r.length-1):`{`+r+`}`,{value:n,unit:r}}function PT(){return new Tx().registerPrefix(`String`,{parse:(e,t)=>new $w({type:X.string,value:t.value})}).registerPrefix(`DateTime`,{parse:(e,t)=>new $w({type:X.dateTime,value:Ww(t.value)})}).registerPrefix(`Quantity`,{parse:(e,t)=>new $w({type:X.Quantity,value:NT(t.value)})}).registerPrefix(`Number`,{parse:(e,t)=>new $w({type:t.value.includes(`.`)?X.decimal:X.integer,value:Number.parseFloat(t.value)})}).registerPrefix(`true`,{parse:()=>new $w({type:X.boolean,value:!0})}).registerPrefix(`false`,{parse:()=>new $w({type:X.boolean,value:!1})}).registerPrefix(`Symbol`,{parse:(e,t)=>new eT(t.value)}).registerPrefix(`{}`,{parse:()=>new tT}).registerPrefix(`(`,AT).registerInfix(`[`,jT).registerInfix(`(`,MT).prefix(`+`,kT.UnaryAdd,(e,t)=>new nT(`+`,t,e=>e)).prefix(`-`,kT.UnarySubtract,(e,t)=>new iT(`-`,t,t,(e,t)=>-t)).infixLeft(`.`,kT.Dot,(e,t,n)=>new lT(e,n)).infixLeft(`/`,kT.Divide,(e,t,n)=>new iT(`/`,e,n,(e,t)=>e/t)).infixLeft(`*`,kT.Multiply,(e,t,n)=>new iT(`*`,e,n,(e,t)=>e*t)).infixLeft(`+`,kT.Add,(e,t,n)=>new iT(`+`,e,n,(e,t)=>e+t)).infixLeft(`-`,kT.Subtract,(e,t,n)=>new iT(`-`,e,n,(e,t)=>e-t)).infixLeft(`|`,kT.Union,(e,t,n)=>new uT(e,n)).infixLeft(`=`,kT.Equals,(e,t,n)=>new dT(e,n)).infixLeft(`!=`,kT.NotEquals,(e,t,n)=>new fT(e,n)).infixLeft(`~`,kT.Equivalent,(e,t,n)=>new pT(e,n)).infixLeft(`!~`,kT.NotEquivalent,(e,t,n)=>new mT(e,n)).infixLeft(`<`,kT.LessThan,(e,t,n)=>new iT(`<`,e,n,(e,t)=>e<t)).infixLeft(`<=`,kT.LessThanOrEquals,(e,t,n)=>new iT(`<=`,e,n,(e,t)=>e<=t)).infixLeft(`>`,kT.GreaterThan,(e,t,n)=>new iT(`>`,e,n,(e,t)=>e>t)).infixLeft(`>=`,kT.GreaterThanOrEquals,(e,t,n)=>new iT(`>=`,e,n,(e,t)=>e>=t)).infixLeft(`&`,kT.Ampersand,(e,t,n)=>new oT(e,n)).infixLeft(`and`,kT.And,(e,t,n)=>new gT(e,n)).infixLeft(`as`,kT.As,(e,t,n)=>new rT(e,n)).infixLeft(`contains`,kT.Contains,(e,t,n)=>new sT(e,n)).infixLeft(`div`,kT.Divide,(e,t,n)=>new iT(`div`,e,n,(e,t)=>Math.trunc(e/t))).infixLeft(`in`,kT.In,(e,t,n)=>new cT(e,n)).infixLeft(`is`,kT.Is,(e,t,n)=>new hT(e,n)).infixLeft(`mod`,kT.Modulo,(e,t,n)=>new iT(`mod`,e,n,(e,t)=>e%t)).infixLeft(`or`,kT.Or,(e,t,n)=>new _T(e,n)).infixLeft(`xor`,kT.Xor,(e,t,n)=>new vT(e,n)).infixLeft(`implies`,kT.Implies,(e,t,n)=>new yT(e,n))}var FT=PT();function IT(e){return new Qw(e,FT.construct(OT(e)).consumeAndParse())}function LT(e,t,n={},r=void 0){let i=Array.isArray(t)?t:[t];for(let e=0;e<i.length;e++){let t=i[e];typeof t==`object`&&`type`in t&&`value`in t||(i[e]=AS(i[e]))}return RT(e,i,n,r).map(e=>e.value)}function RT(e,t,n={},r=void 0){let i;if(typeof e==`string`){let t=r?.get(e);i=t??IT(e),r&&!t&&r.set(e,i)}else i=e;return i.eval({variables:n},t).map(e=>{let t={type:e.type,value:e.value?.valueOf()};return`path`in e&&(t.path=e.path),t})}function zT(e){let t=[];for(let n of e){let e=YS(n.value);e&&t.push(e)}return t}function BT(e){let t=new Set;for(let n of e){let e=aw(n);e&&t.add(e)}return Array.from(t)}function VT(e){let t=new Set;for(let n of e){let{value:e}=n;e&&(PC(e)?t.add(e):Hw(e)?t.add(e.reference):rC(e)?t.add(aC(e)):typeof e.identifier==`object`&&t.add(`identifier:${e.identifier.system}|${e.identifier.value}`))}return Array.from(t)}function HT(e,t={}){let n=[];for(let r of e)UT(t,n,r);return n}function UT(e,t,n){let{type:r,value:i}=n;switch(r){case X.Identifier:WT(t,e,i);break;case X.CodeableConcept:GT(t,e,i);break;case X.Coding:KT(t,e,i);break;case X.ContactPoint:qT(t,e,i);break;default:JT(t,e,void 0,i?.toString())}}function WT(e,t,n){n?.type?.text&&JT(e,t,t.textSearchSystem,n.type.text),JT(e,t,n?.system,n?.value)}function GT(e,t,n){n?.text&&JT(e,t,t.textSearchSystem,n.text);for(let r of n?.coding??iw)KT(e,t,r)}function KT(e,t,n){n&&(n.display&&JT(e,t,t.textSearchSystem,n.display),JT(e,t,n.system,n.code))}function qT(e,t,n){n&&JT(e,t,n.system,n.value?.toLocaleLowerCase())}function JT(e,t,n,r){(n||r)&&!e.some(e=>e.system===n&&e.value===r)&&e.push({system:n,value:r&&t.caseInsensitive?r.toLocaleLowerCase():r})}var Z={EQUALS:`eq`,NOT_EQUALS:`ne`,GREATER_THAN:`gt`,LESS_THAN:`lt`,GREATER_THAN_OR_EQUALS:`ge`,LESS_THAN_OR_EQUALS:`le`,STARTS_AFTER:`sa`,ENDS_BEFORE:`eb`,APPROXIMATELY:`ap`,CONTAINS:`contains`,STARTS_WITH:`sw`,EXACT:`exact`,TEXT:`text`,NOT:`not`,ABOVE:`above`,BELOW:`below`,IN:`in`,NOT_IN:`not-in`,OF_TYPE:`of-type`,MISSING:`missing`,PRESENT:`present`,IDENTIFIER:`identifier`,ITERATE:`iterate`},YT={contains:Z.CONTAINS,exact:Z.EXACT,above:Z.ABOVE,below:Z.BELOW,text:Z.TEXT,not:Z.NOT,in:Z.IN,"not-in":Z.NOT_IN,"of-type":Z.OF_TYPE,missing:Z.MISSING,identifier:Z.IDENTIFIER,iterate:Z.ITERATE},XT={eq:Z.EQUALS,ne:Z.NOT_EQUALS,lt:Z.LESS_THAN,le:Z.LESS_THAN_OR_EQUALS,gt:Z.GREATER_THAN,ge:Z.GREATER_THAN_OR_EQUALS,sa:Z.STARTS_AFTER,eb:Z.ENDS_BEFORE,ap:Z.APPROXIMATELY,sw:Z.STARTS_WITH};function ZT(e,t){if(!e)throw Error(`Invalid search URL`);let n=``,r;if(typeof e==`string`)if(e.includes(`?`)){let[t,i]=e.split(`?`);n=t,r=new URLSearchParams(i)}else n=e;else typeof e==`object`&&(n=e.pathname,r=e.searchParams);let i;i=n.includes(`/`)?n.split(`/`).filter(Boolean).pop():n;let a=[];if(r&&a.push(...r.entries()),t)for(let[e,n]of Object.entries(t))if(Array.isArray(n))for(let t of n)a.push([e,t]);else a.push([e,n??``]);return QT(i,a)}function QT(e,t){let n={resourceType:e};for(let[e,r]of t)$T(n,e,r);return n}function $T(e,t,n){let r,i,a=t.indexOf(`:`);if(a>=0?(r=t.substring(0,a),i=t.substring(a+1)):(r=t,i=``),r!==`_`){if(r===`_has`||t.includes(`.`)){e.filters=YC(e.filters,{code:t,operator:Z.EQUALS,value:n});return}switch(r){case`_sort`:eE(e,n);break;case`_cursor`:e.cursor=n;break;case`_count`:e.count=Number.parseInt(n,10);break;case`_offset`:e.offset=Number.parseInt(n,10);break;case`_total`:e.total=n;break;case`_summary`:n===`count`?(e.total=`accurate`,e.count=0):(n===`true`||n===`data`||n===`text`)&&(e.summary=n);break;case`_include`:{let t=oE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.include=YC(e.include,t);break}case`_revinclude`:{let t=oE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.revInclude=YC(e.revInclude,t);break}case`_fields`:case`_elements`:e.fields=n.split(`,`);break;case`_type`:e.types=n.split(`,`);break;case`_format`:e.format=n;break;case`_pretty`:e.pretty=n===`true`;break;default:{let t=Uw.types[e.resourceType]?.searchParams?.[r];t?e.filters=YC(e.filters,nE(t,Z.EQUALS,i,n)):e.filters=YC(e.filters,rE(r,i,n))}}}}function eE(e,t){for(let n of t.split(`,`)){let t,r=!1;n.startsWith(`-`)?(t=n.substring(1),r=!0):t=n,e.sortRules||=[],e.sortRules.push({code:t,descending:r})}}var tE=[Z.MISSING,Z.PRESENT];function nE(e,t,n,r){if(tE.includes(n||t))return{code:e.code,operator:n||t,value:r};switch(e.type){case`number`:case`date`:case`quantity`:{let{operator:t,value:i}=iE(r,n||Z.EQUALS);if(!sE(e,i))throw new Xx(Ux(`Invalid format for ${e.type} search parameter: ${i}`));return{code:e.code,operator:t,value:i}}case`reference`:case`string`:case`token`:case`uri`:if(!sE(e,r))throw new Xx(Ux(`Invalid format for ${e.type} search parameter: ${r}`));return{code:e.code,operator:aE(n)??t,value:r};default:throw Error(`Unrecognized search parameter type: `+e.type)}}function rE(e,t,n){let r=Z.EQUALS;if(t)r=t;else if(n.length>=2){let e=n.substring(0,2);e in XT&&(n.length===2||n.at(2)?.match(/\d/))&&(r=e,n=n.substring(e.length))}return{code:e,operator:r,value:n}}function iE(e,t){let n=XT[e.substring(0,2)];return n?{operator:n,value:e.substring(2)}:{operator:t,value:e}}function aE(e){return YT[e]}function oE(e){let t=e.split(`:`);if(t.includes(`*`))throw new Xx(Ux(`'*' is not supported as a value for search inclusion parameters`));if(t.length===1)throw new Xx(Ux(`Invalid include value '${e}': must be of the form ResourceType:search-parameter`));if(t.length===2)return{resourceType:t[0],searchParam:t[1]};if(t.length===3)return{resourceType:t[0],searchParam:t[1],targetType:t[2]};throw new Xx(Ux(`Invalid include value '${e}'`))}function sE(e,t){switch(e.type){case`date`:return qS(t);default:return!0}}function cE(e){let t=[];e.fields&&t.push(`_fields=`+e.fields.join(`,`));for(let n of e.filters??iw)t.push(lE(n));e.sortRules&&e.sortRules.length>0&&t.push(uE(e.sortRules)),e.cursor!==void 0&&t.push(`_cursor=`+encodeURIComponent(e.cursor)),e.offset!==void 0&&e.offset!==0&&t.push(`_offset=`+e.offset),e.count!==void 0&&t.push(`_count=`+e.count),e.total!==void 0&&t.push(`_total=`+e.total),e.types&&e.types.length>0&&t.push(`_type=`+e.types.join(`,`));for(let n of e.include??iw)t.push(dE(`_include`,n));for(let n of e.revInclude??iw)t.push(dE(`_revinclude`,n));return t.length===0?``:(XC(t),`?`+t.join(`&`))}function lE(e){let t=e.operator in YT?`:`+e.operator:``,n=e.operator!==Z.EQUALS&&e.operator in XT?e.operator:``;return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}function uE(e){return`_sort=`+e.map(e=>e.descending?`-`+e.code:e.code).join(`,`)}function dE(e,t){return e+(t.modifier?`:`+t.modifier:``)+`=`+t.resourceType+`:`+t.searchParam+(t.targetType?`:`+t.targetType:``)}function fE(e){let t=[],n=``,r=!1;for(let i of e)r?(n+=i,r=!1):i===`\\`?r=!0:i===`,`?(t.push(n),n=``):n+=i;return t.push(n),t}function pE(e,t){if(t.resourceType!==e.resourceType)return!1;for(let n of t.filters??iw)if(!hE(e,t,n))return!1;return!0}var mE=new Sx(1e3);function hE(e,t,n){let r=Uw.types[t.resourceType]?.searchParams?.[n.code];if(!r)return!1;let i=RT(r.expression,[AS(e)],void 0,mE);if(n.operator===Z.MISSING||n.operator===Z.PRESENT)return gE(i,n);switch(r.type){case`reference`:return _E(r,i,n);case`string`:case`uri`:return bE(i,n);case`token`:return vE(i,n);case`date`:return SE(i,n);default:return!1}}function gE(e,t){let n=e.length>0;return(t.operator===Z.MISSING&&t.value===`false`||t.operator===Z.PRESENT&&t.value===`true`)===n}function _E(e,t,n){let r=wE(n.operator);if(n.value===``&&t.length===0)return n.operator===Z.EQUALS;let i=VT(t);for(let t of fE(n.value)){let a=!1;if(t.includes(`/`)?a=i.includes(t):(e.target?.length===1||n.code===`_compartment`)&&(a=i.some(e=>e?.endsWith(`/`+t))),a)return!r}return r}function vE(e,t){let n=HT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let t of r)if(yE(e,t))return!i;return i}function yE(e,t){if(t.includes(`|`)){let[n,r]=t.split(`|`).map(e=>e.toLowerCase());return!n&&!r?!1:n?e.system?.toLowerCase()===n&&(!r||e.value?.toLowerCase()===r):!e.system&&e.value?.toLowerCase()===r}return e.value?.toLowerCase()===t.toLowerCase()}function bE(e,t){let n=BT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let t of r)if(xE(e,t))return!i;return i}function xE(e,t){return e.toLowerCase().includes(t.toLowerCase())}function SE(e,t){let n=zT(e),r=fE(t.value),i=wE(t.operator);for(let e of n)for(let n of r)if(CE(e,t.operator,n))return!i;return i}function CE(e,t,n){if(!e)return!1;let r=YS(n);if(!r)return!1;let i=e.start??`0000`,a=e.end??`9999`,o=r.start,s=r.end;switch(t){case Z.APPROXIMATELY:case Z.EQUALS:case Z.NOT_EQUALS:return i<s&&a>o;case Z.LESS_THAN:return i<o;case Z.GREATER_THAN:return a>s;case Z.LESS_THAN_OR_EQUALS:return i<=s;case Z.GREATER_THAN_OR_EQUALS:return a>=o;case Z.STARTS_AFTER:return i>s;case Z.ENDS_BEFORE:return a<o;default:return!1}}function wE(e){return e===Z.NOT_EQUALS||e===Z.NOT}var TE={resourceType:`*`},EE=[`DomainConfiguration`,`JsonWebKey`,`Login`],DE=[`Package`,`PackageRelease`,`PackageInstallation`,`Project`,`ProjectMembership`,`User`,`UserSecurityRequest`],OE={READ:`read`,VREAD:`vread`,UPDATE:`update`,DELETE:`delete`,HISTORY:`history`,CREATE:`create`,SEARCH:`search`},kE=[OE.READ,OE.VREAD,OE.HISTORY,OE.SEARCH];function AE(e,t){return EE.includes(t)?!1:jE(e,OE.UPDATE,t)}function jE(e,t,n){return!!e.resource?.some(e=>PE(e,n,t))}function ME(e,t,n){return n?n.resource?.find(n=>NE(e,t,n)):TE}function NE(e,t,n){let r=e.resourceType;return PE(n,r,t)?r===`Binary`?!0:!(n.compartment&&!e.meta?.compartment?.some(e=>e.reference===n.compartment?.reference)||n.criteria&&!pE(e,ZT(n.criteria))):!1}function PE(e,t,n){return e.resourceType!==t&&(e.resourceType!==`*`||DE.includes(t))?!1:e.interaction?e.interaction.includes(n):!e.readonly||kE.includes(n)}function FE(){return typeof window<`u`}function IE(){return typeof Buffer<`u`?Buffer:void 0}var LE={assign(e){FE()&&globalThis.location.assign(e)},reload(){FE()&&globalThis.location.reload()},getSearch(){return FE()?globalThis.location.search:``},getPathname(){return FE()?globalThis.location.pathname:``},getLocation(){return FE()?globalThis.location.toString():``},getOrigin(){return FE()?globalThis.location.protocol+`//`+globalThis.location.host+`/`:``}};function RE(e){if(FE()){let t=window.atob(e),n=Uint8Array.from(t,e=>e.codePointAt(0));return new window.TextDecoder().decode(n)}let t=IE();if(t)return t.from(e,`base64`).toString(`utf-8`);throw Error(`Unable to decode base64`)}function zE(e){if(FE()){let t=new window.TextEncoder().encode(e),n=String.fromCodePoint.apply(null,t);return window.btoa(n)}let t=IE();if(t)return t.from(e,`utf8`).toString(`base64`);throw Error(`Unable to encode base64`)}function BE(e){return e=e.padEnd(e.length+(4-e.length%4)%4,`=`),RE(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`))}function VE(){let e=new Uint32Array(28);return crypto.getRandomValues(e),zC(e.buffer)}async function HE(e){return crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))}function UE(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replaceAll(/[xy]/g,e=>{let t=Math.trunc(Math.random()*16);return(e===`x`?t:t&3|8).toString(16)})}function WE(e){let t={};e=jC(e);for(let n of e.entry??iw){let e=n.resource;if(!e)continue;e.meta!==void 0&&(delete e.meta.author,delete e.meta.compartment,delete e.meta.lastUpdated,delete e.meta.project,delete e.meta.versionId,Object.keys(e.meta).length===0&&delete e.meta);let r=e?.id;if(r)t[r]=UE(),n.fullUrl=`urn:uuid:`+t[r],delete n.resource?.id;else if(n.fullUrl?.startsWith(`resource:`)){let e=n.fullUrl.slice(9);t[e]=UE(),n.fullUrl=`urn:uuid:`+t[e]}}let n=e.entry,r=JSON.stringify({resourceType:`Bundle`,type:`transaction`,entry:n?.map(e=>({fullUrl:e.fullUrl,request:{method:`POST`,url:e.resource?.resourceType},resource:e.resource}))},(e,n)=>GE(e,n,t),2);return KE(JSON.parse(r))}function GE(e,t,n){if((e===`reference`||e===`url`)&&typeof t==`string`){let e;if(t.includes(`/`)?e=t.split(`/`)[1]:t.startsWith(`urn:uuid:`)||t.startsWith(`resource:`)?e=t.slice(9):t.startsWith(`#`)&&(e=t.slice(1)),e){let t=n[e];if(t)return`urn:uuid:`+t}}return t}function KE(e){let{sorted:t,cycles:n}=JE(XE(e)),r={},i=[];for(let t of e.entry??iw)t.fullUrl?r[t.fullUrl]=t:i.push(t);let a=t.map(e=>r[e]);for(let e of n)for(let t of e){let e=r[t],n={...e,request:{...e.request,method:`PUT`}};a.push(n)}return a.push(...i),{...e,entry:a}}var qE={NotVisited:`NotVisited`,Visiting:`Visiting`,Visited:`Visited`};function JE(e){let t=[],n={},r=[];for(let t of Object.keys(e))n[t]=qE.NotVisited;function i(a,o){if(n[a]===qE.Visited)return!0;if(n[a]===qE.Visiting){let e=o.lastIndexOf(a);return e!==-1&&r.push(o.slice(e)),!0}n[a]=qE.Visiting,o.push(a);let s=!1;for(let t of e[a]??iw)i(t,o)||(s=!0);return n[a]=qE.Visited,o.pop(),t.unshift(a),!s}for(let t in e)n[t]===qE.NotVisited&&i(t,[]);return{sorted:t,cycles:r}}function YE(e,t){for(let n in e)if(e[n]&&typeof e[n]==`object`){let r=e[n];if(Hw(r)){let e=r.reference;(e.startsWith(`urn:uuid:`)||e.startsWith(`resource:`))&&t(e)}else YE(r,t)}}function XE(e){let t={};for(let n of e.entry??iw)n.fullUrl&&(t[n.fullUrl]=[]);for(let n of e.entry??iw){let e=n.fullUrl;e&&n.resource&&YE(n.resource,n=>{n!==e&&t[n]&&t[n].push(e)})}return t}var ZE={CSS:`text/css`,DICOM:`application/dicom`,FAVICON:`image/vnd.microsoft.icon`,FHIR_JSON:`application/fhir+json`,FORM_URL_ENCODED:`application/x-www-form-urlencoded`,HL7_V2:`x-application/hl7-v2+er7`,HTML:`text/html`,JAVASCRIPT:`text/javascript`,JOSE:`application/jose`,JSON:`application/json`,JSON_PATCH:`application/json-patch+json`,JWT:`application/jwt`,MULTIPART_FORM_DATA:`multipart/form-data`,PNG:`image/png`,SCIM_JSON:`application/scim+json`,SVG:`image/svg+xml`,TEXT:`text/plain`,TYPESCRIPT:`text/typescript`,PING:`x-application/ping`,XML:`text/xml`,CDA_XML:`application/cda+xml`,OCTET_STREAM:`application/octet-stream`},QE=class{listeners;constructor(){this.listeners={}}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeEventListener(e,t){let n=this.listeners[e];if(n){for(let e=0;e<n.length;e++)if(n[e]===t){n.splice(e,1);return}}}dispatchEvent(e){let t=this.listeners[e.type];for(let n of t??iw)n.call(this,e);return!e.defaultPrevented}removeAllListeners(){this.listeners={}}listenerCount(e){return this.listeners[e]?.length??0}},$E=class{emitter=new QE;dispatchEvent(e){this.emitter.dispatchEvent(e)}addEventListener(e,t){this.emitter.addEventListener(e,t)}removeEventListener(e,t){this.emitter.removeEventListener(e,t)}removeAllListeners(){this.emitter.removeAllListeners()}listenerCount(e){return this.emitter.listenerCount(e)}},eD={"Patient-open":`Patient-open`,"Patient-close":`Patient-close`,"ImagingStudy-open":`ImagingStudy-open`,"ImagingStudy-close":`ImagingStudy-close`,"Encounter-open":`Encounter-open`,"Encounter-close":`Encounter-close`,"DiagnosticReport-open":`DiagnosticReport-open`,"DiagnosticReport-close":`DiagnosticReport-close`,"DiagnosticReport-select":`DiagnosticReport-select`,"DiagnosticReport-update":`DiagnosticReport-update`,syncerror:`syncerror`},tD=[`Patient`,`Encounter`,`ImagingStudy`,`DiagnosticReport`,`OperationOutcome`,`Bundle`],nD=[`DiagnosticReport-update`];function rD(e){return nD.includes(e)}function iD(e){if(nD.includes(e))throw new Xx(Wx(`'context.version' is required for '${e}'.`))}var aD={"Patient-open":{patient:{resourceType:`Patient`},encounter:{resourceType:`Encounter`,optional:!0}},"Patient-close":{patient:{resourceType:`Patient`},encounter:{resourceType:`Encounter`,optional:!0}},"ImagingStudy-open":{study:{resourceType:`ImagingStudy`},encounter:{resourceType:`Encounter`,optional:!0},patient:{resourceType:`Patient`,optional:!0}},"ImagingStudy-close":{study:{resourceType:`ImagingStudy`},encounter:{resourceType:`Encounter`,optional:!0},patient:{resourceType:`Patient`,optional:!0}},"Encounter-open":{encounter:{resourceType:`Encounter`},patient:{resourceType:`Patient`}},"Encounter-close":{encounter:{resourceType:`Encounter`},patient:{resourceType:`Patient`}},"DiagnosticReport-open":{report:{resourceType:`DiagnosticReport`},encounter:{resourceType:`Encounter`,optional:!0},study:{resourceType:`ImagingStudy`,optional:!0,manyAllowed:!0},patient:{resourceType:`Patient`}},"DiagnosticReport-close":{report:{resourceType:`DiagnosticReport`},encounter:{resourceType:`Encounter`,optional:!0},study:{resourceType:`ImagingStudy`,optional:!0,manyAllowed:!0},patient:{resourceType:`Patient`}},"DiagnosticReport-select":{report:{resourceType:`DiagnosticReport`,reference:!0},patient:{resourceType:`Patient`,optional:!0,reference:!0},select:{resourceType:`*`,reference:!0,manyAllowed:!0}},"DiagnosticReport-update":{report:{resourceType:`DiagnosticReport`,reference:!0},patient:{resourceType:`Patient`,optional:!0,reference:!0},updates:{resourceType:`Bundle`}},syncerror:{operationoutcome:{resourceType:`OperationOutcome`}}};function oD(e){return tD.includes(e)}function sD(e){return!!e.endpoint}function cD(e){if(!lD(e))throw new Xx(Wx(`subscriptionRequest must be an object conforming to SubscriptionRequest type.`));let{channelType:t,mode:n,topic:r,events:i}=e,a={"hub.channel.type":t,"hub.mode":n,"hub.topic":r,"hub.events":i.join(`,`)};return sD(e)&&(a.endpoint=e.endpoint),new URLSearchParams(a).toString()}function lD(e){if(typeof e!=`object`)return!1;let{channelType:t,mode:n,topic:r,events:i}=e;if(!(t&&n&&r&&i)||typeof r!=`string`||typeof i!=`object`||!Array.isArray(i)||i.length<1||t!==`websocket`||n!==`subscribe`&&n!==`unsubscribe`)return!1;for(let e of i)if(!eD[e])return!1;return!(sD(e)&&!(typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))}function uD(e,t,n,r){if(typeof t!=`object`)throw new Xx(Wx(`context[${n}] is invalid. Context must contain a single valid FHIR resource! Resource is not an object.`));if(!(t.id&&typeof t.id==`string`))throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a valid string ID.`));if(!t.resourceType)throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a resource type. No resource type found.`));let i=r.resourceType;if(i!==`*`){if(!oD(t.resourceType))throw new Xx(Wx(`context[${n}] is invalid. Resource must contain a valid FHIRcast resource type. Resource type is not a known resource type.`));if(i&&t.resourceType!==i)throw new Xx(Wx(`context[${n}] is invalid. context[${n}] for the '${e}' event should contain resource of type ${i}.`))}}function dD(e,t,n,r,i){if(i.set(t.key,(i.get(t.key)??0)+1),r.reference){if(!Hw(t.reference))throw new Xx(Wx(`context[${n}] is invalid. Expected key '${t.key}' to be a reference.`))}else uD(e,t.resource,n,r)}function fD(e,t){let n=new Map,r=aD[e];for(let i=0;i<t.length;i++){let a=t[i].key;if(!r[a])throw new Xx(Wx(`Key '${a}' not found for event '${e}'. Make sure to add only valid keys.`));dD(e,t[i],i,r[a],n)}for(let[t,i]of Object.entries(r)){if(!(i.optional||n.has(t)))throw new Xx(Wx(`Missing required key '${t}' on context for '${e}' event.`));if(!i.manyAllowed&&(n.get(t)??0)>1)throw new Xx(Wx(`${n.get(t)} context entries with key '${t}' found for the '${e}' event when schema only allows for 1.`))}}function pD(e,t,n,r){if(!(e&&typeof e==`string`))throw new Xx(Wx(`Must provide a topic.`));if(!eD[t])throw new Xx(Wx(`Must provide a valid FHIRcast event name. Supported events: ${Object.keys(eD).join(`, `)}`));if(typeof n!=`object`)throw new Xx(Wx(`context must be a context object or array of context objects.`));if(nD.includes(t)&&!r)throw new Xx(Wx(`The '${t}' event must contain a 'context.versionId'.`));let i=Array.isArray(n)?n:[n];return fD(t,i),{timestamp:new Date().toISOString(),id:UE(),event:{"hub.topic":e,"hub.event":t,context:i,...r?{"context.versionId":r}:{}}}}var mD=class extends $E{subRequest;websocket;constructor(e){if(super(),this.subRequest=e,!e.endpoint)throw new Xx(Wx(`Subscription request should contain an endpoint.`));if(!lD(e))throw new Xx(Wx(`Subscription request failed validation.`));let t=new WebSocket(e.endpoint);t.addEventListener(`open`,()=>{this.dispatchEvent({type:`connect`}),t.addEventListener(`message`,e=>{let n=JSON.parse(e.data);if(n[`hub.topic`])return;let r=n;r.event[`hub.event`]!==`heartbeat`&&(this.dispatchEvent({type:`message`,payload:r}),t.send(JSON.stringify({id:n?.id,timestamp:new Date().toISOString()})))}),t.addEventListener(`close`,()=>{this.dispatchEvent({type:`disconnect`})})}),this.websocket=t}disconnect(){this.websocket.close()}};function hD(e){return JSON.parse(BE(e))}function gD(e){return e.split(`.`).length===3}function _D(e){let[t,n,r]=e.split(`.`);return hD(n)}function vD(e){try{return typeof _D(e).login_id==`string`}catch{return!1}}function yD(e){try{let t=_D(e).exp;return typeof t==`number`?t*1e3:void 0}catch{return}}var bD=class{medplum;constructor(e){this.medplum=e}async get(e){return this.medplum.get(`keyvalue/v1/${e}`)}async set(e,t){await this.medplum.put(`keyvalue/v1/${e}`,t,ZE.TEXT)}async delete(e){await this.medplum.delete(`keyvalue/v1/${e}`)}},xD=class{[Symbol.toStringTag]=`ReadablePromise`;suspender;status=`pending`;response;error;constructor(e){this.suspender=e.then(e=>(this.status=`success`,this.response=e,e),e=>{throw this.status=`error`,this.error=e,e})}isPending(){return this.status===`pending`}isOk(){return this.status===`success`}read(){switch(this.status){case`pending`:throw this.suspender;case`error`:throw this.error;default:return this.response}}then(e,t){return this.suspender.then(e,t)}catch(e){return this.suspender.catch(e)}finally(e){return this.suspender.finally(e)}},SD=class{storage;prefix=``;constructor(e,t=``){this.storage=e??globalThis.localStorage??new CD,this.prefix=t}makeKey(e){return this.prefix+e}clear(){this.storage===globalThis.localStorage&&this.prefix?Object.keys(this.storage).filter(e=>e.startsWith(this.prefix)).forEach(e=>{this.storage.removeItem(e)}):this.storage.clear()}getString(e){return this.storage.getItem(this.makeKey(e))??void 0}setString(e,t){t?this.storage.setItem(this.makeKey(e),t):this.storage.removeItem(this.makeKey(e))}getObject(e){let t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?vC(t):void 0)}},CD=class{data;constructor(){this.data=new Map}get length(){return this.data.size}clear(){this.data.clear()}getItem(e){return this.data.get(e)??null}setItem(e,t){t?this.data.set(e,t):this.data.delete(e)}removeItem(e){this.data.delete(e)}key(e){return Array.from(this.data.keys())[e]}},wD={Event:globalThis.Event===void 0?void 0:globalThis.Event,ErrorEvent:void 0,CloseEvent:void 0},TD=!1;function ED(){if(globalThis.Event===void 0)throw Error(`Unable to lazy init events for ReconnectingWebSocket. globalThis.Event is not defined yet`);wD.Event=globalThis.Event,wD.ErrorEvent=class extends Event{message;error;constructor(e,t){super(`error`,t),this.message=e.message,this.error=e}},wD.CloseEvent=class extends Event{code;reason;wasClean=!0;constructor(e=1e3,t=``,n){super(`close`,n),this.code=e,this.reason=t}}}function DD(e,t){if(!e)throw Error(t)}function OD(){}function kD(e){if(e instanceof wD.CloseEvent){let t=e;return new wD.CloseEvent(t.code,t.reason,void 0)}if(e instanceof wD.ErrorEvent){let t=e;return new wD.ErrorEvent(t.error??Error(t.message),void 0)}return new e.constructor(e.type,e)}function AD(e,t){let n=e;return n.error instanceof Error?new wD.ErrorEvent(n.error,t):new wD.ErrorEvent(Error(n.message||`WebSocket error`),t)}var jD={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},MD=!1,ND=class e extends $E{_ws;_retryCount=-1;_uptimeTimeout;_connectTimeout;_shouldReconnect=!0;_connectLock=!1;_binaryType;_closeCalled=!1;_messageQueue=[];_debugLogger=console.log.bind(console);_url;_protocols;_options;constructor(e,t,n={}){TD||=(ED(),!0),super(),this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._options.binaryType?this._binaryType=this._options.binaryType:this._binaryType=`blob`,this._options.debugLogger&&(this._debugLogger=this._options.debugLogger),this._connect()}static get CONNECTING(){return 0}static get OPEN(){return 1}static get CLOSING(){return 2}static get CLOSED(){return 3}get CONNECTING(){return e.CONNECTING}get OPEN(){return e.OPEN}get CLOSING(){return e.CLOSING}get CLOSED(){return e.CLOSED}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((e,t)=>(typeof t==`string`?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e),0)+(this._ws?.bufferedAmount??0)}get extensions(){return this._ws?.extensions??``}get protocol(){return this._ws?.protocol??``}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING}get url(){return this._ws?this._ws.url:``}get shouldReconnect(){return this._shouldReconnect}onclose=null;onerror=null;onmessage=null;onopen=null;close(e=1e3,t){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug(`close enqueued: no ws instance`);return}if(this._ws.readyState===this.CLOSED){this._debug(`close: already closed`);return}this._ws.close(e,t)}reconnect(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED||this._disconnect(e,t),this._connect()}send(e){if(this._ws?.readyState===this.OPEN)this._debug(`send`,e),this._ws.send(e);else{let{maxEnqueuedMessages:t=jD.maxEnqueuedMessages}=this._options;this._messageQueue.length<t&&(this._debug(`enqueue`,e),this._messageQueue.push(e))}}_debug(...e){this._options.debug&&this._debugLogger(`RWS>`,...e)}_getNextDelay(){let{reconnectionDelayGrowFactor:e=jD.reconnectionDelayGrowFactor,minReconnectionDelay:t=jD.minReconnectionDelay,maxReconnectionDelay:n=jD.maxReconnectionDelay}=this._options,r=0;return this._retryCount>0&&(r=t*e**(this._retryCount-1),r>n&&(r=n)),this._debug(`next delay`,r),r}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_connect(){if(this._connectLock||!this._shouldReconnect)return;this._connectLock=!0;let{maxRetries:e=jD.maxRetries,connectionTimeout:t=jD.connectionTimeout}=this._options;if(this._retryCount>=e){this._connectLock=!1,this._debug(`max retries reached`,this._retryCount,`>=`,e);return}this._retryCount++,this._debug(`connect`,this._retryCount),this._removeListeners(),this._wait().then(()=>{if(this._closeCalled){this._connectLock=!1;return}!this._options.WebSocket&&typeof WebSocket>`u`&&!MD&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket.`),MD=!0);let e=this._options.WebSocket||WebSocket;this._debug(`connect`,{url:this._url,protocols:this._protocols}),this._ws=this._protocols?new e(this._url,this._protocols):new e(this._url),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t)}).catch(e=>{this._connectLock=!1,this._handleError(new wD.ErrorEvent(Error(e.message),this))})}_handleTimeout(){this._debug(`timeout event`),this._handleError(new wD.ErrorEvent(Error(`TIMEOUT`),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),!this._ws)return;let n=this._ws;this._removeListeners(),n.addEventListener(`error`,OD);try{n.close(e,t),this._handleClose(new wD.CloseEvent(e,t,this))}catch{}}_acceptOpen(){this._debug(`accept open`),this._retryCount=0}_handleOpen=e=>{this._debug(`open event`);let{minUptime:t=jD.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),DD(this._ws,`WebSocket is not defined`),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(e=>this._ws?.send(e)),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent(kD(e))};_handleMessage=e=>{this._debug(`message event`),this.onmessage&&this.onmessage(e),this.dispatchEvent(kD(e))};_handleError=e=>{let t=AD(e,this);this._debug(`error event`,t.message),this._disconnect(void 0,t.message===`TIMEOUT`?`timeout`:void 0),this.onerror&&this.onerror(t),this._debug(`exec error listeners`),this.dispatchEvent(kD(t)),this._connect()};_handleClose=e=>{this._debug(`close event`),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(kD(e))};_removeListeners(){this._ws&&(this._debug(`removeListeners`),this._ws.removeEventListener(`open`,this._handleOpen),this._ws.removeEventListener(`close`,this._handleClose),this._ws.removeEventListener(`message`,this._handleMessage),this._ws.removeEventListener(`error`,this._handleError))}_addListeners(){this._ws&&(this._debug(`addListeners`),this._ws.addEventListener(`open`,this._handleOpen),this._ws.addEventListener(`close`,this._handleClose),this._ws.addEventListener(`message`,this._handleMessage),this._ws.addEventListener(`error`,this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}},PD=6e4,FD=[WebSocket.CLOSING,WebSocket.CLOSED],ID=class extends $E{criteria;constructor(...e){super(),this.criteria=new Set(e)}getCriteria(){return this.criteria}_addCriteria(e){this.criteria.add(e)}_removeCriteria(e){this.criteria.delete(e)}},LD=class{criteria;emitter;refCount;subscriptionProps;subscriptionId;token;tokenExpiry;state=`idle`;generation=0;lastUnrefTime;constructor(e,t){this.criteria=e,this.emitter=new ID(e),this.refCount=1,this.subscriptionProps=t?{...t}:void 0}nextGeneration(){return++this.generation}},RD=class{medplum;ws;masterSubEmitter;criteriaEntries;criteriaEntriesBySubscriptionId;wsClosed;pingTimer=void 0;tokenRefreshTimer=void 0;pingIntervalMs;waitingForPong=!1;currentProfile;constructor(e,t,n){if(!(e instanceof $D))throw new Xx(Wx("First arg of constructor should be a `MedplumClient`"));let r;try{r=new URL(t).toString()}catch{throw new Xx(Wx(`Not a valid URL`))}let i=n?.ReconnectingWebSocket?new n.ReconnectingWebSocket(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger}):new ND(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger});this.medplum=e,this.ws=i,this.masterSubEmitter=new ID,this.criteriaEntries=new Map,this.criteriaEntriesBySubscriptionId=new Map,this.wsClosed=!1,this.pingIntervalMs=n?.pingIntervalMs??5e3,this.currentProfile=e.getProfile(),this.setupListeners()}setupListeners(){let e=this.ws;e.addEventListener(`message`,e=>{try{let t=JSON.parse(e.data);if(t.type===`pong`){this.waitingForPong=!1;return}let n=t,r=n?.entry?.[0]?.resource;if(r.type===`heartbeat`){this.masterSubEmitter?.dispatchEvent({type:`heartbeat`,payload:n});return}if(r.type===`handshake`){let e=oC(r.subscription),t={type:`connect`,payload:{subscriptionId:e}};this.masterSubEmitter?.dispatchEvent(t);let n=this.criteriaEntriesBySubscriptionId.get(e);if(!n){console.warn(`Received handshake for criteria the SubscriptionManager is not listening for yet`);return}(n.state===`connecting`||n.state===`refreshing`)&&(n.state=`active`),n.emitter.dispatchEvent({...t});return}this.masterSubEmitter?.dispatchEvent({type:`message`,payload:n});let i=this.criteriaEntriesBySubscriptionId.get(oC(r.subscription));if(!i){console.warn(`Received notification for criteria the SubscriptionManager is not listening for`);return}i.emitter.dispatchEvent({type:`message`,payload:n})}catch(e){console.error(e);let t={type:`error`,payload:e};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t})}}),e.addEventListener(`error`,e=>{let t={type:`error`,payload:new Xx({resourceType:`OperationOutcome`,issue:[{severity:`error`,code:`exception`,details:{text:`WebSocket connection closed due to an error`},diagnostics:e.error?Y(e.error):e.message}]})};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t})}),e.addEventListener(`close`,()=>{let e={type:`close`};this.masterSubEmitter?.dispatchEvent(e);for(let t of this.getAllCriteriaEmitters())t.dispatchEvent({...e});this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=void 0,this.waitingForPong=!1),this.tokenRefreshTimer&&=(clearInterval(this.tokenRefreshTimer),void 0),this.wsClosed&&(this.criteriaEntries.clear(),this.criteriaEntriesBySubscriptionId.clear(),this.masterSubEmitter?.removeAllListeners())}),e.addEventListener(`open`,()=>{let t={type:`open`};this.masterSubEmitter?.dispatchEvent(t);for(let e of this.getAllCriteriaEmitters())e.dispatchEvent({...t});this.refreshAllSubscriptions().catch(console.error),this.pingTimer??=setInterval(()=>{this.waitingForPong?(this.waitingForPong=!1,e.reconnect()):(e.send(JSON.stringify({type:`ping`})),this.waitingForPong=!0),this.gcUnrefEntries()},this.pingIntervalMs),this.tokenRefreshTimer??=setInterval(()=>{this.checkTokenExpirations(),this.gcUnrefEntries()},PD)}),this.medplum.addEventListener(`change`,()=>{let e=this.medplum.getProfile();this.currentProfile&&e===void 0?this.ws.close():e&&this.currentProfile?.id!==e.id&&this.ws.reconnect(),this.currentProfile=e})}sendBind(e){this.ws.send(JSON.stringify({type:`bind-with-token`,payload:{token:e}}))}sendUnbind(e){this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:`unbind-from-token`,payload:{token:e}}))}emitError(e,t){let n={type:`error`,payload:t};this.masterSubEmitter?.dispatchEvent(n),e.emitter.dispatchEvent({...n})}maybeEmitDisconnect(e){let{subscriptionId:t}=e;if(t){let n={type:`disconnect`,payload:{subscriptionId:t}};this.masterSubEmitter?.dispatchEvent(n),e.emitter.dispatchEvent({...n})}else console.warn("Called disconnect for `CriteriaEntry` before `subscriptionId` was present.")}isStale(e,t){return this.isEntryGettingRemoved(e)||e.generation!==t}maybeGetCriteriaEntry(e,t){let n=this.criteriaEntries.get(e);if(n){if(!t)return n.bareCriteria;for(let e of n.criteriaWithProps)if(TC(t,e.subscriptionProps))return e}}getAllCriteriaEmitters(){let e=[];for(let t of this.criteriaEntries.values())for(let n of zD(t))n.refCount>0&&e.push(n.emitter);return e}addCriteriaEntry(e){let{criteria:t,subscriptionProps:n}=e,r;this.criteriaEntries.has(t)?r=this.criteriaEntries.get(t):(r={criteriaWithProps:[]},this.criteriaEntries.set(t,r)),n?r.criteriaWithProps.push(e):r.bareCriteria=e}removeCriteriaEntry(e){e.state=`removed`,e.generation++;let{criteria:t,subscriptionProps:n,subscriptionId:r,token:i}=e;if(!this.criteriaEntries.has(t))return;let a=this.criteriaEntries.get(t);n?a.criteriaWithProps=a.criteriaWithProps.filter(e=>{let t=e.subscriptionProps;return!TC(n,t)}):a.bareCriteria=void 0,!a.bareCriteria&&a.criteriaWithProps.length===0&&(this.criteriaEntries.delete(t),this.masterSubEmitter?._removeCriteria(t)),r&&this.criteriaEntriesBySubscriptionId.delete(r),i&&this.sendUnbind(i)}async subscribeToCriteria(e){this.wsClosed&&await this.reconnectIfNeeded(),this.ws.readyState===WebSocket.OPEN&&this.medplum.getProfile()&&e.state===`idle`&&(e.state=`connecting`,await this.rebindCriteriaEntry(e))}async refreshAllSubscriptions(){this.criteriaEntriesBySubscriptionId.clear();let e=[],t=[];for(let n of this.criteriaEntries.values())for(let r of zD(n))r.refCount===0?t.push(r):e.push(r);for(let e of t)this.removeCriteriaEntry(e);for(let t of e)t.token&&this.sendUnbind(t.token),t.token=void 0,t.tokenExpiry=void 0,t.subscriptionId=void 0,t.state=`idle`,t.generation++,await this.subscribeToCriteria(t)}async rebindCriteriaEntry(e){let t=e.nextGeneration();try{if(!e.subscriptionId){let n=await this.medplum.createResource({...e.subscriptionProps,resourceType:`Subscription`,status:`active`,reason:`WebSocket subscription for ${aC(this.medplum.getProfile())}`,channel:{type:`websocket`},criteria:e.criteria});if(e.subscriptionId??=n.id,this.isStale(e,t))return}let{parameter:n}=await this.medplum.get(`fhir/R4/Subscription/${e.subscriptionId}/$get-ws-binding-token`,{cache:`no-cache`}),r=n?.find(e=>e.name===`token`)?.valueString,i=n?.find(e=>e.name===`websocket-url`)?.valueUrl,a=n?.find(e=>e.name===`expiration`)?.valueDateTime;if(!r)throw new Xx(Wx(`Failed to get token`));if(!i)throw new Xx(Wx(`Failed to get URL from $get-ws-binding-token`));if(!a)throw new Xx(Wx(`Failed to get expiration from $get-ws-binding-token`));if(this.isStale(e,t))return;e.token=r,e.tokenExpiry=new Date(a).getTime(),this.criteriaEntriesBySubscriptionId.set(e.subscriptionId,e),this.sendBind(r)}catch(n){console.error(Y(n)),e.generation===t&&!this.isEntryGettingRemoved(e)&&(e.state=e.state===`refreshing`?`active`:`idle`),this.emitError(e,n)}}checkTokenExpirations(){if(!this.medplum.getProfile())return;let e=Date.now();for(let t of this.criteriaEntries.values())for(let n of zD(t))n.refCount===0||!n.tokenExpiry||n.tokenExpiry-e<=3e5&&n.state===`active`&&this.ws.readyState===WebSocket.OPEN&&(n.state=`refreshing`,this.rebindCriteriaEntry(n).catch(e=>{this.masterSubEmitter?.dispatchEvent({type:`error`,payload:e})}))}addCriteria(e,t){this.masterSubEmitter&&this.masterSubEmitter._addCriteria(e);let n=this.maybeGetCriteriaEntry(e,t);if(n)return n.refCount===0&&(n.lastUnrefTime=void 0,n.generation++,n.state!==`active`&&(n.state=n.token?`active`:`idle`)),n.refCount+=1,n.state===`idle`&&this.subscribeToCriteria(n).catch(console.error),n.emitter;let r=new LD(e,t);return this.addCriteriaEntry(r),this.subscribeToCriteria(r).catch(console.error),r.emitter}removeCriteria(e,t){let n=this.maybeGetCriteriaEntry(e,t);if(!n||this.isEntryGettingRemoved(n)){console.warn("Criteria not known to `SubscriptionManager`. Possibly called remove too many times.");return}--n.refCount,n.refCount===0&&(n.lastUnrefTime=Date.now(),n.generation++)}gcUnrefEntries(){let e=Date.now(),t=[];for(let n of this.criteriaEntries.values())for(let r of zD(n))r.refCount===0&&r.lastUnrefTime!==void 0&&e-r.lastUnrefTime>=1e4&&t.push(r);for(let e of t)this.maybeEmitDisconnect(e),this.removeCriteriaEntry(e);t.length>0&&this.criteriaEntries.size===0&&this.closeWebSocket()}isEntryGettingRemoved(e){return e.refCount===0||e.state===`removed`}getWebSocket(){return this.ws}closeWebSocket(){if(!this.wsClosed){if(this.ws.readyState===WebSocket.OPEN)for(let e of this.criteriaEntries.values())for(let t of zD(e))t.token&&this.sendUnbind(t.token);this.wsClosed=!0,this.ws.close()}}reconnectWebSocket(){this.ws.reconnect(),this.wsClosed=!1}getCriteriaCount(){return this.getAllCriteriaEmitters().length}getMasterEmitter(){return this.masterSubEmitter||=new ID(...Array.from(this.criteriaEntries.keys())),this.masterSubEmitter}async reconnectIfNeeded(){FD.includes(this.getWebSocket().readyState)&&await new Promise(e=>{let t=()=>{this.getWebSocket().removeEventListener(`open`,t),e()};this.getWebSocket().addEventListener(`open`,t),this.reconnectWebSocket()})}};function zD(e){return e.bareCriteria?[e.bareCriteria,...e.criteriaWithProps]:e.criteriaWithProps}new Sx(1e3);var BD=`5.1.26-6abd8af`,VD=ZE.FHIR_JSON+`, */*; q=0.1`,HD=`https://api.medplum.com/`,UD=1e3,WD=6e4,GD=0,KD=3e5,qD=`Binary/`,JD={resourceType:`Device`,id:`system`,deviceName:[{type:`model-name`,name:`System`}]},YD=2,XD={ClientCredentials:`client_credentials`,AuthorizationCode:`authorization_code`,RefreshToken:`refresh_token`,JwtBearer:`urn:ietf:params:oauth:grant-type:jwt-bearer`,TokenExchange:`urn:ietf:params:oauth:grant-type:token-exchange`,PreAuthorizedCode:`urn:ietf:params:oauth:grant-type:pre-authorized_code`},ZD={AccessToken:`urn:ietf:params:oauth:token-type:access_token`,RefreshToken:`urn:ietf:params:oauth:token-type:refresh_token`,IdToken:`urn:ietf:params:oauth:token-type:id_token`,Saml1Token:`urn:ietf:params:oauth:token-type:saml1`,Saml2Token:`urn:ietf:params:oauth:token-type:saml2`},QD={JwtBearer:`urn:ietf:params:oauth:client-assertion-type:jwt-bearer`},$D=class extends $E{options;fetch;createPdfImpl;storage;requestCache;cacheTime;baseUrl;fhirBaseUrl;authorizeUrl;tokenUrl;logoutUrl;fhircastHubUrl;cdsServicesUrl;defaultHeaders;onUnauthenticated;autoBatchTime;autoBatchQueue;maxRetries;maxRetryTime;refreshGracePeriod;subscriptionManager;medplumServer;clientId;clientSecret;credentialsInHeader;autoBatchTimerId;accessToken;accessTokenExpires;refreshToken;refreshPromise;profilePromise;sessionDetails;currentRateLimits;basicAuth;initPromise;initComplete=!0;keyValueClient;logLevel;constructor(e){if(super(),e?.baseUrl&&!e.baseUrl.startsWith(`http`))throw Error(`Base URL must start with http or https`);this.options=e??{},this.fetch=e?.fetch??eO(),this.storage=e?.storage??new SD(void 0,e?.storagePrefix),this.createPdfImpl=e?.createPdf,this.baseUrl=ZC(e?.baseUrl??HD),this.fhirBaseUrl=$C(this.baseUrl,e?.fhirUrlPath??`fhir/R4`),this.authorizeUrl=$C(this.baseUrl,e?.authorizeUrl??`oauth2/authorize`),this.tokenUrl=$C(this.baseUrl,e?.tokenUrl??`oauth2/token`),this.logoutUrl=$C(this.baseUrl,e?.logoutUrl??`oauth2/logout`),this.fhircastHubUrl=$C(this.baseUrl,e?.fhircastHubUrl??`fhircast/STU3`),this.cdsServicesUrl=$C(this.baseUrl,e?.cdsServicesUrl??`cds-services`),this.clientId=e?.clientId??``,this.clientSecret=e?.clientSecret??``,this.credentialsInHeader=e?.authCredentialsMethod===`header`,this.defaultHeaders=e?.defaultHeaders??{},this.onUnauthenticated=e?.onUnauthenticated,this.refreshGracePeriod=e?.refreshGracePeriod??KD,this.logLevel=this.initializeLogLevel(e),this.maxRetries=e?.maxRetries??2,this.maxRetryTime=e?.maxRetryTime??2e3,this.cacheTime=e?.cacheTime??(FE()?WD:GD),this.cacheTime>0?this.requestCache=new Sx(e?.resourceCacheSize??UD):this.requestCache=void 0,e?.autoBatchTime?(this.autoBatchTime=e.autoBatchTime,this.autoBatchQueue=[]):(this.autoBatchTime=0,this.autoBatchQueue=void 0),e?.accessToken&&this.setAccessToken(e.accessToken),this.storage.getInitPromise===void 0?(e?.accessToken||this.attemptResumeActiveLogin().catch(console.error),this.initPromise=Promise.resolve(),this.dispatchEvent({type:`storageInitialized`})):(this.initComplete=!1,this.initPromise=this.storage.getInitPromise(),this.initPromise.then(()=>{e?.accessToken||this.attemptResumeActiveLogin().catch(console.error),this.initComplete=!0,this.dispatchEvent({type:`storageInitialized`})}).catch(e=>{console.error(e),this.initComplete=!0,this.dispatchEvent({type:`storageInitFailed`,payload:{error:e}})})),this.setupStorageListener()}get isInitialized(){return this.initComplete}getInitPromise(){return this.initPromise}initializeLogLevel(e){return e?.logLevel?e.logLevel:e?.verbose===void 0?`none`:e.verbose?`verbose`:`none`}async attemptResumeActiveLogin(){let e=this.getActiveLogin();e&&(this.setAccessToken(e.accessToken,e.refreshToken),await this.refreshProfile())}getBaseUrl(){return this.baseUrl}getAuthorizeUrl(){return this.authorizeUrl}getTokenUrl(){return this.tokenUrl}getLogoutUrl(){return this.logoutUrl}getFhircastHubUrl(){return this.fhircastHubUrl}getCdsServicesUrl(){return this.cdsServicesUrl}getDefaultHeaders(){return this.defaultHeaders}clear(){this.storage.clear(),this.clearActiveLogin()}clearActiveLogin(){this.storage.setString(`activeLogin`,void 0),this.requestCache?.clear(),this.accessToken=void 0,this.refreshToken=void 0,this.refreshPromise=void 0,this.accessTokenExpires=void 0,this.sessionDetails=void 0,this.medplumServer=void 0,this.dispatchEvent({type:`change`})}invalidateUrl(e){e=e.toString(),this.requestCache?.delete(e)}invalidateAll(){this.requestCache?.clear()}invalidateSearches(e){let t=$C(this.fhirBaseUrl,e);for(let e of this.requestCache?.keys()??iw)(e.endsWith(t)||e.includes(t+`?`))&&this.requestCache?.delete(e)}get(e,t={}){e=e.toString();let n=this.getCacheEntry(e,t);if(n)return n.value;let r;e.startsWith(this.fhirBaseUrl)&&this.autoBatchQueue&&!t.disableAutoBatch?r=new Promise((n,r)=>{this.autoBatchQueue.push({method:`GET`,url:e.replace(this.fhirBaseUrl,``),options:t,resolve:n,reject:r}),this.autoBatchTimerId||=setTimeout(()=>this.executeAutoBatch(),this.autoBatchTime)}):(t.method=`GET`,r=this.request(e,t));let i=new xD(r);return this.setCacheEntry(e,i,t),i}post(e,t,n,r={}){return e=e.toString(),this.setRequestBody(r,t),n&&this.setRequestContentType(r,n),this.invalidateUrl(e),r.method=`POST`,this.request(e,r)}put(e,t,n,r={}){return e=e.toString(),this.setRequestBody(r,t),n&&this.setRequestContentType(r,n),this.invalidateUrl(e),r.method=`PUT`,this.request(e,r)}patch(e,t,n={}){return e=e.toString(),this.setRequestBody(n,t),this.setRequestContentType(n,ZE.JSON_PATCH),this.invalidateUrl(e),n.method=`PATCH`,this.request(e,n)}delete(e,t={}){return e=e.toString(),this.invalidateUrl(e),t.method=`DELETE`,this.request(e,t)}async startNewUser(e,t){let{codeChallengeMethod:n,codeChallenge:r}=await this.startPkce();return this.post(`auth/newuser`,{...e,clientId:e.clientId??this.clientId,codeChallengeMethod:n,codeChallenge:r},void 0,t)}async startNewProject(e,t){return this.post(`auth/newproject`,e,void 0,t)}async startNewPatient(e,t){return this.post(`auth/newpatient`,e,void 0,t)}async startLogin(e,t){return this.post(`auth/login`,{...await this.ensureCodeChallenge(e),clientId:e.clientId??this.clientId,scope:e.scope},void 0,t)}async startGoogleLogin(e,t){return this.post(`auth/google`,{...await this.ensureCodeChallenge(e),clientId:e.clientId??this.clientId,scope:e.scope},void 0,t)}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(this.logoutUrl,{}),this.clear()}async signInWithRedirect(e){let t=new URLSearchParams(LE.getSearch()).get(`code`);if(!t){await this.requestAuthorization(e);return}return this.processCode(t)}signOutWithRedirect(){LE.assign(this.logoutUrl)}async signInWithExternalAuth(e,t,n,r,i=!0){let a=r;i&&(a=await this.ensureCodeChallenge(r)),LE.assign(this.getExternalAuthRedirectUri(e,t,n,a,i))}async exchangeExternalAccessToken(e,t,n){if(t??=this.clientId,!t)throw Error(`MedplumClient is missing clientId`);let r={grant_type:XD.TokenExchange,subject_token_type:ZD.AccessToken,client_id:t,subject_token:e};return n&&(r.membership_id=n),this.fetchTokens(r)}getExternalAuthRedirectUri(e,t,n,r,i=!0){let a=new URL(e);if(a.searchParams.set(`response_type`,`code`),a.searchParams.set(`client_id`,t),a.searchParams.set(`redirect_uri`,n),a.searchParams.set(`scope`,r.scope??`openid profile email`),a.searchParams.set(`state`,JSON.stringify(r)),i){let{codeChallenge:e,codeChallengeMethod:t}=r;if(!t)throw Error("`LoginRequest` for external auth must include a `codeChallengeMethod`.");if(!e)throw Error("`LoginRequest` for external auth must include a `codeChallenge`.");a.searchParams.set(`code_challenge_method`,t),a.searchParams.set(`code_challenge`,e)}return a.toString()}fhirUrl(...e){return new URL($C(this.fhirBaseUrl,e.join(`/`)))}fhirSearchUrl(e,t){let n=this.fhirUrl(e);return t&&(n.search=tw(t)),n}search(e,t,n){let r=this.fhirSearchUrl(e,t),i=`search-`+r.toString(),a=this.getCacheEntry(i,n);if(a)return a.value;let o=this.getBundle(r,n);return this.setCacheEntry(i,o,n),o}searchOne(e,t,n){let r=this.fhirSearchUrl(e,t);r.searchParams.set(`_count`,`1`),r.searchParams.sort();let i=`searchOne-`+r.toString(),a=this.getCacheEntry(i,n);if(a)return a.value;let o=new xD(this.search(e,r.searchParams,n).then(e=>e.entry?.[0]?.resource));return this.setCacheEntry(i,o,n),o}searchResources(e,t,n){let r=`searchResources-`+this.fhirSearchUrl(e,t).toString(),i=this.getCacheEntry(r,n);if(i)return i.value;let a=new xD(this.search(e,t,n).then(nO));return this.setCacheEntry(r,a,n),a}async*searchResourcePages(e,t,n){let r=this.fhirSearchUrl(e,t);for(;r;){let t=new URL(r).searchParams;t.has(`_count`)||t.set(`_count`,`1000`);let i=await this.search(e,t,n),a=i.link?.find(e=>e.relation===`next`);if(!i.entry?.length&&!a)break;yield nO(i),r=a?.url?new URL(a.url):void 0}}valueSetExpand(e,t){let n=this.fhirUrl(`ValueSet`,`$expand`);return n.search=new URLSearchParams(e).toString(),this.get(n.toString(),t)}getCached(e,t){let n=this.requestCache?.get(this.fhirUrl(e,t).toString())?.value;return n?.isOk()?n.read():void 0}getCachedReference(e){let t=e.reference;if(!t)return;if(t===`system`)return JD;let[n,r]=t.split(`/`);if(!(!n||!r))return this.getCached(n,r)}readResource(e,t,n){if(!t)throw Error(`The "id" parameter cannot be null, undefined, or an empty string.`);return this.get(this.fhirUrl(e,t),n)}readReference(e,t){let n=e.reference;if(!n)return new xD(Promise.reject(Error(`Missing reference`)));if(n===`system`)return new xD(Promise.resolve(JD));let[r,i]=n.split(`/`);return!r||!i?new xD(Promise.reject(Error(`Invalid reference`))):this.readResource(r,i,t)}readCanonical(e,t,n){return Array.isArray(e)?this.searchOne(``,{_type:e.join(`,`),url:t},n):this.searchOne(e,`url=`+t,n)}requestSchema(e,t){if(dS(e))return Promise.resolve();let n=e+`-requestSchema`,r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new xD((async()=>{let t=`{
|
|
57
57
|
StructureDefinitionList(_filter: "name eq ${e}") {
|
|
58
58
|
resourceType,
|
|
59
59
|
name,
|
|
@@ -93,7 +93,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function ar({color:e,theme:t,autoContrast:n}){ret
|
|
|
93
93
|
expression,
|
|
94
94
|
target
|
|
95
95
|
}
|
|
96
|
-
}`.replaceAll(/\s+/g,` `),n=await this.graphql(t);lS(n.data.StructureDefinitionList);for(let e of n.data.SearchParameterList)Aw(e)})());return this.setCacheEntry(n,i,t),i}requestProfileSchema(e,t){if(!t?.expandProfile&&mS(e))return Promise.resolve();let n=e+`-requestSchema`+(t?.expandProfile?`-nested`:``),r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new xD((async()=>{if(t?.expandProfile){let t=this.fhirUrl(`StructureDefinition`,`$expand-profile`);t.search=new URLSearchParams({url:e}).toString(),lS(await this.post(t.toString(),{}))}else{let t=await this.searchOne(`StructureDefinition`,{url:e,_sort:`-_lastUpdated`});if(!t){console.warn(`No StructureDefinition found for ${e}!`);return}uS(t)}})());return this.setCacheEntry(n,i,t),i}readHistory(e,t,n,r){let i=this.fhirUrl(e,t,`_history`);return n?.count&&i.searchParams.set(`_count`,n.count.toString()),n?.offset&&i.searchParams.set(`_offset`,n.offset.toString()),this.get(i.toString(),r)}readVersion(e,t,n,r){return this.get(this.fhirUrl(e,t,`_history`,n),r)}readPatientEverything(e,t){return this.getBundle(this.fhirUrl(`Patient`,e,`$everything`),t)}readPatientSummary(e,t){return this.getBundle(this.fhirUrl(`Patient`,e,`$summary`),t)}createResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);return this.invalidateSearches(e.resourceType),this.post(this.fhirUrl(e.resourceType),e,void 0,t)}async createResourceIfNoneExist(e,t,n={}){let r=this.fhirUrl(e.resourceType);this.setRequestHeader(n,`If-None-Exist`,t);let i=await this.post(r,e,void 0,n);return this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),i}async upsertResource(e,t,n){let r=this.fhirSearchUrl(e.resourceType,t),i=await this.put(r,e,void 0,n);return i||=e,this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),i}async createAttachment(e,t,n,r,i){let a=iO(e,t,n,r);if(a.contentType===ZE.XML){let e=a.data,t;t=e instanceof Blob?await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(!r.result){n(Error(`Failed to load file`));return}t(r.result)},r.readAsText(e,`utf-8`)}):ArrayBuffer.isView(e)?new TextDecoder().decode(e):e,t.includes(`<ClinicalDocument`)&&t.includes(`urn:hl7-org:v3`)&&(a={...a,contentType:ZE.CDA_XML})}let o=i??(typeof t==`object`?t:{}),s=await this.createBinary(a,o);return{contentType:a.contentType,url:s.url,title:a.filename}}createBinary(e,t,n,r,i){let a=iO(e,t,n,r),o=i??(typeof t==`object`?t:{}),{data:s,contentType:c,filename:l,securityContext:u,onProgress:d}=a,f=this.fhirUrl(`Binary`);return l&&f.searchParams.set(`_filename`,l),u?.reference&&this.setRequestHeader(o,`X-Security-Context`,u.reference),d?this.uploadwithProgress(f,s,c,d,o):this.post(f,s,c,o)}uploadwithProgress(e,t,n,r,i){return new Promise((a,o)=>{let s=new XMLHttpRequest,c=()=>s.abort();i?.signal?.addEventListener(`abort`,c);let l=e=>{i?.signal?.removeEventListener(`abort`,c),e instanceof Error?o(e):a(e)};if(s.responseType=`json`,s.onabort=()=>l(new DOMException(`Request aborted`,`AbortError`)),s.onerror=()=>l(Error(`Request error`)),r&&(s.upload.onprogress=e=>r(e),s.upload.onload=e=>r(e)),s.onload=()=>{s.status>=200&&s.status<300?l(s.response):l(new Xx(Zx(s.response||s.statusText)))},s.open(`POST`,e),s.withCredentials=!0,s.setRequestHeader(`Authorization`,`Bearer `+this.accessToken),s.setRequestHeader(`Cache-Control`,`no-cache, no-store, max-age=0`),s.setRequestHeader(`Content-Type`,n),this.options.extendedMode!==!1&&s.setRequestHeader(`X-Medplum`,`extended`),i?.headers){let e=i.headers;for(let[t,n]of Object.entries(e))s.setRequestHeader(t,n)}s.send(t)})}async createPdf(e,t,n,r){if(!this.createPdfImpl)throw Error(`PDF creation not enabled`);let i=oO(e,t,n,r),a=typeof t==`object`?t:{},{docDefinition:o,tableLayouts:s,fonts:c,...l}=i,u=await this.createPdfImpl(o,s,c),d={...l,data:u,contentType:`application/pdf`};return this.createBinary(d,a)}createComment(e,t,n){let r=this.getProfile(),i,a;return e.resourceType===`Encounter`&&(i=iC(e),a=e.subject),e.resourceType===`ServiceRequest`&&(i=e.encounter,a=e.subject),e.resourceType===`Patient`&&(a=iC(e)),this.createResource({resourceType:`Communication`,status:`completed`,basedOn:[iC(e)],encounter:i,subject:a,sender:r?iC(r):void 0,sent:new Date().toISOString(),payload:[{contentString:t}]},n)}async updateResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);if(!e.id)throw Error(`Missing id`);let n=await this.put(this.fhirUrl(e.resourceType,e.id),e,void 0,t);return n||=e,this.cacheResource(n,t),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),n}async patchResource(e,t,n,r){let i=await this.patch(this.fhirUrl(e,t),n,r);return this.cacheResource(i,r),this.invalidateUrl(this.fhirUrl(e,t,`_history`)),this.invalidateSearches(e),i}deleteResource(e,t,n){return this.deleteCacheEntry(this.fhirUrl(e,t).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,t),n)}validateResource(e,t){return this.post(this.fhirUrl(e.resourceType,`$validate`),e,void 0,t)}executeBot(e,t,n,r){let i;if(typeof e==`string`){let t=e;i=this.fhirUrl(`Bot`,t,`$execute`)}else{let t=e;i=this.fhirUrl(`Bot`,`$execute`),i.searchParams.set(`identifier`,t.system+`|`+t.value)}return this.post(i,t,n,r)}executeBatch(e,t){return this.post(this.fhirBaseUrl,e,void 0,t)}sendEmail(e,t){return this.post(`email/v1/send`,e,ZE.JSON,t)}graphql(e,t,n,r){return this.post(this.fhirUrl(`$graphql`),{query:e,operationName:t,variables:n},ZE.JSON,r)}readResourceGraph(e,t,n,r){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${n}`,r)}pushToAgent(e,t,n,r,i,a){let{waitTimeout:o,returnAck:s,...c}=a??{};return this.post(this.fhirUrl(`Agent`,oC(e),`$push`),{destination:typeof t==`string`?t:aC(t),body:n,contentType:r,waitForResponse:i,...o===void 0?void 0:{waitTimeout:o},...s===void 0?void 0:{returnAck:s}},ZE.FHIR_JSON,c)}getCdsServices(e){return this.get(this.cdsServicesUrl,e)}callCdsService(e,t,n){return this.post($C(this.cdsServicesUrl,e),t,ZE.JSON,n)}getActiveLogin(){return this.storage.getObject(`activeLogin`)}async setActiveLogin(e){(!this.sessionDetails?.profile||aC(this.sessionDetails.profile)!==e.profile?.reference)&&this.clearActiveLogin(),this.setAccessToken(e.accessToken,e.refreshToken),this.storage.setObject(`activeLogin`,e),this.addLogin(e),this.refreshPromise=void 0,await this.refreshProfile()}getAccessToken(){return this.accessToken}isAuthenticated(e){return this.accessTokenExpires!==void 0&&Date.now()<this.accessTokenExpires-(e??this.refreshGracePeriod)}setAccessToken(e,t){this.accessToken=e,this.refreshToken=t,this.accessTokenExpires=yD(e),this.medplumServer=vD(e)}getLogins(){return this.storage.getObject(`logins`)??[]}addLogin(e){let t=this.getLogins().filter(t=>t.profile?.reference!==e.profile?.reference);t.push(e),this.storage.setObject(`logins`,t)}async refreshProfile(){if(this.medplumServer)return this.profilePromise=new Promise((e,t)=>{this.get(`auth/me`,{cache:`no-cache`}).then(t=>{this.profilePromise=void 0;let n=this.sessionDetails?.profile?.id!==t.profile.id;this.sessionDetails=t,this.syncStoredLoginProject(),n&&this.dispatchEvent({type:`change`}),e(t.profile),this.dispatchEvent({type:`profileRefreshed`})}).catch(t)}),this.dispatchEvent({type:`profileRefreshing`}),this.profilePromise}syncStoredLoginProject(){let e=this.getActiveLogin(),t=this.sessionDetails?.project?.name;if(!e||!t||e.project.display===t)return;let n={...e,project:{...e.project,display:t}};this.storage.setObject(`activeLogin`,n),this.addLogin(n)}isLoading(){return!this.isInitialized||!!this.profilePromise&&!this.sessionDetails?.profile}isSuperAdmin(){return!!this.sessionDetails?.project.superAdmin}isProjectAdmin(){return!!this.sessionDetails?.membership.admin}getProject(){return this.sessionDetails?.project}getProjectMembership(){return this.sessionDetails?.membership}getProfile(){return this.sessionDetails?.profile}async getProfileAsync(){return this.profilePromise?this.profilePromise:this.sessionDetails?this.sessionDetails.profile:this.refreshProfile()}getUserConfiguration(){return this.sessionDetails?.config}getAccessPolicy(){return this.sessionDetails?.accessPolicy}async download(e,t={}){return(await this.downloadResponse(e,t)).blob()}async downloadResponse(e,t={}){this.refreshPromise&&await this.refreshPromise;let n=e.toString();n.startsWith(qD)&&(e=this.fhirUrl(n));let r=t.headers;return r||(r={},t.headers=r),r.Accept||=`*/*`,this.addFetchOptionsDefaults(t),this.fetchWithRetry(e.toString(),t)}async createMedia(e,t){let{additionalFields:n,...r}=e,i=await this.createResource({resourceType:`Media`,status:`preparation`,content:{contentType:e.contentType},...n});r.securityContext||=iC(i);let a=await this.createAttachment(r,t);return this.updateResource({...i,status:`completed`,content:a})}async uploadMedia(e,t,n,r,i){return this.createMedia({data:e,contentType:t,filename:n,additionalFields:r},i)}async createDocumentReference(e,t){let{additionalFields:n,...r}=e,i=await this.createResource({resourceType:`DocumentReference`,status:`current`,content:[{attachment:{contentType:e.contentType}}],...n});r.securityContext||=iC(i);let a=await this.createAttachment(r,t);return this.updateResource({...i,content:[{attachment:a}]})}async bulkExport(e=``,t,n,r){let i=e&&`${e}/`,a=this.fhirUrl(`${i}$export`);return t&&a.searchParams.set(`_type`,t),n&&a.searchParams.set(`_since`,n),this.startAsyncRequest(a.toString(),r)}async startAsyncRequest(e,t={}){this.addFetchOptionsDefaults(t);let n=t.headers;return n.Prefer=`respond-async`,t.method=`POST`,this.request(e,t)}async wrappedFetch(e,t){return await this.refreshIfExpired(),this.addFetchOptionsDefaults(t),this.fetchWithRetry(e,t)}get keyValue(){return this.keyValueClient||=new bD(this),this.keyValueClient}getBundle(e,t){return new xD((async()=>{let n=await this.get(e,t);for(let e of n.entry??iw)this.cacheResource(e.resource,t);return n})())}isCacheEnabled(e){return!!this.requestCache&&!this.getRequestHeader(e,`x-medplum-on-behalf-of`)}getCacheEntry(e,t){if(!this.isCacheEnabled(t)||t?.cache===`no-cache`||t?.cache===`reload`)return;let n=this.requestCache.get(e);if(!(!n||n.requestTime+this.cacheTime<Date.now()))return n}setCacheEntry(e,t,n){this.isCacheEnabled(n)&&(this.requestCache.set(e,{requestTime:Date.now(),value:t}),n?.signal&&n.signal.addEventListener(`abort`,()=>{this.requestCache.delete(e)}))}cacheResource(e,t){e?.id&&!e.meta?.tag?.some(e=>e.code===`SUBSETTED`)&&this.setCacheEntry(this.fhirUrl(e.resourceType,e.id).toString(),new xD(Promise.resolve(e)),t)}deleteCacheEntry(e){this.requestCache&&this.requestCache.delete(e)}async request(e,t={},n={}){let r=await this.wrappedFetch(e,t);if(r.status===401)return this.handleUnauthenticated(e,t,n);if(r.status===204||r.status===304)return;let i=r.headers.get(`content-type`)?.includes(`json`);if(r.status===404&&!i)throw new Xx(Rx);let a=await this.parseBody(r,i);if(r.status===200&&t.followRedirectOnOk||r.status===201&&t.followRedirectOnCreated){let e=await tO(r,a);if(e)return this.request(e,{...t,method:`GET`,body:void 0})}if(r.status===202&&t.pollStatusOnAccepted){let e=await tO(r,a)??n.statusUrl;if(e)return this.pollStatus(e,t,n)}if(r.status>=400)throw new Xx(Zx(a));return a}async parseBody(e,t){let n;if(e.headers.get(`content-length`)!==`0`){if(t)try{n=await e.json()}catch(t){throw console.error(`Error parsing response`,e.status,t),t}else n=await e.text();return n}}async fetchWithRetry(e,t){e.startsWith(`http`)||(e=$C(this.baseUrl,e));let n=t?.maxRetries??this.maxRetries;for(let r=0;r<=n;r++)try{this.logLevel!==`none`&&this.logRequest(e,t);let i=await this.fetch(e,t);if(this.logLevel!==`none`&&this.logResponse(i),this.setCurrentRateLimit(i),r>=n||!sO(i))return i;let a=this.getRetryDelay(r);if(a>(t.maxRetryTime??this.maxRetryTime))return i;await KC(a,{signal:t.signal})}catch(e){if(e.message===`Failed to fetch`&&r===0&&this.dispatchEvent({type:`offline`}),e.name===`AbortError`||r===n)throw e}throw Error(`Unreachable`)}logRequest(e,t){if(console.log(`> ${t.method} ${e}`),this.logLevel===`verbose`&&t.headers){let e=t.headers;for(let t of XC(Object.keys(e)))console.log(`> ${t}: ${e[t]}`)}}logResponse(e){console.log(`< ${e.status} ${e.statusText}`),this.logLevel===`verbose`&&e.headers&&e.headers.forEach((e,t)=>console.log(`< ${t}: ${e}`))}setCurrentRateLimit(e){if(!e?.headers||typeof e.headers.get!=`function`)return;let t=e.headers.get(`ratelimit`);t&&(this.currentRateLimits=t)}rateLimitStatus(){if(!this.currentRateLimits)return[];let e=this.currentRateLimits;return e.split(`,`).map(t=>{let n=t.split(`;`).map(e=>e.trim());if(n.length!==3)throw Error(`Could not parse RateLimit header: `+e);let r=n[0].substring(1,n[0].length-1),i=n.find(e=>e.startsWith(`r=`))?.substring(2),a=i?Number.parseInt(i,10):NaN,o=n.find(e=>e.startsWith(`t=`))?.substring(2),s=o?Number.parseInt(o,10):NaN;if(!r||Number.isNaN(a)||Number.isNaN(s))throw Error(`Could not parse RateLimit header: `+e);return{name:r,remainingUnits:a,secondsUntilReset:s,resetsAfter:Math.ceil((Date.now()+1e3*s)/1e3)}})}getRetryDelay(e){let t=this.rateLimitStatus(),n=500*1.5**e;for(let e of t)e.remainingUnits||(n=Math.max(n,e.secondsUntilReset*1e3));return n}async pollStatus(e,t,n){let r={...t,method:`GET`,body:void 0,redirect:`follow`};return n.pollCount===void 0?(t.headers&&typeof t.headers==`object`&&`Prefer`in t.headers&&(r.headers={...t.headers},delete r.headers.Prefer),n.statusUrl=e,n.pollCount=1):(await KC(t.pollStatusPeriod??1e3,{signal:t.signal}),n.pollCount++),this.request(e,r,n)}async executeAutoBatch(){if(this.autoBatchQueue===void 0)return;let e=[...this.autoBatchQueue];if(this.autoBatchQueue.length=0,this.autoBatchTimerId=void 0,e.length===1){let t=e[0];try{t.options.method=t.method,t.resolve(await this.request($C(this.fhirBaseUrl,t.url),t.options))}catch(e){t.reject(new Xx(Zx(e)))}return}let t={resourceType:`Bundle`,type:`batch`,entry:e.map(e=>({request:{method:e.method,url:e.url},resource:e.options.body?JSON.parse(e.options.body):void 0}))},n=await this.post(this.fhirBaseUrl,t);for(let t=0;t<e.length;t++){let r=e[t],i=n.entry?.[t];i?.response?.outcome&&!Jx(i.response.outcome)?r.reject(new Xx(i.response.outcome)):r.resolve(i?.resource)}}addFetchOptionsDefaults(e){Object.entries(this.defaultHeaders).forEach(([t,n])=>{this.setRequestHeader(e,t,n)}),this.setRequestHeader(e,`Accept`,VD,!0),this.options.extendedMode!==!1&&this.setRequestHeader(e,`X-Medplum`,`extended`),e.body&&this.setRequestHeader(e,`Content-Type`,ZE.FHIR_JSON,!0),this.accessToken?this.setRequestHeader(e,`Authorization`,`Bearer `+this.accessToken):this.basicAuth&&this.setRequestHeader(e,`Authorization`,`Basic `+this.basicAuth),e.cache||=`no-cache`,e.credentials||=`include`}setRequestContentType(e,t){this.setRequestHeader(e,`Content-Type`,t)}getRequestHeader(e,t){let n=e?.headers;if(n){if(Array.isArray(n)){let e=n.find(([e])=>e.toLowerCase()===t.toLowerCase());return e?e[1]:void 0}else if(n instanceof Headers)return n.get(t)??void 0;else if(NC(n))return n[t]??void 0}}setRequestHeader(e,t,n,r=!1){let i=e.headers;i?Array.isArray(i)?(!r||!i.some(([e])=>e.toLowerCase()===t.toLowerCase()))&&i.push([t,n]):i instanceof Headers?(!r||!i.has(t))&&i.set(t,n):NC(i)&&(!r||!i[t])&&(i[t]=n):e.headers={[t]:n}}setRequestBody(e,t){typeof t==`string`||typeof Blob<`u`&&(t instanceof Blob||t?.constructor.name===`Blob`)||typeof File<`u`&&(t instanceof File||t?.constructor.name===`File`)||typeof Uint8Array<`u`&&(t instanceof Uint8Array||t?.constructor.name===`Uint8Array`)?e.body=t:typeof t==`object`&&t&&(typeof t.getReader==`function`||typeof t.pipe==`function`&&typeof t.on==`function`)?(e.body=t,e.duplex=`half`):t&&(e.body=JSON.stringify(t))}async handleUnauthenticated(e,t,n){let r=n.authAttempt??0,i=r+1<YD?this.refresh(void 0,!0):void 0;if(i)return await i,this.request(e,t,{...n,authAttempt:r+1});throw this.clear(),this.onUnauthenticated?.(),new Xx(zx)}async startPkce(){let e=VE();this.storage.setString(`pkceState`,e);let t=VE().slice(0,128);this.storage.setString(`codeVerifier`,t);try{return{codeChallengeMethod:`S256`,codeChallenge:BC(await HE(t)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)}}catch(e){return console.warn(`Failed to hash code verifier. Falling back to 'plain' code challenge method`,e),{codeChallengeMethod:`plain`,codeChallenge:t}}}async requestAuthorization(e){let t=await this.ensureCodeChallenge(e??{}),n=new URL(this.authorizeUrl);n.searchParams.set(`response_type`,`code`),n.searchParams.set(`state`,this.storage.getString(`pkceState`)),n.searchParams.set(`client_id`,t.clientId??this.clientId),n.searchParams.set(`redirect_uri`,t.redirectUri??LE.getOrigin()),n.searchParams.set(`code_challenge_method`,t.codeChallengeMethod),n.searchParams.set(`code_challenge`,t.codeChallenge),n.searchParams.set(`scope`,t.scope??`openid profile`),LE.assign(n.toString())}processCode(e,t){let n={grant_type:XD.AuthorizationCode,code:e,client_id:t?.clientId??this.clientId??``,redirect_uri:t?.redirectUri??LE.getOrigin()},r=this.storage.getString(`codeVerifier`);return r&&(n.code_verifier=r),this.fetchTokens(n)}refreshIfExpired(e){return!this.refreshPromise&&this.accessTokenExpires!==void 0&&!this.isAuthenticated(e)&&this.refresh(e),this.refreshPromise??Promise.resolve()}refresh(e,t=!1){if(this.refreshPromise)return this.refreshPromise;if(!(!this.refreshToken&&!(this.clientId&&this.clientSecret)))return this.refreshPromise=this.runRefreshWithLock(e,t),this.refreshPromise}async runRefreshWithLock(e,t=!1){let n=()=>{let n=this.accessToken,r=this.getActiveLogin();r?.accessToken&&r.accessToken!==this.accessToken&&this.setAccessToken(r.accessToken,r.refreshToken);let i=this.accessToken!==n;return this.isAuthenticated(e)&&(!t||i)?Promise.resolve(this.getProfile()):this.refreshToken?this.fetchTokens({grant_type:XD.RefreshToken,client_id:this.clientId??``,refresh_token:this.refreshToken}):this.clientId&&this.clientSecret?this.startClientLogin(this.clientId,this.clientSecret):Promise.resolve(void 0)},r=typeof navigator<`u`?navigator.locks:void 0;if(!r?.request)return n();let i=`medplum-refresh:${this.storage.makeKey(`activeLogin`)}`;return r.request(i,n)}async startClientLogin(e,t){return this.clientId=e,this.clientSecret=t,this.fetchTokens({grant_type:XD.ClientCredentials,client_id:e,client_secret:t})}async startJwtBearerLogin(e,t,n){return this.clientId=e,this.fetchTokens({grant_type:XD.JwtBearer,client_id:e,assertion:t,scope:n})}async startJwtAssertionLogin(e){return this.fetchTokens({grant_type:XD.ClientCredentials,client_assertion_type:QD.JwtBearer,client_assertion:e})}setBasicAuth(e,t){this.clientId=e,this.clientSecret=t,this.basicAuth=zE(e+`:`+t)}setLogLevel(e){this.logLevel=e,this.options.verbose=e===`verbose`}getLogLevel(){return this.logLevel}setVerbose(e){this.logLevel=e?`verbose`:`none`,this.options.verbose=e}async fhircastSubscribe(e,t){if(!(typeof e==`string`&&e!==``))throw new Xx(Wx(`Invalid topic provided. Topic must be a valid string.`));if(!(typeof t==`object`&&Array.isArray(t)&&t.length>0))throw new Xx(Wx(`Invalid events provided. Events must be an array of event names containing at least one event.`));let n={channelType:`websocket`,mode:`subscribe`,topic:e,events:t},r=(await this.post(this.fhircastHubUrl,cD(n),ZE.FORM_URL_ENCODED))[`hub.channel.endpoint`];if(!r)throw Error(`Invalid response!`);return n.endpoint=r,n}async fhircastUnsubscribe(e){if(!lD(e))throw new Xx(Wx(`Invalid topic or subscriptionRequest. SubscriptionRequest must be an object.`));if(!(e.endpoint&&typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))throw new Xx(Wx(`Provided subscription request must have an endpoint in order to unsubscribe.`));e.mode=`unsubscribe`,await this.post(this.fhircastHubUrl,cD(e),ZE.FORM_URL_ENCODED)}fhircastConnect(e){return new mD(e)}async fhircastPublish(e,t,n,r){return rD(t)?this.post(this.fhircastHubUrl,pD(e,t,n,r),ZE.JSON):(iD(t),this.post(this.fhircastHubUrl,pD(e,t,n),ZE.JSON))}async fhircastGetContext(e){return this.get(`${this.fhircastHubUrl}/${e}`,{cache:`no-cache`})}async invite(e,t){return this.post(`admin/projects/`+e+`/invite`,t)}async handleTokenError(e){try{let t=await e.json();throw qx(t)?new Xx(t):t.error_description?new Xx(Ux(t.error_description)):Error(JSON.stringify(t))}catch(e){throw e instanceof Xx?(e.message=`Failed to fetch tokens: ${e.message}`,e):new Xx(Ux(`Failed to fetch tokens`),{cause:e})}}async fetchTokens(e){let t=new URLSearchParams(e),n={...this.defaultHeaders,"Content-Type":ZE.FORM_URL_ENCODED};this.basicAuth&&(n.Authorization=`Basic ${this.basicAuth}`),this.credentialsInHeader&&(t.delete(`client_id`),t.delete(`client_secret`),!this.basicAuth&&e.client_id&&e.client_secret&&(n.Authorization=`Basic ${zE(e.client_id+`:`+e.client_secret)}`));let r={method:`POST`,headers:n,body:t.toString(),credentials:`include`},i;try{i=await this.fetchWithRetry(this.tokenUrl,r)}catch(e){throw this.refreshPromise=void 0,e}i.ok||(this.clearActiveLogin(),this.onUnauthenticated?.(),await this.handleTokenError(i));let a=await i.json();return await this.verifyTokens(a),this.getProfile()}async verifyTokens(e){let t=e.access_token;if(gD(t)){let e=_D(t);if(Date.now()>=e.exp*1e3)throw this.clearActiveLogin(),new Xx(Bx);if(e.cid){if(e.cid!==this.clientId)throw this.clearActiveLogin(),new Xx(Vx)}else if(this.clientId&&e.client_id!==this.clientId)throw this.clearActiveLogin(),new Xx(Vx)}return this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile})}checkSessionDetailsMatchLogin(e){return this.sessionDetails&&e?e.profile?.reference?.endsWith(this.sessionDetails.profile.id)??!1:!0}setupStorageListener(){try{window.addEventListener(`storage`,e=>{if(e.key===null)LE.reload();else if(e.key===this.storage.makeKey(`activeLogin`)){let t=e.oldValue?JSON.parse(e.oldValue):void 0,n=e.newValue?JSON.parse(e.newValue):void 0;t?.profile.reference!==n?.profile.reference||!this.checkSessionDetailsMatchLogin(n)?LE.reload():n?this.setAccessToken(n.accessToken,n.refreshToken):this.clear()}})}catch{}}getSubscriptionManager(){return this.subscriptionManager||=new RD(this,ew(this.baseUrl,`/ws/subscriptions-r4`)),this.subscriptionManager}subscribeToCriteria(e,t){return this.getSubscriptionManager().addCriteria(e,t)}unsubscribeFromCriteria(e,t){this.subscriptionManager&&this.subscriptionManager.removeCriteria(e,t)}getMasterSubscriptionEmitter(){return this.getSubscriptionManager().getMasterEmitter()}};function eO(){if(!globalThis.fetch)throw Error(`Fetch not available in this environment`);return globalThis.fetch.bind(globalThis)}async function tO(e,t){let n=e.headers.get(`content-location`);if(n)return n;let r=e.headers.get(`location`);if(r)return r;if(qx(t)&&t.issue?.[0]?.diagnostics)return t.issue[0].diagnostics}function nO(e){let t=e.entry?.map(e=>e.resource)??[];return Object.assign(t,{bundle:e})}function rO(e){return NC(e)&&`data`in e&&`contentType`in e}function iO(e,t,n,r){return rO(e)?e:{data:e,filename:t,contentType:n,onProgress:r}}function aO(e){return NC(e)&&`docDefinition`in e}function oO(e,t,n,r){return aO(e)?e:{docDefinition:e,filename:t,tableLayouts:n,fonts:r}}function sO(e){return e.status===429||e.status>=500}function cO({parentContext:e,path:t,elements:n,profileUrl:r,debugMode:i,accessPolicyResource:a}){if(t===e?.path)return;i??=e?.debugMode??!1,a??=e?.accessPolicyResource;let o=lO(t,n,e,!!i),s=qC(t,`.`,2)[1];o=uO(o,a,s),o=dO(o,a,s);let c=Object.create(null);for(let[e,n]of Object.entries(o))c[t+`.`+e]=n;let l;if(e&&!e.isDefaultContext)l=e.getExtendedProps;else{let e=Object.create(null);l=t=>{let n=qC(t,`.`,2)[1];if(n){if(!e[n]){let t=fO(n,a?.hiddenFields);e[n]={hidden:t,readonly:t||fO(n,a?.readonlyFields)}}return e[n]}}}return{path:t,elements:o,elementsByPath:c,profileUrl:r??e?.profileUrl,debugMode:i,getExtendedProps:l,accessPolicyResource:a}}function lO(e,t,n,r){let i=Object.create(null);if(n)for(let[t,r]of Object.entries(n.elementsByPath)){let n=WC(e,t);n!==void 0&&(i[n]=r)}let a=!1;if(t)for(let[e,n]of Object.entries(t))e in i||(i[e]=n,a=!0);return r&&console.assert(a,`Unnecessary ElementsContext; not using any newly provided elements`),i}function uO(e,t,n){if(!t?.hiddenFields?.length)return e;let r=n?n+`.`:``;return Object.fromEntries(Object.entries(e).filter(([e])=>!fO(r+e,t.hiddenFields)))}function dO(e,t,n){if(!t?.readonlyFields?.length)return e;let r=Object.create(null),i=n?n+`.`:``;for(let[n,a]of Object.entries(e))fO(i+n,t.readonlyFields)?r[n]={...a,readonly:!0}:r[n]=a;return r}function fO(e,t){if(!t?.length)return!1;let n=e.split(`.`);for(let e=1;e<=n.length;e++){let r=n.slice(0,e).join(`.`);if(t.includes(r))return!0}return!1}function pO(e){return e.type!==void 0&&e.type.length>0}function mO(e,t,n,r){let i=wS(e,t.path,{profileUrl:r});if(i){let e=n.typeSchema?.elements??n.elements;return i.some(r=>OS(r,t,n,e))??!1}return console.assert(!1,`getNestedProperty[%s] in isDiscriminatorComponentMatch missed`,t.path),!1}function hO(e,t,n,r){if(e)for(let i of t){let t={value:e,type:i.typeSchema?.type??i.type?.[0].code};if(n.every(e=>mO(t,e,i,i.typeSchema?.url??r)))return i.name}}var gO=class{rootSchema;visitor;elementsContextStack;sliceAllowList;constructor(e,t,n){if(e.type===void 0)throw Error(`schema must include a type`);this.rootSchema=e;let r=cO({parentContext:void 0,path:this.rootSchema.type,elements:n??this.rootSchema.elements,profileUrl:this.rootSchema.name===this.rootSchema.type?void 0:this.rootSchema.url});if(r===void 0)throw Error(`Could not create root elements context`);this.elementsContextStack=[r],this.visitor=t}get elementsContext(){return this.elementsContextStack.at(-1)}crawlElement(e,t,n){this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema);let r=Object.fromEntries(Object.entries(this.elementsContext.elements).filter(([e])=>e.startsWith(t)));this.crawlElementsImpl(r,n),this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlSlice(e,t,n){let r=this.prepareSlices(n.slices,n);if(!CC(r.slices))throw Error(`cannot crawl slice ${t.name} since it has no type information`);this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema),this.sliceAllowList=[t],this.crawlSliceImpl(r.slices[0],t.path,r),this.sliceAllowList=void 0,this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlResource(){this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema),this.crawlElementsImpl(this.rootSchema.elements,this.rootSchema.type),this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlElementsImpl(e,t){let n=_O(e);for(let e of n)this.crawlElementNode(e,t)}crawlElementNode(e,t){let n=t+`.`+e.key;this.visitor.onEnterElement&&this.visitor.onEnterElement(n,e.element,this.elementsContext);for(let n of e.children)this.crawlElementNode(n,t);CC(e.element?.slicing?.slices)&&this.crawlSlicingImpl(e.element.slicing,n),this.visitor.onExitElement&&this.visitor.onExitElement(n,e.element,this.elementsContext)}prepareSlices(e,t){let n=[];for(let t of e){if(!pO(t))continue;let e=t.type.find(e=>CC(e.profile))?.profile?.[0];if(CC(e)){let n=hS(e);n&&(t.typeSchema=n)}n.push(t)}return{...t,slices:n}}crawlSlicingImpl(e,t){let n=this.prepareSlices(e.slices,e);for(let e of n.slices)(this.sliceAllowList===void 0||this.sliceAllowList.includes(e))&&this.crawlSliceImpl(e,t,n)}crawlSliceImpl(e,t,n){let r=e.typeSchema;r&&this.visitor.onEnterSchema&&this.visitor.onEnterSchema(r),this.visitor.onEnterSlice&&this.visitor.onEnterSlice(t,e,n);let i,a=r?.elements??e.elements;CC(a)&&(i=cO({path:t,parentContext:this.elementsContext,elements:a})),i&&this.elementsContextStack.push(i),this.crawlElementsImpl(a,t),i&&this.elementsContextStack.pop(),this.visitor.onExitSlice&&this.visitor.onExitSlice(t,e,n),r&&this.visitor.onExitSchema&&this.visitor.onExitSchema(r)}};function _O(e){let t=[];function n(e,t){return t.startsWith(e+`.`)}function r(e,t){for(let i of e.children)if(n(i.key,t.key)){r(i,t);return}e.children.push(t)}let i=Object.entries(e);i.sort((e,t)=>e[0].localeCompare(t[0]));for(let[e,a]of i){let i={key:e,element:a,children:[]},o=!1;for(let a of t)if(n(a.key,e)){r(a,i),o=!0;break}o||t.push(i)}return t}var vO=`__sliceName`;function yO(e,t){let n=new xO(e,e.resourceType,`resource`);return new gO(t,n).crawlResource(),n.getDefaultValue()}function bO(e,t,n){for(let[r,i]of Object.entries(t)){if(n===void 0||n===r){TO(e,r,i,t);continue}let a=WC(n,r);a!==void 0&&TO(e,a,i,t)}return e}var xO=class{rootValue;schemaStack;valueStack;constructor(e,t,n){this.schemaStack=[],this.valueStack=[],this.rootValue=jC(e),this.valueStack.splice(0,this.valueStack.length,{type:n,path:t,values:[this.rootValue]})}get schema(){return this.schemaStack.at(-1)}get value(){return this.valueStack.at(-1)}onEnterSchema(e){this.schemaStack.push(e)}onExitSchema(){this.schemaStack.pop()}onEnterElement(e,t,n){let r=this.value.values,i=this.value.path,a=WC(i,e);if(a===void 0)throw Error(`Expected ${e} to be prefixed by ${i}`);let o=[];for(let e of r){if(e===void 0)continue;let r=WC(n.path,i),s=Array.isArray(e)?e:[e];for(let e of s){SO(e,a,t,n.elements,r),TO(e,a,t,n.elements);let i=wO(e,a,n.elements,r);i!==void 0&&o.push(i)}}this.valueStack.push({type:`element`,path:e,values:o})}onExitElement(e,t,n){if(!this.valueStack.pop())throw Error(`Expected value context to exist when exiting element`);let r=WC(this.value.path,e);if(r===void 0)throw Error(`Expected ${e} to be prefixed by ${this.value.path}`);let i=WC(n.path,this.value.path);for(let e of this.value.values){let a=wO(e,r,n.elements,i);if(Array.isArray(a))for(let e=a.length-1;e>=0;e--){let t=a[e];CC(t)||a.splice(e,1)}SC(a)&&CO(e,void 0,r,t)}}onEnterSlice(e,t,n){let r=this.value.values,i=[];for(let e of r)if(e!==void 0){let r=Array.isArray(e)?e:[e],a=this.getMatchingSliceValues(r,t,n);i.push(a)}this.valueStack.push({type:`slice`,path:e,values:i})}getMatchingSliceValues(e,t,n){let r=[];for(let i of e)(i[vO]??hO(i,[t],n.discriminator,this.schema.url))===t.name&&r.push(i);for(let n=r.length;n<t.min;n++)if(UC(t.type[0].code)){let t=Object.create(null);r.push(t),e.push(t)}return r}onExitSlice(){let e=this.valueStack.pop();if(!e)throw Error(`Expected value context to exist in onExitSlice`);for(let t of e.values)for(let e=t.length-1;e>=0;e--){let n=t[e];vO in n&&delete n[vO]}}getDefaultValue(){return this.rootValue}};function SO(e,t,n,r,i){let a=wO(e,t,r,i);n.min>0&&a===void 0&&UC(n.type[0].code)&&(n.isArray?CO(e,[Object.create(null)],t,n):CO(e,Object.create(null),t,n))}function CO(e,t,n,r){if(n.includes(`.`))throw Error(`key cannot be nested`);let i=n;if(n.includes(`[x]`)){let e=r.type[0].code;i=n.replace(`[x]`,HC(e))}t===void 0?delete e[i]:e[i]=t}function wO(e,t,n,r){let i=t.split(`.`),a=e,o;for(let e=0;e<i.length;e++){let t=i[e];if(t.includes(`[x]`)){let a=n[(r?r+`.`:``)+i.slice(0,e+1).join(`.`)].type[0].code;t=t.replace(`[x]`,HC(a))}if(e===i.length-1){o=Array.isArray(a)?a.map(e=>e[t]):a[t];continue}if(Array.isArray(a))a=a.map(e=>e[t]);else if(NC(a)){if(a[t]===void 0)return;a=a[t]}else return}return o}function TO(e,t,n,r){if(!(n.fixed||n.pattern))return e;if(Array.isArray(e))return e.map(e=>TO(e,t,n,r));e??=Object.create(null);let i=e,a=t.split(`.`),o=i;for(let e=0;e<a.length;e++){let t=a[e];if(t.includes(`[x]`)){let n=r[a.slice(0,e+1).join(`.`)].type[0].code;t=t.replace(`[x]`,HC(n))}if(e===a.length-1){let e=Array.isArray(o)?o:[o];for(let r of e)n.fixed?r[t]??=n.fixed.value:n.pattern&&(r[t]=EO(r[t],n.pattern.value))}else{if(!(t in o)){let n=a.slice(0,e+1).join(`.`);o[t]=r[n].isArray?[Object.create(null)]:Object.create(null)}o=o[t]}}return i}function EO(e,t){if(Array.isArray(t)&&(Array.isArray(e)||e===void 0))return(e?.length??0)>0?e:jC(t);if(NC(t)&&(NC(e)&&!Array.isArray(e)||e===void 0)){let n=jC(e)??Object.create(null);for(let e of Object.keys(t))n[e]=EO(n[e],t[e]);return n}return e}var DO=Object.prototype.hasOwnProperty;function OO(e){return e===void 0?`undefined`:e===null?`null`:Array.isArray(e)?`array`:typeof e}function kO(e,t){let n=[];for(let r in e)DO.call(e,r)&&e[r]!==void 0&&!(DO.call(t,r)&&t[r]!==void 0)&&n.push(r);return n}function AO(e,t){let n=[];for(let r in e)DO.call(e,r)&&e[r]!==void 0&&DO.call(t,r)&&t[r]!==void 0&&n.push(r);return n}function jO(e){return e.op===`add`}function MO(e){return e.op===`remove`}function NO(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function PO(e,t,n,r=IO){let i=Math.max(e.length,t.length),a=new Map([[0,{operations:[],cost:0}]]);function o(s,c){let l=s*i+c,u=a.get(l);if(u===void 0){if(s>0&&c>0&&!r(e[s-1],t[c-1],n.add(String(s-1))).length)u=o(s-1,c-1);else{let n=[];if(s>0){let e=o(s-1,c),t={op:`remove`,index:s-1};n.push(NO(e,t))}if(c>0){let e=o(s,c-1),r={op:`add`,index:s-1,value:t[c-1]};n.push(NO(e,r))}if(s>0&&c>0){let r=o(s-1,c-1),i={op:`replace`,index:s-1,original:e[s-1],value:t[c-1]};n.push(NO(r,i))}u=n.sort((e,t)=>e.cost-t.cost)[0]}a.set(l,u)}return u}let s=isNaN(e.length)||e.length<=0?0:e.length,[c]=o(s,isNaN(t.length)||t.length<=0?0:t.length).operations.reduce(([e,t],i)=>{if(jO(i)){let r=i.index+1+t,a=r<s+t?String(r):`-`,o={op:i.op,path:n.add(a).toString(),value:i.value};return[e.concat(o),t+1]}else if(MO(i)){let r={op:i.op,path:n.add(String(i.index+t)).toString()};return[e.concat(r),t-1]}else{let a=n.add(String(i.index+t)),o=r(i.original,i.value,a);return[e.concat(...o),t]}},[[],0]);return c}function FO(e,t,n,r=IO){let i=[];return kO(e,t).forEach(e=>{i.push({op:`remove`,path:n.add(e).toString()})}),kO(t,e).forEach(e=>{i.push({op:`add`,path:n.add(e).toString(),value:t[e]})}),AO(e,t).forEach(a=>{i.push(...r(e[a],t[a],n.add(a)))}),i}function IO(e,t,n,r=IO){if(e===t)return[];let i=OO(e),a=OO(t);return i===`array`&&a===`array`?PO(e,t,n,r):i===`object`&&a===`object`?FO(e,t,n,r):[{op:`replace`,path:n.toString(),value:t}]}function LO(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function RO(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}var zO=class e{tokens;constructor(e=[``]){this.tokens=e}static fromJSON(t){let n=t.split(`/`).map(LO);if(n[0]!==``)throw Error(`Invalid JSON Pointer: ${t}`);return new e(n)}toString(){return this.tokens.map(RO).join(`/`)}evaluate(e){let t=null,n=``,r=e;for(let e=1,i=this.tokens.length;e<i;e++){if(t=r,n=this.tokens[e],n===`__proto__`||n===`constructor`||n===`prototype`)throw Error(`Invalid path: `+this.toString());if(t!=null&&(typeof t==`object`||typeof t==`function`)&&!Object.hasOwn(t,n)&&n in t)throw Error(`Invalid inherited key: `+n);r=t?.[n]}return{parent:t,key:n,value:r}}get(e){return this.evaluate(e).value}set(e,t){let n=this.evaluate(e);n.parent&&(n.parent[n.key]=t)}push(e){this.tokens.push(e)}add(t){return new e(this.tokens.concat(String(t)))}parent(){return new e(this.tokens.length>1?this.tokens.slice(0,-1):[``])}};function BO(e){function t(n,r,i){let a=e(n,r,i);return Array.isArray(a)?a:IO(n,r,i,t)}return t}function VO(e,t,n){let r=new zO;return(n?BO(n):IO)(e,t,r)}function HO(e){return e.match(/^\((.+)\)\.identifier$/)?.[1]}function UO(e,t){return new Qw(e,new lT(t,new eT(`identifier`)))}var WO={BOOLEAN:`BOOLEAN`,NUMBER:`NUMBER`,QUANTITY:`QUANTITY`,TEXT:`TEXT`,REFERENCE:`REFERENCE`,CANONICAL:`CANONICAL`,DATE:`DATE`,DATETIME:`DATETIME`,PERIOD:`PERIOD`,UUID:`UUID`};function GO(e,t){return Uw.types[e]?.searchParamsDetails?.[t.code]??qO(e,t)}function KO(e,t,n){let r=Uw.types[e];r||(r={},Uw.types[e]=r),r.searchParamsDetails||={},r.searchParamsDetails[t]=n}function qO(e,t){let n=t.code,r=t.expression,i=QO(e,r),a={elementDefinitions:[],propertyTypes:new Set,array:!1};for(let n of i){let r=tk(n),i=JC(()=>r.join(`.`));r.length===1&&r[0]instanceof wx&&r[0].operator!==`.`?a.propertyTypes.add(`boolean`):t.code.endsWith(`:identifier`)?a.propertyTypes.add(`Identifier`):i().endsWith(`extension.value.code`)||i().endsWith(`extension.value.coding.code`)?(a.array=!0,a.propertyTypes.clear(),a.propertyTypes.add(`code`)):JO(a,r,e,1),i().endsWith(`extension.valueDateTime`)&&(a.array=!1,a.propertyTypes.clear(),a.propertyTypes.add(`dateTime`))}let o;if(t.code.endsWith(`:identifier`)){let t=HO(r);if(t===void 0)throw Error(`Unexpected expression for derived identifier search parameter: ${r}`);o=UO(r,$O(e,t))}else o=$O(e,r);let s=a.elementDefinitions.map(e=>({...e,type:e.type?.filter(e=>a.propertyTypes.has(e.code))})).filter(e=>e.type&&e.type.length>0),c={type:ZO(t,a.propertyTypes),elementDefinitions:s,parsedExpression:o,array:a.array,referenceTargetTypes:nk(t,s)};return KO(e,n,c),c}function JO(e,t,n,r){let i=t[r];if(i instanceof rT){e.propertyTypes.add(i.right.toString());return}if(i instanceof bT){YO(e,i);return}let a=i.toString(),o=zw(n,a);if(!o)throw Error(`Element definition not found for ${n} ${a}`);let s=!1,c=r+1;c<t.length&&t[c]instanceof xT&&(s=!0,c++);let l=t[c];if(o.isArray&&!s&&(e.array=!0),c===t.length-1){if(l instanceof rT){e.elementDefinitions.push(o),e.propertyTypes.add(l.right.toString());return}if(l instanceof bT&&l.name===`ofType`){e.elementDefinitions.push(o),e.propertyTypes.add(l.args[0].toString());return}}if(c>=t.length){e.elementDefinitions.push(o);for(let t of o.type??iw)e.propertyTypes.add(t.code);return}for(let n of o.type??iw){let r=n.code;XO(r)&&(r=o.type[0].code),JO(e,t,r,c)}}function YO(e,t){if(t.name===`as`){e.propertyTypes.add(t.args[0].toString());return}if(t.name===`ofType`){e.propertyTypes.add(t.args[0].toString());return}if(t.name===`resolve`){e.propertyTypes.add(`string`);return}if(t.name===`where`&&t.args[0]instanceof hT){e.propertyTypes.add(t.args[0].right.toString());return}throw Error(`Unhandled FHIRPath function: ${t.name}`)}function XO(e){return e===`Element`||e===`BackboneElement`}function ZO(e,t){switch(e.type){case`date`:return t.size===1&&t.has(X.date)?WO.DATE:WO.DATETIME;case`number`:return WO.NUMBER;case`quantity`:return WO.QUANTITY;case`reference`:return t.has(X.canonical)?WO.CANONICAL:WO.REFERENCE;case`token`:return t.size===1&&t.has(X.boolean)?WO.BOOLEAN:WO.TEXT;default:return WO.TEXT}}function QO(e,t){let n=[];return ek(e,IT(t).child,n),n}function $O(e,t){let n=[],r=IT(t);if(ek(e,r.child,n),n.length===0)return r;let i=n[0];for(let e=1;e<n.length;e++)i=new uT(i,n[e]);return new Qw(`<original-not-available>`,i)}function ek(e,t,n){t instanceof uT?(ek(e,t.left,n),ek(e,t.right,n)):t.toString().includes(e+`.`)&&n.push(t)}function tk(e){return e instanceof rT||e instanceof xT?[tk(e.left),e].flat():e instanceof wx&&e.operator!==`.`?[e]:e instanceof lT?[tk(e.left),tk(e.right)].flat():e instanceof bT&&(e.name===`where`&&!(e.args[0]instanceof hT)||e.name===`last`)?[]:[e]}function nk(e,t){if(e.target?.length===1)return e.target;if(t){let e=new Set;for(let n of t)for(let t of n.type)if(!(t.code!==`Reference`||!t.targetProfile))for(let n of t.targetProfile){let t=n.split(`/`).at(-1);t&&t!==`Resource`&&e.add(t)}if(e.size>0)return Array.from(e)}}var rk=`https://meta.medplum.com/releases`,ik=new Map;function ak(e){let t=e;if(!t.tag_name?.startsWith(`v`))throw Error(`Manifest missing valid tag_name starting with a 'v' (eg. v5.1.15)`);let n=t.assets;if(!n?.length)throw Error(`Manifest missing assets list`);for(let e of n){if(!e.browser_download_url)throw Error(`Asset missing browser download URL`);if(!e.name)throw Error(`Asset missing name`)}}async function ok(e,t,n){let r=t?ik.get(t):void 0;if(!r){let i=t?`v${t}`:`latest`,a=new URL(`${rk}/${i}.json`);if(a.searchParams.set(`a`,e),a.searchParams.set(`c`,BD),n)for(let[e,t]of Object.entries(n))a.searchParams.set(e,t);let o=await fetch(a.toString());if(o.status!==200){let e;try{e=(await o.json()).message}catch(e){console.error(`Failed to parse message from body: ${Y(e)}`)}throw Error(`Received status code ${o.status} while fetching manifest for version '${t??`latest`}'. Message: ${e}`)}let s=await o.json();ak(s),r=s,ik.set(r.tag_name.slice(1),r)}return r}async function sk(e){let t=await ok(e);if(!t.tag_name.startsWith(`v`))throw Error(`Invalid release name found. Release tag '${t.tag_name}' did not start with 'v'`);return t.tag_name.slice(1)}var ck=(0,b.createContext)(void 0);function lk(){return(0,b.useContext)(ck)}function Q(){return lk().medplum}function uk(){return lk().navigate}function dk(){return lk().profile}var fk=[`change`,`storageInitialized`,`storageInitFailed`,`profileRefreshing`,`profileRefreshed`];function pk(e){let t=e.medplum,n=e.navigate??mk,[r,i]=(0,b.useState)({profile:t.getProfile(),loading:t.isLoading()});(0,b.useEffect)(()=>{function e(){i(e=>({...e,profile:t.getProfile(),loading:t.isLoading()}))}for(let n of fk)t.addEventListener(n,e);return()=>{for(let n of fk)t.removeEventListener(n,e)}},[t]);let a=(0,b.useMemo)(()=>({...r,medplum:t,navigate:n}),[r,t,n]);return(0,I.jsx)(ck.Provider,{value:a,children:e.children})}function mk(e){window.location.assign(e)}var hk=new Map,gk=e=>(0,b.useMemo)(()=>{if(!e)return;let t=e.split(`?`)[0];if(!t)return e;let n;try{n=new URLSearchParams(new URL(e).search)}catch{return e}if(!n.has(`Key-Pair-Id`)||!n.has(`Signature`))return e;let r=n.get(`Expires`);if(!r||r.length>13)return e;let i=hk.get(t);if(i){let e=new URLSearchParams(new URL(i).search).get(`Expires`);if(e&&Number.parseInt(e,10)*1e3-5e3>Date.now())return i}return hk.set(t,e),e},[e]),_k=3e3;function vk(e,t,n){let r=Q(),i=dk()?e:void 0,[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(n?.subscriptionProps),l=(0,b.useRef)(!1),u=(0,b.useRef)(void 0),d=(0,b.useRef)(void 0),f=(0,b.useRef)(void 0),p=(0,b.useRef)(t);p.current=t;let m=(0,b.useRef)(n?.onWebSocketOpen);m.current=n?.onWebSocketOpen;let h=(0,b.useRef)(n?.onWebSocketClose);h.current=n?.onWebSocketClose;let g=(0,b.useRef)(n?.onSubscriptionConnect);g.current=n?.onSubscriptionConnect;let _=(0,b.useRef)(n?.onSubscriptionDisconnect);_.current=n?.onSubscriptionDisconnect;let v=(0,b.useRef)(n?.onError);v.current=n?.onError,(0,b.useEffect)(()=>{TC(n?.subscriptionProps,s)||c(n?.subscriptionProps)},[s,n]),(0,b.useEffect)(()=>{u.current&&=(clearTimeout(u.current),void 0);let e=!1;return(d.current!==i||!TC(f.current,s))&&(e=!0),e&&d.current&&r.unsubscribeFromCriteria(d.current,f.current),d.current=i,f.current=s,e&&i?o(r.subscribeToCriteria(i,s)):i||o(void 0),()=>{u.current=setTimeout(()=>{o(void 0),i&&r.unsubscribeFromCriteria(i,s)},_k)}},[r,i,s]);let y=(0,b.useCallback)(e=>{p.current?.(e.payload)},[]),x=(0,b.useCallback)(()=>{m.current?.()},[]),S=(0,b.useCallback)(()=>{h.current?.()},[]),C=(0,b.useCallback)(e=>{g.current?.(e.payload.subscriptionId)},[]),w=(0,b.useCallback)(e=>{_.current?.(e.payload.subscriptionId)},[]),T=(0,b.useCallback)(e=>{v.current?.(e.payload)},[]);(0,b.useEffect)(()=>a?(l.current||=(a.addEventListener(`message`,y),a.addEventListener(`open`,x),a.addEventListener(`close`,S),a.addEventListener(`connect`,C),a.addEventListener(`disconnect`,w),a.addEventListener(`error`,T),!0),()=>{l.current=!1,a.removeEventListener(`message`,y),a.removeEventListener(`open`,x),a.removeEventListener(`close`,S),a.removeEventListener(`connect`,C),a.removeEventListener(`disconnect`,w),a.removeEventListener(`error`,T)}):()=>void 0,[a,y,x,S,C,w,T])}function yk(e){let t=Q(),{resourceType:n,countCriteria:r,subscriptionCriteria:i}=e,[a,o]=(0,b.useState)(0),s=(0,b.useCallback)(e=>{t.search(n,r,{cache:e}).then(e=>o(e.total)).catch(console.error)},[t,n,r]);return(0,b.useEffect)(()=>{s(`default`)},[s]),vk(i,()=>{s(`reload`)}),a}function bk(e,t){let n=Q(),[r,i]=(0,b.useState)(()=>xk(n,e)),a=(0,b.useCallback)(e=>{TC(e,r)||i(e)},[r]);return(0,b.useEffect)(()=>{let r=!0,i=xk(n,e);return!i&&Hw(e)?n.readReference(e).then(e=>{r&&a(e)}).catch(e=>{r&&(a(void 0),t&&t(Zx(e)))}):a(i),(()=>r=!1)},[n,e,a,t]),r}function xk(e,t){if(t){if(Vw(t))return t;if(Hw(t))return e.getCachedReference(t)}}var Sk={group:`group`,display:`display`,question:`question`,boolean:`boolean`,decimal:`decimal`,integer:`integer`,date:`date`,dateTime:`dateTime`,time:`time`,string:`string`,text:`text`,url:`url`,choice:`choice`,openChoice:`open-choice`,attachment:`attachment`,reference:`reference`,quantity:`quantity`},Ck=`${Ox}/fhir/StructureDefinition/questionnaire-itemControl`,wk=`${Ox}/fhir/StructureDefinition/questionnaire-referenceFilter`,Tk=`${Ox}/fhir/StructureDefinition/questionnaire-referenceResource`,Ek=`${Ox}/fhir/StructureDefinition/questionnaire-validationError`,Dk=`${Ox}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression`,Ok=`${Ox}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression`,kk=`${Ox}/fhir/StructureDefinition/questionnaire-signatureRequired`,Ak=`${Ox}/fhir/StructureDefinition/questionnaireresponse-signature`,jk=`${Ox}/fhir/StructureDefinition/questionnaire-hidden`;function Mk(e){return e.type===`choice`||e.type===`open-choice`}function Nk(e,t){return{...t,item:Pk(e.item,t.item,t)}}function Pk(e,t,n){if(!t)return t;let r=[];for(let i of t){let t=e?.find(e=>e.linkId===i.linkId);t&&!Fk(t,n)||(t?.item&&i.item?r.push({...i,item:Pk(t.item,i.item,n)}):r.push(i))}return r}function Fk(e,t){if(_C(e,jk)?.valueBoolean===!0)return!1;let n=Ik(e,t);return n===void 0?Lk(e,t):n}function Ik(e,t){let n=_C(e,Dk);if(t&&n){let e=n.valueExpression?.expression;if(e){let n=AS(t);return jS(RT(e,[n],{"%resource":n}))}}}function Lk(e,t){if(!e.enableWhen)return!0;let n=e.enableBehavior??`any`;for(let r of e.enableWhen){let e=Wk(t?.item,r.question);if(r.operator===`exists`&&!r.answerBoolean&&!e?.length){if(n===`any`)return!0;continue}let{anyMatch:i,allMatch:a}=Kk(r,e,n);if(n===`any`&&i)return!0;if(n===`all`&&!a)return!1}return n!==`any`}function Rk(e,t,n=t.item){for(let r of e){let e=n?.find(e=>e.linkId===r.linkId);e&&(zk(t,r,e),r.item&&e.item&&Rk(r.item,t,e.item))}}function zk(e,t,n){try{let r=Hk(t,e);if(!r)return;let i=Vk(t,r);if(!i)return;n.answer=[i]}catch(e){n.extension=[{url:Ek,valueString:`Expression evaluation failed: ${Y(e)}`}]}}var Bk={[Sk.boolean]:[X.boolean],[Sk.date]:[X.date],[Sk.dateTime]:[X.dateTime],[Sk.time]:[X.time],[Sk.url]:[X.string,X.uri,X.url],[Sk.attachment]:[X.Attachment],[Sk.reference]:[X.Reference],[Sk.quantity]:[X.Quantity],[Sk.decimal]:[X.decimal,X.integer],[Sk.integer]:[X.decimal,X.integer]};function Vk(e,t){if(e.type){if(e.type===Sk.choice||e.type===Sk.openChoice)return{[`value${HC(t.type)}`]:t.value};if(e.type===Sk.string||e.type===Sk.text)return typeof t.value==`string`?{valueString:t.value}:void 0;if(Bk[e.type]?.includes(t.type))return{[`value${HC(e.type)}`]:t.value}}}function Hk(e,t){if(!t)return;let n=_C(e,Ok);if(n){let e=n.valueExpression?.expression;if(e){let n=AS(t),r=RT(e,[n],{"%resource":n});return r.length===0?void 0:r[0]}}}function Uk(e,t,n){let r=[];for(let i of e){let e=n.answerOption?.find(e=>aw(rA(e))===i);if(e){let n=rA(e);n&&r.push({[t]:n.value})}}return r}function Wk(e,t){for(let n of e??iw){if(n.linkId===t)return n.answer;if(n.item){let e=Wk(n.item,t);if(e)return e}}}function Gk(e,t,n){if(n===`exists`)return!!e===t.value;if(e){let[{value:r}]=RT(`%actualAnswer ${n===`=`||n===`!=`?n?.replace(`=`,`~`):n} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":t});return r}else return!1}function Kk(e,t,n){let r=t||[],i=iA(e),a=!1,o=!0;for(let t of r){let r=aA(t),{operator:s}=e;if(Gk(r,i,s)?a=!0:o=!1,n===`any`&&a)break}return{anyMatch:a,allMatch:o}}function qk(e){let t=_C(e,Tk);if(t){if(t.valueCode!==void 0)return[t.valueCode];if(t.valueCodeableConcept)return t.valueCodeableConcept?.coding?.map(e=>e.code)}}function Jk(e,t){let n=jC(e),r=_C(n,Tk);return!t||t.length===0?(r&&(n.extension=n.extension?.filter(e=>e!==r)),n):(r||(n.extension??=[],r={url:Tk},n.extension.push(r)),t.length===1?(r.valueCode=t[0],delete r.valueCodeableConcept):(r.valueCodeableConcept={coding:t.map(e=>({code:e}))},delete r.valueCode),n)}function Yk(e,t,n){let r=_C(e,wk);if(!r?.valueString)return;let i=r.valueString;t?.reference&&(i=i.replaceAll(`$subj`,t.reference)),n?.reference&&(i=i.replaceAll(`$encounter`,n.reference));let a={},o=i.split(`&`);for(let e of o){let[t,n]=qC(e,`=`,2);a[t]=n}return a}function Xk(e,t){return{resourceType:`QuestionnaireResponse`,questionnaire:e.url??aC(e),item:Zk(e.item,t?.item),status:`in-progress`}}function Zk(e,t){let n;for(let r of e??iw){if(r.type===Sk.display)continue;let e=t?.filter(e=>e.linkId===r.linkId);if(e?.length)for(let t of e)t.id=t.id??eA(),t.text=t.text??r.text,t.item=Zk(r.item,t.item),t.answer=tA(r,t),n=YC(n,t);else n=YC(n,Qk(r))}return n}function Qk(e){return{id:eA(),linkId:e.linkId,text:e.text,item:Zk(e.item,void 0),answer:tA(e)}}var $k=1;function eA(){return`id-`+$k++}function tA(e,t){if(!(e.type===Sk.display||e.type===Sk.group)){if(t?.answer&&t.answer.length>0)return t.answer;if(e.initial&&e.initial.length>0)return e.initial.map(e=>({...e}));if(e.answerOption)return e.answerOption.filter(e=>e.initialSelected).map(e=>({...e,initialSelected:void 0}))}}function nA(e){return IS({type:`QuestionnaireItemInitial`,value:e},`value`)}function rA(e){return IS({type:`QuestionnaireItemAnswerOption`,value:e},`value`)}function iA(e){return IS({type:`QuestionnaireItemEnableWhen`,value:e},`answer`)}function aA(e){return IS({type:`QuestionnaireResponseItemAnswer`,value:e},`value`)}function oA(e){let t=bk(e.questionnaire),n=bk(e.defaultValue),[,r]=(0,b.useReducer)(e=>e+1,0),i=(0,b.useRef)({activePage:0});if(!i.current.questionnaire&&t&&(i.current.questionnaire=t,i.current.pages=e.disablePagination?void 0:sA(t)),t&&e.defaultValue&&n&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=Xk(t,n),p()),t&&!e.defaultValue&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=Xk(t),p()),!i.current.questionnaire||!i.current.questionnaireResponse)return{loading:!0};function a(e,t){let n=i.current.questionnaireResponse;for(let t of e)n=n?.item?.find(e=>t.id?e.id===t.id:e.linkId===t.linkId);return t&&(n=n?.item?.find(e=>e.linkId===t.linkId)),n}function o(){i.current.activePage=(i.current.activePage??0)+1,r()}function s(){i.current.activePage=(i.current.activePage??0)-1,r()}function c(e,t){let n=a(e);n&&(n.item??=[],n.item.push(Qk(t)),p())}function l(e,t){let n=a(e,t);n&&(n.answer??=[],n.answer.push({}),p())}function u(e,t,n){let r=a(e,t);r&&(r.answer=n,p())}function d(e){let t=i.current.questionnaireResponse;t&&(e?(t.extension=t.extension??[],t.extension=t.extension.filter(e=>e.url!==Ak),t.extension.push({url:Ak,valueSignature:e})):t.extension=t.extension?.filter(e=>e.url!==Ak),p())}function f(){let e=i.current.questionnaire;if(e?.item){let t=i.current.questionnaireResponse;Rk(e.item,t)}}function p(){let t=i.current.questionnaireResponse,n=i.current.questionnaire;!t||!n||(f(),r(),e.onChange?.(Nk(n,t)))}return{loading:!1,pagination:!!i.current.pages,questionnaire:i.current.questionnaire,questionnaireResponse:Nk(i.current.questionnaire,i.current.questionnaireResponse),subject:e.subject,encounter:e.encounter,activePage:i.current.activePage,pages:i.current.pages,items:cA(i.current.questionnaire,i.current.pages,i.current.activePage),responseItems:lA(i.current.questionnaireResponse,i.current.pages,i.current.activePage),onNextPage:o,onPrevPage:s,onAddGroup:c,onAddAnswer:l,onChangeAnswer:u,onChangeSignature:d}}function sA(e){if(e?.item&&_C(e?.item?.[0],Ck)?.valueCodeableConcept?.coding?.[0]?.code===`page`)return e.item.map((e,t)=>({linkId:e.linkId,title:e.text??`Page ${t+1}`,group:e}))}function cA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function lA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function uA(e,t,n={leading:!1}){let[r,i]=(0,b.useState)(e),a=(0,b.useRef)(!1),o=(0,b.useRef)(void 0),s=(0,b.useRef)(!1),c=(0,b.useCallback)(()=>window.clearTimeout(o.current),[]);return(0,b.useEffect)(()=>{a.current&&(!s.current&&n.leading?(s.current=!0,i(e),o.current=setTimeout(()=>{s.current=!1},t)):(c(),o.current=setTimeout(()=>{s.current=!1,i(e)},t)))},[e,n.leading,t,c]),(0,b.useEffect)(()=>(a.current=!0,c),[c]),[r,c]}var dA=250;function fA(e,t,n){return mA(`searchOne`,e,t,n)}function pA(e,t,n){return mA(`searchResources`,e,t,n)}function mA(e,t,n,r){let i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(),d=(0,b.useMemo)(()=>({resourceType:t,query:n}),[i.fhirSearchUrl(t,n).toString()]),f=r?.enabled??!0,[p]=uA(d,r?.debounceMs??dA,{leading:!0});return(0,b.useEffect)(()=>{if(!f)return()=>{};o(!0);let t=!0;return i[e](p.resourceType,p.query).then(e=>{t&&(o(!1),c(e),u(Lx))}).catch(e=>{t&&(o(!1),c(void 0),u(Zx(e)))}),()=>{t=!1}},[i,e,p,f]),[s,a,l]}function hA(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:sw(t,e.options)}):null}var gA=[`meta`,`implicitRules`,`contained`,`extension`,`modifierExtension`],_A=[`language`,`text`],vA=(0,b.createContext)({path:``,profileUrl:void 0,elements:Object.create(null),elementsByPath:Object.create(null),getExtendedProps:()=>({readonly:!1,hidden:!1}),accessPolicyResource:void 0,debugMode:!1,isDefaultContext:!0});vA.displayName=`ElementsContext`;var yA=[`extension`,`modifierExtension`],bA=[`id`,...gA].filter(e=>!yA.includes(e));function xA(e){return Object.entries(e).filter(([e,t])=>!CC(t.type)||t.max===0||t.path.toLowerCase().endsWith(`extension.url`)&&t.fixed||yA.includes(e)&&!CC(t.slicing?.slices)||bA.includes(e)?!1:!(_A.includes(e)&&t.path.split(`.`).length===2||e.includes(`.`)))}function SA(e,t){return e.line&&e.line.length>t?e.line[t]:``}function CA(e,t,n){let r=e.line||[];for(;r.length<=t;)r.push(``);return r[t]=n,{...e,line:wC(r)}}function wA(e){let[t,n]=(0,b.useState)(e.defaultValue||{}),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a,o,s,c,l,u]=(0,b.useMemo)(()=>[`use`,`type`,`line1`,`line2`,`city`,`state`,`postalCode`].map(t=>r(e.path+`.`+t)),[r,e.path]);function d(r){n(e=>({...e,...r})),e.onChange&&e.onChange({...t,...r})}function f(e){d({use:e})}function p(e){d({type:e})}function m(e){d(CA(t,0,e))}function h(e){d(CA(t,1,e))}function g(e){d({city:e})}function _(e){d({state:e})}function v(e){d({postalCode:e})}return(0,I.jsxs)(V,{gap:`xs`,wrap:`nowrap`,grow:!0,children:[(0,I.jsx)(yg,{disabled:e.disabled||i?.readonly,"data-testid":`address-use`,defaultValue:t.use,onChange:e=>f(e.currentTarget.value),data:[``,`home`,`work`,`temp`,`old`,`billing`]}),(0,I.jsx)(yg,{disabled:e.disabled||a?.readonly,"data-testid":`address-type`,defaultValue:t.type,onChange:e=>p(e.currentTarget.value),data:[``,`postal`,`physical`,`both`]}),(0,I.jsx)(yb,{disabled:e.disabled||o?.readonly,placeholder:`Line 1`,defaultValue:SA(t,0),onChange:e=>m(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||s?.readonly,placeholder:`Line 2`,defaultValue:SA(t,1),onChange:e=>h(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||c?.readonly,placeholder:`City`,defaultValue:t.city,onChange:e=>g(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||l?.readonly,placeholder:`State`,defaultValue:t.state,onChange:e=>_(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||u?.readonly,placeholder:`Postal Code`,defaultValue:t.postalCode,onChange:e=>v(e.currentTarget.value)})]})}function TA(e){let t=dk(),[n,r]=(0,b.useState)(e.defaultValue||{});function i(n){let i=n?{text:n,authorReference:t&&iC(t),time:new Date().toISOString()}:{};r(i),e.onChange&&e.onChange(i)}return(0,I.jsx)(yb,{disabled:e.disabled,name:e.name,placeholder:`Annotation text`,defaultValue:n.text,onChange:e=>i(e.currentTarget.value)})}var EA={outline:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},filled:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`currentColor`,stroke:`none`}},DA=(e,t,n,r)=>{let i=(0,b.forwardRef)(({color:n=`currentColor`,size:i=24,stroke:a=2,title:o,className:s,children:c,...l},u)=>(0,b.createElement)(`svg`,{ref:u,...EA[e],width:i,height:i,className:[`tabler-icon`,`tabler-icon-${t}`,s].join(` `),...e===`filled`?{fill:n}:{strokeWidth:a,stroke:n},...l},[o&&(0,b.createElement)(`title`,{key:`svg-title`},o),...r.map(([e,t])=>(0,b.createElement)(e,t)),...Array.isArray(c)?c:[c]]));return i.displayName=`${n}`,i},OA=DA(`outline`,`adjustments-horizontal`,`AdjustmentsHorizontal`,[[`path`,{d:`M12 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-0`}],[`path`,{d:`M4 6l8 0`,key:`svg-1`}],[`path`,{d:`M16 6l4 0`,key:`svg-2`}],[`path`,{d:`M6 12a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-3`}],[`path`,{d:`M4 12l2 0`,key:`svg-4`}],[`path`,{d:`M10 12l10 0`,key:`svg-5`}],[`path`,{d:`M15 18a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-6`}],[`path`,{d:`M4 18l11 0`,key:`svg-7`}],[`path`,{d:`M19 18l1 0`,key:`svg-8`}]]),kA=DA(`outline`,`alert-circle`,`AlertCircle`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M12 8v4`,key:`svg-1`}],[`path`,{d:`M12 16h.01`,key:`svg-2`}]]),AA=DA(`outline`,`alert-triangle`,`AlertTriangle`,[[`path`,{d:`M12 9v4`,key:`svg-0`}],[`path`,{d:`M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0`,key:`svg-1`}],[`path`,{d:`M12 16h.01`,key:`svg-2`}]]),jA=DA(`outline`,`arrow-down`,`ArrowDown`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M18 13l-6 6`,key:`svg-1`}],[`path`,{d:`M6 13l6 6`,key:`svg-2`}]]),MA=DA(`outline`,`arrow-up`,`ArrowUp`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M18 11l-6 -6`,key:`svg-1`}],[`path`,{d:`M6 11l6 -6`,key:`svg-2`}]]),NA=DA(`outline`,`bleach-off`,`BleachOff`,[[`path`,{d:`M5 19h14m1.986 -1.977a2 2 0 0 0 -.146 -.773l-7.1 -12.25a2 2 0 0 0 -3.5 0l-.815 1.405m-1.488 2.568l-4.797 8.277a2 2 0 0 0 1.75 2.75`,key:`svg-0`}],[`path`,{d:`M3 3l18 18`,key:`svg-1`}]]),PA=DA(`outline`,`bleach`,`Bleach`,[[`path`,{d:`M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75`,key:`svg-0`}]]),FA=DA(`outline`,`bookmark`,`Bookmark`,[[`path`,{d:`M18 7v14l-6 -4l-6 4v-14a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4`,key:`svg-0`}]]),IA=DA(`outline`,`box-multiple`,`BoxMultiple`,[[`path`,{d:`M7 5a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2l0 -10`,key:`svg-0`}],[`path`,{d:`M17 17v2a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2`,key:`svg-1`}]]),LA=DA(`outline`,`brackets-contain`,`BracketsContain`,[[`path`,{d:`M7 4h-4v16h4`,key:`svg-0`}],[`path`,{d:`M17 4h4v16h-4`,key:`svg-1`}],[`path`,{d:`M8 16h.01`,key:`svg-2`}],[`path`,{d:`M12 16h.01`,key:`svg-3`}],[`path`,{d:`M16 16h.01`,key:`svg-4`}]]),RA=DA(`outline`,`brand-asana`,`BrandAsana`,[[`path`,{d:`M9 7a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-0`}],[`path`,{d:`M14 16a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-1`}],[`path`,{d:`M4 16a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-2`}]]),zA=DA(`outline`,`briefcase`,`Briefcase`,[[`path`,{d:`M3 9a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -9`,key:`svg-0`}],[`path`,{d:`M8 7v-2a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v2`,key:`svg-1`}],[`path`,{d:`M12 12l0 .01`,key:`svg-2`}],[`path`,{d:`M3 13a20 20 0 0 0 18 0`,key:`svg-3`}]]),BA=DA(`outline`,`bucket-off`,`BucketOff`,[[`path`,{d:`M5.029 5.036c-.655 .58 -1.029 1.25 -1.029 1.964c0 2.033 3.033 3.712 6.96 3.967m3.788 -.21c3.064 -.559 5.252 -2.029 5.252 -3.757c0 -2.21 -3.582 -4 -8 -4c-1.605 0 -3.1 .236 -4.352 .643`,key:`svg-0`}],[`path`,{d:`M4 7c0 .664 .088 1.324 .263 1.965l2.737 10.035c.5 1.5 2.239 2 5 2s4.5 -.5 5 -2c.1 -.3 .252 -.812 .457 -1.535m.862 -3.146c.262 -.975 .735 -2.76 1.418 -5.354a7.45 7.45 0 0 0 .263 -1.965`,key:`svg-1`}],[`path`,{d:`M3 3l18 18`,key:`svg-2`}]]),VA=DA(`outline`,`bucket`,`Bucket`,[[`path`,{d:`M4 7a8 4 0 1 0 16 0a8 4 0 1 0 -16 0`,key:`svg-0`}],[`path`,{d:`M4 7c0 .664 .088 1.324 .263 1.965l2.737 10.035c.5 1.5 2.239 2 5 2s4.5 -.5 5 -2c.333 -1 1.246 -4.345 2.737 -10.035a7.45 7.45 0 0 0 .263 -1.965`,key:`svg-1`}]]),HA=DA(`outline`,`building`,`Building`,[[`path`,{d:`M3 21l18 0`,key:`svg-0`}],[`path`,{d:`M9 8l1 0`,key:`svg-1`}],[`path`,{d:`M9 12l1 0`,key:`svg-2`}],[`path`,{d:`M9 16l1 0`,key:`svg-3`}],[`path`,{d:`M14 8l1 0`,key:`svg-4`}],[`path`,{d:`M14 12l1 0`,key:`svg-5`}],[`path`,{d:`M14 16l1 0`,key:`svg-6`}],[`path`,{d:`M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16`,key:`svg-7`}]]),UA=DA(`outline`,`calendar`,`Calendar`,[[`path`,{d:`M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12`,key:`svg-0`}],[`path`,{d:`M16 3v4`,key:`svg-1`}],[`path`,{d:`M8 3v4`,key:`svg-2`}],[`path`,{d:`M4 11h16`,key:`svg-3`}],[`path`,{d:`M11 15h1`,key:`svg-4`}],[`path`,{d:`M12 15v3`,key:`svg-5`}]]),WA=DA(`outline`,`check`,`Check`,[[`path`,{d:`M5 12l5 5l10 -10`,key:`svg-0`}]]),GA=DA(`outline`,`checkbox`,`Checkbox`,[[`path`,{d:`M9 11l3 3l8 -8`,key:`svg-0`}],[`path`,{d:`M20 12v6a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h9`,key:`svg-1`}]]),KA=DA(`outline`,`chevron-down`,`ChevronDown`,[[`path`,{d:`M6 9l6 6l6 -6`,key:`svg-0`}]]),qA=DA(`outline`,`circle-check`,`CircleCheck`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12l2 2l4 -4`,key:`svg-1`}]]),JA=DA(`outline`,`circle-minus`,`CircleMinus`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12l6 0`,key:`svg-1`}]]),YA=DA(`outline`,`circle-plus`,`CirclePlus`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12h6`,key:`svg-1`}],[`path`,{d:`M12 9v6`,key:`svg-2`}]]),XA=DA(`outline`,`cloud-upload`,`CloudUpload`,[[`path`,{d:`M7 18a4.6 4.4 0 0 1 0 -9a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-1`,key:`svg-0`}],[`path`,{d:`M9 15l3 -3l3 3`,key:`svg-1`}],[`path`,{d:`M12 12l0 9`,key:`svg-2`}]]),ZA=DA(`outline`,`columns`,`Columns`,[[`path`,{d:`M4 6l5.5 0`,key:`svg-0`}],[`path`,{d:`M4 10l5.5 0`,key:`svg-1`}],[`path`,{d:`M4 14l5.5 0`,key:`svg-2`}],[`path`,{d:`M4 18l5.5 0`,key:`svg-3`}],[`path`,{d:`M14.5 6l5.5 0`,key:`svg-4`}],[`path`,{d:`M14.5 10l5.5 0`,key:`svg-5`}],[`path`,{d:`M14.5 14l5.5 0`,key:`svg-6`}],[`path`,{d:`M14.5 18l5.5 0`,key:`svg-7`}]]),QA=DA(`outline`,`copy`,`Copy`,[[`path`,{d:`M7 9.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667l0 -8.666`,key:`svg-0`}],[`path`,{d:`M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1`,key:`svg-1`}]]),$A=DA(`outline`,`currency-dollar`,`CurrencyDollar`,[[`path`,{d:`M16.7 8a3 3 0 0 0 -2.7 -2h-4a3 3 0 0 0 0 6h4a3 3 0 0 1 0 6h-4a3 3 0 0 1 -2.7 -2`,key:`svg-0`}],[`path`,{d:`M12 3v3m0 12v3`,key:`svg-1`}]]),ej=DA(`outline`,`database`,`Database`,[[`path`,{d:`M4 6a8 3 0 1 0 16 0a8 3 0 1 0 -16 0`,key:`svg-0`}],[`path`,{d:`M4 6v6a8 3 0 0 0 16 0v-6`,key:`svg-1`}],[`path`,{d:`M4 12v6a8 3 0 0 0 16 0v-6`,key:`svg-2`}]]),tj=DA(`outline`,`device-desktop`,`DeviceDesktop`,[[`path`,{d:`M3 5a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v10a1 1 0 0 1 -1 1h-16a1 1 0 0 1 -1 -1v-10`,key:`svg-0`}],[`path`,{d:`M7 20h10`,key:`svg-1`}],[`path`,{d:`M9 16v4`,key:`svg-2`}],[`path`,{d:`M15 16v4`,key:`svg-3`}]]),nj=DA(`outline`,`device-floppy`,`DeviceFloppy`,[[`path`,{d:`M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2`,key:`svg-0`}],[`path`,{d:`M10 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-1`}],[`path`,{d:`M14 4l0 4l-6 0l0 -4`,key:`svg-2`}]]),rj=DA(`outline`,`dots`,`Dots`,[[`path`,{d:`M4 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-0`}],[`path`,{d:`M11 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-1`}],[`path`,{d:`M18 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-2`}]]),ij=DA(`outline`,`edit`,`Edit`,[[`path`,{d:`M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1`,key:`svg-0`}],[`path`,{d:`M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415`,key:`svg-1`}],[`path`,{d:`M16 5l3 3`,key:`svg-2`}]]),aj=DA(`outline`,`equal-not`,`EqualNot`,[[`path`,{d:`M5 10h14`,key:`svg-0`}],[`path`,{d:`M5 14h14`,key:`svg-1`}],[`path`,{d:`M5 19l14 -14`,key:`svg-2`}]]),oj=DA(`outline`,`equal`,`Equal`,[[`path`,{d:`M5 10h14`,key:`svg-0`}],[`path`,{d:`M5 14h14`,key:`svg-1`}]]),sj=DA(`outline`,`eye-off`,`EyeOff`,[[`path`,{d:`M10.585 10.587a2 2 0 0 0 2.829 2.828`,key:`svg-0`}],[`path`,{d:`M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87`,key:`svg-1`}],[`path`,{d:`M3 3l18 18`,key:`svg-2`}]]),cj=DA(`outline`,`eye`,`Eye`,[[`path`,{d:`M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0`,key:`svg-0`}],[`path`,{d:`M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6`,key:`svg-1`}]]),lj=DA(`outline`,`file-alert`,`FileAlert`,[[`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`,key:`svg-0`}],[`path`,{d:`M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2`,key:`svg-1`}],[`path`,{d:`M12 17l.01 0`,key:`svg-2`}],[`path`,{d:`M12 11l0 3`,key:`svg-3`}]]),uj=DA(`outline`,`file-plus`,`FilePlus`,[[`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`,key:`svg-0`}],[`path`,{d:`M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2`,key:`svg-1`}],[`path`,{d:`M12 11l0 6`,key:`svg-2`}],[`path`,{d:`M9 14l6 0`,key:`svg-3`}]]),dj=DA(`outline`,`filter`,`Filter`,[[`path`,{d:`M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227`,key:`svg-0`}]]),fj=DA(`outline`,`folder`,`Folder`,[[`path`,{d:`M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2`,key:`svg-0`}]]),pj=DA(`outline`,`forms`,`Forms`,[[`path`,{d:`M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3`,key:`svg-0`}],[`path`,{d:`M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3`,key:`svg-1`}],[`path`,{d:`M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7`,key:`svg-2`}],[`path`,{d:`M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1`,key:`svg-3`}],[`path`,{d:`M17 12h.01`,key:`svg-4`}],[`path`,{d:`M13 12h.01`,key:`svg-5`}]]),mj=DA(`outline`,`id`,`Id`,[[`path`,{d:`M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10`,key:`svg-0`}],[`path`,{d:`M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-1`}],[`path`,{d:`M15 8l2 0`,key:`svg-2`}],[`path`,{d:`M15 12l2 0`,key:`svg-3`}],[`path`,{d:`M7 16l10 0`,key:`svg-4`}]]),hj=DA(`outline`,`layout-sidebar`,`LayoutSidebar`,[[`path`,{d:`M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12`,key:`svg-0`}],[`path`,{d:`M9 4l0 16`,key:`svg-1`}]]),gj=DA(`outline`,`list-details`,`ListDetails`,[[`path`,{d:`M13 5h8`,key:`svg-0`}],[`path`,{d:`M13 9h5`,key:`svg-1`}],[`path`,{d:`M13 15h8`,key:`svg-2`}],[`path`,{d:`M13 19h5`,key:`svg-3`}],[`path`,{d:`M3 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-4`}],[`path`,{d:`M3 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-5`}]]),_j=DA(`outline`,`lock-access`,`LockAccess`,[[`path`,{d:`M4 8v-2a2 2 0 0 1 2 -2h2`,key:`svg-0`}],[`path`,{d:`M4 16v2a2 2 0 0 0 2 2h2`,key:`svg-1`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v2`,key:`svg-2`}],[`path`,{d:`M16 20h2a2 2 0 0 0 2 -2v-2`,key:`svg-3`}],[`path`,{d:`M8 12a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1v3a1 1 0 0 1 -1 1h-6a1 1 0 0 1 -1 -1l0 -3`,key:`svg-4`}],[`path`,{d:`M10 11v-2a2 2 0 1 1 4 0v2`,key:`svg-5`}]]),vj=DA(`outline`,`lock`,`Lock`,[[`path`,{d:`M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6`,key:`svg-0`}],[`path`,{d:`M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0`,key:`svg-1`}],[`path`,{d:`M8 11v-4a4 4 0 1 1 8 0v4`,key:`svg-2`}]]),yj=DA(`outline`,`logout`,`Logout`,[[`path`,{d:`M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2`,key:`svg-0`}],[`path`,{d:`M9 12h12l-3 -3`,key:`svg-1`}],[`path`,{d:`M18 15l3 -3`,key:`svg-2`}]]),bj=DA(`outline`,`math-greater`,`MathGreater`,[[`path`,{d:`M5 18l14 -6l-14 -6`,key:`svg-0`}]]),xj=DA(`outline`,`math-lower`,`MathLower`,[[`path`,{d:`M19 18l-14 -6l14 -6`,key:`svg-0`}]]),Sj=DA(`outline`,`message`,`Message`,[[`path`,{d:`M8 9h8`,key:`svg-0`}],[`path`,{d:`M8 13h6`,key:`svg-1`}],[`path`,{d:`M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12`,key:`svg-2`}]]),Cj=DA(`outline`,`microscope`,`Microscope`,[[`path`,{d:`M5 21h14`,key:`svg-0`}],[`path`,{d:`M6 18h2`,key:`svg-1`}],[`path`,{d:`M7 18v3`,key:`svg-2`}],[`path`,{d:`M9 11l3 3l6 -6l-3 -3l-6 6`,key:`svg-3`}],[`path`,{d:`M10.5 12.5l-1.5 1.5`,key:`svg-4`}],[`path`,{d:`M17 3l3 3`,key:`svg-5`}],[`path`,{d:`M12 21a6 6 0 0 0 3.715 -10.712`,key:`svg-6`}]]),wj=DA(`outline`,`minus`,`Minus`,[[`path`,{d:`M5 12l14 0`,key:`svg-0`}]]),Tj=DA(`outline`,`moon`,`Moon`,[[`path`,{d:`M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454l0 .008`,key:`svg-0`}]]),Ej=DA(`outline`,`packages`,`Packages`,[[`path`,{d:`M7 16.5l-5 -3l5 -3l5 3v5.5l-5 3l0 -5.5`,key:`svg-0`}],[`path`,{d:`M2 13.5v5.5l5 3`,key:`svg-1`}],[`path`,{d:`M7 16.545l5 -3.03`,key:`svg-2`}],[`path`,{d:`M17 16.5l-5 -3l5 -3l5 3v5.5l-5 3l0 -5.5`,key:`svg-3`}],[`path`,{d:`M12 19l5 3`,key:`svg-4`}],[`path`,{d:`M17 16.5l5 -3`,key:`svg-5`}],[`path`,{d:`M12 13.5v-5.5l-5 -3l5 -3l5 3v5.5`,key:`svg-6`}],[`path`,{d:`M7 5.03v5.455`,key:`svg-7`}],[`path`,{d:`M12 8l5 -3`,key:`svg-8`}]]),Dj=DA(`outline`,`palette`,`Palette`,[[`path`,{d:`M12 21a9 9 0 0 1 0 -18c4.97 0 9 3.582 9 8c0 1.06 -.474 2.078 -1.318 2.828c-.844 .75 -1.989 1.172 -3.182 1.172h-2.5a2 2 0 0 0 -1 3.75a1.3 1.3 0 0 1 -1 2.25`,key:`svg-0`}],[`path`,{d:`M7.5 10.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-1`}],[`path`,{d:`M11.5 7.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-2`}],[`path`,{d:`M15.5 10.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-3`}]]),Oj=DA(`outline`,`pencil`,`Pencil`,[[`path`,{d:`M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4`,key:`svg-0`}],[`path`,{d:`M13.5 6.5l4 4`,key:`svg-1`}]]),kj=DA(`outline`,`pin`,`Pin`,[[`path`,{d:`M15 4.5l-4 4l-4 1.5l-1.5 1.5l7 7l1.5 -1.5l1.5 -4l4 -4`,key:`svg-0`}],[`path`,{d:`M9 15l-4.5 4.5`,key:`svg-1`}],[`path`,{d:`M14.5 4l5.5 5.5`,key:`svg-2`}]]),Aj=DA(`outline`,`pinned-off`,`PinnedOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M15 4.5l-3.249 3.249m-2.57 1.433l-2.181 .818l-1.5 1.5l7 7l1.5 -1.5l.82 -2.186m1.43 -2.563l3.25 -3.251`,key:`svg-1`}],[`path`,{d:`M9 15l-4.5 4.5`,key:`svg-2`}],[`path`,{d:`M14.5 4l5.5 5.5`,key:`svg-3`}]]),jj=DA(`outline`,`player-play`,`PlayerPlay`,[[`path`,{d:`M7 4v16l13 -8l-13 -8`,key:`svg-0`}]]),Mj=DA(`outline`,`plus`,`Plus`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M5 12l14 0`,key:`svg-1`}]]),Nj=DA(`outline`,`receipt`,`Receipt`,[[`path`,{d:`M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2m4 -14h6m-6 4h6m-2 4h2`,key:`svg-0`}]]),Pj=DA(`outline`,`refresh`,`Refresh`,[[`path`,{d:`M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4`,key:`svg-0`}],[`path`,{d:`M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4`,key:`svg-1`}]]),Fj=DA(`outline`,`repeat`,`Repeat`,[[`path`,{d:`M4 12v-3a3 3 0 0 1 3 -3h13m-3 -3l3 3l-3 3`,key:`svg-0`}],[`path`,{d:`M20 12v3a3 3 0 0 1 -3 3h-13m3 3l-3 -3l3 -3`,key:`svg-1`}]]),Ij=DA(`outline`,`report-medical`,`ReportMedical`,[[`path`,{d:`M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2`,key:`svg-0`}],[`path`,{d:`M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2`,key:`svg-1`}],[`path`,{d:`M10 14l4 0`,key:`svg-2`}],[`path`,{d:`M12 12l0 4`,key:`svg-3`}]]),Lj=DA(`outline`,`router`,`Router`,[[`path`,{d:`M3 15a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -4`,key:`svg-0`}],[`path`,{d:`M17 17l0 .01`,key:`svg-1`}],[`path`,{d:`M13 17l0 .01`,key:`svg-2`}],[`path`,{d:`M15 13l0 -2`,key:`svg-3`}],[`path`,{d:`M11.75 8.75a4 4 0 0 1 6.5 0`,key:`svg-4`}],[`path`,{d:`M8.5 6.5a8 8 0 0 1 13 0`,key:`svg-5`}]]),Rj=DA(`outline`,`search`,`Search`,[[`path`,{d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0`,key:`svg-0`}],[`path`,{d:`M21 21l-6 -6`,key:`svg-1`}]]),zj=DA(`outline`,`settings`,`Settings`,[[`path`,{d:`M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065`,key:`svg-0`}],[`path`,{d:`M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0`,key:`svg-1`}]]),Bj=DA(`outline`,`sort-ascending`,`SortAscending`,[[`path`,{d:`M4 6l7 0`,key:`svg-0`}],[`path`,{d:`M4 12l7 0`,key:`svg-1`}],[`path`,{d:`M4 18l9 0`,key:`svg-2`}],[`path`,{d:`M15 9l3 -3l3 3`,key:`svg-3`}],[`path`,{d:`M18 6l0 12`,key:`svg-4`}]]),Vj=DA(`outline`,`sort-descending`,`SortDescending`,[[`path`,{d:`M4 6l9 0`,key:`svg-0`}],[`path`,{d:`M4 12l7 0`,key:`svg-1`}],[`path`,{d:`M4 18l7 0`,key:`svg-2`}],[`path`,{d:`M15 15l3 3l3 -3`,key:`svg-3`}],[`path`,{d:`M18 6l0 12`,key:`svg-4`}]]),Hj=DA(`outline`,`square`,`Square`,[[`path`,{d:`M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14`,key:`svg-0`}]]),Uj=DA(`outline`,`star`,`Star`,[[`path`,{d:`M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873l-6.158 -3.245`,key:`svg-0`}]]),Wj=DA(`outline`,`sun-high`,`SunHigh`,[[`path`,{d:`M14.828 14.828a4 4 0 1 0 -5.656 -5.656a4 4 0 0 0 5.656 5.656`,key:`svg-0`}],[`path`,{d:`M6.343 17.657l-1.414 1.414`,key:`svg-1`}],[`path`,{d:`M6.343 6.343l-1.414 -1.414`,key:`svg-2`}],[`path`,{d:`M17.657 6.343l1.414 -1.414`,key:`svg-3`}],[`path`,{d:`M17.657 17.657l1.414 1.414`,key:`svg-4`}],[`path`,{d:`M4 12h-2`,key:`svg-5`}],[`path`,{d:`M12 4v-2`,key:`svg-6`}],[`path`,{d:`M20 12h2`,key:`svg-7`}],[`path`,{d:`M12 20v2`,key:`svg-8`}]]),Gj=DA(`outline`,`switch-horizontal`,`SwitchHorizontal`,[[`path`,{d:`M16 3l4 4l-4 4`,key:`svg-0`}],[`path`,{d:`M10 7l10 0`,key:`svg-1`}],[`path`,{d:`M8 13l-4 4l4 4`,key:`svg-2`}],[`path`,{d:`M4 17l9 0`,key:`svg-3`}]]),Kj=DA(`outline`,`table-export`,`TableExport`,[[`path`,{d:`M12.5 21h-7.5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v7.5`,key:`svg-0`}],[`path`,{d:`M3 10h18`,key:`svg-1`}],[`path`,{d:`M10 3v18`,key:`svg-2`}],[`path`,{d:`M16 19h6`,key:`svg-3`}],[`path`,{d:`M19 16l3 3l-3 3`,key:`svg-4`}]]),qj=DA(`outline`,`table`,`Table`,[[`path`,{d:`M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14`,key:`svg-0`}],[`path`,{d:`M3 10h18`,key:`svg-1`}],[`path`,{d:`M10 3v18`,key:`svg-2`}]]),Jj=DA(`outline`,`text-recognition`,`TextRecognition`,[[`path`,{d:`M4 8v-2a2 2 0 0 1 2 -2h2`,key:`svg-0`}],[`path`,{d:`M4 16v2a2 2 0 0 0 2 2h2`,key:`svg-1`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v2`,key:`svg-2`}],[`path`,{d:`M16 20h2a2 2 0 0 0 2 -2v-2`,key:`svg-3`}],[`path`,{d:`M12 16v-7`,key:`svg-4`}],[`path`,{d:`M9 9h6`,key:`svg-5`}]]),Yj=DA(`outline`,`trash`,`Trash`,[[`path`,{d:`M4 7l16 0`,key:`svg-0`}],[`path`,{d:`M10 11l0 6`,key:`svg-1`}],[`path`,{d:`M14 11l0 6`,key:`svg-2`}],[`path`,{d:`M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12`,key:`svg-3`}],[`path`,{d:`M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3`,key:`svg-4`}]]),Xj=DA(`outline`,`upload`,`Upload`,[[`path`,{d:`M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2`,key:`svg-0`}],[`path`,{d:`M7 9l5 -5l5 5`,key:`svg-1`}],[`path`,{d:`M12 4l0 12`,key:`svg-2`}]]),Zj=DA(`outline`,`user-plus`,`UserPlus`,[[`path`,{d:`M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0`,key:`svg-0`}],[`path`,{d:`M16 19h6`,key:`svg-1`}],[`path`,{d:`M19 16v6`,key:`svg-2`}],[`path`,{d:`M6 21v-2a4 4 0 0 1 4 -4h4`,key:`svg-3`}]]),Qj=DA(`outline`,`webhook`,`Webhook`,[[`path`,{d:`M4.876 13.61a4 4 0 1 0 6.124 3.39h6`,key:`svg-0`}],[`path`,{d:`M15.066 20.502a4 4 0 1 0 1.934 -7.502c-.706 0 -1.424 .179 -2 .5l-3 -5.5`,key:`svg-1`}],[`path`,{d:`M16 8a4 4 0 1 0 -8 0c0 1.506 .77 2.818 2 3.5l-3 5.5`,key:`svg-2`}]]),$j=DA(`outline`,`x`,`X`,[[`path`,{d:`M18 6l-12 12`,key:`svg-0`}],[`path`,{d:`M6 6l12 12`,key:`svg-1`}]]),eM=DA(`filled`,`circle-filled`,`CircleFilled`,[[`path`,{d:`M7 3.34a10 10 0 1 1 -4.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 4.995 -8.336z`,key:`svg-0`}]]),tM=class extends b.Component{state;constructor(e){super(e),this.state={lastLocation:LE.getLocation()}}static getDerivedStateFromError(e){return{error:e,lastLocation:LE.getLocation()}}componentDidUpdate(e,t){LE.getLocation()!==this.state.lastLocation&&this.setState({lastLocation:LE.getLocation(),error:void 0})}shouldComponentUpdate(e,t){return!!(this.props.children!==e.children||t.error&&!this.state.error||this.state.lastLocation!==LE.getLocation())}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.error?(0,I.jsx)(ou,{icon:(0,I.jsx)(kA,{size:16}),title:`Something went wrong`,color:`red`,children:Y(this.state.error)}):this.props.children}};function nM(){return(0,I.jsx)(hd,{style:{width:`100%`,height:`100vh`},children:(0,I.jsx)(il,{})})}var rM={main:`_main_6s8vf_1`,announcement:`_announcement_6s8vf_7`};function iM(e){return(0,I.jsx)(I.Fragment,{children:e.announcements.map((t,n)=>(0,I.jsx)(z,{className:rM.announcement,style:{backgroundColor:`var(--mantine-color-${t.color??`yellow`}-light)`,color:`var(--mantine-color-${t.color??`yellow`}-light-color)`},role:t.role??`status`,children:(0,I.jsxs)(V,{gap:`xs`,wrap:`nowrap`,h:`100%`,px:`md`,children:[t.icon,(0,I.jsx)(H,{size:`sm`,fw:500,truncate:!0,children:t.message}),t.dismissible&&(0,I.jsx)(Cl,{size:`sm`,variant:`subtle`,"aria-label":`Dismiss announcement`,onClick:()=>e.onDismiss(t),ml:`auto`})]})},t.id??n))})}function aM(e){e.preventDefault(),e.stopPropagation()}function oM(e){return e.button===1||e.ctrlKey||e.metaKey}function sM(e){if(cM(e))return!0;if(e instanceof HTMLTableCellElement){let t=e.children;if(t.length===1&&cM(t[0]))return!0}return!1}function cM(e){return e instanceof HTMLInputElement&&e.type===`checkbox`}async function lM(e,t){return new Promise((n,r)=>{let i=new MessageChannel;i.port1.onmessage=({data:e})=>{i.port1.close(),e.error?r(e.error):n(e.result)},e.contentWindow?.postMessage(t,new URL(e.src).origin,[i.port2])})}function uM(e,t){let n=new Blob([e],{type:ZE.JSON}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t??new Date().toISOString().replaceAll(/\D/g,``)}.json`,document.body.appendChild(i),i.click(),URL.revokeObjectURL(r)}function dM(e){let t=uk(),{to:n,suffix:r,label:i,onClick:a,children:o,...s}=e,c=fM(n);return r&&(c+=`/`+r),(0,I.jsx)(pu,{href:c,"aria-label":i,onAuxClick:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),a?(e.preventDefault(),a(e)):n&&(oM(e)||(e.preventDefault(),t(c)))},...s,children:o})}function fM(e){if(e){if(typeof e==`string`)return pM(e);if(Vw(e))return mM(e);if(Hw(e))return hM(e)}return`#`}function pM(e){return e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`/`)?e:`/`+e}function mM(e){return`/${e.resourceType}/${e.id}`}function hM(e){return`/${e.reference}`}function gM(e){let t=e.split(` `).filter(Boolean);return t.length>1?t[0][0]+t.at(-1)?.at(0):t.length===1?t[0][0]:``}function _M(e){let t=bk(e.value),n=t?lC(t):e.alt??``,r=gM(n),i=gk((t&&fC(t))??e.src??void 0),a=e.radius??`xl`,o={...e,value:void 0,link:void 0};return e.link?(0,I.jsx)(dM,{to:t,children:(0,I.jsx)(Qu,{src:i,alt:n,radius:a,...o,children:r})}):(0,I.jsx)(Qu,{src:i,alt:n,radius:a,...o,children:r})}var vM={logoButton:`_logoButton_799cf_1`,user:`_user_799cf_11`,userName:`_userName_799cf_25`},yM={iconBox:`_iconBox_1mfdi_1`,interactive:`_interactive_1mfdi_12`};function bM(e){let{projectDisplay:t,profileDisplay:n,label:r,selected:i}=e,a=r?`${t} - ${r}`:t;return(0,I.jsxs)(V,{gap:`xs`,align:`center`,wrap:`nowrap`,style:{width:`100%`,minWidth:0},children:[(0,I.jsx)(z,{className:yM.iconBox,children:(0,I.jsx)(zA,{size:16,stroke:2})}),(0,I.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,I.jsx)(H,{size:`sm`,fw:500,truncate:!0,children:a}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,truncate:!0,children:n})]}),i&&(0,I.jsx)(WA,{size:16,stroke:2,color:`var(--mantine-color-blue-6)`})]})}function xM(e){let{membership:t,label:n}=e;return(0,I.jsx)(bM,{projectDisplay:t.project?.display,profileDisplay:t.profile?.display,label:n})}function SM(){return`Medplum`}var CM={divider:`_divider_3o3ui_1`,accountSection:`_accountSection_3o3ui_5`,projectOption:`_projectOption_3o3ui_9`,recentProjectItem:`_recentProjectItem_3o3ui_18`,dropdown:`_dropdown_3o3ui_22`,settingsRow:`_settingsRow_3o3ui_43`,settingsControlWrapper:`_settingsControlWrapper_3o3ui_50`,segmentedControl:`_segmentedControl_3o3ui_57`,appearanceControl:`_appearanceControl_3o3ui_76`,layoutControl:`_layoutControl_3o3ui_93`},wM=`var(--mantine-color-dimmed)`,TM=[{value:`light`,label:(0,I.jsx)(DM,{Icon:Wj,label:`Light`})},{value:`auto`,label:(0,I.jsx)(DM,{Icon:tj,label:`System`})},{value:`dark`,label:(0,I.jsx)(DM,{Icon:Tj,label:`Dark`})}],EM=[{label:`v1`,value:`v1`},{label:`v2`,value:`v2`}];function DM({Icon:e,label:t}){return(0,I.jsx)(`span`,{"aria-label":t,style:{display:`flex`},children:(0,I.jsx)(e,{size:16,color:wM,"aria-hidden":!0})})}function OM(){return(0,I.jsx)(bp,{my:4,mx:4,className:CM.divider})}function kM(e,t){return t?e.project.reference===t.project.reference&&e.profile.reference===t.profile.reference:!1}function AM(e){return`${e.project.reference}-${e.profile.reference}`}function jM(e){let{medplum:t,profile:n,navigate:r}=lk(),i=t.getActiveLogin(),a=t.getLogins().filter(e=>!kM(e,i)),o=t.getProject(),{colorScheme:s,setColorScheme:c}=Vr(),[l]=(0,b.useState)(()=>localStorage.appShellLayoutVersion??`v1`),u=e.showLayoutVersionToggle??!0,d=o?.name??t.getActiveLogin()?.project.display,f=i?.profile.display??(n?cw(n.name?.[0]):void 0);function p(e){t.setActiveLogin(e).then(()=>LE.reload()).catch(console.error)}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{className:CM.accountSection,children:(0,I.jsx)(z,{className:CM.projectOption,children:(0,I.jsx)(bM,{projectDisplay:d,profileDisplay:f,selected:!0})})}),a.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(OM,{}),a.map(e=>(0,I.jsx)(W.Item,{className:CM.recentProjectItem,onClick:()=>p(e),children:(0,I.jsx)(z,{className:CM.projectOption,children:(0,I.jsx)(bM,{projectDisplay:e.project.display,profileDisplay:e.profile.display})})},AM(e)))]}),(0,I.jsx)(OM,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Gj,{size:16,color:wM}),onClick:()=>r(`/signin`),children:(0,I.jsx)(H,{size:`sm`,children:`Switch to another project`})}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:16,color:wM}),onClick:()=>r(`/${aC(n)}`),children:(0,I.jsx)(H,{size:`sm`,children:`Account settings`})}),(0,I.jsxs)(ru,{className:CM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(ru,{align:`center`,gap:`xs`,children:[(0,I.jsx)(Dj,{size:16,color:wM}),(0,I.jsx)(H,{size:`sm`,children:`Appearance`})]}),(0,I.jsx)(z,{className:CM.settingsControlWrapper,children:(0,I.jsx)(ly,{classNames:{root:it(CM.segmentedControl,CM.appearanceControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:s,onChange:e=>c(e),data:TM,"aria-label":`Color scheme`})})]}),u&&(0,I.jsxs)(ru,{className:CM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(ru,{align:`center`,gap:`xs`,children:[(0,I.jsx)(qj,{size:16,color:wM}),(0,I.jsx)(H,{size:`sm`,children:`Layout`})]}),(0,I.jsx)(z,{className:CM.settingsControlWrapper,children:(0,I.jsx)(ly,{classNames:{root:it(CM.segmentedControl,CM.layoutControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:l,onChange:e=>{localStorage.appShellLayoutVersion=e,LE.reload()},data:EM,"aria-label":`App shell layout version`})})]}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(yj,{size:16,color:wM}),onClick:async()=>{await t.signOut(),r(`/signin`)},children:(0,I.jsx)(H,{size:`sm`,children:`Sign out`})}),(0,I.jsx)(OM,{}),(0,I.jsxs)(H,{size:`xs`,c:`dimmed`,fw:500,my:`sm`,ta:`center`,children:[SM(),` `,e.version]})]})}var MM={selectedItems:`selected-items`,options:`options`};function NM(e){let t=cp({onDropdownClose:()=>t.resetSelectedOption(),onDropdownOpen:()=>t.updateSelectedOptionIndex(`active`)}),{name:n,label:r,description:i,error:a,defaultValue:o,toOption:s,loadOptions:c,itemComponent:l,pillComponent:u,emptyComponent:d,onChange:f,onCreate:p,creatable:m,clearable:h,required:g,placeholder:_,leftSection:v,maxValues:y,optionsDropdownMaxHeight:x=320,minInputLength:S=0,...C}=e,w=C.disabled,T=PM(o),[E,D]=(0,b.useState)(``),[O,k]=(0,b.useState)(),[A,j]=(0,b.useState)(),[M,ee]=(0,b.useState)(),[N,P]=(0,b.useState)(T.map(s)),[te,ne]=(0,b.useState)([]),re=l??FM,ie=u??IM,ae=d??LM,oe=(0,b.useRef)(E),se=(0,b.useRef)(void 0),ce=(0,b.useRef)(void 0),le=(0,b.useRef)(O),ue=(0,b.useRef)(A),de=(0,b.useRef)(M);(0,b.useLayoutEffect)(()=>{oe.current=E,le.current=O,ue.current=A,de.current=M});let fe=(0,b.useCallback)(()=>{if(k(void 0),oe.current===ce.current&&c===se.current||(oe.current?.length??0)<S)return;ce.current=oe.current,se.current=c;let e=new AbortController;j(e),c(oe.current??``,e.signal).then(n=>{e.signal.aborted||(ne(n.map(s)),de.current?(n.length>0&&f(n.slice(0,1)),ee(!1)):n.length>0&&t.openDropdown())}).catch(t=>{e.signal.aborted||t.message.includes(`aborted`)||J({color:`red`,message:Y(t)})}).finally(()=>{e.signal.aborted||j(void 0)})},[t,c,f,s,S]),pe=(0,b.useCallback)(e=>{(te&&te.length>0||m)&&t.openDropdown(),t.updateSelectedOptionIndex(),D(e.currentTarget.value),ue.current&&(ue.current.abort(),j(void 0)),le.current!==void 0&&window.clearTimeout(le.current),k(window.setTimeout(()=>fe(),100))},[t,te,m,fe]),me=(0,b.useCallback)(e=>{let t=N.some(t=>t.value===e),n=t?N.filter(t=>t.value!==e):[...N],r=te?.find(t=>t.value===e);if(!r&&m!==!1&&p&&(r=s(p(e))),r){if(y===0){f([r.resource]),N.length>0&&P([]);return}t||n.push(r)}if(y!==void 0)for(;n.length>y;)n.shift();f(n.map(e=>e.resource)),P(n)},[m,te,N,y,f,p,s]),he=(0,b.useMemo)(()=>{if(!w)return e=>{w||(y===1&&(D(``),ne([]),t.closeDropdown()),ce.current=void 0,e===`$create`?(D(``),me(E)):me(e))}},[me,t,w,y,E]),ge=(0,b.useCallback)(e=>{let t=N.filter(t=>t.value!==e.value);f(t.map(e=>e.resource)),P(t)},[N,f]),_e=(0,b.useCallback)(e=>{e.key===`Enter`?(O||A)&&ee(!0):e.key===`Backspace`&&E.length===0&&(aM(e),ge(N[N.length-1]))},[A,ge,E.length,N,O]);(0,b.useEffect)(()=>()=>{ue.current&&ue.current.abort()},[]);let ve=!w&&h&&N.length>0&&(0,I.jsx)(dp.ClearButton,{title:`Clear all`,size:`sm`,onClear:()=>{D(``),P([]),f([]),t.closeDropdown()}}),ye=m&&E.trim().length>0,be=te.length>0||ye;return(0,I.jsxs)(dp,{store:t,onOptionSubmit:he,withinPortal:!0,shadow:`xl`,...C,children:[(0,I.jsx)(dp.DropdownTarget,{children:(0,I.jsx)(dg,{label:r,description:i,error:a,className:e.className,leftSection:v,rightSection:A?(0,I.jsx)(il,{size:16}):ve,required:g,disabled:w,children:(0,I.jsxs)(og.Group,{"data-testid":MM.selectedItems,children:[N.map(e=>(0,I.jsx)(ie,{item:e,disabled:w,onRemove:()=>ge(e)},e.value)),!w&&(y===void 0||y===0||N.length<y)&&(0,I.jsx)(dp.EventsTarget,{children:(0,I.jsx)(dg.Field,{role:`searchbox`,name:n,value:E,placeholder:_,onFocus:pe,onBlur:()=>{t.closeDropdown(),D(``)},onKeyDown:_e,onChange:pe})})]})})}),(0,I.jsx)(dp.Dropdown,{hidden:!be,"data-testid":MM.options,children:(0,I.jsx)(dp.Options,{children:(0,I.jsxs)(Uc,{type:`scroll`,mah:x,children:[te.map(e=>{let t=N.some(t=>t.value===e.value);return(0,I.jsx)(dp.Option,{value:e.value,active:t,children:(0,I.jsx)(re,{...e,active:t})},e.value)}),ye&&(0,I.jsxs)(dp.Option,{value:`$create`,children:[`+ Create `,E]}),!m&&E.trim().length>0&&te.length===0&&(0,I.jsx)(ae,{search:E})]})})})]})}function PM(e){return e?Array.isArray(e)?e:[e]:[]}function FM(e){return(0,I.jsxs)(V,{gap:`xs`,children:[e.active&&(0,I.jsx)(WA,{size:12}),(0,I.jsx)(`span`,{children:e.label})]})}function IM({item:e,disabled:t,onRemove:n}){return(0,I.jsx)(og,{withRemoveButton:!t,onRemove:n,children:e.label})}function LM(){return(0,I.jsx)(dp.Empty,{children:`Nothing found`})}var RM={searchInput:`_searchInput_dick8_1`};function zM(e){return{value:e.id,label:lC(e),resource:e}}function BM(e){let t=uk(),n=Q(),r=(0,b.useCallback)(async(e,t)=>{let r=HM(e),i={signal:t};return UM(await n.graphql(r,void 0,void 0,i),e)},[n]),i=(0,b.useCallback)(e=>{e.length>0&&t(`/${aC(e[0])}`)},[t]);return(0,I.jsx)(NM,{size:`sm`,radius:`md`,className:RM.searchInput,leftSection:(0,I.jsx)(Rj,{size:16}),placeholder:`Search`,itemComponent:VM,toOption:zM,onChange:i,loadOptions:r,maxValues:0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var VM=(0,b.forwardRef)(({resource:e,active:t,...n},r)=>{let i;return e.resourceType===`Patient`?i=e.birthDate:e.resourceType===`ServiceRequest`&&(i=e.subject?.display),(0,I.jsx)(`div`,{ref:r,...n,children:(0,I.jsxs)(V,{wrap:`nowrap`,children:[(0,I.jsx)(_M,{value:e}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:lC(e)}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:i})]})]})})});function HM(e){let t=JSON.stringify(e);return MC(e)?`{
|
|
96
|
+
}`.replaceAll(/\s+/g,` `),n=await this.graphql(t);lS(n.data.StructureDefinitionList);for(let e of n.data.SearchParameterList)Aw(e)})());return this.setCacheEntry(n,i,t),i}requestProfileSchema(e,t){if(!t?.expandProfile&&mS(e))return Promise.resolve();let n=e+`-requestSchema`+(t?.expandProfile?`-nested`:``),r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new xD((async()=>{if(t?.expandProfile){let t=this.fhirUrl(`StructureDefinition`,`$expand-profile`);t.search=new URLSearchParams({url:e}).toString(),lS(await this.post(t.toString(),{}))}else{let t=await this.searchOne(`StructureDefinition`,{url:e,_sort:`-_lastUpdated`});if(!t){console.warn(`No StructureDefinition found for ${e}!`);return}uS(t)}})());return this.setCacheEntry(n,i,t),i}readHistory(e,t,n,r){let i=this.fhirUrl(e,t,`_history`);return n?.count&&i.searchParams.set(`_count`,n.count.toString()),n?.offset&&i.searchParams.set(`_offset`,n.offset.toString()),this.get(i.toString(),r)}readVersion(e,t,n,r){return this.get(this.fhirUrl(e,t,`_history`,n),r)}readPatientEverything(e,t){return this.getBundle(this.fhirUrl(`Patient`,e,`$everything`),t)}readPatientSummary(e,t){return this.getBundle(this.fhirUrl(`Patient`,e,`$summary`),t)}createResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);return this.invalidateSearches(e.resourceType),this.post(this.fhirUrl(e.resourceType),e,void 0,t)}async createResourceIfNoneExist(e,t,n={}){let r=this.fhirUrl(e.resourceType);this.setRequestHeader(n,`If-None-Exist`,t);let i=await this.post(r,e,void 0,n);return this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),i}async upsertResource(e,t,n){let r=this.fhirSearchUrl(e.resourceType,t),i=await this.put(r,e,void 0,n);return i||=e,this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),i}async createAttachment(e,t,n,r,i){let a=iO(e,t,n,r);if(a.contentType===ZE.XML){let e=a.data,t;t=e instanceof Blob?await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(!r.result){n(Error(`Failed to load file`));return}t(r.result)},r.readAsText(e,`utf-8`)}):ArrayBuffer.isView(e)?new TextDecoder().decode(e):e,t.includes(`<ClinicalDocument`)&&t.includes(`urn:hl7-org:v3`)&&(a={...a,contentType:ZE.CDA_XML})}let o=i??(typeof t==`object`?t:{}),s=await this.createBinary(a,o);return{contentType:a.contentType,url:s.url,title:a.filename}}createBinary(e,t,n,r,i){let a=iO(e,t,n,r),o=i??(typeof t==`object`?t:{}),{data:s,contentType:c,filename:l,securityContext:u,onProgress:d}=a,f=this.fhirUrl(`Binary`);return l&&f.searchParams.set(`_filename`,l),u?.reference&&this.setRequestHeader(o,`X-Security-Context`,u.reference),d?this.uploadwithProgress(f,s,c,d,o):this.post(f,s,c,o)}uploadwithProgress(e,t,n,r,i){return new Promise((a,o)=>{let s=new XMLHttpRequest,c=()=>s.abort();i?.signal?.addEventListener(`abort`,c);let l=e=>{i?.signal?.removeEventListener(`abort`,c),e instanceof Error?o(e):a(e)};if(s.responseType=`json`,s.onabort=()=>l(new DOMException(`Request aborted`,`AbortError`)),s.onerror=()=>l(Error(`Request error`)),r&&(s.upload.onprogress=e=>r(e),s.upload.onload=e=>r(e)),s.onload=()=>{s.status>=200&&s.status<300?l(s.response):l(new Xx(Zx(s.response||s.statusText)))},s.open(`POST`,e),s.withCredentials=!0,s.setRequestHeader(`Authorization`,`Bearer `+this.accessToken),s.setRequestHeader(`Cache-Control`,`no-cache, no-store, max-age=0`),s.setRequestHeader(`Content-Type`,n),this.options.extendedMode!==!1&&s.setRequestHeader(`X-Medplum`,`extended`),i?.headers){let e=i.headers;for(let[t,n]of Object.entries(e))s.setRequestHeader(t,n)}s.send(t)})}async createPdf(e,t,n,r){if(!this.createPdfImpl)throw Error(`PDF creation not enabled`);let i=oO(e,t,n,r),a=typeof t==`object`?t:{},{docDefinition:o,tableLayouts:s,fonts:c,...l}=i,u=await this.createPdfImpl(o,s,c),d={...l,data:u,contentType:`application/pdf`};return this.createBinary(d,a)}createComment(e,t,n){let r=this.getProfile(),i,a;return e.resourceType===`Encounter`&&(i=iC(e),a=e.subject),e.resourceType===`ServiceRequest`&&(i=e.encounter,a=e.subject),e.resourceType===`Patient`&&(a=iC(e)),this.createResource({resourceType:`Communication`,status:`completed`,basedOn:[iC(e)],encounter:i,subject:a,sender:r?iC(r):void 0,sent:new Date().toISOString(),payload:[{contentString:t}]},n)}async updateResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);if(!e.id)throw Error(`Missing id`);let n=await this.put(this.fhirUrl(e.resourceType,e.id),e,void 0,t);return n||=e,this.cacheResource(n,t),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),n}async patchResource(e,t,n,r){let i=await this.patch(this.fhirUrl(e,t),n,r);return this.cacheResource(i,r),this.invalidateUrl(this.fhirUrl(e,t,`_history`)),this.invalidateSearches(e),i}deleteResource(e,t,n){return this.deleteCacheEntry(this.fhirUrl(e,t).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,t),n)}validateResource(e,t){return this.post(this.fhirUrl(e.resourceType,`$validate`),e,void 0,t)}executeBot(e,t,n,r){let i;if(typeof e==`string`){let t=e;i=this.fhirUrl(`Bot`,t,`$execute`)}else{let t=e;i=this.fhirUrl(`Bot`,`$execute`),i.searchParams.set(`identifier`,t.system+`|`+t.value)}return this.post(i,t,n,r)}executeBatch(e,t){return this.post(this.fhirBaseUrl,e,void 0,t)}sendEmail(e,t){return this.post(`email/v1/send`,e,ZE.JSON,t)}graphql(e,t,n,r){return this.post(this.fhirUrl(`$graphql`),{query:e,operationName:t,variables:n},ZE.JSON,r)}readResourceGraph(e,t,n,r){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${n}`,r)}pushToAgent(e,t,n,r,i,a){let{waitTimeout:o,returnAck:s,...c}=a??{};return this.post(this.fhirUrl(`Agent`,oC(e),`$push`),{destination:typeof t==`string`?t:aC(t),body:n,contentType:r,waitForResponse:i,...o===void 0?void 0:{waitTimeout:o},...s===void 0?void 0:{returnAck:s}},ZE.FHIR_JSON,c)}getCdsServices(e){return this.get(this.cdsServicesUrl,e)}callCdsService(e,t,n){return this.post($C(this.cdsServicesUrl,e),t,ZE.JSON,n)}getActiveLogin(){return this.storage.getObject(`activeLogin`)}async setActiveLogin(e){(!this.sessionDetails?.profile||aC(this.sessionDetails.profile)!==e.profile?.reference)&&this.clearActiveLogin(),this.setAccessToken(e.accessToken,e.refreshToken),this.storage.setObject(`activeLogin`,e),this.addLogin(e),this.refreshPromise=void 0,await this.refreshProfile()}getAccessToken(){return this.accessToken}isAuthenticated(e){return this.accessTokenExpires!==void 0&&Date.now()<this.accessTokenExpires-(e??this.refreshGracePeriod)}setAccessToken(e,t){this.accessToken=e,this.refreshToken=t,this.accessTokenExpires=yD(e),this.medplumServer=vD(e)}getLogins(){return this.storage.getObject(`logins`)??[]}addLogin(e){let t=this.getLogins().filter(t=>t.profile?.reference!==e.profile?.reference);t.push(e),this.storage.setObject(`logins`,t)}async refreshProfile(){if(this.medplumServer)return this.profilePromise=new Promise((e,t)=>{this.get(`auth/me`,{cache:`no-cache`}).then(t=>{this.profilePromise=void 0;let n=this.sessionDetails?.profile?.id!==t.profile.id;this.sessionDetails=t,this.syncStoredLoginProject(),n&&this.dispatchEvent({type:`change`}),e(t.profile),this.dispatchEvent({type:`profileRefreshed`})}).catch(t)}),this.dispatchEvent({type:`profileRefreshing`}),this.profilePromise}syncStoredLoginProject(){let e=this.getActiveLogin(),t=this.sessionDetails?.project?.name;if(!e||!t||e.project.display===t)return;let n={...e,project:{...e.project,display:t}};this.storage.setObject(`activeLogin`,n),this.addLogin(n)}isLoading(){return!this.isInitialized||!!this.profilePromise&&!this.sessionDetails?.profile}isSuperAdmin(){return!!this.sessionDetails?.project.superAdmin}isProjectAdmin(){return!!this.sessionDetails?.membership.admin}getProject(){return this.sessionDetails?.project}getProjectMembership(){return this.sessionDetails?.membership}getProfile(){return this.sessionDetails?.profile}async getProfileAsync(){return this.profilePromise?this.profilePromise:this.sessionDetails?this.sessionDetails.profile:this.refreshProfile()}getUserConfiguration(){return this.sessionDetails?.config}getAccessPolicy(){return this.sessionDetails?.accessPolicy}async download(e,t={}){return(await this.downloadResponse(e,t)).blob()}async downloadResponse(e,t={}){this.refreshPromise&&await this.refreshPromise;let n=e.toString();n.startsWith(qD)&&(e=this.fhirUrl(n));let r=t.headers;return r||(r={},t.headers=r),r.Accept||=`*/*`,this.addFetchOptionsDefaults(t),this.fetchWithRetry(e.toString(),t)}async createMedia(e,t){let{additionalFields:n,...r}=e,i=await this.createResource({resourceType:`Media`,status:`preparation`,content:{contentType:e.contentType},...n});r.securityContext||=iC(i);let a=await this.createAttachment(r,t);return this.updateResource({...i,status:`completed`,content:a})}async uploadMedia(e,t,n,r,i){return this.createMedia({data:e,contentType:t,filename:n,additionalFields:r},i)}async createDocumentReference(e,t){let{additionalFields:n,...r}=e,i=await this.createResource({resourceType:`DocumentReference`,status:`current`,content:[{attachment:{contentType:e.contentType}}],...n});r.securityContext||=iC(i);let a=await this.createAttachment(r,t);return this.updateResource({...i,content:[{attachment:a}]})}async bulkExport(e=``,t,n,r){let i=e&&`${e}/`,a=this.fhirUrl(`${i}$export`);return t&&a.searchParams.set(`_type`,t),n&&a.searchParams.set(`_since`,n),this.startAsyncRequest(a.toString(),r)}async startAsyncRequest(e,t={}){this.addFetchOptionsDefaults(t);let n=t.headers;return n.Prefer=`respond-async`,t.method=`POST`,this.request(e,t)}async wrappedFetch(e,t){return await this.refreshIfExpired(),this.addFetchOptionsDefaults(t),this.fetchWithRetry(e,t)}get keyValue(){return this.keyValueClient||=new bD(this),this.keyValueClient}getBundle(e,t){return new xD((async()=>{let n=await this.get(e,t);for(let e of n.entry??iw)this.cacheResource(e.resource,t);return n})())}isCacheEnabled(e){return!!this.requestCache&&!this.getRequestHeader(e,`x-medplum-on-behalf-of`)}getCacheEntry(e,t){if(!this.isCacheEnabled(t)||t?.cache===`no-cache`||t?.cache===`reload`)return;let n=this.requestCache.get(e);if(!(!n||n.requestTime+this.cacheTime<Date.now()))return n}setCacheEntry(e,t,n){this.isCacheEnabled(n)&&(this.requestCache.set(e,{requestTime:Date.now(),value:t}),n?.signal&&n.signal.addEventListener(`abort`,()=>{this.requestCache.delete(e)}))}cacheResource(e,t){e?.id&&!e.meta?.tag?.some(e=>e.code===`SUBSETTED`)&&this.setCacheEntry(this.fhirUrl(e.resourceType,e.id).toString(),new xD(Promise.resolve(e)),t)}deleteCacheEntry(e){this.requestCache&&this.requestCache.delete(e)}async request(e,t={},n={}){let r=await this.wrappedFetch(e,t);if(r.status===401)return this.handleUnauthenticated(e,t,n);if(r.status===204||r.status===304)return;let i=r.headers.get(`content-type`)?.includes(`json`);if(r.status===404&&!i)throw new Xx(Rx);let a=await this.parseBody(r,i);if(r.status===200&&t.followRedirectOnOk||r.status===201&&t.followRedirectOnCreated){let e=await tO(r,a);if(e)return this.request(e,{...t,method:`GET`,body:void 0})}if(r.status===202&&t.pollStatusOnAccepted){let e=await tO(r,a)??n.statusUrl;if(e)return this.pollStatus(e,t,n)}if(r.status>=400)throw new Xx(Zx(a));return a}async parseBody(e,t){let n;if(e.headers.get(`content-length`)!==`0`){if(t)try{n=await e.json()}catch(t){throw console.error(`Error parsing response`,e.status,t),t}else n=await e.text();return n}}async fetchWithRetry(e,t){e.startsWith(`http`)||(e=$C(this.baseUrl,e));let n=t?.maxRetries??this.maxRetries;for(let r=0;r<=n;r++)try{this.logLevel!==`none`&&this.logRequest(e,t);let i=await this.fetch(e,t);if(this.logLevel!==`none`&&this.logResponse(i),this.setCurrentRateLimit(i),r>=n||!sO(i))return i;let a=this.getRetryDelay(r);if(a>(t.maxRetryTime??this.maxRetryTime))return i;await KC(a,{signal:t.signal})}catch(e){if(e.message===`Failed to fetch`&&r===0&&this.dispatchEvent({type:`offline`}),e.name===`AbortError`||r===n)throw e}throw Error(`Unreachable`)}logRequest(e,t){if(console.log(`> ${t.method} ${e}`),this.logLevel===`verbose`&&t.headers){let e=t.headers;for(let t of XC(Object.keys(e)))console.log(`> ${t}: ${e[t]}`)}}logResponse(e){console.log(`< ${e.status} ${e.statusText}`),this.logLevel===`verbose`&&e.headers&&e.headers.forEach((e,t)=>console.log(`< ${t}: ${e}`))}setCurrentRateLimit(e){if(!e?.headers||typeof e.headers.get!=`function`)return;let t=e.headers.get(`ratelimit`);t&&(this.currentRateLimits=t)}rateLimitStatus(){if(!this.currentRateLimits)return[];let e=this.currentRateLimits;return e.split(`,`).map(t=>{let n=t.split(`;`).map(e=>e.trim());if(n.length!==3)throw Error(`Could not parse RateLimit header: `+e);let r=n[0].substring(1,n[0].length-1),i=n.find(e=>e.startsWith(`r=`))?.substring(2),a=i?Number.parseInt(i,10):NaN,o=n.find(e=>e.startsWith(`t=`))?.substring(2),s=o?Number.parseInt(o,10):NaN;if(!r||Number.isNaN(a)||Number.isNaN(s))throw Error(`Could not parse RateLimit header: `+e);return{name:r,remainingUnits:a,secondsUntilReset:s,resetsAfter:Math.ceil((Date.now()+1e3*s)/1e3)}})}getRetryDelay(e){let t=this.rateLimitStatus(),n=500*1.5**e;for(let e of t)e.remainingUnits||(n=Math.max(n,e.secondsUntilReset*1e3));return n}async pollStatus(e,t,n){let r={...t,method:`GET`,body:void 0,redirect:`follow`};return n.pollCount===void 0?(t.headers&&typeof t.headers==`object`&&`Prefer`in t.headers&&(r.headers={...t.headers},delete r.headers.Prefer),n.statusUrl=e,n.pollCount=1):(await KC(t.pollStatusPeriod??1e3,{signal:t.signal}),n.pollCount++),this.request(e,r,n)}async executeAutoBatch(){if(this.autoBatchQueue===void 0)return;let e=[...this.autoBatchQueue];if(this.autoBatchQueue.length=0,this.autoBatchTimerId=void 0,e.length===1){let t=e[0];try{t.options.method=t.method,t.resolve(await this.request($C(this.fhirBaseUrl,t.url),t.options))}catch(e){t.reject(new Xx(Zx(e)))}return}let t={resourceType:`Bundle`,type:`batch`,entry:e.map(e=>({request:{method:e.method,url:e.url},resource:e.options.body?JSON.parse(e.options.body):void 0}))},n=await this.post(this.fhirBaseUrl,t);for(let t=0;t<e.length;t++){let r=e[t],i=n.entry?.[t];i?.response?.outcome&&!Jx(i.response.outcome)?r.reject(new Xx(i.response.outcome)):r.resolve(i?.resource)}}addFetchOptionsDefaults(e){Object.entries(this.defaultHeaders).forEach(([t,n])=>{this.setRequestHeader(e,t,n)}),this.setRequestHeader(e,`Accept`,VD,!0),this.options.extendedMode!==!1&&this.setRequestHeader(e,`X-Medplum`,`extended`),e.body&&this.setRequestHeader(e,`Content-Type`,ZE.FHIR_JSON,!0),this.accessToken?this.setRequestHeader(e,`Authorization`,`Bearer `+this.accessToken):this.basicAuth&&this.setRequestHeader(e,`Authorization`,`Basic `+this.basicAuth),e.cache||=`no-cache`,e.credentials||=`include`}setRequestContentType(e,t){this.setRequestHeader(e,`Content-Type`,t)}getRequestHeader(e,t){let n=e?.headers;if(n){if(Array.isArray(n)){let e=n.find(([e])=>e.toLowerCase()===t.toLowerCase());return e?e[1]:void 0}else if(n instanceof Headers)return n.get(t)??void 0;else if(NC(n))return n[t]??void 0}}setRequestHeader(e,t,n,r=!1){let i=e.headers;i?Array.isArray(i)?(!r||!i.some(([e])=>e.toLowerCase()===t.toLowerCase()))&&i.push([t,n]):i instanceof Headers?(!r||!i.has(t))&&i.set(t,n):NC(i)&&(!r||!i[t])&&(i[t]=n):e.headers={[t]:n}}setRequestBody(e,t){typeof t==`string`||typeof Blob<`u`&&(t instanceof Blob||t?.constructor.name===`Blob`)||typeof File<`u`&&(t instanceof File||t?.constructor.name===`File`)||typeof Uint8Array<`u`&&(t instanceof Uint8Array||t?.constructor.name===`Uint8Array`)?e.body=t:typeof t==`object`&&t&&(typeof t.getReader==`function`||typeof t.pipe==`function`&&typeof t.on==`function`)?(e.body=t,e.duplex=`half`):t&&(e.body=JSON.stringify(t))}async handleUnauthenticated(e,t,n){let r=n.authAttempt??0,i=r+1<YD?this.refresh(void 0,!0):void 0;if(i)return await i,this.request(e,t,{...n,authAttempt:r+1});throw this.clear(),this.onUnauthenticated?.(),new Xx(zx)}async startPkce(){let e=VE();this.storage.setString(`pkceState`,e);let t=VE().slice(0,128);this.storage.setString(`codeVerifier`,t);try{return{codeChallengeMethod:`S256`,codeChallenge:BC(await HE(t)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)}}catch(e){return console.warn(`Failed to hash code verifier. Falling back to 'plain' code challenge method`,e),{codeChallengeMethod:`plain`,codeChallenge:t}}}async requestAuthorization(e){let t=await this.ensureCodeChallenge(e??{}),n=new URL(this.authorizeUrl);n.searchParams.set(`response_type`,`code`),n.searchParams.set(`state`,this.storage.getString(`pkceState`)),n.searchParams.set(`client_id`,t.clientId??this.clientId),n.searchParams.set(`redirect_uri`,t.redirectUri??LE.getOrigin()),n.searchParams.set(`code_challenge_method`,t.codeChallengeMethod),n.searchParams.set(`code_challenge`,t.codeChallenge),n.searchParams.set(`scope`,t.scope??`openid profile`),LE.assign(n.toString())}processCode(e,t){let n={grant_type:XD.AuthorizationCode,code:e,client_id:t?.clientId??this.clientId??``,redirect_uri:t?.redirectUri??LE.getOrigin()},r=this.storage.getString(`codeVerifier`);return r&&(n.code_verifier=r),this.fetchTokens(n)}refreshIfExpired(e){return!this.refreshPromise&&this.accessTokenExpires!==void 0&&!this.isAuthenticated(e)&&this.refresh(e),this.refreshPromise??Promise.resolve()}refresh(e,t=!1){if(this.refreshPromise)return this.refreshPromise;if(!(!this.refreshToken&&!(this.clientId&&this.clientSecret)))return this.refreshPromise=this.runRefreshWithLock(e,t),this.refreshPromise}async runRefreshWithLock(e,t=!1){let n=()=>{let n=this.accessToken,r=this.getActiveLogin();r?.accessToken&&r.accessToken!==this.accessToken&&this.setAccessToken(r.accessToken,r.refreshToken);let i=this.accessToken!==n;return this.isAuthenticated(e)&&(!t||i)?Promise.resolve(this.getProfile()):this.refreshToken?this.fetchTokens({grant_type:XD.RefreshToken,client_id:this.clientId??``,refresh_token:this.refreshToken}):this.clientId&&this.clientSecret?this.startClientLogin(this.clientId,this.clientSecret):Promise.resolve(void 0)},r=typeof navigator<`u`?navigator.locks:void 0;if(!r?.request)return n();let i=`medplum-refresh:${this.storage.makeKey(`activeLogin`)}`;return r.request(i,n)}async startClientLogin(e,t){return this.clientId=e,this.clientSecret=t,this.fetchTokens({grant_type:XD.ClientCredentials,client_id:e,client_secret:t})}async startJwtBearerLogin(e,t,n){return this.clientId=e,this.fetchTokens({grant_type:XD.JwtBearer,client_id:e,assertion:t,scope:n})}async startJwtAssertionLogin(e){return this.fetchTokens({grant_type:XD.ClientCredentials,client_assertion_type:QD.JwtBearer,client_assertion:e})}setBasicAuth(e,t){this.clientId=e,this.clientSecret=t,this.basicAuth=zE(e+`:`+t)}setLogLevel(e){this.logLevel=e,this.options.verbose=e===`verbose`}getLogLevel(){return this.logLevel}setVerbose(e){this.logLevel=e?`verbose`:`none`,this.options.verbose=e}async fhircastSubscribe(e,t){if(!(typeof e==`string`&&e!==``))throw new Xx(Wx(`Invalid topic provided. Topic must be a valid string.`));if(!(typeof t==`object`&&Array.isArray(t)&&t.length>0))throw new Xx(Wx(`Invalid events provided. Events must be an array of event names containing at least one event.`));let n={channelType:`websocket`,mode:`subscribe`,topic:e,events:t},r=(await this.post(this.fhircastHubUrl,cD(n),ZE.FORM_URL_ENCODED))[`hub.channel.endpoint`];if(!r)throw Error(`Invalid response!`);return n.endpoint=r,n}async fhircastUnsubscribe(e){if(!lD(e))throw new Xx(Wx(`Invalid topic or subscriptionRequest. SubscriptionRequest must be an object.`));if(!(e.endpoint&&typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))throw new Xx(Wx(`Provided subscription request must have an endpoint in order to unsubscribe.`));e.mode=`unsubscribe`,await this.post(this.fhircastHubUrl,cD(e),ZE.FORM_URL_ENCODED)}fhircastConnect(e){return new mD(e)}async fhircastPublish(e,t,n,r){return rD(t)?this.post(this.fhircastHubUrl,pD(e,t,n,r),ZE.JSON):(iD(t),this.post(this.fhircastHubUrl,pD(e,t,n),ZE.JSON))}async fhircastGetContext(e){return this.get(`${this.fhircastHubUrl}/${e}`,{cache:`no-cache`})}async invite(e,t){return this.post(`admin/projects/`+e+`/invite`,t)}async handleTokenError(e){try{let t=await e.json();throw qx(t)?new Xx(t):t.error_description?new Xx(Ux(t.error_description)):Error(JSON.stringify(t))}catch(e){throw e instanceof Xx?(e.message=`Failed to fetch tokens: ${e.message}`,e):new Xx(Ux(`Failed to fetch tokens`),{cause:e})}}async fetchTokens(e){let t=new URLSearchParams(e),n={...this.defaultHeaders,"Content-Type":ZE.FORM_URL_ENCODED};this.basicAuth&&(n.Authorization=`Basic ${this.basicAuth}`),this.credentialsInHeader&&(t.delete(`client_id`),t.delete(`client_secret`),!this.basicAuth&&e.client_id&&e.client_secret&&(n.Authorization=`Basic ${zE(e.client_id+`:`+e.client_secret)}`));let r={method:`POST`,headers:n,body:t.toString(),credentials:`include`},i;try{i=await this.fetchWithRetry(this.tokenUrl,r)}catch(e){throw this.refreshPromise=void 0,e}i.ok||(this.clearActiveLogin(),this.onUnauthenticated?.(),await this.handleTokenError(i));let a=await i.json();return await this.verifyTokens(a),this.getProfile()}async verifyTokens(e){let t=e.access_token;if(gD(t)){let e=_D(t);if(Date.now()>=e.exp*1e3)throw this.clearActiveLogin(),new Xx(Bx);if(e.cid){if(e.cid!==this.clientId)throw this.clearActiveLogin(),new Xx(Vx)}else if(this.clientId&&e.client_id!==this.clientId)throw this.clearActiveLogin(),new Xx(Vx)}return this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile})}checkSessionDetailsMatchLogin(e){return this.sessionDetails&&e?e.profile?.reference?.endsWith(this.sessionDetails.profile.id)??!1:!0}setupStorageListener(){try{window.addEventListener(`storage`,e=>{if(e.key===null)LE.reload();else if(e.key===this.storage.makeKey(`activeLogin`)){let t=e.oldValue?JSON.parse(e.oldValue):void 0,n=e.newValue?JSON.parse(e.newValue):void 0;t?.profile.reference!==n?.profile.reference||!this.checkSessionDetailsMatchLogin(n)?LE.reload():n?this.setAccessToken(n.accessToken,n.refreshToken):this.clear()}})}catch{}}getSubscriptionManager(){return this.subscriptionManager||=new RD(this,ew(this.baseUrl,`/ws/subscriptions-r4`)),this.subscriptionManager}subscribeToCriteria(e,t){return this.getSubscriptionManager().addCriteria(e,t)}unsubscribeFromCriteria(e,t){this.subscriptionManager&&this.subscriptionManager.removeCriteria(e,t)}getMasterSubscriptionEmitter(){return this.getSubscriptionManager().getMasterEmitter()}};function eO(){if(!globalThis.fetch)throw Error(`Fetch not available in this environment`);return globalThis.fetch.bind(globalThis)}async function tO(e,t){let n=e.headers.get(`content-location`);if(n)return n;let r=e.headers.get(`location`);if(r)return r;if(qx(t)&&t.issue?.[0]?.diagnostics)return t.issue[0].diagnostics}function nO(e){let t=e.entry?.map(e=>e.resource)??[];return Object.assign(t,{bundle:e})}function rO(e){return NC(e)&&`data`in e&&`contentType`in e}function iO(e,t,n,r){return rO(e)?e:{data:e,filename:t,contentType:n,onProgress:r}}function aO(e){return NC(e)&&`docDefinition`in e}function oO(e,t,n,r){return aO(e)?e:{docDefinition:e,filename:t,tableLayouts:n,fonts:r}}function sO(e){return e.status===429||e.status>=500}function cO({parentContext:e,path:t,elements:n,profileUrl:r,debugMode:i,accessPolicyResource:a}){if(t===e?.path)return;i??=e?.debugMode??!1,a??=e?.accessPolicyResource;let o=lO(t,n,e,!!i),s=qC(t,`.`,2)[1];o=uO(o,a,s),o=dO(o,a,s);let c=Object.create(null);for(let[e,n]of Object.entries(o))c[t+`.`+e]=n;let l;if(e&&!e.isDefaultContext)l=e.getExtendedProps;else{let e=Object.create(null);l=t=>{let n=qC(t,`.`,2)[1];if(n){if(!e[n]){let t=fO(n,a?.hiddenFields);e[n]={hidden:t,readonly:t||fO(n,a?.readonlyFields)}}return e[n]}}}return{path:t,elements:o,elementsByPath:c,profileUrl:r??e?.profileUrl,debugMode:i,getExtendedProps:l,accessPolicyResource:a}}function lO(e,t,n,r){let i=Object.create(null);if(n)for(let[t,r]of Object.entries(n.elementsByPath)){let n=WC(e,t);n!==void 0&&(i[n]=r)}let a=!1;if(t)for(let[e,n]of Object.entries(t))e in i||(i[e]=n,a=!0);return r&&console.assert(a,`Unnecessary ElementsContext; not using any newly provided elements`),i}function uO(e,t,n){if(!t?.hiddenFields?.length)return e;let r=n?n+`.`:``;return Object.fromEntries(Object.entries(e).filter(([e])=>!fO(r+e,t.hiddenFields)))}function dO(e,t,n){if(!t?.readonlyFields?.length)return e;let r=Object.create(null),i=n?n+`.`:``;for(let[n,a]of Object.entries(e))fO(i+n,t.readonlyFields)?r[n]={...a,readonly:!0}:r[n]=a;return r}function fO(e,t){if(!t?.length)return!1;let n=e.split(`.`);for(let e=1;e<=n.length;e++){let r=n.slice(0,e).join(`.`);if(t.includes(r))return!0}return!1}function pO(e){return e.type!==void 0&&e.type.length>0}function mO(e,t,n,r){let i=wS(e,t.path,{profileUrl:r});if(i){let e=n.typeSchema?.elements??n.elements;return i.some(r=>OS(r,t,n,e))??!1}return console.assert(!1,`getNestedProperty[%s] in isDiscriminatorComponentMatch missed`,t.path),!1}function hO(e,t,n,r){if(e)for(let i of t){let t={value:e,type:i.typeSchema?.type??i.type?.[0].code};if(n.every(e=>mO(t,e,i,i.typeSchema?.url??r)))return i.name}}var gO=class{rootSchema;visitor;elementsContextStack;sliceAllowList;constructor(e,t,n){if(e.type===void 0)throw Error(`schema must include a type`);this.rootSchema=e;let r=cO({parentContext:void 0,path:this.rootSchema.type,elements:n??this.rootSchema.elements,profileUrl:this.rootSchema.name===this.rootSchema.type?void 0:this.rootSchema.url});if(r===void 0)throw Error(`Could not create root elements context`);this.elementsContextStack=[r],this.visitor=t}get elementsContext(){return this.elementsContextStack.at(-1)}crawlElement(e,t,n){this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema);let r=Object.fromEntries(Object.entries(this.elementsContext.elements).filter(([e])=>e.startsWith(t)));this.crawlElementsImpl(r,n),this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlSlice(e,t,n){let r=this.prepareSlices(n.slices,n);if(!CC(r.slices))throw Error(`cannot crawl slice ${t.name} since it has no type information`);this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema),this.sliceAllowList=[t],this.crawlSliceImpl(r.slices[0],t.path,r),this.sliceAllowList=void 0,this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlResource(){this.visitor.onEnterSchema&&this.visitor.onEnterSchema(this.rootSchema),this.crawlElementsImpl(this.rootSchema.elements,this.rootSchema.type),this.visitor.onExitSchema&&this.visitor.onExitSchema(this.rootSchema)}crawlElementsImpl(e,t){let n=_O(e);for(let e of n)this.crawlElementNode(e,t)}crawlElementNode(e,t){let n=t+`.`+e.key;this.visitor.onEnterElement&&this.visitor.onEnterElement(n,e.element,this.elementsContext);for(let n of e.children)this.crawlElementNode(n,t);CC(e.element?.slicing?.slices)&&this.crawlSlicingImpl(e.element.slicing,n),this.visitor.onExitElement&&this.visitor.onExitElement(n,e.element,this.elementsContext)}prepareSlices(e,t){let n=[];for(let t of e){if(!pO(t))continue;let e=t.type.find(e=>CC(e.profile))?.profile?.[0];if(CC(e)){let n=hS(e);n&&(t.typeSchema=n)}n.push(t)}return{...t,slices:n}}crawlSlicingImpl(e,t){let n=this.prepareSlices(e.slices,e);for(let e of n.slices)(this.sliceAllowList===void 0||this.sliceAllowList.includes(e))&&this.crawlSliceImpl(e,t,n)}crawlSliceImpl(e,t,n){let r=e.typeSchema;r&&this.visitor.onEnterSchema&&this.visitor.onEnterSchema(r),this.visitor.onEnterSlice&&this.visitor.onEnterSlice(t,e,n);let i,a=r?.elements??e.elements;CC(a)&&(i=cO({path:t,parentContext:this.elementsContext,elements:a})),i&&this.elementsContextStack.push(i),this.crawlElementsImpl(a,t),i&&this.elementsContextStack.pop(),this.visitor.onExitSlice&&this.visitor.onExitSlice(t,e,n),r&&this.visitor.onExitSchema&&this.visitor.onExitSchema(r)}};function _O(e){let t=[];function n(e,t){return t.startsWith(e+`.`)}function r(e,t){for(let i of e.children)if(n(i.key,t.key)){r(i,t);return}e.children.push(t)}let i=Object.entries(e);i.sort((e,t)=>e[0].localeCompare(t[0]));for(let[e,a]of i){let i={key:e,element:a,children:[]},o=!1;for(let a of t)if(n(a.key,e)){r(a,i),o=!0;break}o||t.push(i)}return t}var vO=`__sliceName`;function yO(e,t){let n=new xO(e,e.resourceType,`resource`);return new gO(t,n).crawlResource(),n.getDefaultValue()}function bO(e,t,n){for(let[r,i]of Object.entries(t)){if(n===void 0||n===r){TO(e,r,i,t);continue}let a=WC(n,r);a!==void 0&&TO(e,a,i,t)}return e}var xO=class{rootValue;schemaStack;valueStack;constructor(e,t,n){this.schemaStack=[],this.valueStack=[],this.rootValue=jC(e),this.valueStack.splice(0,this.valueStack.length,{type:n,path:t,values:[this.rootValue]})}get schema(){return this.schemaStack.at(-1)}get value(){return this.valueStack.at(-1)}onEnterSchema(e){this.schemaStack.push(e)}onExitSchema(){this.schemaStack.pop()}onEnterElement(e,t,n){let r=this.value.values,i=this.value.path,a=WC(i,e);if(a===void 0)throw Error(`Expected ${e} to be prefixed by ${i}`);let o=[];for(let e of r){if(e===void 0)continue;let r=WC(n.path,i),s=Array.isArray(e)?e:[e];for(let e of s){SO(e,a,t,n.elements,r),TO(e,a,t,n.elements);let i=wO(e,a,n.elements,r);i!==void 0&&o.push(i)}}this.valueStack.push({type:`element`,path:e,values:o})}onExitElement(e,t,n){if(!this.valueStack.pop())throw Error(`Expected value context to exist when exiting element`);let r=WC(this.value.path,e);if(r===void 0)throw Error(`Expected ${e} to be prefixed by ${this.value.path}`);let i=WC(n.path,this.value.path);for(let e of this.value.values){let a=wO(e,r,n.elements,i);if(Array.isArray(a))for(let e=a.length-1;e>=0;e--){let t=a[e];CC(t)||a.splice(e,1)}SC(a)&&CO(e,void 0,r,t)}}onEnterSlice(e,t,n){let r=this.value.values,i=[];for(let e of r)if(e!==void 0){let r=Array.isArray(e)?e:[e],a=this.getMatchingSliceValues(r,t,n);i.push(a)}this.valueStack.push({type:`slice`,path:e,values:i})}getMatchingSliceValues(e,t,n){let r=[];for(let i of e)(i[vO]??hO(i,[t],n.discriminator,this.schema.url))===t.name&&r.push(i);for(let n=r.length;n<t.min;n++)if(UC(t.type[0].code)){let t=Object.create(null);r.push(t),e.push(t)}return r}onExitSlice(){let e=this.valueStack.pop();if(!e)throw Error(`Expected value context to exist in onExitSlice`);for(let t of e.values)for(let e=t.length-1;e>=0;e--){let n=t[e];vO in n&&delete n[vO]}}getDefaultValue(){return this.rootValue}};function SO(e,t,n,r,i){let a=wO(e,t,r,i);n.min>0&&a===void 0&&UC(n.type[0].code)&&(n.isArray?CO(e,[Object.create(null)],t,n):CO(e,Object.create(null),t,n))}function CO(e,t,n,r){if(n.includes(`.`))throw Error(`key cannot be nested`);let i=n;if(n.includes(`[x]`)){let e=r.type[0].code;i=n.replace(`[x]`,HC(e))}t===void 0?delete e[i]:e[i]=t}function wO(e,t,n,r){let i=t.split(`.`),a=e,o;for(let e=0;e<i.length;e++){let t=i[e];if(t.includes(`[x]`)){let a=n[(r?r+`.`:``)+i.slice(0,e+1).join(`.`)].type[0].code;t=t.replace(`[x]`,HC(a))}if(e===i.length-1){o=Array.isArray(a)?a.map(e=>e[t]):a[t];continue}if(Array.isArray(a))a=a.map(e=>e[t]);else if(NC(a)){if(a[t]===void 0)return;a=a[t]}else return}return o}function TO(e,t,n,r){if(!(n.fixed||n.pattern))return e;if(Array.isArray(e))return e.map(e=>TO(e,t,n,r));e??=Object.create(null);let i=e,a=t.split(`.`),o=i;for(let e=0;e<a.length;e++){let t=a[e];if(t.includes(`[x]`)){let n=r[a.slice(0,e+1).join(`.`)].type[0].code;t=t.replace(`[x]`,HC(n))}if(e===a.length-1){let e=Array.isArray(o)?o:[o];for(let r of e)n.fixed?r[t]??=n.fixed.value:n.pattern&&(r[t]=EO(r[t],n.pattern.value))}else{if(!(t in o)){let n=a.slice(0,e+1).join(`.`);o[t]=r[n].isArray?[Object.create(null)]:Object.create(null)}o=o[t]}}return i}function EO(e,t){if(Array.isArray(t)&&(Array.isArray(e)||e===void 0))return(e?.length??0)>0?e:jC(t);if(NC(t)&&(NC(e)&&!Array.isArray(e)||e===void 0)){let n=jC(e)??Object.create(null);for(let e of Object.keys(t))n[e]=EO(n[e],t[e]);return n}return e}var DO=Object.prototype.hasOwnProperty;function OO(e){return e===void 0?`undefined`:e===null?`null`:Array.isArray(e)?`array`:typeof e}function kO(e,t){let n=[];for(let r in e)DO.call(e,r)&&e[r]!==void 0&&!(DO.call(t,r)&&t[r]!==void 0)&&n.push(r);return n}function AO(e,t){let n=[];for(let r in e)DO.call(e,r)&&e[r]!==void 0&&DO.call(t,r)&&t[r]!==void 0&&n.push(r);return n}function jO(e){return e.op===`add`}function MO(e){return e.op===`remove`}function NO(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function PO(e,t,n,r=IO){let i=Math.max(e.length,t.length),a=new Map([[0,{operations:[],cost:0}]]);function o(s,c){let l=s*i+c,u=a.get(l);if(u===void 0){if(s>0&&c>0&&!r(e[s-1],t[c-1],n.add(String(s-1))).length)u=o(s-1,c-1);else{let n=[];if(s>0){let e=o(s-1,c),t={op:`remove`,index:s-1};n.push(NO(e,t))}if(c>0){let e=o(s,c-1),r={op:`add`,index:s-1,value:t[c-1]};n.push(NO(e,r))}if(s>0&&c>0){let r=o(s-1,c-1),i={op:`replace`,index:s-1,original:e[s-1],value:t[c-1]};n.push(NO(r,i))}u=n.sort((e,t)=>e.cost-t.cost)[0]}a.set(l,u)}return u}let s=isNaN(e.length)||e.length<=0?0:e.length,[c]=o(s,isNaN(t.length)||t.length<=0?0:t.length).operations.reduce(([e,t],i)=>{if(jO(i)){let r=i.index+1+t,a=r<s+t?String(r):`-`,o={op:i.op,path:n.add(a).toString(),value:i.value};return[e.concat(o),t+1]}else if(MO(i)){let r={op:i.op,path:n.add(String(i.index+t)).toString()};return[e.concat(r),t-1]}else{let a=n.add(String(i.index+t)),o=r(i.original,i.value,a);return[e.concat(...o),t]}},[[],0]);return c}function FO(e,t,n,r=IO){let i=[];return kO(e,t).forEach(e=>{i.push({op:`remove`,path:n.add(e).toString()})}),kO(t,e).forEach(e=>{i.push({op:`add`,path:n.add(e).toString(),value:t[e]})}),AO(e,t).forEach(a=>{i.push(...r(e[a],t[a],n.add(a)))}),i}function IO(e,t,n,r=IO){if(e===t)return[];let i=OO(e),a=OO(t);return i===`array`&&a===`array`?PO(e,t,n,r):i===`object`&&a===`object`?FO(e,t,n,r):[{op:`replace`,path:n.toString(),value:t}]}function LO(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function RO(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}var zO=class e{tokens;constructor(e=[``]){this.tokens=e}static fromJSON(t){let n=t.split(`/`).map(LO);if(n[0]!==``)throw Error(`Invalid JSON Pointer: ${t}`);return new e(n)}toString(){return this.tokens.map(RO).join(`/`)}evaluate(e){let t=null,n=``,r=e;for(let e=1,i=this.tokens.length;e<i;e++){if(t=r,n=this.tokens[e],n===`__proto__`||n===`constructor`||n===`prototype`)throw Error(`Invalid path: `+this.toString());if(t!=null&&(typeof t==`object`||typeof t==`function`)&&!Object.hasOwn(t,n)&&n in t)throw Error(`Invalid inherited key: `+n);r=t?.[n]}return{parent:t,key:n,value:r}}get(e){return this.evaluate(e).value}set(e,t){let n=this.evaluate(e);n.parent&&(n.parent[n.key]=t)}push(e){this.tokens.push(e)}add(t){return new e(this.tokens.concat(String(t)))}parent(){return new e(this.tokens.length>1?this.tokens.slice(0,-1):[``])}};function BO(e){function t(n,r,i){let a=e(n,r,i);return Array.isArray(a)?a:IO(n,r,i,t)}return t}function VO(e,t,n){let r=new zO;return(n?BO(n):IO)(e,t,r)}function HO(e){return e.match(/^\((.+)\)\.identifier$/)?.[1]}function UO(e,t){return new Qw(e,new lT(t,new eT(`identifier`)))}var WO={BOOLEAN:`BOOLEAN`,NUMBER:`NUMBER`,QUANTITY:`QUANTITY`,TEXT:`TEXT`,REFERENCE:`REFERENCE`,CANONICAL:`CANONICAL`,DATE:`DATE`,DATETIME:`DATETIME`,PERIOD:`PERIOD`,UUID:`UUID`};function GO(e,t){return Uw.types[e]?.searchParamsDetails?.[t.code]??qO(e,t)}function KO(e,t,n){let r=Uw.types[e];r||(r={},Uw.types[e]=r),r.searchParamsDetails||={},r.searchParamsDetails[t]=n}function qO(e,t){let n=t.code,r=t.expression,i=QO(e,r),a={elementDefinitions:[],propertyTypes:new Set,array:!1};for(let n of i){let r=tk(n),i=JC(()=>r.join(`.`));r.length===1&&r[0]instanceof wx&&r[0].operator!==`.`?a.propertyTypes.add(`boolean`):t.code.endsWith(`:identifier`)?a.propertyTypes.add(`Identifier`):i().endsWith(`extension.value.code`)||i().endsWith(`extension.value.coding.code`)?(a.array=!0,a.propertyTypes.clear(),a.propertyTypes.add(`code`)):JO(a,r,e,1),i().endsWith(`extension.valueDateTime`)&&(a.array=!1,a.propertyTypes.clear(),a.propertyTypes.add(`dateTime`))}let o;if(t.code.endsWith(`:identifier`)){let t=HO(r);if(t===void 0)throw Error(`Unexpected expression for derived identifier search parameter: ${r}`);o=UO(r,$O(e,t))}else o=$O(e,r);let s=a.elementDefinitions.map(e=>({...e,type:e.type?.filter(e=>a.propertyTypes.has(e.code))})).filter(e=>e.type&&e.type.length>0),c={type:ZO(t,a.propertyTypes),elementDefinitions:s,parsedExpression:o,array:a.array,referenceTargetTypes:nk(t,s)};return KO(e,n,c),c}function JO(e,t,n,r){let i=t[r];if(i instanceof rT){e.propertyTypes.add(i.right.toString());return}if(i instanceof bT){YO(e,i);return}let a=i.toString(),o=zw(n,a);if(!o)throw Error(`Element definition not found for ${n} ${a}`);let s=!1,c=r+1;c<t.length&&t[c]instanceof xT&&(s=!0,c++);let l=t[c];if(o.isArray&&!s&&(e.array=!0),c===t.length-1){if(l instanceof rT){e.elementDefinitions.push(o),e.propertyTypes.add(l.right.toString());return}if(l instanceof bT&&l.name===`ofType`){e.elementDefinitions.push(o),e.propertyTypes.add(l.args[0].toString());return}}if(c>=t.length){e.elementDefinitions.push(o);for(let t of o.type??iw)e.propertyTypes.add(t.code);return}for(let n of o.type??iw){let r=n.code;XO(r)&&(r=o.type[0].code),JO(e,t,r,c)}}function YO(e,t){if(t.name===`as`){e.propertyTypes.add(t.args[0].toString());return}if(t.name===`ofType`){e.propertyTypes.add(t.args[0].toString());return}if(t.name===`resolve`){e.propertyTypes.add(`string`);return}if(t.name===`where`&&t.args[0]instanceof hT){e.propertyTypes.add(t.args[0].right.toString());return}throw Error(`Unhandled FHIRPath function: ${t.name}`)}function XO(e){return e===`Element`||e===`BackboneElement`}function ZO(e,t){switch(e.type){case`date`:return t.size===1&&t.has(X.date)?WO.DATE:WO.DATETIME;case`number`:return WO.NUMBER;case`quantity`:return WO.QUANTITY;case`reference`:return t.has(X.canonical)?WO.CANONICAL:WO.REFERENCE;case`token`:return t.size===1&&t.has(X.boolean)?WO.BOOLEAN:WO.TEXT;default:return WO.TEXT}}function QO(e,t){let n=[];return ek(e,IT(t).child,n),n}function $O(e,t){let n=[],r=IT(t);if(ek(e,r.child,n),n.length===0)return r;let i=n[0];for(let e=1;e<n.length;e++)i=new uT(i,n[e]);return new Qw(`<original-not-available>`,i)}function ek(e,t,n){t instanceof uT?(ek(e,t.left,n),ek(e,t.right,n)):t.toString().includes(e+`.`)&&n.push(t)}function tk(e){return e instanceof rT||e instanceof xT?[tk(e.left),e].flat():e instanceof wx&&e.operator!==`.`?[e]:e instanceof lT?[tk(e.left),tk(e.right)].flat():e instanceof bT&&(e.name===`where`&&!(e.args[0]instanceof hT)||e.name===`last`)?[]:[e]}function nk(e,t){if(e.target?.length===1)return e.target;if(t){let e=new Set;for(let n of t)for(let t of n.type)if(!(t.code!==`Reference`||!t.targetProfile))for(let n of t.targetProfile){let t=n.split(`/`).at(-1);t&&t!==`Resource`&&e.add(t)}if(e.size>0)return Array.from(e)}}var rk=`https://meta.medplum.com/releases`,ik=new Map;function ak(e){let t=e;if(!t.tag_name?.startsWith(`v`))throw Error(`Manifest missing valid tag_name starting with a 'v' (eg. v5.1.15)`);let n=t.assets;if(!n?.length)throw Error(`Manifest missing assets list`);for(let e of n){if(!e.browser_download_url)throw Error(`Asset missing browser download URL`);if(!e.name)throw Error(`Asset missing name`)}}async function ok(e,t,n){let r=t?ik.get(t):void 0;if(!r){let i=t?`v${t}`:`latest`,a=new URL(`${rk}/${i}.json`);if(a.searchParams.set(`a`,e),a.searchParams.set(`c`,BD),n)for(let[e,t]of Object.entries(n))a.searchParams.set(e,t);let o=await fetch(a.toString());if(o.status!==200){let e;try{e=(await o.json()).message}catch(e){console.error(`Failed to parse message from body: ${Y(e)}`)}throw Error(`Received status code ${o.status} while fetching manifest for version '${t??`latest`}'. Message: ${e}`)}let s=await o.json();ak(s),r=s,ik.set(r.tag_name.slice(1),r)}return r}async function sk(e){let t=await ok(e);if(!t.tag_name.startsWith(`v`))throw Error(`Invalid release name found. Release tag '${t.tag_name}' did not start with 'v'`);return t.tag_name.slice(1)}var ck=(0,b.createContext)(void 0);function lk(){return(0,b.useContext)(ck)}function Q(){return lk().medplum}function uk(){return lk().navigate}function dk(){return lk().profile}var fk=[`change`,`storageInitialized`,`storageInitFailed`,`profileRefreshing`,`profileRefreshed`];function pk(e){let t=e.medplum,n=e.navigate??mk,[r,i]=(0,b.useState)({profile:t.getProfile(),loading:t.isLoading()});(0,b.useEffect)(()=>{function e(){i(e=>({...e,profile:t.getProfile(),loading:t.isLoading()}))}for(let n of fk)t.addEventListener(n,e);return()=>{for(let n of fk)t.removeEventListener(n,e)}},[t]);let a=(0,b.useMemo)(()=>({...r,medplum:t,navigate:n}),[r,t,n]);return(0,I.jsx)(ck.Provider,{value:a,children:e.children})}function mk(e){window.location.assign(e)}var hk=new Map,gk=e=>(0,b.useMemo)(()=>{if(!e)return;let t=e.split(`?`)[0];if(!t)return e;let n;try{n=new URLSearchParams(new URL(e).search)}catch{return e}if(!n.has(`Key-Pair-Id`)||!n.has(`Signature`))return e;let r=n.get(`Expires`);if(!r||r.length>13)return e;let i=hk.get(t);if(i){let e=new URLSearchParams(new URL(i).search).get(`Expires`);if(e&&Number.parseInt(e,10)*1e3-5e3>Date.now())return i}return hk.set(t,e),e},[e]),_k=3e3;function vk(e,t,n){let r=Q(),i=dk()?e:void 0,[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(n?.subscriptionProps),l=(0,b.useRef)(!1),u=(0,b.useRef)(void 0),d=(0,b.useRef)(void 0),f=(0,b.useRef)(void 0),p=(0,b.useRef)(t);p.current=t;let m=(0,b.useRef)(n?.onWebSocketOpen);m.current=n?.onWebSocketOpen;let h=(0,b.useRef)(n?.onWebSocketClose);h.current=n?.onWebSocketClose;let g=(0,b.useRef)(n?.onSubscriptionConnect);g.current=n?.onSubscriptionConnect;let _=(0,b.useRef)(n?.onSubscriptionDisconnect);_.current=n?.onSubscriptionDisconnect;let v=(0,b.useRef)(n?.onError);v.current=n?.onError,(0,b.useEffect)(()=>{TC(n?.subscriptionProps,s)||c(n?.subscriptionProps)},[s,n]),(0,b.useEffect)(()=>{u.current&&=(clearTimeout(u.current),void 0);let e=!1;return(d.current!==i||!TC(f.current,s))&&(e=!0),e&&d.current&&r.unsubscribeFromCriteria(d.current,f.current),d.current=i,f.current=s,e&&i?o(r.subscribeToCriteria(i,s)):i||o(void 0),()=>{u.current=setTimeout(()=>{o(void 0),i&&r.unsubscribeFromCriteria(i,s)},_k)}},[r,i,s]);let y=(0,b.useCallback)(e=>{p.current?.(e.payload)},[]),x=(0,b.useCallback)(()=>{m.current?.()},[]),S=(0,b.useCallback)(()=>{h.current?.()},[]),C=(0,b.useCallback)(e=>{g.current?.(e.payload.subscriptionId)},[]),w=(0,b.useCallback)(e=>{_.current?.(e.payload.subscriptionId)},[]),T=(0,b.useCallback)(e=>{v.current?.(e.payload)},[]);(0,b.useEffect)(()=>a?(l.current||=(a.addEventListener(`message`,y),a.addEventListener(`open`,x),a.addEventListener(`close`,S),a.addEventListener(`connect`,C),a.addEventListener(`disconnect`,w),a.addEventListener(`error`,T),!0),()=>{l.current=!1,a.removeEventListener(`message`,y),a.removeEventListener(`open`,x),a.removeEventListener(`close`,S),a.removeEventListener(`connect`,C),a.removeEventListener(`disconnect`,w),a.removeEventListener(`error`,T)}):()=>void 0,[a,y,x,S,C,w,T])}function yk(e){let t=Q(),{resourceType:n,countCriteria:r,subscriptionCriteria:i}=e,[a,o]=(0,b.useState)(0),s=(0,b.useCallback)(e=>{t.search(n,r,{cache:e}).then(e=>o(e.total)).catch(console.error)},[t,n,r]);return(0,b.useEffect)(()=>{s(`default`)},[s]),vk(i,()=>{s(`reload`)}),a}function bk(e,t){let n=Q(),[r,i]=(0,b.useState)(()=>xk(n,e)),a=(0,b.useCallback)(e=>{TC(e,r)||i(e)},[r]);return(0,b.useEffect)(()=>{let r=!0,i=xk(n,e);return!i&&Hw(e)?n.readReference(e).then(e=>{r&&a(e)}).catch(e=>{r&&(a(void 0),t&&t(Zx(e)))}):a(i),(()=>r=!1)},[n,e,a,t]),r}function xk(e,t){if(t){if(Vw(t))return t;if(Hw(t))return e.getCachedReference(t)}}var Sk={group:`group`,display:`display`,question:`question`,boolean:`boolean`,decimal:`decimal`,integer:`integer`,date:`date`,dateTime:`dateTime`,time:`time`,string:`string`,text:`text`,url:`url`,choice:`choice`,openChoice:`open-choice`,attachment:`attachment`,reference:`reference`,quantity:`quantity`},Ck=`${Ox}/fhir/StructureDefinition/questionnaire-itemControl`,wk=`${Ox}/fhir/StructureDefinition/questionnaire-referenceFilter`,Tk=`${Ox}/fhir/StructureDefinition/questionnaire-referenceResource`,Ek=`${Ox}/fhir/StructureDefinition/questionnaire-validationError`,Dk=`${Ox}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression`,Ok=`${Ox}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression`,kk=`${Ox}/fhir/StructureDefinition/questionnaire-signatureRequired`,Ak=`${Ox}/fhir/StructureDefinition/questionnaireresponse-signature`,jk=`${Ox}/fhir/StructureDefinition/questionnaire-hidden`;function Mk(e){return e.type===`choice`||e.type===`open-choice`}function Nk(e,t){return{...t,item:Pk(e.item,t.item,t)}}function Pk(e,t,n){if(!t)return t;let r=[];for(let i of t){let t=e?.find(e=>e.linkId===i.linkId);t&&!Fk(t,n)||(t?.item&&i.item?r.push({...i,item:Pk(t.item,i.item,n)}):r.push(i))}return r}function Fk(e,t){if(_C(e,jk)?.valueBoolean===!0)return!1;let n=Ik(e,t);return n===void 0?Lk(e,t):n}function Ik(e,t){let n=_C(e,Dk);if(t&&n){let e=n.valueExpression?.expression;if(e){let n=AS(t);return jS(RT(e,[n],{"%resource":n}))}}}function Lk(e,t){if(!e.enableWhen)return!0;let n=e.enableBehavior??`any`;for(let r of e.enableWhen){let e=Wk(t?.item,r.question);if(r.operator===`exists`&&!r.answerBoolean&&!e?.length){if(n===`any`)return!0;continue}let{anyMatch:i,allMatch:a}=Kk(r,e,n);if(n===`any`&&i)return!0;if(n===`all`&&!a)return!1}return n!==`any`}function Rk(e,t,n=t.item){for(let r of e){let e=n?.find(e=>e.linkId===r.linkId);e&&(zk(t,r,e),r.item&&e.item&&Rk(r.item,t,e.item))}}function zk(e,t,n){try{let r=Hk(t,e);if(!r)return;let i=Vk(t,r);if(!i)return;n.answer=[i]}catch(e){n.extension=[{url:Ek,valueString:`Expression evaluation failed: ${Y(e)}`}]}}var Bk={[Sk.boolean]:[X.boolean],[Sk.date]:[X.date],[Sk.dateTime]:[X.dateTime],[Sk.time]:[X.time],[Sk.url]:[X.string,X.uri,X.url],[Sk.attachment]:[X.Attachment],[Sk.reference]:[X.Reference],[Sk.quantity]:[X.Quantity],[Sk.decimal]:[X.decimal,X.integer],[Sk.integer]:[X.decimal,X.integer]};function Vk(e,t){if(e.type){if(e.type===Sk.choice||e.type===Sk.openChoice)return{[`value${HC(t.type)}`]:t.value};if(e.type===Sk.string||e.type===Sk.text)return typeof t.value==`string`?{valueString:t.value}:void 0;if(Bk[e.type]?.includes(t.type))return{[`value${HC(e.type)}`]:t.value}}}function Hk(e,t){if(!t)return;let n=_C(e,Ok);if(n){let e=n.valueExpression?.expression;if(e){let n=AS(t),r=RT(e,[n],{"%resource":n});return r.length===0?void 0:r[0]}}}function Uk(e,t,n){let r=[];for(let i of e){let e=n.answerOption?.find(e=>aw(rA(e))===i);if(e){let n=rA(e);n&&r.push({[t]:n.value})}}return r}function Wk(e,t){for(let n of e??iw){if(n.linkId===t)return n.answer;if(n.item){let e=Wk(n.item,t);if(e)return e}}}function Gk(e,t,n){if(n===`exists`)return!!e===t.value;if(e){let[{value:r}]=RT(`%actualAnswer ${n===`=`||n===`!=`?n?.replace(`=`,`~`):n} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":t});return r}else return!1}function Kk(e,t,n){let r=t||[],i=iA(e),a=!1,o=!0;for(let t of r){let r=aA(t),{operator:s}=e;if(Gk(r,i,s)?a=!0:o=!1,n===`any`&&a)break}return{anyMatch:a,allMatch:o}}function qk(e){let t=_C(e,Tk);if(t){if(t.valueCode!==void 0)return[t.valueCode];if(t.valueCodeableConcept)return t.valueCodeableConcept?.coding?.map(e=>e.code)}}function Jk(e,t){let n=jC(e),r=_C(n,Tk);return!t||t.length===0?(r&&(n.extension=n.extension?.filter(e=>e!==r)),n):(r||(n.extension??=[],r={url:Tk},n.extension.push(r)),t.length===1?(r.valueCode=t[0],delete r.valueCodeableConcept):(r.valueCodeableConcept={coding:t.map(e=>({code:e}))},delete r.valueCode),n)}function Yk(e,t,n){let r=_C(e,wk);if(!r?.valueString)return;let i=r.valueString;t?.reference&&(i=i.replaceAll(`$subj`,t.reference)),n?.reference&&(i=i.replaceAll(`$encounter`,n.reference));let a={},o=i.split(`&`);for(let e of o){let[t,n]=qC(e,`=`,2);a[t]=n}return a}function Xk(e,t){return{resourceType:`QuestionnaireResponse`,questionnaire:e.url??aC(e),item:Zk(e.item,t?.item),status:`in-progress`}}function Zk(e,t){let n;for(let r of e??iw){if(r.type===Sk.display)continue;let e=t?.filter(e=>e.linkId===r.linkId);if(e?.length)for(let t of e)t.id=t.id??eA(),t.text=t.text??r.text,t.item=Zk(r.item,t.item),t.answer=tA(r,t),n=YC(n,t);else n=YC(n,Qk(r))}return n}function Qk(e){return{id:eA(),linkId:e.linkId,text:e.text,item:Zk(e.item,void 0),answer:tA(e)}}var $k=1;function eA(){return`id-`+$k++}function tA(e,t){if(!(e.type===Sk.display||e.type===Sk.group)){if(t?.answer&&t.answer.length>0)return t.answer;if(e.initial&&e.initial.length>0)return e.initial.map(e=>({...e}));if(e.answerOption)return e.answerOption.filter(e=>e.initialSelected).map(e=>({...e,initialSelected:void 0}))}}function nA(e){return IS({type:`QuestionnaireItemInitial`,value:e},`value`)}function rA(e){return IS({type:`QuestionnaireItemAnswerOption`,value:e},`value`)}function iA(e){return IS({type:`QuestionnaireItemEnableWhen`,value:e},`answer`)}function aA(e){return IS({type:`QuestionnaireResponseItemAnswer`,value:e},`value`)}function oA(e){let t=bk(e.questionnaire),n=bk(e.defaultValue),[,r]=(0,b.useReducer)(e=>e+1,0),i=(0,b.useRef)({activePage:0});if(!i.current.questionnaire&&t&&(i.current.questionnaire=t,i.current.pages=e.disablePagination?void 0:sA(t)),t&&e.defaultValue&&n&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=Xk(t,n),p()),t&&!e.defaultValue&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=Xk(t),p()),!i.current.questionnaire||!i.current.questionnaireResponse)return{loading:!0};function a(e,t){let n=i.current.questionnaireResponse;for(let t of e)n=n?.item?.find(e=>t.id?e.id===t.id:e.linkId===t.linkId);return t&&(n=n?.item?.find(e=>e.linkId===t.linkId)),n}function o(){i.current.activePage=(i.current.activePage??0)+1,r()}function s(){i.current.activePage=(i.current.activePage??0)-1,r()}function c(e,t){let n=a(e);n&&(n.item??=[],n.item.push(Qk(t)),p())}function l(e,t){let n=a(e,t);n&&(n.answer??=[],n.answer.push({}),p())}function u(e,t,n){let r=a(e,t);r&&(r.answer=n,p())}function d(e){let t=i.current.questionnaireResponse;t&&(e?(t.extension=t.extension??[],t.extension=t.extension.filter(e=>e.url!==Ak),t.extension.push({url:Ak,valueSignature:e})):t.extension=t.extension?.filter(e=>e.url!==Ak),p())}function f(){let e=i.current.questionnaire;if(e?.item){let t=i.current.questionnaireResponse;Rk(e.item,t)}}function p(){let t=i.current.questionnaireResponse,n=i.current.questionnaire;!t||!n||(f(),r(),e.onChange?.(Nk(n,t)))}return{loading:!1,pagination:!!i.current.pages,questionnaire:i.current.questionnaire,questionnaireResponse:Nk(i.current.questionnaire,i.current.questionnaireResponse),subject:e.subject,encounter:e.encounter,activePage:i.current.activePage,pages:i.current.pages,items:cA(i.current.questionnaire,i.current.pages,i.current.activePage),responseItems:lA(i.current.questionnaireResponse,i.current.pages,i.current.activePage),onNextPage:o,onPrevPage:s,onAddGroup:c,onAddAnswer:l,onChangeAnswer:u,onChangeSignature:d}}function sA(e){if(e?.item&&_C(e?.item?.[0],Ck)?.valueCodeableConcept?.coding?.[0]?.code===`page`)return e.item.map((e,t)=>({linkId:e.linkId,title:e.text??`Page ${t+1}`,group:e}))}function cA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function lA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function uA(e,t,n={leading:!1}){let[r,i]=(0,b.useState)(e),a=(0,b.useRef)(!1),o=(0,b.useRef)(void 0),s=(0,b.useRef)(!1),c=(0,b.useCallback)(()=>window.clearTimeout(o.current),[]);return(0,b.useEffect)(()=>{a.current&&(!s.current&&n.leading?(s.current=!0,i(e),o.current=setTimeout(()=>{s.current=!1},t)):(c(),o.current=setTimeout(()=>{s.current=!1,i(e)},t)))},[e,n.leading,t,c]),(0,b.useEffect)(()=>(a.current=!0,c),[c]),[r,c]}var dA=250;function fA(e,t,n){return mA(`searchOne`,e,t,n)}function pA(e,t,n){return mA(`searchResources`,e,t,n)}function mA(e,t,n,r){let i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(),d=(0,b.useMemo)(()=>({resourceType:t,query:n}),[i.fhirSearchUrl(t,n).toString()]),f=r?.enabled??!0,[p]=uA(d,r?.debounceMs??dA,{leading:!0});return(0,b.useEffect)(()=>{if(!f)return()=>{};o(!0);let t=!0;return i[e](p.resourceType,p.query).then(e=>{t&&(o(!1),c(e),u(Lx))}).catch(e=>{t&&(o(!1),c(void 0),u(Zx(e)))}),()=>{t=!1}},[i,e,p,f]),[s,a,l]}function hA(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:sw(t,e.options)}):null}var gA=[`meta`,`implicitRules`,`contained`,`extension`,`modifierExtension`],_A=[`language`,`text`],vA=(0,b.createContext)({path:``,profileUrl:void 0,elements:Object.create(null),elementsByPath:Object.create(null),getExtendedProps:()=>({readonly:!1,hidden:!1}),accessPolicyResource:void 0,debugMode:!1,isDefaultContext:!0});vA.displayName=`ElementsContext`;var yA=[`extension`,`modifierExtension`],bA=[`id`,...gA].filter(e=>!yA.includes(e));function xA(e){return Object.entries(e).filter(([e,t])=>!CC(t.type)||t.max===0||t.path.toLowerCase().endsWith(`extension.url`)&&t.fixed||yA.includes(e)&&!CC(t.slicing?.slices)||bA.includes(e)?!1:!(_A.includes(e)&&t.path.split(`.`).length===2||e.includes(`.`)))}function SA(e,t){return e.line&&e.line.length>t?e.line[t]:``}function CA(e,t,n){let r=e.line||[];for(;r.length<=t;)r.push(``);return r[t]=n,{...e,line:wC(r)}}function wA(e){let[t,n]=(0,b.useState)(e.defaultValue||{}),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a,o,s,c,l,u]=(0,b.useMemo)(()=>[`use`,`type`,`line1`,`line2`,`city`,`state`,`postalCode`].map(t=>r(e.path+`.`+t)),[r,e.path]);function d(r){n(e=>({...e,...r})),e.onChange&&e.onChange({...t,...r})}function f(e){d({use:e})}function p(e){d({type:e})}function m(e){d(CA(t,0,e))}function h(e){d(CA(t,1,e))}function g(e){d({city:e})}function _(e){d({state:e})}function v(e){d({postalCode:e})}return(0,I.jsxs)(V,{gap:`xs`,wrap:`nowrap`,grow:!0,children:[(0,I.jsx)(yg,{disabled:e.disabled||i?.readonly,"data-testid":`address-use`,defaultValue:t.use,onChange:e=>f(e.currentTarget.value),data:[``,`home`,`work`,`temp`,`old`,`billing`]}),(0,I.jsx)(yg,{disabled:e.disabled||a?.readonly,"data-testid":`address-type`,defaultValue:t.type,onChange:e=>p(e.currentTarget.value),data:[``,`postal`,`physical`,`both`]}),(0,I.jsx)(yb,{disabled:e.disabled||o?.readonly,placeholder:`Line 1`,defaultValue:SA(t,0),onChange:e=>m(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||s?.readonly,placeholder:`Line 2`,defaultValue:SA(t,1),onChange:e=>h(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||c?.readonly,placeholder:`City`,defaultValue:t.city,onChange:e=>g(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||l?.readonly,placeholder:`State`,defaultValue:t.state,onChange:e=>_(e.currentTarget.value)}),(0,I.jsx)(yb,{disabled:e.disabled||u?.readonly,placeholder:`Postal Code`,defaultValue:t.postalCode,onChange:e=>v(e.currentTarget.value)})]})}function TA(e){let t=dk(),[n,r]=(0,b.useState)(e.defaultValue||{});function i(n){let i=n?{text:n,authorReference:t&&iC(t),time:new Date().toISOString()}:{};r(i),e.onChange&&e.onChange(i)}return(0,I.jsx)(yb,{disabled:e.disabled,name:e.name,placeholder:`Annotation text`,defaultValue:n.text,onChange:e=>i(e.currentTarget.value)})}var EA={outline:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},filled:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`currentColor`,stroke:`none`}},DA=(e,t,n,r)=>{let i=(0,b.forwardRef)(({color:n=`currentColor`,size:i=24,stroke:a=2,title:o,className:s,children:c,...l},u)=>(0,b.createElement)(`svg`,{ref:u,...EA[e],width:i,height:i,className:[`tabler-icon`,`tabler-icon-${t}`,s].join(` `),...e===`filled`?{fill:n}:{strokeWidth:a,stroke:n},...l},[o&&(0,b.createElement)(`title`,{key:`svg-title`},o),...r.map(([e,t])=>(0,b.createElement)(e,t)),...Array.isArray(c)?c:[c]]));return i.displayName=`${n}`,i},OA=DA(`outline`,`adjustments-horizontal`,`AdjustmentsHorizontal`,[[`path`,{d:`M12 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-0`}],[`path`,{d:`M4 6l8 0`,key:`svg-1`}],[`path`,{d:`M16 6l4 0`,key:`svg-2`}],[`path`,{d:`M6 12a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-3`}],[`path`,{d:`M4 12l2 0`,key:`svg-4`}],[`path`,{d:`M10 12l10 0`,key:`svg-5`}],[`path`,{d:`M15 18a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-6`}],[`path`,{d:`M4 18l11 0`,key:`svg-7`}],[`path`,{d:`M19 18l1 0`,key:`svg-8`}]]),kA=DA(`outline`,`alert-circle`,`AlertCircle`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M12 8v4`,key:`svg-1`}],[`path`,{d:`M12 16h.01`,key:`svg-2`}]]),AA=DA(`outline`,`alert-triangle`,`AlertTriangle`,[[`path`,{d:`M12 9v4`,key:`svg-0`}],[`path`,{d:`M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0`,key:`svg-1`}],[`path`,{d:`M12 16h.01`,key:`svg-2`}]]),jA=DA(`outline`,`arrow-down`,`ArrowDown`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M18 13l-6 6`,key:`svg-1`}],[`path`,{d:`M6 13l6 6`,key:`svg-2`}]]),MA=DA(`outline`,`arrow-up`,`ArrowUp`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M18 11l-6 -6`,key:`svg-1`}],[`path`,{d:`M6 11l6 -6`,key:`svg-2`}]]),NA=DA(`outline`,`bleach-off`,`BleachOff`,[[`path`,{d:`M5 19h14m1.986 -1.977a2 2 0 0 0 -.146 -.773l-7.1 -12.25a2 2 0 0 0 -3.5 0l-.815 1.405m-1.488 2.568l-4.797 8.277a2 2 0 0 0 1.75 2.75`,key:`svg-0`}],[`path`,{d:`M3 3l18 18`,key:`svg-1`}]]),PA=DA(`outline`,`bleach`,`Bleach`,[[`path`,{d:`M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75`,key:`svg-0`}]]),FA=DA(`outline`,`bookmark`,`Bookmark`,[[`path`,{d:`M18 7v14l-6 -4l-6 4v-14a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4`,key:`svg-0`}]]),IA=DA(`outline`,`box-multiple`,`BoxMultiple`,[[`path`,{d:`M7 5a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2l0 -10`,key:`svg-0`}],[`path`,{d:`M17 17v2a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2`,key:`svg-1`}]]),LA=DA(`outline`,`brackets-contain`,`BracketsContain`,[[`path`,{d:`M7 4h-4v16h4`,key:`svg-0`}],[`path`,{d:`M17 4h4v16h-4`,key:`svg-1`}],[`path`,{d:`M8 16h.01`,key:`svg-2`}],[`path`,{d:`M12 16h.01`,key:`svg-3`}],[`path`,{d:`M16 16h.01`,key:`svg-4`}]]),RA=DA(`outline`,`brand-asana`,`BrandAsana`,[[`path`,{d:`M9 7a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-0`}],[`path`,{d:`M14 16a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-1`}],[`path`,{d:`M4 16a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-2`}]]),zA=DA(`outline`,`briefcase`,`Briefcase`,[[`path`,{d:`M3 9a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -9`,key:`svg-0`}],[`path`,{d:`M8 7v-2a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v2`,key:`svg-1`}],[`path`,{d:`M12 12l0 .01`,key:`svg-2`}],[`path`,{d:`M3 13a20 20 0 0 0 18 0`,key:`svg-3`}]]),BA=DA(`outline`,`bucket-off`,`BucketOff`,[[`path`,{d:`M5.029 5.036c-.655 .58 -1.029 1.25 -1.029 1.964c0 2.033 3.033 3.712 6.96 3.967m3.788 -.21c3.064 -.559 5.252 -2.029 5.252 -3.757c0 -2.21 -3.582 -4 -8 -4c-1.605 0 -3.1 .236 -4.352 .643`,key:`svg-0`}],[`path`,{d:`M4 7c0 .664 .088 1.324 .263 1.965l2.737 10.035c.5 1.5 2.239 2 5 2s4.5 -.5 5 -2c.1 -.3 .252 -.812 .457 -1.535m.862 -3.146c.262 -.975 .735 -2.76 1.418 -5.354a7.45 7.45 0 0 0 .263 -1.965`,key:`svg-1`}],[`path`,{d:`M3 3l18 18`,key:`svg-2`}]]),VA=DA(`outline`,`bucket`,`Bucket`,[[`path`,{d:`M4 7a8 4 0 1 0 16 0a8 4 0 1 0 -16 0`,key:`svg-0`}],[`path`,{d:`M4 7c0 .664 .088 1.324 .263 1.965l2.737 10.035c.5 1.5 2.239 2 5 2s4.5 -.5 5 -2c.333 -1 1.246 -4.345 2.737 -10.035a7.45 7.45 0 0 0 .263 -1.965`,key:`svg-1`}]]),HA=DA(`outline`,`building`,`Building`,[[`path`,{d:`M3 21l18 0`,key:`svg-0`}],[`path`,{d:`M9 8l1 0`,key:`svg-1`}],[`path`,{d:`M9 12l1 0`,key:`svg-2`}],[`path`,{d:`M9 16l1 0`,key:`svg-3`}],[`path`,{d:`M14 8l1 0`,key:`svg-4`}],[`path`,{d:`M14 12l1 0`,key:`svg-5`}],[`path`,{d:`M14 16l1 0`,key:`svg-6`}],[`path`,{d:`M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16`,key:`svg-7`}]]),UA=DA(`outline`,`calendar`,`Calendar`,[[`path`,{d:`M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12`,key:`svg-0`}],[`path`,{d:`M16 3v4`,key:`svg-1`}],[`path`,{d:`M8 3v4`,key:`svg-2`}],[`path`,{d:`M4 11h16`,key:`svg-3`}],[`path`,{d:`M11 15h1`,key:`svg-4`}],[`path`,{d:`M12 15v3`,key:`svg-5`}]]),WA=DA(`outline`,`check`,`Check`,[[`path`,{d:`M5 12l5 5l10 -10`,key:`svg-0`}]]),GA=DA(`outline`,`checkbox`,`Checkbox`,[[`path`,{d:`M9 11l3 3l8 -8`,key:`svg-0`}],[`path`,{d:`M20 12v6a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h9`,key:`svg-1`}]]),KA=DA(`outline`,`chevron-down`,`ChevronDown`,[[`path`,{d:`M6 9l6 6l6 -6`,key:`svg-0`}]]),qA=DA(`outline`,`circle-check`,`CircleCheck`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12l2 2l4 -4`,key:`svg-1`}]]),JA=DA(`outline`,`circle-minus`,`CircleMinus`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12l6 0`,key:`svg-1`}]]),YA=DA(`outline`,`circle-plus`,`CirclePlus`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M9 12h6`,key:`svg-1`}],[`path`,{d:`M12 9v6`,key:`svg-2`}]]),XA=DA(`outline`,`cloud-upload`,`CloudUpload`,[[`path`,{d:`M7 18a4.6 4.4 0 0 1 0 -9a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-1`,key:`svg-0`}],[`path`,{d:`M9 15l3 -3l3 3`,key:`svg-1`}],[`path`,{d:`M12 12l0 9`,key:`svg-2`}]]),ZA=DA(`outline`,`columns`,`Columns`,[[`path`,{d:`M4 6l5.5 0`,key:`svg-0`}],[`path`,{d:`M4 10l5.5 0`,key:`svg-1`}],[`path`,{d:`M4 14l5.5 0`,key:`svg-2`}],[`path`,{d:`M4 18l5.5 0`,key:`svg-3`}],[`path`,{d:`M14.5 6l5.5 0`,key:`svg-4`}],[`path`,{d:`M14.5 10l5.5 0`,key:`svg-5`}],[`path`,{d:`M14.5 14l5.5 0`,key:`svg-6`}],[`path`,{d:`M14.5 18l5.5 0`,key:`svg-7`}]]),QA=DA(`outline`,`copy`,`Copy`,[[`path`,{d:`M7 9.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667l0 -8.666`,key:`svg-0`}],[`path`,{d:`M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1`,key:`svg-1`}]]),$A=DA(`outline`,`currency-dollar`,`CurrencyDollar`,[[`path`,{d:`M16.7 8a3 3 0 0 0 -2.7 -2h-4a3 3 0 0 0 0 6h4a3 3 0 0 1 0 6h-4a3 3 0 0 1 -2.7 -2`,key:`svg-0`}],[`path`,{d:`M12 3v3m0 12v3`,key:`svg-1`}]]),ej=DA(`outline`,`database`,`Database`,[[`path`,{d:`M4 6a8 3 0 1 0 16 0a8 3 0 1 0 -16 0`,key:`svg-0`}],[`path`,{d:`M4 6v6a8 3 0 0 0 16 0v-6`,key:`svg-1`}],[`path`,{d:`M4 12v6a8 3 0 0 0 16 0v-6`,key:`svg-2`}]]),tj=DA(`outline`,`device-desktop`,`DeviceDesktop`,[[`path`,{d:`M3 5a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v10a1 1 0 0 1 -1 1h-16a1 1 0 0 1 -1 -1v-10`,key:`svg-0`}],[`path`,{d:`M7 20h10`,key:`svg-1`}],[`path`,{d:`M9 16v4`,key:`svg-2`}],[`path`,{d:`M15 16v4`,key:`svg-3`}]]),nj=DA(`outline`,`device-floppy`,`DeviceFloppy`,[[`path`,{d:`M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2`,key:`svg-0`}],[`path`,{d:`M10 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-1`}],[`path`,{d:`M14 4l0 4l-6 0l0 -4`,key:`svg-2`}]]),rj=DA(`outline`,`dots`,`Dots`,[[`path`,{d:`M4 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-0`}],[`path`,{d:`M11 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-1`}],[`path`,{d:`M18 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-2`}]]),ij=DA(`outline`,`edit`,`Edit`,[[`path`,{d:`M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1`,key:`svg-0`}],[`path`,{d:`M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415`,key:`svg-1`}],[`path`,{d:`M16 5l3 3`,key:`svg-2`}]]),aj=DA(`outline`,`equal-not`,`EqualNot`,[[`path`,{d:`M5 10h14`,key:`svg-0`}],[`path`,{d:`M5 14h14`,key:`svg-1`}],[`path`,{d:`M5 19l14 -14`,key:`svg-2`}]]),oj=DA(`outline`,`equal`,`Equal`,[[`path`,{d:`M5 10h14`,key:`svg-0`}],[`path`,{d:`M5 14h14`,key:`svg-1`}]]),sj=DA(`outline`,`eye-off`,`EyeOff`,[[`path`,{d:`M10.585 10.587a2 2 0 0 0 2.829 2.828`,key:`svg-0`}],[`path`,{d:`M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87`,key:`svg-1`}],[`path`,{d:`M3 3l18 18`,key:`svg-2`}]]),cj=DA(`outline`,`eye`,`Eye`,[[`path`,{d:`M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0`,key:`svg-0`}],[`path`,{d:`M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6`,key:`svg-1`}]]),lj=DA(`outline`,`file-alert`,`FileAlert`,[[`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`,key:`svg-0`}],[`path`,{d:`M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2`,key:`svg-1`}],[`path`,{d:`M12 17l.01 0`,key:`svg-2`}],[`path`,{d:`M12 11l0 3`,key:`svg-3`}]]),uj=DA(`outline`,`file-plus`,`FilePlus`,[[`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`,key:`svg-0`}],[`path`,{d:`M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2`,key:`svg-1`}],[`path`,{d:`M12 11l0 6`,key:`svg-2`}],[`path`,{d:`M9 14l6 0`,key:`svg-3`}]]),dj=DA(`outline`,`filter`,`Filter`,[[`path`,{d:`M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227`,key:`svg-0`}]]),fj=DA(`outline`,`folder`,`Folder`,[[`path`,{d:`M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2`,key:`svg-0`}]]),pj=DA(`outline`,`forms`,`Forms`,[[`path`,{d:`M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3`,key:`svg-0`}],[`path`,{d:`M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3`,key:`svg-1`}],[`path`,{d:`M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7`,key:`svg-2`}],[`path`,{d:`M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1`,key:`svg-3`}],[`path`,{d:`M17 12h.01`,key:`svg-4`}],[`path`,{d:`M13 12h.01`,key:`svg-5`}]]),mj=DA(`outline`,`id`,`Id`,[[`path`,{d:`M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10`,key:`svg-0`}],[`path`,{d:`M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0`,key:`svg-1`}],[`path`,{d:`M15 8l2 0`,key:`svg-2`}],[`path`,{d:`M15 12l2 0`,key:`svg-3`}],[`path`,{d:`M7 16l10 0`,key:`svg-4`}]]),hj=DA(`outline`,`layout-sidebar`,`LayoutSidebar`,[[`path`,{d:`M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12`,key:`svg-0`}],[`path`,{d:`M9 4l0 16`,key:`svg-1`}]]),gj=DA(`outline`,`list-details`,`ListDetails`,[[`path`,{d:`M13 5h8`,key:`svg-0`}],[`path`,{d:`M13 9h5`,key:`svg-1`}],[`path`,{d:`M13 15h8`,key:`svg-2`}],[`path`,{d:`M13 19h5`,key:`svg-3`}],[`path`,{d:`M3 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-4`}],[`path`,{d:`M3 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-5`}]]),_j=DA(`outline`,`lock-access`,`LockAccess`,[[`path`,{d:`M4 8v-2a2 2 0 0 1 2 -2h2`,key:`svg-0`}],[`path`,{d:`M4 16v2a2 2 0 0 0 2 2h2`,key:`svg-1`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v2`,key:`svg-2`}],[`path`,{d:`M16 20h2a2 2 0 0 0 2 -2v-2`,key:`svg-3`}],[`path`,{d:`M8 12a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1v3a1 1 0 0 1 -1 1h-6a1 1 0 0 1 -1 -1l0 -3`,key:`svg-4`}],[`path`,{d:`M10 11v-2a2 2 0 1 1 4 0v2`,key:`svg-5`}]]),vj=DA(`outline`,`lock`,`Lock`,[[`path`,{d:`M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6`,key:`svg-0`}],[`path`,{d:`M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0`,key:`svg-1`}],[`path`,{d:`M8 11v-4a4 4 0 1 1 8 0v4`,key:`svg-2`}]]),yj=DA(`outline`,`logout`,`Logout`,[[`path`,{d:`M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2`,key:`svg-0`}],[`path`,{d:`M9 12h12l-3 -3`,key:`svg-1`}],[`path`,{d:`M18 15l3 -3`,key:`svg-2`}]]),bj=DA(`outline`,`math-greater`,`MathGreater`,[[`path`,{d:`M5 18l14 -6l-14 -6`,key:`svg-0`}]]),xj=DA(`outline`,`math-lower`,`MathLower`,[[`path`,{d:`M19 18l-14 -6l14 -6`,key:`svg-0`}]]),Sj=DA(`outline`,`message`,`Message`,[[`path`,{d:`M8 9h8`,key:`svg-0`}],[`path`,{d:`M8 13h6`,key:`svg-1`}],[`path`,{d:`M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12`,key:`svg-2`}]]),Cj=DA(`outline`,`microscope`,`Microscope`,[[`path`,{d:`M5 21h14`,key:`svg-0`}],[`path`,{d:`M6 18h2`,key:`svg-1`}],[`path`,{d:`M7 18v3`,key:`svg-2`}],[`path`,{d:`M9 11l3 3l6 -6l-3 -3l-6 6`,key:`svg-3`}],[`path`,{d:`M10.5 12.5l-1.5 1.5`,key:`svg-4`}],[`path`,{d:`M17 3l3 3`,key:`svg-5`}],[`path`,{d:`M12 21a6 6 0 0 0 3.715 -10.712`,key:`svg-6`}]]),wj=DA(`outline`,`minus`,`Minus`,[[`path`,{d:`M5 12l14 0`,key:`svg-0`}]]),Tj=DA(`outline`,`moon`,`Moon`,[[`path`,{d:`M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454l0 .008`,key:`svg-0`}]]),Ej=DA(`outline`,`packages`,`Packages`,[[`path`,{d:`M7 16.5l-5 -3l5 -3l5 3v5.5l-5 3l0 -5.5`,key:`svg-0`}],[`path`,{d:`M2 13.5v5.5l5 3`,key:`svg-1`}],[`path`,{d:`M7 16.545l5 -3.03`,key:`svg-2`}],[`path`,{d:`M17 16.5l-5 -3l5 -3l5 3v5.5l-5 3l0 -5.5`,key:`svg-3`}],[`path`,{d:`M12 19l5 3`,key:`svg-4`}],[`path`,{d:`M17 16.5l5 -3`,key:`svg-5`}],[`path`,{d:`M12 13.5v-5.5l-5 -3l5 -3l5 3v5.5`,key:`svg-6`}],[`path`,{d:`M7 5.03v5.455`,key:`svg-7`}],[`path`,{d:`M12 8l5 -3`,key:`svg-8`}]]),Dj=DA(`outline`,`palette`,`Palette`,[[`path`,{d:`M12 21a9 9 0 0 1 0 -18c4.97 0 9 3.582 9 8c0 1.06 -.474 2.078 -1.318 2.828c-.844 .75 -1.989 1.172 -3.182 1.172h-2.5a2 2 0 0 0 -1 3.75a1.3 1.3 0 0 1 -1 2.25`,key:`svg-0`}],[`path`,{d:`M7.5 10.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-1`}],[`path`,{d:`M11.5 7.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-2`}],[`path`,{d:`M15.5 10.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`,key:`svg-3`}]]),Oj=DA(`outline`,`pencil`,`Pencil`,[[`path`,{d:`M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4`,key:`svg-0`}],[`path`,{d:`M13.5 6.5l4 4`,key:`svg-1`}]]),kj=DA(`outline`,`pin`,`Pin`,[[`path`,{d:`M15 4.5l-4 4l-4 1.5l-1.5 1.5l7 7l1.5 -1.5l1.5 -4l4 -4`,key:`svg-0`}],[`path`,{d:`M9 15l-4.5 4.5`,key:`svg-1`}],[`path`,{d:`M14.5 4l5.5 5.5`,key:`svg-2`}]]),Aj=DA(`outline`,`pinned-off`,`PinnedOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M15 4.5l-3.249 3.249m-2.57 1.433l-2.181 .818l-1.5 1.5l7 7l1.5 -1.5l.82 -2.186m1.43 -2.563l3.25 -3.251`,key:`svg-1`}],[`path`,{d:`M9 15l-4.5 4.5`,key:`svg-2`}],[`path`,{d:`M14.5 4l5.5 5.5`,key:`svg-3`}]]),jj=DA(`outline`,`player-play`,`PlayerPlay`,[[`path`,{d:`M7 4v16l13 -8l-13 -8`,key:`svg-0`}]]),Mj=DA(`outline`,`plus`,`Plus`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M5 12l14 0`,key:`svg-1`}]]),Nj=DA(`outline`,`receipt`,`Receipt`,[[`path`,{d:`M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2m4 -14h6m-6 4h6m-2 4h2`,key:`svg-0`}]]),Pj=DA(`outline`,`refresh`,`Refresh`,[[`path`,{d:`M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4`,key:`svg-0`}],[`path`,{d:`M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4`,key:`svg-1`}]]),Fj=DA(`outline`,`repeat`,`Repeat`,[[`path`,{d:`M4 12v-3a3 3 0 0 1 3 -3h13m-3 -3l3 3l-3 3`,key:`svg-0`}],[`path`,{d:`M20 12v3a3 3 0 0 1 -3 3h-13m3 3l-3 -3l3 -3`,key:`svg-1`}]]),Ij=DA(`outline`,`report-medical`,`ReportMedical`,[[`path`,{d:`M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2`,key:`svg-0`}],[`path`,{d:`M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2`,key:`svg-1`}],[`path`,{d:`M10 14l4 0`,key:`svg-2`}],[`path`,{d:`M12 12l0 4`,key:`svg-3`}]]),Lj=DA(`outline`,`router`,`Router`,[[`path`,{d:`M3 15a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2l0 -4`,key:`svg-0`}],[`path`,{d:`M17 17l0 .01`,key:`svg-1`}],[`path`,{d:`M13 17l0 .01`,key:`svg-2`}],[`path`,{d:`M15 13l0 -2`,key:`svg-3`}],[`path`,{d:`M11.75 8.75a4 4 0 0 1 6.5 0`,key:`svg-4`}],[`path`,{d:`M8.5 6.5a8 8 0 0 1 13 0`,key:`svg-5`}]]),Rj=DA(`outline`,`search`,`Search`,[[`path`,{d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0`,key:`svg-0`}],[`path`,{d:`M21 21l-6 -6`,key:`svg-1`}]]),zj=DA(`outline`,`settings`,`Settings`,[[`path`,{d:`M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065`,key:`svg-0`}],[`path`,{d:`M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0`,key:`svg-1`}]]),Bj=DA(`outline`,`sort-ascending`,`SortAscending`,[[`path`,{d:`M4 6l7 0`,key:`svg-0`}],[`path`,{d:`M4 12l7 0`,key:`svg-1`}],[`path`,{d:`M4 18l9 0`,key:`svg-2`}],[`path`,{d:`M15 9l3 -3l3 3`,key:`svg-3`}],[`path`,{d:`M18 6l0 12`,key:`svg-4`}]]),Vj=DA(`outline`,`sort-descending`,`SortDescending`,[[`path`,{d:`M4 6l9 0`,key:`svg-0`}],[`path`,{d:`M4 12l7 0`,key:`svg-1`}],[`path`,{d:`M4 18l7 0`,key:`svg-2`}],[`path`,{d:`M15 15l3 3l3 -3`,key:`svg-3`}],[`path`,{d:`M18 6l0 12`,key:`svg-4`}]]),Hj=DA(`outline`,`square`,`Square`,[[`path`,{d:`M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14`,key:`svg-0`}]]),Uj=DA(`outline`,`star`,`Star`,[[`path`,{d:`M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873l-6.158 -3.245`,key:`svg-0`}]]),Wj=DA(`outline`,`sun-high`,`SunHigh`,[[`path`,{d:`M14.828 14.828a4 4 0 1 0 -5.656 -5.656a4 4 0 0 0 5.656 5.656`,key:`svg-0`}],[`path`,{d:`M6.343 17.657l-1.414 1.414`,key:`svg-1`}],[`path`,{d:`M6.343 6.343l-1.414 -1.414`,key:`svg-2`}],[`path`,{d:`M17.657 6.343l1.414 -1.414`,key:`svg-3`}],[`path`,{d:`M17.657 17.657l1.414 1.414`,key:`svg-4`}],[`path`,{d:`M4 12h-2`,key:`svg-5`}],[`path`,{d:`M12 4v-2`,key:`svg-6`}],[`path`,{d:`M20 12h2`,key:`svg-7`}],[`path`,{d:`M12 20v2`,key:`svg-8`}]]),Gj=DA(`outline`,`switch-horizontal`,`SwitchHorizontal`,[[`path`,{d:`M16 3l4 4l-4 4`,key:`svg-0`}],[`path`,{d:`M10 7l10 0`,key:`svg-1`}],[`path`,{d:`M8 13l-4 4l4 4`,key:`svg-2`}],[`path`,{d:`M4 17l9 0`,key:`svg-3`}]]),Kj=DA(`outline`,`table-export`,`TableExport`,[[`path`,{d:`M12.5 21h-7.5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v7.5`,key:`svg-0`}],[`path`,{d:`M3 10h18`,key:`svg-1`}],[`path`,{d:`M10 3v18`,key:`svg-2`}],[`path`,{d:`M16 19h6`,key:`svg-3`}],[`path`,{d:`M19 16l3 3l-3 3`,key:`svg-4`}]]),qj=DA(`outline`,`table`,`Table`,[[`path`,{d:`M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14`,key:`svg-0`}],[`path`,{d:`M3 10h18`,key:`svg-1`}],[`path`,{d:`M10 3v18`,key:`svg-2`}]]),Jj=DA(`outline`,`text-recognition`,`TextRecognition`,[[`path`,{d:`M4 8v-2a2 2 0 0 1 2 -2h2`,key:`svg-0`}],[`path`,{d:`M4 16v2a2 2 0 0 0 2 2h2`,key:`svg-1`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v2`,key:`svg-2`}],[`path`,{d:`M16 20h2a2 2 0 0 0 2 -2v-2`,key:`svg-3`}],[`path`,{d:`M12 16v-7`,key:`svg-4`}],[`path`,{d:`M9 9h6`,key:`svg-5`}]]),Yj=DA(`outline`,`trash`,`Trash`,[[`path`,{d:`M4 7l16 0`,key:`svg-0`}],[`path`,{d:`M10 11l0 6`,key:`svg-1`}],[`path`,{d:`M14 11l0 6`,key:`svg-2`}],[`path`,{d:`M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12`,key:`svg-3`}],[`path`,{d:`M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3`,key:`svg-4`}]]),Xj=DA(`outline`,`upload`,`Upload`,[[`path`,{d:`M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2`,key:`svg-0`}],[`path`,{d:`M7 9l5 -5l5 5`,key:`svg-1`}],[`path`,{d:`M12 4l0 12`,key:`svg-2`}]]),Zj=DA(`outline`,`user-plus`,`UserPlus`,[[`path`,{d:`M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0`,key:`svg-0`}],[`path`,{d:`M16 19h6`,key:`svg-1`}],[`path`,{d:`M19 16v6`,key:`svg-2`}],[`path`,{d:`M6 21v-2a4 4 0 0 1 4 -4h4`,key:`svg-3`}]]),Qj=DA(`outline`,`webhook`,`Webhook`,[[`path`,{d:`M4.876 13.61a4 4 0 1 0 6.124 3.39h6`,key:`svg-0`}],[`path`,{d:`M15.066 20.502a4 4 0 1 0 1.934 -7.502c-.706 0 -1.424 .179 -2 .5l-3 -5.5`,key:`svg-1`}],[`path`,{d:`M16 8a4 4 0 1 0 -8 0c0 1.506 .77 2.818 2 3.5l-3 5.5`,key:`svg-2`}]]),$j=DA(`outline`,`x`,`X`,[[`path`,{d:`M18 6l-12 12`,key:`svg-0`}],[`path`,{d:`M6 6l12 12`,key:`svg-1`}]]),eM=DA(`filled`,`circle-filled`,`CircleFilled`,[[`path`,{d:`M7 3.34a10 10 0 1 1 -4.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 4.995 -8.336z`,key:`svg-0`}]]),tM=class extends b.Component{state;constructor(e){super(e),this.state={lastLocation:LE.getLocation()}}static getDerivedStateFromError(e){return{error:e,lastLocation:LE.getLocation()}}componentDidUpdate(e,t){LE.getLocation()!==this.state.lastLocation&&this.setState({lastLocation:LE.getLocation(),error:void 0})}shouldComponentUpdate(e,t){return!!(this.props.children!==e.children||t.error&&!this.state.error||this.state.lastLocation!==LE.getLocation())}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.error?(0,I.jsx)(ou,{icon:(0,I.jsx)(kA,{size:16}),title:`Something went wrong`,color:`red`,children:Y(this.state.error)}):this.props.children}};function nM(){return(0,I.jsx)(hd,{style:{width:`100%`,height:`100vh`},children:(0,I.jsx)(il,{})})}var rM={main:`_main_6s8vf_1`,announcement:`_announcement_6s8vf_7`};function iM(e){return(0,I.jsx)(I.Fragment,{children:e.announcements.map((t,n)=>(0,I.jsx)(z,{className:rM.announcement,style:{backgroundColor:`var(--mantine-color-${t.color??`yellow`}-light)`,color:`var(--mantine-color-${t.color??`yellow`}-light-color)`},role:t.role??`status`,children:(0,I.jsxs)(V,{gap:`xs`,wrap:`nowrap`,h:`100%`,px:`md`,children:[t.icon,(0,I.jsx)(H,{size:`sm`,fw:500,truncate:!0,children:t.message}),t.dismissible&&(0,I.jsx)(Cl,{size:`sm`,variant:`subtle`,"aria-label":`Dismiss announcement`,onClick:()=>e.onDismiss(t),ml:`auto`})]})},t.id??n))})}function aM(e){e.preventDefault(),e.stopPropagation()}function oM(e){return e.button===1||e.ctrlKey||e.metaKey}function sM(e){if(cM(e))return!0;if(e instanceof HTMLTableCellElement){let t=e.children;if(t.length===1&&cM(t[0]))return!0}return!1}function cM(e){return e instanceof HTMLInputElement&&e.type===`checkbox`}async function lM(e,t){return new Promise((n,r)=>{let i=new MessageChannel;i.port1.onmessage=({data:e})=>{i.port1.close(),e.error?r(e.error):n(e.result)},e.contentWindow?.postMessage(t,new URL(e.src).origin,[i.port2])})}function uM(e,t){let n=new Blob([e],{type:ZE.JSON}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t??new Date().toISOString().replaceAll(/\D/g,``)}.json`,document.body.appendChild(i),i.click(),URL.revokeObjectURL(r)}function dM(e){let t=uk(),{to:n,suffix:r,label:i,onClick:a,children:o,...s}=e,c=fM(n);return r&&(c+=`/`+r),(0,I.jsx)(pu,{href:c,"aria-label":i,onAuxClick:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),a?(e.preventDefault(),a(e)):n&&(oM(e)||(e.preventDefault(),t(c)))},...s,children:o})}function fM(e){if(e){if(typeof e==`string`)return pM(e);if(Vw(e))return mM(e);if(Hw(e))return hM(e)}return`#`}function pM(e){return e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`/`)?e:`/`+e}function mM(e){return`/${e.resourceType}/${e.id}`}function hM(e){return`/${e.reference}`}function gM(e){let t=e.split(` `).filter(Boolean);return t.length>1?t[0][0]+t.at(-1)?.at(0):t.length===1?t[0][0]:``}function _M(e){let t=bk(e.value),n=t?lC(t):e.alt??``,r=gM(n),i=gk((t&&fC(t))??e.src??void 0),a=e.radius??`xl`,o={...e,value:void 0,link:void 0};return e.link?(0,I.jsx)(dM,{to:t,children:(0,I.jsx)(Qu,{src:i,alt:n,radius:a,...o,children:r})}):(0,I.jsx)(Qu,{src:i,alt:n,radius:a,...o,children:r})}var vM={logoButton:`_logoButton_3ecx0_1`,user:`_user_3ecx0_11`,userInfo:`_userInfo_3ecx0_25`,userName:`_userName_3ecx0_35`,userProject:`_userProject_3ecx0_40`},yM={iconBox:`_iconBox_1mfdi_1`,interactive:`_interactive_1mfdi_12`};function bM(e){let{projectDisplay:t,profileDisplay:n,label:r,selected:i}=e,a=r?`${t} - ${r}`:t;return(0,I.jsxs)(V,{gap:`xs`,align:`center`,wrap:`nowrap`,style:{width:`100%`,minWidth:0},children:[(0,I.jsx)(z,{className:yM.iconBox,children:(0,I.jsx)(zA,{size:16,stroke:2})}),(0,I.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,I.jsx)(H,{size:`sm`,fw:500,truncate:!0,children:a}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,truncate:!0,children:n})]}),i&&(0,I.jsx)(WA,{size:16,stroke:2,color:`var(--mantine-color-blue-6)`})]})}function xM(e){let{membership:t,label:n}=e;return(0,I.jsx)(bM,{projectDisplay:t.project?.display,profileDisplay:t.profile?.display,label:n})}function SM(){return`Medplum`}var CM={divider:`_divider_3o3ui_1`,accountSection:`_accountSection_3o3ui_5`,projectOption:`_projectOption_3o3ui_9`,recentProjectItem:`_recentProjectItem_3o3ui_18`,dropdown:`_dropdown_3o3ui_22`,settingsRow:`_settingsRow_3o3ui_43`,settingsControlWrapper:`_settingsControlWrapper_3o3ui_50`,segmentedControl:`_segmentedControl_3o3ui_57`,appearanceControl:`_appearanceControl_3o3ui_76`,layoutControl:`_layoutControl_3o3ui_93`},wM=`var(--mantine-color-dimmed)`,TM=[{value:`light`,label:(0,I.jsx)(DM,{Icon:Wj,label:`Light`})},{value:`auto`,label:(0,I.jsx)(DM,{Icon:tj,label:`System`})},{value:`dark`,label:(0,I.jsx)(DM,{Icon:Tj,label:`Dark`})}],EM=[{label:`v1`,value:`v1`},{label:`v2`,value:`v2`}];function DM({Icon:e,label:t}){return(0,I.jsx)(`span`,{"aria-label":t,style:{display:`flex`},children:(0,I.jsx)(e,{size:16,color:wM,"aria-hidden":!0})})}function OM(){return(0,I.jsx)(bp,{my:4,mx:4,className:CM.divider})}function kM(e,t){return t?e.project.reference===t.project.reference&&e.profile.reference===t.profile.reference:!1}function AM(e){return`${e.project.reference}-${e.profile.reference}`}function jM(e){let{medplum:t,profile:n,navigate:r}=lk(),i=t.getActiveLogin(),a=t.getLogins().filter(e=>!kM(e,i)),o=t.getProject(),{colorScheme:s,setColorScheme:c}=Vr(),[l]=(0,b.useState)(()=>localStorage.appShellLayoutVersion??`v1`),u=e.showLayoutVersionToggle??!0,d=o?.name??t.getActiveLogin()?.project.display,f=i?.profile.display??(n?cw(n.name?.[0]):void 0);function p(e){t.setActiveLogin(e).then(()=>LE.reload()).catch(console.error)}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{className:CM.accountSection,children:(0,I.jsx)(z,{className:CM.projectOption,children:(0,I.jsx)(bM,{projectDisplay:d,profileDisplay:f,selected:!0})})}),a.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(OM,{}),a.map(e=>(0,I.jsx)(W.Item,{className:CM.recentProjectItem,onClick:()=>p(e),children:(0,I.jsx)(z,{className:CM.projectOption,children:(0,I.jsx)(bM,{projectDisplay:e.project.display,profileDisplay:e.profile.display})})},AM(e)))]}),(0,I.jsx)(OM,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Gj,{size:16,color:wM}),onClick:()=>r(`/signin`),children:(0,I.jsx)(H,{size:`sm`,children:`Switch to another project`})}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:16,color:wM}),onClick:()=>r(`/${aC(n)}`),children:(0,I.jsx)(H,{size:`sm`,children:`Account settings`})}),(0,I.jsxs)(ru,{className:CM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(ru,{align:`center`,gap:`xs`,children:[(0,I.jsx)(Dj,{size:16,color:wM}),(0,I.jsx)(H,{size:`sm`,children:`Appearance`})]}),(0,I.jsx)(z,{className:CM.settingsControlWrapper,children:(0,I.jsx)(ly,{classNames:{root:it(CM.segmentedControl,CM.appearanceControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:s,onChange:e=>c(e),data:TM,"aria-label":`Color scheme`})})]}),u&&(0,I.jsxs)(ru,{className:CM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(ru,{align:`center`,gap:`xs`,children:[(0,I.jsx)(qj,{size:16,color:wM}),(0,I.jsx)(H,{size:`sm`,children:`Layout`})]}),(0,I.jsx)(z,{className:CM.settingsControlWrapper,children:(0,I.jsx)(ly,{classNames:{root:it(CM.segmentedControl,CM.layoutControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:l,onChange:e=>{localStorage.appShellLayoutVersion=e,LE.reload()},data:EM,"aria-label":`App shell layout version`})})]}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(yj,{size:16,color:wM}),onClick:async()=>{await t.signOut(),r(`/signin`)},children:(0,I.jsx)(H,{size:`sm`,children:`Sign out`})}),(0,I.jsx)(OM,{}),(0,I.jsxs)(H,{size:`xs`,c:`dimmed`,fw:500,my:`sm`,ta:`center`,children:[SM(),` `,e.version]})]})}var MM={selectedItems:`selected-items`,options:`options`};function NM(e){let t=cp({onDropdownClose:()=>t.resetSelectedOption(),onDropdownOpen:()=>t.updateSelectedOptionIndex(`active`)}),{name:n,label:r,description:i,error:a,defaultValue:o,toOption:s,loadOptions:c,itemComponent:l,pillComponent:u,emptyComponent:d,onChange:f,onCreate:p,creatable:m,clearable:h,required:g,placeholder:_,leftSection:v,maxValues:y,optionsDropdownMaxHeight:x=320,minInputLength:S=0,...C}=e,w=C.disabled,T=PM(o),[E,D]=(0,b.useState)(``),[O,k]=(0,b.useState)(),[A,j]=(0,b.useState)(),[M,ee]=(0,b.useState)(),[N,P]=(0,b.useState)(T.map(s)),[te,ne]=(0,b.useState)([]),re=l??FM,ie=u??IM,ae=d??LM,oe=(0,b.useRef)(E),se=(0,b.useRef)(void 0),ce=(0,b.useRef)(void 0),le=(0,b.useRef)(O),ue=(0,b.useRef)(A),de=(0,b.useRef)(M);(0,b.useLayoutEffect)(()=>{oe.current=E,le.current=O,ue.current=A,de.current=M});let fe=(0,b.useCallback)(()=>{if(k(void 0),oe.current===ce.current&&c===se.current||(oe.current?.length??0)<S)return;ce.current=oe.current,se.current=c;let e=new AbortController;j(e),c(oe.current??``,e.signal).then(n=>{e.signal.aborted||(ne(n.map(s)),de.current?(n.length>0&&f(n.slice(0,1)),ee(!1)):n.length>0&&t.openDropdown())}).catch(t=>{e.signal.aborted||t.message.includes(`aborted`)||J({color:`red`,message:Y(t)})}).finally(()=>{e.signal.aborted||j(void 0)})},[t,c,f,s,S]),pe=(0,b.useCallback)(e=>{(te&&te.length>0||m)&&t.openDropdown(),t.updateSelectedOptionIndex(),D(e.currentTarget.value),ue.current&&(ue.current.abort(),j(void 0)),le.current!==void 0&&window.clearTimeout(le.current),k(window.setTimeout(()=>fe(),100))},[t,te,m,fe]),me=(0,b.useCallback)(e=>{let t=N.some(t=>t.value===e),n=t?N.filter(t=>t.value!==e):[...N],r=te?.find(t=>t.value===e);if(!r&&m!==!1&&p&&(r=s(p(e))),r){if(y===0){f([r.resource]),N.length>0&&P([]);return}t||n.push(r)}if(y!==void 0)for(;n.length>y;)n.shift();f(n.map(e=>e.resource)),P(n)},[m,te,N,y,f,p,s]),he=(0,b.useMemo)(()=>{if(!w)return e=>{w||(y===1&&(D(``),ne([]),t.closeDropdown()),ce.current=void 0,e===`$create`?(D(``),me(E)):me(e))}},[me,t,w,y,E]),ge=(0,b.useCallback)(e=>{let t=N.filter(t=>t.value!==e.value);f(t.map(e=>e.resource)),P(t)},[N,f]),_e=(0,b.useCallback)(e=>{e.key===`Enter`?(O||A)&&ee(!0):e.key===`Backspace`&&E.length===0&&(aM(e),ge(N[N.length-1]))},[A,ge,E.length,N,O]);(0,b.useEffect)(()=>()=>{ue.current&&ue.current.abort()},[]);let ve=!w&&h&&N.length>0&&(0,I.jsx)(dp.ClearButton,{title:`Clear all`,size:`sm`,onClear:()=>{D(``),P([]),f([]),t.closeDropdown()}}),ye=m&&E.trim().length>0,be=te.length>0||ye;return(0,I.jsxs)(dp,{store:t,onOptionSubmit:he,withinPortal:!0,shadow:`xl`,...C,children:[(0,I.jsx)(dp.DropdownTarget,{children:(0,I.jsx)(dg,{label:r,description:i,error:a,className:e.className,leftSection:v,rightSection:A?(0,I.jsx)(il,{size:16}):ve,required:g,disabled:w,children:(0,I.jsxs)(og.Group,{"data-testid":MM.selectedItems,children:[N.map(e=>(0,I.jsx)(ie,{item:e,disabled:w,onRemove:()=>ge(e)},e.value)),!w&&(y===void 0||y===0||N.length<y)&&(0,I.jsx)(dp.EventsTarget,{children:(0,I.jsx)(dg.Field,{role:`searchbox`,name:n,value:E,placeholder:_,onFocus:pe,onBlur:()=>{t.closeDropdown(),D(``)},onKeyDown:_e,onChange:pe})})]})})}),(0,I.jsx)(dp.Dropdown,{hidden:!be,"data-testid":MM.options,children:(0,I.jsx)(dp.Options,{children:(0,I.jsxs)(Uc,{type:`scroll`,mah:x,children:[te.map(e=>{let t=N.some(t=>t.value===e.value);return(0,I.jsx)(dp.Option,{value:e.value,active:t,children:(0,I.jsx)(re,{...e,active:t})},e.value)}),ye&&(0,I.jsxs)(dp.Option,{value:`$create`,children:[`+ Create `,E]}),!m&&E.trim().length>0&&te.length===0&&(0,I.jsx)(ae,{search:E})]})})})]})}function PM(e){return e?Array.isArray(e)?e:[e]:[]}function FM(e){return(0,I.jsxs)(V,{gap:`xs`,children:[e.active&&(0,I.jsx)(WA,{size:12}),(0,I.jsx)(`span`,{children:e.label})]})}function IM({item:e,disabled:t,onRemove:n}){return(0,I.jsx)(og,{withRemoveButton:!t,onRemove:n,children:e.label})}function LM(){return(0,I.jsx)(dp.Empty,{children:`Nothing found`})}var RM={searchInput:`_searchInput_dick8_1`};function zM(e){return{value:e.id,label:lC(e),resource:e}}function BM(e){let t=uk(),n=Q(),r=(0,b.useCallback)(async(e,t)=>{let r=HM(e),i={signal:t};return UM(await n.graphql(r,void 0,void 0,i),e)},[n]),i=(0,b.useCallback)(e=>{e.length>0&&t(`/${aC(e[0])}`)},[t]);return(0,I.jsx)(NM,{size:`sm`,radius:`md`,className:RM.searchInput,leftSection:(0,I.jsx)(Rj,{size:16}),placeholder:`Search`,itemComponent:VM,toOption:zM,onChange:i,loadOptions:r,maxValues:0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var VM=(0,b.forwardRef)(({resource:e,active:t,...n},r)=>{let i;return e.resourceType===`Patient`?i=e.birthDate:e.resourceType===`ServiceRequest`&&(i=e.subject?.display),(0,I.jsx)(`div`,{ref:r,...n,children:(0,I.jsxs)(V,{wrap:`nowrap`,children:[(0,I.jsx)(_M,{value:e}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:lC(e)}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:i})]})]})})});function HM(e){let t=JSON.stringify(e);return MC(e)?`{
|
|
97
97
|
Patients1: PatientList(_id: ${t}, _count: 1) {
|
|
98
98
|
resourceType
|
|
99
99
|
id
|
|
@@ -156,7 +156,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function ar({color:e,theme:t,autoContrast:n}){ret
|
|
|
156
156
|
display
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
}`.replaceAll(/\s+/g,` `)}function UM(e,t){let n=[];return e.data.Patients1&&n.push(...e.data.Patients1),e.data.Patients2&&n.push(...e.data.Patients2),e.data.ServiceRequestList&&n.push(...e.data.ServiceRequestList),GM(WM(n),t).slice(0,5)}function WM(e){let t=new Set,n=[];for(let r of e)t.has(r.id)||(t.add(r.id),n.push(r));return n}function GM(e,t){return e.sort((e,n)=>KM(n,t)-KM(e,t))}function KM(e,t){let n=0;if(e.identifier)for(let r of e.identifier)n=Math.max(n,qM(r.value,t));if(e.resourceType===`Patient`&&e.name)for(let r of e.name)n=Math.max(n,qM(cw(r),t));return n}function qM(e,t){if(!e)return 0;let n=e.toLowerCase().indexOf(t.toLowerCase());return n<0?0:100-n}function JM(e){let t=dk(),[n,r]=(0,b.useState)(!1);return(0,I.jsxs)(zu.Header,{p:0,style:{zIndex:101},children:[(0,I.jsx)(z,{p:8,h:60,children:(0,I.jsxs)(V,{justify:`space-between`,children:[(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(qc,{className:vM.logoButton,"aria-expanded":e.navbarOpen,"aria-controls":`navbar`,onClick:()=>e.navbarToggle(),children:e.logo}),!e.headerSearchDisabled&&(0,I.jsx)(BM,{pathname:e.pathname,searchParams:e.searchParams})]}),(0,I.jsxs)(V,{gap:`lg`,pr:`sm`,children:[e.notifications,(0,I.jsxs)(W,{width:260,shadow:`md`,radius:`md`,position:`bottom-end`,transitionProps:{transition:`fade-down`},opened:n,onClose:()=>r(!1),children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(qc,{className:vM.user,"aria-label":`User menu`,"data-active":n||void 0,onClick:()=>r(e=>!e),children:(0,I.jsxs)(V,{gap:7,children:[(0,I.jsx)(_M,{value:t,radius:`xl`,size:24}),(0,I.jsx)(H,{size:`sm`,className:vM.userName,children:cw(t?.name?.[0])}),(0,I.jsx)(KA,{size:12,stroke:1.5})]})})}),(0,I.jsx)(W.Dropdown,{className:CM.dropdown,children:(0,I.jsx)(jM,{version:e.version})})]})]})]})}),!!e.announcements?.length&&e.onDismissAnnouncement&&(0,I.jsx)(iM,{announcements:e.announcements,onDismiss:e.onDismissAnnouncement})]})}var YM=()=>kb({opened:!1,empty:!1,selected:-1,listId:``,query:``,registeredActions:new Set}),XM=e=>Ab(e);function ZM(e,t){let n=t.getState();t.setState({...n,...e(t.getState())})}function QM(e){ZM(()=>({opened:!0,selected:-1}),e)}function $M(e){ZM(()=>({opened:!1}),e)}function eN(e){ZM(e=>({opened:!e.opened,selected:e.opened?e.selected:-1}),e)}function tN(e,t){t.updateState(t=>({...t,selected:e}))}function nN(e,t){t.updateState(t=>({...t,listId:e}))}function rN(e,t=document){let n=t.querySelector(e);if(n)return n;let r=t instanceof ShadowRoot?t.host.children:t.children;for(let t=0;t<r.length;t+=1){let n=r[t];if(n.shadowRoot){let t=rN(e,n.shadowRoot);if(t)return t}let i=rN(e,n);if(i)return i}return null}function iN(e,t){let n=t.getState(),r=n.listId?rN(`#${n.listId}`):null,i=r?.querySelector(`[data-selected]`),a=r?.querySelectorAll(`[data-action]`)??[],o=lt(e===-1?a.length-1:e===a.length?0:e,0,a.length-1);return i?.removeAttribute(`data-selected`),a[o]?.scrollIntoView({block:`nearest`}),a[o]?.setAttribute(`data-selected`,`true`),tN(o,t),o}function aN(e){return iN(e.getState().selected+1,e)}function oN(e){return iN(e.getState().selected-1,e)}function sN(e){rN(`#${e.getState().listId} [data-selected]`)?.click()}function cN(e,t){let n=t.getState();return n.registeredActions.add(e),()=>{n.registeredActions.delete(e)}}function lN(e,t){ZM(()=>({query:e}),t),Promise.resolve().then(()=>{iN(0,t),ZM(e=>({empty:e.query.trim().length>0&&e.registeredActions.size===0||!1}),t)})}function uN({clearQuery:e},t){t.updateState(t=>({...t,selected:-1,query:e?``:t.query,empty:e?!1:t.empty}))}var dN={open:QM,close:$M,toggle:eN,updateState:ZM,setSelectedAction:tN,setListId:nN,selectAction:iN,selectNextAction:aN,selectPreviousAction:oN,triggerSelectedAction:sN,registerAction:cN,setQuery:lN,clearSpotlightState:uN};function fN(){let e=YM();return[e,{open:()=>QM(e),close:()=>$M(e),toggle:()=>eN(e)}]}var[pN,mN]=fN(),{open:hN,close:gN,toggle:_N}=mN;function vN(e){return Array.isArray(e)?e.map(e=>e.trim()).join(`,`).toLowerCase().trim():typeof e==`string`?e.toLowerCase().trim():``}function yN(e){return e.reduce((e,t)=>`actions`in t?[...e,...t.actions.map(e=>({...e,group:t.group}))]:[...e,t],[])}function bN(e){let t={},n=[];return e.forEach(e=>{e.group?(t[e.group]||(t[e.group]={pushed:!1,data:{group:e.group,actions:[]}}),t[e.group].data.actions.push(e),t[e.group].pushed||(t[e.group].pushed=!0,n.push(t[e.group].data))):n.push(e)}),n}var xN=(e,t)=>{let n=e.trim().toLowerCase(),r=[[],[]];return yN(t).forEach(e=>{e.label?.toLowerCase().includes(n)?r[0].push(e):(e.description?.toLowerCase().includes(n)||vN(e.keywords).includes(n))&&r[1].push(e)}),bN(r.flat())};function SN(e){let t=e;return t.group!==void 0&&Array.isArray(t.actions)}function CN(e,t){if(!Array.isArray(e))return[];let n=0;return e.reduce((e,r)=>{if(n>=t)return e;if(SN(r)){let i=CN(r.actions,t-n);e.push({group:r.group,actions:i}),n+=i.length}else e.push(r),n+=1;return e},[])}var wN={root:`m_d2b315db`,content:`m_3cd250e0`,body:`m_d2abce9b`,search:`m_f366a061`,actionsList:`m_6e463822`,action:`m_d49bb8ef`,actionBody:`m_3d475731`,actionSection:`m_832642f6`,actionLabel:`m_6c2a1345`,actionDescription:`m_a6d9d78d`,empty:`m_82f78f74`,footer:`m_ddcaf054`,actionsGroup:`m_5a3e5f7b`},[TN,EN]=Ke(`Spotlight component was not found in tree`),DN={dimmedSections:!0,highlightQuery:!1},ON=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,id:o,description:s,label:c,leftSection:l,rightSection:u,children:d,dimmedSections:f,highlightQuery:p,highlightColor:m,closeSpotlightOnTrigger:h,onClick:g,onMouseDown:_,keywords:v,vars:y,...b}=R(`SpotlightAction`,DN,e),x=EN(),S={classNames:i,styles:a},C=p&&typeof c==`string`?(0,I.jsx)(Up,{component:`span`,highlight:x.query,color:m,...x.getStyles(`actionLabel`,S),children:c}):(0,I.jsx)(`span`,{...x.getStyles(`actionLabel`,S),children:c});return(0,I.jsx)(qc,{ref:t,"data-action":!0,...x.getStyles(`action`,{className:n,style:r,...S}),...b,onMouseDown:e=>{e.preventDefault(),_?.(e)},onClick:e=>{g?.(e),(h??x.closeOnActionTrigger)&&dN.close(x.store)},tabIndex:-1,children:d||(0,I.jsxs)(I.Fragment,{children:[l&&(0,I.jsx)(z,{component:`span`,mod:{position:`left`,dimmed:f},...x.getStyles(`actionSection`,S),children:l}),(0,I.jsxs)(`span`,{...x.getStyles(`actionBody`,S),children:[C,(0,I.jsx)(`span`,{...x.getStyles(`actionDescription`,S),children:s})]}),u&&(0,I.jsx)(z,{component:`span`,mod:{position:`right`,dimmed:f},...x.getStyles(`actionSection`,S),children:u})]})})});ON.classes=wN,ON.displayName=`@mantine/spotlight/SpotlightAction`;var kN=B((e,t)=>{let{className:n,style:r,styles:i,classNames:a,label:o,children:s,...c}=R(`SpotlightActionsGroup`,null,e);return(0,I.jsx)(z,{...EN().getStyles(`actionsGroup`,{className:n,style:r,classNames:a,styles:i}),ref:t,...c,__vars:{"--spotlight-label":`'${o?.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`},children:s})});kN.classes=wN,kN.displayName=`@mantine/core/SpotlightActionsGroup`;var AN=B((e,t)=>{let{className:n,style:r,id:i,children:a,vars:o,classNames:s,styles:c,...l}=R(`SpotlightActionsList`,null,e),u=EN(),d=`mantine-${(0,b.useId)().replace(/:/g,``)}`,f=i||d;return(0,b.useEffect)(()=>(dN.setListId(f,u.store),()=>dN.setListId(``,u.store)),[]),(0,I.jsx)(Hc.Autosize,{...u.getStyles(`actionsList`,{className:n,style:r,classNames:s,styles:c}),ref:t,type:`scroll`,scrollbarSize:`var(--spotlight-actions-list-padding)`,offsetScrollbars:`y`,id:f,...l,children:a})});AN.classes=wN,AN.displayName=`@mantine/spotlight/SpotlightActionsList`;var jN=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,...o}=R(`SpotlightEmpty`,null,e);return(0,I.jsx)(z,{ref:t,...EN().getStyles(`empty`,{classNames:i,styles:a,className:n,style:r}),...o})});jN.classes=wN,jN.displayName=`@mantine/spotlight/SpotlightEmpty`;var MN=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,...o}=R(`SpotlightFooter`,null,e);return(0,I.jsx)(z,{ref:t,...EN().getStyles(`footer`,{className:n,classNames:i,style:r,styles:a}),...o})});MN.classes=wN,MN.displayName=`@mantine/spotlight/SpotlightFooter`;function NN(e,t){if(!e)return[];let n=()=>dN.open(t);return Array.isArray(e)?e.map(e=>[e,n]):[[e,n]]}var PN={size:600,yOffset:80,zIndex:Je(`max`),overlayProps:{backgroundOpacity:.35,blur:7},transitionProps:{duration:200,transition:`pop`},store:pN,clearQueryOnClose:!0,closeOnActionTrigger:!0,shortcut:`mod + K`,maxHeight:400},FN=B((e,t)=>{let n=R(`SpotlightRoot`,PN,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,store:l,children:u,query:d,onQueryChange:f,transitionProps:p,clearQueryOnClose:m,shortcut:h,tagsToIgnore:g,triggerOnContentEditable:_,disabled:v,onSpotlightOpen:y,onSpotlightClose:b,forceOpened:x,closeOnActionTrigger:S,maxHeight:C,scrollable:w,attributes:T,...E}=n,D=er(),{opened:O,query:k}=XM(l),A=typeof d==`string`?d:k,j=e=>{f?.(e),dN.setQuery(e,l)},M=L({name:`Spotlight`,classes:wN,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:T});return an(NN(h,l),g,_),xt(()=>{O?y?.():b?.()},[O]),v?null:(0,I.jsx)(TN,{value:{getStyles:M,query:A,setQuery:j,store:l,closeOnActionTrigger:S},children:(0,I.jsx)(Bh,{ref:t,...E,withCloseButton:!1,opened:O||!!x,padding:0,onClose:()=>dN.close(l),className:i,style:a,classNames:st({theme:D,classNames:[wN,r],props:n,stylesCtx:void 0}),styles:ct({theme:D,styles:o,props:n,stylesCtx:void 0}),transitionProps:{...p,onExited:()=>{m&&j(``),dN.clearSpotlightState({clearQuery:m},l),p?.onExited?.()}},__vars:{"--spotlight-max-height":w?F(C):void 0},__staticSelector:`Spotlight`,"data-scrollable":w||void 0,children:u})})});FN.classes=wN,FN.displayName=`@mantine/spotlight/SpotlightRoot`;var IN={size:`lg`},LN=B((e,t)=>{let{classNames:n,styles:r,onKeyDown:i,onChange:a,vars:o,value:s,...c}=R(`SpotlightSearch`,IN,e),l=EN(),u=l.getStyles(`search`),[d,f]=(0,b.useState)(!1),p=e=>{i?.(e),!d&&(e.nativeEvent.code===`ArrowDown`&&(e.preventDefault(),dN.selectNextAction(l.store)),e.nativeEvent.code===`ArrowUp`&&(e.preventDefault(),dN.selectPreviousAction(l.store)),(e.nativeEvent.code===`Enter`||e.nativeEvent.code===`NumpadEnter`)&&(e.preventDefault(),dN.triggerSelectedAction(l.store)))};return(0,I.jsx)(Zl,{ref:t,classNames:[{input:u.className},n],styles:[{input:u.style},r],...c,value:s??l.query,onChange:e=>{l.setQuery(e.currentTarget.value),a?.(e)},onKeyDown:p,onCompositionStart:()=>f(!0),onCompositionEnd:()=>f(!1)})});LN.classes=wN,LN.displayName=`@mantine/spotlight/SpotlightSearch`;var RN={size:600,yOffset:80,limit:1/0,zIndex:Je(`max`),overlayProps:{backgroundOpacity:.35,blur:7},transitionProps:{duration:200,transition:`pop`},store:pN,filter:xN,clearQueryOnClose:!0,closeOnActionTrigger:!0,shortcut:`mod + K`},zN=B((e,t)=>{let{searchProps:n,filter:r,query:i,onQueryChange:a,actions:o,nothingFound:s,highlightQuery:c,limit:l,scrollAreaProps:u,...d}=R(`Spotlight`,RN,e),[f,p]=Ht({value:i,defaultValue:``,finalValue:``,onChange:a}),m=CN(r(f,o),l).map(e=>{if(SN(e)){let t=e.actions.map(({id:e,...t})=>(0,I.jsx)(ON,{highlightQuery:c,...t},e));return(0,I.jsx)(kN,{label:e.group,children:t},e.group)}return(0,I.jsx)(ON,{highlightQuery:c,...e},e.id)});return(0,I.jsxs)(FN,{...d,query:f,onQueryChange:p,ref:t,children:[(0,I.jsx)(LN,{...n}),m.length>0&&(0,I.jsx)(AN,{...u,children:m}),m.length===0&&s&&(0,I.jsx)(jN,{children:s})]})});zN.classes=wN,zN.displayName=`@mantine/spotlight/Spotlight`,zN.Search=LN,zN.ActionsList=AN,zN.Action=ON,zN.Empty=jN,zN.ActionsGroup=kN,zN.Footer=MN,zN.Root=FN,zN.open=mN.open,zN.close=mN.close,zN.toggle=mN.toggle;var BN=(0,b.createContext)({submitting:!1});BN.displayName=`FormContext`;function VN(e){let t={};for(let n of Array.from(e.elements))n instanceof HTMLInputElement?HN(t,n):n instanceof HTMLTextAreaElement?t[n.name]=n.value:n instanceof HTMLSelectElement&&UN(t,n);return t}function HN(e,t){t.disabled||(t.type===`checkbox`||t.type===`radio`)&&!t.checked||(e[t.name]=t.value)}function UN(e,t){e[t.name]=t.value}function WN(e){let[t,n]=(0,b.useState)(!1);return(0,I.jsx)(BN.Provider,{value:{submitting:t},children:(0,I.jsx)(`form`,{style:e.style,"data-testid":e.testid,onSubmit:t=>{t.preventDefault();let r=VN(t.target);if(e.onSubmit){n(!0);let t=e.onSubmit(r);t?.then?t.catch(console.error).finally(()=>{n(!1)}):n(!1)}},children:e.children})})}function GN(e){let{children:t,...n}=e,{submitting:r}=(0,b.useContext)(BN);return(0,I.jsx)(U,{type:`submit`,loading:r,...n,children:t})}function KN(e){let t=Q(),n=t.getUserConfiguration();function r(r){let{menuname:i,bookmarkname:a}=r,o=`${e.pathname}?${e.searchParams.toString()}`,s=jC(n);(s.menu?.find(({title:e})=>e===i))?.link?.push({name:a,target:o}),t.updateResource(s).then(r=>{n.menu=r.menu,t.dispatchEvent({type:`change`}),J({color:`green`,message:`Success`}),e.onOk()}).catch(e=>{J({color:`red`,message:Y(e)})})}return(0,I.jsx)(Bh,{title:`Add Bookmark`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:e.onCancel,children:(0,I.jsx)(WN,{onSubmit:r,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(qN,{config:n}),(0,I.jsx)(yb,{label:`Bookmark Name`,type:`text`,name:`bookmarkname`,placeholder:`Bookmark Name`,defaultValue:e.pathname.split(`/`)[1]||``,withAsterisk:!0}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(GN,{mt:`sm`,children:`OK`})})]})})})}function qN(e){function t(e){return e?.menu?.map(e=>e.title)}let n=t(e.config);return(0,I.jsx)(yg,{name:`menuname`,defaultValue:n[0],label:`Select Menu Option`,data:n,withAsterisk:!0})}function JN(e){return typeof e.code==`string`?e.code:JSON.stringify(e)}function YN(e){return typeof e.display==`string`?e.display:JN(e)}function XN(e){return{value:JN(e),label:YN(e),resource:e}}function ZN(e){return{code:e,display:e}}function QN(e){let t=Q(),{binding:n,creatable:r,clearable:i,expandParams:a,withHelpText:o,...s}=e,c=(0,b.useCallback)(async(e,r)=>{if(!n)return[];let i=(await t.valueSetExpand({count:10,...a,url:n,filter:e},{signal:r})).expansion?.contains??[],o=[];for(let e of i)e.code&&!o.some(t=>t.code===e.code)&&o.push(e);return o},[t,a,n]);return(0,I.jsx)(NM,{...s,creatable:r??!0,clearable:i??!0,toOption:XN,loadOptions:c,onCreate:ZN,itemComponent:o?$N:void 0})}var $N=(0,b.forwardRef)(({label:e,resource:t,active:n,...r},i)=>(0,I.jsx)(`div`,{ref:i,...r,children:(0,I.jsxs)(V,{wrap:`nowrap`,gap:`xs`,children:[n&&(0,I.jsx)(WA,{size:12}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:e}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:`${t.system}#${t.code}`})]})]})}));function eP(e){let{defaultValue:t,onChange:n,withHelpText:r,...i}=e,[a,o]=(0,b.useState)(t);function s(e){let t=e[0],r=nP(t);o(r),n&&n(r)}return(0,I.jsx)(QN,{defaultValue:tP(a),onChange:s,withHelpText:r??!0,...i})}function tP(e){return e?{code:e}:void 0}function nP(e){return e?.code}function rP(e){let[t,n]=(0,b.useState)(e.defaultValue),r=e.onChange,i=(0,b.useCallback)(e=>{n(e),r&&r(e)},[r]);return(0,I.jsx)(eP,{disabled:e.disabled,"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:t,onChange:i,name:e.name,placeholder:e.placeholder,binding:`https://medplum.com/fhir/ValueSet/resource-types`,creatable:!1,maxValues:e.maxValues??1,clearable:!1,withHelpText:!1})}var iP={navbar:`_navbar_196ng_1`,logoButton:`_logoButton_196ng_6`,menuTitle:`_menuTitle_196ng_25`,link:`_link_196ng_52`,dismissButton:`_dismissButton_196ng_92`,linkLabel:`_linkLabel_196ng_110`,iconWrapper:`_iconWrapper_196ng_121`,alertDot:`_alertDot_196ng_128`,linkCount:`_linkCount_196ng_139`,addBookmarkLink:`_addBookmarkLink_196ng_192`,toggleButton:`_toggleButton_196ng_202`,divider:`_divider_196ng_231`},aP={actionSection:`_actionSection_1l8yv_8`,action:`_action_1l8yv_8`,actionDescription:`_actionDescription_1l8yv_27`,actionsGroup:`_actionsGroup_1l8yv_32`,actionsList:`_actionsList_1l8yv_55`,content:`_content_1l8yv_60`},oP=200;function sP(){return(0,I.jsxs)(G,{gap:`xs`,py:`lg`,children:[(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Press `,(0,I.jsx)(Cm,{children:`⌘`}),` + `,(0,I.jsx)(Cm,{children:`K`}),` to open Search next time.`]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`(`,(0,I.jsx)(Cm,{children:`Ctrl`}),` + `,(0,I.jsx)(Cm,{children:`K`}),` on Windows)`]})]})}function cP({patientsOnly:e}){let t=Q(),n=uk(),[r,i]=(0,b.useState)((0,I.jsx)(sP,{})),[a,o]=(0,b.useState)([]),s=pt(r=>{let a=lP(r);e?t.graphql(a).then(e=>{o(fP(uP(e).filter(e=>e.resourceType===`Patient`),n))}).catch(console.error).finally(()=>i(`No results found`)):Promise.all([t.graphql(a),t.valueSetExpand({url:`https://medplum.com/fhir/ValueSet/resource-types`,filter:r,count:5})]).then(([e,t])=>{o(pP(uP(e),t.expansion?.contains??[],n))}).catch(console.error).finally(()=>i(`No results found`))},oP);return(0,I.jsx)(zN,{actions:a,nothingFound:r,radius:`md`,highlightQuery:!0,searchProps:{leftSection:(0,I.jsx)(Rj,{size:`1.2rem`,stroke:2,color:`var(--mantine-color-gray-5)`}),placeholder:`Start typing to search…`,type:`search`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,name:e?`provider-spotlight-search`:`spotlight-search`,"data-1p-ignore":`true`,"data-lpignore":`true`,leftSectionProps:{style:{marginLeft:`calc(var(--mantine-spacing-md) - 12px)`}}},classNames:{body:aP.body,content:aP.content,search:aP.search,actionsList:aP.actionsList,action:aP.action,actionSection:aP.actionSection,actionDescription:aP.actionDescription,actionsGroup:aP.actionsGroup},onQueryChange:e=>{if(!e){s.cancel(),i((0,I.jsx)(sP,{})),o([]);return}i(`Searching...`),s(e)}})}function lP(e){let t=JSON.stringify(e);return MC(e)?`{
|
|
159
|
+
}`.replaceAll(/\s+/g,` `)}function UM(e,t){let n=[];return e.data.Patients1&&n.push(...e.data.Patients1),e.data.Patients2&&n.push(...e.data.Patients2),e.data.ServiceRequestList&&n.push(...e.data.ServiceRequestList),GM(WM(n),t).slice(0,5)}function WM(e){let t=new Set,n=[];for(let r of e)t.has(r.id)||(t.add(r.id),n.push(r));return n}function GM(e,t){return e.sort((e,n)=>KM(n,t)-KM(e,t))}function KM(e,t){let n=0;if(e.identifier)for(let r of e.identifier)n=Math.max(n,qM(r.value,t));if(e.resourceType===`Patient`&&e.name)for(let r of e.name)n=Math.max(n,qM(cw(r),t));return n}function qM(e,t){if(!e)return 0;let n=e.toLowerCase().indexOf(t.toLowerCase());return n<0?0:100-n}function JM(e){let t=Q(),n=dk(),[r,i]=(0,b.useState)(!1),a=t.getProject()?.name??t.getActiveLogin()?.project.display;return(0,I.jsxs)(zu.Header,{p:0,style:{zIndex:101},children:[(0,I.jsx)(z,{p:8,h:60,children:(0,I.jsxs)(V,{justify:`space-between`,children:[(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(qc,{className:vM.logoButton,"aria-expanded":e.navbarOpen,"aria-controls":`navbar`,onClick:()=>e.navbarToggle(),children:e.logo}),!e.headerSearchDisabled&&(0,I.jsx)(BM,{pathname:e.pathname,searchParams:e.searchParams})]}),(0,I.jsxs)(V,{gap:`lg`,pr:`sm`,children:[e.notifications,(0,I.jsxs)(W,{width:260,shadow:`md`,radius:`md`,position:`bottom-end`,transitionProps:{transition:`fade-down`},opened:r,onClose:()=>i(!1),children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(qc,{className:vM.user,"aria-label":`User menu`,"data-active":r||void 0,onClick:()=>i(e=>!e),children:(0,I.jsxs)(V,{gap:7,children:[(0,I.jsx)(_M,{value:n,radius:`xl`,size:24}),(0,I.jsxs)(G,{gap:0,className:vM.userInfo,children:[(0,I.jsx)(H,{size:`sm`,className:vM.userName,truncate:!0,children:cw(n?.name?.[0])}),a&&(0,I.jsx)(H,{size:`xs`,c:`dimmed`,className:vM.userProject,title:a,truncate:!0,children:a})]}),(0,I.jsx)(KA,{size:12,stroke:1.5})]})})}),(0,I.jsx)(W.Dropdown,{className:CM.dropdown,children:(0,I.jsx)(jM,{version:e.version})})]})]})]})}),!!e.announcements?.length&&e.onDismissAnnouncement&&(0,I.jsx)(iM,{announcements:e.announcements,onDismiss:e.onDismissAnnouncement})]})}var YM=()=>kb({opened:!1,empty:!1,selected:-1,listId:``,query:``,registeredActions:new Set}),XM=e=>Ab(e);function ZM(e,t){let n=t.getState();t.setState({...n,...e(t.getState())})}function QM(e){ZM(()=>({opened:!0,selected:-1}),e)}function $M(e){ZM(()=>({opened:!1}),e)}function eN(e){ZM(e=>({opened:!e.opened,selected:e.opened?e.selected:-1}),e)}function tN(e,t){t.updateState(t=>({...t,selected:e}))}function nN(e,t){t.updateState(t=>({...t,listId:e}))}function rN(e,t=document){let n=t.querySelector(e);if(n)return n;let r=t instanceof ShadowRoot?t.host.children:t.children;for(let t=0;t<r.length;t+=1){let n=r[t];if(n.shadowRoot){let t=rN(e,n.shadowRoot);if(t)return t}let i=rN(e,n);if(i)return i}return null}function iN(e,t){let n=t.getState(),r=n.listId?rN(`#${n.listId}`):null,i=r?.querySelector(`[data-selected]`),a=r?.querySelectorAll(`[data-action]`)??[],o=lt(e===-1?a.length-1:e===a.length?0:e,0,a.length-1);return i?.removeAttribute(`data-selected`),a[o]?.scrollIntoView({block:`nearest`}),a[o]?.setAttribute(`data-selected`,`true`),tN(o,t),o}function aN(e){return iN(e.getState().selected+1,e)}function oN(e){return iN(e.getState().selected-1,e)}function sN(e){rN(`#${e.getState().listId} [data-selected]`)?.click()}function cN(e,t){let n=t.getState();return n.registeredActions.add(e),()=>{n.registeredActions.delete(e)}}function lN(e,t){ZM(()=>({query:e}),t),Promise.resolve().then(()=>{iN(0,t),ZM(e=>({empty:e.query.trim().length>0&&e.registeredActions.size===0||!1}),t)})}function uN({clearQuery:e},t){t.updateState(t=>({...t,selected:-1,query:e?``:t.query,empty:e?!1:t.empty}))}var dN={open:QM,close:$M,toggle:eN,updateState:ZM,setSelectedAction:tN,setListId:nN,selectAction:iN,selectNextAction:aN,selectPreviousAction:oN,triggerSelectedAction:sN,registerAction:cN,setQuery:lN,clearSpotlightState:uN};function fN(){let e=YM();return[e,{open:()=>QM(e),close:()=>$M(e),toggle:()=>eN(e)}]}var[pN,mN]=fN(),{open:hN,close:gN,toggle:_N}=mN;function vN(e){return Array.isArray(e)?e.map(e=>e.trim()).join(`,`).toLowerCase().trim():typeof e==`string`?e.toLowerCase().trim():``}function yN(e){return e.reduce((e,t)=>`actions`in t?[...e,...t.actions.map(e=>({...e,group:t.group}))]:[...e,t],[])}function bN(e){let t={},n=[];return e.forEach(e=>{e.group?(t[e.group]||(t[e.group]={pushed:!1,data:{group:e.group,actions:[]}}),t[e.group].data.actions.push(e),t[e.group].pushed||(t[e.group].pushed=!0,n.push(t[e.group].data))):n.push(e)}),n}var xN=(e,t)=>{let n=e.trim().toLowerCase(),r=[[],[]];return yN(t).forEach(e=>{e.label?.toLowerCase().includes(n)?r[0].push(e):(e.description?.toLowerCase().includes(n)||vN(e.keywords).includes(n))&&r[1].push(e)}),bN(r.flat())};function SN(e){let t=e;return t.group!==void 0&&Array.isArray(t.actions)}function CN(e,t){if(!Array.isArray(e))return[];let n=0;return e.reduce((e,r)=>{if(n>=t)return e;if(SN(r)){let i=CN(r.actions,t-n);e.push({group:r.group,actions:i}),n+=i.length}else e.push(r),n+=1;return e},[])}var wN={root:`m_d2b315db`,content:`m_3cd250e0`,body:`m_d2abce9b`,search:`m_f366a061`,actionsList:`m_6e463822`,action:`m_d49bb8ef`,actionBody:`m_3d475731`,actionSection:`m_832642f6`,actionLabel:`m_6c2a1345`,actionDescription:`m_a6d9d78d`,empty:`m_82f78f74`,footer:`m_ddcaf054`,actionsGroup:`m_5a3e5f7b`},[TN,EN]=Ke(`Spotlight component was not found in tree`),DN={dimmedSections:!0,highlightQuery:!1},ON=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,id:o,description:s,label:c,leftSection:l,rightSection:u,children:d,dimmedSections:f,highlightQuery:p,highlightColor:m,closeSpotlightOnTrigger:h,onClick:g,onMouseDown:_,keywords:v,vars:y,...b}=R(`SpotlightAction`,DN,e),x=EN(),S={classNames:i,styles:a},C=p&&typeof c==`string`?(0,I.jsx)(Up,{component:`span`,highlight:x.query,color:m,...x.getStyles(`actionLabel`,S),children:c}):(0,I.jsx)(`span`,{...x.getStyles(`actionLabel`,S),children:c});return(0,I.jsx)(qc,{ref:t,"data-action":!0,...x.getStyles(`action`,{className:n,style:r,...S}),...b,onMouseDown:e=>{e.preventDefault(),_?.(e)},onClick:e=>{g?.(e),(h??x.closeOnActionTrigger)&&dN.close(x.store)},tabIndex:-1,children:d||(0,I.jsxs)(I.Fragment,{children:[l&&(0,I.jsx)(z,{component:`span`,mod:{position:`left`,dimmed:f},...x.getStyles(`actionSection`,S),children:l}),(0,I.jsxs)(`span`,{...x.getStyles(`actionBody`,S),children:[C,(0,I.jsx)(`span`,{...x.getStyles(`actionDescription`,S),children:s})]}),u&&(0,I.jsx)(z,{component:`span`,mod:{position:`right`,dimmed:f},...x.getStyles(`actionSection`,S),children:u})]})})});ON.classes=wN,ON.displayName=`@mantine/spotlight/SpotlightAction`;var kN=B((e,t)=>{let{className:n,style:r,styles:i,classNames:a,label:o,children:s,...c}=R(`SpotlightActionsGroup`,null,e);return(0,I.jsx)(z,{...EN().getStyles(`actionsGroup`,{className:n,style:r,classNames:a,styles:i}),ref:t,...c,__vars:{"--spotlight-label":`'${o?.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`},children:s})});kN.classes=wN,kN.displayName=`@mantine/core/SpotlightActionsGroup`;var AN=B((e,t)=>{let{className:n,style:r,id:i,children:a,vars:o,classNames:s,styles:c,...l}=R(`SpotlightActionsList`,null,e),u=EN(),d=`mantine-${(0,b.useId)().replace(/:/g,``)}`,f=i||d;return(0,b.useEffect)(()=>(dN.setListId(f,u.store),()=>dN.setListId(``,u.store)),[]),(0,I.jsx)(Hc.Autosize,{...u.getStyles(`actionsList`,{className:n,style:r,classNames:s,styles:c}),ref:t,type:`scroll`,scrollbarSize:`var(--spotlight-actions-list-padding)`,offsetScrollbars:`y`,id:f,...l,children:a})});AN.classes=wN,AN.displayName=`@mantine/spotlight/SpotlightActionsList`;var jN=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,...o}=R(`SpotlightEmpty`,null,e);return(0,I.jsx)(z,{ref:t,...EN().getStyles(`empty`,{classNames:i,styles:a,className:n,style:r}),...o})});jN.classes=wN,jN.displayName=`@mantine/spotlight/SpotlightEmpty`;var MN=B((e,t)=>{let{className:n,style:r,classNames:i,styles:a,...o}=R(`SpotlightFooter`,null,e);return(0,I.jsx)(z,{ref:t,...EN().getStyles(`footer`,{className:n,classNames:i,style:r,styles:a}),...o})});MN.classes=wN,MN.displayName=`@mantine/spotlight/SpotlightFooter`;function NN(e,t){if(!e)return[];let n=()=>dN.open(t);return Array.isArray(e)?e.map(e=>[e,n]):[[e,n]]}var PN={size:600,yOffset:80,zIndex:Je(`max`),overlayProps:{backgroundOpacity:.35,blur:7},transitionProps:{duration:200,transition:`pop`},store:pN,clearQueryOnClose:!0,closeOnActionTrigger:!0,shortcut:`mod + K`,maxHeight:400},FN=B((e,t)=>{let n=R(`SpotlightRoot`,PN,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,store:l,children:u,query:d,onQueryChange:f,transitionProps:p,clearQueryOnClose:m,shortcut:h,tagsToIgnore:g,triggerOnContentEditable:_,disabled:v,onSpotlightOpen:y,onSpotlightClose:b,forceOpened:x,closeOnActionTrigger:S,maxHeight:C,scrollable:w,attributes:T,...E}=n,D=er(),{opened:O,query:k}=XM(l),A=typeof d==`string`?d:k,j=e=>{f?.(e),dN.setQuery(e,l)},M=L({name:`Spotlight`,classes:wN,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:T});return an(NN(h,l),g,_),xt(()=>{O?y?.():b?.()},[O]),v?null:(0,I.jsx)(TN,{value:{getStyles:M,query:A,setQuery:j,store:l,closeOnActionTrigger:S},children:(0,I.jsx)(Bh,{ref:t,...E,withCloseButton:!1,opened:O||!!x,padding:0,onClose:()=>dN.close(l),className:i,style:a,classNames:st({theme:D,classNames:[wN,r],props:n,stylesCtx:void 0}),styles:ct({theme:D,styles:o,props:n,stylesCtx:void 0}),transitionProps:{...p,onExited:()=>{m&&j(``),dN.clearSpotlightState({clearQuery:m},l),p?.onExited?.()}},__vars:{"--spotlight-max-height":w?F(C):void 0},__staticSelector:`Spotlight`,"data-scrollable":w||void 0,children:u})})});FN.classes=wN,FN.displayName=`@mantine/spotlight/SpotlightRoot`;var IN={size:`lg`},LN=B((e,t)=>{let{classNames:n,styles:r,onKeyDown:i,onChange:a,vars:o,value:s,...c}=R(`SpotlightSearch`,IN,e),l=EN(),u=l.getStyles(`search`),[d,f]=(0,b.useState)(!1),p=e=>{i?.(e),!d&&(e.nativeEvent.code===`ArrowDown`&&(e.preventDefault(),dN.selectNextAction(l.store)),e.nativeEvent.code===`ArrowUp`&&(e.preventDefault(),dN.selectPreviousAction(l.store)),(e.nativeEvent.code===`Enter`||e.nativeEvent.code===`NumpadEnter`)&&(e.preventDefault(),dN.triggerSelectedAction(l.store)))};return(0,I.jsx)(Zl,{ref:t,classNames:[{input:u.className},n],styles:[{input:u.style},r],...c,value:s??l.query,onChange:e=>{l.setQuery(e.currentTarget.value),a?.(e)},onKeyDown:p,onCompositionStart:()=>f(!0),onCompositionEnd:()=>f(!1)})});LN.classes=wN,LN.displayName=`@mantine/spotlight/SpotlightSearch`;var RN={size:600,yOffset:80,limit:1/0,zIndex:Je(`max`),overlayProps:{backgroundOpacity:.35,blur:7},transitionProps:{duration:200,transition:`pop`},store:pN,filter:xN,clearQueryOnClose:!0,closeOnActionTrigger:!0,shortcut:`mod + K`},zN=B((e,t)=>{let{searchProps:n,filter:r,query:i,onQueryChange:a,actions:o,nothingFound:s,highlightQuery:c,limit:l,scrollAreaProps:u,...d}=R(`Spotlight`,RN,e),[f,p]=Ht({value:i,defaultValue:``,finalValue:``,onChange:a}),m=CN(r(f,o),l).map(e=>{if(SN(e)){let t=e.actions.map(({id:e,...t})=>(0,I.jsx)(ON,{highlightQuery:c,...t},e));return(0,I.jsx)(kN,{label:e.group,children:t},e.group)}return(0,I.jsx)(ON,{highlightQuery:c,...e},e.id)});return(0,I.jsxs)(FN,{...d,query:f,onQueryChange:p,ref:t,children:[(0,I.jsx)(LN,{...n}),m.length>0&&(0,I.jsx)(AN,{...u,children:m}),m.length===0&&s&&(0,I.jsx)(jN,{children:s})]})});zN.classes=wN,zN.displayName=`@mantine/spotlight/Spotlight`,zN.Search=LN,zN.ActionsList=AN,zN.Action=ON,zN.Empty=jN,zN.ActionsGroup=kN,zN.Footer=MN,zN.Root=FN,zN.open=mN.open,zN.close=mN.close,zN.toggle=mN.toggle;var BN=(0,b.createContext)({submitting:!1});BN.displayName=`FormContext`;function VN(e){let t={};for(let n of Array.from(e.elements))n instanceof HTMLInputElement?HN(t,n):n instanceof HTMLTextAreaElement?t[n.name]=n.value:n instanceof HTMLSelectElement&&UN(t,n);return t}function HN(e,t){t.disabled||(t.type===`checkbox`||t.type===`radio`)&&!t.checked||(e[t.name]=t.value)}function UN(e,t){e[t.name]=t.value}function WN(e){let[t,n]=(0,b.useState)(!1);return(0,I.jsx)(BN.Provider,{value:{submitting:t},children:(0,I.jsx)(`form`,{style:e.style,"data-testid":e.testid,onSubmit:t=>{t.preventDefault();let r=VN(t.target);if(e.onSubmit){n(!0);let t=e.onSubmit(r);t?.then?t.catch(console.error).finally(()=>{n(!1)}):n(!1)}},children:e.children})})}function GN(e){let{children:t,...n}=e,{submitting:r}=(0,b.useContext)(BN);return(0,I.jsx)(U,{type:`submit`,loading:r,...n,children:t})}function KN(e){let t=Q(),n=t.getUserConfiguration();function r(r){let{menuname:i,bookmarkname:a}=r,o=`${e.pathname}?${e.searchParams.toString()}`,s=jC(n);(s.menu?.find(({title:e})=>e===i))?.link?.push({name:a,target:o}),t.updateResource(s).then(r=>{n.menu=r.menu,t.dispatchEvent({type:`change`}),J({color:`green`,message:`Success`}),e.onOk()}).catch(e=>{J({color:`red`,message:Y(e)})})}return(0,I.jsx)(Bh,{title:`Add Bookmark`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:e.onCancel,children:(0,I.jsx)(WN,{onSubmit:r,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(qN,{config:n}),(0,I.jsx)(yb,{label:`Bookmark Name`,type:`text`,name:`bookmarkname`,placeholder:`Bookmark Name`,defaultValue:e.pathname.split(`/`)[1]||``,withAsterisk:!0}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(GN,{mt:`sm`,children:`OK`})})]})})})}function qN(e){function t(e){return e?.menu?.map(e=>e.title)}let n=t(e.config);return(0,I.jsx)(yg,{name:`menuname`,defaultValue:n[0],label:`Select Menu Option`,data:n,withAsterisk:!0})}function JN(e){return typeof e.code==`string`?e.code:JSON.stringify(e)}function YN(e){return typeof e.display==`string`?e.display:JN(e)}function XN(e){return{value:JN(e),label:YN(e),resource:e}}function ZN(e){return{code:e,display:e}}function QN(e){let t=Q(),{binding:n,creatable:r,clearable:i,expandParams:a,withHelpText:o,...s}=e,c=(0,b.useCallback)(async(e,r)=>{if(!n)return[];let i=(await t.valueSetExpand({count:10,...a,url:n,filter:e},{signal:r})).expansion?.contains??[],o=[];for(let e of i)e.code&&!o.some(t=>t.code===e.code)&&o.push(e);return o},[t,a,n]);return(0,I.jsx)(NM,{...s,creatable:r??!0,clearable:i??!0,toOption:XN,loadOptions:c,onCreate:ZN,itemComponent:o?$N:void 0})}var $N=(0,b.forwardRef)(({label:e,resource:t,active:n,...r},i)=>(0,I.jsx)(`div`,{ref:i,...r,children:(0,I.jsxs)(V,{wrap:`nowrap`,gap:`xs`,children:[n&&(0,I.jsx)(WA,{size:12}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:e}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:`${t.system}#${t.code}`})]})]})}));function eP(e){let{defaultValue:t,onChange:n,withHelpText:r,...i}=e,[a,o]=(0,b.useState)(t);function s(e){let t=e[0],r=nP(t);o(r),n&&n(r)}return(0,I.jsx)(QN,{defaultValue:tP(a),onChange:s,withHelpText:r??!0,...i})}function tP(e){return e?{code:e}:void 0}function nP(e){return e?.code}function rP(e){let[t,n]=(0,b.useState)(e.defaultValue),r=e.onChange,i=(0,b.useCallback)(e=>{n(e),r&&r(e)},[r]);return(0,I.jsx)(eP,{disabled:e.disabled,"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:t,onChange:i,name:e.name,placeholder:e.placeholder,binding:`https://medplum.com/fhir/ValueSet/resource-types`,creatable:!1,maxValues:e.maxValues??1,clearable:!1,withHelpText:!1})}var iP={navbar:`_navbar_g9m3l_1`,logoButton:`_logoButton_g9m3l_6`,menuTitle:`_menuTitle_g9m3l_25`,link:`_link_g9m3l_52`,dismissButton:`_dismissButton_g9m3l_92`,linkLabel:`_linkLabel_g9m3l_110`,userLink:`_userLink_g9m3l_121`,userLinkLabel:`_userLinkLabel_g9m3l_128`,iconWrapper:`_iconWrapper_g9m3l_141`,alertDot:`_alertDot_g9m3l_148`,linkCount:`_linkCount_g9m3l_159`,addBookmarkLink:`_addBookmarkLink_g9m3l_212`,toggleButton:`_toggleButton_g9m3l_222`,divider:`_divider_g9m3l_251`},aP={actionSection:`_actionSection_1l8yv_8`,action:`_action_1l8yv_8`,actionDescription:`_actionDescription_1l8yv_27`,actionsGroup:`_actionsGroup_1l8yv_32`,actionsList:`_actionsList_1l8yv_55`,content:`_content_1l8yv_60`},oP=200;function sP(){return(0,I.jsxs)(G,{gap:`xs`,py:`lg`,children:[(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Press `,(0,I.jsx)(Cm,{children:`⌘`}),` + `,(0,I.jsx)(Cm,{children:`K`}),` to open Search next time.`]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`(`,(0,I.jsx)(Cm,{children:`Ctrl`}),` + `,(0,I.jsx)(Cm,{children:`K`}),` on Windows)`]})]})}function cP({patientsOnly:e}){let t=Q(),n=uk(),[r,i]=(0,b.useState)((0,I.jsx)(sP,{})),[a,o]=(0,b.useState)([]),s=pt(r=>{let a=lP(r);e?t.graphql(a).then(e=>{o(fP(uP(e).filter(e=>e.resourceType===`Patient`),n))}).catch(console.error).finally(()=>i(`No results found`)):Promise.all([t.graphql(a),t.valueSetExpand({url:`https://medplum.com/fhir/ValueSet/resource-types`,filter:r,count:5})]).then(([e,t])=>{o(pP(uP(e),t.expansion?.contains??[],n))}).catch(console.error).finally(()=>i(`No results found`))},oP);return(0,I.jsx)(zN,{actions:a,nothingFound:r,radius:`md`,highlightQuery:!0,searchProps:{leftSection:(0,I.jsx)(Rj,{size:`1.2rem`,stroke:2,color:`var(--mantine-color-gray-5)`}),placeholder:`Start typing to search…`,type:`search`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,name:e?`provider-spotlight-search`:`spotlight-search`,"data-1p-ignore":`true`,"data-lpignore":`true`,leftSectionProps:{style:{marginLeft:`calc(var(--mantine-spacing-md) - 12px)`}}},classNames:{body:aP.body,content:aP.content,search:aP.search,actionsList:aP.actionsList,action:aP.action,actionSection:aP.actionSection,actionDescription:aP.actionDescription,actionsGroup:aP.actionsGroup},onQueryChange:e=>{if(!e){s.cancel(),i((0,I.jsx)(sP,{})),o([]);return}i(`Searching...`),s(e)}})}function lP(e){let t=JSON.stringify(e);return MC(e)?`{
|
|
160
160
|
Patients1: PatientList(_id: ${t}, _count: 1) {
|
|
161
161
|
resourceType
|
|
162
162
|
id
|
|
@@ -194,7 +194,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function ar({color:e,theme:t,autoContrast:n}){ret
|
|
|
194
194
|
identifier { system value }
|
|
195
195
|
subject { display }
|
|
196
196
|
}
|
|
197
|
-
}`.replaceAll(/\s+/g,` `)}function uP(e){let t=[];return e.data.Patients1&&t.push(...e.data.Patients1),e.data.Patients2&&t.push(...e.data.Patients2),e.data.ServiceRequestList&&t.push(...e.data.ServiceRequestList),dP(t)}function dP(e){let t=new Set,n=[];for(let r of e)r.id&&!t.has(r.id)&&(t.add(r.id),n.push(r));return n}function fP(e,t){let n=e.filter(e=>!!e.id).map(e=>({id:e.id,label:e.name?cw(e.name[0]):e.id,description:e.birthDate,leftSection:(0,I.jsx)(_M,{value:e,radius:`xl`,size:24}),onClick:()=>t(`/Patient/${e.id}`)}));return n.length>0?[{group:`Patients`,actions:n}]:[]}function pP(e,t,n){let r=[],i=t.map(e=>({id:`resource-type-${e.code}`,label:e.display??e.code??``,description:`Resource Type`,onClick:()=>n(`/${e.code}`)}));i.length>0&&r.push({group:`Resource Types`,actions:i});let a=[],o=[];for(let t of e)t.resourceType===`Patient`&&t.id?a.push({id:t.id,label:t.name?cw(t.name[0]):t.id,description:t.birthDate,leftSection:(0,I.jsx)(_M,{value:t,radius:`xl`,size:24}),onClick:()=>n(`/Patient/${t.id}`)}):t.resourceType===`ServiceRequest`&&t.id&&o.push({id:t.id,label:t.id,description:t.subject?.display,onClick:()=>n(`/ServiceRequest/${t.id}`)});return a.length>0&&r.push({group:`Patients`,actions:a}),o.length>0&&r.push({group:`Service Requests`,actions:o}),r}function mP(e){let t=uk(),n=dk(),r=_P(e.pathname,e.searchParams,e.menus),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(!1);function c(n,r){n.stopPropagation(),n.preventDefault(),t(r),window.innerWidth<768&&e.closeNavbar()}function l(e){e&&t(`/${e}`)}let u=e.opened??!0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(zu.Navbar,{id:`navbar`,className:iP.navbar,children:[e.logo&&(0,I.jsx)(zu.Section,{px:`xs`,pt:`xs`,pb:`4px`,children:(0,I.jsx)(qc,{className:iP.logoButton,onClick:e.navbarToggle,"aria-expanded":u,"aria-controls":`navbar`,"aria-label":`Medplum Logo`,children:e.logo})}),(0,I.jsx)(Hc,{px:`xs`,pb:`xs`,pt:`sm`,h:`100%`,children:(0,I.jsxs)(zu.Section,{grow:!0,children:[e.spotlightEnabled&&(0,I.jsx)(z,{mb:2,children:(0,I.jsx)(Kv,{label:`Search`,position:`right`,transitionProps:{duration:0},disabled:u,children:(0,I.jsxs)(qc,{className:iP.link,onClick:()=>mN.open(),"aria-label":`Search`,children:[(0,I.jsx)(Rj,{size:`1.2rem`}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":u||void 0,children:`Search`})]})})}),e.spotlightEnabled&&(0,I.jsx)(cP,{patientsOnly:e.patientsOnly}),!e.resourceTypeSearchDisabled&&(0,I.jsx)(zu.Section,{mb:`sm`,children:(0,I.jsx)(rP,{name:`resourceType`,placeholder:`Resource Type`,maxValues:0,onChange:e=>l(e)},window.location.pathname)}),e.menus?.map((e,t)=>(0,I.jsxs)(b.Fragment,{children:[e.title&&(0,I.jsx)(H,{className:iP.menuTitle,"data-opened":u||void 0,children:e.title}),(0,I.jsx)(G,{gap:`2`,children:e.links?.map(e=>e.notificationCount?(0,I.jsx)(gP,{to:e.href,active:e.href===r?.href,onClick:t=>c(t,e.href),icon:e.icon,label:e.label??``,opened:u,alert:e.alert,notificationCount:e.notificationCount,onDismiss:e.onDismiss},e.href):(0,I.jsx)(hP,{to:e.href,active:e.href===r?.href,onClick:t=>c(t,e.href),icon:e.icon,label:e.label??``,opened:u,alert:e.alert,count:e.count,onDismiss:e.onDismiss},e.href))})]},`menu-${e.title??t}`)),e.displayAddBookmark&&(0,I.jsx)(Kv,{label:`Add Bookmark`,position:`right`,transitionProps:{duration:0},disabled:u,children:(0,I.jsxs)(qc,{className:`${iP.link} ${iP.addBookmarkLink}`,onClick:()=>s(!0),children:[(0,I.jsx)(YA,{}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":u||void 0,children:`Add Bookmark`})]})})]})}),e.userMenuEnabled&&(0,I.jsxs)(zu.Section,{px:`xs`,py:`xs`,children:[(0,I.jsx)(Kv,{label:u?`Close Sidebar`:`Open Sidebar`,position:`right`,transitionProps:{duration:0},children:(0,I.jsx)(qc,{className:iP.toggleButton,"data-opened":u||void 0,"aria-label":u?`Close Sidebar`:`Open Sidebar`,onClick:e.navbarToggle,"aria-expanded":u,"aria-controls":`navbar`,children:(0,I.jsx)(hj,{})})}),(0,I.jsx)(bp,{my:`xs`,className:iP.divider}),(0,I.jsxs)(W,{width:260,shadow:`md`,radius:`md`,position:`top-start`,transitionProps:{transition:`fade-up`},opened:i,onClose:()=>a(!1),children:[(0,I.jsx)(W.Target,{children:(0,I.jsxs)(qc,{className:iP.link,pl:`7`,"aria-label":`User menu`,"data-active":i||void 0,onClick:()=>a(e=>!e),bd:`1px 0 0 0 solid var(--mantine-color-gray-200)`,children:[(0,I.jsx)(_M,{value:n,radius:`xl`,size:24}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":u||void 0,children:cw(n?.name?.[0])})]})}),(0,I.jsx)(W.Dropdown,{className:CM.dropdown,children:(0,I.jsx)(jM,{version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle})})]})]})]}),e.pathname&&e.searchParams&&(0,I.jsx)(KN,{pathname:e.pathname,searchParams:e.searchParams,visible:o,onOk:()=>s(!1),onCancel:()=>s(!1)})]})}function hP(e){let{to:t,icon:n,label:r,onClick:i,active:a,count:o,alert:s,opened:c,onDismiss:l}=e,u=o!==void 0&&o>0,d=n??(0,I.jsx)(FA,{}),f=u&&s&&!c;function p(e){e.preventDefault(),e.stopPropagation(),l?.()}return(0,I.jsx)(Kv,{label:r,position:`right`,transitionProps:{duration:0},disabled:c,children:(0,I.jsxs)(dM,{to:t,onClick:i,className:iP.link,"data-active":a||void 0,children:[(0,I.jsxs)(`span`,{className:iP.iconWrapper,children:[d,f&&(0,I.jsx)(`span`,{className:iP.alertDot})]}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":c||void 0,children:r}),u&&(0,I.jsx)(`span`,{className:iP.linkCount,"data-opened":c||void 0,"data-alert":s||void 0,children:o.toLocaleString()}),l&&c&&(0,I.jsx)(Kv,{label:`Dismiss`,openDelay:500,children:(0,I.jsx)(qc,{"aria-label":`Dismiss`,className:iP.dismissButton,onClick:p,children:(0,I.jsx)($j,{size:14})})})]})})}function gP(e){let t=yk(e.notificationCount);return(0,I.jsx)(hP,{to:e.to,active:e.active,onClick:e.onClick,icon:e.icon,label:e.label,opened:e.opened,alert:e.alert,count:t,onDismiss:e.onDismiss})}function _P(e,t,n){if(!e||!t||!n)return;let r,i=0;for(let a of n)if(a.links)for(let n of a.links){let a=vP(e,t,n.href);a>i&&(i=a,r=n)}return r}function vP(e,t,n){let r=new URL(n,`https://example.com`);if(e!==r.pathname)return 0;let i=[`_count`,`_offset`];for(let[e,n]of r.searchParams.entries())if(!i.includes(e)&&t.get(e)!==n)return 0;let a=1;for(let[e,n]of t.entries())i.includes(e)||r.searchParams.get(e)===n&&a++;return a}var yP=250,bP=59,xP=60,SP=36;function CP(e){let[t,n]=(0,b.useState)(localStorage.navbarOpen===`true`),[r]=(0,b.useState)(e.layoutVersion??localStorage.appShellLayoutVersion??`v1`),i=Q(),a=dk(),[o,s]=(0,b.useState)(()=>{try{let e=localStorage.appShellDismissedAnnouncements;return new Set(e?JSON.parse(e):[])}catch{return new Set}}),c=e.announcements?.filter(e=>!e.id||!o.has(e.id)),l=c?.length?c.length*SP:0;function u(e){localStorage.navbarOpen=e.toString(),n(e)}function d(e){e.id&&s(t=>{let n=new Set(t);return n.add(e.id),localStorage.appShellDismissedAnnouncements=JSON.stringify([...n]),n}),e.onDismiss?.(e)}function f(){u(!1)}function p(){u(!t)}if(i.isLoading())return(0,I.jsx)(nM,{});let m,h,g,_;return r===`v2`?(m={height:l},h={width:t?yP:bP,breakpoint:0,collapsed:{desktop:!a,mobile:!a}},g=c?.length?(0,I.jsx)(zu.Header,{style:{zIndex:101},children:(0,I.jsx)(iM,{announcements:c,onDismiss:d})}):void 0,_=a?(0,I.jsx)(mP,{logo:e.logo,pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,navbarToggle:p,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:!0,opened:t,spotlightEnabled:!0,patientsOnly:e.spotlightPatientsOnly,userMenuEnabled:!0,version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle}):void 0):(m={height:xP+l},h={width:yP,breakpoint:`sm`,collapsed:{desktop:!a||!t,mobile:!a||!t}},g=a&&(0,I.jsx)(JM,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarOpen:t,navbarToggle:p,notifications:e.notifications,announcements:c,onDismissAnnouncement:d}),_=a&&t?(0,I.jsx)(mP,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,navbarToggle:p,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled,patientsOnly:e.spotlightPatientsOnly}):void 0),(0,I.jsxs)(zu,{header:m,navbar:h,padding:0,children:[g,_,(0,I.jsx)(zu.Main,{className:rM.main,children:(0,I.jsx)(tM,{children:(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(nM,{}),children:e.children})})})]})}var wP=`https://ccda.medplum.com`,TP=`https://ccda-validator.medplum.com/`;function EP(e){let{url:t}=e,[n,r]=(0,b.useState)(!1),i=(0,b.useRef)(null),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{t&&n&&i.current&&(lM(i.current,{command:`loadCcdaXml`,value:t}).catch(console.error),r(!1))},[t,n]),t?(0,I.jsxs)(`div`,{"data-testid":`ccda-iframe`,style:{maxWidth:e.maxWidth},children:[(0,I.jsx)(`div`,{style:{minHeight:400},children:(0,I.jsx)(`iframe`,{title:`C-CDA Viewer`,width:`100%`,height:`400`,ref:i,src:wP,allowFullScreen:!0,frameBorder:0,seamless:!0,onLoad:()=>r(!0)})}),(0,I.jsxs)(`div`,{style:{marginTop:`10px`,marginBottom:`10px`,display:`flex`,alignItems:`center`},children:[(0,I.jsx)(U,{type:`button`,onClick:async()=>{if(t)try{c(!0);let e=await(await fetch(t)).text(),n=new FormData;n.append(`ccdaFile`,new Blob([e],{type:`text/xml`}),`ccda.xml`);let r=await fetch(`${TP}referenceccdaservice/?validationObjective=C-CDA_IG_Plus_Vocab&referenceFileName=No%20scenario%20File&curesUpdate=true&severityLevel=WARNING`,{method:`POST`,body:n,credentials:`omit`,redirect:`manual`});if(!r.ok)throw Error(`Validation failed: ${r.status} ${r.statusText}`);o(await r.json())}catch(e){o(void 0),console.error(`CCDA validation error:`,e)}finally{c(!1)}},disabled:s,children:s?`Validating...`:`Validate`}),a&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{style:{marginLeft:`15px`},children:[(0,I.jsx)(`strong`,{children:`Validation Results:`}),` `,a?a.resultsMetaData.resultMetaData.filter(e=>e?.type.includes(`Error`)).reduce((e,t)=>e+(t.count||0),0):0,` errors found`]}),(0,I.jsx)(U,{type:`button`,onClick:()=>{a&&uM(JSON.stringify(a,null,2),`ccda-validation-results`)},color:`green`,style:{marginLeft:`auto`},children:`Download Full Results`})]})]})]}):null}function DP(e){let{maxRetries:t=5,...n}=e,[r,i]=(0,b.useState)(0),[a,o]=(0,b.useState)(`fetching`),s=(0,b.useRef)(void 0);return(0,b.useEffect)(()=>()=>{s.current!==void 0&&clearTimeout(s.current)},[]),a===`failed`?(0,I.jsx)(`div`,{className:`image-placeholder`,children:`Image unavailable`}):a===`backoff`?(0,I.jsx)(il,{}):(0,I.jsx)(`img`,{onLoad:()=>o(`loaded`),onError:()=>{if(r>=t){o(`failed`);return}o(`backoff`);let e=Math.min(1e3*2**r,16e3);s.current=setTimeout(()=>{i(e=>e+1),o(`fetching`),s.current=void 0},e)},...n})}function OP(e){let{contentType:t,data:n,url:r,title:i}=e.value??{},a=gk(r);if(!a&&!n)return null;let o=a??`data:${t};base64,${n}`;return(0,I.jsxs)(`div`,{"data-testid":`attachment-display`,children:[t?.startsWith(`image/`)&&(0,I.jsx)(DP,{"data-testid":`attachment-image`,style:{maxWidth:e.maxWidth},src:o,alt:i}),t?.startsWith(`video/`)&&(0,I.jsx)(`video`,{"data-testid":`attachment-video`,style:{maxWidth:e.maxWidth},controls:!0,children:(0,I.jsx)(`source`,{type:t,src:o})}),(t?.startsWith(`text/`)||t===`application/json`||t===`application/pdf`)&&(0,I.jsx)(`div`,{"data-testid":`attachment-iframe`,style:{maxWidth:e.maxWidth,minHeight:400},children:(0,I.jsx)(`iframe`,{title:`Attachment`,width:`100%`,height:`400`,src:o+`#navpanes=0`,allowFullScreen:!0,frameBorder:0,seamless:!0})}),t===ZE.CDA_XML&&(0,I.jsx)(EP,{url:o}),(0,I.jsx)(`div`,{"data-testid":`download-link`,style:{padding:`2px 16px 16px 16px`},children:(0,I.jsx)(pu,{href:r,"data-testid":`attachment-details`,target:`_blank`,rel:`noopener noreferrer`,download:kP(i),children:i||`Download`})})]})}function kP(e){return e?.includes(`.`)?e:void 0}var AP={root:`_root_1bd5a_1`,compact:`_compact_1bd5a_19`};function jP(e){let{children:t,compact:n}=e;return(0,I.jsx)(`dl`,{className:it(AP.root,{[AP.compact]:n}),children:t})}function MP(e){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`dt`,{children:e.term}),(0,I.jsx)(`dd`,{children:e.children})]})}function NP(e){let t=e.values?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(OP,{value:t,maxWidth:e.maxWidth})},`attatchment-`+n)),n;if(e.includeDescriptionListEntry){if(e.property===void 0)throw Error(`props.property is required when includeDescriptionListEntry is true`);if(!CC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);n=(0,I.jsx)(MP,{term:Fw(e.path.split(`.`).pop()),children:t})}else n=(0,I.jsx)(I.Fragment,{children:t});return n}function PP(e){let t=Q(),n=(0,b.useRef)(null);function r(e){aM(e),n.current?.click()}function i(e){aM(e);let t=e.target.files;t&&Array.from(t).forEach(a)}function a(n){n&&n.name&&(e.onUploadStart&&e.onUploadStart(),t.createAttachment({data:n,contentType:n.type||`application/octet-stream`,filename:n.name,securityContext:e.securityContext,onProgress:e.onUploadProgress}).then(t=>e.onUpload(t)).catch(t=>{e.onUploadError&&e.onUploadError(Zx(t))}))}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{disabled:e.disabled,type:`file`,"data-testid":`upload-file-input`,style:{display:`none`},ref:n,onChange:e=>i(e)}),e.children({onClick:r,disabled:e.disabled})]})}function FP(e){let[t,n]=(0,b.useState)(e.defaultValue??[]);function r(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(`table`,{style:{width:`100%`},children:[(0,I.jsxs)(`colgroup`,{children:[(0,I.jsx)(`col`,{width:`97%`}),(0,I.jsx)(`col`,{width:`3%`})]}),(0,I.jsxs)(`tbody`,{children:[t.map((n,i)=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(OP,{value:n,maxWidth:200})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(vl,{disabled:e.disabled,title:`Remove`,variant:`subtle`,size:`sm`,color:`gray`,onClick:e=>{aM(e);let n=t.slice();n.splice(i,1),r(n)},children:(0,I.jsx)(JA,{})})})]},`${i}-${t.length}`)),(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{}),(0,I.jsx)(`td`,{children:(0,I.jsx)(PP,{disabled:e.disabled,onUpload:e=>{r([...t,e])},children:e=>(0,I.jsx)(vl,{...e,title:`Add`,variant:`subtle`,size:`sm`,color:e.disabled?`gray`:`green`,children:(0,I.jsx)(XA,{})})})})]})]})]})}function IP(e){let[t,n]=(0,b.useState)(e.defaultValue);function r(t){n(t),e.onChange&&e.onChange(t)}return t?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(OP,{value:t,maxWidth:200}),(0,I.jsx)(U,{disabled:e.disabled,onClick:e=>{aM(e),r(void 0)},children:`Remove`})]}):(0,I.jsx)(PP,{disabled:e.disabled,securityContext:e.securityContext,onUpload:r,children:e=>(0,I.jsx)(U,{...e,children:`Upload...`})})}var LP={root:`_root_1vii2_1`};function RP(e){let{children:t,...n}=e;return(0,I.jsx)(mp,{className:LP.root,...n,children:t})}var zP={paper:`_paper_1igaj_1`,fill:`_fill_1igaj_20`};function BP(e){let{width:t,fill:n,className:r,children:i,...a}=e,o=t?{maxWidth:t}:void 0;return(0,I.jsx)(Xc,{className:it(zP.paper,n&&zP.fill,r),style:o,shadow:`sm`,radius:`sm`,withBorder:!0,...a,children:i})}function VP(e){let{children:t,...n}=e;return(0,I.jsx)(RP,{children:(0,I.jsx)(BP,{...n,children:t})})}function HP(e){return(0,I.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 180 180`,style:{width:e.size,height:e.size},children:[(0,I.jsx)(`title`,{children:`Medplum Logo`}),(0,I.jsx)(`path`,{fill:e.fill??`#9c36b5`,d:`M84 56c-3-15-15-24-23-28l5-10c8 2 14 8 20 14 0-12 1-16 5-21 8-9 13-9 41-9 0 7 1 18-3 24-7 9-16 7-41 8 5 8 7 14 8 22 36-24 74-7 74 39 0 42-40 83-80 83s-80-41-80-83c0-46 38-63 74-39Zm-3 43H65c-4 0-7 3-7 7v4c0 4 3 7 7 7h16v16c0 4 3 7 7 7h4c4 0 7-3 7-7v-16h16c4 0 7-3 7-7v-4c0-4-3-7-7-7H99V83c0-4-3-7-7-7h-4c-4 0-7 3-7 7z`})]})}function UP(e,t){return e?.issue?.filter(e=>KP(e.expression?.[0],t))?.map(e=>e.details?.text)?.join(`
|
|
197
|
+
}`.replaceAll(/\s+/g,` `)}function uP(e){let t=[];return e.data.Patients1&&t.push(...e.data.Patients1),e.data.Patients2&&t.push(...e.data.Patients2),e.data.ServiceRequestList&&t.push(...e.data.ServiceRequestList),dP(t)}function dP(e){let t=new Set,n=[];for(let r of e)r.id&&!t.has(r.id)&&(t.add(r.id),n.push(r));return n}function fP(e,t){let n=e.filter(e=>!!e.id).map(e=>({id:e.id,label:e.name?cw(e.name[0]):e.id,description:e.birthDate,leftSection:(0,I.jsx)(_M,{value:e,radius:`xl`,size:24}),onClick:()=>t(`/Patient/${e.id}`)}));return n.length>0?[{group:`Patients`,actions:n}]:[]}function pP(e,t,n){let r=[],i=t.map(e=>({id:`resource-type-${e.code}`,label:e.display??e.code??``,description:`Resource Type`,onClick:()=>n(`/${e.code}`)}));i.length>0&&r.push({group:`Resource Types`,actions:i});let a=[],o=[];for(let t of e)t.resourceType===`Patient`&&t.id?a.push({id:t.id,label:t.name?cw(t.name[0]):t.id,description:t.birthDate,leftSection:(0,I.jsx)(_M,{value:t,radius:`xl`,size:24}),onClick:()=>n(`/Patient/${t.id}`)}):t.resourceType===`ServiceRequest`&&t.id&&o.push({id:t.id,label:t.id,description:t.subject?.display,onClick:()=>n(`/ServiceRequest/${t.id}`)});return a.length>0&&r.push({group:`Patients`,actions:a}),o.length>0&&r.push({group:`Service Requests`,actions:o}),r}function mP(e){let t=Q(),n=uk(),r=dk(),i=_P(e.pathname,e.searchParams,e.menus),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(!1),l=t.getProject()?.name??t.getActiveLogin()?.project.display;function u(t,r){t.stopPropagation(),t.preventDefault(),n(r),window.innerWidth<768&&e.closeNavbar()}function d(e){e&&n(`/${e}`)}let f=e.opened??!0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(zu.Navbar,{id:`navbar`,className:iP.navbar,children:[e.logo&&(0,I.jsx)(zu.Section,{px:`xs`,pt:`xs`,pb:`4px`,children:(0,I.jsx)(qc,{className:iP.logoButton,onClick:e.navbarToggle,"aria-expanded":f,"aria-controls":`navbar`,"aria-label":`Medplum Logo`,children:e.logo})}),(0,I.jsx)(Hc,{px:`xs`,pb:`xs`,pt:`sm`,h:`100%`,children:(0,I.jsxs)(zu.Section,{grow:!0,children:[e.spotlightEnabled&&(0,I.jsx)(z,{mb:2,children:(0,I.jsx)(Kv,{label:`Search`,position:`right`,transitionProps:{duration:0},disabled:f,children:(0,I.jsxs)(qc,{className:iP.link,onClick:()=>mN.open(),"aria-label":`Search`,children:[(0,I.jsx)(Rj,{size:`1.2rem`}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":f||void 0,children:`Search`})]})})}),e.spotlightEnabled&&(0,I.jsx)(cP,{patientsOnly:e.patientsOnly}),!e.resourceTypeSearchDisabled&&(0,I.jsx)(zu.Section,{mb:`sm`,children:(0,I.jsx)(rP,{name:`resourceType`,placeholder:`Resource Type`,maxValues:0,onChange:e=>d(e)},window.location.pathname)}),e.menus?.map((e,t)=>(0,I.jsxs)(b.Fragment,{children:[e.title&&(0,I.jsx)(H,{className:iP.menuTitle,"data-opened":f||void 0,children:e.title}),(0,I.jsx)(G,{gap:`2`,children:e.links?.map(e=>e.notificationCount?(0,I.jsx)(gP,{to:e.href,active:e.href===i?.href,onClick:t=>u(t,e.href),icon:e.icon,label:e.label??``,opened:f,alert:e.alert,notificationCount:e.notificationCount,onDismiss:e.onDismiss},e.href):(0,I.jsx)(hP,{to:e.href,active:e.href===i?.href,onClick:t=>u(t,e.href),icon:e.icon,label:e.label??``,opened:f,alert:e.alert,count:e.count,onDismiss:e.onDismiss},e.href))})]},`menu-${e.title??t}`)),e.displayAddBookmark&&(0,I.jsx)(Kv,{label:`Add Bookmark`,position:`right`,transitionProps:{duration:0},disabled:f,children:(0,I.jsxs)(qc,{className:`${iP.link} ${iP.addBookmarkLink}`,onClick:()=>c(!0),children:[(0,I.jsx)(YA,{}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":f||void 0,children:`Add Bookmark`})]})})]})}),e.userMenuEnabled&&(0,I.jsxs)(zu.Section,{px:`xs`,py:`xs`,children:[(0,I.jsx)(Kv,{label:f?`Close Sidebar`:`Open Sidebar`,position:`right`,transitionProps:{duration:0},children:(0,I.jsx)(qc,{className:iP.toggleButton,"data-opened":f||void 0,"aria-label":f?`Close Sidebar`:`Open Sidebar`,onClick:e.navbarToggle,"aria-expanded":f,"aria-controls":`navbar`,children:(0,I.jsx)(hj,{})})}),(0,I.jsx)(bp,{my:`xs`,className:iP.divider}),(0,I.jsxs)(W,{width:260,shadow:`md`,radius:`md`,position:`top-start`,transitionProps:{transition:`fade-up`},opened:a,onClose:()=>o(!1),children:[(0,I.jsx)(W.Target,{children:(0,I.jsxs)(qc,{className:`${iP.link} ${iP.userLink}`,pl:`7`,"aria-label":`User menu`,"data-active":a||void 0,onClick:()=>o(e=>!e),bd:`1px 0 0 0 solid var(--mantine-color-gray-200)`,children:[(0,I.jsx)(_M,{value:r,radius:`xl`,size:24}),(0,I.jsxs)(`span`,{className:iP.userLinkLabel,"data-opened":f||void 0,children:[(0,I.jsx)(H,{span:!0,inherit:!0,truncate:!0,children:cw(r?.name?.[0])}),l&&(0,I.jsx)(H,{span:!0,inherit:!0,fz:`xs`,c:`dimmed`,truncate:!0,title:l,children:l})]})]})}),(0,I.jsx)(W.Dropdown,{className:CM.dropdown,children:(0,I.jsx)(jM,{version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle})})]})]})]}),e.pathname&&e.searchParams&&(0,I.jsx)(KN,{pathname:e.pathname,searchParams:e.searchParams,visible:s,onOk:()=>c(!1),onCancel:()=>c(!1)})]})}function hP(e){let{to:t,icon:n,label:r,onClick:i,active:a,count:o,alert:s,opened:c,onDismiss:l}=e,u=o!==void 0&&o>0,d=n??(0,I.jsx)(FA,{}),f=u&&s&&!c;function p(e){e.preventDefault(),e.stopPropagation(),l?.()}return(0,I.jsx)(Kv,{label:r,position:`right`,transitionProps:{duration:0},disabled:c,children:(0,I.jsxs)(dM,{to:t,onClick:i,className:iP.link,"data-active":a||void 0,children:[(0,I.jsxs)(`span`,{className:iP.iconWrapper,children:[d,f&&(0,I.jsx)(`span`,{className:iP.alertDot})]}),(0,I.jsx)(`span`,{className:iP.linkLabel,"data-opened":c||void 0,children:r}),u&&(0,I.jsx)(`span`,{className:iP.linkCount,"data-opened":c||void 0,"data-alert":s||void 0,children:o.toLocaleString()}),l&&c&&(0,I.jsx)(Kv,{label:`Dismiss`,openDelay:500,children:(0,I.jsx)(qc,{"aria-label":`Dismiss`,className:iP.dismissButton,onClick:p,children:(0,I.jsx)($j,{size:14})})})]})})}function gP(e){let t=yk(e.notificationCount);return(0,I.jsx)(hP,{to:e.to,active:e.active,onClick:e.onClick,icon:e.icon,label:e.label,opened:e.opened,alert:e.alert,count:t,onDismiss:e.onDismiss})}function _P(e,t,n){if(!e||!t||!n)return;let r,i=0;for(let a of n)if(a.links)for(let n of a.links){let a=vP(e,t,n.href);a>i&&(i=a,r=n)}return r}function vP(e,t,n){let r=new URL(n,`https://example.com`);if(e!==r.pathname)return 0;let i=[`_count`,`_offset`];for(let[e,n]of r.searchParams.entries())if(!i.includes(e)&&t.get(e)!==n)return 0;let a=1;for(let[e,n]of t.entries())i.includes(e)||r.searchParams.get(e)===n&&a++;return a}var yP=250,bP=59,xP=60,SP=36;function CP(e){let[t,n]=(0,b.useState)(localStorage.navbarOpen===`true`),[r]=(0,b.useState)(e.layoutVersion??localStorage.appShellLayoutVersion??`v1`),i=Q(),a=dk(),[o,s]=(0,b.useState)(()=>{try{let e=localStorage.appShellDismissedAnnouncements;return new Set(e?JSON.parse(e):[])}catch{return new Set}}),c=e.announcements?.filter(e=>!e.id||!o.has(e.id)),l=c?.length?c.length*SP:0;function u(e){localStorage.navbarOpen=e.toString(),n(e)}function d(e){e.id&&s(t=>{let n=new Set(t);return n.add(e.id),localStorage.appShellDismissedAnnouncements=JSON.stringify([...n]),n}),e.onDismiss?.(e)}function f(){u(!1)}function p(){u(!t)}if(i.isLoading())return(0,I.jsx)(nM,{});let m,h,g,_;return r===`v2`?(m={height:l},h={width:t?yP:bP,breakpoint:0,collapsed:{desktop:!a,mobile:!a}},g=c?.length?(0,I.jsx)(zu.Header,{style:{zIndex:101},children:(0,I.jsx)(iM,{announcements:c,onDismiss:d})}):void 0,_=a?(0,I.jsx)(mP,{logo:e.logo,pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,navbarToggle:p,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:!0,opened:t,spotlightEnabled:!0,patientsOnly:e.spotlightPatientsOnly,userMenuEnabled:!0,version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle}):void 0):(m={height:xP+l},h={width:yP,breakpoint:`sm`,collapsed:{desktop:!a||!t,mobile:!a||!t}},g=a&&(0,I.jsx)(JM,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarOpen:t,navbarToggle:p,notifications:e.notifications,announcements:c,onDismissAnnouncement:d}),_=a&&t?(0,I.jsx)(mP,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,navbarToggle:p,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled,patientsOnly:e.spotlightPatientsOnly}):void 0),(0,I.jsxs)(zu,{header:m,navbar:h,padding:0,children:[g,_,(0,I.jsx)(zu.Main,{className:rM.main,children:(0,I.jsx)(tM,{children:(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(nM,{}),children:e.children})})})]})}var wP=`https://ccda.medplum.com`,TP=`https://ccda-validator.medplum.com/`;function EP(e){let{url:t}=e,[n,r]=(0,b.useState)(!1),i=(0,b.useRef)(null),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{t&&n&&i.current&&(lM(i.current,{command:`loadCcdaXml`,value:t}).catch(console.error),r(!1))},[t,n]),t?(0,I.jsxs)(`div`,{"data-testid":`ccda-iframe`,style:{maxWidth:e.maxWidth},children:[(0,I.jsx)(`div`,{style:{minHeight:400},children:(0,I.jsx)(`iframe`,{title:`C-CDA Viewer`,width:`100%`,height:`400`,ref:i,src:wP,allowFullScreen:!0,frameBorder:0,seamless:!0,onLoad:()=>r(!0)})}),(0,I.jsxs)(`div`,{style:{marginTop:`10px`,marginBottom:`10px`,display:`flex`,alignItems:`center`},children:[(0,I.jsx)(U,{type:`button`,onClick:async()=>{if(t)try{c(!0);let e=await(await fetch(t)).text(),n=new FormData;n.append(`ccdaFile`,new Blob([e],{type:`text/xml`}),`ccda.xml`);let r=await fetch(`${TP}referenceccdaservice/?validationObjective=C-CDA_IG_Plus_Vocab&referenceFileName=No%20scenario%20File&curesUpdate=true&severityLevel=WARNING`,{method:`POST`,body:n,credentials:`omit`,redirect:`manual`});if(!r.ok)throw Error(`Validation failed: ${r.status} ${r.statusText}`);o(await r.json())}catch(e){o(void 0),console.error(`CCDA validation error:`,e)}finally{c(!1)}},disabled:s,children:s?`Validating...`:`Validate`}),a&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{style:{marginLeft:`15px`},children:[(0,I.jsx)(`strong`,{children:`Validation Results:`}),` `,a?a.resultsMetaData.resultMetaData.filter(e=>e?.type.includes(`Error`)).reduce((e,t)=>e+(t.count||0),0):0,` errors found`]}),(0,I.jsx)(U,{type:`button`,onClick:()=>{a&&uM(JSON.stringify(a,null,2),`ccda-validation-results`)},color:`green`,style:{marginLeft:`auto`},children:`Download Full Results`})]})]})]}):null}function DP(e){let{maxRetries:t=5,...n}=e,[r,i]=(0,b.useState)(0),[a,o]=(0,b.useState)(`fetching`),s=(0,b.useRef)(void 0);return(0,b.useEffect)(()=>()=>{s.current!==void 0&&clearTimeout(s.current)},[]),a===`failed`?(0,I.jsx)(`div`,{className:`image-placeholder`,children:`Image unavailable`}):a===`backoff`?(0,I.jsx)(il,{}):(0,I.jsx)(`img`,{onLoad:()=>o(`loaded`),onError:()=>{if(r>=t){o(`failed`);return}o(`backoff`);let e=Math.min(1e3*2**r,16e3);s.current=setTimeout(()=>{i(e=>e+1),o(`fetching`),s.current=void 0},e)},...n})}function OP(e){let{contentType:t,data:n,url:r,title:i}=e.value??{},a=gk(r);if(!a&&!n)return null;let o=a??`data:${t};base64,${n}`;return(0,I.jsxs)(`div`,{"data-testid":`attachment-display`,children:[t?.startsWith(`image/`)&&(0,I.jsx)(DP,{"data-testid":`attachment-image`,style:{maxWidth:e.maxWidth},src:o,alt:i}),t?.startsWith(`video/`)&&(0,I.jsx)(`video`,{"data-testid":`attachment-video`,style:{maxWidth:e.maxWidth},controls:!0,children:(0,I.jsx)(`source`,{type:t,src:o})}),(t?.startsWith(`text/`)||t===`application/json`||t===`application/pdf`)&&(0,I.jsx)(`div`,{"data-testid":`attachment-iframe`,style:{maxWidth:e.maxWidth,minHeight:400},children:(0,I.jsx)(`iframe`,{title:`Attachment`,width:`100%`,height:`400`,src:o+`#navpanes=0`,allowFullScreen:!0,frameBorder:0,seamless:!0})}),t===ZE.CDA_XML&&(0,I.jsx)(EP,{url:o}),(0,I.jsx)(`div`,{"data-testid":`download-link`,style:{padding:`2px 16px 16px 16px`},children:(0,I.jsx)(pu,{href:r,"data-testid":`attachment-details`,target:`_blank`,rel:`noopener noreferrer`,download:kP(i),children:i||`Download`})})]})}function kP(e){return e?.includes(`.`)?e:void 0}var AP={root:`_root_1bd5a_1`,compact:`_compact_1bd5a_19`};function jP(e){let{children:t,compact:n}=e;return(0,I.jsx)(`dl`,{className:it(AP.root,{[AP.compact]:n}),children:t})}function MP(e){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`dt`,{children:e.term}),(0,I.jsx)(`dd`,{children:e.children})]})}function NP(e){let t=e.values?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(OP,{value:t,maxWidth:e.maxWidth})},`attatchment-`+n)),n;if(e.includeDescriptionListEntry){if(e.property===void 0)throw Error(`props.property is required when includeDescriptionListEntry is true`);if(!CC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);n=(0,I.jsx)(MP,{term:Fw(e.path.split(`.`).pop()),children:t})}else n=(0,I.jsx)(I.Fragment,{children:t});return n}function PP(e){let t=Q(),n=(0,b.useRef)(null);function r(e){aM(e),n.current?.click()}function i(e){aM(e);let t=e.target.files;t&&Array.from(t).forEach(a)}function a(n){n&&n.name&&(e.onUploadStart&&e.onUploadStart(),t.createAttachment({data:n,contentType:n.type||`application/octet-stream`,filename:n.name,securityContext:e.securityContext,onProgress:e.onUploadProgress}).then(t=>e.onUpload(t)).catch(t=>{e.onUploadError&&e.onUploadError(Zx(t))}))}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{disabled:e.disabled,type:`file`,"data-testid":`upload-file-input`,style:{display:`none`},ref:n,onChange:e=>i(e)}),e.children({onClick:r,disabled:e.disabled})]})}function FP(e){let[t,n]=(0,b.useState)(e.defaultValue??[]);function r(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(`table`,{style:{width:`100%`},children:[(0,I.jsxs)(`colgroup`,{children:[(0,I.jsx)(`col`,{width:`97%`}),(0,I.jsx)(`col`,{width:`3%`})]}),(0,I.jsxs)(`tbody`,{children:[t.map((n,i)=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(OP,{value:n,maxWidth:200})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(vl,{disabled:e.disabled,title:`Remove`,variant:`subtle`,size:`sm`,color:`gray`,onClick:e=>{aM(e);let n=t.slice();n.splice(i,1),r(n)},children:(0,I.jsx)(JA,{})})})]},`${i}-${t.length}`)),(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{}),(0,I.jsx)(`td`,{children:(0,I.jsx)(PP,{disabled:e.disabled,onUpload:e=>{r([...t,e])},children:e=>(0,I.jsx)(vl,{...e,title:`Add`,variant:`subtle`,size:`sm`,color:e.disabled?`gray`:`green`,children:(0,I.jsx)(XA,{})})})})]})]})]})}function IP(e){let[t,n]=(0,b.useState)(e.defaultValue);function r(t){n(t),e.onChange&&e.onChange(t)}return t?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(OP,{value:t,maxWidth:200}),(0,I.jsx)(U,{disabled:e.disabled,onClick:e=>{aM(e),r(void 0)},children:`Remove`})]}):(0,I.jsx)(PP,{disabled:e.disabled,securityContext:e.securityContext,onUpload:r,children:e=>(0,I.jsx)(U,{...e,children:`Upload...`})})}var LP={root:`_root_1vii2_1`};function RP(e){let{children:t,...n}=e;return(0,I.jsx)(mp,{className:LP.root,...n,children:t})}var zP={paper:`_paper_1igaj_1`,fill:`_fill_1igaj_20`};function BP(e){let{width:t,fill:n,className:r,children:i,...a}=e,o=t?{maxWidth:t}:void 0;return(0,I.jsx)(Xc,{className:it(zP.paper,n&&zP.fill,r),style:o,shadow:`sm`,radius:`sm`,withBorder:!0,...a,children:i})}function VP(e){let{children:t,...n}=e;return(0,I.jsx)(RP,{children:(0,I.jsx)(BP,{...n,children:t})})}function HP(e){return(0,I.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 180 180`,style:{width:e.size,height:e.size},children:[(0,I.jsx)(`title`,{children:`Medplum Logo`}),(0,I.jsx)(`path`,{fill:e.fill??`#9c36b5`,d:`M84 56c-3-15-15-24-23-28l5-10c8 2 14 8 20 14 0-12 1-16 5-21 8-9 13-9 41-9 0 7 1 18-3 24-7 9-16 7-41 8 5 8 7 14 8 22 36-24 74-7 74 39 0 42-40 83-80 83s-80-41-80-83c0-46 38-63 74-39Zm-3 43H65c-4 0-7 3-7 7v4c0 4 3 7 7 7h16v16c0 4 3 7 7 7h4c4 0 7-3 7-7v-16h16c4 0 7-3 7-7v-4c0-4-3-7-7-7H99V83c0-4-3-7-7-7h-4c-4 0-7 3-7 7z`})]})}function UP(e,t){return e?.issue?.filter(e=>KP(e.expression?.[0],t))?.map(e=>e.details?.text)?.join(`
|
|
198
198
|
`)}function WP(e,t){return e?.issue?.filter(e=>KP(e.expression?.[0],t))}var GP=/\[\d+\]/;function KP(e,t){if((typeof e==`string`&&GP.test(e))!==(typeof t==`string`&&GP.test(t))&&(e=e?.replace(GP,``),t=t?.replace(GP,``)),e===t)return!0;if(!e||!t)return!1;let n=e.indexOf(`.`);if(n>=0&&e.substring(n+1)===t)return!0;let r=t.indexOf(`.`);return r>=0&&t.substring(r+1)===e}function qP(e){let{onSuccess:t}=e,n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1);return(0,I.jsx)(VP,{width:450,children:(0,I.jsxs)(WN,{onSubmit:e=>{i(void 0),n.post(`auth/changepassword`,e).then(()=>{o(!0),t?.()}).catch(e=>i(Zx(e)))},children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{children:`Change password`})]}),!a&&(0,I.jsxs)(G,{gap:`xl`,mt:`xl`,children:[(0,I.jsx)(ev,{name:`oldPassword`,label:`Old password`,required:!0,autoFocus:!0,error:UP(r,`oldPassword`)}),(0,I.jsx)(ev,{name:`newPassword`,label:`New password`,required:!0,error:UP(r,`newPassword`)}),(0,I.jsx)(ev,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:UP(r,`confirmPassword`)}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,wrap:`nowrap`,children:(0,I.jsx)(U,{type:`submit`,children:`Change password`})})]}),a&&(0,I.jsx)(`div`,{"data-testid":`success`,children:`Password changed successfully`})]})})}var JP=/^patient\/Condition\.(?:\*|c?r?u?d?s?)$/,YP=`?category=http://terminology.hl7.org/CodeSystem/condition-category|encounter-diagnosis`,XP=`?category=http://terminology.hl7.org/CodeSystem/condition-category|problem-list-item`,ZP=`?category=http://hl7.org/fhir/us/core/CodeSystem/condition-category|health-concern`,QP=/^patient\/Observation\.(?:\*|c?r?u?d?s?)$/,$P=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category|clinical-test`,eF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|laboratory`,tF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|social-history`,nF=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-category|sdoh`,rF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|survey`,iF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|vital-signs`;function aF(e){let t=Q();return(0,I.jsx)(WN,{onSubmit:n=>{t.post(`auth/scope`,{login:e.login,scope:Object.keys(n).join(` `)}).then(e.handleAuthResponse).catch(console.log)},children:(0,I.jsxs)(G,{children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[e.logo??(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:e.title??`Choose scope`}),e.children]}),(0,I.jsx)(G,{children:(e.scope??`openid`).split(` `).map(e=>{let t;return JP.test(e)?t=[e+YP,e+XP,e+ZP]:QP.test(e)&&(t=[e+$P,e+eF,e+tF,e+nF,e+rF,e+iF]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Bd,{id:e,name:e,label:e,defaultChecked:!0},e),t?.map(e=>(0,I.jsx)(Bd,{id:e,name:e,label:e},e))]},e+`_group`)})}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(GN,{fullWidth:!0,children:e.submitLabel??`Set Scope`})})]})})}function oF(e){let[t,n]=(0,b.useState)();return(0,I.jsxs)(WN,{onSubmit:t=>{n(void 0),e.onSubmit(t)?.catch(e=>n(Y(e)))},children:[(0,I.jsxs)(hd,{style:{flexDirection:`column`},children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:e.title}),!e.qrCodeUrl&&e.description&&(0,I.jsx)(H,{c:`dimmed`,mb:`lg`,mt:`-lg`,ta:`center`,children:e.description})]}),t&&(0,I.jsx)(ou,{icon:(0,I.jsx)(kA,{size:16}),title:`Error`,color:`red`,mb:`lg`,children:t}),e.qrCodeUrl&&(0,I.jsx)(hd,{children:(0,I.jsxs)(G,{mb:`xl`,justify:`center`,children:[e.description&&(0,I.jsx)(H,{c:`dimmed`,mb:`md`,mt:`-lg`,ta:`center`,children:e.description}),(0,I.jsx)(Kp,{src:e.qrCodeUrl,alt:`Multi Factor Auth QR Code`,w:`60%`,mx:`auto`,radius:`md`,p:`xs`,bg:`var(--mantine-color-white)`,style:{border:`1px solid light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-4))`}})]})}),(0,I.jsx)(G,{gap:`sm`,children:(0,I.jsx)(yb,{name:`token`,label:`MFA code`,autoComplete:`one-time-code`,required:!0,autoFocus:!0})}),(0,I.jsxs)(G,{gap:`xs`,pt:`md`,children:[(0,I.jsx)(GN,{fullWidth:!0,children:e.buttonText}),e.footer]})]})}function sF(e){let{allowedMethods:t,qrCodeUrl:n,onEnrollEmail:r,onEnrollTotp:i}=e,[a,o]=(0,b.useState)(),s=t.includes(`email`),c=t.includes(`totp`);return s&&c&&!a?(0,I.jsxs)(hd,{style:{flexDirection:`column`},children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,ta:`center`,children:`Set up multi-factor authentication`}),(0,I.jsxs)(G,{w:`100%`,children:[(0,I.jsx)(H,{c:`dimmed`,ta:`center`,children:`Choose how you want to verify your identity when you sign in.`}),(0,I.jsx)(U,{fullWidth:!0,onClick:()=>o(`totp`),children:`Use an authenticator app (recommended)`}),(0,I.jsx)(U,{fullWidth:!0,variant:`default`,onClick:r,children:`Continue with email-based MFA`})]})]}):s&&!c?(0,I.jsxs)(hd,{style:{flexDirection:`column`},children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Set up email-based MFA`}),(0,I.jsxs)(G,{w:`100%`,children:[(0,I.jsx)(H,{c:`dimmed`,ta:`center`,children:`When you sign in, we'll email you a verification code to confirm your identity.`}),(0,I.jsx)(U,{fullWidth:!0,onClick:r,children:`Enable email-based MFA`})]})]}):(0,I.jsx)(oF,{title:e.totpTitle,description:e.totpDescription,buttonText:e.totpButtonText??`Enroll`,qrCodeUrl:n,onSubmit:e=>i(e.token)})}function cF(e){let{methods:t,email:n,onRequestEmailCode:r,onSubmit:i}=e,[a,o]=(0,b.useState)(!!e.initialEmailMode),s=()=>{Promise.resolve(r()).then(()=>o(!0)).catch(e=>J({color:`red`,message:Y(e)}))},c;return a?c=(0,I.jsx)(pu,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Resend code`}):t.includes(`email`)&&(c=(0,I.jsx)(pu,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Get a code by email instead`})),(0,I.jsx)(oF,{title:a?`Enter verification code`:`Enter MFA code`,description:a?(0,I.jsxs)(I.Fragment,{children:[`Enter the 6-digit code we emailed`,n?` to `:``,n&&(0,I.jsx)(`strong`,{children:n})]}):`Enter the code from your authenticator app.`,buttonText:e.buttonText??`Submit code`,onSubmit:e=>i(e.token),footer:c})}function lF(e){let{outcome:t,issues:n,...r}=e,i=t?.issue||n;return!i||i.length===0?null:(0,I.jsx)(ou,{icon:(0,I.jsx)(kA,{size:16}),color:`red`,...r,children:i.map(e=>(0,I.jsx)(`div`,{"data-testid":`text-field-error`,children:$x(e)},e.details?.text))})}function uF(e){let t=Q(),[n,r]=(0,b.useState)(),i=WP(n,void 0);return(0,I.jsxs)(WN,{onSubmit:async n=>{try{e.handleAuthResponse(await t.startNewProject({login:e.login,projectName:n.projectName}))}catch(e){r(Zx(e))}},children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Create a new project`})]}),(0,I.jsx)(lF,{issues:i,mb:`lg`}),(0,I.jsx)(G,{gap:`sm`,children:(0,I.jsx)(yb,{name:`projectName`,label:`Project Name`,placeholder:`My Project`,required:!0,autoFocus:!0,error:UP(n,`projectName`)})}),(0,I.jsxs)(G,{gap:`xs`,mt:`md`,children:[(0,I.jsx)(GN,{fullWidth:!0,children:`Create Project`}),(0,I.jsxs)(H,{c:`dimmed`,size:`xs`,pt:`lg`,ta:`center`,children:[`By clicking "Create Project" you agree to the Medplum`,` `,(0,I.jsx)(pu,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(pu,{href:`https://www.medplum.com/terms`,children:`Terms\xA0of\xA0Service`}),`.`]})]})]})}function dF(e,t){let n=document.getElementsByTagName(`head`)[0],r=document.createElement(`script`);r.async=!0,r.src=e,r.onload=t??null,n.appendChild(r)}function fF(e){let{googleClientId:t,handleGoogleCredential:n}=e,r=(0,b.useRef)(null),[i,a]=(0,b.useState)(typeof google<`u`),o=(0,b.useRef)(!1),s=(0,b.useRef)(!1);return(0,b.useEffect)(()=>{if(typeof google>`u`){dF(`https://accounts.google.com/gsi/client`,()=>a(!0));return}o.current||=(google.accounts.id.initialize({client_id:t,callback:n}),!0),r.current&&!s.current&&(google.accounts.id.renderButton(r.current,{type:`standard`,logo_alignment:`center`,width:r.current.clientWidth}),s.current=!0)},[t,i,n]),t?(0,I.jsx)(z,{ref:r,w:`100%`,h:40,display:`flex`,style:{justifyContent:`center`}}):null}function pF(e){if(e)return e;let t=LE.getOrigin();if(t&&[].includes(t))return`__GOOGLE_CLIENT_ID__`}function mF(e){typeof grecaptcha>`u`&&dF(`https://www.google.com/recaptcha/api.js?render=`+e)}function hF(e){return new Promise((t,n)=>{grecaptcha.ready(async()=>{try{t(await grecaptcha.execute(e,{action:`submit`}))}catch(e){n(e)}})})}function gF(e){let t=pF(e.googleClientId),n=e.recaptchaSiteKey,r=Q(),[i,a]=(0,b.useState)(),o=WP(i,void 0);return(0,b.useEffect)(()=>{n&&mF(n)},[n]),(0,I.jsxs)(WN,{onSubmit:async t=>{a(void 0);try{let i=``;n&&(i=await hF(n)),e.handleAuthResponse(await r.startNewUser({projectId:e.projectId,clientId:e.clientId,firstName:t.firstName,lastName:t.lastName,email:t.email,password:t.password,remember:t.remember===`true`,recaptchaSiteKey:n,recaptchaToken:i}))}catch(e){a(Zx(e))}},children:[(0,I.jsx)(ru,{direction:`column`,align:`center`,justify:`center`,children:e.children}),(0,I.jsx)(lF,{issues:o,mb:`lg`}),t&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(fF,{googleClientId:t,handleGoogleCredential:async t=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:t.clientId,googleCredential:t.credential,projectId:e.projectId,createUser:!0}))}catch(e){a(Zx(e))}}})}),(0,I.jsx)(bp,{label:`or`,labelPosition:`center`,my:`lg`})]}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(yb,{name:`firstName`,type:`text`,label:`First name`,placeholder:`First name`,required:!0,autoFocus:!0,error:UP(i,`firstName`)}),(0,I.jsx)(yb,{name:`lastName`,type:`text`,label:`Last name`,placeholder:`Last name`,required:!0,error:UP(i,`lastName`)}),(0,I.jsx)(yb,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,error:UP(i,`email`)}),(0,I.jsx)(ev,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,error:UP(i,`password`)})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(Bd,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(GN,{fullWidth:!0,children:`Register Account`}),(0,I.jsxs)(H,{c:`dimmed`,size:`xs`,pt:`lg`,ta:`center`,children:[`By clicking "Register Account" you agree to the Medplum`,` `,(0,I.jsx)(pu,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(pu,{href:`https://www.medplum.com/terms`,children:`Terms\xA0of\xA0Service`}),`.`]}),(0,I.jsxs)(H,{c:`dimmed`,size:`xs`,ta:`center`,children:[`This site is protected by reCAPTCHA and the Google`,` `,(0,I.jsx)(pu,{href:`https://policies.google.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(pu,{href:`https://policies.google.com/terms`,children:`Terms\xA0of\xA0Service`}),` apply.`]})]})]})}function _F(e){let{type:t,projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,onSuccess:o}=e,s=Q(),[c,l]=(0,b.useState)(e.login),[u,d]=(0,b.useState)(),[f,p]=(0,b.useState)(!1);(0,b.useEffect)(()=>{t===`patient`&&c&&s.startNewPatient({login:c,projectId:n}).then(e=>s.processCode(e.code)).then(()=>o()).catch(e=>d(Zx(e)))},[s,t,n,c,o]);function m(e){e.code&&s.processCode(e.code).then(()=>o()).catch(e=>d(Zx(e))),e.login&&l(e.login),e.emailVerificationRequired&&p(!0)}return(0,I.jsxs)(VP,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:[(0,I.jsx)(lF,{issues:WP(u,void 0),mb:`lg`}),!c&&(0,I.jsx)(gF,{projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,handleAuthResponse:m,children:e.children}),f&&(0,I.jsx)(`div`,{children:`Please check your email for a verification link. Click the link to continue setting up your account.`}),c&&!f&&t===`project`&&(0,I.jsx)(uF,{login:c,handleAuthResponse:m})]})}function vF(e){let{projectId:t,recaptchaSiteKey:n,onSuccess:r,onSignIn:i,onRegister:a}=e,o=Q(),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{n&&mF(n)},[n]),(0,I.jsx)(VP,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:(0,I.jsxs)(WN,{onSubmit:async e=>{c(void 0);try{let i=``;n&&(i=await hF(n)),await o.post(`auth/resetpassword`,{...e,projectId:t,recaptchaToken:i}),u(!0),r?.()}catch(e){c(Zx(e))}},children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Reset your password`})]}),(0,I.jsx)(lF,{issues:WP(s,void 0),mb:`lg`}),!l&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(G,{gap:`sm`,mb:`md`,children:(0,I.jsx)(yb,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:UP(s,`email`)})}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(GN,{fullWidth:!0,children:`Reset Password`}),i&&(0,I.jsx)(H,{size:`sm`,mt:`lg`,c:`dimmed`,style:{textAlign:`center`},"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:(0,I.jsx)(pu,{onClick:i,children:`Back to Sign In`})}),a&&(0,I.jsxs)(H,{size:`sm`,mt:`none`,c:`dimmed`,style:{textAlign:`center`},"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:[`Don't have an account? `,(0,I.jsx)(pu,{onClick:a,children:`Sign Up`})]})]})]}),l&&(0,I.jsx)(H,{c:`dimmed`,size:`sm`,ta:`center`,mt:`md`,children:`If the account exists on our system, a password reset email will be sent.`})]})})}function yF(e){let{id:t,secret:n,onSuccess:r,onSignIn:i}=e,a=Q(),[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(!1);return(0,I.jsxs)(VP,{width:450,children:[(0,I.jsx)(lF,{issues:WP(o,void 0)}),(0,I.jsxs)(WN,{onSubmit:e=>{if(e.password!==e.confirmPassword){s(Ux(`Passwords do not match`,`confirmPassword`));return}s(void 0),a.post(`auth/setpassword`,{id:t,secret:n,password:e.password}).then(()=>{l(!0),r?.()}).catch(e=>s(Zx(e)))},children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{children:`Set password`})]}),!c&&(0,I.jsxs)(G,{children:[(0,I.jsx)(ev,{name:`password`,label:`New password`,required:!0,error:UP(o,`password`)}),(0,I.jsx)(ev,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:UP(o,`confirmPassword`)}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(U,{type:`submit`,children:`Set password`})})]}),c&&(0,I.jsxs)(`div`,{"data-testid":`success`,children:[`Password set. You can now\xA0`,i?(0,I.jsx)(pu,{component:`button`,type:`button`,onClick:i,children:`sign in`}):`sign in`,`.`]})]})]})}function bF(e){let[t,n]=(0,b.useState)();return t?(0,I.jsx)(SF,{email:t,resetEmail:()=>n(void 0),...e}):(0,I.jsx)(xF,{setEmail:n,...e})}function xF(e){let{setEmail:t,onRegister:n,handleAuthResponse:r,children:i,disableEmailAuth:a,...o}=e,s=Q(),c=!e.disableGoogleAuth&&pF(e.googleClientId),[l,u]=(0,b.useState)(),d=WP(l,void 0),f=(0,b.useCallback)(async e=>{if(!e.authorizeUrl)return!1;let t=JSON.stringify({...await s.ensureCodeChallenge(o),domain:e.domain,returnTo:LE.getLocation()}),n=new URL(e.authorizeUrl);return n.searchParams.set(`state`,t),LE.assign(n.toString()),!0},[s,o]),p=(0,b.useCallback)(async e=>{await f(await s.post(`auth/method`,{email:e.email}))||t(e.email)},[s,f,t]),m=(0,b.useCallback)(async e=>{try{let t=await s.startGoogleLogin({...o,googleCredential:e.credential});await f(t)||r(t)}catch(e){u(Zx(e))}},[s,o,f,r]);return(0,I.jsxs)(WN,{onSubmit:p,children:[(0,I.jsx)(ru,{direction:`column`,align:`center`,justify:`center`,children:i}),(0,I.jsx)(lF,{issues:d,mb:`lg`}),c&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(fF,{googleClientId:c,handleGoogleCredential:m})}),!a&&(0,I.jsx)(bp,{label:`or`,labelPosition:`center`,my:`lg`})]}),!a&&(0,I.jsx)(yb,{name:`email`,type:`email`,label:`Email`,mb:`md`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:UP(l,`email`),"data-testid":`auth.email`}),(0,I.jsxs)(G,{gap:`xs`,children:[!a&&(0,I.jsx)(GN,{fullWidth:!0,children:`Continue`}),n&&(0,I.jsxs)(H,{size:`sm`,mt:`lg`,c:`dimmed`,style:{textAlign:`center`},"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:[`Don’t have an account? `,(0,I.jsx)(pu,{onClick:n,children:`Register`})]})]})]})}function SF(e){let{onForgotPassword:t,handleAuthResponse:n,children:r,...i}=e,a=Q(),[o,s]=(0,b.useState)(),c=WP(o,void 0);return(0,I.jsxs)(WN,{onSubmit:(0,b.useCallback)(e=>a.startLogin({...i,password:e.password,remember:e.remember===`on`}).then(n).catch(e=>s(Zx(e))),[a,i,n]),children:[(0,I.jsx)(ru,{direction:`column`,align:`center`,justify:`center`,children:r}),(0,I.jsx)(lF,{issues:c,mb:`lg`}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(yb,{label:`Email`,value:e.email,disabled:!0,rightSectionWidth:36,rightSection:(0,I.jsx)(vl,{variant:`subtle`,color:`gray`,onClick:e.resetEmail,"aria-label":`Change email`,children:(0,I.jsx)(Oj,{size:`1rem`,stroke:1.5})})}),(0,I.jsx)(ev,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,autoFocus:!0,error:UP(o,`password`),"data-testid":`auth.password`})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(Bd,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(GN,{children:`Sign In`}),t&&(0,I.jsx)(H,{size:`sm`,mt:`lg`,c:`dimmed`,style:{textAlign:`center`},"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:(0,I.jsx)(pu,{onClick:t,children:`Reset Password`})})]})]})}function CF(e){let t=Q(),n=cp(),[r,i]=(0,b.useState)(``),[a,o]=(0,b.useState)();function s(e){return!!e?.toLowerCase()?.includes(r.toLowerCase())}function c(e){return s(e.profile?.display)||s(e.project?.display)||s(wF(e))}function l(n){t.post(`auth/profile`,{login:e.login,profile:n}).then(e.handleAuthResponse).catch(e=>o(Zx(e)))}let u=e.memberships.filter(c).slice(0,10).map(e=>(0,I.jsx)(dp.Option,{value:e.id,className:yM.interactive,children:(0,I.jsx)(xM,{membership:e,label:wF(e)})},e.id));return(0,I.jsxs)(G,{gap:`0`,children:[(0,I.jsxs)(ru,{justify:`center`,align:`center`,direction:`column`,wrap:`nowrap`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Choose a Project`})]}),(0,I.jsx)(lF,{outcome:a,mb:`lg`}),(0,I.jsxs)(dp,{store:n,onOptionSubmit:l,children:[(0,I.jsx)(dp.EventsTarget,{children:(0,I.jsx)(yb,{placeholder:`Search`,value:r,mb:`md`,autoFocus:!0,leftSection:(0,I.jsx)(Rj,{size:16}),onChange:e=>{i(e.currentTarget.value),n.updateSelectedOptionIndex()}})}),(0,I.jsx)(`div`,{children:(0,I.jsx)(dp.Options,{style:{marginLeft:`-10px`,marginRight:`-10px`,marginBottom:`-10px`},children:u.length>0?u:(0,I.jsx)(dp.Empty,{children:`Nothing found...`})})})]}),(0,I.jsx)(H,{size:`sm`,ta:`center`,mt:`md`,children:(0,I.jsx)(pu,{component:`button`,type:`button`,onClick:()=>{window.location.href=`/signin?project=new&login=${e.login}`},children:`Create a new project`})})]})}function wF(e){return gC(e,`https://medplum.com/identifier/label`)}function TF(e){let{login:t,chooseScopes:n,chooseScopeFormProps:r,onSuccess:i,onForgotPassword:a,onRegister:o,onCode:s,...c}=e,l=Q(),[u,d]=(0,b.useState)(),f=(0,b.useRef)(!1),[p,m]=(0,b.useState)(!1),[h,g]=(0,b.useState)(),[_,v]=(0,b.useState)(),[y,x]=(0,b.useState)(!1),[S,C]=(0,b.useState)(),[w,T]=(0,b.useState)(),[E,D]=(0,b.useState)(!1),[O,k]=(0,b.useState)(),A=(0,b.useCallback)(e=>{s?s(e):l.processCode(e).then(()=>{i&&i()}).catch(e=>J({color:`red`,message:Y(e)}))},[l,s,i]),j=(0,b.useCallback)(e=>{if(m(!!e.mfaEnrollRequired),g(e.enrollQrCode),v(e.allowedMfaMethods),x(!!e.mfaRequired),e.mfaRequired){let t=e.mfaMethods;C(t),T(e.email),t?.length===1&&t[0]===`email`&&D(!0)}else C(void 0),T(void 0),D(!1);e.login&&d(e.login),e.memberships&&k(e.memberships),e.code&&(n?k(void 0):A(e.code))},[n,A]),M=(0,b.useCallback)(async()=>{u&&await l.post(`auth/mfa/send-email`,{login:u})},[l,u]),ee=(0,b.useCallback)(()=>{u&&l.post(`auth/mfa/login-enroll`,{login:u,method:`email`}).then(j).catch(e=>J({color:`red`,message:Y(e)}))},[l,u,j]),N=(0,b.useCallback)(e=>{A(e.code)},[A]);return(0,b.useEffect)(()=>{t&&!f.current&&!u&&(f.current=!0,l.get(`auth/login/`+t).then(j).catch(e=>J({color:`red`,message:Y(e)})))},[l,t,f,u,j]),(0,I.jsx)(VP,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:u?p?(0,I.jsx)(sF,{allowedMethods:_??[`totp`],qrCodeUrl:h,onEnrollEmail:ee,totpTitle:`Enroll in MFA`,totpDescription:`Scan this QR code with your authenticator app.`,onEnrollTotp:async e=>{j(await l.post(`auth/mfa/login-enroll`,{login:u,method:`totp`,token:e}))}}):y?(0,I.jsx)(cF,{methods:S??[],email:w,initialEmailMode:E,onRequestEmailCode:M,onSubmit:async e=>{j(await l.post(`auth/mfa/verify`,{login:u,token:e}))}}):e.projectId===`new`?(0,I.jsx)(uF,{login:u,handleAuthResponse:j}):O?(0,I.jsx)(CF,{login:u,memberships:O,handleAuthResponse:j}):e.chooseScopes?(0,I.jsx)(aF,{login:u,scope:e.scope,handleAuthResponse:N,...r}):(0,I.jsx)(`div`,{children:`Success`}):(0,I.jsx)(bF,{onForgotPassword:a,onRegister:o,handleAuthResponse:j,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...c,children:e.children})})}function EF(e){return(0,I.jsx)(I.Fragment,{children:xw(e.value)})}function DF(e){return(0,I.jsx)(I.Fragment,{children:Sw(e.value,e.includeCode)})}function OF(e){let t=e.value;if(!t)return null;let n=[];return t.value&&n.push(t.value),(t.use||t.system)&&(n.push(` [`),t.use&&n.push(t.use),t.use&&t.system&&n.push(` `),t.system&&n.push(t.system),n.push(`]`)),(0,I.jsx)(I.Fragment,{children:n.join(``).trim()})}function kF(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[t.name,t.name&&`: `,t.telecom?.map(e=>(0,I.jsx)(OF,{value:e},`telecom-${t.name}-${e.value}`))]}):null}function AF(e,t,n){let r=NS(e,t,{profileUrl:n});return r?Array.isArray(r)?[r.map(e=>e.value),r[0].type]:[r.value,r.type]:[void 0,`undefined`]}function jF(e,t,n){let r=PS(e,t,n);return r?Array.isArray(r)?[r.map(e=>e.value),r[0].type]:[r.value,r.type]:[void 0,`undefined`]}function MF(e){let{elementDefinitionType:t}=e,n=Q(),r=(0,b.useContext)(vA),[i,a]=(0,b.useState)(pS(`Extension`)),o=(0,b.useMemo)(()=>{if(CC(t?.profile))return t.profile[0]},[t]),[s,c]=(0,b.useState)(o!==void 0);if((0,b.useEffect)(()=>{o&&(c(!0),n.requestProfileSchema(o).then(()=>{let e=hS(o);c(!1),e&&a(e)}).catch(e=>{c(!1),console.warn(e)}))},[n,o]),o&&(s||!mS(o)))return(0,I.jsx)(`div`,{children:`Loading...`});if(i.elements[`value[x]`]?.max!==0){let[t,n]=AF({type:`Extension`,value:e.value},`value[x]`,o??r.profileUrl);return(0,I.jsx)(KF,{propertyType:n,value:t})}return(0,I.jsx)(XF,{path:e.path,value:{type:i.type,value:e.value},compact:e.compact,ignoreMissingValues:e.ignoreMissingValues,link:e.link,profileUrl:o})}function NF(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:cw(t,e.options)}):null}function PF(e){return(0,I.jsxs)(`div`,{children:[e.value?.system,`: `,e.value?.value]})}function FF(e){return(0,I.jsx)(I.Fragment,{children:bw(e.value)})}function IF(e){return(0,I.jsx)(I.Fragment,{children:yw(e.value,e.precision)})}function LF(e){return(0,I.jsx)(I.Fragment,{children:vw(e.value,e.precision,e.exclusive)})}function RF(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(IF,{value:t.numerator,precision:e.precision}),`\xA0/\xA0`,(0,I.jsx)(IF,{value:t.denominator,precision:e.precision})]}):null}function zF(e){if(!e.value)return null;let t=e.value.display||e.value.reference||vC(e.value);return e.link!==!1&&e.value.reference?(0,I.jsx)(dM,{to:e.value,children:t}):(0,I.jsx)(I.Fragment,{children:t})}function BF(e,t,n,r){if(!CC(n?.slices))return[e];let i=Array(t.length+1);for(let e=0;e<i.length;e++)i[e]=[];for(let a of e){let e=hO(a,t,n.discriminator,r),o=e?t.findIndex(t=>t.name===e):-1;o===-1&&(o=t.length),i[o].push(a)}return i}async function VF({medplum:e,property:t}){return new Promise((n,r)=>{if(!t.slicing){n([]);return}let i=[],a=[],o=[];for(let n of t.slicing.slices){if(!pO(n)){console.debug(`Unsupported slice definition`,n);continue}let t;CC(n.elements)||(t=n.type[0]?.profile?.[0]),i.push(n),a.push(t),t&&o.push(e.requestProfileSchema(t))}Promise.all(o).then(()=>{for(let e=0;e<i.length;e++){let t=i[e],n=a[e];n&&(t.typeSchema=hS(n))}n(i)}).catch(r)})}function HF(e,t,n){return t===void 0?n:(0,I.jsx)(e,{value:t,children:n})}function UF(e){let{slice:t,property:n}=e,r=t.typeSchema?.elements??t.elements,i=(0,b.useContext)(vA),a=(0,b.useMemo)(()=>{if(CC(r))return cO({parentContext:i,elements:r,path:e.path,profileUrl:t.typeSchema?.url})},[i,e.path,t.typeSchema?.url,r]);return HF(vA.Provider,a,(0,I.jsx)(I.Fragment,{children:e.value.map((r,i)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(KF,{property:n,path:e.path,arrayElement:!0,elementDefinitionType:t.type[0],propertyType:t.type[0].code,value:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${i}-${e.value.length}`))}))}var WF=50;function GF(e){let{property:t,propertyType:n}=e,r=Q(),i=(0,b.useMemo)(()=>Array.isArray(e.values)?e.values:[],[e.values]),[a,o]=(0,b.useState)(!0),[s,c]=(0,b.useState)([]),[l,u]=(0,b.useState)(()=>[i]),[d,f]=(0,b.useState)(0),p=(0,b.useContext)(vA);if((0,b.useEffect)(()=>{VF({medplum:r,property:t}).then(e=>{f(i.length),c(e),u(BF(i.slice(0,WF),e,t.slicing,p.profileUrl)),o(!1)}).catch(e=>{console.error(e),o(!1)})},[r,t,p.profileUrl,u,i]),a)return(0,I.jsx)(`div`,{children:`Loading...`});let m;if(t.type[0]?.code!==`Extension`){let r=l[s.length],i=r.map((i,a)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(KF,{path:e.path,arrayElement:!0,property:t,propertyType:n,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${a}-${r.length}`));if(e.includeDescriptionListEntry){if(!CC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);m=(0,I.jsx)(MP,{term:Fw(e.path.split(`.`).pop()),children:i})}else m=(0,I.jsx)(I.Fragment,{children:i})}return(0,I.jsxs)(I.Fragment,{children:[s.map((n,r)=>{if(!e.path)throw Error(`Displaying a resource property with slices of type ${e.propertyType} requires path`);let i=(0,I.jsx)(UF,{path:e.path,slice:n,property:t,value:l[r],ignoreMissingValues:e.ignoreMissingValues,link:e.link},n.name);return e.includeDescriptionListEntry&&(i=(0,I.jsx)(MP,{term:Fw(n.name),children:i},n.name)),i}),m,d>WF&&(0,I.jsx)(V,{justify:`right`,children:(0,I.jsxs)(H,{children:[`... `,d,` total values`]})})]})}function KF(e){let{property:t,propertyType:n,value:r}=e;if(t?.path?.endsWith(`.id`))return(0,I.jsxs)(ru,{gap:3,align:`center`,children:[r,!SC(r)&&(0,I.jsx)(gp,{value:r,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Kv,{label:e?`Copied`:`Copy`,withArrow:!0,position:`right`,children:(0,I.jsx)(vl,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,children:e?(0,I.jsx)(WA,{size:`1rem`}):(0,I.jsx)(QA,{size:`1rem`})})})})]});if(t&&(t.isArray||t.max>1)&&!e.arrayElement)return n===X.Attachment?(0,I.jsx)(NP,{values:r,maxWidth:e.maxWidth,includeDescriptionListEntry:e.includeArrayDescriptionListEntry,property:t,path:e.path}):(0,I.jsx)(GF,{path:e.path,property:t,propertyType:n,values:r,includeDescriptionListEntry:e.includeArrayDescriptionListEntry,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(n){case X.boolean:return(0,I.jsx)(I.Fragment,{children:r===void 0?``:(!!r).toString()});case X.SystemString:case X.string:return e.property?.path?.toLowerCase().includes(`secret`)?(0,I.jsx)(qF,{value:r}):(0,I.jsx)(`div`,{style:{whiteSpace:`pre-wrap`},children:r});case X.code:case X.date:case X.decimal:case X.id:case X.integer:case X.positiveInt:case X.unsignedInt:case X.uri:case X.url:case X.xhtml:return NC(r)&&!PC(r)?(console.warn(`Non-standard FHIR data or missing primitive value with extension`,{path:e.path,propertyType:n,value:r}),null):(0,I.jsx)(I.Fragment,{children:r?.toString()});case X.canonical:return(0,I.jsx)(zF,{value:{reference:r},link:e.link});case X.dateTime:case X.instant:return(0,I.jsx)(I.Fragment,{children:dw(r)});case X.time:return(0,I.jsx)(I.Fragment,{children:uw(r)});case X.markdown:return(0,I.jsx)(`pre`,{children:r});case X.Address:return(0,I.jsx)(hA,{value:r});case X.Annotation:return(0,I.jsx)(I.Fragment,{children:r?.text});case X.Attachment:return(0,I.jsx)(OP,{value:r,maxWidth:e.maxWidth});case X.CodeableConcept:return(0,I.jsx)(EF,{value:r});case X.Coding:return(0,I.jsx)(DF,{value:r});case X.ContactDetail:return(0,I.jsx)(kF,{value:r});case X.ContactPoint:return(0,I.jsx)(OF,{value:r});case X.HumanName:return(0,I.jsx)(NF,{value:r});case X.Identifier:return(0,I.jsx)(PF,{value:r});case X.Money:return(0,I.jsx)(FF,{value:r});case X.Period:return(0,I.jsx)(I.Fragment,{children:fw(r)});case X.Quantity:case X.Duration:return(0,I.jsx)(IF,{value:r});case X.Range:return(0,I.jsx)(LF,{value:r});case X.Ratio:return(0,I.jsx)(RF,{value:r});case X.Reference:return(0,I.jsx)(zF,{value:r,link:e.link});case X.Timing:return(0,I.jsx)(I.Fragment,{children:gw(r)});case X.Dosage:case X.UsageContext:if(!e.path)throw Error(`Displaying property of type ${e.propertyType} requires path`);return(0,I.jsx)(XF,{path:e.path,value:{type:n,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});case X.Extension:if(!e.path)throw Error(`Displaying property of type ${e.propertyType} requires path`);return(0,I.jsx)(MF,{path:e.path,value:r,compact:!0,ignoreMissingValues:e.ignoreMissingValues,elementDefinitionType:e.elementDefinitionType});default:if(!t)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);if(!e.path)throw Error(`Displaying property of type ${e.propertyType} requires path`);return(0,I.jsx)(XF,{path:e.path,value:{type:t.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}function qF(e){let[t,n]=(0,b.useState)(!1),r=e.value??``,i=!SC(r),a=`•`.repeat(8);return(0,I.jsxs)(ru,{gap:3,align:`center`,children:[t?(0,I.jsx)(`div`,{style:{whiteSpace:`pre-wrap`},children:r}):(0,I.jsx)(`div`,{style:{whiteSpace:`pre-wrap`},"aria-hidden":`true`,children:i?a:``}),i&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(gp,{value:e.value,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Kv,{label:e?`Copied`:`Copy secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(vl,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,"aria-label":e?`Copied`:`Copy secret`,children:e?(0,I.jsx)(WA,{size:`1rem`}):(0,I.jsx)(QA,{size:`1rem`})})})}),(0,I.jsx)(Kv,{label:t?`Hide secret`:`Show secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(vl,{variant:`subtle`,color:`gray`,onClick:()=>n(!t),"aria-label":t?`Hide secret`:`Show secret`,children:t?(0,I.jsx)(sj,{size:`1rem`}):(0,I.jsx)(cj,{size:`1rem`})})})]})]})}var JF=[`extension`,`modifierExtension`],YF=gA.filter(e=>!JF.includes(e));function XF(e){let t=e.value,{value:n,type:r}=t,i=(0,b.useContext)(vA),a=e.profileUrl??i?.profileUrl,o=(0,b.useMemo)(()=>fS(r,a),[a,r]),s=(0,b.useMemo)(()=>{if(o)return cO({parentContext:i,elements:o.elements,path:e.path,profileUrl:o.url,accessPolicyResource:e.accessPolicyResource})},[o,i,e.path,e.accessPolicyResource]);if(SC(n))return null;if(!o)return(0,I.jsxs)(`div`,{children:[r,`\xA0not implemented`]});if(typeof n==`object`&&`name`in n&&Object.keys(n).length===1&&typeof n.name==`string`)return(0,I.jsx)(`div`,{children:n.name});let c=s??i;return HF(vA.Provider,s,(0,I.jsx)(jP,{compact:e.compact,children:Object.entries(c.elements).map(([n,r])=>{if(JF.includes(n)&&SC(r.slicing?.slices)||YF.includes(n)||_A.includes(n)&&r.path.split(`.`).length===2||n.includes(`.`))return null;let[i,a]=AF(t,n,c.profileUrl);if((e.ignoreMissingValues||r.max===0)&&SC(i)||e.path.endsWith(`.extension`)&&(n===`url`||n===`id`))return null;let o=r.max>1||r.isArray,s=(0,I.jsx)(KF,{property:r,propertyType:a,path:e.path+`.`+n,value:i,ignoreMissingValues:e.ignoreMissingValues,includeArrayDescriptionListEntry:o,link:e.link},n);return o?s:(0,I.jsx)(MP,{term:Fw(n),children:s},n)})}))}var ZF={dimmed:`_dimmed_11me5_1`,preserveBreaks:`_preserveBreaks_11me5_5`},QF=`Read Only`;function $F(e,t){return e?(0,I.jsx)(Kv.Floating,{label:e,children:t}):t}function eI(e){let{debugMode:t}=(0,b.useContext)(vA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,$F(e?.readonly?QF:void 0,(0,I.jsxs)(V,{wrap:`nowrap`,"data-testid":e.testId,children:[(0,I.jsx)(`div`,{children:e.children}),(0,I.jsx)(`div`,{children:(0,I.jsx)(Zl.Wrapper,{id:e.htmlFor,label:n,classNames:{label:e?.readonly?ZF.dimmed:void 0},description:e.description,withAsterisk:e.withAsterisk,children:null})})]}))}function tI(e){let{debugMode:t}=(0,b.useContext)(vA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,$F(e?.readonly?QF:void 0,(0,I.jsx)(Zl.Wrapper,{id:e.htmlFor,label:n,classNames:{label:it({[ZF.dimmed]:e?.readonly},ZF.preserveBreaks)},description:e.description,withAsterisk:e.withAsterisk,error:UP(e.outcome,e.errorExpression??e.htmlFor),"data-testid":e.testId,children:e.children}))}function nI(e,t,n,r,i){let a=r.type;if(a.length>1)for(let n of a){let r=t.replace(`[x]`,HC(n.code));r in e&&delete e[r]}return SC(i)?e[n]=void 0:e[n]=i,e}function rI(e){return!!e&&!SC(e.url)&&!SC(e.name)}function iI(e){let{defaultValue:t,onChange:n,withHelpText:r,outcome:i,path:a,valuePath:o,...s}=e,[c,l]=(0,b.useState)(t);function u(e){let t=oI(e);l(t),n&&n(t)}return(0,I.jsx)(QN,{defaultValue:c&&aI(c),onChange:u,withHelpText:r??!0,...s})}function aI(e){return e.coding?.map(e=>({system:e.system,code:e.code,display:e.display}))}function oI(e){if(e.length!==0)return{coding:e.map(e=>({system:e.system,code:e.code,display:e.display}))}}function sI(e){let{defaultValue:t,onChange:n,withHelpText:r,response:i,...a}=e,[o,s]=(0,b.useState)(i?.answer?.[0]?.valueCoding??t);function c(e){let t=e[0],r=t&&lI(t);s(r),n&&n(r)}return(0,I.jsx)(QN,{defaultValue:o?cI(o):void 0,maxValues:1,onChange:c,withHelpText:r??!0,...a})}function cI(e){return{system:e.system,code:e.code,display:e.display}}function lI(e){return{system:e.system,code:e.code,display:e.display}}function uI(e){let{path:t,outcome:n}=e,{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(vA),[a,o]=(0,b.useState)(e.defaultValue),[s,c,l]=(0,b.useMemo)(()=>[`system`,`use`,`value`].map(e=>r[t+`.`+e]),[r,t]),[u,d,f]=(0,b.useMemo)(()=>[`system`,`use`,`value`].map(e=>i(t+`.`+e)),[i,t]);function p(t){t&&Object.keys(t).length===0&&(t=void 0),o(t),e.onChange&&e.onChange(t)}function m(e){let t={...a,system:e};e||delete t.system,p(t)}function h(e){let t={...a,use:e};e||delete t.use,p(t)}function g(e){let t={...a,value:e};e||delete t.value,p(t)}let _=e.valuePath??t;return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,align:`flex-start`,children:[(0,I.jsx)(yg,{disabled:e.disabled||u?.readonly,"data-testid":`system`,defaultValue:a?.system,required:(s?.min??0)>0,onChange:e=>m(e.currentTarget.value),data:[``,`email`,`phone`,`fax`,`pager`,`sms`,`url`,`other`],error:UP(n,_+`.system`)}),(0,I.jsx)(yg,{disabled:e.disabled||d?.readonly,"data-testid":`use`,defaultValue:a?.use,required:(c?.min??0)>0,onChange:e=>h(e.currentTarget.value),data:[``,`home`,`work`,`temp`,`old`,`mobile`],error:UP(n,_+`.use`)}),(0,I.jsx)(yb,{disabled:e.disabled||f?.readonly,placeholder:`Value`,defaultValue:a?.value,required:(l?.min??0)>0,onChange:e=>g(e.currentTarget.value),error:UP(n,_+`.value`)})]})}function dI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a]=(0,b.useMemo)(()=>[`name`,`telecom`].map(t=>r(e.path+`.`+t)),[r,e.path]);function o(t){n(t),e.onChange&&e.onChange(t)}function s(e){let n={...t,name:e};e||delete n.name,o(n)}function c(e){let n={...t,telecom:e&&[e]};e||delete n.telecom,o(n)}return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(yb,{disabled:e.disabled||i?.readonly,"data-testid":e.name+`-name`,name:e.name+`-name`,placeholder:`Name`,style:{width:180},defaultValue:t?.name,onChange:e=>s(e.currentTarget.value)}),(0,I.jsx)(uI,{disabled:e.disabled||a?.readonly,name:e.name+`-telecom`,path:e.path+`.telecom`,defaultValue:t?.telecom?.[0],onChange:c,outcome:e.outcome})]})}function fI(e){if(!e)return``;let t=new Date(e);return lw(t)?t.toLocaleDateString(`sv`)+`T`+t.toLocaleTimeString(`sv`):``}function pI(e){if(!e)return``;let t=new Date(e);return lw(t)?t.toISOString():``}function mI(e){return(0,I.jsx)(yb,{id:e.name,name:e.name,label:e.label,"data-autofocus":e.autoFocus,"data-testid":e[`data-testid`]??e.name,placeholder:e.placeholder,required:e.required,disabled:e.disabled,type:hI(),step:1,defaultValue:fI(e.defaultValue),autoFocus:e.autoFocus,error:UP(e.outcome,e.name),onChange:t=>{if(e.onChange){let n=t.currentTarget.value;e.onChange(pI(n))}}})}function hI(){return`datetime-local`}function gI(e){let{propertyType:t}=e,n=Q(),r=(0,b.useMemo)(()=>{if(CC(t.profile))return t.profile[0]},[t]),[i,a]=(0,b.useState)(r!==void 0);return(0,b.useEffect)(()=>{r&&(a(!0),n.requestProfileSchema(r).then(()=>a(!1)).catch(e=>{a(!1),console.warn(e)}))},[n,r]),r&&(i||!mS(r))?(0,I.jsx)(`div`,{children:`Loading...`}):(0,I.jsx)(rL,{profileUrl:r,path:e.path,typeName:`Extension`,defaultValue:e.defaultValue,onChange:e.onChange})}function _I(e){let{outcome:t,path:n}=e,[r,i]=(0,b.useState)(e.defaultValue),{getExtendedProps:a}=(0,b.useContext)(vA),[o,s,c,l,u]=(0,b.useMemo)(()=>[`use`,`prefix`,`given`,`family`,`suffix`].map(t=>a(e.path+`.`+t)),[a,e.path]);function d(t){i(t),e.onChange&&e.onChange(t)}function f(e){d({...r,use:e||void 0})}function p(e){d({...r,prefix:e?e.split(` `):void 0})}function m(e){d({...r,given:e?e.split(` `):void 0})}function h(e){d({...r,family:e||void 0})}function g(e){d({...r,suffix:e?e.split(` `):void 0})}let _=e.valuePath??n;return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(yg,{disabled:e.disabled||o?.readonly,defaultValue:r?.use,name:e.name+`-use`,"data-testid":`use`,onChange:e=>f(e.currentTarget.value),data:[``,`temp`,`old`,`usual`,`official`,`nickname`,`anonymous`,`maiden`],error:UP(t,_+`.use`)}),(0,I.jsx)(yb,{disabled:e.disabled||s?.readonly,placeholder:`Prefix`,name:e.name+`-prefix`,defaultValue:r?.prefix?.join(` `),onChange:e=>p(e.currentTarget.value),error:UP(t,_+`.prefix`)}),(0,I.jsx)(yb,{disabled:e.disabled||c?.readonly,placeholder:`Given`,name:e.name+`-given`,defaultValue:r?.given?.join(` `),onChange:e=>m(e.currentTarget.value),error:UP(t,_+`.given`)}),(0,I.jsx)(yb,{disabled:e.disabled||l?.readonly,name:e.name+`-family`,placeholder:`Family`,defaultValue:r?.family,onChange:e=>h(e.currentTarget.value),error:UP(t,_+`.family`)}),(0,I.jsx)(yb,{disabled:e.disabled||u?.readonly,placeholder:`Suffix`,name:e.name+`-suffix`,defaultValue:r?.suffix?.join(` `),onChange:e=>g(e.currentTarget.value),error:UP(t,_+`.suffix`)})]})}function vI(e){let[t,n]=(0,b.useState)(e.defaultValue),{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(vA),[a,o]=(0,b.useMemo)(()=>[`system`,`value`].map(t=>r[e.path+`.`+t]),[r,e.path]),[s,c]=(0,b.useMemo)(()=>[`system`,`value`].map(t=>i(e.path+`.`+t)),[i,e.path]);function l(t){n(t),e.onChange&&e.onChange(t)}let u=e.valuePath??e.path;return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,align:`flex-start`,children:[(0,I.jsx)(yb,{disabled:e.disabled||s?.readonly,placeholder:`System`,required:(a?.min??0)>0,defaultValue:t?.system,onChange:e=>l({...t,system:e.currentTarget.value}),error:UP(e.outcome,u+`.system`)}),(0,I.jsx)(yb,{disabled:e.disabled||c?.readonly,placeholder:`Value`,required:(o?.min??0)>0,defaultValue:t?.value,onChange:e=>l({...t,value:e.currentTarget.value}),error:UP(e.outcome,u+`.value`)})]})}var yI=[`USD`,`EUR`,`CAD`,`GBP`,`AUD`];function bI(e){let{onChange:t}=e,[n,r]=(0,b.useState)(e.defaultValue),{getExtendedProps:i}=(0,b.useContext)(vA),[a,o]=(0,b.useMemo)(()=>[`currency`,`value`].map(t=>i(e.path+`.`+t)),[i,e.path]),s=(0,b.useCallback)(e=>{r(e),t&&t(e)},[t]),c=(0,b.useCallback)(e=>{s({...n,currency:e.currentTarget.value})},[n,s]),l=(0,b.useCallback)(e=>{s({...n,value:e.currentTarget.valueAsNumber})},[n,s]),u=(0,I.jsx)(yg,{disabled:e.disabled||a?.readonly,defaultValue:n?.currency,data:yI,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:c});return(0,I.jsx)(yb,{disabled:e.disabled||o?.readonly,type:`number`,name:e.name,label:e.label,placeholder:e.placeholder??`Value`,defaultValue:n?.value?.toString()??`USD`,leftSection:(0,I.jsx)($A,{size:14}),rightSection:u,rightSectionWidth:92,onChange:l})}function xI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a]=(0,b.useMemo)(()=>[`start`,`end`].map(t=>r(e.path+`.`+t)),[r,e.path]);function o(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(mI,{disabled:e.disabled||i?.readonly,name:e.name+`.start`,placeholder:`Start`,defaultValue:t?.start,onChange:e=>o({...t,start:e})}),(0,I.jsx)(mI,{disabled:e.disabled||a?.readonly,name:e.name+`.end`,placeholder:`End`,defaultValue:t?.end,onChange:e=>o({...t,end:e})})]})}function SI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a,o]=(0,b.useMemo)(()=>[`comparator`,`value`,`unit`].map(t=>r(e.path+`.`+t)),[r,e.path]);function s(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(yg,{disabled:e.disabled||i?.readonly,style:{width:80},"data-testid":e.name+`-comparator`,defaultValue:t?.comparator,data:[``,`<`,`<=`,`>=`,`>`],onChange:e=>s({...t,comparator:e.currentTarget.value})}),(0,I.jsx)(yb,{disabled:e.disabled||a?.readonly,id:e.name,name:e.name,required:e.required,"data-autofocus":e.autoFocus,"data-testid":e.name+`-value`,type:`number`,placeholder:`Value`,defaultValue:t?.value,autoFocus:e.autoFocus,step:`any`,onWheel:t=>{e.disableWheel&&t.currentTarget.blur()},onChange:e=>{s({...t,value:CI(e.currentTarget.value)})}}),(0,I.jsx)(yb,{disabled:e.disabled||o?.readonly,placeholder:`Unit`,"data-testid":e.name+`-unit`,defaultValue:t?.unit,onChange:e=>s({...t,unit:e.currentTarget.value})})]})}function CI(e){if(e)return Number.parseFloat(e)}function wI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a]=(0,b.useMemo)(()=>[`low`,`high`].map(t=>r(e.path+`.`+t)),[r,e.path]);function o(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(SI,{path:e.path+`.low`,disabled:e.disabled||i?.readonly,name:e.name+`-low`,defaultValue:t?.low,onChange:e=>o({...t,low:e})}),(0,I.jsx)(SI,{path:e.path+`.high`,disabled:e.disabled||a?.readonly,name:e.name+`-high`,defaultValue:t?.high,onChange:e=>o({...t,high:e})})]})}function TI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(vA),[i,a]=(0,b.useMemo)(()=>[`numerator`,`denominator`].map(t=>r(e.path+`.`+t)),[r,e.path]);function o(t){n(t),e.onChange&&e.onChange(t)}return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(SI,{path:e.path+`.numerator`,disabled:e.disabled||i?.readonly,name:e.name+`-numerator`,defaultValue:t?.numerator,onChange:e=>o({...t,numerator:e})}),(0,I.jsx)(SI,{path:e.path+`.denominator`,disabled:e.disabled||a?.readonly,name:e.name+`-denominator`,defaultValue:t?.denominator,onChange:e=>o({...t,denominator:e})})]})}var EI={Device:`device-name`,Observation:`code`,Subscription:`criteria`,User:`email:contains`},DI=`AccessPolicy.Account.ActivityDefinition.Bot.CapabilityStatement.CareTeam.ClientApplication.CodeSystem.CompartmentDefinition.ConceptMap.EffectEvidenceSynthesis.Endpoint.EventDefinition.Evidence.EvidenceVariable.ExampleScenario.GraphDefinition.Group.HealthcareService.ImplementationGuide.InsurancePlan.Library.Location.Measure.MedicinalProduct.MessageDefinition.NamingSystem.OperationDefinition.Organization.Patient.Person.PlanDefinition.Practitioner.Project.Questionnaire.RelatedPerson.ResearchDefinition.ResearchElementDefinition.ResearchStudy.RiskEvidenceSynthesis.SearchParameter.StructureDefinition.StructureMap.TerminologyCapabilities.TestScript.UserConfiguration.ValueSet`.split(`.`);function OI(e){return{value:aC(e)??``,label:lC(e),resource:e}}function kI(e){return EI[e]??(DI.includes(e)?`name`:`_id`)}var AI=(0,b.forwardRef)(({label:e,resource:t,active:n,...r},i)=>(0,I.jsx)(`div`,{ref:i,...r,children:(0,I.jsxs)(V,{wrap:`nowrap`,children:[(0,I.jsx)(_M,{value:t}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:e}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:t.birthDate||t.id})]})]})}));AI.displayName=`DefaultResourceItemComponent`;function jI(e){let t=Q(),{resourceType:n,searchCriteria:r}=e,i=e.itemComponent??AI,a=e.onChange,o=(0,b.useRef)(e.defaultValue),[s,c]=(0,b.useState)(!e.defaultValue||e.defaultValue.length===0?[]:void 0);(0,b.useEffect)(()=>{let e=!1,n=o.current;return n&&n.length>0&&Promise.allSettled(n.map(e=>{if(Vw(e))return Promise.resolve(e);if(Hw(e)){let n=e;return t.readReference(n)}return Promise.reject(Error(`Not a resolvable item`))})).then(t=>{e||c(t.filter(e=>e.status===`fulfilled`).map(e=>e.value))}).catch(()=>{}),()=>{e=!0}},[t]);let l=(0,b.useCallback)(async(e,i)=>{let a=kI(n),o=new URLSearchParams({[a]:e??``,_count:`10`,...r});return await t.searchResources(n,o,{signal:i})},[t,n,r]),u=(0,b.useCallback)(e=>{a&&a(e)},[a]);return s===void 0?null:(0,I.jsx)(NM,{disabled:e.disabled,name:e.name,label:e.label,error:e.error,required:e.required,itemComponent:i,defaultValue:s,placeholder:e.placeholder,maxValues:e.maxValues,toOption:OI,loadOptions:l,onChange:u,clearable:!0})}function MI(e){let t=e.onChange,n=(0,b.useCallback)(e=>{t&&t(e[0])},[t]);return(0,I.jsx)(jI,{resourceType:e.resourceType,name:e.name,defaultValue:e.defaultValue?[e.defaultValue]:void 0,searchCriteria:e.searchCriteria,placeholder:e.placeholder,required:e.required,itemComponent:e.itemComponent,onChange:n,disabled:e.disabled,label:e.label,error:e.error,maxValues:1})}function NI(e){let{onChange:t}=e,n=Q(),[r,i]=(0,b.useState)(e.defaultValue),[a,o]=(0,b.useState)(()=>PI(e.targetTypes)),[s,c]=(0,b.useState)(()=>FI(e.defaultValue,a)),l=(0,b.useRef)(new Sx),u=(0,b.useMemo)(()=>s?.type===`profile`?{...e.searchCriteria,_profile:s.value}:e.searchCriteria,[e.searchCriteria,s]);(0,b.useEffect)(()=>{let e=!1,t=a?.map(t=>{if(!LI(t))return Promise.resolve(t);e=!0;let r=t.value,i=l.current.get(r);if(i)return i;let a=new xD(II(n,t.value).then(e=>{let n={...t};return e?CC(e.type)?(n.resourceType=e.type,n.name=e.name,n.title=e.title):(console.error(`StructureDefinition.type missing for ${t.value}`),n.error=`StructureDefinition.type missing`):(console.error(`StructureDefinition not found for ${t.value}`),n.error=`StructureDefinition not found`),n}).catch(e=>(console.error(e),{...t,error:e})));return l.current.set(r,a),a});!t||!e||Promise.all(t).then(e=>{if(o(e),!s)return;let t=e.findIndex(e=>e.value===s.value||e.resourceType===s.resourceType);if(t===-1){console.debug(`defaultValue had unexpected resourceType: ${s.resourceType}`);return}c(e[t])}).catch(console.error)},[n,s,a]);let d=(0,b.useCallback)(e=>{let n=e?iC(e):void 0;i(n),t&&t(n)},[t]),f=(0,b.useMemo)(()=>a?a.map(e=>({value:e.value,label:e.type===`profile`?e.title??e.name??e.resourceType??e.value:e.value})):[],[a]);return(0,I.jsxs)(I.Fragment,{children:[e.name&&(0,I.jsx)(`input`,{type:`hidden`,name:e.name,value:r?.reference??``}),(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[a&&a.length>1&&(0,I.jsx)(yg,{name:e.name+`-resourceType`,disabled:e.disabled,"data-autofocus":e.autoFocus,"data-testid":`reference-input-resource-type-select`,defaultValue:s?.resourceType,autoFocus:e.autoFocus,onChange:e=>{let t=e.currentTarget.value;c(a.find(e=>e.value===t))},data:f}),!a&&(0,I.jsx)(rP,{disabled:e.disabled,autoFocus:e.autoFocus,testId:`reference-input-resource-type-input`,defaultValue:s?.resourceType,onChange:e=>{c(e?{type:`resourceType`,value:e,resourceType:e}:void 0)},name:e.name+`-resourceType`,placeholder:`Resource Type`}),(0,I.jsx)(MI,{resourceType:s?.resourceType,name:e.name+`-id`,required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:d,disabled:e.disabled})]})]})}function PI(e){if(!e||e.length===0||e.length===1&&e[0]===`Resource`)return;let t=[];for(let n of e)n.includes(`/`)?t.push({type:`profile`,value:n}):t.push({type:`resourceType`,value:n,resourceType:n});return t}function FI(e,t){let n=e?.reference?.split(`/`)[0];if(n)return t?.find(e=>e.resourceType===n)||{type:`resourceType`,value:n,resourceType:n};if(t&&t.length>0)return t[0]}async function II(e,t){let n=hS(t);if(n)return{type:n.type,name:n.name,title:n.title};let r=`{
|
|
199
199
|
StructureDefinitionList(url: "${t}", _sort: "_lastUpdated", _count: 1) {
|
|
200
200
|
type,
|
|
@@ -203,7 +203,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function ar({color:e,theme:t,autoContrast:n}){ret
|
|
|
203
203
|
}
|
|
204
204
|
}`.replaceAll(/\s+/g,` `);return(await e.graphql(r)).data.StructureDefinitionList[0]}function LI(e){return e.type===`profile`&&!e?.error&&SC(e.resourceType)}function RI(e,t,n){return t===void 0?e:n===void 0?t:`${t}[${n}]`}var zI={indented:`_indented_ldk1d_1`};function BI({propertyDisplayName:e,onClick:t,testId:n}){let r=e?`Add ${e}`:`Add`;return e?(0,I.jsx)(U,{title:r,size:`sm`,color:`green.6`,variant:`subtle`,"data-testid":n,leftSection:(0,I.jsx)(YA,{size:`1.25rem`}),onClick:t,children:r}):(0,I.jsx)(vl,{title:r,color:`green.6`,"data-testid":n,onClick:t,children:(0,I.jsx)(YA,{size:`1.25rem`})})}function VI({propertyDisplayName:e,onClick:t,testId:n}){return(0,I.jsx)(vl,{title:e?`Remove ${e}`:`Remove`,color:`red.5`,"data-testid":n,variant:`subtle`,onClick:t,children:(0,I.jsx)(JA,{size:`1.25rem`})})}function HI(e){let{slice:t,property:n}=e,[r,i]=(0,b.useState)(e.defaultValue),a=t.typeSchema?.elements??t.elements,o=(0,b.useContext)(vA),s=(0,b.useMemo)(()=>{if(CC(a))return cO({parentContext:o,elements:a,path:e.path,profileUrl:t.typeSchema?.url})},[o,e.path,t.typeSchema?.url,a]);function c(t){i(t),e.onChange&&e.onChange(t)}let l=t.min>0,u=SC(t.elements),d=Iw(t.name),f=e.property.readonly&&r.length===0;return HF(vA.Provider,s,(0,I.jsx)(tI,{title:d,description:t.definition,withAsterisk:l,fhirPath:`${n.path}:${t.name}`,testId:e.testId,readonly:e.property.readonly,children:f?(0,I.jsx)(H,{c:`dimmed`,children:`(empty)`}):(0,I.jsxs)(G,{className:u?zI.indented:void 0,children:[r.map((n,i)=>(0,I.jsxs)(V,{wrap:`nowrap`,children:[(0,I.jsx)(`div`,{style:{flexGrow:1},"data-testid":e.testId&&`${e.testId}-elements-${i}`,children:(0,I.jsx)(QI,{elementDefinitionType:t.type[0],name:t.name,defaultValue:n,onChange:e=>{let t=[...r];t[i]=e,c(t)},outcome:e.outcome,min:t.min,max:t.max,binding:t.binding,path:e.path,valuePath:void 0,readOnly:e.property.readonly})}),!e.property.readonly&&r.length>t.min&&(0,I.jsx)(VI,{propertyDisplayName:d,testId:e.testId&&`${e.testId}-remove-${i}`,onClick:e=>{aM(e);let t=[...r];t.splice(i,1),c(t)}})]},`${i}-${r.length}`)),!e.property.readonly&&r.length<t.max&&(0,I.jsx)(V,{wrap:`nowrap`,style:{justifyContent:`flex-start`},children:(0,I.jsx)(BI,{propertyDisplayName:d,onClick:e=>{aM(e),c([...r,void 0])},testId:e.testId&&`${e.testId}-add`})})]})}))}function UI(e){let{property:t}=e,n=Q(),[r,i]=(0,b.useState)(!0),[a,o]=(0,b.useState)([]),[s]=(0,b.useState)(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[c,l]=(0,b.useState)(()=>[s]),u=(0,b.useContext)(vA),d=t.type[0]?.code;(0,b.useEffect)(()=>{VF({medplum:n,property:t}).then(e=>{o(e);let n=BF(s,e,t.slicing,u.profileUrl);WI(n,e),l(n),i(!1)}).catch(e=>{console.error(e),i(!1)})},[n,t,s,u.profileUrl,l]);function f(t,n){let r=[...c];if(r[n]=t,l(r),e.onChange){let t=r.flat().filter(e=>e!==void 0);e.onChange(t)}}if(r)return(0,I.jsx)(`div`,{children:`Loading...`});let p=a.length,m=c[p],h=!(e.hideNonSliceValues??(d===`Extension`&&a.length>0)),g=Fw(t.path),_=e.property.readonly&&a.length===0&&s.length===0;return(0,I.jsxs)(G,{className:e.indent?zI.indented:void 0,children:[_&&(0,I.jsx)(H,{c:`dimmed`,children:`(empty)`}),a.map((n,r)=>(0,I.jsx)(HI,{slice:n,path:e.path,valuePath:e.valuePath,property:t,defaultValue:c[r],onChange:e=>{f(e,r)},testId:`slice-${n.name}`},n.name)),h&&m.map((t,n)=>(0,I.jsxs)(V,{wrap:`nowrap`,style:{flexGrow:1},children:[(0,I.jsx)(`div`,{style:{flexGrow:1},children:(0,I.jsx)(XI,{arrayElement:!0,property:e.property,name:e.name+`.`+n,path:e.path,valuePath:RI(e.path,e.valuePath,n),defaultValue:t,onChange:e=>{let t=[...m];t[n]=e,f(t,p)},defaultPropertyType:void 0,outcome:e.outcome})}),!e.property.readonly&&(0,I.jsx)(VI,{propertyDisplayName:g,testId:`nonsliced-remove-${n}`,onClick:e=>{aM(e);let t=[...m];t.splice(n,1),f(t,p)}})]},`${n}-${m.length}`)),!e.property.readonly&&h&&c.flat().length<t.max&&(0,I.jsx)(V,{wrap:`nowrap`,style:{justifyContent:`flex-start`},children:(0,I.jsx)(BI,{propertyDisplayName:g,onClick:e=>{aM(e);let t=[...m];t.push(void 0),f(t,p)},testId:`nonsliced-add`})})]})}function WI(e,t){for(let n=0;n<t.length;n++){let r=t[n],i=e[n];for(;i.length<r.min;)i.push(void 0)}}function GI(e){let[t,n]=(0,b.useState)(!1),r=gt(),i=(0,b.useRef)(null),a={...e.styles};return t||(a.input||={},a.input.WebkitTextSecurity=`disc`),(0,I.jsxs)(ru,{gap:`xs`,children:[(0,I.jsx)(_m,{...e,styles:{...a,root:{...a.root??{},flexGrow:1}},ref:i,autosize:!0,minRows:1,onFocus:()=>n(!0),onBlur:()=>n(!1)}),(0,I.jsx)(vl,{title:`Copy secret`,onClick:()=>{r.copy(i.current?.value),J({color:`green`,message:`Copied`})},children:(0,I.jsx)(QA,{})})]})}var KI=[`sun`,`mon`,`tue`,`wed`,`thu`,`fri`,`sat`];function qI(e){let[t,n]=(0,b.useState)(e.defaultValue),[r,i]=(0,b.useState)(!e.disabled&&(e.defaultModalOpen??!1));return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(`span`,{"data-testid":`timinginput-display`,children:gw(t)||`No repeat`}),(0,I.jsx)(U,{disabled:e.disabled,onClick:()=>i(!0),children:`Edit`})]}),!e.disabled&&(0,I.jsx)(YI,{path:e.path,visible:r,defaultValue:t,onOk:t=>{e.onChange&&e.onChange(t),n(t),i(!1)},onCancel:()=>i(!1)})]})}var JI={repeat:{period:1,periodUnit:`d`}};function YI(e){let[t,n]=(0,b.useState)(e.defaultValue||JI),[r,i]=(0,b.useState)(()=>(e.defaultValue?.repeat?.timeOfDay??[]).map((e,t)=>({id:t,value:e}))),a=(0,b.useRef)(r.length),{getExtendedProps:o}=(0,b.useContext)(vA),[s,c,l,u,d,f]=(0,b.useMemo)(()=>[`event`,`repeat`,`repeat.period`,`repeat.periodUnit`,`repeat.dayOfWeek`,`repeat.timeOfDay`].map(t=>o(e.path+`.`+t)),[o,e.path]);function p(e){n(t=>({...t,event:[e]}))}function m(e){n(t=>({...t,repeat:e}))}function h(e){n(t=>({...t,repeat:{...t.repeat,period:e}}))}function g(e){n(t=>({...t,repeat:{...t.repeat,periodUnit:e}}))}function _(e){n(t=>({...t,repeat:{...t.repeat,dayOfWeek:e}}))}function v(e){i(t=>{let r=e(t),i=r.map(e=>e.value);return n(e=>({...e,repeat:{...e.repeat,timeOfDay:i}})),r})}return(0,I.jsx)(Bh,{title:`Timing`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:()=>e.onCancel(),children:(0,I.jsxs)(G,{gap:`md`,children:[(0,I.jsx)(tI,{title:`Starts on`,htmlFor:`timing-dialog-start`,children:(0,I.jsx)(mI,{disabled:s?.readonly,name:`timing-dialog-start`,onChange:e=>p(e)})}),(0,I.jsx)(Uy,{disabled:c?.readonly,label:`Repeat`,checked:!!t.repeat,onChange:e=>m(e.currentTarget.checked?JI.repeat:void 0)}),t.repeat&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(tI,{title:`Repeat every`,htmlFor:`timing-dialog-period`,children:(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(yb,{disabled:l?.readonly,type:`number`,step:1,id:`timing-dialog-period`,name:`timing-dialog-period`,defaultValue:t.repeat.period||1,onChange:e=>h(Number.parseInt(e.currentTarget.value,10)||1)}),(0,I.jsx)(yg,{disabled:u?.readonly,id:`timing-dialog-periodUnit`,name:`timing-dialog-periodUnit`,defaultValue:t.repeat.periodUnit,onChange:e=>g(e.currentTarget.value),data:[{label:`minute`,value:`min`},{label:`hour`,value:`h`},{label:`day`,value:`d`},{label:`week`,value:`wk`},{label:`month`,value:`mo`},{label:`year`,value:`a`}]})]})}),t.repeat.periodUnit===`wk`&&(0,I.jsx)(tI,{title:`Repeat on`,children:(0,I.jsx)(qd.Group,{multiple:!0,onChange:_,value:t.repeat?.dayOfWeek,children:(0,I.jsx)(V,{justify:`space-between`,mt:`xs`,gap:`xs`,children:KI.map(e=>(0,I.jsx)(qd,{value:e,size:`xs`,radius:`xl`,disabled:d?.readonly,checked:(t.repeat?.dayOfWeek??[]).includes(e),children:e.charAt(0).toUpperCase()},e))})})}),(0,I.jsx)(tI,{title:`At times`,children:(0,I.jsxs)(G,{mt:`xs`,children:[r.map((e,t)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(yb,{disabled:f?.readonly,type:`time`,id:`timing-dialog-repeat-timeOfDay[${t}]`,name:`timing-dialog-repeat-timeOfDay[${t}]`,"data-testid":`timing-repeat-timeOfDay-input-${t}`,defaultValue:e.value.slice(0,5),onChange:n=>{let r=`${n.currentTarget.value}:00`;v(n=>n.with(t,{...e,value:r}))},style:{flexGrow:1}}),(0,I.jsx)(VI,{testId:`timing-repeat-timeOfDay-remove-${t}`,onClick:()=>v(e=>e.toSpliced(t,1))})]},e.id)),(0,I.jsx)(z,{children:(0,I.jsx)(BI,{propertyDisplayName:`Time of Day`,onClick:()=>v(e=>{let t=a.current++;return e.concat({id:t,value:`00:00:00`})})})})]})})]}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{onClick:()=>e.onOk(t),children:`OK`})})]})})}function XI(e){let{property:t,name:n,onChange:r,defaultValue:i}=e,a=e.defaultPropertyType&&e.defaultPropertyType!==`undefined`?e.defaultPropertyType:t.type[0].code,o=t.type;if((t.isArray||t.max>1)&&!e.arrayElement){if(a===X.Attachment)return(0,I.jsx)(FP,{name:n,defaultValue:i,onChange:r,disabled:t.readonly});let s=o[0]?.code!==X.Extension;return(0,I.jsx)(UI,{property:t,name:n,path:e.path,valuePath:e.valuePath,defaultValue:i,indent:s,onChange:r,outcome:e.outcome})}else if(o.length>1)return(0,I.jsx)(ZI,{elementDefinitionTypes:o,...e});else return(0,I.jsx)(QI,{name:n,defaultValue:i,onChange:t=>{if(e.onChange){let n=e.name.replace(`[x]`,HC(o[0].code));e.onChange(t,n)}},outcome:e.outcome,elementDefinitionType:o[0],min:t.min,max:t.min,binding:t.binding,path:e.path,valuePath:e.valuePath,readOnly:t.readonly})}function ZI(e){let t=e.elementDefinitionTypes,n;e.defaultPropertyType&&(n=t.find(t=>t.code===e.defaultPropertyType)),n||=t[0];let[r,i]=(0,b.useState)(n);return(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,align:`flex-start`,children:[(0,I.jsx)(yg,{disabled:e.property.readonly,style:{width:`200px`},defaultValue:r.code,"data-testid":e.name&&e.name+`-selector`,onChange:e=>{i(t.find(t=>t.code===e.currentTarget.value))},data:t.map(e=>({value:e.code,label:e.code}))}),(0,I.jsx)(QI,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:t=>{e.onChange&&e.onChange(t,e.name.replace(`[x]`,HC(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path,valuePath:e.valuePath,readOnly:e.property.readonly})]})}function QI(e){let{name:t,onChange:n,outcome:r,binding:i,path:a,valuePath:o,readOnly:s}=e,c=e.min!==void 0&&e.min>0,l=e.elementDefinitionType.code,u=(0,b.useContext)(vA),d=(0,b.useMemo)(()=>{if(!UC(l)||!SC(e.defaultValue))return e.defaultValue;let t=Object.create(null);if(u.path===e.path)bO(t,u.elements);else{let n=WC(u.path,e.path);if(n===void 0)return e.defaultValue;bO(t,u.elements,n)}return CC(t)?t:e.defaultValue},[l,u.path,u.elements,e.path,e.defaultValue]);if(!l)return(0,I.jsx)(`div`,{children:`Property type not specified `});function f(){return{name:t,defaultValue:d,onChange:n,outcome:r,path:a,valuePath:o,disabled:s}}function p(){return{id:t,name:t,"data-testid":t,defaultValue:d,required:c,error:UP(e.outcome,o??a),disabled:s}}switch(l){case X.SystemString:case X.canonical:case X.string:case X.uri:case X.url:return e.path===`Project.secret.value[x]`||e.path===`ClientApplication.certificateTrustStore`?(0,I.jsx)(GI,{...p(),onChange:t=>{e.onChange&&e.onChange(t.currentTarget.value)}}):(0,I.jsx)(yb,{...p(),onChange:e=>{n&&n(e.currentTarget.value)}});case X.date:return(0,I.jsx)(yb,{...p(),type:`date`,onChange:e=>{n&&n(e.currentTarget.value)}});case X.time:return(0,I.jsx)(yb,{...p(),type:`time`,step:1,onChange:e=>{n&&n(e.currentTarget.value)}});case X.dateTime:case X.instant:return(0,I.jsx)(mI,{...p(),onChange:n,outcome:r});case X.decimal:case X.integer:case X.positiveInt:case X.unsignedInt:return(0,I.jsx)(yb,{...p(),type:`number`,step:l===X.decimal?`any`:`1`,onChange:e=>{if(n){let t=e.currentTarget.valueAsNumber;n(Number.isNaN(t)?void 0:t)}}});case X.code:return(0,I.jsx)(eP,{...p(),error:void 0,onChange:n,binding:i?.valueSet,creatable:!0,maxValues:1});case X.boolean:return(0,I.jsx)(Bd,{...p(),defaultChecked:!!d,onChange:e=>{n&&n(e.currentTarget.checked)}});case X.base64Binary:case X.markdown:case X.xhtml:return(0,I.jsx)(_m,{...p(),spellCheck:l!==X.base64Binary,onChange:e=>{n&&n(e.currentTarget.value)}});case X.Address:return(0,I.jsx)(wA,{...f()});case X.Annotation:return(0,I.jsx)(TA,{...f()});case X.Attachment:return(0,I.jsx)(IP,{...f()});case X.CodeableConcept:return(0,I.jsx)(iI,{binding:i?.valueSet,...f()});case X.Coding:return(0,I.jsx)(sI,{binding:i?.valueSet,...f()});case X.ContactDetail:return(0,I.jsx)(dI,{...f()});case X.ContactPoint:return(0,I.jsx)(uI,{...f()});case X.Extension:return(0,I.jsx)(gI,{...f(),propertyType:e.elementDefinitionType});case X.HumanName:return(0,I.jsx)(_I,{...f()});case X.Identifier:return(0,I.jsx)(vI,{...f()});case X.Money:return(0,I.jsx)(bI,{...f()});case X.Period:return(0,I.jsx)(xI,{...f()});case X.Duration:case X.Quantity:return(0,I.jsx)(SI,{...f()});case X.Range:return(0,I.jsx)(wI,{...f()});case X.Ratio:return(0,I.jsx)(TI,{...f()});case X.Reference:return(0,I.jsx)(NI,{...f(),targetTypes:eL(e.elementDefinitionType)});case X.Timing:return(0,I.jsx)(qI,{...f()});case X.Dosage:case X.UsageContext:default:return(0,I.jsx)(rL,{...f(),typeName:l})}}var $I=[`${Ox}/fhir/StructureDefinition/`,`https://medplum.com/fhir/StructureDefinition/`];function eL(e){return e?.targetProfile?.map(e=>{let t=$I.find(t=>e.startsWith(t));return t?e.slice(t.length):e})}function tL(e){let[t,n]=(0,b.useState)(e.defaultValue??{}),r=(0,b.useContext)(vA),i=(0,b.useMemo)(()=>xA(r.elements),[r.elements]);function a(t){n(t),e.onChange&&e.onChange(t)}let o={type:e.type,value:t};return(0,I.jsx)(G,{style:{flexGrow:1},"data-testid":e.testId,children:i.map(([n,r])=>{let[i,s]=jF(o,n,r),c=r.min!==void 0&&r.min>0,l=e.valuePath?e.valuePath+`.`+n:void 0,u=(0,I.jsx)(XI,{property:r,name:n,path:e.path+`.`+n,valuePath:l,defaultValue:i,defaultPropertyType:s,onChange:(e,i)=>{a(nI({...t},n,i??n,r,e))},outcome:e.outcome},n);return e.type===`Extension`||yA.includes(n)?u:r.type.length===1&&r.type[0].code===`boolean`?(0,I.jsx)(eI,{title:Fw(n),description:r.description,htmlFor:n,fhirPath:r.path,withAsterisk:c,readonly:r.readonly,children:u},n):(0,I.jsx)(tI,{title:Fw(n),description:r.description,withAsterisk:c,htmlFor:n,outcome:e.outcome,fhirPath:r.path,errorExpression:l,readonly:r.readonly,children:u},n)})})}var nL={nested:`_nested_1ya4k_1`};function rL(e){let[t]=(0,b.useState)(()=>e.defaultValue??{}),n=(0,b.useContext)(vA),r=e.profileUrl??n?.profileUrl,i=(0,b.useMemo)(()=>fS(e.typeName,r),[e.typeName,r]),a=i?.type??e.typeName,o=(0,b.useMemo)(()=>{if(i)return cO({parentContext:n,elements:i.elements,path:e.path,profileUrl:i.url,accessPolicyResource:e.accessPolicyResource})},[i,n,e.path,e.accessPolicyResource]);if(!i)return(0,I.jsxs)(`div`,{children:[a,`\xA0not implemented`]});let s=n.path!==``;return HF(vA.Provider,o,(0,I.jsx)(z,{className:it({[nL.nested]:s}),children:(0,I.jsx)(tL,{path:e.path,valuePath:e.valuePath,type:a,defaultValue:t,onChange:e.onChange,outcome:e.outcome})}))}var iL={noteBody:`_noteBody_10swh_1`,noteCite:`_noteCite_10swh_5`,noteRoot:`_noteRoot_10swh_10`};function aL({value:e}){return e?(0,I.jsx)(G,{justify:`flex-start`,gap:`xs`,children:e.map(e=>e.text&&(0,I.jsx)(ad,{classNames:{cite:iL.noteCite,root:iL.noteRoot},cite:e.authorReference?.display||e.authorString,icon:null,children:e.text},`note-${e.text}`))}):null}function oL(e){let{value:t,link:n,...r}=e,[i,a]=(0,b.useState)(),o=bk(t,a),s;if(i&&!Jx(i))s=`[${Y(i)}]`;else if(o)s=lC(o);else return null;return n?(0,I.jsx)(dM,{to:t,...r,children:s}):(0,I.jsx)(H,{component:`span`,...r,children:s})}function sL(e){return(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(_M,{size:24,radius:12,value:e.value,link:e.link}),(0,I.jsx)(oL,{value:e.value,link:e.link})]})}var cL={draft:`blue`,active:`blue`,"on-hold":`yellow`,revoked:`red`,completed:`green`,"entered-in-error":`red`,unknown:`gray`,retired:`gray`,registered:`blue`,preliminary:`blue`,final:`green`,amended:`yellow`,corrected:`yellow`,cancelled:`red`,requested:`blue`,received:`blue`,accepted:`blue`,rejected:`red`,ready:`blue`,"in-progress":`blue`,failed:`red`,proposed:`blue`,pending:`blue`,booked:`blue`,arrived:`blue`,fulfilled:`green`,noshow:`red`,"checked-in":`blue`,waitlist:`gray`,routine:`gray`,urgent:`red`,asap:`red`,stat:`red`,"not-done":`red`,connected:`green`,disconnected:`red`,finished:`green`,planned:`gray`};function lL(e){let{status:t,...n}=e;return(0,I.jsx)(td,{color:e.color||cL[t],...n,children:t.replaceAll(`-`,` `)})}var uL={table:`_table_pe9td_1`,criticalRow:`_criticalRow_pe9td_12`,noteBody:`_noteBody_pe9td_23`,noteCite:`_noteCite_pe9td_27`,noteRoot:`_noteRoot_pe9td_32`};dL.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1,hideSubject:!1};function dL(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)();if((0,b.useEffect)(()=>{n?.specimen&&Promise.allSettled(n.specimen.map(e=>t.readReference(e))).then(e=>e.filter(e=>e.status===`fulfilled`).map(e=>e.value)).then(i).catch(console.error)},[t,n]),!n)return null;let a=r?.flatMap(e=>e.note||[])||[];if(n.presentedForm&&n.presentedForm.length>0){let e=n.presentedForm[0];e.contentType?.startsWith(`text/plain`)&&e.data&&a.push({text:window.atob(e.data)})}return(0,I.jsxs)(G,{children:[(0,I.jsx)(q,{children:`Diagnostic Report`}),(0,I.jsx)(fL,{value:n,hideSubject:e.hideSubject}),r&&!e.hideSpecimenInfo&&hL(r),n.result&&(0,I.jsx)(gL,{hideObservationNotes:e.hideObservationNotes,value:n.result}),a.length>0&&(0,I.jsx)(aL,{value:a}),n.conclusion&&(0,I.jsxs)(G,{mt:`md`,children:[(0,I.jsx)(H,{fw:500,size:`sm`,c:`dimmed`,children:`Conclusion`}),(0,I.jsx)(H,{children:n.conclusion})]})]})}function fL({value:e,hideSubject:t=!1}){let n=!!(e.subject&&!t),r=n||!!e.resultsInterpreter?.length,i=!!(e.performer?.length||e.issued||e.status);return(0,I.jsxs)(V,{mt:`md`,gap:`xl`,align:`stretch`,wrap:`nowrap`,children:[r&&(0,I.jsxs)(G,{gap:`md`,style:{flex:1},children:[n&&(0,I.jsx)(pL,{label:`Subject`,children:(0,I.jsx)(sL,{value:e.subject,link:!0})}),e.resultsInterpreter?.map(e=>(0,I.jsx)(pL,{label:`Interpreter`,children:(0,I.jsx)(sL,{value:e,link:!0})},e.reference))]}),r&&i&&(0,I.jsx)(bp,{orientation:`vertical`}),i&&(0,I.jsxs)(G,{gap:`md`,style:{flex:1},children:[e.performer?.map(e=>(0,I.jsx)(pL,{label:`Performer`,children:(0,I.jsx)(mL,{value:e})},e.reference)),e.issued&&(0,I.jsx)(pL,{label:`Issued`,children:(0,I.jsx)(H,{children:dw(e.issued)})}),e.status&&(0,I.jsx)(pL,{label:`Status`,children:(0,I.jsx)(lL,{status:e.status})})]})]})}function pL({label:e,children:t}){return(0,I.jsxs)(V,{gap:`md`,align:`flex-start`,wrap:`nowrap`,children:[(0,I.jsx)(H,{c:`dimmed`,w:110,style:{flexShrink:0},children:e}),(0,I.jsx)(`div`,{children:t})]})}function mL({value:e}){let t=bk(e),n=t?.resourceType===`Organization`?t.address?.[0]:void 0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sL,{value:e,link:!0}),n&&(0,I.jsx)(H,{size:`sm`,c:`dimmed`,mt:4,ml:34,children:(0,I.jsx)(hA,{value:n})})]})}function hL(e){return(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(q,{order:2,size:`h6`,children:`Specimens`}),(0,I.jsx)(Am,{type:`ordered`,children:e?.map(e=>(0,I.jsx)(Am.Item,{ml:`sm`,children:(0,I.jsxs)(V,{gap:20,children:[(0,I.jsxs)(V,{gap:5,children:[(0,I.jsx)(H,{fw:500,children:`Collected:`}),` `,dw(e.collection?.collectedDateTime)]}),(0,I.jsxs)(V,{gap:5,children:[(0,I.jsx)(H,{fw:500,children:`Received:`}),` `,dw(e.receivedTime)]})]})},`specimen-${e.id}`))})]})}function gL(e){return(0,I.jsxs)(`table`,{className:uL.table,children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Test`}),(0,I.jsx)(`th`,{children:`Value`}),(0,I.jsx)(`th`,{children:`Reference Range`}),(0,I.jsx)(`th`,{children:`Interpretation`}),(0,I.jsx)(`th`,{children:`Category`}),(0,I.jsx)(`th`,{children:`Performer`}),(0,I.jsx)(`th`,{children:`Status`})]})}),(0,I.jsx)(`tbody`,{children:(0,I.jsx)(_L,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function _L(e){return(0,I.jsx)(I.Fragment,{children:e.value?.map(t=>(0,I.jsx)(vL,{value:t,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${Hw(t)?t.reference:t.id}`))})}function vL(e){let t=bk(e.value);if(!t||e.ancestorIds?.includes(t.id))return null;let n=!e.hideObservationNotes&&t.note,r=xL(t);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`tr`,{className:it({[uL.criticalRow]:r}),children:[(0,I.jsx)(`td`,{rowSpan:n?2:1,children:(0,I.jsx)(dM,{to:t,children:(0,I.jsx)(EF,{value:t.code})})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(yL,{value:t})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(bL,{value:t.referenceRange})}),(0,I.jsx)(`td`,{children:t.interpretation&&t.interpretation.length>0&&(0,I.jsx)(EF,{value:t.interpretation[0]})}),(0,I.jsx)(`td`,{children:t.category&&t.category.length>0&&(0,I.jsx)(I.Fragment,{children:t.category.map(e=>(0,I.jsx)(`div`,{children:(0,I.jsx)(EF,{value:e})},`category-${xw(e)}`))})}),(0,I.jsx)(`td`,{children:t.performer?.map(e=>(0,I.jsx)(zF,{value:e},e.reference))}),(0,I.jsx)(`td`,{children:t.status&&(0,I.jsx)(lL,{status:t.status})})]}),t.hasMember&&(0,I.jsx)(_L,{value:t.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,t.id]:[t.id],hideObservationNotes:e.hideObservationNotes}),n&&(0,I.jsx)(`tr`,{children:(0,I.jsx)(`td`,{colSpan:6,children:(0,I.jsx)(aL,{value:t.note})})})]})}function yL(e){let t=e.value;return(0,I.jsx)(I.Fragment,{children:Cw(t)})}function bL(e){let t=e.value&&e.value.length>0&&e.value[0];return t?t.text?(0,I.jsx)(I.Fragment,{children:t.text}):(0,I.jsx)(LF,{value:t}):null}function xL(e){let t=e.interpretation?.[0]?.coding?.[0]?.code;return t===`AA`||t===`LL`||t===`HH`||t===`A`}var SL={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function CL(e){let{name:t,path:n,property:r,originalValue:i,revisedValue:a}=e,o=!!r?.type?.find(e=>e.code===`Attachment`),[s,c]=(0,b.useState)(o);return(0,I.jsx)(I.Fragment,{children:o&&!s||!o?(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:t}),(0,I.jsx)(K.Td,{className:SL.removed,children:i&&(0,I.jsx)(KF,{path:n,property:r,propertyType:i.type,value:i.value,ignoreMissingValues:!0})}),(0,I.jsx)(K.Td,{className:SL.added,children:a&&(0,I.jsx)(KF,{path:n,property:r,propertyType:a.type,value:a.value,ignoreMissingValues:!0})})]})}):(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:t}),(0,I.jsx)(K.Td,{colSpan:2,style:{textAlign:`right`},children:(0,I.jsx)(U,{onClick:()=>c(e=>!e),variant:`light`,children:`Expand`})})]})})}var wL={root:`_root_15xvr_1`,removed:`_removed_15xvr_20`,added:`_added_15xvr_25`};function TL(e){let t=Q(),{original:n,revised:r}=e,[i,a]=(0,b.useState)(!1);(0,b.useEffect)(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]);let o=(0,b.useMemo)(()=>{if(!i)return null;let e=[AS(n)],t=[AS(r)],a=[],o=EL(VO(n,r));for(let r of o){let i=r.path,o=DL(i),s=OL(n.resourceType,o),c=r.op===`add`?void 0:RT(o,e),l=r.op===`remove`?void 0:RT(o,t);a.push({key:`op-${r.op}-${r.path}`,name:`${HC(r.op)} ${o}`,path:s?.path??n.resourceType+`.`+o,property:s,originalValue:kL(s,c),revisedValue:kL(s,l)})}return a},[i,n,r]);return o?(0,I.jsxs)(K,{className:wL.root,children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{}),(0,I.jsx)(K.Th,{children:`Before`}),(0,I.jsx)(K.Th,{children:`After`})]})}),(0,I.jsx)(K.Tbody,{children:o.map(e=>{let{key:t,...n}=e;return(0,I.jsx)(CL,{...n},t)})})]}):null}function EL(e){let t=[];for(let n of e){let{op:r,path:i}=n;if(i.startsWith(`/meta/author`)||i.startsWith(`/meta/compartment`)||i.startsWith(`/meta/lastUpdated`)||i.startsWith(`/meta/versionId`))continue;let a=e.filter(e=>e.op===r&&e.path===i).length,o={op:r,path:i};a>1&&(r===`add`||r===`remove`)&&/\/[0-9-]+$/.test(i)&&(o.op=`replace`,o.path=i.replace(/\/[^/]+$/,``)),t.some(e=>e.op===o.op&&e.path===o.path)||t.push(o)}return t}function DL(e){let t=e.split(`/`).filter(Boolean),n=``;for(let e=0;e<t.length;e++){let r=t[e];r===`-`?n+=`.last()`:/^\d+$/.test(r)?n+=`[${r}]`:(e>0&&(n+=`.`),n+=r)}return n.endsWith(`.url`)&&(n=n.replace(/\.url$/,``)),n}function OL(e,t){try{return GO(e,{resourceType:`SearchParameter`,base:[e],code:e+`.`+t,expression:e+`.`+t})?.elementDefinitions?.[0]}catch(n){console.warn(`Failed to get element definition`,{resourceType:e,fhirPath:t,err:n});return}}function kL(e,t){return t&&{type:Array.isArray(t)?t[0].type:t.type,value:AL(t,!!e?.isArray)}}function AL(e,t){let n=Dx(e).flatMap(e=>e.value);return t?n:n[0]}function jL(e){let{profileUrl:t}=e,n=Q(),r=n.getAccessPolicy(),i=bk(e.value),[a,o]=(0,b.useState)(!1);(0,b.useEffect)(()=>{if(i)if(t)n.requestProfileSchema(t,{expandProfile:!0}).then(()=>{hS(t)?o(!0):console.error(`Schema not found for ${t}`)}).catch(e=>{console.error(`Error in requestProfileSchema`,e)});else{let e=i.resourceType;n.requestSchema(e).then(()=>{o(!0)}).catch(console.error)}},[n,t,i]);let s=(0,b.useMemo)(()=>i&&ME(i,OE.READ,r),[r,i]);return!a||!i?null:(0,I.jsx)(XF,{path:i.resourceType,value:{type:i.resourceType,value:e.forceUseInput?e.value:i},profileUrl:t,ignoreMissingValues:e.ignoreMissingValues,accessPolicyResource:s})}var ML={item:`_item_5q6yx_1`,itemPadding:`_itemPadding_5q6yx_5`};function NL(e){return(0,I.jsx)(RP,{children:e.children})}function PL(e){let{resource:t,profile:n,padding:r,popupMenuItems:i,...a}=e,o=n??t.meta?.author,s=t.meta?.onBehalfOf,c=e.dateTime??t.meta?.lastUpdated;return(0,I.jsxs)(BP,{"data-testid":`timeline-item`,fill:!0,...a,children:[(0,I.jsxs)(V,{justify:`space-between`,gap:8,mx:`xs`,my:`sm`,children:[(0,I.jsx)(_M,{value:o,link:!0,size:`md`}),(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsxs)(H,{size:`sm`,children:[(0,I.jsx)(oL,{c:`inherit`,fw:500,value:o,link:!0}),s&&(0,I.jsxs)(H,{component:`span`,size:`xs`,c:`dimmed`,children:[` on behalf of `,(0,I.jsx)(oL,{c:`inherit`,value:s,link:!0})]})]}),(0,I.jsxs)(H,{size:`xs`,children:[(0,I.jsx)(dM,{c:`dimmed`,to:e.resource,children:dw(c)}),(0,I.jsx)(H,{component:`span`,c:`dimmed`,mx:8,children:`·`}),(0,I.jsx)(dM,{c:`dimmed`,to:e.resource,children:e.resource.resourceType})]})]}),i&&(0,I.jsxs)(W,{position:`bottom-end`,shadow:`md`,width:200,children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(vl,{color:`gray`,variant:`subtle`,radius:`xl`,"aria-label":`Actions for ${aC(e.resource)}`,children:(0,I.jsx)(rj,{})})}),i]})]}),(0,I.jsx)(tM,{children:(0,I.jsx)(`div`,{className:it(ML.item,{[ML.itemPadding]:r}),children:e.children})})]})}function FL(e,t){e.sort((e,n)=>{let r=IL(e,t),i=IL(n,t);return r>i?1:r<i?-1:LL(e,t)-LL(n,t)})}function IL(e,t){if(!RL(e,t)){let t=e.priority;if(typeof t==`string`)return{stat:4,asap:3,urgent:2}[t]??0}return 0}function LL(e,t){if(!RL(e,t)){if(e.resourceType===`Communication`&&e.sent)return new Date(e.sent).getTime();if((e.resourceType===`DiagnosticReport`||e.resourceType===`Media`||e.resourceType===`Observation`)&&e.issued)return new Date(e.issued).getTime();if(e.resourceType===`DocumentReference`&&e.date)return new Date(e.date).getTime()}let n=e.meta?.lastUpdated;return n?new Date(n).getTime():0}function RL(e,t){return!!t&&e.resourceType===t.resourceType&&e.id===t.id}var zL={pinnedComment:`_pinnedComment_u08s5_1`};function BL(e){let t=Q(),n=t.getProfile(),r=(0,b.useRef)(null),i=bk(e.value),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)([]),[l,u]=(0,b.useState)(10),d=e.loadTimelineResources,f=(0,b.useRef)(s);(0,b.useLayoutEffect)(()=>{f.current=s});let p=(0,b.useCallback)(e=>{FL(e,i),e.reverse(),c(e)},[i]),m=(0,b.useCallback)(e=>{let t=[];for(let n of e){if(n.status!==`fulfilled`)continue;let e=n.value;if(e.type===`history`&&o(e),e.entry)for(let n of e.entry)t.push(n.resource)}p(t)},[p]),h=(0,b.useCallback)(e=>p([...f.current,e]),[p]),g=(0,b.useCallback)(()=>{let n,r;`resourceType`in e.value?(n=e.value.resourceType,r=e.value.id):[n,r]=e.value.reference?.split(`/`),d(t,n,r).then(m).catch(console.error)},[t,e.value,d,m]);(0,b.useEffect)(()=>g(),[g]);function _(r){!i||!e.createCommunication||t.createResource(e.createCommunication(i,n,r)).then(e=>h(e)).catch(console.error)}function v(r){!i||!e.createMedia||t.createResource(e.createMedia(i,n,r)).then(e=>h(e)).then(()=>Ib({id:`upload-notification`,color:`teal`,title:`Upload complete`,message:``,icon:(0,I.jsx)(WA,{size:16}),autoClose:2e3})).catch(e=>Ib({id:`upload-notification`,color:`red`,title:`Upload error`,message:Y(e),icon:(0,I.jsx)(lj,{size:16}),autoClose:2e3}))}function y(){J({id:`upload-notification`,loading:!0,title:`Initializing upload...`,message:`Please wait...`,autoClose:!1,withCloseButton:!1})}function x(e){Ib({id:`upload-notification`,loading:!0,title:`Uploading...`,message:qL(e),autoClose:!1,withCloseButton:!1})}function S(e){Ib({id:`upload-notification`,color:`red`,title:`Upload error`,message:Y(e),icon:(0,I.jsx)(lj,{size:16}),autoClose:2e3})}if(!i)return(0,I.jsx)(hd,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(il,{})});let C=s.filter(e=>e).slice(0,l);return(0,I.jsxs)(NL,{children:[e.createCommunication&&(0,I.jsx)(BP,{children:(0,I.jsx)(WN,{testid:`timeline-form`,onSubmit:e=>{_(e.text);let t=r.current;t&&(t.value=``,t.focus())},children:(0,I.jsxs)(V,{gap:`xs`,wrap:`nowrap`,style:{width:`100%`},children:[(0,I.jsx)(_M,{value:n}),(0,I.jsx)(yb,{name:`text`,ref:r,placeholder:`Add comment`,style:{width:`100%`,maxWidth:300}}),(0,I.jsx)(vl,{type:`submit`,radius:`xl`,color:`blue`,variant:`filled`,children:(0,I.jsx)(Sj,{size:16})}),(0,I.jsx)(PP,{securityContext:iC(i),onUpload:v,onUploadStart:y,onUploadProgress:x,onUploadError:S,children:e=>(0,I.jsx)(vl,{...e,radius:`xl`,color:`blue`,variant:`filled`,children:(0,I.jsx)(XA,{size:16})})})]})})}),C.map(t=>{let n=`${t.resourceType}/${t.id}/${t.meta?.versionId}`,r=e.getMenu?e.getMenu({primaryResource:i,currentResource:t,reloadTimeline:g}):void 0;if(t.resourceType===i.resourceType&&t.id===i.id)return(0,I.jsx)(VL,{history:a,resource:t,popupMenuItems:r},n);switch(t.resourceType){case`AuditEvent`:return(0,I.jsx)(GL,{resource:t,popupMenuItems:r},n);case`Communication`:return(0,I.jsx)(UL,{resource:t,popupMenuItems:r},n);case`DiagnosticReport`:return(0,I.jsx)(KL,{resource:t,popupMenuItems:r},n);case`Media`:return(0,I.jsx)(WL,{resource:t,popupMenuItems:r},n);default:return(0,I.jsx)(PL,{resource:t,padding:!0,children:(0,I.jsx)(jL,{value:t,ignoreMissingValues:!0})},n)}}),l<s.length&&(0,I.jsx)(V,{justify:`center`,pb:`lg`,children:(0,I.jsx)(U,{onClick:()=>u(l+10),children:`Show More`})})]})}function VL(e){let{history:t,resource:n,...r}=e,i=HL(t,n);return i?(0,I.jsx)(PL,{resource:n,padding:!0,...r,children:(0,I.jsx)(TL,{original:i,revised:e.resource})}):(0,I.jsxs)(PL,{resource:n,padding:!0,...r,children:[(0,I.jsx)(`h3`,{children:`Created`}),(0,I.jsx)(jL,{value:n,ignoreMissingValues:!0,forceUseInput:!0})]})}function HL(e,t){let n=e.entry??[],r=n.findIndex(e=>e.resource?.meta?.versionId===t.meta?.versionId);if(!(r>=n.length-1))return n[r+1].resource}function UL(e){let t=!e.resource.priority||e.resource.priority===`routine`?void 0:zL.pinnedComment;return(0,I.jsx)(PL,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:t,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(`p`,{children:e.resource.payload?.[0]?.contentString})})}function WL(e){let t=e.resource.content?.contentType,n=t&&!t.startsWith(`image/`)&&!t.startsWith(`video/`)&&t!==`application/pdf`;return(0,I.jsx)(PL,{resource:e.resource,padding:!!n,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(OP,{value:e.resource.content})})}function GL(e){return(0,I.jsx)(PL,{resource:e.resource,padding:!0,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(Hc,{children:(0,I.jsx)(`pre`,{children:e.resource.outcomeDesc})})})}function KL(e){return(0,I.jsx)(PL,{resource:e.resource,padding:!0,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(dL,{value:e.resource})})}function qL(e){if(e.lengthComputable){let t=100*e.loaded/e.total;return`Uploaded: ${JL(e.loaded)} / ${JL(e.total)} ${t.toFixed(2)}%`}return`Uploaded: ${JL(e.loaded)}`}function JL(e){if(e===0)return`0.00 B`;let t=Math.floor(Math.log(e)/Math.log(1024));return(e/1024**t).toFixed(2)+` `+` KMGTP`.charAt(t)+`B`}function YL(e){let{resource:t,...n}=e;return(0,I.jsx)(BL,{value:t,loadTimelineResources:async(e,t,n)=>{let r=`${t}/${n}`;return Promise.allSettled([e.readHistory(t,n),e.search(`Task`,{_filter:`based-on eq ${r} or focus eq ${r} or subject eq ${r}`,_count:100})])},...n})}function XL(e){let{encounter:t,...n}=e;return(0,I.jsx)(BL,{value:t,loadTimelineResources:async(e,t,n)=>Promise.allSettled([e.readHistory(`Encounter`,n),e.search(`Communication`,`encounter=Encounter/`+n),e.search(`Media`,`encounter=Encounter/`+n)]),createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,encounter:iC(e),subject:e.subject,sender:iC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,encounter:iC(e),subject:e.subject,operator:iC(t),issued:new Date().toISOString(),content:n}),...n})}function ZL(e){let t;try{t=LT(e.path,e.resource)}catch(e){return console.warn(`FhirPathDisplay:`,e),null}if(t.length>1)throw Error(`Component "path" for "FhirPathDisplay" must resolve to a single element. \
|
|
205
205
|
Received ${t.length} elements \
|
|
206
|
-
[${JSON.stringify(t,null,2)}]`);return(0,I.jsx)(KF,{value:t[0]||``,propertyType:e.propertyType})}function QL(e){return(0,I.jsxs)(Bh,{title:`Export`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:e.onCancel,children:[(0,I.jsxs)(z,{display:`flex`,style:{justifyContent:`space-between`},children:[e.exportCsv&&(0,I.jsx)($L,{text:`CSV`,exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,I.jsx)($L,{text:`Transaction Bundle`,exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),(0,I.jsx)(H,{style:{marginTop:`10px`,marginLeft:`2px`},children:`Limited to 1000 records`})]})}function $L(e){return(0,I.jsx)(U,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var eR={string:[Z.EQUALS,Z.NOT,Z.CONTAINS,Z.EXACT],fulltext:[Z.EQUALS,Z.NOT,Z.CONTAINS,Z.EXACT],token:[Z.EQUALS,Z.NOT,Z.TEXT],reference:[Z.EQUALS,Z.NOT],numeric:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS],quantity:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS],date:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS,Z.STARTS_AFTER,Z.ENDS_BEFORE,Z.APPROXIMATELY],datetime:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS,Z.STARTS_AFTER,Z.ENDS_BEFORE,Z.APPROXIMATELY],uri:[Z.EQUALS,Z.NOT,Z.ABOVE,Z.BELOW]},tR={eq:`equals`,ne:`not equals`,gt:`greater than`,lt:`less than`,ge:`greater than or equals`,le:`less than or equals`,sa:`starts after`,eb:`ends before`,ap:`approximately`,sw:`starts with`,contains:`contains`,exact:`exact`,text:`text`,not:`not`,above:`above`,below:`below`,in:`in`,"not-in":`not in`,"of-type":`of type`,missing:`missing`,present:`present`,identifier:`identifier`,iterate:`iterate`};function nR(e,t){return{...e,filters:t,offset:0,name:void 0}}function rR(e,t){return nR(e,(e.filters??[]).filter(e=>e.code!==t))}function iR(e,t,n,r,i){i&&(e=rR(e,t));let a=[];return e.filters&&a.push(...e.filters),a.push({code:t,operator:n,value:r??``}),nR(e,a)}function aR(e,t){if(!e.filters)return e;let n=[...e.filters];return n.splice(t,1),{...e,filters:n,name:void 0}}function oR(e,t){return lR(e,t,-1)}function sR(e,t){return lR(e,t,0)}function cR(e,t){return lR(e,t,1)}function lR(e,t,n){let r=new Date;r.setDate(r.getDate()+n),r.setHours(0,0,0,0);let i=new Date(r.getTime());return i.setDate(i.getDate()+1),i.setTime(i.getTime()-1),gR(e,t,r,i)}function uR(e,t){let n=new Date;return gR(e,t,n,new Date(n.getTime()+1440*60*1e3))}function dR(e,t){return mR(e,t,-1)}function fR(e,t){return mR(e,t,0)}function pR(e,t){return mR(e,t,1)}function mR(e,t,n){let r=new Date;r.setMonth(r.getMonth()+n),r.setDate(1),r.setHours(0,0,0,0);let i=new Date(r.getTime());return i.setMonth(i.getMonth()+1),i.setDate(1),i.setHours(0,0,0,0),i.setTime(i.getTime()-1),gR(e,t,r,i)}function hR(e,t){let n=new Date;return n.setMonth(0),n.setDate(1),n.setHours(0,0,0,0),gR(e,t,n,new Date)}function gR(e,t,n,r){return e=rR(e,t),e=_R(e,t,Z.GREATER_THAN_OR_EQUALS,n),e=_R(e,t,Z.LESS_THAN_OR_EQUALS,r),e}function _R(e,t,n,r){return iR(e,t,n,r.toISOString())}function vR(e,t,n=!0){return iR(e,t,Z.MISSING,n.toString())}function yR(e,t){return e.offset===t?e:{...e,offset:t,name:void 0}}function bR(e,t){let n=e.count??20;return yR(e,(t-1)*n)}function xR(e,t,n){return t===SR(e)&&n!==void 0&&n===CR(e)?e:{...e,sortRules:[{code:t,descending:!!n}],name:void 0}}function SR(e){let t=e.sortRules;if(!t||t.length===0)return;let n=t[0].code;return n.startsWith(`-`)?n.substr(1):n}function CR(e){let t=e.sortRules;return!t||t.length===0?!1:!!t[0].descending}function wR(e){return eR[e.type]}function TR(e){return tR[e]??``}function ER(e){let t=e;return t.includes(`.`)&&(t=t.split(`.`).pop()),t===`versionId`?`Version ID`:(t=t.replace(`[x]`,``),t=t.replaceAll(/([A-Z])/g,` $1`),t=t.replaceAll(/[-_]/g,` `),t=t.replaceAll(/\s+/g,` `),t=t.trim(),t.toLowerCase()===`id`?`ID`:t.split(/\s/).map(HC).join(` `))}function DR(e,t){let n=t.name;return n===`id`?(0,I.jsx)(dM,{to:`/${e.resourceType}/${e.id}`,children:e.id}):n===`meta.versionId`?e.meta?.versionId:n===`_lastUpdated`?dw(e.meta?.lastUpdated):`${e.resourceType}.${t.name}`===t.elementDefinition?.path?OR(e,t.elementDefinition):t.searchParams?.length===1&&t.name===t.searchParams[0].code?kR(e,t.searchParams[0]):null}function OR(e,t){let n=t.path?.split(`.`)?.pop()?.replaceAll(`[x]`,``)??``,[r,i]=AF({type:e.resourceType,value:e},n);return r?(0,I.jsx)(KF,{path:t.path,property:t,propertyType:i,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function kR(e,t){let n=RT(t.expression,[{type:e.resourceType,value:e}]);return!n||n.length===0?null:(0,I.jsx)(I.Fragment,{children:n.map((e,t)=>(0,I.jsx)(KF,{propertyType:e.type,value:e.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${t}-${n.length}`))})}function AR(e){let t=(0,b.useRef)(!1),[n,r]=(0,b.useState)({search:JSON.parse(vC(e.search))}),[i,a]=(0,b.useState)(!1);(0,b.useEffect)(()=>{r({search:e.search})},[e.search]);let o=(0,b.useMemo)(()=>{if(!e.visible)return[];let t=e.search.resourceType;return XC(jR(pS(t),Nw(t))).map(e=>({value:e,label:ER(e)}))},[e.visible,e.search.resourceType]);function s(e){r({search:{...n.search,fields:e}})}return(0,I.jsx)(Bh,{title:`Fields`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:()=>{e.onCancel()},size:`auto`,withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{t.current=i},onClick:()=>{t.current||e.onCancel(),t.current=!1},children:(0,I.jsx)(`div`,{"data-testid":`overlay-child`})},children:(0,I.jsxs)(G,{children:[(0,I.jsx)(hg,{style:{width:550},placeholder:`Select fields to display`,data:o,value:n.search.fields??[],onChange:s,onDropdownOpen:()=>a(!0),onDropdownClose:()=>a(!1),maxDropdownHeight:`250px`,clearButtonProps:{"aria-label":`Clear selection`},clearable:!0,searchable:!0}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{onClick:()=>e.onOk(n.search),children:`OK`})})]})})}function jR(e,t){let n=[],r=new Set,i=new Set;for(let t of Object.keys(e.elements))n.push(t),r.add(t.toLowerCase()),i.add(ER(t));if(t)for(let e of Object.keys(t)){let t=ER(e);!r.has(e)&&!i.has(t)&&(n.push(e),r.add(e),i.add(t))}return n}function MR(e){let t=GO(e.resourceType,e.searchParam),n=e.name??`filter-value`;switch(t.type){case WO.REFERENCE:return(0,I.jsx)(NI,{name:n,defaultValue:e.defaultValue?{reference:e.defaultValue}:void 0,targetTypes:e.searchParam.target,autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(t.reference):e.onChange(``)}});case WO.BOOLEAN:return(0,I.jsx)(Bd,{name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultChecked:e.defaultValue===`true`,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.checked.toString())});case WO.DATE:return(0,I.jsx)(yb,{type:`date`,name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value)});case WO.DATETIME:return(0,I.jsx)(mI,{name:n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case WO.NUMBER:return(0,I.jsx)(yb,{type:`number`,name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value)});case WO.QUANTITY:return(0,I.jsx)(SI,{name:n,path:``,defaultValue:NR(e.defaultValue),autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(`${t.value}`):e.onChange(``)}});default:return(0,I.jsx)(yb,{name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value),placeholder:`Search value`})}}function NR(e){if(e){let[t,n,r]=e.split(`|`);if(t)return{value:Number.parseFloat(t),system:n,unit:r}}}function PR(e){let[t,n]=(0,b.useState)(jC(e.search)),r=(0,b.useRef)(t);(0,b.useLayoutEffect)(()=>{r.current=t}),(0,b.useEffect)(()=>{n(jC(e.search))},[e.search]);function i(e){n(iR(r.current,e.code,e.operator,e.value))}let a=e.search.resourceType,o=Nw(a)??{},s=t.filters||[];return(0,I.jsx)(Bh,{title:`Filters`,closeButtonProps:{"aria-label":`Close`},size:900,opened:e.visible,onClose:e.onCancel,children:(0,I.jsxs)(WN,{onSubmit:()=>e.onOk(r.current),children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`table`,{children:[(0,I.jsxs)(`colgroup`,{children:[(0,I.jsx)(`col`,{style:{width:200}}),(0,I.jsx)(`col`,{style:{width:200}}),(0,I.jsx)(`col`,{style:{width:380}}),(0,I.jsx)(`col`,{style:{width:40}})]}),(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Field`}),(0,I.jsx)(`th`,{children:`Operation`}),(0,I.jsx)(`th`,{children:`Value`}),(0,I.jsx)(`th`,{})]})}),(0,I.jsx)(`tbody`,{children:s.map((e,t)=>(0,I.jsx)(FR,{id:`filter-${t}-row`,resourceType:a,searchParams:o,value:e,onChange:e=>{let i=[...s];i[t]=e,n(nR(r.current,i))},onDelete:()=>n(aR(r.current,t))},`filter-${t}-row`))})]}),(0,I.jsx)(BI,{propertyDisplayName:`Filter`,onClick:()=>i({})})]}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(GN,{children:`OK`})})]})})}function FR(e){let t=e.value;function n(t){e.onChange({code:t,operator:Z.EQUALS,value:``})}function r(n){e.onChange({code:t.code,operator:n,value:``})}function i(n){e.onChange({code:t.code,operator:t.operator,value:n})}let a=e.searchParams[t.code],o=a&&wR(a);return(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(yg,{"data-testid":`${e.id}-filter-field`,defaultValue:e.value.code,onChange:e=>n(e.currentTarget.value),data:[``,...Object.keys(e.searchParams).map(e=>({value:e,label:ER(e)}))]})}),(0,I.jsx)(`td`,{children:o&&(0,I.jsx)(yg,{"data-testid":`${e.id}-filter-operation`,defaultValue:t.operator,onChange:e=>r(e.currentTarget.value),data:[``,...o.map(e=>({value:e,label:TR(e)}))]},`${e.id}-filter-value-${e.value.code}`)}),(0,I.jsx)(`td`,{children:a&&t.operator&&(0,I.jsx)(MR,{name:`${e.id}-filter-value`,resourceType:e.resourceType,searchParam:a,defaultValue:t.value,onChange:i},`${e.id}-filter-value-${e.value.code}-${e.value.operator}`)}),(0,I.jsx)(`td`,{children:e.onDelete&&(0,I.jsx)(vl,{variant:`outline`,color:`red`,radius:`xl`,"aria-label":`Delete filter`,onClick:e.onDelete,children:(0,I.jsx)($j,{style:{width:`70%`,height:`70%`},stroke:1.5})})})]})}function IR(e){let[t,n]=(0,b.useState)(e.defaultValue??``);if(!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:t})}return(0,I.jsx)(Bh,{title:e.title,size:`xl`,opened:e.visible,onClose:e.onCancel,children:(0,I.jsx)(WN,{onSubmit:r,children:(0,I.jsxs)(Fp,{children:[(0,I.jsx)(Fp.Col,{span:10,children:(0,I.jsx)(MR,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:t,autoFocus:!0,onChange:n})}),(0,I.jsx)(Fp.Col,{span:2,children:(0,I.jsx)(U,{onClick:r,fullWidth:!0,children:`OK`})})]})})})}function LR(e){let{resourceType:t,filter:n}=e,r=Uw.types[t].searchParams?.[n.code];if(r){if(r.type===`reference`&&(n.operator===Z.EQUALS||n.operator===Z.NOT_EQUALS))return(0,I.jsx)(oL,{value:{reference:n.value}});let e=GO(t,r);if(n.code===`_lastUpdated`||e.type===WO.DATETIME)return(0,I.jsx)(I.Fragment,{children:dw(n.value)})}return(0,I.jsx)(I.Fragment,{children:n.value})}function RR(e){if(!e.searchParams)return null;function t(t,n){i(xR(e.search,t.code,n))}function n(t){i(rR(e.search,t.code))}function r(t,n){e.onPrompt(t,{code:t.code,operator:n,value:``})}function i(t){e.onChange(t)}return e.searchParams.length===1?(0,I.jsx)(zR,{search:e.search,searchParam:e.searchParams[0],onSort:t,onPrompt:r,onChange:i,onClear:n}):(0,I.jsx)(W.Dropdown,{children:e.searchParams.map(e=>(0,I.jsx)(W.Item,{children:ER(e.code)},e.code))})}function zR(e){switch(e.searchParam.type){case`date`:return(0,I.jsx)(BR,{...e});case`number`:case`quantity`:return(0,I.jsx)(VR,{...e});case`reference`:return(0,I.jsx)(HR,{...e});case`string`:return(0,I.jsx)(UR,{...e});case`token`:return(0,I.jsx)(WR,{...e});case`uri`:return(0,I.jsx)(GR,{...e});default:return(0,I.jsxs)(I.Fragment,{children:[`Unknown search param type: `,e.searchParam.type]})}}function BR(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Oldest to Newest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Newest to Oldest`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT_EQUALS),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(xj,{size:14}),onClick:()=>e.onPrompt(t,Z.ENDS_BEFORE),children:`Before...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(bj,{size:14}),onClick:()=>e.onPrompt(t,Z.STARTS_AFTER),children:`After...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(LA,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Between...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(cR(e.search,n)),children:`Tomorrow`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(sR(e.search,n)),children:`Today`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(oR(e.search,n)),children:`Yesterday`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(uR(e.search,n)),children:`Next 24 Hours`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(pR(e.search,n)),children:`Next Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(fR(e.search,n)),children:`This Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(dR(e.search,n)),children:`Last Month`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(hR(e.search,n)),children:`Year to date`}),(0,I.jsx)(KR,{...e})]})}function VR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Smallest to Largest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Largest to Smallest`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT_EQUALS),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(bj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN),children:`Greater than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN_OR_EQUALS),children:`Greater than or equal to...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(xj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN),children:`Less than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN_OR_EQUALS),children:`Less than or equal to...`}),(0,I.jsx)(KR,{...e})]})}function HR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(KR,{...e})]})}function UR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort A to Z`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Z to A`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(VA,{size:14}),onClick:()=>e.onPrompt(t,Z.CONTAINS),children:`Contains...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(BA,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Does not contain...`}),(0,I.jsx)(KR,{...e})]})}function WR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.TEXT),children:`Text contains...`}),(0,I.jsx)(KR,{...e})]})}function GR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(KR,{...e})]})}function KR(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(PA,{size:14}),onClick:()=>e.onChange(vR(e.search,n)),children:`Missing`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(NA,{size:14}),onClick:()=>e.onChange(vR(e.search,n,!1)),children:`Not missing`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)($j,{size:14}),onClick:()=>e.onClear(t),children:`Clear filters`})]})}function qR(e){switch(e){case`next`:return{"aria-label":`Next page`};case`previous`:return{"aria-label":`Previous page`};case`first`:return{"aria-label":`First page`};case`last`:return{"aria-label":`Last page`};default:return{}}}var JR={root:`_root_vlout_1`,table:`_table_vlout_8`,tr:`_tr_vlout_12`,th:`_th_vlout_18`,control:`_control_vlout_22`,icon:`_icon_vlout_31`};function YR(e){let t=e.resourceType,n=[];for(let r of e.fields||[`id`,`_lastUpdated`])n.push(XR(t,r));return n}function XR(e,t){if(t===`_lastUpdated`)return{name:`_lastUpdated`,searchParams:[{resourceType:`SearchParameter`,base:[`Resource`],code:`_lastUpdated`,name:`_lastUpdated`,type:`date`,expression:`Resource.meta.lastUpdated`}]};if(t===`meta.versionId`)return{name:`meta.versionId`,searchParams:[{resourceType:`SearchParameter`,base:[`Resource`],code:`_versionId`,name:`_versionId`,type:`token`,expression:`Resource.meta.versionId`}]};let n=zw(e,t),r=Pw(e,t.toLowerCase());if(n&&r)return{name:t,elementDefinition:n,searchParams:[r]};if(n){let r=Nw(e),i;if(r){let n=RegExp(`${e}\\.${t.replaceAll(`[x]`,``)}([^\\w-]|$)`);i=Object.values(r).filter(e=>!!e.expression&&n.test(e?.expression)),i.length===0&&(i=void 0)}return{name:t,elementDefinition:n,searchParams:i}}return r?{name:t,elementDefinition:GO(e,r).elementDefinitions?.[0],searchParams:[r]}:{name:t}}var ZR=class extends Event{definition;constructor(e){super(`change`),this.definition=e}},QR=class extends Event{response;constructor(e){super(`load`),this.response=e}},$R=class extends Event{resource;browserEvent;constructor(e,t){super(`click`),this.resource=e,this.browserEvent=t}};function ez(e){let t=Q(),[n,r]=(0,b.useState)(),{search:i,onLoad:a}=e,[o,s]=(0,b.useState)(i);TC(i,o)||s(i);let[c,l]=(0,b.useState)({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),u=(0,b.useRef)(c);(0,b.useLayoutEffect)(()=>{u.current=c});let d=o.total??`accurate`,f=(0,b.useCallback)(e=>{r(void 0),t.requestSchema(o.resourceType).then(()=>t.search(o.resourceType,cE({...o,total:d,fields:void 0}),e)).then(e=>{l({...u.current,searchResponse:e}),a&&a(new QR(e))}).catch(e=>{l({...u.current,searchResponse:void 0}),r(Zx(e))})},[t,o,d,a]),p=(0,b.useCallback)(()=>{l({...u.current,searchResponse:void 0}),f({cache:`reload`})},[f]);(0,b.useEffect)(()=>{f()},[f]);function m(e,t){e.stopPropagation();let n=e.target.checked,r={...u.current.selected};n?r[t]=!0:delete r[t],l({...u.current,selected:r})}function h(e){e.stopPropagation();let t=e.target.checked,n={},r=u.current.searchResponse;t&&r?.entry&&r.entry.forEach(e=>{e.resource?.id&&(n[e.resource.id]=!0)}),l({...u.current,selected:n})}function g(){if(!c.searchResponse?.entry||c.searchResponse.entry.length===0)return!1;for(let e of c.searchResponse.entry)if(e.resource?.id&&!c.selected[e.resource.id])return!1;return!0}function _(t){e.onChange&&e.onChange(new ZR(t))}function v(t,n){if(sM(t.target)||t.button===2)return;aM(t);let r=oM(t);!r&&e.onClick&&e.onClick(new $R(n,t)),r&&e.onAuxClick&&e.onAuxClick(new $R(n,t))}function y(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(n)return(0,I.jsx)(lF,{outcome:n});if(!dS(o.resourceType))return(0,I.jsx)(hd,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(il,{})});let x=e.checkboxesEnabled,S=YR(o),C=o.resourceType,w=c.searchResponse,T=(w?.entry)?.map(e=>e.resource),E=`subtle`,D=`gray`,O=window.innerWidth<768;return(0,I.jsxs)(`div`,{className:JR.root,"data-testid":`search-control`,children:[!e.hideToolbar&&(0,I.jsxs)(V,{justify:`space-between`,mb:`xl`,children:[(0,I.jsxs)(V,{gap:2,children:[(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(ZA,{size:16}),onClick:()=>l({...u.current,fieldEditorVisible:!0,dialogOpenTime:Date.now()}),children:`Fields`}),(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(dj,{size:16}),onClick:()=>l({...u.current,filterEditorVisible:!0,dialogOpenTime:Date.now()}),children:`Filters`}),e.onNew&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(uj,{size:16}),onClick:e.onNew,children:`New...`}),!O&&y()&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(Kj,{size:16}),onClick:e.onExport?e.onExport:()=>l({...u.current,exportDialogVisible:!0,dialogOpenTime:Date.now()}),children:`Export...`}),!O&&e.onDelete&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(Yj,{size:16}),onClick:()=>e.onDelete(Object.keys(c.selected)),children:`Delete...`}),!O&&e.onBulk&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(IA,{size:16}),onClick:()=>e.onBulk(Object.keys(c.selected)),children:`Bulk...`})]}),(0,I.jsxs)(V,{gap:2,children:[w&&(0,I.jsxs)(H,{size:`xs`,c:`dimmed`,"data-testid":`count-display`,children:[iz(o,w).toLocaleString(),`-`,az(o,w).toLocaleString(),w.total!==void 0&&` of ${o.total===`estimate`?`~`:``}${w.total?.toLocaleString()}`]}),(0,I.jsx)(vl,{variant:E,color:D,title:`Refresh`,onClick:p,children:(0,I.jsx)(Pj,{size:16})})]})]}),(0,I.jsxs)(K,{className:JR.table,children:[(0,I.jsxs)(K.Thead,{children:[(0,I.jsxs)(K.Tr,{children:[x&&(0,I.jsx)(K.Th,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"aria-label":`all-checkbox`,"data-testid":`all-checkbox`,checked:g(),onChange:e=>h(e)})}),S.map(e=>(0,I.jsx)(K.Th,{children:(0,I.jsxs)(W,{shadow:`md`,width:240,position:`bottom-end`,children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(qc,{className:JR.control,p:2,children:(0,I.jsxs)(V,{justify:`space-between`,wrap:`nowrap`,children:[(0,I.jsx)(H,{fw:500,children:ER(e.name)}),(0,I.jsx)(hd,{className:JR.icon,children:(0,I.jsx)(OA,{size:14,stroke:1.5})})]})})}),(0,I.jsx)(RR,{search:o,searchParams:e.searchParams,onPrompt:(e,t)=>{l({...u.current,filterDialogVisible:!0,filterDialogSearchParam:e,filterDialogFilter:t,dialogOpenTime:Date.now()})},onChange:e=>{_(e)}})]})},e.name))]}),!e.hideFilters&&(0,I.jsxs)(K.Tr,{children:[x&&(0,I.jsx)(K.Th,{}),S.map(e=>(0,I.jsx)(K.Th,{children:e.searchParams&&(0,I.jsx)(tz,{resourceType:C,searchParams:e.searchParams,filters:o.filters})},e.name))]})]}),(0,I.jsx)(K.Tbody,{children:T?.map(e=>e&&(0,I.jsxs)(K.Tr,{className:JR.tr,"data-testid":`search-control-row`,onClick:t=>v(t,e),onAuxClick:t=>v(t,e),children:[x&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${e.id}`,checked:!!c.selected[e.id],onChange:t=>m(t,e.id)})}),S.map(t=>(0,I.jsx)(K.Td,{children:DR(e,t)},t.name))]},e.id))})]}),!T?.length&&(0,I.jsx)(RP,{children:(0,I.jsx)(hd,{style:{height:150},children:(0,I.jsx)(H,{size:`xl`,c:`dimmed`,children:`No results`})})}),w&&(0,I.jsx)(hd,{m:`md`,p:`md`,children:(0,I.jsx)(X_,{value:nz(o),total:rz(o,w),onChange:e=>_(bR(o,e)),getControlProps:qR})}),(0,I.jsx)(AR,{search:o,visible:c.fieldEditorVisible,onOk:e=>{_(e),l({...u.current,fieldEditorVisible:!1})},onCancel:()=>{l({...u.current,fieldEditorVisible:!1})}},`search-field-editor-${c.dialogOpenTime}`),(0,I.jsx)(PR,{search:o,visible:c.filterEditorVisible,onOk:e=>{_(e),l({...u.current,filterEditorVisible:!1})},onCancel:()=>{l({...u.current,filterEditorVisible:!1})}},`search-filter-editor-${c.dialogOpenTime}`),(0,I.jsx)(QL,{visible:c.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{l({...u.current,exportDialogVisible:!1})}},`search-export-dialog-${c.dialogOpenTime}`),(0,I.jsx)(IR,{visible:c.filterDialogVisible,title:c.filterDialogSearchParam?.code?ER(c.filterDialogSearchParam.code):``,resourceType:C,searchParam:c.filterDialogSearchParam,filter:c.filterDialogFilter,defaultValue:``,onOk:e=>{_(iR(o,e.code,e.operator,e.value)),l({...u.current,filterDialogVisible:!1})},onCancel:()=>{l({...u.current,filterDialogVisible:!1})}},`search-filter-dialog-${c.dialogOpenTime}`)]})}function tz(e){let t=(e.filters??[]).filter(t=>e.searchParams.find(e=>e.code===t.code));return t.length===0?(0,I.jsx)(`span`,{children:`no filters`}):(0,I.jsx)(I.Fragment,{children:t.map(t=>(0,I.jsxs)(`div`,{children:[TR(t.operator),`\xA0`,(0,I.jsx)(LR,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function nz(e){return Math.floor((e.offset??0)/(e.count??20))+1}function rz(e,t){let n=e.count??20,r=oz(e,t);return Math.ceil(r/n)}function iz(e,t){return Math.min(oz(e,t),(e.offset??0)+1)}function az(e,t){return Math.max(iz(e,t)+(t.entry?.length??0)-1,0)}function oz(e,t){let n=t.total;return n===void 0&&(n=(e.offset??0)+(t.entry?.length??0)+ +!!t.link?.some(e=>e.relation===`next`)),n}function sz(e){let t=Q(),[n,r]=(0,b.useState)(!1),[i,a]=(0,b.useState)(),{query:o,fields:s}=e,[c,l]=(0,b.useState)(),[u,d]=(0,b.useState)({});(0,b.useEffect)(()=>{a(void 0),t.graphql(o).then(l).catch(e=>a(Zx(e)))},[t,o]);function f(e,t){e.stopPropagation();let n=e.target.checked,r={...u};n?r[t]=!0:delete r[t],d(r)}function p(e){e.stopPropagation();let t=e.target.checked,n={},r=c?.data.ResourceList;t&&r&&r.forEach(e=>{e.id&&(n[e.id]=!0)}),d(n)}function m(){let e=c?.data.ResourceList;if(!e||e.length===0)return!1;for(let t of e)if(t.id&&!u[t.id])return!1;return!0}function h(t,n){sM(t.target)||(aM(t),t.button!==1&&e.onClick&&e.onClick(new $R(n,t)),t.button===1&&e.onAuxClick&&e.onAuxClick(new $R(n,t)))}if((0,b.useEffect)(()=>{t.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[t,e.resourceType]),!n)return(0,I.jsx)(il,{});let g=e.checkboxesEnabled;return(0,I.jsxs)(`div`,{onContextMenu:e=>aM(e),"data-testid":`search-control`,children:[(0,I.jsxs)(K,{children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[g&&(0,I.jsx)(K.Th,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"aria-label":`all-checkbox`,"data-testid":`all-checkbox`,checked:m(),onChange:e=>p(e)})}),s.map(e=>(0,I.jsx)(K.Th,{children:e.name},e.name))]})}),(0,I.jsx)(K.Tbody,{children:c?.data.ResourceList.map(e=>e&&(0,I.jsxs)(K.Tr,{"data-testid":`search-control-row`,onClick:t=>h(t,e),onAuxClick:t=>h(t,e),children:[g&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${e.id}`,checked:!!u[e.id],onChange:t=>f(t,e.id)})}),s.map(t=>(0,I.jsx)(K.Td,{children:(0,I.jsx)(ZL,{propertyType:t.propertyType,path:t.fhirPath,resource:e})},t.name))]},e.id))})]}),c?.data.ResourceList.length===0&&(0,I.jsx)(`div`,{"data-testid":`empty-search`,children:`No results`}),i&&(0,I.jsx)(`div`,{"data-testid":`search-error`,children:(0,I.jsx)(`pre`,{style:{textAlign:`left`},children:JSON.stringify(i,void 0,2)})}),e.onBulk&&(0,I.jsx)(U,{onClick:()=>e.onBulk(Object.keys(u)),children:`Bulk...`})]})}var cz=(0,b.memo)(sz),lz={root:`_root_1fbwr_1`,entry:`_entry_1fbwr_8`,key:`_key_1fbwr_13`,value:`_value_1fbwr_20`};function uz(e){return(0,I.jsx)(Hc,{children:(0,I.jsx)(`div`,{className:lz.root,children:e.children})})}uz.Entry=function(e){return(0,I.jsx)(`div`,{className:lz.entry,children:e.children})},uz.Key=function(e){return(0,I.jsx)(`div`,{className:lz.key,children:e.children})},uz.Value=function(e){return(0,I.jsx)(`div`,{className:lz.value,children:e.children})};var dz={list:`_list_y4z6g_1`,link:`_link_y4z6g_6`};function fz(e){let{baseUrl:t,tabs:n,children:r,...i}=e,a=pz(n),o=uk(),[s,c]=(0,b.useState)(()=>{let e=LE.getPathname().split(`/`).pop();if(e){let t=e.toLowerCase(),n=a.find(e=>e.value.split(/[?#]/)[0].toLowerCase()===t);if(n)return n.value}return a[0].value});function l(e){e||=a[0].value,c(e),o(`${t}/${e}`)}return(0,I.jsxs)(vb,{value:s,onChange:l,...i,children:[(0,I.jsx)(vb.List,{className:dz.list,children:a.map(e=>(0,I.jsx)(vb.Tab,{value:e.value,children:(0,I.jsx)(pu,{className:dz.link,href:`${t}/${e.value}`,onClick:mz,children:e.label})},e.value))}),r]})}function pz(e){return e.map(e=>PC(e)?{label:e,value:e.toLowerCase()}:e)}function mz(e){oM(e)||e.preventDefault()}function hz(e){let{group:t}=e;return(0,I.jsx)(Xc,{withBorder:!0,radius:`md`,p:`xs`,display:`flex`,style:{alignItems:`center`,justifyContent:`center`},children:(0,I.jsxs)(V,{children:[t.measureScore&&(0,I.jsx)(vz,{group:t}),!t.measureScore&&(0,I.jsx)(_z,{group:t})]})})}function gz(e){let{measure:t}=e;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(H,{fz:`md`,fw:500,mb:8,children:t.title}),(0,I.jsx)(H,{fz:`xs`,c:`dimmed`,mb:8,children:t.subtitle})]})}function _z(e){let{group:t}=e,n=t.population,r=n?.find(e=>xw(e.code)===`numerator`),i=n?.find(e=>xw(e.code)===`denominator`),a=r?.count,o=i?.count;if(o===0)return(0,I.jsxs)(z,{children:[(0,I.jsx)(q,{order:3,children:`Not Applicable`}),(0,I.jsx)(H,{children:`Denominator: ${o}`})]});if(a===void 0||o===void 0)return(0,I.jsxs)(z,{children:[(0,I.jsx)(q,{order:3,children:`Insufficient Data`}),(0,I.jsx)(H,{children:`Numerator: ${a}`}),(0,I.jsx)(H,{children:`Denominator: ${o}`})]});let s=a/o*100;return(0,I.jsx)(ey,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:bz(s)}],label:(0,I.jsx)(ru,{justify:`center`,children:(0,I.jsxs)(H,{fw:700,fz:18,children:[a,` / `,o]})})})}function vz(e){let{group:t}=e;return(0,I.jsx)(I.Fragment,{children:(t.measureScore?.unit??t.measureScore?.code)===`%`?(0,I.jsx)(ey,{size:120,thickness:12,roundCaps:!0,sections:[{value:yz(t),color:bz(t?.measureScore?.value??0)}],label:(0,I.jsx)(ru,{justify:`center`,children:(0,I.jsx)(H,{fw:700,fz:18,children:(0,I.jsx)(IF,{value:t.measureScore})})})}):(0,I.jsx)(ru,{h:120,align:`center`,children:(0,I.jsx)(q,{order:3,children:(0,I.jsx)(IF,{value:t.measureScore})})})})}function yz(e){let t=e.measureScore?.value,n=e.measureScore?.unit;return t?t<=1&&n===`%`?t*100:t:0}function bz(e){return e<=33?`red`:e<=67?`yellow`:`green`}function xz(e){let t=bk(e.measureReport),[n]=fA(`Measure`,{url:t?.measure});return t?(0,I.jsxs)(z,{children:[n&&(0,I.jsx)(gz,{measure:n}),(0,I.jsx)(_y,{cols:{base:3,sm:1},spacing:{base:`md`,sm:`sm`},children:t.group?.map((e,t)=>(0,I.jsx)(hz,{group:e},e.id??t))})]}):null}var Sz=`patient-accounts`,Cz=`Patient Accounts`,wz=[`Organization`,`HealthcareService`,`CareTeam`];function Tz(e){let{patient:t}=e,n=Q(),r=n.isProjectAdmin()||n.isSuperAdmin(),i=(0,b.useMemo)(()=>sC(t.meta)??[],[t.meta]),[a,o]=(0,b.useState)(i),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!0),[d,f]=(0,b.useState)(!1),p=(0,b.useMemo)(()=>{let e=[];for(let t of a)i.some(e=>e.reference===t.reference)||e.push({reference:t,type:`addition`});for(let t of i)a.some(e=>e.reference===t.reference)||e.push({reference:t,type:`removal`});return e},[i,a]),m=p.length>0,h=(0,b.useCallback)(e=>{e?.reference&&(a.some(t=>t.reference===e.reference)||o(t=>[...t,e]))},[a]),g=(0,b.useCallback)(e=>{o(t=>t.filter(t=>t.reference!==e))},[]),_=(0,b.useCallback)(async()=>{let r=t.id;if(!r){zb.show({id:Sz,title:Cz,color:`red`,message:`Cannot update accounts: Patient resource has no ID.`,icon:(0,I.jsx)($j,{size:`1rem`}),autoClose:!1,withCloseButton:!0});return}f(!0),c(!1);let i=n.fhirUrl(`Patient`,r,`$set-accounts`),o={resourceType:`Parameters`,parameter:[...a.map(e=>({name:`accounts`,valueReference:{reference:e.reference}})),{name:`propagate`,valueBoolean:l}]};zb.show({id:Sz,title:Cz,loading:!0,message:l?`Saving account changes and propagating to compartment...`:`Saving account changes...`,autoClose:!1,withCloseButton:!1});try{let t={};l&&(t.Prefer=`respond-async`),await n.post(i,o,void 0,{headers:t}),n.invalidateUrl(n.fhirUrl(`Patient`,r)),zb.update({id:Sz,title:Cz,color:`green`,message:l?`Account changes saved. Compartment updates are being applied.`:`Account changes saved.`,icon:(0,I.jsx)(WA,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0}),e.onSaved?.()}catch(e){zb.update({id:Sz,title:Cz,color:`red`,message:Y(e),icon:(0,I.jsx)($j,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}finally{f(!1)}},[n,t,a,l,e]);return r?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(G,{children:[(0,I.jsx)(q,{order:3,children:`Current Accounts`}),a.length===0?(0,I.jsx)(H,{c:`dimmed`,children:`No accounts assigned to this patient.`}):(0,I.jsxs)(K,{children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{children:`Type`}),(0,I.jsx)(K.Th,{children:`Account`}),(0,I.jsx)(K.Th,{})]})}),(0,I.jsx)(K.Tbody,{children:a.map(e=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:(0,I.jsx)(Ez,{reference:e})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(sL,{value:e,link:!0})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(vl,{variant:`subtle`,color:`red`,"aria-label":`Remove ${e.reference}`,onClick:()=>g(e.reference),children:(0,I.jsx)($j,{size:16})})})]},e.reference))})]}),(0,I.jsx)(bp,{}),(0,I.jsx)(q,{order:4,children:`Add Account`}),(0,I.jsx)(NI,{name:`newAccount`,placeholder:`Search for Organization, HealthcareService, or CareTeam...`,targetTypes:wz,onChange:e=>{e&&h(e)}}),m&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(bp,{}),(0,I.jsx)(q,{order:4,children:`Pending Changes`}),(0,I.jsx)(G,{gap:`xs`,children:p.map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[e.type===`addition`?(0,I.jsx)(td,{color:`green`,variant:`light`,leftSection:(0,I.jsx)(Mj,{size:12}),children:`Add`}):(0,I.jsx)(td,{color:`red`,variant:`light`,leftSection:(0,I.jsx)(wj,{size:12}),children:`Remove`}),(0,I.jsx)(sL,{value:e.reference,link:!0})]},`${e.type}-${e.reference.reference}`))})]}),(0,I.jsx)(z,{children:(0,I.jsx)(U,{disabled:!m||d,onClick:()=>c(!0),children:`Save Changes`})})]}),(0,I.jsx)(Bh,{opened:s,onClose:()=>c(!1),title:`Confirm Account Changes`,size:`md`,keepMounted:!0,children:(0,I.jsxs)(G,{children:[(0,I.jsxs)(H,{children:[`The following changes will be applied to Patient`,` `,(0,I.jsxs)(`strong`,{children:[t.name?.[0]?.given?.join(` `),` `,t.name?.[0]?.family]}),`:`]}),p.filter(e=>e.type===`addition`).length>0&&(0,I.jsxs)(z,{children:[(0,I.jsx)(H,{fw:600,c:`green`,children:`Adding:`}),(0,I.jsx)(G,{gap:`xs`,mt:`xs`,children:p.filter(e=>e.type===`addition`).map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(Mj,{size:14,color:`green`}),(0,I.jsx)(sL,{value:e.reference})]},e.reference.reference))})]}),p.filter(e=>e.type===`removal`).length>0&&(0,I.jsxs)(z,{children:[(0,I.jsx)(H,{fw:600,c:`red`,children:`Removing:`}),(0,I.jsx)(G,{gap:`xs`,mt:`xs`,children:p.filter(e=>e.type===`removal`).map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(wj,{size:14,color:`red`}),(0,I.jsx)(sL,{value:e.reference})]},e.reference.reference))})]}),(0,I.jsx)(Bd,{label:`Propagate changes to all resources in this patient's compartment`,checked:l,onChange:e=>u(e.currentTarget.checked)}),(0,I.jsxs)(V,{justify:`right`,mt:`md`,children:[(0,I.jsx)(U,{variant:`default`,onClick:()=>c(!1),children:`Cancel`}),(0,I.jsx)(U,{onClick:_,loading:d,children:`Confirm`})]})]})})]}):(0,I.jsx)(ou,{color:`blue`,title:`Admin access required`,children:`You need project admin access to manage patient account assignments.`})}function Ez({reference:e}){let t=e.reference?.split(`/`)[0]??`Unknown`;return(0,I.jsx)(td,{variant:`light`,color:{Organization:`blue`,HealthcareService:`teal`,CareTeam:`violet`}[t]??`gray`,size:`sm`,children:t})}var Dz=`patient-export`,Oz=`Patient Export`,kz={everything:{operation:`$everything`,extension:`json`,contentType:ZE.FHIR_JSON},summary:{operation:`$summary`,extension:`json`,contentType:ZE.FHIR_JSON},ccda:{operation:`$ccda-export`,extension:`xml`,contentType:ZE.CDA_XML},ccdaReferral:{operation:`$ccda-export`,type:`referral`,extension:`xml`,contentType:ZE.CDA_XML}};function Az(e){let t=Q(),{patient:n}=e,[r,i]=(0,b.useState)(`everything`),[a,o]=(0,b.useState)(!1);return(0,I.jsx)(WN,{onSubmit:(0,b.useCallback)(async e=>{let i=oC(n),{operation:o,type:s,contentType:c,extension:l}=kz[r],u=t.fhirUrl(`Patient`,i,o),d={};r===`everything`&&a&&u.searchParams.set(`_inlineAttachments`,`true`),s&&(d.type=s),e.author&&(d.author={reference:e.author}),e.authoredOn&&(d.authoredOn=pI(e.authoredOn)),e.startDate&&(d.start=e.startDate),e.endDate&&(d.end=e.endDate),zb.show({id:Dz,title:Oz,loading:!0,message:`Exporting...`,autoClose:!1,withCloseButton:!1});try{jz(await t.post(u,d,void 0,{cache:`no-cache`,headers:{Accept:c}}),`Patient-export-${i}-${new Date().toISOString().replaceAll(`:`,`-`)}.${l}`,c),zb.update({id:Dz,title:Oz,color:`green`,message:`Done`,icon:(0,I.jsx)(WA,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0})}catch(e){zb.update({id:Dz,title:Oz,color:`red`,message:Y(e),icon:(0,I.jsx)($j,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}},[t,n,r,a]),children:(0,I.jsxs)(G,{children:[(0,I.jsx)(tI,{title:`Export Format`,description:`Required`,withAsterisk:!0,children:(0,I.jsx)(ly,{name:`format`,value:r,onChange:i,data:[{label:`FHIR Everything`,value:`everything`},{label:`Patient Summary`,value:`summary`},{label:`C-CDA`,value:`ccda`},{label:`C-CDA Referral`,value:`ccdaReferral`}],fullWidth:!0})}),(0,I.jsx)(tI,{title:`Author`,description:`Optional author for composition. Default value is current user.`,children:(0,I.jsx)(NI,{name:`author`,placeholder:`Author`,targetTypes:[`Organization`,`Practitioner`,`PractitionerRole`]})}),(0,I.jsx)(tI,{title:`Authored On`,description:`Optional date for composition authored on. Default value is current date.`,children:(0,I.jsx)(mI,{name:`authoredOn`,placeholder:`Authored on`})}),(0,I.jsx)(tI,{title:`Start Date`,description:`The start date of care. If no start date is provided, all records prior to the end date are in scope.`,children:(0,I.jsx)(mI,{name:`startDate`,placeholder:`Start date`})}),(0,I.jsx)(tI,{title:`End Date`,description:`The end date of care. If no end date is provided, all records subsequent to the start date are in scope.`,children:(0,I.jsx)(mI,{name:`endDate`,placeholder:`End date`})}),r===`everything`&&(0,I.jsx)(tI,{title:`Inline Attachments`,description:`Embed DocumentReference file attachments as base64-encoded data instead of storage URLs.`,children:(0,I.jsx)(G,{gap:`xs`,children:(0,I.jsx)(Bd,{label:`Inline attachments`,checked:a,onChange:e=>o(e.currentTarget.checked)})})}),(0,I.jsx)(V,{justify:`right`,children:(0,I.jsx)(GN,{children:`Request Export`})})]})})}function jz(e,t,n){let r=typeof e==`string`?e:JSON.stringify(e,null,2),i=new Blob([r],{type:n}),a=window.URL.createObjectURL(i),o=document.createElement(`a`);document.body.appendChild(o),o.style.display=`none`,o.href=a,o.download=t,o.click(),window.URL.revokeObjectURL(a)}function Mz(e){if(e.gender===`male`)return`blue`;if(e.gender===`female`)return`pink`}function Nz(e){let t=bk(e.patient);return t?(0,I.jsxs)(uz,{children:[(0,I.jsx)(_M,{value:t,size:`lg`,color:Mz(t)}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Name`}),(0,I.jsx)(uz.Value,{children:(0,I.jsx)(dM,{to:t,fw:500,children:t.name?(0,I.jsx)(NF,{value:t.name[0],options:{use:!1}}):`[blank]`})})]}),t.birthDate&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`DoB`}),(0,I.jsx)(uz.Value,{children:t.birthDate})]}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Age`}),(0,I.jsx)(uz.Value,{children:hC(t.birthDate)})]})]}),t.gender&&(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Gender`}),(0,I.jsx)(uz.Value,{children:t.gender})]}),t.address&&(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`State`}),(0,I.jsx)(uz.Value,{children:t.address[0]?.state})]}),t.identifier?.map(e=>(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:e?.system}),(0,I.jsx)(uz.Value,{children:e?.value})]},`${e?.system}-${e?.value}`))]}):null}function Pz(e){let{patient:t,...n}=e;return(0,I.jsx)(BL,{value:t,loadTimelineResources:(0,b.useCallback)((e,t,n)=>{let r=`${t}/${n}`;return Promise.allSettled([e.readHistory(`Patient`,n),e.search(`ClinicalImpression`,{subject:r,_count:100}),e.search(`Communication`,{subject:r,_count:100}),e.search(`Device`,{patient:r,_count:100}),e.search(`DeviceRequest`,{patient:r,_count:100}),e.search(`DiagnosticReport`,{subject:r,_count:100}),e.search(`Media`,{subject:r,_count:100}),e.search(`ServiceRequest`,{subject:r,_count:100}),e.search(`Task`,{subject:r,_count:100})])},[]),createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,subject:iC(e),sender:iC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,subject:iC(e),operator:iC(t),issued:new Date().toISOString(),content:n}),...n})}var Fz={section:`_section_pqpwm_1`,hovering:`_hovering_pqpwm_7`,editing:`_editing_pqpwm_11`};function Iz(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)();function d(){c(void 0)}function f(){o(void 0)}if((0,b.useEffect)(()=>{t.requestSchema(`PlanDefinition`).then(()=>i(!0)).catch(console.log)},[t]),(0,b.useEffect)(()=>(u(Wz(n??{resourceType:`PlanDefinition`,status:`active`})),document.addEventListener(`mouseover`,d),document.addEventListener(`click`,f),()=>{document.removeEventListener(`mouseover`,d),document.removeEventListener(`click`,f)}),[n]),!r||!l)return null;function p(e,t){u(n=>({...n,[e]:t}))}return(0,I.jsx)(`div`,{children:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(l),children:[(0,I.jsx)(yb,{label:`Plan Title`,py:`md`,defaultValue:l.title,onChange:e=>p(`title`,e.currentTarget.value)}),(0,I.jsx)(Lz,{actions:l.action||[],selectedKey:a,setSelectedKey:o,hoverKey:s,setHoverKey:c,onChange:e=>p(`action`,e)}),(0,I.jsx)(GN,{children:`Save`})]})})}function Lz(e){function t(t){e.onChange(e.actions.map(e=>e.id===t.id?t:e))}function n(t){e.onChange([...e.actions,t]),e.setSelectedKey(t.id)}function r(t){e.onChange(e.actions.filter(e=>e!==t))}return(0,I.jsxs)(G,{gap:`md`,className:Fz.section,children:[e.actions.map(n=>(0,I.jsx)(Rz,{action:n,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:t,onRemove:()=>r(n)},n.id)),(0,I.jsx)(`div`,{children:(0,I.jsx)(U,{variant:`outline`,onClick:e=>{aM(e),n({id:Uz()})},children:`Add action`})})]})}function Rz(e){let{action:t}=e;function n(t){t.stopPropagation(),e.setSelectedKey(e.action.id)}function r(t){aM(t),e.setHoverKey(e.action.id)}return(0,I.jsx)(`div`,{onClick:n,onMouseOver:r,onFocus:r,children:(0,I.jsx)(zz,{action:t,onChange:e.onChange,selectedKey:e.selectedKey,hoverKey:e.hoverKey,onRemove:e.onRemove})})}function zz(e){let{action:t}=e,[n,r]=(0,b.useState)(),i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),l=e.selectedKey===e.action.id,u=e.hoverKey===e.action.id;function d(n,r){e.onChange({...t,[n]:r})}let f=it(Fz.section,{[Fz.hovering]:u&&!l});return(0,b.useEffect)(()=>{(async()=>{if(!t.definitionCanonical)return;o(!0);let e=await i.readCanonical([`Questionnaire`,`ActivityDefinition`],t.definitionCanonical);r(Vz(e)),c(e),o(!1)})().catch(console.error)},[t.definitionCanonical,i]),a?(0,I.jsx)(il,{}):(0,I.jsxs)(Xc,{"data-testid":t.id,className:f,p:0,radius:`sm`,withBorder:!0,children:[(0,I.jsxs)(ru,{w:`100%`,p:`xs`,bg:`gray.0`,gap:`md`,align:`center`,justify:`space-between`,children:[(0,I.jsx)(yb,{w:`100%`,name:`actionTitle-${t.id}`,defaultValue:t.title,placeholder:`Title`,onChange:e=>d(`title`,e.currentTarget.value)}),(0,I.jsx)(Cl,{"data-testid":`close-button`,onClick:e.onRemove})]}),l&&(0,I.jsxs)(G,{gap:`xl`,p:`md`,children:[(0,I.jsx)(z,{children:(0,I.jsx)(yb,{label:`Task Description`,placeholder:`Enter task description`,name:`actionDescription-${t.id}`,defaultValue:t.description,onChange:e=>d(`description`,e.currentTarget.value)})}),(0,I.jsx)(z,{children:(0,I.jsx)(yg,{label:`Type of Action`,value:n,onChange:t=>{let n=t.currentTarget.value===`standard`?void 0:t.currentTarget.value;r(n),e.onChange({...e.action,definitionCanonical:n===`standard`?void 0:e.action.definitionCanonical})},data:[{value:`standard`,label:`Standard task`},{value:`questionnaire`,label:`Task with Questionnaire`},{value:`activitydefinition`,label:`Task with Activity Definition`}]})}),n===`questionnaire`&&(0,I.jsxs)(G,{gap:0,children:[(0,I.jsxs)(V,{gap:0,mb:`xs`,children:[(0,I.jsx)(H,{fw:600,children:`Select questionnaire`}),(0,I.jsx)(H,{c:`red`,children:`*`})]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mb:`sm`,children:[`Questionnaire to be shown in the task in Encounter view. You can create new one from`,` `,(0,I.jsx)(pu,{href:`/Questionnaire`,target:`_blank`,c:`blue`,children:`questionnaires list`})]}),(0,I.jsx)(Bz,{resource:s,resourceType:`Questionnaire`,action:t,onChange:e.onChange,placeholder:`Search for questionnaire`})]}),n===`activitydefinition`&&(0,I.jsxs)(G,{gap:0,children:[(0,I.jsxs)(V,{gap:0,mb:`xs`,children:[(0,I.jsx)(H,{fw:600,children:`Select activity definition`}),(0,I.jsx)(H,{c:`red`,children:`*`})]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mb:`sm`,children:[`ActivityDefinition.kind resource to be shown in the task in Encounter view. You can create new one from`,` `,(0,I.jsx)(pu,{href:`/ActivityDefinition`,target:`_blank`,c:`blue`,children:`activity definitions list`})]}),(0,I.jsx)(Bz,{resource:s,resourceType:`ActivityDefinition`,action:t,onChange:e.onChange,placeholder:`Search for activity definition`})]})]})]})}function Bz(e){let{id:t}=e.action,{resource:n}=e;return(0,I.jsx)(MI,{name:t,placeholder:e.placeholder,resourceType:e.resourceType,defaultValue:n,onChange:t=>{t?e.onChange({...e.action,definitionCanonical:`url`in t?t.url:void 0,definitionUri:`url`in t?void 0:aC(t)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function Vz(e){return e===void 0?`standard`:e.resourceType.toLowerCase()}var Hz=1;function Uz(e){if(e){if(e.startsWith(`id-`)){let t=Number.parseInt(e.substring(3),10);Number.isNaN(t)||(Hz=Math.max(Hz,t+1))}return e}return`id-`+Hz++}function Wz(e){return{...e,action:Gz(e.action)}}function Gz(e){if(e)return e.map(e=>({...e,id:Uz(e.id),action:Gz(e.action)}))}var Kz=`modulepreload`,qz=function(e){return`/`+e},Jz={},Yz=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,new URL(`../../../src/node/plugins/importAnalysisBuild.ts`,import.meta.url)).href}r=o(t.map(t=>{if(t=qz(t,n),t=s(t),t in Jz)return;Jz[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Kz,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Xz=150,Zz;function Qz({onScan:e,onError:t,scanOnce:n=!0}){let r=(0,b.useRef)(null),i=(0,b.useRef)(null),a=(0,b.useRef)(e),o=(0,b.useRef)(t),[s,c]=(0,b.useState)(!0),[l,u]=(0,b.useState)();return(0,b.useEffect)(()=>{a.current=e},[e]),(0,b.useEffect)(()=>{o.current=t},[t]),(0,b.useEffect)(()=>{let e=r.current,t=i.current,s=t?.getContext(`2d`,{willReadFrequently:!0});if(!e||!t||!s)return;let l=e,d=t,f=s,p=0,m,h=!1,g=!1,_=0,v;function y(){m?.getTracks().forEach(e=>e.stop())}function b(e){let t=e instanceof Error?e:Error(String(e));h||(c(!1),u(Y(t)),o.current?.(t))}function x(e){if(!(h||g||!v)){if(l.readyState===l.HAVE_ENOUGH_DATA&&(c(!1),e-_>=Xz)){_=e,d.height=l.videoHeight,d.width=l.videoWidth,f.drawImage(l,0,0,d.width,d.height);let t=f.getImageData(0,0,d.width,d.height),r=v(t.data,t.width,t.height,{inversionAttempts:`attemptBoth`});if(r?.data&&(g=n,a.current(r.data),n)){y();return}}p=requestAnimationFrame(x)}}async function S(){try{if(v=await $z(),h)return;if(!navigator.mediaDevices?.getUserMedia)throw Error(`Camera access is not available in this browser.`);let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:`environment`}});if(h){e.getTracks().forEach(e=>e.stop());return}m=e,l.srcObject=e,l.setAttribute(`playsinline`,`true`),await l.play(),h||(p=requestAnimationFrame(x))}catch(e){b(e)}}return S().catch(b),()=>{h=!0,cancelAnimationFrame(p),y()}},[n]),(0,I.jsxs)(G,{gap:`sm`,children:[l&&(0,I.jsx)(ou,{color:`red`,children:l}),(0,I.jsx)(`video`,{ref:r,width:640,height:480,muted:!0,style:{aspectRatio:`4 / 3`,display:l?`none`:`block`,width:`100%`,height:`auto`,maxHeight:`70vh`,background:`black`}}),(0,I.jsx)(`canvas`,{ref:i,hidden:!0}),s&&!l&&(0,I.jsxs)(H,{c:`dimmed`,size:`sm`,children:[(0,I.jsx)(il,{size:`xs`,mr:`xs`}),`Loading camera...`]})]})}async function $z(){return Zz||=Yz(()=>import(`./jsQR-DtKuncVr.js`).then(e=>c(e.default,1)).then(e=>e.default),[]).catch(e=>{throw Zz=void 0,Error(`QR code scanning requires the optional "jsqr" dependency. Install jsqr to use QrCodeScanner. ${Y(e)}`)}),Zz}var eB=30,tB=50;function nB(e){let t=e.formState,n=e.item,r=e.responseItem;function i(i){if(t&&e.context)if(n.repeats&&e.index!==void 0&&n.type!==Sk.choice&&n.type!==Sk.openChoice){let n=[...r.answer||[]];i.length===0?n.splice(e.index,1):n[e.index]=i[0],t.onChangeAnswer(e.context,e.item,n)}else t.onChangeAnswer(e.context,e.item,i)}let a=n.type;if(!a)return null;let o=n.linkId;if(!o)return null;let s=n.repeats&&e.index!==void 0&&n.type!==Sk.choice&&n.type!==Sk.openChoice?`${o}-${e.index}`:o,c;n.initial&&n.initial.length>0?c=n.initial[0]:n.answerOption&&n.answerOption.length>0&&(c=n.answerOption.find(e=>e.initialSelected));let l=uB(r,e.index)??nA(c),u=_C(r,`${Ox}/fhir/StructureDefinition/questionnaire-validationError`),d=null;switch(a){case Sk.display:d=(0,I.jsx)(`p`,{children:e.item.text},e.item.linkId);break;case Sk.boolean:d=(0,I.jsx)(eI,{title:e.item.text,htmlFor:s,children:(0,I.jsx)(Bd,{id:s,name:o,required:e.required??n.required,defaultChecked:l?.value,onChange:e=>i([{valueBoolean:e.currentTarget.checked}])})},e.item.linkId);break;case Sk.decimal:d=(0,I.jsx)(yb,{type:`number`,step:`any`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i(e.currentTarget.value===``?[]:[{valueDecimal:e.currentTarget.valueAsNumber}])});break;case Sk.integer:d=(0,I.jsx)(yb,{type:`number`,step:1,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i(e.currentTarget.value===``?[]:[{valueInteger:e.currentTarget.valueAsNumber}])});break;case Sk.date:d=(0,I.jsx)(yb,{type:`date`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDate:e.currentTarget.value}])});break;case Sk.dateTime:d=(0,I.jsx)(mI,{name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDateTime:e}])});break;case Sk.time:d=(0,I.jsx)(yb,{type:`time`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueTime:e.currentTarget.value}])});break;case Sk.string:case Sk.url:d=(0,I.jsx)(yb,{id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>{let t=e.currentTarget.value;i(t===``?[]:[{valueString:t}])}});break;case Sk.text:d=(0,I.jsx)(_m,{id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>{let t=e.currentTarget.value;i(t===``?[]:[{valueString:t}])}});break;case Sk.attachment:d=(0,I.jsx)(V,{py:4,children:(0,I.jsx)(IP,{path:``,name:s,defaultValue:l?.value,onChange:e=>i([{valueAttachment:e}])})});break;case Sk.reference:d=(0,I.jsx)(NI,{name:s,required:e.required??n.required,targetTypes:qk(n),searchCriteria:Yk(n,t?.subject,t?.encounter),defaultValue:l?.value,onChange:e=>i([{valueReference:e}])});break;case Sk.quantity:d=(0,I.jsx)(SI,{path:``,name:s,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueQuantity:e}]),disableWheel:!0});break;case Sk.choice:case Sk.openChoice:{let{widget:t,multiselect:a}=mB(n),o={name:s,item:n,required:e.required??n.required,initial:c,response:r,multiselect:a,onChangeAnswer:i};d=t===`check-box`?(0,I.jsx)(cB,{...o}):t===`drop-down`?(0,I.jsx)(rB,{...o}):(0,I.jsx)(sB,{...o})}break;default:return null}return(0,I.jsxs)(I.Fragment,{children:[d,u?.valueString&&(0,I.jsx)(H,{c:`red`,size:`lg`,mt:4,children:u.valueString})]})}function rB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o,multiselect:s}=e;if(!n.answerOption?.length&&!n.answerValueSet)return(0,I.jsx)(lB,{});let c=nA(i),l=uB(o)??c,u=dB(o),d=n.repeats||s;if(n.answerValueSet)return(0,I.jsx)(QN,{name:t,placeholder:`Select items`,binding:n.answerValueSet,maxValues:d?void 0:1,required:r,onChange:e=>{d?e.length===0?a([{}]):a(e.map(e=>({valueCoding:e}))):a([{valueCoding:e[0]}])},defaultValue:l?.value});if(d){let{propertyName:e,data:t}=hB(n);return(0,I.jsx)(hg,{data:t,placeholder:`Select items`,searchable:!0,defaultValue:u||[aw(c)],required:r,onChange:t=>{t.length===0?a([{}]):a(Uk(t,e,n))}})}else{let e=[``];if(n.answerOption)for(let t of n.answerOption){let n=rA(t);e.push(aw(n))}return(0,I.jsx)(yg,{id:t,name:t,required:r,onChange:e=>{let t=e.currentTarget.selectedIndex;if(t===0){a([{}]);return}let r=n.answerOption[t-1],i=rA(r);a([{[`value`+HC(i.type)]:i.value}])},defaultValue:Sw(l?.value)||l?.value,data:e})}}function iB(e,t){return e?t.valueSetExpand({url:e,count:31}).then(e=>e.expansion?.contains??[]):Promise.resolve([])}function aB(e){let t=Q(),[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{async function n(){if(e){a(!0);try{r(await iB(e,t))}catch(e){console.error(`Error loading value set:`,e)}finally{a(!1)}}}n().catch(console.error)},[e,t]),[n,i]}function oB(e,t){return e.map((e,n)=>[`${t}-valueset-${n}`,{type:`Coding`,value:{system:e.system,code:e.code,display:e.display}}])}function sB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o}=e,s=zw(`QuestionnaireItemAnswerOption`,`value[x]`),c=nA(i),[l,u]=aB(n.answerValueSet),d=[],f;if(n.answerValueSet)d.push(...oB(l,t));else if(n.answerOption){let e=n.answerOption.slice(0,tB).map((e,n)=>{let r=`${t}-option-${n}`,i=rA(e);return i?.value?(c&&vC(i)===vC(c)&&(f=r),[r,i]):null}).filter(e=>e!==null);d.push(...e)}let p=fB(d,uB(o));if(u)return(0,I.jsx)(H,{children:`Loading options...`});if(d.length===0)return(0,I.jsx)(lB,{});let m=d.slice(0,eB);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Dv.Group,{name:t,value:p??f,required:r,onChange:e=>{let t=d.find(t=>t[0]===e);if(t){let e=t[1];a([{[`value`+HC(e.type)]:e.value}])}},children:m.map(([e,t])=>(0,I.jsx)(Dv,{id:e,value:e,py:4,required:r,label:(0,I.jsx)(KF,{property:s,propertyType:t.type,value:t.value})},e))}),(n.answerValueSet&&d.length>eB||n.answerOption&&d.length>tB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mt:`xs`,children:[`Showing first `,eB,` options`]})]})}function cB(e){let{name:t,item:n,onChangeAnswer:r,response:i}=e,a=zw(`QuestionnaireItemAnswerOption`,`value[x]`),[o,s]=aB(n.answerValueSet),[c,l]=(0,b.useState)(n.answerValueSet?(i?.answer?.map(e=>e.valueCoding)||[]).filter(e=>e!==void 0):dB(i)),u=[];if(n.answerValueSet)u.push(...oB(o,t));else if(n.answerOption){let e=n.answerOption.slice(0,tB).map((e,n)=>{let r=`${t}-option-${n}`,i=rA(e);return i?.value?[r,i]:null}).filter(e=>e!==null);u.push(...e)}if(s)return(0,I.jsx)(H,{children:`Loading options...`});if(u.length===0)return(0,I.jsx)(lB,{});let d=u.slice(0,eB),f=(e,t)=>{if(n.answerValueSet){let n=c,i;i=t?[...n,e.value]:n.filter(t=>!TC(t,e.value)),l(i),i.length===0?r([{}]):r(i.map(e=>({valueCoding:e})))}else{let i=c,a=aw(e),o;o=t?[...i,a]:i.filter(e=>e!==a),l(o),o.length===0?r([{}]):r(Uk(o,`value`+HC(e.type),n))}};return(0,I.jsxs)(V,{style:{flexDirection:`column`,alignItems:`flex-start`},children:[d.map(([e,t])=>{let r=aw(t),i=n.answerValueSet?c.some(e=>TC(e,t.value)):c.includes(r);return(0,I.jsx)(Bd,{id:e,label:(0,I.jsx)(KF,{property:a,propertyType:t.type,value:t.value}),checked:i,onChange:e=>f(t,e.currentTarget.checked)},e)}),(n.answerValueSet&&u.length>eB||n.answerOption&&u.length>tB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Showing first `,eB,` options`]})]})}function lB(){return(0,I.jsx)(yb,{disabled:!0,placeholder:`No Answers Defined`})}function uB(e,t=0){return rA(e?.answer?.[t]??{})}function dB(e){let t=e?.answer;return t?t.map(e=>rA(e)).map(e=>Sw(e?.value)||e?.value).filter(Boolean):[]}function fB(e,t){return e.find(e=>TC(e[1].value,t?.value))?.[0]}var pB=[`drop-down`,`radio-button`,`check-box`];function mB(e){let t=`radio-button`,n=!1;e.answerValueSet&&(t=`drop-down`);for(let r of e.extension??[]){if(r.url!==Ck)continue;let e=r.valueCodeableConcept?.coding?.[0]?.code;pB.includes(e)&&(t=e),e===`multi-select`&&(n=!0)}return t===`radio-button`&&n&&(t=`check-box`),{widget:t,multiselect:n}}function hB(e){if(e.answerOption?.length===0)return{propertyName:``,data:[]};let t=e.answerOption[0];return{propertyName:`value`+HC(rA(t).type),data:(e.answerOption??[]).map(e=>{let t=aw(rA(e));return{value:t,label:t}})}}var gB={section:`_section_my8o4_1`,hovering:`_hovering_my8o4_10`,editing:`_editing_my8o4_14`,questionBody:`_questionBody_my8o4_20`,topActions:`_topActions_my8o4_24`,bottomActions:`_bottomActions_my8o4_33`,movementActions:`_movementActions_my8o4_44`,movementIcons:`_movementIcons_my8o4_56`,columnAlignment:`_columnAlignment_my8o4_60`,linkIdInput:`_linkIdInput_my8o4_65`,typeSelect:`_typeSelect_my8o4_70`,preserveBreaks:`_preserveBreaks_my8o4_74`};function _B(e){let t=Q(),n=bk(e.questionnaire),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)();function d(){u(void 0)}function f(){c(void 0)}return(0,b.useEffect)(()=>{t.requestSchema(`Questionnaire`).then(()=>i(!0)).catch(console.log)},[t]),(0,b.useEffect)(()=>(o(EB(n??{resourceType:`Questionnaire`,status:`active`})),document.addEventListener(`mouseover`,d),document.addEventListener(`click`,f),()=>{document.removeEventListener(`mouseover`,d),document.removeEventListener(`click`,f)}),[n]),!r||!a?null:(0,I.jsx)(`div`,{children:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(a),children:[(0,I.jsx)(vB,{item:a,selectedKey:s,setSelectedKey:c,hoverKey:l,setHoverKey:u,onChange:(t,n)=>{o(t),e.autoSave&&!n&&e.onSubmit&&e.onSubmit(t)}}),(0,I.jsx)(GN,{children:`Save`})]})})}function vB(e){let t=e.item,n=e.item,r=Vw(e.item),i=r||n.type===Sk.group,a=n.linkId??`[untitled]`,o=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,c=(0,b.useRef)(e.item);(0,b.useLayoutEffect)(()=>{c.current=e.item});function l(t){aM(t),e.setSelectedKey(e.item.id)}function u(t){aM(t),e.setHoverKey(e.item.id)}function d(t){let n=c.current;e.onChange({...n,item:n.item?.map(e=>e.id===t.id?t:e)})}function f(t,n){e.onChange({...e.item,item:[...e.item.item??[],t]},n)}function p(t){e.onChange({...e.item,item:e.item.item?.filter(e=>e!==t)})}function m(t,n){e.onChange({...c.current,[t]:n})}function h(t){e.onChange({...e.item,...t})}function g(t){e.onChange({...e.item,item:e.item.item?.map(e=>e===t?{...e,repeats:!e.repeats}:e)})}function _(t,n){let r=AB(e.item.item,t,n);e.onChange({...e.item,item:r})}let v=it(gB.section,{[gB.editing]:o,[gB.hovering]:s&&!o});return(0,I.jsxs)(`div`,{"data-testid":n.linkId,className:v,onClick:l,onMouseOver:u,onFocus:u,children:[(0,I.jsx)(`div`,{className:gB.questionBody,children:o?(0,I.jsxs)(I.Fragment,{children:[r&&(0,I.jsx)(yb,{size:`xl`,defaultValue:t.title,onBlur:e=>m(`title`,e.currentTarget.value)}),!r&&(0,I.jsx)(_m,{autosize:!0,minRows:2,defaultValue:n.text,onBlur:e=>m(`text`,e.currentTarget.value)}),n.type===`reference`&&(0,I.jsx)(xB,{item:n,onChange:h}),Mk(n)&&(0,I.jsx)(yB,{item:n,onChange:e=>h(e)})]}):(0,I.jsxs)(I.Fragment,{children:[t.title&&(0,I.jsx)(q,{children:t.title}),n.text&&(0,I.jsx)(`div`,{className:gB.preserveBreaks,children:n.text}),!i&&(0,I.jsx)(nB,{item:n,index:0,required:!1,responseItem:{linkId:n.linkId}})]})}),n.item?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(vB,{item:t,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:n===0,isLast:n===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:d,onRemove:()=>p(t),onRepeatable:g,onMoveUp:()=>_(n,-1),onMoveDown:()=>_(n,1)})},t.id)),!i&&(0,I.jsx)(`div`,{className:gB.topActions,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(yb,{size:`xs`,className:gB.linkIdInput,defaultValue:n.linkId,onBlur:e=>m(`linkId`,e.currentTarget.value)}),!i&&(0,I.jsx)(yg,{size:`xs`,className:gB.typeSelect,defaultValue:n.type,onChange:e=>m(`type`,e.currentTarget.value),data:[{value:`display`,label:`Display`},{value:`boolean`,label:`Boolean`},{value:`decimal`,label:`Decimal`},{value:`integer`,label:`Integer`},{value:`date`,label:`Date`},{value:`dateTime`,label:`Date/Time`},{value:`time`,label:`Time`},{value:`string`,label:`String`},{value:`text`,label:`Text`},{value:`url`,label:`URL`},{value:`choice`,label:`Choice`},{value:`open-choice`,label:`Open Choice`},{value:`attachment`,label:`Attachment`},{value:`reference`,label:`Reference`},{value:`quantity`,label:`Quantity`}]})]}):(0,I.jsx)(`div`,{children:a})}),!r&&(0,I.jsx)(z,{className:gB.movementActions,children:(0,I.jsxs)(z,{className:gB.columnAlignment,children:[!e.isFirst&&(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,I.jsx)(MA,{"data-testid":`up-button`,size:15,className:gB.movementIcons})}),!e.isLast&&(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,I.jsx)(jA,{"data-testid":`down-button`,size:15,className:gB.movementIcons})})]})}),(0,I.jsxs)(`div`,{className:gB.bottomActions,children:[i&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f({id:TB(),linkId:wB(`q`),type:`string`,text:`Question`})},children:`Add item`}),(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f({id:TB(),linkId:wB(`g`),type:`group`,text:`Group`},!0)},children:`Add group`})]}),r&&(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f(kB(),!0)},children:`Add Page`}),o&&!r&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onRepeatable&&e.onRepeatable(n)},children:n.repeats?`Remove Repeatable`:`Make Repeatable`}),(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onRemove&&e.onRemove()},children:`Remove`})]})]})]})}function yB(e){let t=zw(`QuestionnaireItemAnswerOption`,`value[x]`),n=e.item.answerOption??[];return(0,I.jsxs)(`div`,{children:[e.item.answerValueSet===void 0?(0,I.jsx)(bB,{options:n,property:t,item:e.item,onChange:e.onChange}):(0,I.jsx)(yb,{placeholder:`Enter Value Set`,defaultValue:e.item.answerValueSet,onChange:t=>e.onChange({...e.item,answerValueSet:t.target.value})}),(0,I.jsxs)(z,{display:`flex`,children:[(0,I.jsx)(pu,{href:`#`,onClick:t=>{aM(t),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...n,{id:TB()}]})},children:`Add choice`}),(0,I.jsx)(Sy,{w:`lg`}),(0,I.jsx)(pu,{href:`#`,onClick:t=>{aM(t),e.onChange({...e.item,answerOption:[],answerValueSet:``})},children:`Add value set`})]})]})}function bB(e){return(0,I.jsx)(`div`,{children:e.options.map(t=>{let[n,r]=AF({type:`QuestionnaireItemAnswerOption`,value:t},`value`);return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`row`,justifyContent:`space-between`,alignItems:`center`,width:`80%`},children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(XI,{name:`value[x]`,path:`Questionnaire.answerOption.value[x]`,property:e.property,defaultPropertyType:r,defaultValue:n,onChange:(n,r)=>{let i=[...e.options],a=i.findIndex(e=>e.id===t.id);i[a]={id:t.id,[r]:n},e.onChange({...e.item,answerOption:i})},outcome:void 0},t.id)}),(0,I.jsx)(`div`,{children:(0,I.jsx)(pu,{href:`#`,onClick:n=>{aM(n),e.onChange({...e.item,answerOption:e.options.filter(e=>e.id!==t.id)})},children:`Remove`})})]},t.id)})})}function xB(e){let t=qk(e.item)??[];return(0,I.jsxs)(I.Fragment,{children:[t.map((n,r)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(rP,{name:`resourceType`,placeholder:`Resource Type`,defaultValue:n,onChange:r=>{e.onChange(Jk(e.item,t.map(e=>e===n?r:e)))}}),(0,I.jsx)(pu,{href:`#`,onClick:r=>{aM(r),e.onChange(Jk(e.item,t.filter(e=>e!==n)))},children:`Remove`})]},`${n}-${r}`)),(0,I.jsx)(pu,{href:`#`,onClick:n=>{aM(n),e.onChange(Jk(e.item,[...t,``]))},children:`Add Resource Type`})]})}var SB=1,CB=1;function wB(e){return e+SB++}function TB(){return`id-`+CB++}function EB(e){return{...e,id:e.id||TB(),item:DB(e.item)}}function DB(e){if(e)return e.forEach(e=>{e.id?.match(/^id-\d+$/)&&(CB=Math.max(CB,Number.parseInt(e.id.substring(3),10)+1)),e.linkId?.match(/^q\d+$/)&&(SB=Math.max(SB,Number.parseInt(e.linkId.substring(1),10)+1))}),e.map(e=>({...e,id:e.id||TB(),item:DB(e.item),answerOption:OB(e.answerOption)}))}function OB(e){if(e)return e.map(e=>({...e,id:e.id||TB()}))}function kB(){return{id:TB(),linkId:wB(`s`),type:`group`,text:`New Page`,extension:[{url:Ck,valueCodeableConcept:{coding:[{system:`http://hl7.org/fhir/questionnaire-item-control`,code:`page`}]}}]}}function AB(e,t,n){let r=e??[],i=t+n;if(i<0||i>=r.length)return r;let a=[...r];return[a[t],a[i]]=[a[i],a[t]],a}var jB=class{x;y;pressure;time;constructor(e,t,n,r){if(isNaN(e)||isNaN(t))throw Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=n||0,this.time=r||Date.now()}distanceTo(e){return Math.sqrt((this.x-e.x)**2+(this.y-e.y)**2)}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time===e.time?0:this.distanceTo(e)/(this.time-e.time)}},MB=class e{constructor(e,t,n,r,i,a){this.startPoint=e,this.control2=t,this.control1=n,this.endPoint=r,this.startWidth=i,this.endWidth=a}static fromPoints(t,n){let r=this.calculateControlPoints(t[0],t[1],t[2]).c2,i=this.calculateControlPoints(t[1],t[2],t[3]).c1;return new e(t[1],r,i,t[2],n.start,n.end)}static calculateControlPoints(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=t.x-n.x,o=t.y-n.y,s={x:(e.x+t.x)/2,y:(e.y+t.y)/2},c={x:(t.x+n.x)/2,y:(t.y+n.y)/2},l=Math.sqrt(r*r+i*i),u=Math.sqrt(a*a+o*o),d=s.x-c.x,f=s.y-c.y,p=l+u==0?0:u/(l+u),m={x:c.x+d*p,y:c.y+f*p},h=t.x-m.x,g=t.y-m.y;return{c1:new jB(s.x+h,s.y+g),c2:new jB(c.x+h,c.y+g)}}length(){let e=0,t,n;for(let r=0;r<=10;r+=1){let i=r/10,a=this.point(i,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),o=this.point(i,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(r>0){let r=a-t,i=o-n;e+=Math.sqrt(r*r+i*i)}t=a,n=o}return e}point(e,t,n,r,i){return t*(1-e)*(1-e)*(1-e)+3*n*(1-e)*(1-e)*e+3*r*(1-e)*e*e+i*e*e*e}},NB=class{_et;constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,n){this._et.addEventListener(e,t,n)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,n){this._et.removeEventListener(e,t,n)}};function PB(e,t=250){let n=0,r=null,i,a,o,s=()=>{n=Date.now(),r=null,i=e.apply(a,o),r||(a=null,o=[])};return function(...c){let l=Date.now(),u=t-(l-n);return a=this,o=c,u<=0||u>t?(r&&=(clearTimeout(r),null),n=l,i=e.apply(a,o),r||(a=null,o=[])):r||=window.setTimeout(s,u),i}}var FB=class e extends NB{constructor(t,n={}){super(),this.canvas=t,this.velocityFilterWeight=n.velocityFilterWeight||.7,this.minWidth=n.minWidth||.5,this.maxWidth=n.maxWidth||2.5,this.throttle=n.throttle??16,this.minDistance=n.minDistance??5,this.dotSize=n.dotSize||0,this.penColor=n.penColor||`black`,this.backgroundColor=n.backgroundColor||`rgba(0,0,0,0)`,this.compositeOperation=n.compositeOperation||`source-over`,this.canvasContextOptions=n.canvasContextOptions??{},this._strokeMoveUpdate=this.throttle?PB(e.prototype._strokeUpdate,this.throttle):e.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._handlePointerCancel=this._handlePointerCancel.bind(this),this._handleTouchCancel=this._handleTouchCancel.bind(this),this._ctx=t.getContext(`2d`,this.canvasContextOptions),this.clear(),this.on()}dotSize;minWidth;maxWidth;penColor;minDistance;velocityFilterWeight;compositeOperation;backgroundColor;throttle;canvasContextOptions;_ctx;_drawingStroke=!1;_isEmpty=!0;_dataUrl;_dataUrlOptions;_lastPoints=[];_data=[];_lastVelocity=0;_lastWidth=0;_strokeMoveUpdate;_strokePointerId;clear(){let{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._dataUrl=void 0,this._dataUrlOptions=void 0,this._strokePointerId=void 0}redraw(){let e=this._data,t=this._dataUrl,n=this._dataUrlOptions;this.clear(),t&&this.fromDataURL(t,n),this.fromData(e,{clear:!1})}fromDataURL(e,t={}){return new Promise((n,r)=>{let i=new Image,a=t.ratio||window.devicePixelRatio||1,o=t.width||this.canvas.width/a,s=t.height||this.canvas.height/a,c=t.xOffset||0,l=t.yOffset||0;this._reset(this._getPointGroupOptions()),i.onload=()=>{this._ctx.drawImage(i,c,l,o,s),n()},i.onerror=e=>{r(e)},i.crossOrigin=`anonymous`,i.src=e,this._isEmpty=!1,this._dataUrl=e,this._dataUrlOptions={...t}})}toDataURL(e=`image/png`,t){switch(e){case`image/svg+xml`:return typeof t!=`object`&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!=`number`&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction=`none`,this.canvas.style.msTouchAction=`none`,this.canvas.style.userSelect=`none`,this.canvas.style.webkitUserSelect=`none`;let e=/Macintosh/.test(navigator.userAgent)&&`ontouchstart`in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),`ontouchstart`in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction=`auto`,this.canvas.style.msTouchAction=`auto`,this.canvas.style.userSelect=`auto`,this.canvas.style.webkitUserSelect=`auto`,this.canvas.removeEventListener(`pointerdown`,this._handlePointerDown),this.canvas.removeEventListener(`mousedown`,this._handleMouseDown),this.canvas.removeEventListener(`touchstart`,this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){let e=window.document===this.canvas.ownerDocument?window:this.canvas.ownerDocument.defaultView??this.canvas.ownerDocument;return{addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}_removeMoveUpEventListeners(){let{removeEventListener:e}=this._getListenerFunctions();e(`pointermove`,this._handlePointerMove),e(`pointerup`,this._handlePointerUp),e(`pointercancel`,this._handlePointerCancel),e(`mousemove`,this._handleMouseMove),e(`mouseup`,this._handleMouseUp),e(`touchmove`,this._handleTouchMove),e(`touchend`,this._handleTouchEnd),e(`touchcancel`,this._handleTouchCancel)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)==1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:`pressure`in e?e.pressure:0}}_touchEventToSignatureEvent(e){let t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_handlePointerCancel(e){this._allowPointerId(e)&&(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e),!1))}_handleTouchCancel(e){e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e),!1)}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return this._strokePointerId===void 0?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&`penColor`in e?e.penColor:this.penColor,dotSize:e&&`dotSize`in e?e.dotSize:this.dotSize,minWidth:e&&`minWidth`in e?e.minWidth:this.minWidth,maxWidth:e&&`maxWidth`in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&`velocityFilterWeight`in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&`compositeOperation`in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent(`beginStroke`,{detail:e,cancelable:!0})))return;let{addEventListener:t}=this._getListenerFunctions();switch(e.event.type){case`mousedown`:t(`mousemove`,this._handleMouseMove,{passive:!1}),t(`mouseup`,this._handleMouseUp,{passive:!1});break;case`touchstart`:t(`touchmove`,this._handleTouchMove,{passive:!1}),t(`touchend`,this._handleTouchEnd,{passive:!1}),t(`touchcancel`,this._handleTouchCancel,{passive:!1});break;case`pointerdown`:t(`pointermove`,this._handlePointerMove,{passive:!1}),t(`pointerup`,this._handlePointerUp,{passive:!1}),t(`pointercancel`,this._handlePointerCancel,{passive:!1});break;default:}this._drawingStroke=!0;let n=this._getPointGroupOptions(),r={...n,points:[]};this._data.push(r),this._reset(n),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent(`beforeUpdateStroke`,{detail:e}));let t=this._createPoint(e.x,e.y,e.pressure),n=this._data[this._data.length-1],r=n.points,i=r.length>0&&r[r.length-1],a=i?t.distanceTo(i)<=this.minDistance:!1,o=this._getPointGroupOptions(n);if(!i||!(i&&a)){let e=this._addPoint(t,o);i?e&&this._drawCurve(e,o):this._drawDot(t,o),r.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent(`afterUpdateStroke`,{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent(`endStroke`,{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener(`pointerdown`,this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener(`mousedown`,this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener(`touchstart`,this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,n){let r=this.canvas.getBoundingClientRect();return new jB(e-r.left,t-r.top,n,new Date().getTime())}_addPoint(e,t){let{_lastPoints:n}=this;if(n.push(e),n.length>2){n.length===3&&n.unshift(n[0]);let e=this._calculateCurveWidths(n[1],n[2],t),r=MB.fromPoints(n,e);return n.shift(),r}return null}_calculateCurveWidths(e,t,n){let r=n.velocityFilterWeight*t.velocityFrom(e)+(1-n.velocityFilterWeight)*this._lastVelocity,i=this._strokeWidth(r,n),a={end:i,start:this._lastWidth};return this._lastVelocity=r,this._lastWidth=i,a}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,n){let r=this._ctx;r.moveTo(e,t),r.arc(e,t,n,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){let n=this._ctx,r=e.endWidth-e.startWidth,i=Math.ceil(e.length())*2;n.beginPath(),n.fillStyle=t.penColor;for(let n=0;n<i;n+=1){let a=n/i,o=a*a,s=o*a,c=1-a,l=c*c,u=l*c,d=u*e.startPoint.x;d+=3*l*a*e.control1.x,d+=3*c*o*e.control2.x,d+=s*e.endPoint.x;let f=u*e.startPoint.y;f+=3*l*a*e.control1.y,f+=3*c*o*e.control2.y,f+=s*e.endPoint.y;let p=Math.min(e.startWidth+s*r,t.maxWidth);this._drawCurveSegment(d,f,p)}n.closePath(),n.fill()}_drawDot(e,t){let n=this._ctx,r=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;n.beginPath(),this._drawCurveSegment(e.x,e.y,r),n.closePath(),n.fillStyle=t.penColor,n.fill()}_fromData(e,t,n){for(let r of e){let{points:e}=r,i=this._getPointGroupOptions(r);if(e.length>1)for(let n=0;n<e.length;n+=1){let r=e[n],a=new jB(r.x,r.y,r.pressure,r.time);n===0&&this._reset(i);let o=this._addPoint(a,i);o&&t(o,i)}else this._reset(i),n(e[0],i)}}toSVG({includeBackgroundColor:e=!1,includeDataUrl:t=!1}={}){let n=this._data,r=Math.max(window.devicePixelRatio||1,1),i=this.canvas.width/r,a=this.canvas.height/r,o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);if(o.setAttribute(`xmlns`,`http://www.w3.org/2000/svg`),o.setAttribute(`xmlns:xlink`,`http://www.w3.org/1999/xlink`),o.setAttribute(`viewBox`,`0 0 ${i} ${a}`),o.setAttribute(`width`,i.toString()),o.setAttribute(`height`,a.toString()),e&&this.backgroundColor){let e=document.createElement(`rect`);e.setAttribute(`width`,`100%`),e.setAttribute(`height`,`100%`),e.setAttribute(`fill`,this.backgroundColor),o.appendChild(e)}if(t&&this._dataUrl){let e=this._dataUrlOptions?.ratio||window.devicePixelRatio||1,t=this._dataUrlOptions?.width||this.canvas.width/e,n=this._dataUrlOptions?.height||this.canvas.height/e,r=this._dataUrlOptions?.xOffset||0,i=this._dataUrlOptions?.yOffset||0,a=document.createElement(`image`);a.setAttribute(`x`,r.toString()),a.setAttribute(`y`,i.toString()),a.setAttribute(`width`,t.toString()),a.setAttribute(`height`,n.toString()),a.setAttribute(`preserveAspectRatio`,`none`),a.setAttribute(`href`,this._dataUrl),o.appendChild(a)}return this._fromData(n,(e,{penColor:t})=>{let n=document.createElement(`path`);if(!isNaN(e.control1.x)&&!isNaN(e.control1.y)&&!isNaN(e.control2.x)&&!isNaN(e.control2.y)){let r=`M ${e.startPoint.x.toFixed(3)},${e.startPoint.y.toFixed(3)} C ${e.control1.x.toFixed(3)},${e.control1.y.toFixed(3)} ${e.control2.x.toFixed(3)},${e.control2.y.toFixed(3)} ${e.endPoint.x.toFixed(3)},${e.endPoint.y.toFixed(3)}`;n.setAttribute(`d`,r),n.setAttribute(`stroke-width`,(e.endWidth*2.25).toFixed(3)),n.setAttribute(`stroke`,t),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke-linecap`,`round`),o.appendChild(n)}},(e,{penColor:t,dotSize:n,minWidth:r,maxWidth:i})=>{let a=document.createElement(`circle`),s=n>0?n:(r+i)/2;a.setAttribute(`r`,s.toString()),a.setAttribute(`cx`,e.x.toString()),a.setAttribute(`cy`,e.y.toString()),a.setAttribute(`fill`,t),o.appendChild(a)}),o.outerHTML}};function IB(e){let t=Q(),{width:n=500,height:r=200,defaultValue:i,who:a,onChange:o,...s}=e,c=(0,b.useRef)(null),l=(0,b.useRef)(null),u=(0,b.useRef)(o);(0,b.useLayoutEffect)(()=>{u.current=o}),(0,b.useEffect)(()=>{function e(){u.current?.({type:[{system:Ox+`/fhir/signature-type`,code:`ProofOfOrigin`,display:`Proof of Origin`}],when:new Date().toISOString(),who:a??iC(t.getProfile()),data:l.current?.toDataURL().split(`,`)[1]})}if(c.current){let t=new FB(c.current);i?.data&&t.fromDataURL(i.data).catch(console.error),t.addEventListener(`endStroke`,e),l.current=t}return()=>{l.current&&l.current.removeEventListener(`beginStroke`,e)}},[t,i,a]);let d=()=>{l.current&&l.current.clear(),u.current?.(void 0)};return(0,I.jsxs)(Xc,{withBorder:!0,p:0,w:n,h:r,pos:`relative`,...s,children:[(0,I.jsx)(`canvas`,{ref:c,width:n,height:r,"aria-label":`Signature input area`}),(0,I.jsx)(U,{onClick:d,"aria-label":`Clear signature`,pos:`absolute`,top:0,right:0,size:`xs`,leftSection:(0,I.jsx)(Yj,{size:16}),variant:`subtle`,color:`gray`,children:`Clear`})]})}function LB(e){let t=[...e.context,e.responseItem];return(0,I.jsxs)(`div`,{children:[e.item.text&&(0,I.jsx)(q,{order:4,mb:`md`,children:e.item.text}),(0,I.jsx)(BB,{formState:e.formState,context:t,items:e.item.item??[],responseItems:e.responseItem.item??[]})]},e.item.linkId)}function RB(e){return(0,I.jsxs)(I.Fragment,{children:[e.responseItems.map(t=>(0,I.jsx)(LB,{formState:e.formState,context:e.context,item:e.item,responseItem:t},`group-${t.id}`)),(0,I.jsx)(pu,{onClick:()=>e.formState.onAddGroup(e.context,e.item),children:`Add Group: ${e.item.text}`})]})}function zB(e){let{formState:t,context:n,item:r,responseItem:i}=e,a=r.type===Sk.choice||r.type===Sk.openChoice,o=!a,s=!a&&i.answer&&i.answer.length>0?i.answer:[{}];return(0,I.jsxs)(tI,{title:e.item.text,withAsterisk:e.item.required,children:[(0,I.jsx)(G,{gap:`xs`,children:s?.map((e,a)=>(0,I.jsx)(nB,{formState:t,context:n,item:r,responseItem:i,index:a},`${r.linkId}-${a}`))}),o&&(0,I.jsx)(pu,{onClick:()=>t.onAddAnswer(n,r),children:`Add Item`})]},e.item.linkId)}function BB(e){let{formState:t,context:n,items:r,responseItems:i}=e,a=n.length===0,o=!1;return(0,I.jsx)(G,{gap:`xl`,children:r.map((e,r)=>{if(!Fk(e,t.questionnaireResponse))return null;let s=e.type===Sk.group,c=a&&s&&o;if(s&&(o=!0),e.type===Sk.display)return(0,I.jsx)(`p`,{children:e.text},`display-${e.id}-${r}`);let l=i.filter(t=>t.linkId===e.linkId);return e.type===Sk.group&&e.repeats?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(RB,{formState:t,context:n,item:e,responseItems:l})]},`repeating-group-${e.id}-${r}`):e.type===Sk.group?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(LB,{formState:t,context:n,item:e,responseItem:l[0]})]},`group-${e.id}-${r}`):e.type===Sk.boolean?(0,I.jsx)(nB,{formState:t,context:n,item:e,responseItem:l[0],index:0},`boolean-item-${e.id}-${r}`):e.repeats?(0,I.jsx)(zB,{formState:t,context:n,item:e,responseItem:l[0]},`repeating-item-${e.id}-${r}`):(0,I.jsx)(tI,{htmlFor:e.linkId,title:e.text,withAsterisk:e.required,children:(0,I.jsx)(nB,{formState:t,context:n,item:e,responseItem:l[0],index:0})},`repeating-item-${e.id}-${r}`)})})}function VB(e){let{formState:t,submitButtonText:n,excludeButtons:r,children:i}=e,a=t.pages,o=t.activePage,s=o>0,c=o<a.length-1,l=o===a.length-1;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Fy,{active:o,allowNextStepsSelect:!1,p:6,children:a.map((e,t)=>(0,I.jsx)(Fy.Step,{label:e.title,children:t===o&&i},e.linkId))}),!r&&(0,I.jsxs)(V,{justify:`flex-end`,mt:`xl`,gap:`xs`,children:[s&&(0,I.jsx)(U,{onClick:t.onPrevPage,children:`Back`}),c&&(0,I.jsx)(U,{onClick:e=>{e.currentTarget.closest(`form`).reportValidity()&&t.onNextPage()},children:`Next`}),l&&(0,I.jsx)(GN,{children:n??`Submit`})]})]})}function HB(e){let t=Q(),[n,r]=(0,b.useState)(!1),i=(0,b.useRef)(e),a=(0,b.useRef)(void 0);(0,b.useLayoutEffect)(()=>{i.current=e});let o=(0,b.useCallback)(e=>{a.current=e},[]),s=oA({questionnaire:e.questionnaire,defaultValue:e.questionnaireResponse,subject:e.subject,encounter:e.encounter,source:e.source,disablePagination:e.disablePagination,onChange:o}),c=(0,b.useRef)(s);(0,b.useLayoutEffect)(()=>{c.current=s}),(0,b.useEffect)(()=>{let e=a.current;e&&(a.current=void 0,r(!1),i.current.onChange?.(e))});let l=(0,b.useMemo)(()=>s.loading?!1:!!_C(s.questionnaire,kk),[s]),u=(0,b.useMemo)(()=>s.loading?!1:!!s.questionnaireResponse.extension?.find(e=>e.url===Ak),[s]),d=(0,b.useCallback)(()=>{let e=c.current;if(e.loading)return;let n=i.current.onSubmit;if(!n)return;if(l&&!u){r(!0);return}let a=e.questionnaire,o=e.questionnaireResponse,s=i.current.subject,d=i.current.source;if(!d){let e=t.getProfile();e&&(d=iC(e))}n({...o,questionnaire:a.url??aC(a),subject:s,source:d,authored:new Date().toISOString(),status:`completed`})},[t,l,u]);return s.loading?null:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:d,children:[s.questionnaire.title&&(0,I.jsx)(q,{order:1,fz:`1.625rem`,fw:700,lh:1.3,mb:`xl`,children:s.questionnaire.title}),e.afterHeader&&(0,I.jsxs)(G,{gap:`xl`,mb:`xl`,children:[e.afterHeader,(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`})]}),s.pagination?(0,I.jsx)(VB,{formState:s,submitButtonText:e.submitButtonText,excludeButtons:e.excludeButtons,children:(0,I.jsx)(BB,{formState:s,context:[],items:s.items,responseItems:s.responseItems})}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(BB,{formState:s,context:[],items:s.items,responseItems:s.responseItems}),l&&(0,I.jsxs)(G,{mt:`md`,gap:0,children:[(0,I.jsx)(H,{size:`sm`,fw:500,children:`Signature`}),(0,I.jsx)(IB,{onChange:s.onChangeSignature}),!u&&n&&(0,I.jsx)(H,{c:`red`,size:`sm`,children:`Signature is required.`})]}),!e.excludeButtons&&(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,gap:`xs`,children:(0,I.jsx)(GN,{children:e.submitButtonText??`Submit`})})]})]})}var UB={section:`_section_4m5it_1`},WB=[`gender`,`age`,`gestationalAge`,`context`,`appliesTo`,`category`],GB={definition:{resourceType:`ObservationDefinition`,code:{text:``}},onSubmit:()=>{}};function KB(e){e=Object.assign(GB,e);let t=e.definition,[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(1),[o,s]=(0,b.useState)(1);return(0,b.useEffect)(()=>{r(XB(YB(t,s).qualifiedInterval||[],a))},[t]),(0,I.jsxs)(WN,{testid:`reference-range-editor`,onSubmit:c,children:[(0,I.jsx)(G,{children:n.map(e=>(0,I.jsx)(qB,{unit:QB(t.quantitativeDetails?.unit),onChange:d,onAdd:f,onRemove:p,onRemoveGroup:u,intervalGroup:e},`group-${e.id}`))}),(0,I.jsx)(vl,{title:`Add Group`,variant:`subtle`,size:`sm`,onClick:e=>{aM(e),l({id:`group-id-${i}`,filters:{},intervals:[]}),a(e=>e+1)},children:(0,I.jsx)(YA,{})}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(GN,{children:`Save`})})]});function c(){let r=n.flatMap(e=>e.intervals).filter(e=>!$B(e));e.onSubmit({...t,qualifiedInterval:r})}function l(e){r(t=>[...t,e])}function u(e){r(t=>t.filter(t=>t.id!==e.id))}function d(e,t){r(n=>{n=[...n];let r=n.find(t=>t.id===e),i=r?.intervals.findIndex(e=>e.id===t.id);return i!==void 0&&r?.intervals[i]&&(r.intervals[i]=t),n})}function f(e,t){t.id===void 0&&(t.id=`id-${o}`,s(e=>e+1)),r(n=>{n=[...n];let r=n.findIndex(t=>t.id===e);if(r!==-1){let e={...n[r]};t={...t,...e.filters},e.intervals=[...e.intervals,t],n[r]=e}return n})}function p(e,t){r(n=>{n=[...n];let r=n.find(t=>t.id===e);return r&&(r.intervals=r.intervals.filter(e=>e.id!==t.id)),n})}}function qB(e){let{intervalGroup:t,unit:n}=e;return(0,I.jsx)(RP,{"data-testid":t.id,className:UB.section,children:(0,I.jsxs)(G,{gap:`lg`,children:[(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(vl,{title:`Remove Group`,variant:`subtle`,"data-testid":`remove-group-button-${t.id}`,size:`sm`,onClick:n=>{aM(n),e.onRemoveGroup(t)},children:(0,I.jsx)(JA,{})},`remove-group-button-${t.id}`)}),(0,I.jsx)(JB,{intervalGroup:t,onChange:e.onChange}),(0,I.jsx)(bp,{}),t.intervals.map(n=>(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsxs)(V,{children:[(0,I.jsx)(yb,{"data-testid":`condition-${n.id}`,defaultValue:n.condition,label:`Condition: `,size:`sm`,onChange:r=>{aM(r),e.onChange(t.id,{...n,condition:r.currentTarget.value.trim()})}},`condition-${n.id}`),(0,I.jsx)(vl,{title:`Remove Interval`,variant:`subtle`,size:`sm`,"data-testid":`remove-interval-${n.id}`,onClick:r=>{aM(r),e.onRemove(t.id,n)},children:(0,I.jsx)(JA,{})},`remove-interval-${n.id}`)]}),(0,I.jsx)(wI,{path:``,onChange:r=>{e.onChange(t.id,{...n,range:r})},name:`range-${n.id}`,defaultValue:n.range},`range-${n.id}`)]},`interval-${n.id}`)),(0,I.jsx)(vl,{title:`Add Interval`,variant:`subtle`,size:`sm`,onClick:r=>{aM(r),e.onAdd(t.id,{range:{low:{unit:n},high:{unit:n}}})},children:(0,I.jsx)(YA,{})})]})})}function JB(e){let{intervalGroup:t,onChange:n}=e,r=t.filters.age??{},i={low:r.low?.unit?r.low:{...r.low,unit:`years`,system:`http://unitsofmeasure.org`},high:r.high?.unit?r.high:{...r.high,unit:`years`,system:`http://unitsofmeasure.org`}};return(0,I.jsxs)(G,{style:{maxWidth:`50%`},children:[(0,I.jsx)(V,{children:(0,I.jsx)(yg,{data:[``,`male`,`female`],label:`Gender:`,defaultValue:t.filters.gender||``,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``&&(i=void 0),n(t.id,{...r,gender:i})}}})}),(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(H,{component:`label`,htmlFor:`div-age-${t.id}`,children:`Age:`}),(0,I.jsx)(`div`,{id:`div-age-${t.id}`,children:(0,I.jsx)(wI,{path:``,name:`age-${t.id}`,defaultValue:i,onChange:e=>{for(let r of t.intervals)n(t.id,{...r,age:e})}},`age-${t.id}`)})]}),(0,I.jsx)(yg,{data:[``,`pre-puberty`,`follicular`,`midcycle`,`luteal`,`postmenopausal`],label:`Endocrine:`,defaultValue:t.filters.context?.text||``,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``?(i=void 0,n(t.id,{...r,context:void 0})):n(t.id,{...r,context:{text:i,coding:[{code:i,system:`http://terminology.hl7.org/CodeSystem/referencerange-meaning`}]}})}}}),(0,I.jsx)(yg,{data:[``,`reference`,`critical`,`absolute`],label:`Category: `,defaultValue:t.filters.category,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``?n(t.id,{...r,category:void 0}):n(t.id,{...r,category:i})}}})]})}function YB(e,t){let n=e.qualifiedInterval||[],r=Math.max(...n.map(e=>{let t=Number.parseInt(e.id?.substring(3)||``,10);return Number.isNaN(t)?-1/0:t}))+1;return Number.isFinite(r)||(r=1),e={...e,qualifiedInterval:n.map(e=>({...e,id:e.id||`id-${r++}`}))},t(r),e}function XB(e,t){let n=1,r={};for(let t of e){let e=ZB(t);e in r||(r[e]={id:`group-id-${n++}`,filters:Object.fromEntries(WB.map(e=>[e,t[e]])),intervals:[]}),r[e].intervals.push(t)}return t(n),Object.values(r)}function ZB(e){return[`gender=${e.gender}`,`age=${vw(e.age)}`,`gestationalAge=${vw(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(e=>e.text).join(`+`)}`,`category=${e.category}`].join(`:`)}function QB(e){return e&&(GC(e,`http://unitsofmeasure.org`)||e.text)}function $B(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}function eV(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)();if((0,b.useEffect)(()=>{n&&!r&&(t.executeBatch(s(n)).then(o).catch(console.log),i(!0))},[t,n,r]),!n||!a)return null;return(0,I.jsx)(Fp,{children:n.action?.map((t,n)=>{let r=t.resource&&c(t.resource),i=r?.input?.[0]?.valueReference,a=r?.output?.[0]?.valueReference;return(0,I.jsxs)(b.Fragment,{children:[(0,I.jsx)(Fp.Col,{span:1,p:`md`,children:r?.status===`completed`?(0,I.jsx)(GA,{}):(0,I.jsx)(Hj,{color:`gray`})}),(0,I.jsxs)(Fp.Col,{span:9,p:`xs`,children:[(0,I.jsx)(H,{fw:500,children:t.title}),t.description&&(0,I.jsx)(`div`,{children:t.description}),(0,I.jsxs)(`div`,{children:[`Last edited by\xA0`,(0,I.jsx)(oL,{value:r?.meta?.author}),`\xA0on\xA0`,dw(r?.meta?.lastUpdated)]}),(0,I.jsxs)(`div`,{children:[`Status: `,(0,I.jsx)(lL,{status:r?.status||`unknown`})]})]}),(0,I.jsxs)(Fp.Col,{span:2,p:`md`,children:[i&&!a&&(0,I.jsx)(U,{onClick:()=>e.onStart(r,i),children:`Start`}),i&&a&&(0,I.jsx)(U,{onClick:()=>e.onEdit(r,i,a),children:`Edit`})]})]},`action-${n}`)})});function s(e){let t=[];if(e.action)for(let n of e.action)n.resource?.reference&&t.push({request:{method:`GET`,url:n.resource.reference}});return{resourceType:`Bundle`,type:`batch`,entry:t}}function c(e){for(let t of a?.entry??[])if(t.resource&&e.reference===aC(t.resource))return t.resource}}function tV(e,t){return rV(nV(e,t),e,t)}function nV(e,t){let n=e.length,r=t.length,i=n+r+1,a=1+2*i,o=Math.trunc(a/2),s=Array(a);s[o+1]={i:0,j:-1,prev:void 0,snake:!0};for(let a=0;a<i;a++){for(let i=-a;i<=a;i+=2){let c=o+i,l=c+1,u=c-1,d=s[l],f=s[u],p,m=0;i===-a||i!==a&&f.i<d.i?(m=d.i,p=d):(m=f.i+1,p=f),s[u]=void 0;let h=m-i,g={i:m,j:h,prev:iV(p),snake:!1};for(;m<n&&h<r&&e[m]===t[h];)m++,h++;if(m>g.i&&(g={i:m,j:h,prev:g,snake:!0}),s[c]=g,m>=n&&h>=r)return s[c]}s[o+a-1]=void 0}}function rV(e,t,n){let r=[],i=e;for(i.snake&&(i=i.prev);i?.prev&&i.prev.j>=0;){let e=i.i,a=i.j;i=i.prev;let o=i.i,s=i.j,c={position:o,lines:t.slice(o,e)},l={position:s,lines:n.slice(s,a)},u;u=c.lines.length===0&&l.lines.length>0?`insert`:c.lines.length>0&&l.lines.length===0?`delete`:`change`,r.push({original:c,revised:l,type:u}),i.snake&&(i=i.prev)}return r}function iV(e){return e&&!e.snake&&e.prev?e.prev:e}function aV(e){let t=(e.entry??[]).filter(e=>!!e.resource).map(e=>({meta:e.resource?.meta,lines:vC(e.resource,!0).match(/[^\r\n]+/g)})).sort((e,t)=>e.meta.lastUpdated.localeCompare(t.meta.lastUpdated));if(!t.length)return[];let n=t[0].lines.map(e=>({id:t[0].meta.versionId,meta:t[0].meta,value:e,span:1}));return oV(n,t),sV(n),n}function oV(e,t){for(let n=1;n<t.length;n++){let r=tV(t[n-1].lines,t[n].lines);for(let i of r){let r=i.original.position,a=i.original.lines,o=i.revised.lines;if((i.type===`delete`||i.type===`change`)&&e.splice(r,a.length),i.type===`insert`||i.type===`change`)for(let a=0;a<i.revised.lines.length;a++)e.splice(r+a,0,{id:t[n].meta.versionId,meta:t[n].meta,value:o[a],span:1})}}}function sV(e){let t=0;for(;t<e.length;){let n=t;for(;n<e.length&&e[n].id===e[t].id;)e[n].span=-1,n++;e[t].span=n-t,t=n}}var cV={container:`_container_1gji2_1`,root:`_root_1gji2_5`,startRow:`_startRow_1gji2_20`,normalRow:`_normalRow_1gji2_25`,author:`_author_1gji2_30`,onBehalfOf:`_onBehalfOf_1gji2_34`,dateTime:`_dateTime_1gji2_40`,lineNumber:`_lineNumber_1gji2_46`,line:`_line_1gji2_46`,pre:`_pre_1gji2_61`};function lV(e,t){return`/${e.resourceType}/${e.id}/_history/${t}`}function uV(e){let t=Math.floor((Date.now()-Date.parse(e))/1e3),n=Math.floor(t/31536e3);if(n>0)return dV(n,`year`);let r=Math.floor(t/2592e3);if(r>0)return dV(r,`month`);let i=Math.floor(t/86400);if(i>0)return dV(i,`day`);let a=Math.floor(t/3600);if(a>0)return dV(a,`hour`);let o=Math.floor(t/60);return o>0?dV(o,`minute`):dV(t,`second`)}function dV(e,t){return`${e} ${e===1?t:t+`s`} ago`}function fV(e){let t=Q(),[n,r]=(0,b.useState)(e.history);if((0,b.useEffect)(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(r).catch(console.log)},[t,e.history,e.resourceType,e.id]),!n)return(0,I.jsx)(`div`,{children:`Loading...`});let i=n.entry?.[0]?.resource;if(!i)return null;let a=aV(n);return(0,I.jsx)(`div`,{className:cV.container,children:(0,I.jsx)(`table`,{className:cV.root,children:(0,I.jsx)(`tbody`,{children:a.map((e,t)=>(0,I.jsxs)(`tr`,{className:e.span>0?cV.startRow:cV.normalRow,children:[e.span>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`td`,{className:cV.author,rowSpan:e.span,children:[(0,I.jsx)(oL,{value:e.meta.author,link:!0,fz:`xs`}),e.meta.onBehalfOf&&(0,I.jsxs)(`div`,{className:cV.onBehalfOf,children:[`on behalf of `,(0,I.jsx)(oL,{value:e.meta.onBehalfOf,link:!0,fz:`xs`,c:`dimmed`})]})]}),(0,I.jsx)(`td`,{className:cV.dateTime,rowSpan:e.span,children:(0,I.jsx)(dM,{to:lV(i,e.meta.versionId),fz:`xs`,children:uV(e.meta.lastUpdated)})})]}),(0,I.jsx)(`td`,{className:cV.lineNumber,children:t+1}),(0,I.jsx)(`td`,{className:cV.line,children:(0,I.jsx)(`pre`,{className:cV.pre,children:e.value})})]},`row-`+t))})})})}var pV={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function mV(e){let t=e.original,n=e.revised;return e.ignoreMeta&&(t={...t,meta:void 0},n={...n,meta:void 0}),(0,I.jsx)(`pre`,{style:{color:`gray`},children:tV(vC(t,!0).match(/[^\r\n]+/g)??[`{`,`}`],vC(n,!0).match(/[^\r\n]+/g)??[`{`,`}`]).map((e,t)=>(0,I.jsx)(hV,{delta:e},`delta`+t))})}function hV(e){return(0,I.jsxs)(I.Fragment,{children:[`...`,(0,I.jsx)(`br`,{}),e.delta.original.lines.length>0&&(0,I.jsx)(`div`,{className:pV.removed,children:e.delta.original.lines.join(`
|
|
206
|
+
[${JSON.stringify(t,null,2)}]`);return(0,I.jsx)(KF,{value:t[0]||``,propertyType:e.propertyType})}function QL(e){return(0,I.jsxs)(Bh,{title:`Export`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:e.onCancel,children:[(0,I.jsxs)(z,{display:`flex`,style:{justifyContent:`space-between`},children:[e.exportCsv&&(0,I.jsx)($L,{text:`CSV`,exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,I.jsx)($L,{text:`Transaction Bundle`,exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),(0,I.jsx)(H,{style:{marginTop:`10px`,marginLeft:`2px`},children:`Limited to 1000 records`})]})}function $L(e){return(0,I.jsx)(U,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var eR={string:[Z.EQUALS,Z.NOT,Z.CONTAINS,Z.EXACT],fulltext:[Z.EQUALS,Z.NOT,Z.CONTAINS,Z.EXACT],token:[Z.EQUALS,Z.NOT,Z.TEXT],reference:[Z.EQUALS,Z.NOT],numeric:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS],quantity:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS],date:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS,Z.STARTS_AFTER,Z.ENDS_BEFORE,Z.APPROXIMATELY],datetime:[Z.EQUALS,Z.NOT_EQUALS,Z.GREATER_THAN,Z.LESS_THAN,Z.GREATER_THAN_OR_EQUALS,Z.LESS_THAN_OR_EQUALS,Z.STARTS_AFTER,Z.ENDS_BEFORE,Z.APPROXIMATELY],uri:[Z.EQUALS,Z.NOT,Z.ABOVE,Z.BELOW]},tR={eq:`equals`,ne:`not equals`,gt:`greater than`,lt:`less than`,ge:`greater than or equals`,le:`less than or equals`,sa:`starts after`,eb:`ends before`,ap:`approximately`,sw:`starts with`,contains:`contains`,exact:`exact`,text:`text`,not:`not`,above:`above`,below:`below`,in:`in`,"not-in":`not in`,"of-type":`of type`,missing:`missing`,present:`present`,identifier:`identifier`,iterate:`iterate`};function nR(e,t){return{...e,filters:t,offset:0,name:void 0}}function rR(e,t){return nR(e,(e.filters??[]).filter(e=>e.code!==t))}function iR(e,t,n,r,i){i&&(e=rR(e,t));let a=[];return e.filters&&a.push(...e.filters),a.push({code:t,operator:n,value:r??``}),nR(e,a)}function aR(e,t){if(!e.filters)return e;let n=[...e.filters];return n.splice(t,1),{...e,filters:n,name:void 0}}function oR(e,t){return lR(e,t,-1)}function sR(e,t){return lR(e,t,0)}function cR(e,t){return lR(e,t,1)}function lR(e,t,n){let r=new Date;r.setDate(r.getDate()+n),r.setHours(0,0,0,0);let i=new Date(r.getTime());return i.setDate(i.getDate()+1),i.setTime(i.getTime()-1),gR(e,t,r,i)}function uR(e,t){let n=new Date;return gR(e,t,n,new Date(n.getTime()+1440*60*1e3))}function dR(e,t){return mR(e,t,-1)}function fR(e,t){return mR(e,t,0)}function pR(e,t){return mR(e,t,1)}function mR(e,t,n){let r=new Date;r.setMonth(r.getMonth()+n),r.setDate(1),r.setHours(0,0,0,0);let i=new Date(r.getTime());return i.setMonth(i.getMonth()+1),i.setDate(1),i.setHours(0,0,0,0),i.setTime(i.getTime()-1),gR(e,t,r,i)}function hR(e,t){let n=new Date;return n.setMonth(0),n.setDate(1),n.setHours(0,0,0,0),gR(e,t,n,new Date)}function gR(e,t,n,r){return e=rR(e,t),e=_R(e,t,Z.GREATER_THAN_OR_EQUALS,n),e=_R(e,t,Z.LESS_THAN_OR_EQUALS,r),e}function _R(e,t,n,r){return iR(e,t,n,r.toISOString())}function vR(e,t,n=!0){return iR(e,t,Z.MISSING,n.toString())}function yR(e,t){return e.offset===t?e:{...e,offset:t,name:void 0}}function bR(e,t){let n=e.count??20;return yR(e,(t-1)*n)}function xR(e,t,n){return t===SR(e)&&n!==void 0&&n===CR(e)?e:{...e,sortRules:[{code:t,descending:!!n}],name:void 0}}function SR(e){let t=e.sortRules;if(!t||t.length===0)return;let n=t[0].code;return n.startsWith(`-`)?n.substr(1):n}function CR(e){let t=e.sortRules;return!t||t.length===0?!1:!!t[0].descending}function wR(e){return eR[e.type]}function TR(e){return tR[e]??``}function ER(e){let t=e;return t.includes(`.`)&&(t=t.split(`.`).pop()),t===`versionId`?`Version ID`:(t=t.replace(`[x]`,``),t=t.replaceAll(/([A-Z])/g,` $1`),t=t.replaceAll(/[-_]/g,` `),t=t.replaceAll(/\s+/g,` `),t=t.trim(),t.toLowerCase()===`id`?`ID`:t.split(/\s/).map(HC).join(` `))}function DR(e,t){let n=t.name;return n===`id`?(0,I.jsx)(dM,{to:`/${e.resourceType}/${e.id}`,children:e.id}):n===`meta.versionId`?e.meta?.versionId:n===`_lastUpdated`?dw(e.meta?.lastUpdated):`${e.resourceType}.${t.name}`===t.elementDefinition?.path?OR(e,t.elementDefinition):t.searchParams?.length===1&&t.name===t.searchParams[0].code?kR(e,t.searchParams[0]):null}function OR(e,t){let n=t.path?.split(`.`)?.pop()?.replaceAll(`[x]`,``)??``,[r,i]=AF({type:e.resourceType,value:e},n);return r?(0,I.jsx)(KF,{path:t.path,property:t,propertyType:i,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function kR(e,t){let n=RT(t.expression,[{type:e.resourceType,value:e}]);return!n||n.length===0?null:(0,I.jsx)(I.Fragment,{children:n.map((e,t)=>(0,I.jsx)(KF,{propertyType:e.type,value:e.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${t}-${n.length}`))})}function AR(e){let t=(0,b.useRef)(!1),[n,r]=(0,b.useState)({search:JSON.parse(vC(e.search))}),[i,a]=(0,b.useState)(!1);(0,b.useEffect)(()=>{r({search:e.search})},[e.search]);let o=(0,b.useMemo)(()=>{if(!e.visible)return[];let t=e.search.resourceType;return XC(jR(pS(t),Nw(t))).map(e=>({value:e,label:ER(e)}))},[e.visible,e.search.resourceType]);function s(e){r({search:{...n.search,fields:e}})}return(0,I.jsx)(Bh,{title:`Fields`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:()=>{e.onCancel()},size:`auto`,withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{t.current=i},onClick:()=>{t.current||e.onCancel(),t.current=!1},children:(0,I.jsx)(`div`,{"data-testid":`overlay-child`})},children:(0,I.jsxs)(G,{children:[(0,I.jsx)(hg,{style:{width:550},placeholder:`Select fields to display`,data:o,value:n.search.fields??[],onChange:s,onDropdownOpen:()=>a(!0),onDropdownClose:()=>a(!1),maxDropdownHeight:`250px`,clearButtonProps:{"aria-label":`Clear selection`},clearable:!0,searchable:!0}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{onClick:()=>e.onOk(n.search),children:`OK`})})]})})}function jR(e,t){let n=[],r=new Set,i=new Set;for(let t of Object.keys(e.elements))n.push(t),r.add(t.toLowerCase()),i.add(ER(t));if(t)for(let e of Object.keys(t)){let t=ER(e);!r.has(e)&&!i.has(t)&&(n.push(e),r.add(e),i.add(t))}return n}function MR(e){let t=GO(e.resourceType,e.searchParam),n=e.name??`filter-value`;switch(t.type){case WO.REFERENCE:return(0,I.jsx)(NI,{name:n,defaultValue:e.defaultValue?{reference:e.defaultValue}:void 0,targetTypes:e.searchParam.target,autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(t.reference):e.onChange(``)}});case WO.BOOLEAN:return(0,I.jsx)(Bd,{name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultChecked:e.defaultValue===`true`,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.checked.toString())});case WO.DATE:return(0,I.jsx)(yb,{type:`date`,name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value)});case WO.DATETIME:return(0,I.jsx)(mI,{name:n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case WO.NUMBER:return(0,I.jsx)(yb,{type:`number`,name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value)});case WO.QUANTITY:return(0,I.jsx)(SI,{name:n,path:``,defaultValue:NR(e.defaultValue),autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(`${t.value}`):e.onChange(``)}});default:return(0,I.jsx)(yb,{name:n,"data-autofocus":e.autoFocus,"data-testid":n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:t=>e.onChange(t.currentTarget.value),placeholder:`Search value`})}}function NR(e){if(e){let[t,n,r]=e.split(`|`);if(t)return{value:Number.parseFloat(t),system:n,unit:r}}}function PR(e){let[t,n]=(0,b.useState)(jC(e.search)),r=(0,b.useRef)(t);(0,b.useLayoutEffect)(()=>{r.current=t}),(0,b.useEffect)(()=>{n(jC(e.search))},[e.search]);function i(e){n(iR(r.current,e.code,e.operator,e.value))}let a=e.search.resourceType,o=Nw(a)??{},s=t.filters||[];return(0,I.jsx)(Bh,{title:`Filters`,closeButtonProps:{"aria-label":`Close`},size:900,opened:e.visible,onClose:e.onCancel,children:(0,I.jsxs)(WN,{onSubmit:()=>e.onOk(r.current),children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`table`,{children:[(0,I.jsxs)(`colgroup`,{children:[(0,I.jsx)(`col`,{style:{width:200}}),(0,I.jsx)(`col`,{style:{width:200}}),(0,I.jsx)(`col`,{style:{width:380}}),(0,I.jsx)(`col`,{style:{width:40}})]}),(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Field`}),(0,I.jsx)(`th`,{children:`Operation`}),(0,I.jsx)(`th`,{children:`Value`}),(0,I.jsx)(`th`,{})]})}),(0,I.jsx)(`tbody`,{children:s.map((e,t)=>(0,I.jsx)(FR,{id:`filter-${t}-row`,resourceType:a,searchParams:o,value:e,onChange:e=>{let i=[...s];i[t]=e,n(nR(r.current,i))},onDelete:()=>n(aR(r.current,t))},`filter-${t}-row`))})]}),(0,I.jsx)(BI,{propertyDisplayName:`Filter`,onClick:()=>i({})})]}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(GN,{children:`OK`})})]})})}function FR(e){let t=e.value;function n(t){e.onChange({code:t,operator:Z.EQUALS,value:``})}function r(n){e.onChange({code:t.code,operator:n,value:``})}function i(n){e.onChange({code:t.code,operator:t.operator,value:n})}let a=e.searchParams[t.code],o=a&&wR(a);return(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(yg,{"data-testid":`${e.id}-filter-field`,defaultValue:e.value.code,onChange:e=>n(e.currentTarget.value),data:[``,...Object.keys(e.searchParams).map(e=>({value:e,label:ER(e)}))]})}),(0,I.jsx)(`td`,{children:o&&(0,I.jsx)(yg,{"data-testid":`${e.id}-filter-operation`,defaultValue:t.operator,onChange:e=>r(e.currentTarget.value),data:[``,...o.map(e=>({value:e,label:TR(e)}))]},`${e.id}-filter-value-${e.value.code}`)}),(0,I.jsx)(`td`,{children:a&&t.operator&&(0,I.jsx)(MR,{name:`${e.id}-filter-value`,resourceType:e.resourceType,searchParam:a,defaultValue:t.value,onChange:i},`${e.id}-filter-value-${e.value.code}-${e.value.operator}`)}),(0,I.jsx)(`td`,{children:e.onDelete&&(0,I.jsx)(vl,{variant:`outline`,color:`red`,radius:`xl`,"aria-label":`Delete filter`,onClick:e.onDelete,children:(0,I.jsx)($j,{style:{width:`70%`,height:`70%`},stroke:1.5})})})]})}function IR(e){let[t,n]=(0,b.useState)(e.defaultValue??``);if(!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:t})}return(0,I.jsx)(Bh,{title:e.title,size:`xl`,opened:e.visible,onClose:e.onCancel,children:(0,I.jsx)(WN,{onSubmit:r,children:(0,I.jsxs)(Fp,{children:[(0,I.jsx)(Fp.Col,{span:10,children:(0,I.jsx)(MR,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:t,autoFocus:!0,onChange:n})}),(0,I.jsx)(Fp.Col,{span:2,children:(0,I.jsx)(U,{onClick:r,fullWidth:!0,children:`OK`})})]})})})}function LR(e){let{resourceType:t,filter:n}=e,r=Uw.types[t].searchParams?.[n.code];if(r){if(r.type===`reference`&&(n.operator===Z.EQUALS||n.operator===Z.NOT_EQUALS))return(0,I.jsx)(oL,{value:{reference:n.value}});let e=GO(t,r);if(n.code===`_lastUpdated`||e.type===WO.DATETIME)return(0,I.jsx)(I.Fragment,{children:dw(n.value)})}return(0,I.jsx)(I.Fragment,{children:n.value})}function RR(e){if(!e.searchParams)return null;function t(t,n){i(xR(e.search,t.code,n))}function n(t){i(rR(e.search,t.code))}function r(t,n){e.onPrompt(t,{code:t.code,operator:n,value:``})}function i(t){e.onChange(t)}return e.searchParams.length===1?(0,I.jsx)(zR,{search:e.search,searchParam:e.searchParams[0],onSort:t,onPrompt:r,onChange:i,onClear:n}):(0,I.jsx)(W.Dropdown,{children:e.searchParams.map(e=>(0,I.jsx)(W.Item,{children:ER(e.code)},e.code))})}function zR(e){switch(e.searchParam.type){case`date`:return(0,I.jsx)(BR,{...e});case`number`:case`quantity`:return(0,I.jsx)(VR,{...e});case`reference`:return(0,I.jsx)(HR,{...e});case`string`:return(0,I.jsx)(UR,{...e});case`token`:return(0,I.jsx)(WR,{...e});case`uri`:return(0,I.jsx)(GR,{...e});default:return(0,I.jsxs)(I.Fragment,{children:[`Unknown search param type: `,e.searchParam.type]})}}function BR(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Oldest to Newest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Newest to Oldest`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT_EQUALS),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(xj,{size:14}),onClick:()=>e.onPrompt(t,Z.ENDS_BEFORE),children:`Before...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(bj,{size:14}),onClick:()=>e.onPrompt(t,Z.STARTS_AFTER),children:`After...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(LA,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Between...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(cR(e.search,n)),children:`Tomorrow`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(sR(e.search,n)),children:`Today`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(oR(e.search,n)),children:`Yesterday`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(uR(e.search,n)),children:`Next 24 Hours`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(pR(e.search,n)),children:`Next Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(fR(e.search,n)),children:`This Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(dR(e.search,n)),children:`Last Month`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(UA,{size:14}),onClick:()=>e.onChange(hR(e.search,n)),children:`Year to date`}),(0,I.jsx)(KR,{...e})]})}function VR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Smallest to Largest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Largest to Smallest`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT_EQUALS),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(bj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN),children:`Greater than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN_OR_EQUALS),children:`Greater than or equal to...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(xj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN),children:`Less than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(zj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN_OR_EQUALS),children:`Less than or equal to...`}),(0,I.jsx)(KR,{...e})]})}function HR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(KR,{...e})]})}function UR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Bj,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort A to Z`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>e.onSort(t,!0),children:`Sort Z to A`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(VA,{size:14}),onClick:()=>e.onPrompt(t,Z.CONTAINS),children:`Contains...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(BA,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Does not contain...`}),(0,I.jsx)(KR,{...e})]})}function WR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.TEXT),children:`Text contains...`}),(0,I.jsx)(KR,{...e})]})}function GR(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(oj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(aj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(KR,{...e})]})}function KR(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(PA,{size:14}),onClick:()=>e.onChange(vR(e.search,n)),children:`Missing`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(NA,{size:14}),onClick:()=>e.onChange(vR(e.search,n,!1)),children:`Not missing`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)($j,{size:14}),onClick:()=>e.onClear(t),children:`Clear filters`})]})}function qR(e){switch(e){case`next`:return{"aria-label":`Next page`};case`previous`:return{"aria-label":`Previous page`};case`first`:return{"aria-label":`First page`};case`last`:return{"aria-label":`Last page`};default:return{}}}var JR={root:`_root_vlout_1`,table:`_table_vlout_8`,tr:`_tr_vlout_12`,th:`_th_vlout_18`,control:`_control_vlout_22`,icon:`_icon_vlout_31`};function YR(e){let t=e.resourceType,n=[];for(let r of e.fields||[`id`,`_lastUpdated`])n.push(XR(t,r));return n}function XR(e,t){if(t===`_lastUpdated`)return{name:`_lastUpdated`,searchParams:[{resourceType:`SearchParameter`,base:[`Resource`],code:`_lastUpdated`,name:`_lastUpdated`,type:`date`,expression:`Resource.meta.lastUpdated`}]};if(t===`meta.versionId`)return{name:`meta.versionId`,searchParams:[{resourceType:`SearchParameter`,base:[`Resource`],code:`_versionId`,name:`_versionId`,type:`token`,expression:`Resource.meta.versionId`}]};let n=zw(e,t),r=Pw(e,t.toLowerCase());if(n&&r)return{name:t,elementDefinition:n,searchParams:[r]};if(n){let r=Nw(e),i;if(r){let n=RegExp(`${e}\\.${t.replaceAll(`[x]`,``)}([^\\w-]|$)`);i=Object.values(r).filter(e=>!!e.expression&&n.test(e?.expression)),i.length===0&&(i=void 0)}return{name:t,elementDefinition:n,searchParams:i}}return r?{name:t,elementDefinition:GO(e,r).elementDefinitions?.[0],searchParams:[r]}:{name:t}}var ZR=class extends Event{definition;constructor(e){super(`change`),this.definition=e}},QR=class extends Event{response;constructor(e){super(`load`),this.response=e}},$R=class extends Event{resource;browserEvent;constructor(e,t){super(`click`),this.resource=e,this.browserEvent=t}};function ez(e){let t=Q(),[n,r]=(0,b.useState)(),{search:i,onLoad:a}=e,[o,s]=(0,b.useState)(i);TC(i,o)||s(i);let[c,l]=(0,b.useState)({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),u=(0,b.useRef)(c);(0,b.useLayoutEffect)(()=>{u.current=c});let d=o.total??`accurate`,f=(0,b.useCallback)(e=>{r(void 0),t.requestSchema(o.resourceType).then(()=>t.search(o.resourceType,cE({...o,total:d,fields:void 0}),e)).then(e=>{l({...u.current,searchResponse:e}),a&&a(new QR(e))}).catch(e=>{l({...u.current,searchResponse:void 0}),r(Zx(e))})},[t,o,d,a]),p=(0,b.useCallback)(()=>{l({...u.current,searchResponse:void 0}),f({cache:`reload`})},[f]);(0,b.useEffect)(()=>{f()},[f]);function m(e,t){e.stopPropagation();let n=e.target.checked,r={...u.current.selected};n?r[t]=!0:delete r[t],l({...u.current,selected:r})}function h(e){e.stopPropagation();let t=e.target.checked,n={},r=u.current.searchResponse;t&&r?.entry&&r.entry.forEach(e=>{e.resource?.id&&(n[e.resource.id]=!0)}),l({...u.current,selected:n})}function g(){if(!c.searchResponse?.entry||c.searchResponse.entry.length===0)return!1;for(let e of c.searchResponse.entry)if(e.resource?.id&&!c.selected[e.resource.id])return!1;return!0}function _(t){e.onChange&&e.onChange(new ZR(t))}function v(t,n){if(sM(t.target)||t.button===2)return;aM(t);let r=oM(t);!r&&e.onClick&&e.onClick(new $R(n,t)),r&&e.onAuxClick&&e.onAuxClick(new $R(n,t))}function y(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(n)return(0,I.jsx)(lF,{outcome:n});if(!dS(o.resourceType))return(0,I.jsx)(hd,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(il,{})});let x=e.checkboxesEnabled,S=YR(o),C=o.resourceType,w=c.searchResponse,T=(w?.entry)?.map(e=>e.resource),E=`subtle`,D=`gray`,O=window.innerWidth<768;return(0,I.jsxs)(`div`,{className:JR.root,"data-testid":`search-control`,children:[!e.hideToolbar&&(0,I.jsxs)(V,{justify:`space-between`,mb:`xl`,children:[(0,I.jsxs)(V,{gap:2,children:[(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(ZA,{size:16}),onClick:()=>l({...u.current,fieldEditorVisible:!0,dialogOpenTime:Date.now()}),children:`Fields`}),(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(dj,{size:16}),onClick:()=>l({...u.current,filterEditorVisible:!0,dialogOpenTime:Date.now()}),children:`Filters`}),e.onNew&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(uj,{size:16}),onClick:e.onNew,children:`New...`}),!O&&y()&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(Kj,{size:16}),onClick:e.onExport?e.onExport:()=>l({...u.current,exportDialogVisible:!0,dialogOpenTime:Date.now()}),children:`Export...`}),!O&&e.onDelete&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(Yj,{size:16}),onClick:()=>e.onDelete(Object.keys(c.selected)),children:`Delete...`}),!O&&e.onBulk&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(IA,{size:16}),onClick:()=>e.onBulk(Object.keys(c.selected)),children:`Bulk...`})]}),(0,I.jsxs)(V,{gap:2,children:[w&&(0,I.jsxs)(H,{size:`xs`,c:`dimmed`,"data-testid":`count-display`,children:[iz(o,w).toLocaleString(),`-`,az(o,w).toLocaleString(),w.total!==void 0&&` of ${o.total===`estimate`?`~`:``}${w.total?.toLocaleString()}`]}),(0,I.jsx)(vl,{variant:E,color:D,title:`Refresh`,onClick:p,children:(0,I.jsx)(Pj,{size:16})})]})]}),(0,I.jsxs)(K,{className:JR.table,children:[(0,I.jsxs)(K.Thead,{children:[(0,I.jsxs)(K.Tr,{children:[x&&(0,I.jsx)(K.Th,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"aria-label":`all-checkbox`,"data-testid":`all-checkbox`,checked:g(),onChange:e=>h(e)})}),S.map(e=>(0,I.jsx)(K.Th,{children:(0,I.jsxs)(W,{shadow:`md`,width:240,position:`bottom-end`,children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(qc,{className:JR.control,p:2,children:(0,I.jsxs)(V,{justify:`space-between`,wrap:`nowrap`,children:[(0,I.jsx)(H,{fw:500,children:ER(e.name)}),(0,I.jsx)(hd,{className:JR.icon,children:(0,I.jsx)(OA,{size:14,stroke:1.5})})]})})}),(0,I.jsx)(RR,{search:o,searchParams:e.searchParams,onPrompt:(e,t)=>{l({...u.current,filterDialogVisible:!0,filterDialogSearchParam:e,filterDialogFilter:t,dialogOpenTime:Date.now()})},onChange:e=>{_(e)}})]})},e.name))]}),!e.hideFilters&&(0,I.jsxs)(K.Tr,{children:[x&&(0,I.jsx)(K.Th,{}),S.map(e=>(0,I.jsx)(K.Th,{children:e.searchParams&&(0,I.jsx)(tz,{resourceType:C,searchParams:e.searchParams,filters:o.filters})},e.name))]})]}),(0,I.jsx)(K.Tbody,{children:T?.map(e=>e&&(0,I.jsxs)(K.Tr,{className:JR.tr,"data-testid":`search-control-row`,onClick:t=>v(t,e),onAuxClick:t=>v(t,e),children:[x&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${e.id}`,checked:!!c.selected[e.id],onChange:t=>m(t,e.id)})}),S.map(t=>(0,I.jsx)(K.Td,{children:DR(e,t)},t.name))]},e.id))})]}),!T?.length&&(0,I.jsx)(RP,{children:(0,I.jsx)(hd,{style:{height:150},children:(0,I.jsx)(H,{size:`xl`,c:`dimmed`,children:`No results`})})}),w&&(0,I.jsx)(hd,{m:`md`,p:`md`,children:(0,I.jsx)(X_,{value:nz(o),total:rz(o,w),onChange:e=>_(bR(o,e)),getControlProps:qR})}),(0,I.jsx)(AR,{search:o,visible:c.fieldEditorVisible,onOk:e=>{_(e),l({...u.current,fieldEditorVisible:!1})},onCancel:()=>{l({...u.current,fieldEditorVisible:!1})}},`search-field-editor-${c.dialogOpenTime}`),(0,I.jsx)(PR,{search:o,visible:c.filterEditorVisible,onOk:e=>{_(e),l({...u.current,filterEditorVisible:!1})},onCancel:()=>{l({...u.current,filterEditorVisible:!1})}},`search-filter-editor-${c.dialogOpenTime}`),(0,I.jsx)(QL,{visible:c.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{l({...u.current,exportDialogVisible:!1})}},`search-export-dialog-${c.dialogOpenTime}`),(0,I.jsx)(IR,{visible:c.filterDialogVisible,title:c.filterDialogSearchParam?.code?ER(c.filterDialogSearchParam.code):``,resourceType:C,searchParam:c.filterDialogSearchParam,filter:c.filterDialogFilter,defaultValue:``,onOk:e=>{_(iR(o,e.code,e.operator,e.value)),l({...u.current,filterDialogVisible:!1})},onCancel:()=>{l({...u.current,filterDialogVisible:!1})}},`search-filter-dialog-${c.dialogOpenTime}`)]})}function tz(e){let t=(e.filters??[]).filter(t=>e.searchParams.find(e=>e.code===t.code));return t.length===0?(0,I.jsx)(`span`,{children:`no filters`}):(0,I.jsx)(I.Fragment,{children:t.map(t=>(0,I.jsxs)(`div`,{children:[TR(t.operator),`\xA0`,(0,I.jsx)(LR,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function nz(e){return Math.floor((e.offset??0)/(e.count??20))+1}function rz(e,t){let n=e.count??20,r=oz(e,t);return Math.ceil(r/n)}function iz(e,t){return Math.min(oz(e,t),(e.offset??0)+1)}function az(e,t){return Math.max(iz(e,t)+(t.entry?.length??0)-1,0)}function oz(e,t){let n=t.total;return n===void 0&&(n=(e.offset??0)+(t.entry?.length??0)+ +!!t.link?.some(e=>e.relation===`next`)),n}function sz(e){let t=Q(),[n,r]=(0,b.useState)(!1),[i,a]=(0,b.useState)(),{query:o,fields:s}=e,[c,l]=(0,b.useState)(),[u,d]=(0,b.useState)({});(0,b.useEffect)(()=>{a(void 0),t.graphql(o).then(l).catch(e=>a(Zx(e)))},[t,o]);function f(e,t){e.stopPropagation();let n=e.target.checked,r={...u};n?r[t]=!0:delete r[t],d(r)}function p(e){e.stopPropagation();let t=e.target.checked,n={},r=c?.data.ResourceList;t&&r&&r.forEach(e=>{e.id&&(n[e.id]=!0)}),d(n)}function m(){let e=c?.data.ResourceList;if(!e||e.length===0)return!1;for(let t of e)if(t.id&&!u[t.id])return!1;return!0}function h(t,n){sM(t.target)||(aM(t),t.button!==1&&e.onClick&&e.onClick(new $R(n,t)),t.button===1&&e.onAuxClick&&e.onAuxClick(new $R(n,t)))}if((0,b.useEffect)(()=>{t.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[t,e.resourceType]),!n)return(0,I.jsx)(il,{});let g=e.checkboxesEnabled;return(0,I.jsxs)(`div`,{onContextMenu:e=>aM(e),"data-testid":`search-control`,children:[(0,I.jsxs)(K,{children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[g&&(0,I.jsx)(K.Th,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"aria-label":`all-checkbox`,"data-testid":`all-checkbox`,checked:m(),onChange:e=>p(e)})}),s.map(e=>(0,I.jsx)(K.Th,{children:e.name},e.name))]})}),(0,I.jsx)(K.Tbody,{children:c?.data.ResourceList.map(e=>e&&(0,I.jsxs)(K.Tr,{"data-testid":`search-control-row`,onClick:t=>h(t,e),onAuxClick:t=>h(t,e),children:[g&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${e.id}`,checked:!!u[e.id],onChange:t=>f(t,e.id)})}),s.map(t=>(0,I.jsx)(K.Td,{children:(0,I.jsx)(ZL,{propertyType:t.propertyType,path:t.fhirPath,resource:e})},t.name))]},e.id))})]}),c?.data.ResourceList.length===0&&(0,I.jsx)(`div`,{"data-testid":`empty-search`,children:`No results`}),i&&(0,I.jsx)(`div`,{"data-testid":`search-error`,children:(0,I.jsx)(`pre`,{style:{textAlign:`left`},children:JSON.stringify(i,void 0,2)})}),e.onBulk&&(0,I.jsx)(U,{onClick:()=>e.onBulk(Object.keys(u)),children:`Bulk...`})]})}var cz=(0,b.memo)(sz),lz={root:`_root_1fbwr_1`,entry:`_entry_1fbwr_8`,key:`_key_1fbwr_13`,value:`_value_1fbwr_20`};function uz(e){return(0,I.jsx)(Hc,{children:(0,I.jsx)(`div`,{className:lz.root,children:e.children})})}uz.Entry=function(e){return(0,I.jsx)(`div`,{className:lz.entry,children:e.children})},uz.Key=function(e){return(0,I.jsx)(`div`,{className:lz.key,children:e.children})},uz.Value=function(e){return(0,I.jsx)(`div`,{className:lz.value,children:e.children})};var dz={list:`_list_y4z6g_1`,link:`_link_y4z6g_6`};function fz(e){let{baseUrl:t,tabs:n,children:r,...i}=e,a=pz(n),o=uk(),[s,c]=(0,b.useState)(()=>{let e=LE.getPathname().split(`/`).pop();if(e){let t=e.toLowerCase(),n=a.find(e=>e.value.split(/[?#]/)[0].toLowerCase()===t);if(n)return n.value}return a[0].value});function l(e){e||=a[0].value,c(e),o(`${t}/${e}`)}return(0,I.jsxs)(vb,{value:s,onChange:l,...i,children:[(0,I.jsx)(vb.List,{className:dz.list,children:a.map(e=>(0,I.jsx)(vb.Tab,{value:e.value,children:(0,I.jsx)(pu,{className:dz.link,href:`${t}/${e.value}`,onClick:mz,children:e.label})},e.value))}),r]})}function pz(e){return e.map(e=>PC(e)?{label:e,value:e.toLowerCase()}:e)}function mz(e){oM(e)||e.preventDefault()}function hz(e){let{group:t}=e;return(0,I.jsx)(Xc,{withBorder:!0,radius:`md`,p:`xs`,display:`flex`,style:{alignItems:`center`,justifyContent:`center`},children:(0,I.jsxs)(V,{children:[t.measureScore&&(0,I.jsx)(vz,{group:t}),!t.measureScore&&(0,I.jsx)(_z,{group:t})]})})}function gz(e){let{measure:t}=e;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(H,{fz:`md`,fw:500,mb:8,children:t.title}),(0,I.jsx)(H,{fz:`xs`,c:`dimmed`,mb:8,children:t.subtitle})]})}function _z(e){let{group:t}=e,n=t.population,r=n?.find(e=>xw(e.code)===`numerator`),i=n?.find(e=>xw(e.code)===`denominator`),a=r?.count,o=i?.count;if(o===0)return(0,I.jsxs)(z,{children:[(0,I.jsx)(q,{order:3,children:`Not Applicable`}),(0,I.jsx)(H,{children:`Denominator: ${o}`})]});if(a===void 0||o===void 0)return(0,I.jsxs)(z,{children:[(0,I.jsx)(q,{order:3,children:`Insufficient Data`}),(0,I.jsx)(H,{children:`Numerator: ${a}`}),(0,I.jsx)(H,{children:`Denominator: ${o}`})]});let s=a/o*100;return(0,I.jsx)(ey,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:bz(s)}],label:(0,I.jsx)(ru,{justify:`center`,children:(0,I.jsxs)(H,{fw:700,fz:18,children:[a,` / `,o]})})})}function vz(e){let{group:t}=e;return(0,I.jsx)(I.Fragment,{children:(t.measureScore?.unit??t.measureScore?.code)===`%`?(0,I.jsx)(ey,{size:120,thickness:12,roundCaps:!0,sections:[{value:yz(t),color:bz(t?.measureScore?.value??0)}],label:(0,I.jsx)(ru,{justify:`center`,children:(0,I.jsx)(H,{fw:700,fz:18,children:(0,I.jsx)(IF,{value:t.measureScore})})})}):(0,I.jsx)(ru,{h:120,align:`center`,children:(0,I.jsx)(q,{order:3,children:(0,I.jsx)(IF,{value:t.measureScore})})})})}function yz(e){let t=e.measureScore?.value,n=e.measureScore?.unit;return t?t<=1&&n===`%`?t*100:t:0}function bz(e){return e<=33?`red`:e<=67?`yellow`:`green`}function xz(e){let t=bk(e.measureReport),[n]=fA(`Measure`,{url:t?.measure});return t?(0,I.jsxs)(z,{children:[n&&(0,I.jsx)(gz,{measure:n}),(0,I.jsx)(_y,{cols:{base:3,sm:1},spacing:{base:`md`,sm:`sm`},children:t.group?.map((e,t)=>(0,I.jsx)(hz,{group:e},e.id??t))})]}):null}var Sz=`patient-accounts`,Cz=`Patient Accounts`,wz=[`Organization`,`HealthcareService`,`CareTeam`];function Tz(e){let{patient:t}=e,n=Q(),r=n.isProjectAdmin()||n.isSuperAdmin(),i=(0,b.useMemo)(()=>sC(t.meta)??[],[t.meta]),[a,o]=(0,b.useState)(i),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!0),[d,f]=(0,b.useState)(!1),p=(0,b.useMemo)(()=>{let e=[];for(let t of a)i.some(e=>e.reference===t.reference)||e.push({reference:t,type:`addition`});for(let t of i)a.some(e=>e.reference===t.reference)||e.push({reference:t,type:`removal`});return e},[i,a]),m=p.length>0,h=(0,b.useCallback)(e=>{e?.reference&&(a.some(t=>t.reference===e.reference)||o(t=>[...t,e]))},[a]),g=(0,b.useCallback)(e=>{o(t=>t.filter(t=>t.reference!==e))},[]),_=(0,b.useCallback)(async()=>{let r=t.id;if(!r){zb.show({id:Sz,title:Cz,color:`red`,message:`Cannot update accounts: Patient resource has no ID.`,icon:(0,I.jsx)($j,{size:`1rem`}),autoClose:!1,withCloseButton:!0});return}f(!0),c(!1);let i=n.fhirUrl(`Patient`,r,`$set-accounts`),o={resourceType:`Parameters`,parameter:[...a.map(e=>({name:`accounts`,valueReference:{reference:e.reference}})),{name:`propagate`,valueBoolean:l}]};zb.show({id:Sz,title:Cz,loading:!0,message:l?`Saving account changes and propagating to compartment...`:`Saving account changes...`,autoClose:!1,withCloseButton:!1});try{let t={};l&&(t.Prefer=`respond-async`),await n.post(i,o,void 0,{headers:t}),n.invalidateUrl(n.fhirUrl(`Patient`,r)),zb.update({id:Sz,title:Cz,color:`green`,message:l?`Account changes saved. Compartment updates are being applied.`:`Account changes saved.`,icon:(0,I.jsx)(WA,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0}),e.onSaved?.()}catch(e){zb.update({id:Sz,title:Cz,color:`red`,message:Y(e),icon:(0,I.jsx)($j,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}finally{f(!1)}},[n,t,a,l,e]);return r?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(G,{children:[(0,I.jsx)(q,{order:3,children:`Current Accounts`}),a.length===0?(0,I.jsx)(H,{c:`dimmed`,children:`No accounts assigned to this patient.`}):(0,I.jsxs)(K,{children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{children:`Type`}),(0,I.jsx)(K.Th,{children:`Account`}),(0,I.jsx)(K.Th,{})]})}),(0,I.jsx)(K.Tbody,{children:a.map(e=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:(0,I.jsx)(Ez,{reference:e})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(sL,{value:e,link:!0})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(vl,{variant:`subtle`,color:`red`,"aria-label":`Remove ${e.reference}`,onClick:()=>g(e.reference),children:(0,I.jsx)($j,{size:16})})})]},e.reference))})]}),(0,I.jsx)(bp,{}),(0,I.jsx)(q,{order:4,children:`Add Account`}),(0,I.jsx)(NI,{name:`newAccount`,placeholder:`Search for Organization, HealthcareService, or CareTeam...`,targetTypes:wz,onChange:e=>{e&&h(e)}}),m&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(bp,{}),(0,I.jsx)(q,{order:4,children:`Pending Changes`}),(0,I.jsx)(G,{gap:`xs`,children:p.map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[e.type===`addition`?(0,I.jsx)(td,{color:`green`,variant:`light`,leftSection:(0,I.jsx)(Mj,{size:12}),children:`Add`}):(0,I.jsx)(td,{color:`red`,variant:`light`,leftSection:(0,I.jsx)(wj,{size:12}),children:`Remove`}),(0,I.jsx)(sL,{value:e.reference,link:!0})]},`${e.type}-${e.reference.reference}`))})]}),(0,I.jsx)(z,{children:(0,I.jsx)(U,{disabled:!m||d,onClick:()=>c(!0),children:`Save Changes`})})]}),(0,I.jsx)(Bh,{opened:s,onClose:()=>c(!1),title:`Confirm Account Changes`,size:`md`,keepMounted:!0,children:(0,I.jsxs)(G,{children:[(0,I.jsxs)(H,{children:[`The following changes will be applied to Patient`,` `,(0,I.jsxs)(`strong`,{children:[t.name?.[0]?.given?.join(` `),` `,t.name?.[0]?.family]}),`:`]}),p.filter(e=>e.type===`addition`).length>0&&(0,I.jsxs)(z,{children:[(0,I.jsx)(H,{fw:600,c:`green`,children:`Adding:`}),(0,I.jsx)(G,{gap:`xs`,mt:`xs`,children:p.filter(e=>e.type===`addition`).map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(Mj,{size:14,color:`green`}),(0,I.jsx)(sL,{value:e.reference})]},e.reference.reference))})]}),p.filter(e=>e.type===`removal`).length>0&&(0,I.jsxs)(z,{children:[(0,I.jsx)(H,{fw:600,c:`red`,children:`Removing:`}),(0,I.jsx)(G,{gap:`xs`,mt:`xs`,children:p.filter(e=>e.type===`removal`).map(e=>(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(wj,{size:14,color:`red`}),(0,I.jsx)(sL,{value:e.reference})]},e.reference.reference))})]}),(0,I.jsx)(Bd,{label:`Propagate changes to all resources in this patient's compartment`,checked:l,onChange:e=>u(e.currentTarget.checked)}),(0,I.jsxs)(V,{justify:`right`,mt:`md`,children:[(0,I.jsx)(U,{variant:`default`,onClick:()=>c(!1),children:`Cancel`}),(0,I.jsx)(U,{onClick:_,loading:d,children:`Confirm`})]})]})})]}):(0,I.jsx)(ou,{color:`blue`,title:`Admin access required`,children:`You need project admin access to manage patient account assignments.`})}function Ez({reference:e}){let t=e.reference?.split(`/`)[0]??`Unknown`;return(0,I.jsx)(td,{variant:`light`,color:{Organization:`blue`,HealthcareService:`teal`,CareTeam:`violet`}[t]??`gray`,size:`sm`,children:t})}var Dz=`patient-export`,Oz=`Patient Export`,kz={everything:{operation:`$everything`,extension:`json`,contentType:ZE.FHIR_JSON},summary:{operation:`$summary`,extension:`json`,contentType:ZE.FHIR_JSON},ccda:{operation:`$ccda-export`,extension:`xml`,contentType:ZE.CDA_XML},ccdaReferral:{operation:`$ccda-export`,type:`referral`,extension:`xml`,contentType:ZE.CDA_XML}};function Az(e){let t=Q(),{patient:n}=e,[r,i]=(0,b.useState)(`everything`),[a,o]=(0,b.useState)(!1);return(0,I.jsx)(WN,{onSubmit:(0,b.useCallback)(async e=>{let i=oC(n),{operation:o,type:s,contentType:c,extension:l}=kz[r],u=t.fhirUrl(`Patient`,i,o),d={};r===`everything`&&a&&u.searchParams.set(`_inlineAttachments`,`true`),s&&(d.type=s),e.author&&(d.author={reference:e.author}),e.authoredOn&&(d.authoredOn=pI(e.authoredOn)),e.startDate&&(d.start=e.startDate),e.endDate&&(d.end=e.endDate),zb.show({id:Dz,title:Oz,loading:!0,message:`Exporting...`,autoClose:!1,withCloseButton:!1});try{jz(await t.post(u,d,void 0,{cache:`no-cache`,headers:{Accept:c}}),`Patient-export-${i}-${new Date().toISOString().replaceAll(`:`,`-`)}.${l}`,c),zb.update({id:Dz,title:Oz,color:`green`,message:`Done`,icon:(0,I.jsx)(WA,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0})}catch(e){zb.update({id:Dz,title:Oz,color:`red`,message:Y(e),icon:(0,I.jsx)($j,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}},[t,n,r,a]),children:(0,I.jsxs)(G,{children:[(0,I.jsx)(tI,{title:`Export Format`,description:`Required`,withAsterisk:!0,children:(0,I.jsx)(ly,{name:`format`,value:r,onChange:i,data:[{label:`FHIR Everything`,value:`everything`},{label:`Patient Summary`,value:`summary`},{label:`C-CDA`,value:`ccda`},{label:`C-CDA Referral`,value:`ccdaReferral`}],fullWidth:!0})}),(0,I.jsx)(tI,{title:`Author`,description:`Optional author for composition. Default value is current user.`,children:(0,I.jsx)(NI,{name:`author`,placeholder:`Author`,targetTypes:[`Organization`,`Practitioner`,`PractitionerRole`]})}),(0,I.jsx)(tI,{title:`Authored On`,description:`Optional date for composition authored on. Default value is current date.`,children:(0,I.jsx)(mI,{name:`authoredOn`,placeholder:`Authored on`})}),(0,I.jsx)(tI,{title:`Start Date`,description:`The start date of care. If no start date is provided, all records prior to the end date are in scope.`,children:(0,I.jsx)(mI,{name:`startDate`,placeholder:`Start date`})}),(0,I.jsx)(tI,{title:`End Date`,description:`The end date of care. If no end date is provided, all records subsequent to the start date are in scope.`,children:(0,I.jsx)(mI,{name:`endDate`,placeholder:`End date`})}),r===`everything`&&(0,I.jsx)(tI,{title:`Inline Attachments`,description:`Embed DocumentReference file attachments as base64-encoded data instead of storage URLs.`,children:(0,I.jsx)(G,{gap:`xs`,children:(0,I.jsx)(Bd,{label:`Inline attachments`,checked:a,onChange:e=>o(e.currentTarget.checked)})})}),(0,I.jsx)(V,{justify:`right`,children:(0,I.jsx)(GN,{children:`Request Export`})})]})})}function jz(e,t,n){let r=typeof e==`string`?e:JSON.stringify(e,null,2),i=new Blob([r],{type:n}),a=window.URL.createObjectURL(i),o=document.createElement(`a`);document.body.appendChild(o),o.style.display=`none`,o.href=a,o.download=t,o.click(),window.URL.revokeObjectURL(a)}function Mz(e){if(e.gender===`male`)return`blue`;if(e.gender===`female`)return`pink`}function Nz(e){let t=bk(e.patient);return t?(0,I.jsxs)(uz,{children:[(0,I.jsx)(_M,{value:t,size:`lg`,color:Mz(t)}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Name`}),(0,I.jsx)(uz.Value,{children:(0,I.jsx)(dM,{to:t,fw:500,children:t.name?(0,I.jsx)(NF,{value:t.name[0],options:{use:!1}}):`[blank]`})})]}),t.birthDate&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`DoB`}),(0,I.jsx)(uz.Value,{children:t.birthDate})]}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Age`}),(0,I.jsx)(uz.Value,{children:hC(t.birthDate)})]})]}),t.gender&&(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Gender`}),(0,I.jsx)(uz.Value,{children:t.gender})]}),t.address&&(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`State`}),(0,I.jsx)(uz.Value,{children:t.address[0]?.state})]}),t.identifier?.map(e=>(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:e?.system}),(0,I.jsx)(uz.Value,{children:e?.value})]},`${e?.system}-${e?.value}`))]}):null}function Pz(e){let{patient:t,...n}=e;return(0,I.jsx)(BL,{value:t,loadTimelineResources:(0,b.useCallback)((e,t,n)=>{let r=`${t}/${n}`;return Promise.allSettled([e.readHistory(`Patient`,n),e.search(`ClinicalImpression`,{subject:r,_count:100}),e.search(`Communication`,{subject:r,_count:100}),e.search(`Device`,{patient:r,_count:100}),e.search(`DeviceRequest`,{patient:r,_count:100}),e.search(`DiagnosticReport`,{subject:r,_count:100}),e.search(`Media`,{subject:r,_count:100}),e.search(`ServiceRequest`,{subject:r,_count:100}),e.search(`Task`,{subject:r,_count:100})])},[]),createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,subject:iC(e),sender:iC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,subject:iC(e),operator:iC(t),issued:new Date().toISOString(),content:n}),...n})}var Fz={section:`_section_pqpwm_1`,hovering:`_hovering_pqpwm_7`,editing:`_editing_pqpwm_11`};function Iz(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)();function d(){c(void 0)}function f(){o(void 0)}if((0,b.useEffect)(()=>{t.requestSchema(`PlanDefinition`).then(()=>i(!0)).catch(console.log)},[t]),(0,b.useEffect)(()=>(u(Wz(n??{resourceType:`PlanDefinition`,status:`active`})),document.addEventListener(`mouseover`,d),document.addEventListener(`click`,f),()=>{document.removeEventListener(`mouseover`,d),document.removeEventListener(`click`,f)}),[n]),!r||!l)return null;function p(e,t){u(n=>({...n,[e]:t}))}return(0,I.jsx)(`div`,{children:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(l),children:[(0,I.jsx)(yb,{label:`Plan Title`,py:`md`,defaultValue:l.title,onChange:e=>p(`title`,e.currentTarget.value)}),(0,I.jsx)(Lz,{actions:l.action||[],selectedKey:a,setSelectedKey:o,hoverKey:s,setHoverKey:c,onChange:e=>p(`action`,e)}),(0,I.jsx)(GN,{children:`Save`})]})})}function Lz(e){function t(t){e.onChange(e.actions.map(e=>e.id===t.id?t:e))}function n(t){e.onChange([...e.actions,t]),e.setSelectedKey(t.id)}function r(t){e.onChange(e.actions.filter(e=>e!==t))}return(0,I.jsxs)(G,{gap:`md`,className:Fz.section,children:[e.actions.map(n=>(0,I.jsx)(Rz,{action:n,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:t,onRemove:()=>r(n)},n.id)),(0,I.jsx)(`div`,{children:(0,I.jsx)(U,{variant:`outline`,onClick:e=>{aM(e),n({id:Uz()})},children:`Add action`})})]})}function Rz(e){let{action:t}=e;function n(t){t.stopPropagation(),e.setSelectedKey(e.action.id)}function r(t){aM(t),e.setHoverKey(e.action.id)}return(0,I.jsx)(`div`,{onClick:n,onMouseOver:r,onFocus:r,children:(0,I.jsx)(zz,{action:t,onChange:e.onChange,selectedKey:e.selectedKey,hoverKey:e.hoverKey,onRemove:e.onRemove})})}function zz(e){let{action:t}=e,[n,r]=(0,b.useState)(),i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),l=e.selectedKey===e.action.id,u=e.hoverKey===e.action.id;function d(n,r){e.onChange({...t,[n]:r})}let f=it(Fz.section,{[Fz.hovering]:u&&!l});return(0,b.useEffect)(()=>{(async()=>{if(!t.definitionCanonical)return;o(!0);let e=await i.readCanonical([`Questionnaire`,`ActivityDefinition`],t.definitionCanonical);r(Vz(e)),c(e),o(!1)})().catch(console.error)},[t.definitionCanonical,i]),a?(0,I.jsx)(il,{}):(0,I.jsxs)(Xc,{"data-testid":t.id,className:f,p:0,radius:`sm`,withBorder:!0,children:[(0,I.jsxs)(ru,{w:`100%`,p:`xs`,bg:`gray.0`,gap:`md`,align:`center`,justify:`space-between`,children:[(0,I.jsx)(yb,{w:`100%`,name:`actionTitle-${t.id}`,defaultValue:t.title,placeholder:`Title`,onChange:e=>d(`title`,e.currentTarget.value)}),(0,I.jsx)(Cl,{"data-testid":`close-button`,onClick:e.onRemove})]}),l&&(0,I.jsxs)(G,{gap:`xl`,p:`md`,children:[(0,I.jsx)(z,{children:(0,I.jsx)(yb,{label:`Task Description`,placeholder:`Enter task description`,name:`actionDescription-${t.id}`,defaultValue:t.description,onChange:e=>d(`description`,e.currentTarget.value)})}),(0,I.jsx)(z,{children:(0,I.jsx)(yg,{label:`Type of Action`,value:n,onChange:t=>{let n=t.currentTarget.value===`standard`?void 0:t.currentTarget.value;r(n),e.onChange({...e.action,definitionCanonical:n===`standard`?void 0:e.action.definitionCanonical})},data:[{value:`standard`,label:`Standard task`},{value:`questionnaire`,label:`Task with Questionnaire`},{value:`activitydefinition`,label:`Task with Activity Definition`}]})}),n===`questionnaire`&&(0,I.jsxs)(G,{gap:0,children:[(0,I.jsxs)(V,{gap:0,mb:`xs`,children:[(0,I.jsx)(H,{fw:600,children:`Select questionnaire`}),(0,I.jsx)(H,{c:`red`,children:`*`})]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mb:`sm`,children:[`Questionnaire to be shown in the task in Encounter view. You can create new one from`,` `,(0,I.jsx)(pu,{href:`/Questionnaire`,target:`_blank`,c:`blue`,children:`questionnaires list`})]}),(0,I.jsx)(Bz,{resource:s,resourceType:`Questionnaire`,action:t,onChange:e.onChange,placeholder:`Search for questionnaire`})]}),n===`activitydefinition`&&(0,I.jsxs)(G,{gap:0,children:[(0,I.jsxs)(V,{gap:0,mb:`xs`,children:[(0,I.jsx)(H,{fw:600,children:`Select activity definition`}),(0,I.jsx)(H,{c:`red`,children:`*`})]}),(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mb:`sm`,children:[`ActivityDefinition.kind resource to be shown in the task in Encounter view. You can create new one from`,` `,(0,I.jsx)(pu,{href:`/ActivityDefinition`,target:`_blank`,c:`blue`,children:`activity definitions list`})]}),(0,I.jsx)(Bz,{resource:s,resourceType:`ActivityDefinition`,action:t,onChange:e.onChange,placeholder:`Search for activity definition`})]})]})]})}function Bz(e){let{id:t}=e.action,{resource:n}=e;return(0,I.jsx)(MI,{name:t,placeholder:e.placeholder,resourceType:e.resourceType,defaultValue:n,onChange:t=>{t?e.onChange({...e.action,definitionCanonical:`url`in t?t.url:void 0,definitionUri:`url`in t?void 0:aC(t)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function Vz(e){return e===void 0?`standard`:e.resourceType.toLowerCase()}var Hz=1;function Uz(e){if(e){if(e.startsWith(`id-`)){let t=Number.parseInt(e.substring(3),10);Number.isNaN(t)||(Hz=Math.max(Hz,t+1))}return e}return`id-`+Hz++}function Wz(e){return{...e,action:Gz(e.action)}}function Gz(e){if(e)return e.map(e=>({...e,id:Uz(e.id),action:Gz(e.action)}))}var Kz=`modulepreload`,qz=function(e){return`/`+e},Jz={},Yz=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,new URL(`../../../src/node/plugins/importAnalysisBuild.ts`,import.meta.url)).href}r=o(t.map(t=>{if(t=qz(t,n),t=s(t),t in Jz)return;Jz[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Kz,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Xz=150,Zz;function Qz({onScan:e,onError:t,scanOnce:n=!0}){let r=(0,b.useRef)(null),i=(0,b.useRef)(null),a=(0,b.useRef)(e),o=(0,b.useRef)(t),[s,c]=(0,b.useState)(!0),[l,u]=(0,b.useState)();return(0,b.useEffect)(()=>{a.current=e},[e]),(0,b.useEffect)(()=>{o.current=t},[t]),(0,b.useEffect)(()=>{let e=r.current,t=i.current,s=t?.getContext(`2d`,{willReadFrequently:!0});if(!e||!t||!s)return;let l=e,d=t,f=s,p=0,m,h=!1,g=!1,_=0,v;function y(){m?.getTracks().forEach(e=>e.stop())}function b(e){let t=e instanceof Error?e:Error(String(e));h||(c(!1),u(Y(t)),o.current?.(t))}function x(e){if(!(h||g||!v)){if(l.readyState===l.HAVE_ENOUGH_DATA&&(c(!1),e-_>=Xz)){_=e,d.height=l.videoHeight,d.width=l.videoWidth,f.drawImage(l,0,0,d.width,d.height);let t=f.getImageData(0,0,d.width,d.height),r=v(t.data,t.width,t.height,{inversionAttempts:`attemptBoth`});if(r?.data&&(g=n,a.current(r.data),n)){y();return}}p=requestAnimationFrame(x)}}async function S(){try{if(v=await $z(),h)return;if(!navigator.mediaDevices?.getUserMedia)throw Error(`Camera access is not available in this browser.`);let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:`environment`}});if(h){e.getTracks().forEach(e=>e.stop());return}m=e,l.srcObject=e,l.setAttribute(`playsinline`,`true`),await l.play(),h||(p=requestAnimationFrame(x))}catch(e){b(e)}}return S().catch(b),()=>{h=!0,cancelAnimationFrame(p),y()}},[n]),(0,I.jsxs)(G,{gap:`sm`,children:[l&&(0,I.jsx)(ou,{color:`red`,children:l}),(0,I.jsx)(`video`,{ref:r,width:640,height:480,muted:!0,style:{aspectRatio:`4 / 3`,display:l?`none`:`block`,width:`100%`,height:`auto`,maxHeight:`70vh`,background:`black`}}),(0,I.jsx)(`canvas`,{ref:i,hidden:!0}),s&&!l&&(0,I.jsxs)(H,{c:`dimmed`,size:`sm`,children:[(0,I.jsx)(il,{size:`xs`,mr:`xs`}),`Loading camera...`]})]})}async function $z(){return Zz||=Yz(()=>import(`./jsQR-BHcLbI6s.js`).then(e=>c(e.default,1)).then(e=>e.default),[]).catch(e=>{throw Zz=void 0,Error(`QR code scanning requires the optional "jsqr" dependency. Install jsqr to use QrCodeScanner. ${Y(e)}`)}),Zz}var eB=30,tB=50;function nB(e){let t=e.formState,n=e.item,r=e.responseItem;function i(i){if(t&&e.context)if(n.repeats&&e.index!==void 0&&n.type!==Sk.choice&&n.type!==Sk.openChoice){let n=[...r.answer||[]];i.length===0?n.splice(e.index,1):n[e.index]=i[0],t.onChangeAnswer(e.context,e.item,n)}else t.onChangeAnswer(e.context,e.item,i)}let a=n.type;if(!a)return null;let o=n.linkId;if(!o)return null;let s=n.repeats&&e.index!==void 0&&n.type!==Sk.choice&&n.type!==Sk.openChoice?`${o}-${e.index}`:o,c;n.initial&&n.initial.length>0?c=n.initial[0]:n.answerOption&&n.answerOption.length>0&&(c=n.answerOption.find(e=>e.initialSelected));let l=uB(r,e.index)??nA(c),u=_C(r,`${Ox}/fhir/StructureDefinition/questionnaire-validationError`),d=null;switch(a){case Sk.display:d=(0,I.jsx)(`p`,{children:e.item.text},e.item.linkId);break;case Sk.boolean:d=(0,I.jsx)(eI,{title:e.item.text,htmlFor:s,children:(0,I.jsx)(Bd,{id:s,name:o,required:e.required??n.required,defaultChecked:l?.value,onChange:e=>i([{valueBoolean:e.currentTarget.checked}])})},e.item.linkId);break;case Sk.decimal:d=(0,I.jsx)(yb,{type:`number`,step:`any`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i(e.currentTarget.value===``?[]:[{valueDecimal:e.currentTarget.valueAsNumber}])});break;case Sk.integer:d=(0,I.jsx)(yb,{type:`number`,step:1,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i(e.currentTarget.value===``?[]:[{valueInteger:e.currentTarget.valueAsNumber}])});break;case Sk.date:d=(0,I.jsx)(yb,{type:`date`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDate:e.currentTarget.value}])});break;case Sk.dateTime:d=(0,I.jsx)(mI,{name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDateTime:e}])});break;case Sk.time:d=(0,I.jsx)(yb,{type:`time`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueTime:e.currentTarget.value}])});break;case Sk.string:case Sk.url:d=(0,I.jsx)(yb,{id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>{let t=e.currentTarget.value;i(t===``?[]:[{valueString:t}])}});break;case Sk.text:d=(0,I.jsx)(_m,{id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>{let t=e.currentTarget.value;i(t===``?[]:[{valueString:t}])}});break;case Sk.attachment:d=(0,I.jsx)(V,{py:4,children:(0,I.jsx)(IP,{path:``,name:s,defaultValue:l?.value,onChange:e=>i([{valueAttachment:e}])})});break;case Sk.reference:d=(0,I.jsx)(NI,{name:s,required:e.required??n.required,targetTypes:qk(n),searchCriteria:Yk(n,t?.subject,t?.encounter),defaultValue:l?.value,onChange:e=>i([{valueReference:e}])});break;case Sk.quantity:d=(0,I.jsx)(SI,{path:``,name:s,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueQuantity:e}]),disableWheel:!0});break;case Sk.choice:case Sk.openChoice:{let{widget:t,multiselect:a}=mB(n),o={name:s,item:n,required:e.required??n.required,initial:c,response:r,multiselect:a,onChangeAnswer:i};d=t===`check-box`?(0,I.jsx)(cB,{...o}):t===`drop-down`?(0,I.jsx)(rB,{...o}):(0,I.jsx)(sB,{...o})}break;default:return null}return(0,I.jsxs)(I.Fragment,{children:[d,u?.valueString&&(0,I.jsx)(H,{c:`red`,size:`lg`,mt:4,children:u.valueString})]})}function rB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o,multiselect:s}=e;if(!n.answerOption?.length&&!n.answerValueSet)return(0,I.jsx)(lB,{});let c=nA(i),l=uB(o)??c,u=dB(o),d=n.repeats||s;if(n.answerValueSet)return(0,I.jsx)(QN,{name:t,placeholder:`Select items`,binding:n.answerValueSet,maxValues:d?void 0:1,required:r,onChange:e=>{d?e.length===0?a([{}]):a(e.map(e=>({valueCoding:e}))):a([{valueCoding:e[0]}])},defaultValue:l?.value});if(d){let{propertyName:e,data:t}=hB(n);return(0,I.jsx)(hg,{data:t,placeholder:`Select items`,searchable:!0,defaultValue:u||[aw(c)],required:r,onChange:t=>{t.length===0?a([{}]):a(Uk(t,e,n))}})}else{let e=[``];if(n.answerOption)for(let t of n.answerOption){let n=rA(t);e.push(aw(n))}return(0,I.jsx)(yg,{id:t,name:t,required:r,onChange:e=>{let t=e.currentTarget.selectedIndex;if(t===0){a([{}]);return}let r=n.answerOption[t-1],i=rA(r);a([{[`value`+HC(i.type)]:i.value}])},defaultValue:Sw(l?.value)||l?.value,data:e})}}function iB(e,t){return e?t.valueSetExpand({url:e,count:31}).then(e=>e.expansion?.contains??[]):Promise.resolve([])}function aB(e){let t=Q(),[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{async function n(){if(e){a(!0);try{r(await iB(e,t))}catch(e){console.error(`Error loading value set:`,e)}finally{a(!1)}}}n().catch(console.error)},[e,t]),[n,i]}function oB(e,t){return e.map((e,n)=>[`${t}-valueset-${n}`,{type:`Coding`,value:{system:e.system,code:e.code,display:e.display}}])}function sB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o}=e,s=zw(`QuestionnaireItemAnswerOption`,`value[x]`),c=nA(i),[l,u]=aB(n.answerValueSet),d=[],f;if(n.answerValueSet)d.push(...oB(l,t));else if(n.answerOption){let e=n.answerOption.slice(0,tB).map((e,n)=>{let r=`${t}-option-${n}`,i=rA(e);return i?.value?(c&&vC(i)===vC(c)&&(f=r),[r,i]):null}).filter(e=>e!==null);d.push(...e)}let p=fB(d,uB(o));if(u)return(0,I.jsx)(H,{children:`Loading options...`});if(d.length===0)return(0,I.jsx)(lB,{});let m=d.slice(0,eB);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Dv.Group,{name:t,value:p??f,required:r,onChange:e=>{let t=d.find(t=>t[0]===e);if(t){let e=t[1];a([{[`value`+HC(e.type)]:e.value}])}},children:m.map(([e,t])=>(0,I.jsx)(Dv,{id:e,value:e,py:4,required:r,label:(0,I.jsx)(KF,{property:s,propertyType:t.type,value:t.value})},e))}),(n.answerValueSet&&d.length>eB||n.answerOption&&d.length>tB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mt:`xs`,children:[`Showing first `,eB,` options`]})]})}function cB(e){let{name:t,item:n,onChangeAnswer:r,response:i}=e,a=zw(`QuestionnaireItemAnswerOption`,`value[x]`),[o,s]=aB(n.answerValueSet),[c,l]=(0,b.useState)(n.answerValueSet?(i?.answer?.map(e=>e.valueCoding)||[]).filter(e=>e!==void 0):dB(i)),u=[];if(n.answerValueSet)u.push(...oB(o,t));else if(n.answerOption){let e=n.answerOption.slice(0,tB).map((e,n)=>{let r=`${t}-option-${n}`,i=rA(e);return i?.value?[r,i]:null}).filter(e=>e!==null);u.push(...e)}if(s)return(0,I.jsx)(H,{children:`Loading options...`});if(u.length===0)return(0,I.jsx)(lB,{});let d=u.slice(0,eB),f=(e,t)=>{if(n.answerValueSet){let n=c,i;i=t?[...n,e.value]:n.filter(t=>!TC(t,e.value)),l(i),i.length===0?r([{}]):r(i.map(e=>({valueCoding:e})))}else{let i=c,a=aw(e),o;o=t?[...i,a]:i.filter(e=>e!==a),l(o),o.length===0?r([{}]):r(Uk(o,`value`+HC(e.type),n))}};return(0,I.jsxs)(V,{style:{flexDirection:`column`,alignItems:`flex-start`},children:[d.map(([e,t])=>{let r=aw(t),i=n.answerValueSet?c.some(e=>TC(e,t.value)):c.includes(r);return(0,I.jsx)(Bd,{id:e,label:(0,I.jsx)(KF,{property:a,propertyType:t.type,value:t.value}),checked:i,onChange:e=>f(t,e.currentTarget.checked)},e)}),(n.answerValueSet&&u.length>eB||n.answerOption&&u.length>tB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Showing first `,eB,` options`]})]})}function lB(){return(0,I.jsx)(yb,{disabled:!0,placeholder:`No Answers Defined`})}function uB(e,t=0){return rA(e?.answer?.[t]??{})}function dB(e){let t=e?.answer;return t?t.map(e=>rA(e)).map(e=>Sw(e?.value)||e?.value).filter(Boolean):[]}function fB(e,t){return e.find(e=>TC(e[1].value,t?.value))?.[0]}var pB=[`drop-down`,`radio-button`,`check-box`];function mB(e){let t=`radio-button`,n=!1;e.answerValueSet&&(t=`drop-down`);for(let r of e.extension??[]){if(r.url!==Ck)continue;let e=r.valueCodeableConcept?.coding?.[0]?.code;pB.includes(e)&&(t=e),e===`multi-select`&&(n=!0)}return t===`radio-button`&&n&&(t=`check-box`),{widget:t,multiselect:n}}function hB(e){if(e.answerOption?.length===0)return{propertyName:``,data:[]};let t=e.answerOption[0];return{propertyName:`value`+HC(rA(t).type),data:(e.answerOption??[]).map(e=>{let t=aw(rA(e));return{value:t,label:t}})}}var gB={section:`_section_my8o4_1`,hovering:`_hovering_my8o4_10`,editing:`_editing_my8o4_14`,questionBody:`_questionBody_my8o4_20`,topActions:`_topActions_my8o4_24`,bottomActions:`_bottomActions_my8o4_33`,movementActions:`_movementActions_my8o4_44`,movementIcons:`_movementIcons_my8o4_56`,columnAlignment:`_columnAlignment_my8o4_60`,linkIdInput:`_linkIdInput_my8o4_65`,typeSelect:`_typeSelect_my8o4_70`,preserveBreaks:`_preserveBreaks_my8o4_74`};function _B(e){let t=Q(),n=bk(e.questionnaire),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)();function d(){u(void 0)}function f(){c(void 0)}return(0,b.useEffect)(()=>{t.requestSchema(`Questionnaire`).then(()=>i(!0)).catch(console.log)},[t]),(0,b.useEffect)(()=>(o(EB(n??{resourceType:`Questionnaire`,status:`active`})),document.addEventListener(`mouseover`,d),document.addEventListener(`click`,f),()=>{document.removeEventListener(`mouseover`,d),document.removeEventListener(`click`,f)}),[n]),!r||!a?null:(0,I.jsx)(`div`,{children:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(a),children:[(0,I.jsx)(vB,{item:a,selectedKey:s,setSelectedKey:c,hoverKey:l,setHoverKey:u,onChange:(t,n)=>{o(t),e.autoSave&&!n&&e.onSubmit&&e.onSubmit(t)}}),(0,I.jsx)(GN,{children:`Save`})]})})}function vB(e){let t=e.item,n=e.item,r=Vw(e.item),i=r||n.type===Sk.group,a=n.linkId??`[untitled]`,o=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,c=(0,b.useRef)(e.item);(0,b.useLayoutEffect)(()=>{c.current=e.item});function l(t){aM(t),e.setSelectedKey(e.item.id)}function u(t){aM(t),e.setHoverKey(e.item.id)}function d(t){let n=c.current;e.onChange({...n,item:n.item?.map(e=>e.id===t.id?t:e)})}function f(t,n){e.onChange({...e.item,item:[...e.item.item??[],t]},n)}function p(t){e.onChange({...e.item,item:e.item.item?.filter(e=>e!==t)})}function m(t,n){e.onChange({...c.current,[t]:n})}function h(t){e.onChange({...e.item,...t})}function g(t){e.onChange({...e.item,item:e.item.item?.map(e=>e===t?{...e,repeats:!e.repeats}:e)})}function _(t,n){let r=AB(e.item.item,t,n);e.onChange({...e.item,item:r})}let v=it(gB.section,{[gB.editing]:o,[gB.hovering]:s&&!o});return(0,I.jsxs)(`div`,{"data-testid":n.linkId,className:v,onClick:l,onMouseOver:u,onFocus:u,children:[(0,I.jsx)(`div`,{className:gB.questionBody,children:o?(0,I.jsxs)(I.Fragment,{children:[r&&(0,I.jsx)(yb,{size:`xl`,defaultValue:t.title,onBlur:e=>m(`title`,e.currentTarget.value)}),!r&&(0,I.jsx)(_m,{autosize:!0,minRows:2,defaultValue:n.text,onBlur:e=>m(`text`,e.currentTarget.value)}),n.type===`reference`&&(0,I.jsx)(xB,{item:n,onChange:h}),Mk(n)&&(0,I.jsx)(yB,{item:n,onChange:e=>h(e)})]}):(0,I.jsxs)(I.Fragment,{children:[t.title&&(0,I.jsx)(q,{children:t.title}),n.text&&(0,I.jsx)(`div`,{className:gB.preserveBreaks,children:n.text}),!i&&(0,I.jsx)(nB,{item:n,index:0,required:!1,responseItem:{linkId:n.linkId}})]})}),n.item?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(vB,{item:t,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:n===0,isLast:n===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:d,onRemove:()=>p(t),onRepeatable:g,onMoveUp:()=>_(n,-1),onMoveDown:()=>_(n,1)})},t.id)),!i&&(0,I.jsx)(`div`,{className:gB.topActions,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(yb,{size:`xs`,className:gB.linkIdInput,defaultValue:n.linkId,onBlur:e=>m(`linkId`,e.currentTarget.value)}),!i&&(0,I.jsx)(yg,{size:`xs`,className:gB.typeSelect,defaultValue:n.type,onChange:e=>m(`type`,e.currentTarget.value),data:[{value:`display`,label:`Display`},{value:`boolean`,label:`Boolean`},{value:`decimal`,label:`Decimal`},{value:`integer`,label:`Integer`},{value:`date`,label:`Date`},{value:`dateTime`,label:`Date/Time`},{value:`time`,label:`Time`},{value:`string`,label:`String`},{value:`text`,label:`Text`},{value:`url`,label:`URL`},{value:`choice`,label:`Choice`},{value:`open-choice`,label:`Open Choice`},{value:`attachment`,label:`Attachment`},{value:`reference`,label:`Reference`},{value:`quantity`,label:`Quantity`}]})]}):(0,I.jsx)(`div`,{children:a})}),!r&&(0,I.jsx)(z,{className:gB.movementActions,children:(0,I.jsxs)(z,{className:gB.columnAlignment,children:[!e.isFirst&&(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,I.jsx)(MA,{"data-testid":`up-button`,size:15,className:gB.movementIcons})}),!e.isLast&&(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,I.jsx)(jA,{"data-testid":`down-button`,size:15,className:gB.movementIcons})})]})}),(0,I.jsxs)(`div`,{className:gB.bottomActions,children:[i&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f({id:TB(),linkId:wB(`q`),type:`string`,text:`Question`})},children:`Add item`}),(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f({id:TB(),linkId:wB(`g`),type:`group`,text:`Group`},!0)},children:`Add group`})]}),r&&(0,I.jsx)(pu,{href:`#`,onClick:e=>{e.preventDefault(),f(kB(),!0)},children:`Add Page`}),o&&!r&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onRepeatable&&e.onRepeatable(n)},children:n.repeats?`Remove Repeatable`:`Make Repeatable`}),(0,I.jsx)(pu,{href:`#`,onClick:t=>{t.preventDefault(),e.onRemove&&e.onRemove()},children:`Remove`})]})]})]})}function yB(e){let t=zw(`QuestionnaireItemAnswerOption`,`value[x]`),n=e.item.answerOption??[];return(0,I.jsxs)(`div`,{children:[e.item.answerValueSet===void 0?(0,I.jsx)(bB,{options:n,property:t,item:e.item,onChange:e.onChange}):(0,I.jsx)(yb,{placeholder:`Enter Value Set`,defaultValue:e.item.answerValueSet,onChange:t=>e.onChange({...e.item,answerValueSet:t.target.value})}),(0,I.jsxs)(z,{display:`flex`,children:[(0,I.jsx)(pu,{href:`#`,onClick:t=>{aM(t),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...n,{id:TB()}]})},children:`Add choice`}),(0,I.jsx)(Sy,{w:`lg`}),(0,I.jsx)(pu,{href:`#`,onClick:t=>{aM(t),e.onChange({...e.item,answerOption:[],answerValueSet:``})},children:`Add value set`})]})]})}function bB(e){return(0,I.jsx)(`div`,{children:e.options.map(t=>{let[n,r]=AF({type:`QuestionnaireItemAnswerOption`,value:t},`value`);return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`row`,justifyContent:`space-between`,alignItems:`center`,width:`80%`},children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(XI,{name:`value[x]`,path:`Questionnaire.answerOption.value[x]`,property:e.property,defaultPropertyType:r,defaultValue:n,onChange:(n,r)=>{let i=[...e.options],a=i.findIndex(e=>e.id===t.id);i[a]={id:t.id,[r]:n},e.onChange({...e.item,answerOption:i})},outcome:void 0},t.id)}),(0,I.jsx)(`div`,{children:(0,I.jsx)(pu,{href:`#`,onClick:n=>{aM(n),e.onChange({...e.item,answerOption:e.options.filter(e=>e.id!==t.id)})},children:`Remove`})})]},t.id)})})}function xB(e){let t=qk(e.item)??[];return(0,I.jsxs)(I.Fragment,{children:[t.map((n,r)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(rP,{name:`resourceType`,placeholder:`Resource Type`,defaultValue:n,onChange:r=>{e.onChange(Jk(e.item,t.map(e=>e===n?r:e)))}}),(0,I.jsx)(pu,{href:`#`,onClick:r=>{aM(r),e.onChange(Jk(e.item,t.filter(e=>e!==n)))},children:`Remove`})]},`${n}-${r}`)),(0,I.jsx)(pu,{href:`#`,onClick:n=>{aM(n),e.onChange(Jk(e.item,[...t,``]))},children:`Add Resource Type`})]})}var SB=1,CB=1;function wB(e){return e+SB++}function TB(){return`id-`+CB++}function EB(e){return{...e,id:e.id||TB(),item:DB(e.item)}}function DB(e){if(e)return e.forEach(e=>{e.id?.match(/^id-\d+$/)&&(CB=Math.max(CB,Number.parseInt(e.id.substring(3),10)+1)),e.linkId?.match(/^q\d+$/)&&(SB=Math.max(SB,Number.parseInt(e.linkId.substring(1),10)+1))}),e.map(e=>({...e,id:e.id||TB(),item:DB(e.item),answerOption:OB(e.answerOption)}))}function OB(e){if(e)return e.map(e=>({...e,id:e.id||TB()}))}function kB(){return{id:TB(),linkId:wB(`s`),type:`group`,text:`New Page`,extension:[{url:Ck,valueCodeableConcept:{coding:[{system:`http://hl7.org/fhir/questionnaire-item-control`,code:`page`}]}}]}}function AB(e,t,n){let r=e??[],i=t+n;if(i<0||i>=r.length)return r;let a=[...r];return[a[t],a[i]]=[a[i],a[t]],a}var jB=class{x;y;pressure;time;constructor(e,t,n,r){if(isNaN(e)||isNaN(t))throw Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=n||0,this.time=r||Date.now()}distanceTo(e){return Math.sqrt((this.x-e.x)**2+(this.y-e.y)**2)}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time===e.time?0:this.distanceTo(e)/(this.time-e.time)}},MB=class e{constructor(e,t,n,r,i,a){this.startPoint=e,this.control2=t,this.control1=n,this.endPoint=r,this.startWidth=i,this.endWidth=a}static fromPoints(t,n){let r=this.calculateControlPoints(t[0],t[1],t[2]).c2,i=this.calculateControlPoints(t[1],t[2],t[3]).c1;return new e(t[1],r,i,t[2],n.start,n.end)}static calculateControlPoints(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=t.x-n.x,o=t.y-n.y,s={x:(e.x+t.x)/2,y:(e.y+t.y)/2},c={x:(t.x+n.x)/2,y:(t.y+n.y)/2},l=Math.sqrt(r*r+i*i),u=Math.sqrt(a*a+o*o),d=s.x-c.x,f=s.y-c.y,p=l+u==0?0:u/(l+u),m={x:c.x+d*p,y:c.y+f*p},h=t.x-m.x,g=t.y-m.y;return{c1:new jB(s.x+h,s.y+g),c2:new jB(c.x+h,c.y+g)}}length(){let e=0,t,n;for(let r=0;r<=10;r+=1){let i=r/10,a=this.point(i,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),o=this.point(i,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(r>0){let r=a-t,i=o-n;e+=Math.sqrt(r*r+i*i)}t=a,n=o}return e}point(e,t,n,r,i){return t*(1-e)*(1-e)*(1-e)+3*n*(1-e)*(1-e)*e+3*r*(1-e)*e*e+i*e*e*e}},NB=class{_et;constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,n){this._et.addEventListener(e,t,n)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,n){this._et.removeEventListener(e,t,n)}};function PB(e,t=250){let n=0,r=null,i,a,o,s=()=>{n=Date.now(),r=null,i=e.apply(a,o),r||(a=null,o=[])};return function(...c){let l=Date.now(),u=t-(l-n);return a=this,o=c,u<=0||u>t?(r&&=(clearTimeout(r),null),n=l,i=e.apply(a,o),r||(a=null,o=[])):r||=window.setTimeout(s,u),i}}var FB=class e extends NB{constructor(t,n={}){super(),this.canvas=t,this.velocityFilterWeight=n.velocityFilterWeight||.7,this.minWidth=n.minWidth||.5,this.maxWidth=n.maxWidth||2.5,this.throttle=n.throttle??16,this.minDistance=n.minDistance??5,this.dotSize=n.dotSize||0,this.penColor=n.penColor||`black`,this.backgroundColor=n.backgroundColor||`rgba(0,0,0,0)`,this.compositeOperation=n.compositeOperation||`source-over`,this.canvasContextOptions=n.canvasContextOptions??{},this._strokeMoveUpdate=this.throttle?PB(e.prototype._strokeUpdate,this.throttle):e.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._handlePointerCancel=this._handlePointerCancel.bind(this),this._handleTouchCancel=this._handleTouchCancel.bind(this),this._ctx=t.getContext(`2d`,this.canvasContextOptions),this.clear(),this.on()}dotSize;minWidth;maxWidth;penColor;minDistance;velocityFilterWeight;compositeOperation;backgroundColor;throttle;canvasContextOptions;_ctx;_drawingStroke=!1;_isEmpty=!0;_dataUrl;_dataUrlOptions;_lastPoints=[];_data=[];_lastVelocity=0;_lastWidth=0;_strokeMoveUpdate;_strokePointerId;clear(){let{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._dataUrl=void 0,this._dataUrlOptions=void 0,this._strokePointerId=void 0}redraw(){let e=this._data,t=this._dataUrl,n=this._dataUrlOptions;this.clear(),t&&this.fromDataURL(t,n),this.fromData(e,{clear:!1})}fromDataURL(e,t={}){return new Promise((n,r)=>{let i=new Image,a=t.ratio||window.devicePixelRatio||1,o=t.width||this.canvas.width/a,s=t.height||this.canvas.height/a,c=t.xOffset||0,l=t.yOffset||0;this._reset(this._getPointGroupOptions()),i.onload=()=>{this._ctx.drawImage(i,c,l,o,s),n()},i.onerror=e=>{r(e)},i.crossOrigin=`anonymous`,i.src=e,this._isEmpty=!1,this._dataUrl=e,this._dataUrlOptions={...t}})}toDataURL(e=`image/png`,t){switch(e){case`image/svg+xml`:return typeof t!=`object`&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!=`number`&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction=`none`,this.canvas.style.msTouchAction=`none`,this.canvas.style.userSelect=`none`,this.canvas.style.webkitUserSelect=`none`;let e=/Macintosh/.test(navigator.userAgent)&&`ontouchstart`in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),`ontouchstart`in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction=`auto`,this.canvas.style.msTouchAction=`auto`,this.canvas.style.userSelect=`auto`,this.canvas.style.webkitUserSelect=`auto`,this.canvas.removeEventListener(`pointerdown`,this._handlePointerDown),this.canvas.removeEventListener(`mousedown`,this._handleMouseDown),this.canvas.removeEventListener(`touchstart`,this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){let e=window.document===this.canvas.ownerDocument?window:this.canvas.ownerDocument.defaultView??this.canvas.ownerDocument;return{addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}_removeMoveUpEventListeners(){let{removeEventListener:e}=this._getListenerFunctions();e(`pointermove`,this._handlePointerMove),e(`pointerup`,this._handlePointerUp),e(`pointercancel`,this._handlePointerCancel),e(`mousemove`,this._handleMouseMove),e(`mouseup`,this._handleMouseUp),e(`touchmove`,this._handleTouchMove),e(`touchend`,this._handleTouchEnd),e(`touchcancel`,this._handleTouchCancel)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)==1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:`pressure`in e?e.pressure:0}}_touchEventToSignatureEvent(e){let t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_handlePointerCancel(e){this._allowPointerId(e)&&(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e),!1))}_handleTouchCancel(e){e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e),!1)}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return this._strokePointerId===void 0?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&`penColor`in e?e.penColor:this.penColor,dotSize:e&&`dotSize`in e?e.dotSize:this.dotSize,minWidth:e&&`minWidth`in e?e.minWidth:this.minWidth,maxWidth:e&&`maxWidth`in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&`velocityFilterWeight`in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&`compositeOperation`in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent(`beginStroke`,{detail:e,cancelable:!0})))return;let{addEventListener:t}=this._getListenerFunctions();switch(e.event.type){case`mousedown`:t(`mousemove`,this._handleMouseMove,{passive:!1}),t(`mouseup`,this._handleMouseUp,{passive:!1});break;case`touchstart`:t(`touchmove`,this._handleTouchMove,{passive:!1}),t(`touchend`,this._handleTouchEnd,{passive:!1}),t(`touchcancel`,this._handleTouchCancel,{passive:!1});break;case`pointerdown`:t(`pointermove`,this._handlePointerMove,{passive:!1}),t(`pointerup`,this._handlePointerUp,{passive:!1}),t(`pointercancel`,this._handlePointerCancel,{passive:!1});break;default:}this._drawingStroke=!0;let n=this._getPointGroupOptions(),r={...n,points:[]};this._data.push(r),this._reset(n),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent(`beforeUpdateStroke`,{detail:e}));let t=this._createPoint(e.x,e.y,e.pressure),n=this._data[this._data.length-1],r=n.points,i=r.length>0&&r[r.length-1],a=i?t.distanceTo(i)<=this.minDistance:!1,o=this._getPointGroupOptions(n);if(!i||!(i&&a)){let e=this._addPoint(t,o);i?e&&this._drawCurve(e,o):this._drawDot(t,o),r.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent(`afterUpdateStroke`,{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent(`endStroke`,{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener(`pointerdown`,this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener(`mousedown`,this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener(`touchstart`,this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,n){let r=this.canvas.getBoundingClientRect();return new jB(e-r.left,t-r.top,n,new Date().getTime())}_addPoint(e,t){let{_lastPoints:n}=this;if(n.push(e),n.length>2){n.length===3&&n.unshift(n[0]);let e=this._calculateCurveWidths(n[1],n[2],t),r=MB.fromPoints(n,e);return n.shift(),r}return null}_calculateCurveWidths(e,t,n){let r=n.velocityFilterWeight*t.velocityFrom(e)+(1-n.velocityFilterWeight)*this._lastVelocity,i=this._strokeWidth(r,n),a={end:i,start:this._lastWidth};return this._lastVelocity=r,this._lastWidth=i,a}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,n){let r=this._ctx;r.moveTo(e,t),r.arc(e,t,n,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){let n=this._ctx,r=e.endWidth-e.startWidth,i=Math.ceil(e.length())*2;n.beginPath(),n.fillStyle=t.penColor;for(let n=0;n<i;n+=1){let a=n/i,o=a*a,s=o*a,c=1-a,l=c*c,u=l*c,d=u*e.startPoint.x;d+=3*l*a*e.control1.x,d+=3*c*o*e.control2.x,d+=s*e.endPoint.x;let f=u*e.startPoint.y;f+=3*l*a*e.control1.y,f+=3*c*o*e.control2.y,f+=s*e.endPoint.y;let p=Math.min(e.startWidth+s*r,t.maxWidth);this._drawCurveSegment(d,f,p)}n.closePath(),n.fill()}_drawDot(e,t){let n=this._ctx,r=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;n.beginPath(),this._drawCurveSegment(e.x,e.y,r),n.closePath(),n.fillStyle=t.penColor,n.fill()}_fromData(e,t,n){for(let r of e){let{points:e}=r,i=this._getPointGroupOptions(r);if(e.length>1)for(let n=0;n<e.length;n+=1){let r=e[n],a=new jB(r.x,r.y,r.pressure,r.time);n===0&&this._reset(i);let o=this._addPoint(a,i);o&&t(o,i)}else this._reset(i),n(e[0],i)}}toSVG({includeBackgroundColor:e=!1,includeDataUrl:t=!1}={}){let n=this._data,r=Math.max(window.devicePixelRatio||1,1),i=this.canvas.width/r,a=this.canvas.height/r,o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);if(o.setAttribute(`xmlns`,`http://www.w3.org/2000/svg`),o.setAttribute(`xmlns:xlink`,`http://www.w3.org/1999/xlink`),o.setAttribute(`viewBox`,`0 0 ${i} ${a}`),o.setAttribute(`width`,i.toString()),o.setAttribute(`height`,a.toString()),e&&this.backgroundColor){let e=document.createElement(`rect`);e.setAttribute(`width`,`100%`),e.setAttribute(`height`,`100%`),e.setAttribute(`fill`,this.backgroundColor),o.appendChild(e)}if(t&&this._dataUrl){let e=this._dataUrlOptions?.ratio||window.devicePixelRatio||1,t=this._dataUrlOptions?.width||this.canvas.width/e,n=this._dataUrlOptions?.height||this.canvas.height/e,r=this._dataUrlOptions?.xOffset||0,i=this._dataUrlOptions?.yOffset||0,a=document.createElement(`image`);a.setAttribute(`x`,r.toString()),a.setAttribute(`y`,i.toString()),a.setAttribute(`width`,t.toString()),a.setAttribute(`height`,n.toString()),a.setAttribute(`preserveAspectRatio`,`none`),a.setAttribute(`href`,this._dataUrl),o.appendChild(a)}return this._fromData(n,(e,{penColor:t})=>{let n=document.createElement(`path`);if(!isNaN(e.control1.x)&&!isNaN(e.control1.y)&&!isNaN(e.control2.x)&&!isNaN(e.control2.y)){let r=`M ${e.startPoint.x.toFixed(3)},${e.startPoint.y.toFixed(3)} C ${e.control1.x.toFixed(3)},${e.control1.y.toFixed(3)} ${e.control2.x.toFixed(3)},${e.control2.y.toFixed(3)} ${e.endPoint.x.toFixed(3)},${e.endPoint.y.toFixed(3)}`;n.setAttribute(`d`,r),n.setAttribute(`stroke-width`,(e.endWidth*2.25).toFixed(3)),n.setAttribute(`stroke`,t),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke-linecap`,`round`),o.appendChild(n)}},(e,{penColor:t,dotSize:n,minWidth:r,maxWidth:i})=>{let a=document.createElement(`circle`),s=n>0?n:(r+i)/2;a.setAttribute(`r`,s.toString()),a.setAttribute(`cx`,e.x.toString()),a.setAttribute(`cy`,e.y.toString()),a.setAttribute(`fill`,t),o.appendChild(a)}),o.outerHTML}};function IB(e){let t=Q(),{width:n=500,height:r=200,defaultValue:i,who:a,onChange:o,...s}=e,c=(0,b.useRef)(null),l=(0,b.useRef)(null),u=(0,b.useRef)(o);(0,b.useLayoutEffect)(()=>{u.current=o}),(0,b.useEffect)(()=>{function e(){u.current?.({type:[{system:Ox+`/fhir/signature-type`,code:`ProofOfOrigin`,display:`Proof of Origin`}],when:new Date().toISOString(),who:a??iC(t.getProfile()),data:l.current?.toDataURL().split(`,`)[1]})}if(c.current){let t=new FB(c.current);i?.data&&t.fromDataURL(i.data).catch(console.error),t.addEventListener(`endStroke`,e),l.current=t}return()=>{l.current&&l.current.removeEventListener(`beginStroke`,e)}},[t,i,a]);let d=()=>{l.current&&l.current.clear(),u.current?.(void 0)};return(0,I.jsxs)(Xc,{withBorder:!0,p:0,w:n,h:r,pos:`relative`,...s,children:[(0,I.jsx)(`canvas`,{ref:c,width:n,height:r,"aria-label":`Signature input area`}),(0,I.jsx)(U,{onClick:d,"aria-label":`Clear signature`,pos:`absolute`,top:0,right:0,size:`xs`,leftSection:(0,I.jsx)(Yj,{size:16}),variant:`subtle`,color:`gray`,children:`Clear`})]})}function LB(e){let t=[...e.context,e.responseItem];return(0,I.jsxs)(`div`,{children:[e.item.text&&(0,I.jsx)(q,{order:4,mb:`md`,children:e.item.text}),(0,I.jsx)(BB,{formState:e.formState,context:t,items:e.item.item??[],responseItems:e.responseItem.item??[]})]},e.item.linkId)}function RB(e){return(0,I.jsxs)(I.Fragment,{children:[e.responseItems.map(t=>(0,I.jsx)(LB,{formState:e.formState,context:e.context,item:e.item,responseItem:t},`group-${t.id}`)),(0,I.jsx)(pu,{onClick:()=>e.formState.onAddGroup(e.context,e.item),children:`Add Group: ${e.item.text}`})]})}function zB(e){let{formState:t,context:n,item:r,responseItem:i}=e,a=r.type===Sk.choice||r.type===Sk.openChoice,o=!a,s=!a&&i.answer&&i.answer.length>0?i.answer:[{}];return(0,I.jsxs)(tI,{title:e.item.text,withAsterisk:e.item.required,children:[(0,I.jsx)(G,{gap:`xs`,children:s?.map((e,a)=>(0,I.jsx)(nB,{formState:t,context:n,item:r,responseItem:i,index:a},`${r.linkId}-${a}`))}),o&&(0,I.jsx)(pu,{onClick:()=>t.onAddAnswer(n,r),children:`Add Item`})]},e.item.linkId)}function BB(e){let{formState:t,context:n,items:r,responseItems:i}=e,a=n.length===0,o=!1;return(0,I.jsx)(G,{gap:`xl`,children:r.map((e,r)=>{if(!Fk(e,t.questionnaireResponse))return null;let s=e.type===Sk.group,c=a&&s&&o;if(s&&(o=!0),e.type===Sk.display)return(0,I.jsx)(`p`,{children:e.text},`display-${e.id}-${r}`);let l=i.filter(t=>t.linkId===e.linkId);return e.type===Sk.group&&e.repeats?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(RB,{formState:t,context:n,item:e,responseItems:l})]},`repeating-group-${e.id}-${r}`):e.type===Sk.group?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(LB,{formState:t,context:n,item:e,responseItem:l[0]})]},`group-${e.id}-${r}`):e.type===Sk.boolean?(0,I.jsx)(nB,{formState:t,context:n,item:e,responseItem:l[0],index:0},`boolean-item-${e.id}-${r}`):e.repeats?(0,I.jsx)(zB,{formState:t,context:n,item:e,responseItem:l[0]},`repeating-item-${e.id}-${r}`):(0,I.jsx)(tI,{htmlFor:e.linkId,title:e.text,withAsterisk:e.required,children:(0,I.jsx)(nB,{formState:t,context:n,item:e,responseItem:l[0],index:0})},`repeating-item-${e.id}-${r}`)})})}function VB(e){let{formState:t,submitButtonText:n,excludeButtons:r,children:i}=e,a=t.pages,o=t.activePage,s=o>0,c=o<a.length-1,l=o===a.length-1;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Fy,{active:o,allowNextStepsSelect:!1,p:6,children:a.map((e,t)=>(0,I.jsx)(Fy.Step,{label:e.title,children:t===o&&i},e.linkId))}),!r&&(0,I.jsxs)(V,{justify:`flex-end`,mt:`xl`,gap:`xs`,children:[s&&(0,I.jsx)(U,{onClick:t.onPrevPage,children:`Back`}),c&&(0,I.jsx)(U,{onClick:e=>{e.currentTarget.closest(`form`).reportValidity()&&t.onNextPage()},children:`Next`}),l&&(0,I.jsx)(GN,{children:n??`Submit`})]})]})}function HB(e){let t=Q(),[n,r]=(0,b.useState)(!1),i=(0,b.useRef)(e),a=(0,b.useRef)(void 0);(0,b.useLayoutEffect)(()=>{i.current=e});let o=(0,b.useCallback)(e=>{a.current=e},[]),s=oA({questionnaire:e.questionnaire,defaultValue:e.questionnaireResponse,subject:e.subject,encounter:e.encounter,source:e.source,disablePagination:e.disablePagination,onChange:o}),c=(0,b.useRef)(s);(0,b.useLayoutEffect)(()=>{c.current=s}),(0,b.useEffect)(()=>{let e=a.current;e&&(a.current=void 0,r(!1),i.current.onChange?.(e))});let l=(0,b.useMemo)(()=>s.loading?!1:!!_C(s.questionnaire,kk),[s]),u=(0,b.useMemo)(()=>s.loading?!1:!!s.questionnaireResponse.extension?.find(e=>e.url===Ak),[s]),d=(0,b.useCallback)(()=>{let e=c.current;if(e.loading)return;let n=i.current.onSubmit;if(!n)return;if(l&&!u){r(!0);return}let a=e.questionnaire,o=e.questionnaireResponse,s=i.current.subject,d=i.current.source;if(!d){let e=t.getProfile();e&&(d=iC(e))}n({...o,questionnaire:a.url??aC(a),subject:s,source:d,authored:new Date().toISOString(),status:`completed`})},[t,l,u]);return s.loading?null:(0,I.jsxs)(WN,{testid:`questionnaire-form`,onSubmit:d,children:[s.questionnaire.title&&(0,I.jsx)(q,{order:1,fz:`1.625rem`,fw:700,lh:1.3,mb:`xl`,children:s.questionnaire.title}),e.afterHeader&&(0,I.jsxs)(G,{gap:`xl`,mb:`xl`,children:[e.afterHeader,(0,I.jsx)(bp,{color:`var(--mantine-color-gray-2)`})]}),s.pagination?(0,I.jsx)(VB,{formState:s,submitButtonText:e.submitButtonText,excludeButtons:e.excludeButtons,children:(0,I.jsx)(BB,{formState:s,context:[],items:s.items,responseItems:s.responseItems})}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(BB,{formState:s,context:[],items:s.items,responseItems:s.responseItems}),l&&(0,I.jsxs)(G,{mt:`md`,gap:0,children:[(0,I.jsx)(H,{size:`sm`,fw:500,children:`Signature`}),(0,I.jsx)(IB,{onChange:s.onChangeSignature}),!u&&n&&(0,I.jsx)(H,{c:`red`,size:`sm`,children:`Signature is required.`})]}),!e.excludeButtons&&(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,gap:`xs`,children:(0,I.jsx)(GN,{children:e.submitButtonText??`Submit`})})]})]})}var UB={section:`_section_4m5it_1`},WB=[`gender`,`age`,`gestationalAge`,`context`,`appliesTo`,`category`],GB={definition:{resourceType:`ObservationDefinition`,code:{text:``}},onSubmit:()=>{}};function KB(e){e=Object.assign(GB,e);let t=e.definition,[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(1),[o,s]=(0,b.useState)(1);return(0,b.useEffect)(()=>{r(XB(YB(t,s).qualifiedInterval||[],a))},[t]),(0,I.jsxs)(WN,{testid:`reference-range-editor`,onSubmit:c,children:[(0,I.jsx)(G,{children:n.map(e=>(0,I.jsx)(qB,{unit:QB(t.quantitativeDetails?.unit),onChange:d,onAdd:f,onRemove:p,onRemoveGroup:u,intervalGroup:e},`group-${e.id}`))}),(0,I.jsx)(vl,{title:`Add Group`,variant:`subtle`,size:`sm`,onClick:e=>{aM(e),l({id:`group-id-${i}`,filters:{},intervals:[]}),a(e=>e+1)},children:(0,I.jsx)(YA,{})}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(GN,{children:`Save`})})]});function c(){let r=n.flatMap(e=>e.intervals).filter(e=>!$B(e));e.onSubmit({...t,qualifiedInterval:r})}function l(e){r(t=>[...t,e])}function u(e){r(t=>t.filter(t=>t.id!==e.id))}function d(e,t){r(n=>{n=[...n];let r=n.find(t=>t.id===e),i=r?.intervals.findIndex(e=>e.id===t.id);return i!==void 0&&r?.intervals[i]&&(r.intervals[i]=t),n})}function f(e,t){t.id===void 0&&(t.id=`id-${o}`,s(e=>e+1)),r(n=>{n=[...n];let r=n.findIndex(t=>t.id===e);if(r!==-1){let e={...n[r]};t={...t,...e.filters},e.intervals=[...e.intervals,t],n[r]=e}return n})}function p(e,t){r(n=>{n=[...n];let r=n.find(t=>t.id===e);return r&&(r.intervals=r.intervals.filter(e=>e.id!==t.id)),n})}}function qB(e){let{intervalGroup:t,unit:n}=e;return(0,I.jsx)(RP,{"data-testid":t.id,className:UB.section,children:(0,I.jsxs)(G,{gap:`lg`,children:[(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(vl,{title:`Remove Group`,variant:`subtle`,"data-testid":`remove-group-button-${t.id}`,size:`sm`,onClick:n=>{aM(n),e.onRemoveGroup(t)},children:(0,I.jsx)(JA,{})},`remove-group-button-${t.id}`)}),(0,I.jsx)(JB,{intervalGroup:t,onChange:e.onChange}),(0,I.jsx)(bp,{}),t.intervals.map(n=>(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsxs)(V,{children:[(0,I.jsx)(yb,{"data-testid":`condition-${n.id}`,defaultValue:n.condition,label:`Condition: `,size:`sm`,onChange:r=>{aM(r),e.onChange(t.id,{...n,condition:r.currentTarget.value.trim()})}},`condition-${n.id}`),(0,I.jsx)(vl,{title:`Remove Interval`,variant:`subtle`,size:`sm`,"data-testid":`remove-interval-${n.id}`,onClick:r=>{aM(r),e.onRemove(t.id,n)},children:(0,I.jsx)(JA,{})},`remove-interval-${n.id}`)]}),(0,I.jsx)(wI,{path:``,onChange:r=>{e.onChange(t.id,{...n,range:r})},name:`range-${n.id}`,defaultValue:n.range},`range-${n.id}`)]},`interval-${n.id}`)),(0,I.jsx)(vl,{title:`Add Interval`,variant:`subtle`,size:`sm`,onClick:r=>{aM(r),e.onAdd(t.id,{range:{low:{unit:n},high:{unit:n}}})},children:(0,I.jsx)(YA,{})})]})})}function JB(e){let{intervalGroup:t,onChange:n}=e,r=t.filters.age??{},i={low:r.low?.unit?r.low:{...r.low,unit:`years`,system:`http://unitsofmeasure.org`},high:r.high?.unit?r.high:{...r.high,unit:`years`,system:`http://unitsofmeasure.org`}};return(0,I.jsxs)(G,{style:{maxWidth:`50%`},children:[(0,I.jsx)(V,{children:(0,I.jsx)(yg,{data:[``,`male`,`female`],label:`Gender:`,defaultValue:t.filters.gender||``,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``&&(i=void 0),n(t.id,{...r,gender:i})}}})}),(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(H,{component:`label`,htmlFor:`div-age-${t.id}`,children:`Age:`}),(0,I.jsx)(`div`,{id:`div-age-${t.id}`,children:(0,I.jsx)(wI,{path:``,name:`age-${t.id}`,defaultValue:i,onChange:e=>{for(let r of t.intervals)n(t.id,{...r,age:e})}},`age-${t.id}`)})]}),(0,I.jsx)(yg,{data:[``,`pre-puberty`,`follicular`,`midcycle`,`luteal`,`postmenopausal`],label:`Endocrine:`,defaultValue:t.filters.context?.text||``,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``?(i=void 0,n(t.id,{...r,context:void 0})):n(t.id,{...r,context:{text:i,coding:[{code:i,system:`http://terminology.hl7.org/CodeSystem/referencerange-meaning`}]}})}}}),(0,I.jsx)(yg,{data:[``,`reference`,`critical`,`absolute`],label:`Category: `,defaultValue:t.filters.category,onChange:e=>{for(let r of t.intervals){let i=e.currentTarget.value;i===``?n(t.id,{...r,category:void 0}):n(t.id,{...r,category:i})}}})]})}function YB(e,t){let n=e.qualifiedInterval||[],r=Math.max(...n.map(e=>{let t=Number.parseInt(e.id?.substring(3)||``,10);return Number.isNaN(t)?-1/0:t}))+1;return Number.isFinite(r)||(r=1),e={...e,qualifiedInterval:n.map(e=>({...e,id:e.id||`id-${r++}`}))},t(r),e}function XB(e,t){let n=1,r={};for(let t of e){let e=ZB(t);e in r||(r[e]={id:`group-id-${n++}`,filters:Object.fromEntries(WB.map(e=>[e,t[e]])),intervals:[]}),r[e].intervals.push(t)}return t(n),Object.values(r)}function ZB(e){return[`gender=${e.gender}`,`age=${vw(e.age)}`,`gestationalAge=${vw(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(e=>e.text).join(`+`)}`,`category=${e.category}`].join(`:`)}function QB(e){return e&&(GC(e,`http://unitsofmeasure.org`)||e.text)}function $B(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}function eV(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)();if((0,b.useEffect)(()=>{n&&!r&&(t.executeBatch(s(n)).then(o).catch(console.log),i(!0))},[t,n,r]),!n||!a)return null;return(0,I.jsx)(Fp,{children:n.action?.map((t,n)=>{let r=t.resource&&c(t.resource),i=r?.input?.[0]?.valueReference,a=r?.output?.[0]?.valueReference;return(0,I.jsxs)(b.Fragment,{children:[(0,I.jsx)(Fp.Col,{span:1,p:`md`,children:r?.status===`completed`?(0,I.jsx)(GA,{}):(0,I.jsx)(Hj,{color:`gray`})}),(0,I.jsxs)(Fp.Col,{span:9,p:`xs`,children:[(0,I.jsx)(H,{fw:500,children:t.title}),t.description&&(0,I.jsx)(`div`,{children:t.description}),(0,I.jsxs)(`div`,{children:[`Last edited by\xA0`,(0,I.jsx)(oL,{value:r?.meta?.author}),`\xA0on\xA0`,dw(r?.meta?.lastUpdated)]}),(0,I.jsxs)(`div`,{children:[`Status: `,(0,I.jsx)(lL,{status:r?.status||`unknown`})]})]}),(0,I.jsxs)(Fp.Col,{span:2,p:`md`,children:[i&&!a&&(0,I.jsx)(U,{onClick:()=>e.onStart(r,i),children:`Start`}),i&&a&&(0,I.jsx)(U,{onClick:()=>e.onEdit(r,i,a),children:`Edit`})]})]},`action-${n}`)})});function s(e){let t=[];if(e.action)for(let n of e.action)n.resource?.reference&&t.push({request:{method:`GET`,url:n.resource.reference}});return{resourceType:`Bundle`,type:`batch`,entry:t}}function c(e){for(let t of a?.entry??[])if(t.resource&&e.reference===aC(t.resource))return t.resource}}function tV(e,t){return rV(nV(e,t),e,t)}function nV(e,t){let n=e.length,r=t.length,i=n+r+1,a=1+2*i,o=Math.trunc(a/2),s=Array(a);s[o+1]={i:0,j:-1,prev:void 0,snake:!0};for(let a=0;a<i;a++){for(let i=-a;i<=a;i+=2){let c=o+i,l=c+1,u=c-1,d=s[l],f=s[u],p,m=0;i===-a||i!==a&&f.i<d.i?(m=d.i,p=d):(m=f.i+1,p=f),s[u]=void 0;let h=m-i,g={i:m,j:h,prev:iV(p),snake:!1};for(;m<n&&h<r&&e[m]===t[h];)m++,h++;if(m>g.i&&(g={i:m,j:h,prev:g,snake:!0}),s[c]=g,m>=n&&h>=r)return s[c]}s[o+a-1]=void 0}}function rV(e,t,n){let r=[],i=e;for(i.snake&&(i=i.prev);i?.prev&&i.prev.j>=0;){let e=i.i,a=i.j;i=i.prev;let o=i.i,s=i.j,c={position:o,lines:t.slice(o,e)},l={position:s,lines:n.slice(s,a)},u;u=c.lines.length===0&&l.lines.length>0?`insert`:c.lines.length>0&&l.lines.length===0?`delete`:`change`,r.push({original:c,revised:l,type:u}),i.snake&&(i=i.prev)}return r}function iV(e){return e&&!e.snake&&e.prev?e.prev:e}function aV(e){let t=(e.entry??[]).filter(e=>!!e.resource).map(e=>({meta:e.resource?.meta,lines:vC(e.resource,!0).match(/[^\r\n]+/g)})).sort((e,t)=>e.meta.lastUpdated.localeCompare(t.meta.lastUpdated));if(!t.length)return[];let n=t[0].lines.map(e=>({id:t[0].meta.versionId,meta:t[0].meta,value:e,span:1}));return oV(n,t),sV(n),n}function oV(e,t){for(let n=1;n<t.length;n++){let r=tV(t[n-1].lines,t[n].lines);for(let i of r){let r=i.original.position,a=i.original.lines,o=i.revised.lines;if((i.type===`delete`||i.type===`change`)&&e.splice(r,a.length),i.type===`insert`||i.type===`change`)for(let a=0;a<i.revised.lines.length;a++)e.splice(r+a,0,{id:t[n].meta.versionId,meta:t[n].meta,value:o[a],span:1})}}}function sV(e){let t=0;for(;t<e.length;){let n=t;for(;n<e.length&&e[n].id===e[t].id;)e[n].span=-1,n++;e[t].span=n-t,t=n}}var cV={container:`_container_1gji2_1`,root:`_root_1gji2_5`,startRow:`_startRow_1gji2_20`,normalRow:`_normalRow_1gji2_25`,author:`_author_1gji2_30`,onBehalfOf:`_onBehalfOf_1gji2_34`,dateTime:`_dateTime_1gji2_40`,lineNumber:`_lineNumber_1gji2_46`,line:`_line_1gji2_46`,pre:`_pre_1gji2_61`};function lV(e,t){return`/${e.resourceType}/${e.id}/_history/${t}`}function uV(e){let t=Math.floor((Date.now()-Date.parse(e))/1e3),n=Math.floor(t/31536e3);if(n>0)return dV(n,`year`);let r=Math.floor(t/2592e3);if(r>0)return dV(r,`month`);let i=Math.floor(t/86400);if(i>0)return dV(i,`day`);let a=Math.floor(t/3600);if(a>0)return dV(a,`hour`);let o=Math.floor(t/60);return o>0?dV(o,`minute`):dV(t,`second`)}function dV(e,t){return`${e} ${e===1?t:t+`s`} ago`}function fV(e){let t=Q(),[n,r]=(0,b.useState)(e.history);if((0,b.useEffect)(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(r).catch(console.log)},[t,e.history,e.resourceType,e.id]),!n)return(0,I.jsx)(`div`,{children:`Loading...`});let i=n.entry?.[0]?.resource;if(!i)return null;let a=aV(n);return(0,I.jsx)(`div`,{className:cV.container,children:(0,I.jsx)(`table`,{className:cV.root,children:(0,I.jsx)(`tbody`,{children:a.map((e,t)=>(0,I.jsxs)(`tr`,{className:e.span>0?cV.startRow:cV.normalRow,children:[e.span>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`td`,{className:cV.author,rowSpan:e.span,children:[(0,I.jsx)(oL,{value:e.meta.author,link:!0,fz:`xs`}),e.meta.onBehalfOf&&(0,I.jsxs)(`div`,{className:cV.onBehalfOf,children:[`on behalf of `,(0,I.jsx)(oL,{value:e.meta.onBehalfOf,link:!0,fz:`xs`,c:`dimmed`})]})]}),(0,I.jsx)(`td`,{className:cV.dateTime,rowSpan:e.span,children:(0,I.jsx)(dM,{to:lV(i,e.meta.versionId),fz:`xs`,children:uV(e.meta.lastUpdated)})})]}),(0,I.jsx)(`td`,{className:cV.lineNumber,children:t+1}),(0,I.jsx)(`td`,{className:cV.line,children:(0,I.jsx)(`pre`,{className:cV.pre,children:e.value})})]},`row-`+t))})})})}var pV={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function mV(e){let t=e.original,n=e.revised;return e.ignoreMeta&&(t={...t,meta:void 0},n={...n,meta:void 0}),(0,I.jsx)(`pre`,{style:{color:`gray`},children:tV(vC(t,!0).match(/[^\r\n]+/g)??[`{`,`}`],vC(n,!0).match(/[^\r\n]+/g)??[`{`,`}`]).map((e,t)=>(0,I.jsx)(hV,{delta:e},`delta`+t))})}function hV(e){return(0,I.jsxs)(I.Fragment,{children:[`...`,(0,I.jsx)(`br`,{}),e.delta.original.lines.length>0&&(0,I.jsx)(`div`,{className:pV.removed,children:e.delta.original.lines.join(`
|
|
207
207
|
`)}),e.delta.revised.lines.length>0&&(0,I.jsx)(`div`,{className:pV.added,children:e.delta.revised.lines.join(`
|
|
208
208
|
`)}),`...`,(0,I.jsx)(`br`,{})]})}var gV={splitButton:`_splitButton_1i0gi_1`,menuControl:`_menuControl_1i0gi_6`};function _V(e){let{outcome:t}=e,n=Q(),r=bk(e.defaultValue),i=r?.resourceType,[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),l=n.getAccessPolicy(),u=er();(0,b.useEffect)(()=>{if(r)if(e.profileUrl){let t=e.profileUrl;n.requestProfileSchema(e.profileUrl,{expandProfile:!0}).then(()=>{let e=hS(t);e?(o(!0),c(yO(r,e))):console.error(`Schema not found for ${t}`)}).catch(e=>{console.error(`Error in requestProfileSchema`,e)})}else n.requestSchema(i).then(()=>{c(r),o(!0)}).catch(console.log)},[n,r,i,e.profileUrl]);let d=(0,b.useMemo)(()=>r&&ME(r,OE.READ,l),[l,r]),f=(0,b.useMemo)(()=>n.isSuperAdmin()||!l||!CC(s?.resourceType)?!0:AE(l,s?.resourceType),[n,l,s?.resourceType]);return!a||!s?(0,I.jsx)(`div`,{children:`Loading...`}):f?(0,I.jsxs)(`form`,{noValidate:!0,autoComplete:`off`,onSubmit:t=>{t.preventDefault(),e.onSubmit&&e.onSubmit(s)},children:[(0,I.jsxs)(G,{mb:`xl`,children:[(0,I.jsx)(tI,{title:`Resource Type`,htmlFor:`resourceType`,outcome:t,children:(0,I.jsx)(yb,{name:`resourceType`,defaultValue:s.resourceType,disabled:!0})}),(0,I.jsx)(tI,{title:`ID`,htmlFor:`id`,outcome:t,children:(0,I.jsx)(yb,{name:`id`,defaultValue:s.id,disabled:!0})})]}),(0,I.jsx)(rL,{path:s.resourceType,valuePath:s.resourceType,typeName:i,defaultValue:s,outcome:t,onChange:c,profileUrl:e.profileUrl,accessPolicyResource:d}),(0,I.jsxs)(V,{justify:`flex-end`,mt:`xl`,wrap:`nowrap`,gap:0,children:[(0,I.jsx)(U,{type:`submit`,className:it((e.onPatch||e.onDelete)&&gV.splitButton),children:r?.id?`Update`:`Create`}),(e.onPatch||e.onDelete)&&(0,I.jsxs)(W,{transitionProps:{transition:`pop`},position:`bottom-end`,withinPortal:!0,children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(vl,{variant:`filled`,color:u.primaryColor,size:36,className:gV.menuControl,"aria-label":`More actions`,children:(0,I.jsx)(KA,{size:14,stroke:1.5})})}),(0,I.jsxs)(W.Dropdown,{children:[e.onPatch&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(ij,{size:14,stroke:1.5}),onClick:()=>{e.onPatch(s)},children:`Patch`}),e.onDelete&&(0,I.jsx)(W.Item,{color:`red`,leftSection:(0,I.jsx)(Yj,{size:14,stroke:1.5,color:`red`}),onClick:()=>{e.onDelete(s)},children:`Delete`})]})]})]})]}):(0,I.jsxs)(ou,{color:`red`,title:`Permission denied`,icon:(0,I.jsx)(kA,{}),children:[`Your access level prevents you from editing and creating `,s.resourceType,` resources.`]})}function vV(e){let t=Q(),[n,r]=(0,b.useState)(e.history);return(0,b.useEffect)(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(r).catch(console.log)},[t,e.history,e.resourceType,e.id]),n?(0,I.jsxs)(K,{withTableBorder:!0,withRowBorders:!0,withColumnBorders:!0,children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{children:`Author`}),(0,I.jsx)(K.Th,{children:`On Behalf Of`}),(0,I.jsx)(K.Th,{children:`Date`}),(0,I.jsx)(K.Th,{children:`Version`})]})}),(0,I.jsx)(K.Tbody,{children:n.entry?.map((e,t)=>(0,I.jsx)(yV,{entry:e},`entry-`+t))})]}):(0,I.jsx)(`div`,{children:`Loading...`})}function yV(e){let{response:t,resource:n}=e.entry;return n?(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:(0,I.jsx)(sL,{value:n.meta?.author,link:!0})}),(0,I.jsx)(K.Td,{children:n.meta?.onBehalfOf&&(0,I.jsx)(sL,{value:n.meta.onBehalfOf,link:!0})}),(0,I.jsx)(K.Td,{children:dw(n.meta?.lastUpdated)}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(dM,{to:bV(n),children:n.meta?.versionId})})]}):(0,I.jsx)(K.Tr,{children:(0,I.jsx)(K.Td,{colSpan:4,children:Y(t?.outcome)})})}function bV(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}var xV=e=>{throw TypeError(e)},SV=(e,t,n)=>t.has(e)||xV(`Cannot `+n),CV=(e,t,n)=>(SV(e,t,`read from private field`),n?n.call(e):t.get(e)),wV=(e,t,n)=>t.has(e)?xV(`Cannot add the same private member more than once`):t instanceof WeakSet?t.add(e):t.set(e,n),TV=(e,t,n,r)=>(SV(e,t,`write to private field`),r?r.call(e,n):t.set(e,n),n),EV=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,DV=/^[\\/]{2}/;function OV(e,t){return t+e.replace(/\\/g,`/`)}var kV=`popstate`;function AV(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function jV(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return IV(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:LV(t)}return zV(t,n,null,e)}function MV(e,t){if(e===!1||e==null)throw Error(t)}function NV(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function PV(){return Math.random().toString(36).substring(2,10)}function FV(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function IV(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?RV(t):t,state:n,key:t&&t.key||r||PV(),mask:i}}function LV({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function RV(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function zV(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=AV(e)?e:IV(h.location,e,t);n&&n(r,e),l=u()+1;let d=FV(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=AV(e)?e:IV(h.location,e,t);n&&n(r,e),l=u();let i=FV(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return BV(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(kV,d),c=e,()=>{i.removeEventListener(kV,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function BV(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),MV(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:LV(t);return i=i.replace(/ $/,`%20`),!n&&DV.test(i)&&(i=r+i),new URL(i,r)}var VV,HV=class{constructor(e){if(wV(this,VV,new Map),e)for(let[t,n]of e)this.set(t,n)}get(e){if(CV(this,VV).has(e))return CV(this,VV).get(e);if(e.defaultValue!==void 0)return e.defaultValue;throw Error(`No value found for context`)}set(e,t){CV(this,VV).set(e,t)}};VV=new WeakMap;var UV=new Set([`lazy`,`caseSensitive`,`path`,`id`,`index`,`children`]);function WV(e){return UV.has(e)}var GV=new Set([`lazy`,`caseSensitive`,`path`,`id`,`index`,`middleware`,`children`]);function KV(e){return GV.has(e)}function qV(e){return e.index===!0}function JV(e,t,n=[],r={},i=!1){return e.map((e,a)=>{let o=[...n,String(a)],s=typeof e.id==`string`?e.id:o.join(`-`);if(MV(e.index!==!0||!e.children,`Cannot specify children on an index route`),MV(i||!r[s],`Found a route id collision on id "${s}". Route id's must be globally unique within Data Router usages`),qV(e)){let n={...e,id:s};return r[s]=YV(n,t(n)),n}else{let n={...e,id:s,children:void 0};return r[s]=YV(n,t(n)),e.children&&(n.children=JV(e.children,t,o,r,i)),n}})}function YV(e,t){return Object.assign(e,{...t,...typeof t.lazy==`object`&&t.lazy!=null?{lazy:{...e.lazy,...t.lazy}}:{}})}function XV(e,t,n=`/`){return ZV(e,t,n,!1)}function ZV(e,t,n,r,i){let a=_H((typeof t==`string`?RV(t):t).pathname||`/`,n);if(a==null)return null;let o=i??$V(e),s=null,c=gH(a);for(let e=0;s==null&&e<o.length;++e)s=fH(o[e],c,r);return s}function QV(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,data:t[n.id],loaderData:t[n.id],handle:n.handle}}function $V(e){let t=eH(e);return nH(t),t}function eH(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;MV(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=DH([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(MV(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),eH(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:uH(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=hH(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of tH(e.path))a(e,t,!0,n)}),t}function tH(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=tH(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function nH(e){e.sort((e,t)=>e.score===t.score?dH(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var rH=/^:[\w-]+$/,iH=3,aH=2,oH=1,sH=10,cH=-2,lH=e=>e===`*`;function uH(e,t){let n=e.split(`/`),r=n.length;return n.some(lH)&&(r+=cH),t&&(r+=aH),n.filter(e=>!lH(e)).reduce((e,t)=>e+(rH.test(t)?iH:t===``?oH:sH),r)}function dH(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function fH(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?mH(u,l,s.matcher,s.compiledParams):pH(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=pH({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:DH([a,d.pathname]),pathnameBase:kH(DH([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=DH([a,d.pathnameBase]))}return o}function pH(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=hH(e.path,e.caseSensitive,e.end);return mH(e,t,n,r)}function mH(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return n&&!i?e[t]=void 0:e[t]=(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function hH(e,t=!1,n=!0){NV(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function gH(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return NV(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function _H(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function vH({basename:e,pathname:t}){return t===`/`?e:DH([e,t])}var yH=e=>EV.test(e);function bH(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?RV(e):e,a;return n?(n=EH(n),a=n.startsWith(`/`)?xH(n.substring(1),`/`):xH(n,t)):a=t,{pathname:a,search:AH(r),hash:jH(i)}}function xH(e,t){let n=OH(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function SH(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function CH(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function wH(e){let t=CH(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function TH(e,t,n,r=!1){let i;typeof e==`string`?i=RV(e):(i={...e},MV(!i.pathname||!i.pathname.includes(`?`),SH(`?`,`pathname`,`search`,i)),MV(!i.pathname||!i.pathname.includes(`#`),SH(`#`,`pathname`,`hash`,i)),MV(!i.search||!i.search.includes(`#`),SH(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=bH(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var EH=e=>e.replace(/[\\/]{2,}/g,`/`),DH=e=>EH(e.join(`/`)),OH=e=>e.replace(/\/+$/,``),kH=e=>OH(e).replace(/^\/*/,`/`),AH=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,jH=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,MH=[`EvalError`,`RangeError`,`ReferenceError`,`SyntaxError`,`TypeError`,`URIError`],NH=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function PH(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function FH(e){return DH(e.map(e=>e.route.path).filter(Boolean))||`/`}var IH=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function LH(e,t){let n=e;if(typeof n!=`string`||!EV.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(IH)try{let e=new URL(window.location.href),r=DV.test(n)?new URL(OV(n,e.protocol)):new URL(n),a=_H(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{NV(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}var RH=Symbol(`Uninstrumented`);function zH(e,t){let n={lazy:[],"lazy.loader":[],"lazy.action":[],"lazy.middleware":[],middleware:[],loader:[],action:[]};e.forEach(e=>e({id:t.id,index:t.index,path:t.path,instrument(e){let t=Object.keys(n);for(let r of t)e[r]&&n[r].push(e[r])}}));let r={};if(typeof t.lazy==`function`&&n.lazy.length>0){let e=VH(n.lazy,t.lazy,()=>void 0);e&&(r.lazy=e)}if(typeof t.lazy==`object`){let e=t.lazy;[`middleware`,`loader`,`action`].forEach(t=>{let i=e[t],a=n[`lazy.${t}`];if(typeof i==`function`&&a.length>0){let e=VH(a,i,()=>void 0);e&&(r.lazy=Object.assign(r.lazy||{},{[t]:e}))}})}return[`loader`,`action`].forEach(e=>{let i=t[e];if(typeof i==`function`&&n[e].length>0){let t=i[RH]??i,a=VH(n[e],t,(...e)=>UH(e[0]));a&&(e===`loader`&&t.hydrate===!0&&(a.hydrate=!0),a[RH]=t,r[e]=a)}}),t.middleware&&t.middleware.length>0&&n.middleware.length>0&&(r.middleware=t.middleware.map(e=>{let t=e[RH]??e,r=VH(n.middleware,t,(...e)=>UH(e[0]));return r?(r[RH]=t,r):e})),r}function BH(e,t){let n={navigate:[],fetch:[]};if(t.forEach(e=>e({instrument(e){let t=Object.keys(e);for(let r of t)e[r]&&n[r].push(e[r])}})),n.navigate.length>0){let t=e.navigate[RH]??e.navigate,r=VH(n.navigate,t,(...t)=>{let[n,r]=t;return{to:typeof n==`number`||typeof n==`string`?n:n?LV(n):`.`,...WH(e,r??{})}});r&&(r[RH]=t,e.navigate=r)}if(n.fetch.length>0){let t=e.fetch[RH]??e.fetch,r=VH(n.fetch,t,(...t)=>{let[n,,r,i]=t;return{href:r??`.`,fetcherKey:n,...WH(e,i??{})}});r&&(r[RH]=t,e.fetch=r)}return e}function VH(e,t,n){return e.length===0?null:async(...r)=>{let i=await HH(e,n(...r),()=>t(...r),e.length-1);if(i.type===`error`)throw i.value;return i.value}}async function HH(e,t,n,r){let i=e[r],a;if(i){let o,s=async()=>(o?console.error(`You cannot call instrumented handlers more than once`):o=HH(e,t,n,r-1),a=await o,MV(a,`Expected a result`),a.type===`error`&&a.value instanceof Error?{status:`error`,error:a.value}:{status:`success`,error:void 0});try{await i(s,t)}catch(e){console.error(`An instrumentation function threw an error:`,e)}o||await s(),await o}else try{a={type:`success`,value:await n()}}catch(e){a={type:`error`,value:e}}return a||{type:`error`,value:Error(`No result assigned in instrumentation chain.`)}}function UH(e){let{request:t,context:n,params:r,pattern:i}=e;return{request:GH(t),params:{...r},pattern:i,context:KH(n)}}function WH(e,t){return{currentUrl:LV(e.state.location),...`formMethod`in t?{formMethod:t.formMethod}:{},...`formEncType`in t?{formEncType:t.formEncType}:{},...`formData`in t?{formData:t.formData}:{},...`body`in t?{body:t.body}:{}}}function GH(e){return{method:e.method,url:e.url,headers:{get:(...t)=>e.headers.get(...t)}}}function KH(e){if(JH(e)){let t={...e};return Object.freeze(t),t}else return{get:t=>e.get(t)}}var qH=Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);function JH(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null||Object.getOwnPropertyNames(t).sort().join(`\0`)===qH}var YH=[`POST`,`PUT`,`PATCH`,`DELETE`],XH=new Set(YH),ZH=[`GET`,...YH],QH=new Set(ZH),$H=new Set([301,302,303,307,308]),eU=new Set([307,308]),tU={state:`idle`,location:void 0,matches:void 0,historyAction:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0},nU={state:`idle`,data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0},rU={state:`unblocked`,proceed:void 0,reset:void 0,location:void 0},iU=e=>({hasErrorBoundary:!!e.hasErrorBoundary}),aU=`remix-router-transitions`,oU=Symbol(`ResetLoaderData`),sU,cU,lU,uU,dU=class{constructor(e){wV(this,sU),wV(this,cU),wV(this,lU),wV(this,uU),TV(this,sU,e),TV(this,cU,$V(e))}get stableRoutes(){return CV(this,sU)}get activeRoutes(){return CV(this,lU)??CV(this,sU)}get branches(){return CV(this,uU)??CV(this,cU)}get hasHMRRoutes(){return CV(this,lU)!=null}setRoutes(e){TV(this,sU,e),TV(this,cU,$V(e))}setHmrRoutes(e){TV(this,lU,e),TV(this,uU,$V(e))}commitHmrRoutes(){CV(this,lU)&&(TV(this,sU,CV(this,lU)),TV(this,cU,CV(this,uU)),TV(this,lU,void 0),TV(this,uU,void 0))}};sU=new WeakMap,cU=new WeakMap,lU=new WeakMap,uU=new WeakMap;function fU(e){let t=e.window?e.window:typeof window<`u`?window:void 0,n=t!==void 0&&t.document!==void 0&&t.document.createElement!==void 0;MV(e.routes.length>0,`You must provide a non-empty routes array to createRouter`);let r=e.hydrationRouteProperties||[],i=e.mapRouteProperties||iU,a=i;if(e.instrumentations){let t=e.instrumentations;a=e=>({...i(e),...zH(t.map(e=>e.route).filter(Boolean),e)})}let o={},s=new dU(JV(e.routes,a,void 0,o)),c=e.basename||`/`;c.startsWith(`/`)||(c=`/${c}`);let l=e.dataStrategy||kU,u={...e.future},d=null,f=new Set,p=null,m=null,h=null,g=null,_=e.hydrationData!=null,v=ZV(s.activeRoutes,e.history.location,c,!1,s.branches),y=!1,b=null,x,S;if(v==null&&!e.patchRoutesOnNavigation){let t=eW(404,{pathname:e.history.location.pathname}),{matches:n,route:r}=$U(s.activeRoutes);x=!0,S=!x,v=n,b={[r.id]:t}}else if(v&&!e.hydrationData&&qe(v,s.activeRoutes,e.history.location.pathname).active&&(v=null),!v){x=!1,S=!x,v=[];let t=qe(null,s.activeRoutes,e.history.location.pathname);t.active&&t.matches&&(y=!0,v=t.matches)}else if(v.some(e=>e.route.lazy))x=!1,S=!x;else if(!v.some(e=>_U(e.route)))x=!0,S=!x;else{let t=e.hydrationData?e.hydrationData.loaderData:null,n=e.hydrationData?e.hydrationData.errors:null,r=v;if(n){let e=v.findIndex(e=>n[e.route.id]!==void 0);r=r.slice(0,e+1)}S=!1,x=!0,r.forEach(e=>{let r=vU(e.route,t,n);S||=r.renderFallback,x&&=!r.shouldLoad})}let C,w={historyAction:e.history.action,location:e.history.location,matches:v,initialized:x,renderFallback:S,navigation:tU,restoreScrollPosition:e.hydrationData==null?null:!1,preventScrollReset:!1,revalidation:`idle`,loaderData:e.hydrationData&&e.hydrationData.loaderData||{},actionData:e.hydrationData&&e.hydrationData.actionData||null,errors:e.hydrationData&&e.hydrationData.errors||b,fetchers:new Map,blockers:new Map},T=`POP`,E=null,D=!1,O,k=!1,A=new Map,j=null,M=!1,ee=!1,N=new Set,P=new Map,te=0,ne=-1,re=new Map,ie=new Set,ae=new Map,oe=new Map,se=new Set,ce=new Map,le,ue=null;function de(){if(d=e.history.listen(({action:t,location:n,delta:r})=>{if(le){le(),le=void 0;return}NV(ce.size===0||r!=null,"You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");let i=F({currentLocation:w.location,nextLocation:n,historyAction:t});if(i&&r!=null){let t=new Promise(e=>{le=e});e.history.go(r*-1),He(i,{state:`blocked`,location:n,proceed(){He(i,{state:`proceeding`,proceed:void 0,reset:void 0,location:n}),t.then(()=>e.history.go(r))},reset(){let e=new Map(w.blockers);e.set(i,rU),me({blockers:e})}}),E?.resolve(),E=null;return}return ve(t,n)}),n){wW(t,A);let e=()=>TW(t,A);t.addEventListener(`pagehide`,e),j=()=>t.removeEventListener(`pagehide`,e)}return w.initialized||ve(`POP`,w.location,{initialHydration:!0}),C}function fe(){d&&d(),j&&j(),f.clear(),O&&O.abort(),w.fetchers.forEach((e,t)=>Pe(w.fetchers,t)),w.blockers.forEach((e,t)=>Ve(t))}function pe(e){if(f.add(e),p){let{newErrors:t}=p;p=null,e(w,{deletedFetchers:[],newErrors:t,viewTransitionOpts:void 0,flushSync:!1})}return()=>f.delete(e)}function me(e,t={}){e.matches&&=e.matches.map(e=>{let t=o[e.route.id],n=e.route;return n.element!==t.element||n.errorElement!==t.errorElement||n.hydrateFallbackElement!==t.hydrateFallbackElement?{...e,route:t}:e}),w={...w,...e};let n=[],r=[];w.fetchers.forEach((e,t)=>{e.state===`idle`&&(se.has(t)?n.push(t):r.push(t))}),se.forEach(e=>{!w.fetchers.has(e)&&!P.has(e)&&n.push(e)}),f.size===0&&(p={newErrors:e.errors??null}),[...f].forEach(r=>r(w,{deletedFetchers:n,newErrors:e.errors??null,viewTransitionOpts:t.viewTransitionOpts,flushSync:t.flushSync===!0})),n.forEach(e=>Pe(w.fetchers,e)),r.forEach(e=>w.fetchers.delete(e))}function he(t,n,{flushSync:r}={}){let i=w.actionData!=null&&w.navigation.formMethod!=null&&hW(w.navigation.formMethod)&&w.navigation.state===`loading`&&t.state?._isRedirect!==!0,a;a=n.actionData?Object.keys(n.actionData).length>0?n.actionData:null:i?w.actionData:null;let o=n.loaderData?XU(w.loaderData,n.loaderData,n.matches||[],n.errors):w.loaderData,c=w.blockers;c.size>0&&(c=new Map(c),c.forEach((e,t)=>c.set(t,rU)));let l=M?!1:Ke(t,n.matches||w.matches),u=D===!0||w.navigation.formMethod!=null&&hW(w.navigation.formMethod)&&t.state?._isRedirect!==!0;s.commitHmrRoutes(),M||T===`POP`||(T===`PUSH`?e.history.push(t,t.state):T===`REPLACE`&&e.history.replace(t,t.state));let d;if(T===`POP`){let e=A.get(w.location.pathname);e&&e.has(t.pathname)?d={currentLocation:w.location,nextLocation:t}:A.has(t.pathname)&&(d={currentLocation:t,nextLocation:w.location})}else if(k){let e=A.get(w.location.pathname);e?e.add(t.pathname):(e=new Set([t.pathname]),A.set(w.location.pathname,e)),d={currentLocation:w.location,nextLocation:t}}me({...n,actionData:a,loaderData:o,historyAction:T,location:t,initialized:!0,renderFallback:!1,navigation:tU,revalidation:`idle`,restoreScrollPosition:l,preventScrollReset:u,blockers:c},{viewTransitionOpts:d,flushSync:r===!0}),T=`POP`,D=!1,k=!1,M=!1,ee=!1,E?.resolve(),E=null,ue?.resolve(),ue=null}async function ge(t,n){if(E?.resolve(),E=null,typeof t==`number`){E||=EW();let n=E.promise;return e.history.go(t),n}let{path:r,submission:i,error:a}=hU(!1,mU(w.location,w.matches,c,t,n?.fromRouteId,n?.relative),n),o;n?.mask&&(o={pathname:``,search:``,hash:``,...typeof n.mask==`string`?RV(n.mask):{...w.location.mask,...n.mask}});let s=w.location,l=IV(s,r,n&&n.state,void 0,o);l={...l,...e.history.encodeLocation(l)};let u=n&&n.replace!=null?n.replace:void 0,d=`PUSH`;u===!0?d=`REPLACE`:u===!1||i!=null&&hW(i.formMethod)&&i.formAction===w.location.pathname+w.location.search&&(d=`REPLACE`);let f=n&&`preventScrollReset`in n?n.preventScrollReset===!0:void 0,p=(n&&n.flushSync)===!0,m=F({currentLocation:s,nextLocation:l,historyAction:d});if(m){He(m,{state:`blocked`,location:l,proceed(){He(m,{state:`proceeding`,proceed:void 0,reset:void 0,location:l}),ge(t,n)},reset(){let e=new Map(w.blockers);e.set(m,rU),me({blockers:e})}});return}await ve(d,l,{submission:i,pendingError:a,preventScrollReset:f,replace:n&&n.replace,enableViewTransition:n&&n.viewTransition,flushSync:p,callSiteDefaultShouldRevalidate:n&&n.defaultShouldRevalidate})}function _e(){ue||=EW(),ke(),me({revalidation:`loading`});let e=ue.promise;return w.navigation.state===`submitting`?e:w.navigation.state===`idle`?(ve(w.historyAction,w.location,{startUninterruptedRevalidation:!0}),e):(ve(T||w.historyAction,w.navigation.location,{overrideNavigation:w.navigation,enableViewTransition:k===!0}),e)}async function ve(t,n,r){O&&O.abort(),O=null,T=t,M=(r&&r.startUninterruptedRevalidation)===!0,I(w.location,w.matches),D=(r&&r.preventScrollReset)===!0,k=(r&&r.enableViewTransition)===!0;let i=s.activeRoutes,a=r?.initialHydration&&w.matches&&w.matches.length>0&&!y?w.matches:ZV(i,n,c,!1,s.branches),o=(r&&r.flushSync)===!0;if(a&&w.initialized&&!ee&&rW(w.location,n)&&!(r&&r.submission&&hW(r.submission.formMethod))){he(n,{matches:a},{flushSync:o});return}let l=qe(a,i,n.pathname);if(l.active&&l.matches&&(a=l.matches),!a){let{error:e,notFoundMatches:t,route:r}=Ue(n.pathname);he(n,{matches:t,loaderData:{},errors:{[r.id]:e}},{flushSync:o});return}let u=r&&r.overrideNavigation?{...r.overrideNavigation,matches:a,historyAction:t}:void 0;O=new AbortController;let d=WU(e.history,n,O.signal,r&&r.submission),f=e.getContext?await e.getContext():new HV,p;if(r&&r.pendingError)p=[QU(a).route.id,{type:`error`,error:r.pendingError}];else if(r&&r.submission&&hW(r.submission.formMethod)){let i=await ye(d,n,r.submission,a,t,f,l.active,r&&r.initialHydration===!0,{replace:r.replace,flushSync:o});if(i.shortCircuited)return;if(i.pendingActionResult){let[e,t]=i.pendingActionResult;if(cW(t)&&PH(t.error)&&t.error.status===404){O=null,he(n,{matches:i.matches,loaderData:{},errors:{[e]:t.error}});return}}a=i.matches||a,p=i.pendingActionResult,u=yW(n,a,t,r.submission),o=!1,l.active=!1,d=WU(e.history,d.url,d.signal)}let{shortCircuited:m,matches:h,loaderData:g,errors:_,workingFetchers:v}=await be(d,n,a,t,f,l.active,u,r&&r.submission,r&&r.fetcherSubmission,r&&r.replace,r&&r.initialHydration===!0,o,p,r&&r.callSiteDefaultShouldRevalidate);m||(O=null,he(n,{matches:h||a,...ZU(p),loaderData:g,errors:_,...v?{fetchers:v}:{}}))}async function ye(t,n,i,l,u,d,f,p,m={}){if(ke(),me({navigation:bW(n,l,u,i)},{flushSync:m.flushSync===!0}),f){let e=await Je(l,n.pathname,t.signal);if(e.type===`aborted`)return{shortCircuited:!0};if(e.type===`error`){if(e.partialMatches.length===0){let{matches:t,route:n}=$U(s.activeRoutes);return{matches:t,pendingActionResult:[n.id,{type:`error`,error:e.error}]}}let t=QU(e.partialMatches).route.id;return{matches:e.partialMatches,pendingActionResult:[t,{type:`error`,error:e.error}]}}else if(e.matches)l=e.matches;else{let{notFoundMatches:e,error:t,route:r}=Ue(n.pathname);return{matches:e,pendingActionResult:[r.id,{type:`error`,error:t}]}}}let h,g=_W(l,n);if(!g.route.action&&!g.route.lazy)h={type:`error`,error:eW(405,{method:t.method,pathname:n.pathname,routeId:g.route.id})};else{let e=await De(t,n,FU(a,o,t,n,l,g,p?[]:r,d),d,null);if(h=e[g.route.id],!h){for(let t of l)if(e[t.route.id]){h=e[t.route.id];break}}if(t.signal.aborted)return{shortCircuited:!0}}if(lW(h)){let n;return n=m&&m.replace!=null?m.replace:UU(h.response.headers.get(`Location`),new URL(t.url),c,e.history)===w.location.pathname+w.location.search,await Ee(t,h,!0,{submission:i,replace:n}),{shortCircuited:!0}}if(cW(h)){let e=QU(l,g.route.id);return(m&&m.replace)!==!0&&(T=`PUSH`),{matches:l,pendingActionResult:[e.route.id,h,g.route.id]}}return{matches:l,pendingActionResult:[g.route.id,h]}}async function be(t,n,i,l,u,d,f,p,m,h,g,_,v,y){let b=f||yW(n,i,l,p),x=p||m||vW(b),S=!M&&!g;if(d){if(S){let e=xe(v);me({navigation:b,...e===void 0?{}:{actionData:e}},{flushSync:_})}let e=await Je(i,n.pathname,t.signal);if(e.type===`aborted`)return{shortCircuited:!0};if(e.type===`error`){if(e.partialMatches.length===0){let{matches:t,route:n}=$U(s.activeRoutes);return{matches:t,loaderData:{},errors:{[n.id]:e.error}}}let t=QU(e.partialMatches).route.id;return{matches:e.partialMatches,loaderData:{},errors:{[t]:e.error}}}else if(e.matches)i=e.matches;else{let{error:e,notFoundMatches:t,route:r}=Ue(n.pathname);return{matches:t,loaderData:{},errors:{[r.id]:e}}}}let C=s.activeRoutes,{dsMatches:T,revalidatingFetchers:E}=gU(t,u,a,o,e.history,w,i,x,n,g?[]:r,g===!0,ee,N,se,ae,ie,C,c,e.patchRoutesOnNavigation!=null,s.branches,v,y);if(ne=++te,!e.dataStrategy&&!T.some(e=>e.shouldLoad)&&!T.some(e=>e.route.middleware&&e.route.middleware.length>0)&&E.length===0){let e=new Map(w.fetchers),t=Re(e);return he(n,{matches:i,loaderData:{},errors:v&&cW(v[1])?{[v[0]]:v[1].error}:null,...ZU(v),...t?{fetchers:e}:{}},{flushSync:_}),{shortCircuited:!0}}if(S){let e={};if(!d){e.navigation=b;let t=xe(v);t!==void 0&&(e.actionData=t)}E.length>0&&(e.fetchers=Se(E)),me(e,{flushSync:_})}E.forEach(e=>{Ie(e.key),e.controller&&P.set(e.key,e.controller)});let D=()=>E.forEach(e=>Ie(e.key));O&&O.signal.addEventListener(`abort`,D);let{loaderResults:k,fetcherResults:A}=await Oe(T,E,t,n,u);if(t.signal.aborted)return{shortCircuited:!0};O&&O.signal.removeEventListener(`abort`,D),E.forEach(e=>P.delete(e.key));let j=tW(k);if(j)return await Ee(t,j.result,!0,{replace:h}),{shortCircuited:!0};if(j=tW(A),j)return ie.add(j.key),await Ee(t,j.result,!0,{replace:h}),{shortCircuited:!0};let re=new Map(w.fetchers),{loaderData:oe,errors:ce}=YU(w,i,k,v,E,A,re);g&&w.errors&&(ce={...w.errors,...ce});let le=Re(re),ue=ze(ne,re),de=le||ue||E.length>0;return{matches:i,loaderData:oe,errors:ce,...de?{workingFetchers:re}:{}}}function xe(e){if(e&&!cW(e[1]))return{[e[0]]:e[1].data};if(w.actionData)return Object.keys(w.actionData).length===0?null:w.actionData}function Se(e){let t=new Map(w.fetchers);return e.forEach(e=>{let n=t.get(e.key),r=xW(void 0,n?n.data:void 0);t.set(e.key,r)}),t}async function Ce(t,n,r,i){Ie(t);let a=(i&&i.flushSync)===!0,o=s.activeRoutes,l=mU(w.location,w.matches,c,r,n,i?.relative),u=ZV(o,l,c,!1,s.branches),d=qe(u,o,l);if(d.active&&d.matches&&(u=d.matches),!u){je(t,n,eW(404,{pathname:l}),{flushSync:a});return}let{path:f,submission:p,error:m}=hU(!0,l,i);if(m){je(t,n,m,{flushSync:a});return}let h=e.getContext?await e.getContext():new HV,g=(i&&i.preventScrollReset)===!0;if(p&&hW(p.formMethod)){await we(t,n,f,u,h,d.active,a,g,p,i&&i.defaultShouldRevalidate);return}ae.set(t,{routeId:n,path:f}),await Te(t,n,f,u,h,d.active,a,g,p)}async function we(t,n,i,l,u,d,f,p,m,h){ke(),ae.delete(t),Ae(t,SW(m,w.fetchers.get(t)),{flushSync:f});let g=new AbortController,_=WU(e.history,i,g.signal,m);if(d){let e=await Je(l,new URL(_.url).pathname,_.signal,t);if(e.type===`aborted`)return;if(e.type===`error`){je(t,n,e.error,{flushSync:f});return}else if(e.matches)l=e.matches;else{je(t,n,eW(404,{pathname:i}),{flushSync:f});return}}let v=_W(l,i);if(!v.route.action&&!v.route.lazy){je(t,n,eW(405,{method:m.formMethod,pathname:i,routeId:n}),{flushSync:f});return}P.set(t,g);let y=te,b=FU(a,o,_,i,l,v,r,u),x=await De(_,i,b,u,t),S=x[v.route.id];if(!S){for(let e of b)if(x[e.route.id]){S=x[e.route.id];break}}if(_.signal.aborted){P.get(t)===g&&P.delete(t);return}if(se.has(t)){if(lW(S)||cW(S)){Ae(t,CW(void 0));return}}else{if(lW(S))if(P.delete(t),ne>y){Ae(t,CW(void 0));return}else return ie.add(t),Ae(t,xW(m)),Ee(_,S,!1,{fetcherSubmission:m,preventScrollReset:p});if(cW(S)){je(t,n,S.error);return}}let C=w.navigation.location||w.location,E=WU(e.history,C,g.signal),D=s.activeRoutes,k=w.navigation.state===`idle`?w.matches:ZV(D,w.navigation.location,c,!1,s.branches);MV(k,`Didn't find any matches after fetcher action`);let A=++te;re.set(t,A);let{dsMatches:j,revalidatingFetchers:M}=gU(E,u,a,o,e.history,w,k,m,C,r,!1,ee,N,se,ae,ie,D,c,e.patchRoutesOnNavigation!=null,s.branches,[v.route.id,S],h),oe=xW(m,S.data),ce=new Map(w.fetchers);ce.set(t,oe),M.filter(e=>e.key!==t).forEach(e=>{let t=e.key,n=ce.get(t),r=xW(void 0,n?n.data:void 0);ce.set(t,r),Ie(t),e.controller&&P.set(t,e.controller)}),me({fetchers:ce});let le=()=>M.forEach(e=>Ie(e.key));g.signal.addEventListener(`abort`,le);let{loaderResults:ue,fetcherResults:de}=await Oe(j,M,E,C,u);if(g.signal.aborted)return;g.signal.removeEventListener(`abort`,le),re.delete(t),P.delete(t),M.forEach(e=>P.delete(e.key));let fe=w.fetchers.has(t),pe=e=>{if(!fe)return e;let n=new Map(e.fetchers);return n.set(t,CW(S.data)),{...e,fetchers:n}},ge=tW(ue);if(ge)return w=pe(w),Ee(E,ge.result,!1,{preventScrollReset:p});if(ge=tW(de),ge)return ie.add(ge.key),w=pe(w),Ee(E,ge.result,!1,{preventScrollReset:p});let _e=new Map(w.fetchers);fe&&_e.set(t,CW(S.data));let{loaderData:ve,errors:ye}=YU(w,k,ue,void 0,M,de,_e);ze(A,_e),w.navigation.state===`loading`&&A>ne?(MV(T,`Expected pending action`),O&&O.abort(),he(w.navigation.location,{matches:k,loaderData:ve,errors:ye,fetchers:_e})):(me({errors:ye,loaderData:XU(w.loaderData,ve,k,ye),fetchers:_e}),ee=!1)}async function Te(t,n,i,s,c,l,u,d,f){let p=w.fetchers.get(t);Ae(t,xW(f,p?p.data:void 0),{flushSync:u});let m=new AbortController,h=WU(e.history,i,m.signal);if(l){let e=await Je(s,new URL(h.url).pathname,h.signal,t);if(e.type===`aborted`)return;if(e.type===`error`){je(t,n,e.error,{flushSync:u});return}else if(e.matches)s=e.matches;else{je(t,n,eW(404,{pathname:i}),{flushSync:u});return}}let g=_W(s,i);P.set(t,m);let _=te,v=await De(h,i,FU(a,o,h,i,s,g,r,c),c,t),y=v[g.route.id];if(!y){for(let e of s)if(v[e.route.id]){y=v[e.route.id];break}}if(P.get(t)===m&&P.delete(t),!h.signal.aborted){if(se.has(t)){Ae(t,CW(void 0));return}if(lW(y))if(ne>_){Ae(t,CW(void 0));return}else{ie.add(t),await Ee(h,y,!1,{preventScrollReset:d});return}if(cW(y)){je(t,n,y.error);return}Ae(t,CW(y.data))}}async function Ee(r,i,a,{submission:o,fetcherSubmission:s,preventScrollReset:l,replace:u}={}){a||(E?.resolve(),E=null),i.response.headers.has(`X-Remix-Revalidate`)&&(ee=!0);let d=i.response.headers.get(`Location`);MV(d,`Expected a Location header on the redirect Response`),d=UU(d,new URL(r.url),c,e.history);let f=IV(w.location,d,{_isRedirect:!0});if(n){let e=!1;if(i.response.headers.has(`X-Remix-Reload-Document`))e=!0;else if(yH(d)){let n=BV(t,d,!0);e=n.origin!==t.location.origin||_H(n.pathname,c)==null}if(e){u?t.location.replace(d):t.location.assign(d);return}}O=null;let p=u===!0||i.response.headers.has(`X-Remix-Replace`)?`REPLACE`:`PUSH`,{formMethod:m,formAction:h,formEncType:g}=w.navigation;!o&&!s&&m&&h&&g&&(o=vW(w.navigation));let _=o||s;eU.has(i.response.status)&&_&&hW(_.formMethod)?await ve(p,f,{submission:{..._,formAction:d},preventScrollReset:l||D,enableViewTransition:a?k:void 0}):await ve(p,f,{overrideNavigation:yW(f,[],p,o),fetcherSubmission:s,preventScrollReset:l||D,enableViewTransition:a?k:void 0})}async function De(e,t,n,r,i){let a,o={};try{a=await IU(l,e,t,n,i,r,!1)}catch(e){return n.filter(e=>e.shouldLoad).forEach(t=>{o[t.route.id]={type:`error`,error:e}}),o}if(e.signal.aborted)return o;if(!hW(e.method))for(let e of n){if(a[e.route.id]?.type===`error`)break;!a.hasOwnProperty(e.route.id)&&!w.loaderData.hasOwnProperty(e.route.id)&&(!w.errors||!w.errors.hasOwnProperty(e.route.id))&&e.shouldCallHandler()&&(a[e.route.id]={type:`error`,result:Error(`No result returned from dataStrategy for route ${e.route.id}`)})}for(let[t,r]of Object.entries(a))if(sW(r)){let i=r.result;o[t]={type:`redirect`,response:BU(i,e,t,n,c)}}else o[t]=await zU(r);return o}async function Oe(e,t,n,r,i){let a=De(n,r,e,i,null),o=Promise.all(t.map(async e=>{if(e.matches&&e.match&&e.request&&e.controller){let t=(await De(e.request,e.path,e.matches,i,e.key))[e.match.route.id];return{[e.key]:t}}else return Promise.resolve({[e.key]:{type:`error`,error:eW(404,{pathname:e.path})}})}));return{loaderResults:await a,fetcherResults:(await o).reduce((e,t)=>Object.assign(e,t),{})}}function ke(){ee=!0,ae.forEach((e,t)=>{P.has(t)&&N.add(t),Ie(t)})}function Ae(e,t,n={}){let r=new Map(w.fetchers);r.set(e,t),me({fetchers:r},{flushSync:(n&&n.flushSync)===!0})}function je(e,t,n,r={}){let i=QU(w.matches,t),a=new Map(w.fetchers);Pe(a,e),me({errors:{[i.route.id]:n},fetchers:a},{flushSync:(r&&r.flushSync)===!0})}function Me(e){return oe.set(e,(oe.get(e)||0)+1),se.has(e)&&se.delete(e),w.fetchers.get(e)||nU}function Ne(e,t){Ie(e,t?.reason),Ae(e,CW(null))}function Pe(e,t){let n=w.fetchers.get(t);P.has(t)&&!(n&&n.state===`loading`&&re.has(t))&&Ie(t),ae.delete(t),re.delete(t),ie.delete(t),se.delete(t),N.delete(t),e.delete(t)}function Fe(e){let t=(oe.get(e)||0)-1;t<=0?(oe.delete(e),se.add(e)):oe.set(e,t),me({fetchers:new Map(w.fetchers)})}function Ie(e,t){let n=P.get(e);n&&(n.abort(t),P.delete(e))}function Le(e,t){for(let n of e){let e=t.get(n);MV(e,`Expected fetcher: ${n}`);let r=CW(e.data);t.set(n,r)}}function Re(e){let t=[],n=!1;for(let r of ie){let i=e.get(r);MV(i,`Expected fetcher: ${r}`),i.state===`loading`&&(ie.delete(r),t.push(r),n=!0)}return Le(t,e),n}function ze(e,t){let n=[];for(let[r,i]of re)if(i<e){let e=t.get(r);MV(e,`Expected fetcher: ${r}`),e.state===`loading`&&(Ie(r),re.delete(r),n.push(r))}return Le(n,t),n.length>0}function Be(e,t){let n=w.blockers.get(e)||rU;return ce.get(e)!==t&&ce.set(e,t),n}function Ve(e){w.blockers.delete(e),ce.delete(e)}function He(e,t){let n=w.blockers.get(e)||rU;MV(n.state===`unblocked`&&t.state===`blocked`||n.state===`blocked`&&t.state===`blocked`||n.state===`blocked`&&t.state===`proceeding`||n.state===`blocked`&&t.state===`unblocked`||n.state===`proceeding`&&t.state===`unblocked`,`Invalid blocker state transition: ${n.state} -> ${t.state}`);let r=new Map(w.blockers);r.set(e,t),me({blockers:r})}function F({currentLocation:e,nextLocation:t,historyAction:n}){if(ce.size===0)return;ce.size>1&&NV(!1,`A router only supports one blocker at a time`);let r=Array.from(ce.entries()),[i,a]=r[r.length-1],o=w.blockers.get(i);if(!(o&&o.state===`proceeding`)&&a({currentLocation:e,nextLocation:t,historyAction:n}))return i}function Ue(e){let t=eW(404,{pathname:e}),n=s.activeRoutes,{matches:r,route:i}=$U(n);return{notFoundMatches:r,route:i,error:t}}function We(e,t,n){if(m=e,g=t,h=n||null,!_&&w.navigation===tU){_=!0;let e=Ke(w.location,w.matches);e!=null&&me({restoreScrollPosition:e})}return()=>{m=null,g=null,h=null}}function Ge(e,t){return h&&h(e,t.map(e=>QV(e,w.loaderData)))||e.key}function I(e,t){if(m&&g){let n=Ge(e,t);m[n]=g()}}function Ke(e,t){if(m){let n=Ge(e,t),r=m[n];if(typeof r==`number`)return r}return null}function qe(t,n,r){if(e.patchRoutesOnNavigation){let e=s.branches;if(!t)return{active:!0,matches:ZV(n,r,c,!0,e)||[]};if(Object.keys(t[0].params).length>0)return{active:!0,matches:ZV(n,r,c,!0,e)}}return{active:!1,matches:null}}async function Je(t,n,r,i){if(!e.patchRoutesOnNavigation)return{type:`success`,matches:t};let l=t;for(;;){let t=o;try{await e.patchRoutesOnNavigation({signal:r,path:n,matches:l,fetcherKey:i,patch:(e,n)=>{r.aborted||SU(e,n,s,t,a,!1)}})}catch(e){return{type:`error`,error:e,partialMatches:l}}if(r.aborted)return{type:`aborted`};let u=s.branches,d=ZV(s.activeRoutes,n,c,!1,u),f=null;if(d&&(Object.keys(d[0].params).length===0||(f=ZV(s.activeRoutes,n,c,!0,u),!(f&&l.length<f.length&&Ye(l,f.slice(0,l.length))))))return{type:`success`,matches:d};if(f||=ZV(s.activeRoutes,n,c,!0,u),!f||Ye(l,f))return{type:`success`,matches:null};l=f}}function Ye(e,t){return e.length===t.length&&e.every((e,n)=>e.route.id===t[n].route.id)}function Xe(e){o={},s.setHmrRoutes(JV(e,a,void 0,o))}function Ze(e,t,n=!1){SU(e,t,s,o,a,n),s.hasHMRRoutes||me({})}return C={get basename(){return c},get future(){return u},get state(){return w},get routes(){return s.stableRoutes},get branches(){return s.branches},get manifest(){return o},get window(){return t},initialize:de,subscribe:pe,enableScrollRestoration:We,navigate:ge,fetch:Ce,revalidate:_e,createHref:t=>e.history.createHref(t),encodeLocation:t=>e.history.encodeLocation(t),getFetcher:Me,resetFetcher:Ne,deleteFetcher:Fe,dispose:fe,getBlocker:Be,deleteBlocker:Ve,patchRoutes:Ze,_internalFetchControllers:P,_internalSetRoutes:Xe,_internalSetStateDoNotUseOrYouWillBreakYourApp(e){me(e)}},e.instrumentations&&(C=BH(C,e.instrumentations.map(e=>e.router).filter(Boolean))),C}function pU(e){return e!=null&&(`formData`in e&&e.formData!=null||`body`in e&&e.body!==void 0)}function mU(e,t,n,r,i,a){let o,s;if(i){o=[];for(let e of t)if(o.push(e),e.route.id===i){s=e;break}}else o=t,s=t[t.length-1];let c=TH(r||`.`,wH(o),_H(e.pathname,n)||e.pathname,a===`path`);if(r??(c.search=e.search,c.hash=e.hash),(r==null||r===``||r===`.`)&&s){let e=gW(c.search);if(s.route.index&&!e)c.search=c.search?c.search.replace(/^\?/,`?index&`):`?index`;else if(!s.route.index&&e){let e=new URLSearchParams(c.search),t=e.getAll(`index`);e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();c.search=n?`?${n}`:``}}return n!==`/`&&(c.pathname=vH({basename:n,pathname:c.pathname})),LV(c)}function hU(e,t,n){if(!n||!pU(n))return{path:t};if(n.formMethod&&!mW(n.formMethod))return{path:t,error:eW(405,{method:n.formMethod})};let r=()=>({path:t,error:eW(400,{type:`invalid-body`})}),i=(n.formMethod||`get`).toUpperCase(),a=nW(t);if(n.body!==void 0){if(n.formEncType===`text/plain`){if(!hW(i))return r();let e=typeof n.body==`string`?n.body:n.body instanceof FormData||n.body instanceof URLSearchParams?Array.from(n.body.entries()).reduce((e,[t,n])=>`${e}${t}=${n}
|
|
209
209
|
`,``):String(n.body);return{path:t,submission:{formMethod:i,formAction:a,formEncType:n.formEncType,formData:void 0,json:void 0,text:e}}}else if(n.formEncType===`application/json`){if(!hW(i))return r();try{let e=typeof n.body==`string`?JSON.parse(n.body):n.body;return{path:t,submission:{formMethod:i,formAction:a,formEncType:n.formEncType,formData:void 0,json:e,text:void 0}}}catch{return r()}}}MV(typeof FormData==`function`,`FormData is not available in this environment`);let o,s;if(n.formData)o=KU(n.formData),s=n.formData;else if(n.body instanceof FormData)o=KU(n.body),s=n.body;else if(n.body instanceof URLSearchParams)o=n.body,s=qU(o);else if(n.body==null)o=new URLSearchParams,s=new FormData;else try{o=new URLSearchParams(n.body),s=qU(o)}catch{return r()}let c={formMethod:i,formAction:a,formEncType:n&&n.formEncType||`application/x-www-form-urlencoded`,formData:s,json:void 0,text:void 0};if(hW(c.formMethod))return{path:t,submission:c};let l=RV(t);return e&&l.search&&gW(l.search)&&o.append(`index`,``),l.search=`?${o}`,{path:LV(l),submission:c}}function gU(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x){let S=b?cW(b[1])?b[1].error:b[1].data:void 0,C=i.createURL(a.location),w=i.createURL(c),T;if(u&&a.errors){let e=Object.keys(a.errors)[0];T=o.findIndex(t=>t.route.id===e)}else if(b&&cW(b[1])){let e=b[0];T=o.findIndex(t=>t.route.id===e)-1}let E=b?b[1].statusCode:void 0,D=E&&E>=400,O={currentUrl:C,currentParams:a.matches[0]?.params||{},nextUrl:w,nextParams:o[0].params,...s,actionResult:S,actionStatus:E},k=FH(o),A=o.map((i,o)=>{let{route:s}=i,f=null;if(T!=null&&o>T)f=!1;else if(s.lazy)f=!0;else if(!_U(s))f=!1;else if(u){let{shouldLoad:e}=vU(s,a.loaderData,a.errors);f=e}else yU(a.loaderData,a.matches[o],i)&&(f=!0);if(f!==null)return PU(n,r,e,c,k,i,l,t,f);let p=!1;typeof x==`boolean`?p=x:D?p=!1:d||C.pathname+C.search===w.pathname+w.search?p=!0:C.search===w.search?bU(a.matches[o],i)&&(p=!0):p=!0;let m={...O,defaultShouldRevalidate:p};return PU(n,r,e,c,k,i,l,t,xU(i,m),m,x)}),j=[];return m.forEach((e,s)=>{if(u||!o.some(t=>t.route.id===e.routeId)||p.has(s))return;let c=a.fetchers.get(s),m=c&&c.state!==`idle`&&c.data===void 0,b=ZV(g,e.path,_??`/`,!1,y);if(!b){if(v&&m)return;j.push({key:s,routeId:e.routeId,path:e.path,matches:null,match:null,request:null,controller:null});return}if(h.has(s))return;let S=_W(b,e.path),C=new AbortController,w=WU(i,e.path,C.signal),T=null;if(f.has(s))f.delete(s),T=FU(n,r,w,e.path,b,S,l,t);else if(m)d&&(T=FU(n,r,w,e.path,b,S,l,t));else{let i;i=typeof x==`boolean`?x:D?!1:d;let a={...O,defaultShouldRevalidate:i};xU(S,a)&&(T=FU(n,r,w,e.path,b,S,l,t,a))}T&&j.push({key:s,routeId:e.routeId,path:e.path,matches:T,match:S,request:w,controller:C})}),{dsMatches:A,revalidatingFetchers:j}}function _U(e){return e.loader!=null||e.middleware!=null&&e.middleware.length>0}function vU(e,t,n){if(e.lazy)return{shouldLoad:!0,renderFallback:!0};if(!_U(e))return{shouldLoad:!1,renderFallback:!1};let r=t!=null&&e.id in t,i=n!=null&&n[e.id]!==void 0;if(!r&&i)return{shouldLoad:!1,renderFallback:!1};if(typeof e.loader==`function`&&e.loader.hydrate===!0)return{shouldLoad:!0,renderFallback:!r};let a=!r&&!i;return{shouldLoad:a,renderFallback:a}}function yU(e,t,n){let r=!t||n.route.id!==t.route.id,i=!e.hasOwnProperty(n.route.id);return r||i}function bU(e,t){let n=e.route.path;return e.pathname!==t.pathname||n!=null&&n.endsWith(`*`)&&e.params[`*`]!==t.params[`*`]}function xU(e,t){if(e.route.shouldRevalidate){let n=e.route.shouldRevalidate(t);if(typeof n==`boolean`)return n}return t.defaultShouldRevalidate}function SU(e,t,n,r,i,a){let o;if(e){let t=r[e];MV(t,`No route found to patch children into: routeId = ${e}`),t.children||=[],o=t.children}else o=n.activeRoutes;let s=[],c=[];if(t.forEach(e=>{let t=o.find(t=>CU(e,t));t?c.push({existingRoute:t,newRoute:e}):s.push(e)}),s.length>0){let t=JV(s,i,[e||`_`,`patch`,String(o?.length||`0`)],r);o.push(...t)}if(a&&c.length>0)for(let e=0;e<c.length;e++){let{existingRoute:t,newRoute:n}=c[e],r=t,[a]=JV([n],i,[],{},!0);Object.assign(r,{element:a.element?a.element:r.element,errorElement:a.errorElement?a.errorElement:r.errorElement,hydrateFallbackElement:a.hydrateFallbackElement?a.hydrateFallbackElement:r.hydrateFallbackElement})}n.hasHMRRoutes||n.setRoutes([...n.activeRoutes])}function CU(e,t){return`id`in e&&`id`in t&&e.id===t.id?!0:e.index===t.index&&e.path===t.path&&e.caseSensitive===t.caseSensitive?(!e.children||e.children.length===0)&&(!t.children||t.children.length===0)?!0:e.children?.every((e,n)=>t.children?.some(t=>CU(e,t)))??!1:!1}var wU=new WeakMap,TU=({key:e,route:t,manifest:n,mapRouteProperties:r})=>{let i=n[t.id];if(MV(i,`No route found in manifest`),!i.lazy||typeof i.lazy!=`object`)return;let a=i.lazy[e];if(!a)return;let o=wU.get(i);o||(o={},wU.set(i,o));let s=o[e];if(s)return s;let c=(async()=>{let t=WV(e),n=i[e]!==void 0&&e!==`hasErrorBoundary`;if(t)NV(!t,`Route property `+e+` is not a supported lazy route property. This property will be ignored.`),o[e]=Promise.resolve();else if(n)NV(!1,`Route "${i.id}" has a static property "${e}" defined. The lazy property will be ignored.`);else{let t=await a();t!=null&&(Object.assign(i,{[e]:t}),Object.assign(i,r(i)))}typeof i.lazy==`object`&&(i.lazy[e]=void 0,Object.values(i.lazy).every(e=>e===void 0)&&(i.lazy=void 0))})();return o[e]=c,c},EU=new WeakMap;function DU(e,t,n,r,i){let a=n[e.id];if(MV(a,`No route found in manifest`),!e.lazy)return{lazyRoutePromise:void 0,lazyHandlerPromise:void 0};if(typeof e.lazy==`function`){let t=EU.get(a);if(t)return{lazyRoutePromise:t,lazyHandlerPromise:t};let n=(async()=>{MV(typeof e.lazy==`function`,`No lazy route function found`);let t=await e.lazy(),n={};for(let e in t){let r=t[e];if(r===void 0)continue;let i=KV(e),o=a[e]!==void 0&&e!==`hasErrorBoundary`;i?NV(!i,`Route property `+e+` is not a supported property to be returned from a lazy route function. This property will be ignored.`):o?NV(!o,`Route "${a.id}" has a static property "${e}" defined but its lazy function is also returning a value for this property. The lazy route property "${e}" will be ignored.`):n[e]=r}Object.assign(a,n),Object.assign(a,{...r(a),lazy:void 0})})();return EU.set(a,n),n.catch(()=>{}),{lazyRoutePromise:n,lazyHandlerPromise:n}}let o=Object.keys(e.lazy),s=[],c;for(let a of o){if(i&&i.includes(a))continue;let o=TU({key:a,route:e,manifest:n,mapRouteProperties:r});o&&(s.push(o),a===t&&(c=o))}let l=s.length>0?Promise.all(s).then(()=>{}):void 0;return l?.catch(()=>{}),c?.catch(()=>{}),{lazyRoutePromise:l,lazyHandlerPromise:c}}async function OU(e){let t=e.matches.filter(e=>e.shouldLoad),n={};return(await Promise.all(t.map(e=>e.resolve()))).forEach((e,r)=>{n[t[r].route.id]=e}),n}async function kU(e){return e.matches.some(e=>e.route.middleware)?AU(e,()=>OU(e)):OU(e)}function AU(e,t){return jU(e,t,e=>{if(pW(e))throw e;return e},aW,n);function n(t,n,r){if(r)return Promise.resolve(Object.assign(r.value,{[n]:{type:`error`,result:t}}));{let{matches:r}=e,i=QU(r,r[Math.min(Math.max(r.findIndex(e=>e.route.id===n),0),Math.max(r.findIndex(e=>e.shouldCallHandler()),0))].route.id).route.id;return Promise.resolve({[i]:{type:`error`,result:t}})}}}async function jU(e,t,n,r,i){let{matches:a,...o}=e;return await MU(o,a.flatMap(e=>e.route.middleware?e.route.middleware.map(t=>[e.route.id,t]):[]),t,n,r,i)}async function MU(e,t,n,r,i,a,o=0){let{request:s}=e;if(s.signal.aborted)throw s.signal.reason??Error(`Request aborted: ${s.method} ${s.url}`);let c=t[o];if(!c)return await n();let[l,u]=c,d,f=async()=>{if(d)throw Error("You may only call `next()` once per middleware");try{return d={value:await MU(e,t,n,r,i,a,o+1)},d.value}catch(e){return d={value:await a(e,l,d)},d.value}};try{let t=await u(e,f),n=t==null?void 0:r(t);return i(n)?n:d?n??d.value:(d={value:await f()},d.value)}catch(e){return await a(e,l,d)}}function NU(e,t,n,r,i){let a=TU({key:`middleware`,route:r.route,manifest:t,mapRouteProperties:e}),o=DU(r.route,hW(n.method)?`action`:`loader`,t,e,i);return{middleware:a,route:o.lazyRoutePromise,handler:o.lazyHandlerPromise}}function PU(e,t,n,r,i,a,o,s,c,l=null,u){let d=!1,f=NU(e,t,n,a,o);return{...a,_lazyPromises:f,shouldLoad:c,shouldRevalidateArgs:l,shouldCallHandler(e){return d=!0,l?typeof u==`boolean`?xU(a,{...l,defaultShouldRevalidate:u}):typeof e==`boolean`?xU(a,{...l,defaultShouldRevalidate:e}):xU(a,l):c},resolve(e){let{lazy:t,loader:o,middleware:l}=a.route,u=d||c||e&&!hW(n.method)&&(t||o),p=l&&l.length>0&&!o&&!t;return u&&(hW(n.method)||!p)?LU({request:n,path:r,pattern:i,match:a,lazyHandlerPromise:f?.handler,lazyRoutePromise:f?.route,handlerOverride:e,scopedContext:s}):Promise.resolve({type:`data`,result:void 0})}}}function FU(e,t,n,r,i,a,o,s,c=null){return i.map(l=>l.route.id===a.route.id?PU(e,t,n,r,FH(i),l,o,s,!0,c):{...l,shouldLoad:!1,shouldRevalidateArgs:c,shouldCallHandler:()=>!1,_lazyPromises:NU(e,t,n,l,o),resolve:()=>Promise.resolve({type:`data`,result:void 0})})}async function IU(e,t,n,r,i,a,o){r.some(e=>e._lazyPromises?.middleware)&&await Promise.all(r.map(e=>e._lazyPromises?.middleware));let s={request:t,url:GU(t,n),pattern:FH(r),params:r[0].params,context:a,matches:r},c=o?()=>{throw Error("You cannot call `runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`")}:e=>{let t=s;return AU(t,()=>e({...t,fetcherKey:i,runClientMiddleware:()=>{throw Error("Cannot call `runClientMiddleware()` from within an `runClientMiddleware` handler")}}))},l=await e({...s,fetcherKey:i,runClientMiddleware:c});try{await Promise.all(r.flatMap(e=>[e._lazyPromises?.handler,e._lazyPromises?.route]))}catch{}return l}async function LU({request:e,path:t,pattern:n,match:r,lazyHandlerPromise:i,lazyRoutePromise:a,handlerOverride:o,scopedContext:s}){let c,l,u=hW(e.method),d=u?`action`:`loader`,f=i=>{let a,c=new Promise((e,t)=>a=t);l=()=>a(),e.signal.addEventListener(`abort`,l);let u=a=>typeof i==`function`?i({request:e,url:GU(e,t),pattern:n,params:r.params,context:s},...a===void 0?[]:[a]):Promise.reject(Error(`You cannot call the handler for a route which defines a boolean "${d}" [routeId: ${r.route.id}]`)),f=(async()=>{try{return{type:`data`,result:await(o?o(e=>u(e)):u())}}catch(e){return{type:`error`,result:e}}})();return Promise.race([f,c])};try{let t=u?r.route.action:r.route.loader;if(i||a)if(t){let e,[n]=await Promise.all([f(t).catch(t=>{e=t}),i,a]);if(e!==void 0)throw e;c=n}else{await i;let t=u?r.route.action:r.route.loader;if(t)[c]=await Promise.all([f(t),a]);else if(d===`action`){let t=new URL(e.url),n=t.pathname+t.search;throw eW(405,{method:e.method,pathname:n,routeId:r.route.id})}else return{type:`data`,result:void 0}}else if(t)c=await f(t);else{let t=new URL(e.url);throw eW(404,{pathname:t.pathname+t.search})}}catch(e){return{type:`error`,result:e}}finally{l&&e.signal.removeEventListener(`abort`,l)}return c}async function RU(e){let t=e.headers.get(`Content-Type`);return t&&/\bapplication\/json\b/.test(t)?e.body==null?null:e.json():e.text()}async function zU(e){let{result:t,type:n}=e;if(dW(t)){let e;try{e=await RU(t)}catch(e){return{type:`error`,error:e}}return n===`error`?{type:`error`,error:new NH(t.status,t.statusText,e),statusCode:t.status,headers:t.headers}:{type:`data`,data:e,statusCode:t.status,headers:t.headers}}return n===`error`?uW(t)?t.data instanceof Error?{type:`error`,error:t.data,statusCode:t.init?.status,headers:t.init?.headers?new Headers(t.init.headers):void 0}:{type:`error`,error:iW(t),statusCode:PH(t)?t.status:void 0,headers:t.init?.headers?new Headers(t.init.headers):void 0}:{type:`error`,error:t,statusCode:PH(t)?t.status:void 0}:uW(t)?{type:`data`,data:t.data,statusCode:t.init?.status,headers:t.init?.headers?new Headers(t.init.headers):void 0}:{type:`data`,data:t}}function BU(e,t,n,r,i){let a=e.headers.get(`Location`);if(MV(a,`Redirects returned/thrown from loaders/actions must have a Location header`),!yH(a)){let o=r.slice(0,r.findIndex(e=>e.route.id===n)+1);a=mU(new URL(t.url),o,i,a),e.headers.set(`Location`,a)}return e}var VU=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function HU(e){try{return VU.includes(new URL(e).protocol)}catch{return!1}}function UU(e,t,n,r){if(yH(e)){let r=e,i=DV.test(r)?new URL(OV(r,t.protocol)):new URL(r);if(HU(i.toString()))throw Error(`Invalid redirect location`);let a=_H(i.pathname,n)!=null;if(i.origin===t.origin&&a)return EH(i.pathname)+i.search+i.hash}try{if(HU(r.createURL(e).toString()))throw Error(`Invalid redirect location`)}catch{}return e}function WU(e,t,n,r){let i=e.createURL(nW(t)).toString(),a={signal:n};if(r&&hW(r.formMethod)){let{formMethod:e,formEncType:t}=r;a.method=e.toUpperCase(),t===`application/json`?(a.headers=new Headers({"Content-Type":t}),a.body=JSON.stringify(r.json)):t===`text/plain`?a.body=r.text:t===`application/x-www-form-urlencoded`&&r.formData?a.body=KU(r.formData):a.body=r.formData}return new Request(i,a)}function GU(e,t){let n=new URL(e.url),r=typeof t==`string`?RV(t):t;if(n.pathname=r.pathname||`/`,r.search){let e=new URLSearchParams(r.search),t=e.getAll(`index`);e.delete(`index`);for(let n of t.filter(Boolean))e.append(`index`,n);n.search=e.size?`?${e.toString()}`:``}else n.search=``;return n.hash=r.hash||``,n}function KU(e){let t=new URLSearchParams;for(let[n,r]of e.entries())t.append(n,typeof r==`string`?r:r.name);return t}function qU(e){let t=new FormData;for(let[n,r]of e.entries())t.append(n,r);return t}function JU(e,t,n,r=!1,i=!1){let a={},o=null,s,c=!1,l={},u=n&&cW(n[1])?n[1].error:void 0;return e.forEach(n=>{if(!(n.route.id in t))return;let d=n.route.id,f=t[d];if(MV(!lW(f),`Cannot handle redirect results in processLoaderData`),cW(f)){let t=f.error;if(u!==void 0&&(t=u,u=void 0),o||={},i)o[d]=t;else{let n=QU(e,d);o[n.route.id]??(o[n.route.id]=t)}r||(a[d]=oU),c||(c=!0,s=PH(f.error)?f.error.status:500),f.headers&&(l[d]=f.headers)}else a[d]=f.data,f.statusCode&&f.statusCode!==200&&!c&&(s=f.statusCode),f.headers&&(l[d]=f.headers)}),u!==void 0&&n&&(o={[n[0]]:u},n[2]&&(a[n[2]]=void 0)),{loaderData:a,errors:o,statusCode:s||200,loaderHeaders:l}}function YU(e,t,n,r,i,a,o){let{loaderData:s,errors:c}=JU(t,n,r);return i.filter(e=>!e.matches||e.matches.some(e=>e.shouldLoad)).forEach(t=>{let{key:n,match:r,controller:i}=t;if(i&&i.signal.aborted)return;let s=a[n];if(MV(s,`Did not find corresponding fetcher result`),cW(s)){let t=QU(e.matches,r?.route.id);c&&c[t.route.id]||(c={...c,[t.route.id]:s.error}),o.delete(n)}else if(lW(s))MV(!1,`Unhandled fetcher revalidation redirect`);else{let e=CW(s.data);o.set(n,e)}}),{loaderData:s,errors:c}}function XU(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!==oU).reduce((e,[t,n])=>(e[t]=n,e),{});for(let a of n){let n=a.route.id;if(!t.hasOwnProperty(n)&&e.hasOwnProperty(n)&&a.route.loader&&(i[n]=e[n]),r&&r.hasOwnProperty(n))break}return i}function ZU(e){return e?cW(e[1])?{actionData:{}}:{actionData:{[e[0]]:e[1].data}}:{}}function QU(e,t){return(t?e.slice(0,e.findIndex(e=>e.route.id===t)+1):[...e]).reverse().find(e=>e.route.hasErrorBoundary===!0)||e[0]}function $U(e){let t=e.length===1?e[0]:e.find(e=>e.index||!e.path||e.path===`/`)||{id:`__shim-error-route__`};return{matches:[{params:{},pathname:``,pathnameBase:``,route:t}],route:t}}function eW(e,{pathname:t,routeId:n,method:r,type:i,message:a}={}){let o=`Unknown Server Error`,s=`Unknown @remix-run/router error`;return e===400?(o=`Bad Request`,r&&t&&n?s=`You made a ${r} request to "${t}" but did not provide a \`loader\` for route "${n}", so there is no way to handle the request.`:i===`invalid-body`&&(s=`Unable to encode submission body`)):e===403?(o=`Forbidden`,s=`Route "${n}" does not match URL "${t}"`):e===404?(o=`Not Found`,s=`No route matches URL "${t}"`):e===405&&(o=`Method Not Allowed`,r&&t&&n?s=`You made a ${r.toUpperCase()} request to "${t}" but did not provide an \`action\` for route "${n}", so there is no way to handle the request.`:r&&(s=`Invalid request method "${r.toUpperCase()}"`)),new NH(e||500,o,Error(s),!0)}function tW(e){let t=Object.entries(e);for(let e=t.length-1;e>=0;e--){let[n,r]=t[e];if(lW(r))return{key:n,result:r}}}function nW(e){return LV({...typeof e==`string`?RV(e):e,hash:``})}function rW(e,t){return e.pathname!==t.pathname||e.search!==t.search?!1:e.hash===``?t.hash!==``:e.hash===t.hash?!0:t.hash!==``}function iW(e){return new NH(e.init?.status??500,e.init?.statusText??`Internal Server Error`,e.data)}function aW(e){return typeof e==`object`&&!!e&&Object.entries(e).every(([e,t])=>typeof e==`string`&&oW(t))}function oW(e){return typeof e==`object`&&!!e&&`type`in e&&`result`in e&&(e.type===`data`||e.type===`error`)}function sW(e){return dW(e.result)&&$H.has(e.result.status)}function cW(e){return e.type===`error`}function lW(e){return(e&&e.type)===`redirect`}function uW(e){return typeof e==`object`&&!!e&&`type`in e&&`data`in e&&`init`in e&&e.type===`DataWithResponseInit`}function dW(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.headers==`object`&&e.body!==void 0}function fW(e){return $H.has(e)}function pW(e){return dW(e)&&fW(e.status)&&e.headers.has(`Location`)}function mW(e){return QH.has(e.toUpperCase())}function hW(e){return XH.has(e.toUpperCase())}function gW(e){return new URLSearchParams(e).getAll(`index`).some(e=>e===``)}function _W(e,t){let n=typeof t==`string`?RV(t).search:t.search;if(e[e.length-1].route.index&&gW(n||``))return e[e.length-1];let r=CH(e);return r[r.length-1]}function vW(e){let{formMethod:t,formAction:n,formEncType:r,text:i,formData:a,json:o}=e;if(!(!t||!n||!r)){if(i!=null)return{formMethod:t,formAction:n,formEncType:r,formData:void 0,json:void 0,text:i};if(a!=null)return{formMethod:t,formAction:n,formEncType:r,formData:a,json:void 0,text:void 0};if(o!==void 0)return{formMethod:t,formAction:n,formEncType:r,formData:void 0,json:o,text:void 0}}}function yW(e,t,n,r){return r?{state:`loading`,location:e,matches:t,historyAction:n,formMethod:r.formMethod,formAction:r.formAction,formEncType:r.formEncType,formData:r.formData,json:r.json,text:r.text}:{state:`loading`,location:e,matches:t,historyAction:n,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0}}function bW(e,t,n,r){return{state:`submitting`,location:e,matches:t,historyAction:n,formMethod:r.formMethod,formAction:r.formAction,formEncType:r.formEncType,formData:r.formData,json:r.json,text:r.text}}function xW(e,t){return e?{state:`loading`,formMethod:e.formMethod,formAction:e.formAction,formEncType:e.formEncType,formData:e.formData,json:e.json,text:e.text,data:t}:{state:`loading`,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0,data:t}}function SW(e,t){return{state:`submitting`,formMethod:e.formMethod,formAction:e.formAction,formEncType:e.formEncType,formData:e.formData,json:e.json,text:e.text,data:t?t.data:void 0}}function CW(e){return{state:`idle`,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0,data:e}}function wW(e,t){try{let n=e.sessionStorage.getItem(aU);if(n){let e=JSON.parse(n);for(let[n,r]of Object.entries(e||{}))r&&Array.isArray(r)&&t.set(n,new Set(r||[]))}}catch{}}function TW(e,t){if(t.size>0){let n={};for(let[e,r]of t)n[e]=[...r];try{e.sessionStorage.setItem(aU,JSON.stringify(n))}catch(e){NV(!1,`Failed to save applied view transitions in sessionStorage (${e}).`)}}}function EW(){let e,t,n=new Promise((r,i)=>{e=async e=>{r(e);try{await n}catch{}},t=async e=>{i(e);try{await n}catch{}}});return{promise:n,resolve:e,reject:t}}var DW=b.createContext(null);DW.displayName=`DataRouter`;var OW=b.createContext(null);OW.displayName=`DataRouterState`;var kW=b.createContext(!1);function AW(){return b.useContext(kW)}var jW=b.createContext({isTransitioning:!1});jW.displayName=`ViewTransition`;var MW=b.createContext(new Map);MW.displayName=`Fetchers`;var NW=b.createContext(null);NW.displayName=`Await`;var PW=b.createContext(null);PW.displayName=`Navigation`;var FW=b.createContext(null);FW.displayName=`Location`;var IW=b.createContext({outlet:null,matches:[],isDataRoute:!1});IW.displayName=`Route`;var LW=b.createContext(null);LW.displayName=`RouteError`;var RW=`REACT_ROUTER_ERROR`,zW=`REDIRECT`,BW=`ROUTE_ERROR_RESPONSE`;function VW(e){if(e.startsWith(`${RW}:${zW}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function HW(e){if(e.startsWith(`${RW}:${BW}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new NH(t.status,t.statusText,t.data)}catch{}}function UW(e,{relative:t}={}){MV(WW(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=b.useContext(PW),{hash:i,pathname:a,search:o}=$W(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:DH([n,a])),r.createHref({pathname:s,search:o,hash:i})}function WW(){return b.useContext(FW)!=null}function GW(){return MV(WW(),`useLocation() may be used only in the context of a <Router> component.`),b.useContext(FW).location}var KW=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function qW(e){b.useContext(PW).static||b.useLayoutEffect(e)}function JW(){let{isDataRoute:e}=b.useContext(IW);return e?vG():YW()}function YW(){MV(WW(),`useNavigate() may be used only in the context of a <Router> component.`);let e=b.useContext(DW),{basename:t,navigator:n}=b.useContext(PW),{matches:r}=b.useContext(IW),{pathname:i}=GW(),a=JSON.stringify(wH(r)),o=b.useRef(!1);return qW(()=>{o.current=!0}),b.useCallback((r,s={})=>{if(NV(o.current,KW),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=TH(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:DH([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var XW=b.createContext(null);function ZW(e){let t=b.useContext(IW).outlet;return b.useMemo(()=>t&&b.createElement(XW.Provider,{value:e},t),[t,e])}function QW(){let{matches:e}=b.useContext(IW);return e[e.length-1]?.params??{}}function $W(e,{relative:t}={}){let{matches:n}=b.useContext(IW),{pathname:r}=GW(),i=JSON.stringify(wH(n));return b.useMemo(()=>TH(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function eG(e,t){return tG(e,t)}function tG(e,t,n){MV(WW(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=b.useContext(PW),{matches:i}=b.useContext(IW),a=i[i.length-1],o=a?a.params:{},s=a?a.pathname:`/`,c=a?a.pathnameBase:`/`,l=a&&a.route;{let e=l&&l.path||``;bG(s,!l||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${s}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
@@ -235,4 +235,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
235
235
|
}
|
|
236
236
|
]
|
|
237
237
|
}`,hZ=`MSH|^~\\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT|MSG00001|P|2.1\rPID|||PATID1234^5^M11||JONES^WILLIAM^A^III||19610615|M-||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(919)379-1212|(919)271-3434||S||PATID12345001^2^M10|123456789|987654^NC\rNK1|1|JONES^BARBARA^K|SPO|||||20011105\rPV1|1|I|2000^2012^01||||004777^LEBAUER^SIDNEY^J.|||SUR||-||1|A0-`;function gZ(){let e=Q(),{id:t}=QW(),[n,r]=(0,b.useState)(),[i,a]=(0,b.useState)(),[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(mZ),[u,d]=(0,b.useState)(hZ),[f,p]=(0,b.useState)(ZE.FHIR_JSON),m=(0,b.useRef)(null),h=(0,b.useRef)(null),[g,_]=(0,b.useState)(!1);(0,b.useEffect)(()=>{e.readResource(`Bot`,t).then(async t=>{r(t),a(t.runtimeVersion===`vmcontext`?`commonjs`:`esnext`),s(await _Z(e,t))}).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))},[e,t]);let v=(0,b.useCallback)(async()=>lM(m.current,{command:`getValue`}),[]),y=(0,b.useCallback)(async()=>lM(m.current,{command:`getOutput`}),[]),x=(0,b.useCallback)(async()=>f===ZE.FHIR_JSON?JSON.parse(c):u,[f,c,u]),S=(0,b.useCallback)(async n=>{n.preventDefault(),n.stopPropagation(),_(!0);try{let n=await v(),r=await y(),a=await e.createAttachment({data:n,filename:`index.ts`,contentType:ZE.TYPESCRIPT}),o=await e.createAttachment({data:r,filename:i===`commonjs`?`index.cjs`:`index.mjs`,contentType:ZE.JAVASCRIPT}),s=[{op:`add`,path:`/sourceCode`,value:a},{op:`add`,path:`/executableCode`,value:o}];await e.patchResource(`Bot`,t,s),J({color:`green`,message:`Saved`})}catch(e){J({color:`red`,message:Y(e),autoClose:!1})}finally{_(!1)}},[e,t,i,v,y]),C=(0,b.useCallback)(async n=>{n.preventDefault(),n.stopPropagation(),_(!0);try{await e.post(e.fhirUrl(`Bot`,t,`$deploy`)),J({color:`green`,message:`Deployed`})}catch(e){J({color:`red`,message:Y(e),autoClose:!1})}finally{_(!1)}},[e,t]),w=(0,b.useCallback)(async n=>{n.preventDefault(),n.stopPropagation(),_(!0);try{let n=await x(),r=await e.post(e.fhirUrl(`Bot`,t,`$execute`),n,f);await lM(h.current,{command:`setValue`,value:r}),J({color:`green`,message:`Success`})}catch(e){J({color:`red`,message:Y(e),autoClose:!1})}finally{_(!1)}},[e,t,x,f]);return!n||o===void 0?null:(0,I.jsxs)(Fp,{m:0,gutter:0,style:{overflow:`hidden`},children:[(0,I.jsx)(Fp.Col,{span:8,children:(0,I.jsxs)(Xc,{m:2,pb:`xs`,pr:`xs`,pt:`xs`,shadow:`md`,mih:400,children:[(0,I.jsx)(pZ,{iframeRef:m,language:`typescript`,module:i,testId:`code-frame`,defaultValue:o,minHeight:`528px`}),(0,I.jsxs)(V,{justify:`flex-end`,gap:`xs`,children:[(0,I.jsx)(U,{type:`button`,onClick:S,loading:g,leftSection:(0,I.jsx)(nj,{size:`1rem`}),children:`Save`}),(0,I.jsx)(U,{type:`button`,onClick:C,loading:g,leftSection:(0,I.jsx)(XA,{size:`1rem`}),children:`Deploy`}),(0,I.jsx)(U,{type:`button`,onClick:w,loading:g,leftSection:(0,I.jsx)(jj,{size:`1rem`}),children:`Execute`})]})]})}),(0,I.jsxs)(Fp.Col,{span:4,children:[(0,I.jsxs)(Xc,{m:2,pb:`xs`,pr:`xs`,pt:`xs`,shadow:`md`,children:[(0,I.jsx)(yg,{data:[{label:`FHIR`,value:ZE.FHIR_JSON},{label:`HL7`,value:ZE.HL7_V2}],onChange:e=>p(e.currentTarget.value)}),f===ZE.FHIR_JSON?(0,I.jsx)(bm,{value:c,onChange:e=>l(e),autosize:!0,minRows:15}):(0,I.jsx)(`textarea`,{className:dZ.hl7Input,value:u,onChange:e=>d(e.currentTarget.value),rows:15})]}),(0,I.jsx)(Xc,{m:2,p:`xs`,shadow:`md`,children:(0,I.jsx)(fZ,{iframeRef:h,className:`medplum-bot-output-frame`,testId:`output-frame`,minHeight:`200px`})})]})]})}async function _Z(e,t){if(t.sourceCode?.url){let n=t.sourceCode.url?.split(`/`)?.find(MC);return(await e.download(e.fhirUrl(`Binary`,n))).text()}return t.code??``}function vZ(e){let t=e.meta;return t&&={...t,lastUpdated:void 0,versionId:void 0,author:void 0},{...e,meta:t}}function yZ(){let e=Q(),{resourceType:t,id:n}=QW(),r={reference:t+`/`+n},i=(0,b.useCallback)(t=>{e.updateResource(vZ(t)).then(()=>{J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})},[e]);switch(t){case`PlanDefinition`:return(0,I.jsx)(VP,{children:(0,I.jsx)(Iz,{value:r,onSubmit:i})});case`Questionnaire`:return(0,I.jsx)(VP,{children:(0,I.jsx)(_B,{questionnaire:r,onSubmit:i})});default:return null}}function bZ(){let{resourceType:e,id:t}=QW(),n=bk({reference:e+`/`+t}),r=JW();return n?(0,I.jsx)(VP,{children:(0,I.jsx)(eV,{value:n,onStart:(e,t)=>r(`/forms/${oC(t)}`)?.catch(console.error),onEdit:(e,t,n)=>r(`/${n.reference}}`)?.catch(console.error)})}):null}function xZ(){let e=Q(),{resourceType:t,id:n}=QW(),r=bk({reference:t+`/`+n}),i=(0,b.useRef)(0),[a,o]=(0,b.useState)([]);(0,b.useEffect)(()=>{r&&o((r.payload??iw).map(e=>({key:i.current++,item:e})))},[r]);let s=(0,b.useCallback)((e,t)=>{o(n=>n.map(n=>n.key===e?{...n,item:{...n.item,contentString:t}}:n))},[]),c=(0,b.useCallback)(()=>{o(e=>[...e,{key:i.current++,item:{contentString:``}}])},[]),l=(0,b.useCallback)(()=>{r&&e.updateResource(vZ({...r,payload:a.map(e=>e.item)})).then(()=>J({color:`green`,message:`Saved`})).catch(e=>J({color:`red`,message:Y(e)}))},[e,r,a]);return r?(0,I.jsx)(VP,{children:(0,I.jsxs)(G,{children:[a.filter(({item:e})=>`contentString`in e).map(({key:e,item:t})=>(0,I.jsx)(_m,{autosize:!0,minRows:3,maxRows:20,value:t.contentString??``,onChange:t=>s(e,t.currentTarget.value),placeholder:`Enter content...`},e)),(0,I.jsxs)(V,{justify:`flex-end`,children:[(0,I.jsx)(U,{variant:`outline`,onClick:c,children:`Add payload`}),(0,I.jsx)(U,{onClick:l,children:`Save`})]}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:`This tab manages string payloads only. Attachments and References can be managed in the Edit tab.`})]})}):null}function SZ(){let e=Q(),{resourceType:t,id:n}=QW(),r=JW();return(0,I.jsxs)(VP,{children:[(0,I.jsxs)(`p`,{children:[`Are you sure you want to delete this `,t,`?`]}),(0,I.jsx)(U,{color:`red`,onClick:()=>{e.deleteResource(t,n).then(()=>r(`/${t}`)?.catch(console.error)).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))},children:`Delete`})]})}var CZ={selectProfileBtn:`_selectProfileBtn_tbaz6_1`,chevron:`_chevron_tbaz6_13`};function wZ(){let{resourceType:e,id:t}=QW(),n=bk({reference:e+`/`+t}),[r,i]=(0,b.useState)(),a=cp({onDropdownClose:()=>a.resetSelectedOption()}),o=(0,b.useMemo)(()=>{if(CC(n?.meta?.profile))return[(0,I.jsx)(dp.Option,{value:``,children:`None`},``),...n.meta.profile.map(e=>(0,I.jsx)(dp.Option,{value:e,children:e},e))]},[n?.meta?.profile]);if((0,b.useEffect)(()=>{n?.meta?.profile?.length===1&&i(n.meta.profile[0])},[n?.meta?.profile]),!n)return null;let s;return CC(o)&&(s=(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsxs)(G,{align:`flex-end`,gap:`xs`,children:[(0,I.jsxs)(dp,{store:a,width:250,position:`bottom-end`,withinPortal:!1,onOptionSubmit:e=>{i(e),a.closeDropdown()},children:[(0,I.jsx)(dp.Target,{children:(0,I.jsx)(qc,{onClick:()=>a.toggleDropdown(),children:(0,I.jsxs)(Xd,{fw:`bold`,fs:`sm`,className:CZ.selectProfileBtn,children:[(0,I.jsx)(`span`,{children:`Pick profile`}),(0,I.jsx)(KA,{stroke:1.5,className:CZ.chevron})]})})}),(0,I.jsx)(dp.Dropdown,{w:`max-content`,children:(0,I.jsx)(dp.Options,{children:o})})]}),(0,I.jsx)(z,{children:r?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(H,{span:!0,size:`sm`,c:`dimmed`,children:`Displaying profile:\xA0`}),(0,I.jsx)(H,{span:!0,size:`sm`,children:r||`Nothing selected`})]}):(0,I.jsx)(H,{span:!0,size:`sm`,c:`dimmed`,children:`No profile displayed`})})]})})),(0,I.jsx)(VP,{children:(0,I.jsxs)(G,{gap:`xl`,children:[s,(0,I.jsx)(jL,{value:n,profileUrl:r})]})})}function TZ(){let e=Q(),{resourceType:t,id:n}=QW(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(),s=JW(),[c,l]=(0,b.useState)();(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>{i(jC(e)),o(jC(e))}).catch(e=>{l(Zx(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n]);let u=(0,b.useCallback)(r=>{l(void 0),e.updateResource(vZ(r)).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(Zx(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n,s]),d=(0,b.useCallback)(i=>{l(void 0);let a=VO(r,vZ(i));e.patchResource(t,n,a).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(Zx(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n,r,s]),f=(0,b.useCallback)(()=>s(`/${t}/${n}/delete`)?.catch(console.error),[s,t,n]);return a?(0,I.jsx)(VP,{children:(0,I.jsx)(_V,{defaultValue:a,onSubmit:u,onPatch:d,onDelete:f,outcome:c})}):null}function EZ(){let{resourceType:e,id:t}=QW(),n=bk({reference:e+`/`+t});return n?(0,I.jsx)(VP,{maw:700,children:n.resourceType===`Patient`?(0,I.jsx)(Az,{patient:n}):(0,I.jsx)(ou,{icon:(0,I.jsx)(kA,{size:16}),title:`Unsupported export type`,color:`red`,children:`This page is only supported for Patient resources`})}):null}function DZ({resource:e,currentProfile:t,onChange:n}){let r=e.resourceType,i=Q(),[a,o]=(0,b.useState)();return(0,b.useEffect)(()=>{i.searchResources(`StructureDefinition`,{type:r,derivation:`constraint`,_count:50}).then(e=>{o(e.filter(rI))}).catch(console.error)},[i,n,r]),(0,I.jsx)(vb,{value:t?.url,onChange:e=>{let t=a?.find(t=>t.url===e);t&&n(t)},children:(0,I.jsx)(vb.List,{children:a?.map(t=>{let n=e.meta?.profile?.includes(t.url),r=n?`This profile is present in this resource's meta.profile property.`:`This profile is not included in this resource's meta.profile property.`;return(0,I.jsx)(vb.Tab,{value:t.url,title:r,rightSection:n&&(0,I.jsx)(Sb,{variant:`outline`,color:`green`,size:`xs`,style:{borderStyle:`none`},children:(0,I.jsx)(eM,{size:`90%`})}),children:t.title||t.name},t.url)})})})}function OZ(e,t){let n=Q(),r=JW();return{defaultValue:{resourceType:e},handleSubmit:e=>{t&&t(void 0),n.createResource(e).then(e=>r(`/`+e.resourceType+`/`+e.id)).catch(e=>{t&&t(Zx(e)),J({color:`red`,message:Y(e),autoClose:!1,styles:{description:{whiteSpace:`pre-line`}}})})}}}function kZ(){let{resourceType:e}=QW(),t=GW(),[n,r]=(0,b.useState)(),{defaultValue:i,handleSubmit:a}=OZ(e,r),[o,s]=(0,b.useState)(),c=t.pathname.toLowerCase().endsWith(`profiles`),l=(0,b.useCallback)(e=>{let t=vZ(e);o&&nw(t,o.url),a(t)},[o,a]);return c?(0,I.jsx)(VP,{children:(0,I.jsxs)(G,{children:[(0,I.jsx)(DZ,{resource:i,currentProfile:o,onChange:s}),o?(0,I.jsx)(_V,{defaultValue:i,onSubmit:l,outcome:n,profileUrl:o.url},o.url):(0,I.jsx)(H,{my:`lg`,fz:`lg`,fs:`italic`,ta:`center`,children:`Select a profile above`})]})}):(0,I.jsx)(VP,{children:(0,I.jsx)(_V,{defaultValue:i,onSubmit:a,outcome:n})})}function AZ(){let e=Q(),{resourceType:t,id:n}=QW();return(0,I.jsx)(VP,{children:(0,I.jsx)(vV,{history:e.readHistory(t,n).read()})})}function jZ(){let{resourceType:e}=QW(),[t,n]=(0,b.useState)(),{defaultValue:r,handleSubmit:i}=OZ(e,n),a=(0,b.useCallback)(e=>{i(JSON.parse(e[`new-resource`]))},[i]);return(0,I.jsxs)(VP,{children:[t&&(0,I.jsx)(lF,{outcome:t}),(0,I.jsxs)(WN,{onSubmit:a,children:[(0,I.jsx)(bm,{name:`new-resource`,"data-testid":`create-resource-json`,autosize:!0,minRows:24,defaultValue:vC(r,!0),formatOnBlur:!0,deserialize:JSON.parse}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,wrap:`nowrap`,children:(0,I.jsx)(U,{type:`submit`,children:`OK`})})]})]})}function MZ(){let e=Q(),{resourceType:t,id:n}=QW(),r=bk({reference:t+`/`+n}),i=JW(),[a,o]=(0,b.useState)(),s=(0,b.useCallback)(r=>{e.updateResource(vZ(JSON.parse(r.resource))).then(()=>{o(void 0),i(`/${t}/${n}/details`)?.catch(console.error),J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n,i]);return r?(0,I.jsxs)(VP,{children:[a&&(0,I.jsx)(lF,{outcome:a}),(0,I.jsxs)(WN,{onSubmit:s,children:[(0,I.jsx)(bm,{name:`resource`,"data-testid":`resource-json`,autosize:!0,minRows:24,defaultValue:vC(r,!0),formatOnBlur:!0,deserialize:JSON.parse}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,wrap:`nowrap`,children:(0,I.jsx)(U,{type:`submit`,children:`OK`})})]})]}):null}function NZ(e){let{resourceType:t,id:n}=e;return(0,I.jsxs)(VP,{children:[(0,I.jsxs)(ou,{icon:(0,I.jsx)(kA,{size:16}),mb:`xl`,children:[`This is just a preview! Access your form here:`,(0,I.jsx)(`br`,{}),(0,I.jsx)(pu,{href:`/forms/${n}`,children:`/forms/${n}`})]}),(0,I.jsx)(HB,{questionnaire:{reference:t+`/`+n},onSubmit:()=>alert(`You submitted the preview`)})]})}var PZ={propertyTable:`_propertyTable_1xts4_1`,propertiesTitle:`_propertiesTitle_1xts4_17`};function FZ(e){return e.valueCode||e.valueString||(e.valueBoolean===void 0?void 0:String(e.valueBoolean))||(e.valueInteger===void 0?void 0:String(e.valueInteger))||(e.valueDecimal===void 0?void 0:String(e.valueDecimal))||e.valueDate||e.valueDateTime||`N/A`}function IZ(e){let{properties:t}=e,n=t.map(e=>{let t=``,n=``,r=``;return e.part?.forEach(e=>{e.name===`code`?t=e.valueCode||``:e.name===`description`?n=e.valueString||``:e.name===`value`&&(r=FZ(e))}),{code:t,description:n,value:r}});return(0,I.jsxs)(K,{className:PZ.propertyTable,children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{children:`Code`}),(0,I.jsx)(K.Th,{children:`Description`}),(0,I.jsx)(K.Th,{children:`Value`})]})}),(0,I.jsx)(K.Tbody,{children:n.map((e,t)=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:e.code}),(0,I.jsx)(K.Td,{children:e.description}),(0,I.jsx)(K.Td,{children:e.value})]},`property-${t}`))})]})}function LZ(e){let{valueSet:t}=e,n=Q(),r=t.url,[i,a]=(0,b.useState)(),[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(),f=(0,b.useCallback)(async e=>{if(a(e),s(void 0),d(void 0),!e?.code||!e?.system){l(!1);return}l(!0);try{let t=new URLSearchParams({system:e.system,code:e.code}),r=n.fhirUrl(`CodeSystem`,`$lookup`)+`?`+t.toString();s(await n.get(r))}catch(e){d(e instanceof Error?e:Error(String(e)))}finally{l(!1)}},[n]),p=(0,b.useMemo)(()=>o?.parameter?.filter(e=>e.name===`property`&&e.part)??[],[o]),m=p.length>0;return(0,I.jsx)(VP,{children:(0,I.jsxs)(G,{gap:`xl`,children:[(0,I.jsx)(QN,{binding:r,placeholder:`Select a value from the ValueSet`,onChange:e=>f(e[0]),defaultValue:i,maxValues:1}),i?(0,I.jsxs)(G,{gap:`md`,children:[(0,I.jsxs)(jP,{children:[(0,I.jsx)(MP,{term:`Code`,children:i.code}),i.system&&(0,I.jsx)(MP,{term:`System`,children:i.system}),i.display&&(0,I.jsx)(MP,{term:`Display`,children:i.display})]}),c&&(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(il,{size:`sm`}),(0,I.jsx)(H,{size:`sm`,c:`dimmed`,children:`Loading properties...`})]}),!c&&u&&(0,I.jsxs)(ou,{icon:(0,I.jsx)(kA,{size:16}),title:`Lookup Failed`,color:`red`,children:[`Failed to retrieve code information: `,Y(u)]}),!c&&!u&&m&&(0,I.jsx)(tM,{children:(0,I.jsxs)(G,{gap:`xs`,mt:`lg`,children:[(0,I.jsx)(H,{fw:500,size:`sm`,c:`dimmed`,className:PZ.propertiesTitle,children:`Properties`}),(0,I.jsx)(IZ,{properties:p})]})})]}):null]})})}function RZ(){let{resourceType:e,id:t}=QW(),n=bk({reference:e+`/`+t});return n?n.resourceType===`Questionnaire`?(0,I.jsx)(NZ,{resourceType:e,id:t}):n.resourceType===`ValueSet`?(0,I.jsx)(LZ,{valueSet:n}):null:null}function zZ(){let e=Q(),{resourceType:t,id:n}=QW(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)();return(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>i(jC(e))).catch(e=>{J({color:`red`,message:Y(e)})})},[e,t,n]),r?(0,I.jsxs)(VP,{children:[(0,I.jsxs)(q,{order:2,children:[`Available `,t,` profiles`]}),(0,I.jsx)(G,{children:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(DZ,{resource:r,currentProfile:a,onChange:o}),a?(0,I.jsx)(BZ,{profile:a,resource:r,onResourceUpdated:e=>i(e)},a.url):(0,I.jsx)(H,{my:`lg`,fz:`lg`,fs:`italic`,ta:`center`,children:`Select a profile above`})]})})]}):null}var BZ=({profile:e,resource:t,onResourceUpdated:n})=>{let r=Q(),[i,a]=(0,b.useState)(),[o,s]=(0,b.useState)(()=>t.meta?.profile?.includes(e.url)),c=(0,b.useCallback)(t=>{a(void 0);let i=vZ(t);o?nw(i,e.url):rw(i,e.url),r.updateResource(i).then(e=>{n(e),J({color:`green`,message:`Success`})}).catch(e=>{a(Zx(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[r,e.url,n,o]);return(0,I.jsxs)(G,{children:[(0,I.jsx)(Uy,{size:`md`,checked:o,label:`Conform resource to ${e.title}`,onChange:e=>s(e.currentTarget.checked),"data-testid":`profile-toggle`}),o?(0,I.jsx)(_V,{profileUrl:e.url,defaultValue:t,onSubmit:c,outcome:i}):(0,I.jsx)(`form`,{noValidate:!0,onSubmit:e=>{e.preventDefault(),c(t)},children:(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(U,{type:`submit`,children:`OK`})})})]})},VZ={"Create Only":`create`,"Update Only":`update`,"Delete Only":`delete`,"All Interactions":void 0},HZ=Object.keys(VZ);function UZ(){let e=Q(),{id:t}=QW(),n=bk({reference:`Questionnaire/${t}`}),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(`create`),[s,c]=(0,b.useState)(0),l=e.searchResources(`Subscription`,`status=active&_count=100`).read().filter(e=>WZ(e,n));function u(){r&&n&&e.createResource({resourceType:`Subscription`,status:`active`,reason:`Connect bot ${r.name} to questionnaire responses`,criteria:`QuestionnaireResponse?questionnaire=${n.url?`${n.url},${aC(n)}`:aC(n)}`,channel:{type:`rest-hook`,endpoint:aC(r)},...a?{extension:[{url:`https://medplum.com/fhir/StructureDefinition/subscription-supported-interaction`,valueCode:a}]}:void 0}).then(()=>{i(void 0),c(Date.now()),e.invalidateSearches(`Subscription`),J({color:`green`,message:`Success`})}).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))}return(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Bots`}),(0,I.jsxs)(G,{children:[l.length===0&&(0,I.jsx)(`p`,{children:`No bots found.`}),l.map(e=>(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:(0,I.jsx)(oL,{value:{reference:e.channel?.endpoint},link:!0})}),(0,I.jsxs)(`p`,{children:[`Criteria: `,e.criteria]})]},e.id))]}),(0,I.jsx)(bp,{}),(0,I.jsxs)(G,{mt:10,children:[(0,I.jsx)(Ul,{size:`lg`,htmlFor:`bot`,children:`Connect to bot`}),(0,I.jsxs)(V,{children:[(0,I.jsx)(MI,{name:`bot`,resourceType:`Bot`,onChange:e=>i(e)}),(0,I.jsx)(U,{onClick:u,children:`Connect`})]}),(0,I.jsx)(V,{children:(0,I.jsx)(yg,{name:`subscription-trigger-event`,defaultValue:`Create Only`,label:`Subscription Trigger Event`,data:HZ,onChange:e=>o(VZ[e.target.value])})})]}),(0,I.jsx)(`div`,{style:{display:`none`},children:s})]})}function WZ(e,t){if(!t)return!1;let n=e.criteria||``,r=e.channel?.endpoint||``;return n.startsWith(`QuestionnaireResponse?`)&&r.startsWith(`Bot/`)&&(n.includes(aC(t))||(t.url?n.includes(t.url):!1))}function GZ(){let{id:e}=QW(),t=JW(),n=Q().readReference({reference:`Questionnaire/${e}`}).read(),[r,i]=(0,b.useState)({resourceType:`QuestionnaireResponse`,filters:[{code:`questionnaire`,operator:Z.EQUALS,value:n.url?`${n.url},Questionnaire/${e}`:`Questionnaire/${e}`}],fields:[`id`,`_lastUpdated`]});return(0,I.jsx)(VP,{children:(0,I.jsx)(ez,{search:r,onClick:e=>t(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0,hideToolbar:!0})})}function KZ(){let e=Q(),{resourceType:t,id:n}=QW(),r=bk({reference:t+`/`+n}),i=(0,b.useCallback)(t=>{e.updateResource(vZ(t)).then(()=>{J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})},[e]);return r?(0,I.jsx)(VP,{children:(0,I.jsx)(KB,{onSubmit:i,definition:r})}):null}function qZ(){let{resourceType:e,id:t}=QW(),n=bk({reference:e+`/`+t});return n?(0,I.jsx)(VP,{children:e===`MeasureReport`?(0,I.jsx)(xz,{measureReport:n}):(0,I.jsx)(dL,{value:n})}):null}var JZ={container:`_container_1ue98_1`,entry:`_entry_1ue98_14`,active:`_active_1ue98_21`};function YZ(e){let t=Q(),n=bk(e.value),[r,i]=(0,b.useState)();return(0,b.useEffect)(()=>{if(!n)return;let e=tq(n);if(!e)return;let r=`reference`in e?e.reference:aC(e);t.search(`ServiceRequest`,`subject=`+r).then(e=>{let t=(e.entry??[]).map(e=>e.resource);FL(t),t.reverse(),i(t)}).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))},[t,n]),r?(0,I.jsx)(`div`,{"data-testid":`quick-service-requests`,className:JZ.container,children:r.map(e=>(0,I.jsxs)(`div`,{className:it(JZ.entry,{[JZ.active]:e.id===n?.id}),children:[(0,I.jsx)(`p`,{children:(0,I.jsx)(dM,{to:e,children:XZ(e)})}),e.category?.[0]?.text&&(0,I.jsx)(`p`,{children:e.category[0]?.text}),e.code?.coding?.[0]?.code&&(0,I.jsx)(`p`,{children:e.code.coding[0]?.code}),(0,I.jsx)(`p`,{children:ZZ(e)})]},e.id))}):null}function XZ(e){if(e.identifier){for(let t of e.identifier)if(t.value)return t.value}return e.id||``}function ZZ(e){return e.authoredOn?e.authoredOn.substring(0,10):e.meta?.lastUpdated?e.meta.lastUpdated.substring(0,10):``}var QZ={container:`_container_1l2dh_1`};function $Z(e){let t=bk(e.valueSet);if(!t)return null;let n=[``],r=t.compose?.include?.[0]?.concept?.map(e=>e.code);return r&&n.push(...r),e.defaultValue&&!n.includes(e.defaultValue)&&n.push(e.defaultValue),(0,I.jsx)(`div`,{className:QZ.container,children:(0,I.jsx)(yg,{defaultValue:e.defaultValue,onChange:t=>e.onChange(t.currentTarget.value),data:n})})}function eQ(e){let t=bk(e.specimen);return t?(0,I.jsxs)(uz,{children:[(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Type`}),(0,I.jsx)(uz.Value,{children:`Specimen`})]}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Collected`}),(0,I.jsx)(uz.Value,{children:dw(t.collection?.collectedDateTime)})]}),(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Specimen Age`}),(0,I.jsx)(uz.Value,{children:tQ(t)})]}),t.collection?.collectedDateTime&&t.receivedTime?(0,I.jsxs)(uz.Entry,{children:[(0,I.jsx)(uz.Key,{children:`Specimen Stability`}),(0,I.jsx)(uz.Value,{children:nQ(t)})]}):(0,I.jsx)(I.Fragment,{})]}):null}function tQ(e){let t=e.collection?.collectedDateTime;if(t)return rQ(iQ(new Date(t),new Date))}function nQ(e){if(!(!e.collection?.collectedDateTime||!e.receivedTime))return rQ(iQ(new Date(e.collection.collectedDateTime),new Date(e.receivedTime)))}function rQ(e){return e.toString().padStart(3,`0`)+`D`}function iQ(e,t){let n=t.getTime()-e.getTime();return Math.floor(n/(1e3*3600*24))}function aQ(e){let t=[`Timeline`];return e===`Bot`&&t.push(`Editor`,`Subscriptions`),e===`PlanDefinition`&&t.push(`Apply`,`Builder`),e===`Questionnaire`&&t.push(`Preview`,`Builder`,`Bots`,`Responses`),e===`ValueSet`&&t.push(`Preview`),(e===`DiagnosticReport`||e===`MeasureReport`)&&t.push(`Report`),e===`RequestGroup`&&t.push(`Checklist`),e===`ObservationDefinition`&&t.push(`Ranges`),e===`Agent`&&t.push(`Tools`),e===`User`&&t.push(`Email`),e===`Communication`&&t.push(`Payload`),t.push(`Details`,`Edit`,`Event`,`History`,`Blame`,`JSON`,`Apps`,`Profiles`),e===`Patient`&&t.push(`Accounts`,`Export`),t}function oQ(){let e=Q(),{resourceType:t,id:n}=QW(),r={reference:t+`/`+n},[i,a]=(0,b.useState)(),o=bk(r,a),s=aQ(t);async function c(){let r=(await e.readHistory(t,n)).entry?.find(e=>!!e.resource)?.resource;r?l(r):J({color:`red`,message:`No history to restore`,autoClose:!1})}function l(t){e.updateResource(vZ(t)).then(()=>{a(void 0),J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})}if(i)return Yx(i)?(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Deleted`}),(0,I.jsx)(`p`,{children:`The resource was deleted.`}),(0,I.jsx)(U,{color:`red`,onClick:c,children:`Restore`})]}):(0,I.jsx)(lF,{outcome:i});function u(e){let t=o,n=t.orderDetail||[];n.length===0&&n.push({}),n[0].text!==e&&(n[0].text=e,l({...t,orderDetail:n}))}let d=o&&tq(o),f=o&&nq(o),p=e.getUserConfiguration()?.option?.find(e=>e.id===`statusValueSet`)?.valueString;return(0,I.jsxs)(I.Fragment,{children:[o?.resourceType===`ServiceRequest`&&p&&(0,I.jsx)($Z,{valueSet:{reference:p},defaultValue:o.orderDetail?.[0]?.text,onChange:u},aC(o)+`-`+o.orderDetail?.[0]?.text),o&&(0,I.jsx)(YZ,{value:o}),o&&(0,I.jsxs)(Xc,{children:[d&&(0,I.jsx)(Nz,{patient:d}),f&&(0,I.jsx)(eQ,{specimen:f}),t!==`Patient`&&(0,I.jsx)(jX,{resource:r}),(0,I.jsx)(Hc,{children:(0,I.jsx)(fz,{baseUrl:`/${t}/${n}`,tabs:s})})]}),(0,I.jsx)(PG,{})]})}function sQ(){let e=JW(),{resourceType:t,id:n,versionId:r,tab:i}=QW(),a=Q(),[o,s]=(0,b.useState)(!0),[c,l]=(0,b.useState)(),[u,d]=(0,b.useState)();if((0,b.useEffect)(()=>{d(void 0),s(!0),a.readHistory(t,n).then(e=>l(e)).then(()=>s(!1)).catch(e=>{d(e),s(!1)})},[a,t,n]),o)return(0,I.jsx)(nM,{});let f=c?.entry??[],p=f.findIndex(e=>e.resource?.meta?.versionId===r);if(p===-1)return(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Version not found`}),(0,I.jsx)(dM,{to:`/${t}/${n}`,children:`Return to resource`})]});let m=f[p].resource,h=p<f.length-1?f[p+1].resource:void 0,g=`diff`,_=i||g,v=f.length-p;return(0,I.jsx)(mp,{maw:1200,children:(0,I.jsx)(BP,{children:(0,I.jsxs)(G,{gap:`lg`,children:[u&&(0,I.jsx)(`pre`,{"data-testid":`error`,children:JSON.stringify(u,void 0,2)}),(0,I.jsxs)(_y,{cols:2,mb:`lg`,children:[(0,I.jsx)(X_,{total:f.length,value:v,getControlProps:qR,onChange:r=>e(`/${t}/${n}/_history/${f[f.length-r]?.resource?.meta?.versionId}/${_}`)?.catch(console.error)}),(0,I.jsx)(V,{justify:`right`,children:(0,I.jsx)(ly,{data:[{value:`diff`,label:`Diff`},{value:`raw`,label:`Raw`}],value:_,onChange:i=>e(`/${t}/${n}/_history/${r}/${i||g}`)?.catch(console.error)})})]}),(0,I.jsx)(z,{mb:`lg`,children:(0,I.jsxs)(jP,{compact:!0,children:[(0,I.jsx)(MP,{term:`Version ID`,children:m.meta?.versionId}),(0,I.jsx)(MP,{term:`Author`,children:(0,I.jsx)(sL,{value:m.meta?.author,link:!0},m.meta?.author?.reference)}),(0,I.jsx)(MP,{term:`Date/Time`,children:dw(m.meta?.lastUpdated)})]})}),_===`diff`&&(0,I.jsx)(mV,{original:h??{},revised:m}),_===`raw`&&(0,I.jsx)(`pre`,{style:{fontSize:`9pt`},children:JSON.stringify(m,void 0,2)})]})})})}function cQ(){let{resourceType:e,id:t}=QW(),n=JW(),[r,i]=(0,b.useState)({resourceType:`Subscription`,filters:[{code:`url`,operator:Z.EQUALS,value:`${e}/${t}`}],fields:[`id`,`criteria`,`status`,`_lastUpdated`]});return(0,I.jsx)(VP,{children:(0,I.jsx)(ez,{search:r,onClick:e=>n(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0})})}function lQ(e){let t=Q(),{resource:n,opened:r,onClose:i}=e,[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(`update`),[d,f]=(0,b.useState)(!1);return(0,I.jsx)(Bh,{opened:r,onClose:i,title:`Resend Subscriptions`,children:(0,I.jsx)(WN,{onSubmit:(0,b.useCallback)(async()=>{if(n?.id)try{await t.post(t.fhirUrl(n.resourceType,n.id,`$resend`),{subscription:a&&s?aC(s):void 0,interaction:l,verbose:d}),J({color:`green`,message:`Done`}),i()}catch(e){J({color:`red`,message:Y(e),autoClose:!1})}},[t,n,i,a,s,l,d]),children:(0,I.jsxs)(G,{children:[(0,I.jsx)(Bd,{label:`Choose subscription (all subscriptions by default)`,onChange:e=>o(e.currentTarget.checked)}),a&&(0,I.jsx)(MI,{name:`subscription`,resourceType:`Subscription`,placeholder:`Subscription`,onChange:c}),(0,I.jsx)(yg,{label:`Interaction`,description:`The interaction type to resend (update by default)`,defaultValue:`update`,data:[{label:`Update`,value:`update`},{label:`Create`,value:`create`},{label:`Delete`,value:`delete`}],onChange:e=>u(e.currentTarget.value)}),(0,I.jsx)(Bd,{label:`Verbose mode`,onChange:e=>f(e.currentTarget.checked)}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{type:`submit`,children:`Resend`})})]})})})}function uQ(){let e=Q(),t=uk(),{resourceType:n,id:r}=QW(),i={reference:n+`/`+r},[a,o]=(0,b.useState)(),s=on(!1);function c(t,n){return e.updateResource({...t,priority:n})}function l(e,t){c(e,`stat`).then(t).catch(console.error)}function u(e,t){c(e,`routine`).then(t).catch(console.error)}function d(e){t(`/${e.resourceType}/${e.id}`)}function f(e){t(`/${e.resourceType}/${e.id}/edit`)}function p(e){t(`/${e.resourceType}/${e.id}/delete`)}function m(e){o(e),s[1].open()}function h(e){t(`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`)}function g(t,n){let r=`aws-textract`;J({id:r,title:`AWS Textract in Progress`,message:`Extracting text... This may take a moment...`,loading:!0,autoClose:!1}),e.post(e.fhirUrl(t.resourceType,t.id,`$aws-textract`),{}).then(()=>{n(),Ib({id:r,title:`AWS Textract Successful`,message:`Text successfully extracted.`,color:`green`,icon:(0,I.jsx)(WA,{size:`1rem`}),loading:!1,withCloseButton:!0})}).catch(e=>Ib({id:r,title:`AWS Textract Error`,color:`red`,message:Y(e),icon:(0,I.jsx)($j,{size:`1rem`}),loading:!1,withCloseButton:!0}))}function _(t){let{primaryResource:n,currentResource:r,reloadTimeline:i}=t,a=r.resourceType===n.resourceType&&r.id===n.id,o=r.resourceType===`Communication`&&r.priority!==`stat`,s=r.resourceType===`Communication`&&r.priority===`stat`,c=a,_=!a,v=!a,y=!a,b=e.getProjectMembership()?.admin,x=b,S=$X()&&(r.resourceType===`DocumentReference`||r.resourceType===`Media`);return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Label,{children:`Resource`}),o&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{size:14}),onClick:()=>l(r,i),"aria-label":`Pin ${aC(r)}`,children:`Pin`}),s&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>u(r,i),"aria-label":`Unpin ${aC(r)}`,children:`Unpin`}),_&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(gj,{size:14}),onClick:()=>d(r),"aria-label":`Details ${aC(r)}`,children:`Details`}),c&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(gj,{size:14}),onClick:()=>h(r),"aria-label":`Details ${aC(r)}`,children:`Details`}),v&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(ij,{size:14}),onClick:()=>f(r),"aria-label":`Edit ${aC(r)}`,children:`Edit`}),b&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Label,{children:`Admin`}),x&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Fj,{size:14}),onClick:()=>m(r),"aria-label":`Resend Subscriptions ${aC(r)}`,children:`Resend Subscriptions`})]}),S&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Label,{children:`AWS AI`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Jj,{size:14}),onClick:()=>g(r,i),"aria-label":`AWS Textract ${aC(r)}`,children:`AWS Textract`})]}),y&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Label,{children:`Danger zone`}),(0,I.jsx)(W.Item,{color:`red`,leftSection:(0,I.jsx)(Yj,{size:14}),onClick:()=>p(r),"aria-label":`Delete ${aC(r)}`,children:`Delete`})]})]})}return(0,I.jsxs)(I.Fragment,{children:[n===`Encounter`&&(0,I.jsx)(XL,{encounter:i,getMenu:_}),n===`Patient`&&(0,I.jsx)(Pz,{patient:i,getMenu:_}),n===`ServiceRequest`&&(0,I.jsx)(YK,{serviceRequest:i,getMenu:_}),n!==`Encounter`&&n!==`Patient`&&n!==`ServiceRequest`&&(0,I.jsx)(YL,{resource:i,getMenu:_}),(0,I.jsx)(lQ,{resource:a,opened:s[0],onClose:s[1].close},`resend-subscriptions-${a?.id}`)]})}function dQ(e){let{opened:t,close:n,version:r,loadingStatus:i,handleStatus:a,handleUpgrade:o}=e,[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{t&&(s||sk(`app-tools-page`).then(c).catch(console.error),a())},[t,s,a]),s&&r&&!i?r===`unknown`?(0,I.jsx)(`p`,{children:`Unable to determine the current version of the agent. Check the network connectivity of the agent.`}):r.startsWith(s)?(0,I.jsxs)(`p`,{children:[`This agent is already on the latest version (`,s,`).`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Are you sure you want to upgrade this agent from version `,r,` to version `,s,`?`]}),(0,I.jsxs)(V,{children:[(0,I.jsx)(U,{onClick:()=>{o(l),n()},"aria-label":`Confirm upgrade`,children:`Confirm Upgrade`}),(0,I.jsx)(Bd,{label:`Force`,onChange:e=>u(e.currentTarget.checked)})]})]}):(0,I.jsx)(nM,{})}var fQ=[`live`,`ping`,`hl7ConnectionsOpen`,`hl7ClientCount`,`hl7QueueDepth`,`webSocketQueueDepth`,`outstandingHeartbeats`];function pQ(e){return e==null?``:typeof e==`object`?JSON.stringify(e):typeof e==`number`?e.toLocaleString():e.toString()}function mQ(e){let t=Object.keys(e.entries).filter(t=>e.entries[t]?.rtt);return t.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(q,{order:3,mt:`md`,children:e.title}),(0,I.jsxs)(K,{children:[(0,I.jsx)(K.Thead,{children:(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Th,{children:`Name`}),(0,I.jsx)(K.Th,{children:`Count`}),(0,I.jsx)(K.Th,{children:`Pending`}),(0,I.jsx)(K.Th,{children:`Min (ms)`}),(0,I.jsx)(K.Th,{children:`Avg (ms)`}),(0,I.jsx)(K.Th,{children:`Max (ms)`}),(0,I.jsx)(K.Th,{children:`p50 (ms)`}),(0,I.jsx)(K.Th,{children:`p95 (ms)`}),(0,I.jsx)(K.Th,{children:`p99 (ms)`})]})}),(0,I.jsx)(K.Tbody,{children:t.map(t=>{let n=e.entries[t].rtt;return(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:t}),(0,I.jsx)(K.Td,{children:n.count}),(0,I.jsx)(K.Td,{children:n.pendingCount}),(0,I.jsx)(K.Td,{children:n.min}),(0,I.jsx)(K.Td,{children:n.average}),(0,I.jsx)(K.Td,{children:n.max}),(0,I.jsx)(K.Td,{children:n.p50}),(0,I.jsx)(K.Td,{children:n.p95}),(0,I.jsx)(K.Td,{children:n.p99})]},t)})})]})]}):null}function hQ(e){let{stats:t}=e,n=new Set([...fQ,`channelStats`,`clientStats`]),r=Object.entries(t).filter(([e])=>!n.has(e));return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(K,{mt:`sm`,children:(0,I.jsxs)(K.Tbody,{children:[fQ.map(e=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:e}),(0,I.jsx)(K.Td,{children:pQ(t[e])})]},e)),r.map(([e,t])=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:e}),(0,I.jsx)(K.Td,{children:pQ(t)})]},e))]})}),(0,I.jsx)(mQ,{title:`Channel Stats`,entries:t.channelStats}),(0,I.jsx)(mQ,{title:`Client Stats`,entries:t.clientStats})]})}function gQ(){let e=Q(),{id:t}=QW(),n=(0,b.useMemo)(()=>({reference:`Agent/`+t}),[t]),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),[p,m]=(0,b.useState)(),[h,g]=(0,b.useState)(),[_,v]=(0,b.useState)(),[y,x]=(0,b.useState)(),[S,C]=(0,b.useState)(!1),[w,T]=(0,b.useState)(),[E,D]=(0,b.useState)(!1),[O,k]=(0,b.useState)(),[A,j]=(0,b.useState)(20),[M,ee]=(0,b.useState)(),[N,{open:P,close:te}]=on(!1),ne=r||a||s||S||l||d,re=(0,b.useCallback)(()=>{i(!0),e.get(e.fhirUrl(`Agent`,t,`$status`),{cache:`reload`}).then(e=>{m(e.parameter?.find(e=>e.name===`status`)?.valueCode),g(e.parameter?.find(e=>e.name===`version`)?.valueString),v(e.parameter?.find(e=>e.name===`lastUpdated`)?.valueInstant)}).catch(e=>fe(Y(e))).finally(()=>i(!1))},[e,t]),ie=(0,b.useCallback)(t=>{let r=t.host,i=t.pingCount||1;r&&(C(!0),e.pushToAgent(n,r,`PING ${i}`,ZE.PING,!0).then(e=>x(e)).catch(e=>fe(Y(e))).finally(()=>C(!1)))},[e,n]),ae=(0,b.useCallback)(()=>{o(!0),e.get(e.fhirUrl(`Agent`,t,`$reload-config`),{cache:`reload`}).then(e=>{de(`Agent config reloaded successfully.`)}).catch(e=>fe(Y(e))).finally(()=>o(!1))},[e,t]),oe=(0,b.useCallback)(n=>{c(!0);let r=e.fhirUrl(`Agent`,t,`$upgrade`);r.searchParams.set(`force`,String(n)),e.get(r,{cache:`reload`}).then(e=>{de(`Agent upgraded successfully.`)}).catch(e=>fe(Y(e))).finally(()=>c(!1))},[e,t]),se=(0,b.useCallback)((n,r)=>{u(!0);let i=e.fhirUrl(`Agent`,t,`$fetch-logs`);i.searchParams.set(`limit`,String(n)),r&&i.searchParams.set(`before`,r),e.get(i,{cache:`reload`}).then(e=>{let t=e?.parameter?.find(e=>e.name===`logs`)?.valueString,n=e?.parameter?.find(e=>e.name===`hasMore`)?.valueBoolean??!1,i=e?.parameter?.find(e=>e.name===`nextBefore`)?.valueString;T(e=>r&&e?t?`${e}\n${t}`:e:t),D(n),k(i)}).catch(e=>fe(Y(e))).finally(()=>u(!1))},[e,t]),ce=(0,b.useCallback)(e=>{let t=Number(e.logLimit)||20;j(t),se(t)},[se]),le=(0,b.useCallback)(()=>{se(A,O)},[se,A,O]),ue=(0,b.useCallback)(()=>{f(!0),e.get(e.fhirUrl(`Agent`,t,`$stats`),{cache:`reload`}).then(e=>{let t=e.parameter?.find(e=>e.name===`stats`)?.valueString;if(t)try{ee(JSON.parse(t))}catch(e){fe(Y(e))}}).catch(e=>fe(Y(e))).finally(()=>f(!1))},[e,t]);function de(e){J({color:`green`,title:`Success`,icon:(0,I.jsx)(WA,{size:`1rem`}),message:e})}function fe(e){J({color:`red`,title:`Error`,message:e,autoClose:!1})}return(0,I.jsxs)(VP,{children:[(0,I.jsx)(Bh,{opened:N,onClose:te,title:`Upgrade Agent`,centered:!0,children:(0,I.jsx)(dQ,{opened:N,close:te,version:h,loadingStatus:r,handleStatus:re,handleUpgrade:oe})}),(0,I.jsx)(q,{order:1,children:`Agent Tools`}),(0,I.jsxs)(`div`,{style:{marginBottom:10},children:[`Agent: `,(0,I.jsx)(oL,{value:n,link:!0})]}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsx)(q,{order:2,children:`Agent Status`}),(0,I.jsx)(`p`,{children:`Retrieve the status of the agent. This tests whether the agent is connected to the Medplum server, and the last time it was able to communicate.`}),(0,I.jsx)(U,{onClick:re,loading:r,disabled:ne&&!r,children:`Get Status`}),!r&&p&&(0,I.jsx)(K,{children:(0,I.jsxs)(K.Tbody,{children:[(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:`Status`}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(lL,{status:p})})]}),(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:`Version`}),(0,I.jsx)(K.Td,{children:h})]}),(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:`Last Updated`}),(0,I.jsx)(K.Td,{children:dw(_,void 0,{timeZoneName:`longOffset`})})]})]})}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsx)(q,{order:2,children:`Reload Config`}),(0,I.jsx)(`p`,{children:`Reload the configuration of this agent, syncing it with the current version of the Agent resource on the Medplum server.`}),(0,I.jsx)(U,{onClick:ae,loading:a,disabled:ne&&!a,"aria-label":`Reload config`,children:`Reload Config`}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsx)(q,{order:2,children:`Upgrade Agent`}),(0,I.jsx)(`p`,{children:`Upgrade the version of this agent, to either the latest (default) or a specified version.`}),(0,I.jsx)(U,{onClick:P,loading:s,disabled:ne&&!s,"aria-label":`Upgrade agent`,children:`Upgrade`}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsxs)(WN,{onSubmit:ce,children:[(0,I.jsx)(q,{order:2,children:`Fetch Logs`}),(0,I.jsx)(`p`,{children:`Fetch logs from the agent.`}),w?.length?(0,I.jsx)(Xd,{block:!0,mb:15,children:w}):null,(0,I.jsxs)(V,{children:[(0,I.jsx)(D_,{w:100,id:`logLimit`,name:`logLimit`,placeholder:`20`,label:`Log Limit`}),(0,I.jsx)(U,{mt:22,loading:l,disabled:ne&&!l,"aria-label":`Fetch logs`,type:`submit`,children:`Fetch Logs`}),E?(0,I.jsx)(U,{mt:22,type:`button`,variant:`default`,onClick:le,loading:l,disabled:ne&&!l,"aria-label":`Load more logs`,children:`Load More`}):null]})]}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsx)(q,{order:2,children:`Agent Stats`}),(0,I.jsx)(`p`,{children:`Fetch runtime statistics from the agent, including connection counts, queue depths, RTT metrics, and overall agent health.`}),(0,I.jsx)(U,{onClick:ue,loading:d,disabled:ne&&!d,"aria-label":`Get stats`,children:`Get Stats`}),!d&&M&&(0,I.jsx)(hQ,{stats:M}),(0,I.jsx)(bp,{my:`lg`}),(0,I.jsx)(q,{order:2,children:`Ping from Agent`}),(0,I.jsx)(`p`,{children:`Send a ping command from the agent to a valid IP address or hostname. Use this tool to troubleshoot local network connectivity.`}),(0,I.jsx)(WN,{onSubmit:ie,children:(0,I.jsxs)(V,{children:[(0,I.jsx)(yb,{id:`host`,name:`host`,placeholder:`ex. 127.0.0.1`,label:`IP Address / Hostname`,rightSection:(0,I.jsx)(vl,{size:24,radius:`xl`,variant:`filled`,type:`submit`,"aria-label":`Ping`,loading:S,disabled:ne&&!S,children:(0,I.jsx)(Lj,{style:{width:`1rem`,height:`1rem`},stroke:1.5})})}),(0,I.jsx)(D_,{id:`pingCount`,name:`pingCount`,placeholder:`1`,label:`Ping Count`})]})}),!S&&y&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(q,{order:5,mt:`sm`,mb:0,children:`Last Ping`}),(0,I.jsx)(`pre`,{children:y})]})]})}function _Q(){let e=Q(),{id:t}=QW(),n=bk({reference:`User/${t}`}),[r,i]=(0,b.useState)(``),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1);if(!n)return null;if(!n.project)return(0,I.jsx)(VP,{children:(0,I.jsx)(ou,{color:`yellow`,children:`Update Email is only available for project-scoped Users.`})});function d(){if(!r)return;u(!0);let n={resourceType:`Parameters`,parameter:[{name:`email`,valueString:r}]};a&&n.parameter?.push({name:`updateProfileTelecom`,valueBoolean:!0}),s&&n.parameter?.push({name:`skipEmailVerification`,valueBoolean:!0}),e.post(e.fhirUrl(`User`,t,`$update-email`),n).then(()=>{J({color:`green`,message:`Email updated successfully`}),i(``)}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})}).finally(()=>u(!1))}return(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{order:1,children:`Update Email`}),(0,I.jsxs)(`p`,{children:[`Update the email address for this User. The current email is `,(0,I.jsx)(`strong`,{children:n.email}),`.`]}),(0,I.jsx)(`form`,{onSubmit:e=>{e.preventDefault(),d()},children:(0,I.jsxs)(G,{children:[(0,I.jsx)(yb,{label:`New Email`,type:`email`,required:!0,placeholder:`new@example.com`,value:r,onChange:e=>i(e.currentTarget.value)}),(0,I.jsx)(Bd,{label:`Update profile telecom`,description:`Add the new email to the associated profile resource's telecom and mark the old email as old`,checked:a,onChange:e=>o(e.currentTarget.checked)}),(0,I.jsx)(Bd,{label:`Skip email verification`,description:`Do not send a verification email to the new address`,checked:s,onChange:e=>c(e.currentTarget.checked)}),(0,I.jsx)(`div`,{children:(0,I.jsx)(U,{type:`submit`,loading:l,disabled:!r,children:`Update Email`})})]})})]})}function vQ(){let e=JW(),t=Q(),[n,r]=(0,b.useState)();(0,b.useEffect)(()=>{t.get(`auth/me`,{cache:`no-cache`}).then(r).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))},[t]);function i(e){t.post(`auth/revoke`,{loginId:e}).then(()=>t.get(`auth/me`,{cache:`no-cache`})).then(r).then(()=>J({color:`green`,message:`Login revoked`})).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))}return n?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Security`}),(0,I.jsxs)(jP,{children:[(0,I.jsx)(MP,{term:`ID`,children:(0,I.jsx)(pu,{href:`/${aC(n.profile)}`,children:n.profile.id})}),(0,I.jsx)(MP,{term:`Resource Type`,children:n.profile.resourceType}),(0,I.jsx)(MP,{term:`Name`,children:cw(n.profile.name?.[0])})]})]}),(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Sessions`}),(0,I.jsxs)(K,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`OS`}),(0,I.jsx)(`th`,{children:`Browser`}),(0,I.jsx)(`th`,{children:`IP Address`}),(0,I.jsx)(`th`,{children:`Auth Method`}),(0,I.jsx)(`th`,{children:`Last Updated`}),(0,I.jsx)(`th`,{})]})}),(0,I.jsx)(`tbody`,{children:n.security.sessions.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:e.os}),(0,I.jsx)(`td`,{children:e.browser}),(0,I.jsx)(`td`,{children:e.remoteAddress}),(0,I.jsx)(`td`,{children:e.authMethod}),(0,I.jsx)(`td`,{children:dw(e.lastUpdated)}),(0,I.jsx)(`td`,{children:(0,I.jsx)(pu,{href:`#`,onClick:()=>i(e.id),children:`Revoke`})})]},e.id))})]})]}),(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Password`}),(0,I.jsx)(U,{onClick:()=>e(`/changepassword`)?.catch(console.error),children:`Change password`})]}),(0,I.jsxs)(VP,{children:[(0,I.jsx)(q,{children:`Multi Factor Auth`}),(0,I.jsxs)(`p`,{children:[`Enrolled: `,n.security.mfaEnrolled.toString()]}),(0,I.jsx)(U,{onClick:()=>e(`/mfa`)?.catch(console.error),children:n.security.mfaEnrolled?`Manage MFA`:`Enroll`})]})]}):null}function yQ(){let{id:e,secret:t}=QW(),n=JW();return(0,I.jsx)(yF,{id:e,secret:t,onSignIn:()=>n(`/signin`)?.catch(console.error)})}function bQ(){let e=dk(),t=JW(),[n]=LK(),r=ZX(),i=(0,b.useCallback)(()=>{let e=n.get(`next`);t(e?.startsWith(`/`)?e:`/`)?.catch(console.error)},[n,t]);return(0,b.useEffect)(()=>{e&&n.has(`next`)&&i()},[e,n,i]),(0,I.jsxs)(TF,{onSuccess:()=>i(),onForgotPassword:()=>t(`/resetpassword`)?.catch(console.error),onRegister:QX()?()=>t(`/register`)?.catch(console.error):void 0,googleClientId:r.googleClientId,login:n.get(`login`)||void 0,projectId:n.get(`project`)||void 0,children:[(0,I.jsx)(HP,{size:32}),n.get(`project`)!==`new`&&(0,I.jsxs)(q,{order:3,py:`lg`,ta:`center`,children:[`Sign in to `,SM()]}),n.get(`project`)===`new`&&(0,I.jsx)(q,{order:3,py:`lg`,ta:`center`,children:`Sign in again to create a new project`})]})}function xQ(){let e=JW(),t=GW(),[n,r]=(0,b.useState)(),[i,a]=(0,b.useState)(),[o,s]=(0,b.useState)();return(0,b.useEffect)(()=>{let e=Object.fromEntries(new URLSearchParams(t.search).entries());r(e.resourceType),a(e.query),s(JSON.parse(e.fields))},[t]),!n||!i||!o?null:(0,I.jsx)(cz,{resourceType:n,checkboxesEnabled:!0,query:i,fields:o,onClick:t=>e(`/${n}/${t.resource.id}`)?.catch(console.error),onAuxClick:e=>window.open(`/${n}/${e.resource.id}`,`_blank`),onBulk:t=>{e(`/bulk/${n}?ids=${t.join(`,`)}`)?.catch(console.error)}})}function SQ(){let{id:e,secret:t}=QW(),n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1);return(0,I.jsxs)(VP,{width:450,children:[(0,I.jsx)(lF,{issues:WP(r,void 0)}),(0,I.jsxs)(WN,{onSubmit:async()=>{i(void 0);try{let r=Gx(await n.post(`auth/verifyemail`,{id:e,secret:t}));r?LE.assign(r):o(!0)}catch(e){i(Zx(e))}},children:[(0,I.jsxs)(ru,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(HP,{size:32}),(0,I.jsx)(q,{children:`Email address verification required`})]}),!a&&(0,I.jsxs)(G,{children:[(0,I.jsx)(`p`,{children:`In order to sign in, click the button below to verify your ability to receive email at the address this link was sent to.`}),(0,I.jsx)(V,{justify:`center`,mt:`xl`,children:(0,I.jsx)(GN,{children:`Verify email`})})]}),a&&(0,I.jsxs)(`div`,{"data-testid":`success`,children:[`Email verified. You can now\xA0`,(0,I.jsx)(dM,{to:`/signin`,children:`sign in`}),`.`]})]})]})}function CQ(){return(0,I.jsx)(IG,{children:(0,I.jsxs)($,{errorElement:(0,I.jsx)(AX,{}),children:[(0,I.jsx)($,{path:`/signin`,element:(0,I.jsx)(bQ,{})}),(0,I.jsx)($,{path:`/oauth`,element:(0,I.jsx)(tZ,{})}),(0,I.jsx)($,{path:`/resetpassword`,element:(0,I.jsx)(rZ,{})}),(0,I.jsx)($,{path:`/setpassword/:id/:secret`,element:(0,I.jsx)(yQ,{})}),(0,I.jsx)($,{path:`/verifyemail/:id/:secret`,element:(0,I.jsx)(SQ,{})}),(0,I.jsx)($,{path:`/register`,element:(0,I.jsx)(nZ,{})}),(0,I.jsx)($,{path:`/changepassword`,element:(0,I.jsx)(DX,{})}),(0,I.jsx)($,{path:`/security`,element:(0,I.jsx)(vQ,{})}),(0,I.jsx)($,{path:`/mfa`,element:(0,I.jsx)(YX,{})}),(0,I.jsx)($,{path:`/batch`,element:(0,I.jsx)(TX,{})}),(0,I.jsx)($,{path:`/bulk/:resourceType`,element:(0,I.jsx)(EX,{})}),(0,I.jsx)($,{path:`/smart`,element:(0,I.jsx)(xQ,{})}),(0,I.jsx)($,{path:`/forms/:id`,element:(0,I.jsx)(MX,{})}),(0,I.jsx)($,{path:`/admin/super`,element:(0,I.jsx)(wJ,{})}),(0,I.jsx)($,{path:`/admin/super/asyncjob/:tab`,element:(0,I.jsx)(uJ,{})}),(0,I.jsx)($,{path:`/admin/super/asyncjob`,element:(0,I.jsx)(uJ,{})}),(0,I.jsx)($,{path:`/admin/super/db/:tab`,element:(0,I.jsx)(Fq,{})}),(0,I.jsx)($,{path:`/admin/super/db`,element:(0,I.jsx)(Fq,{})}),(0,I.jsx)($,{path:`/admin/config`,element:(0,I.jsx)(Hq,{})}),(0,I.jsxs)($,{path:`/admin`,element:(0,I.jsx)(Gq,{}),children:[(0,I.jsx)($,{path:`bots/:membershipId`,element:(0,I.jsx)(Rq,{})}),(0,I.jsx)($,{path:`bots/new`,element:(0,I.jsx)(cq,{})}),(0,I.jsx)($,{path:`bots`,element:(0,I.jsx)(aq,{})}),(0,I.jsx)($,{path:`clients/:membershipId`,element:(0,I.jsx)(Rq,{})}),(0,I.jsx)($,{path:`clients/new`,element:(0,I.jsx)(lq,{})}),(0,I.jsx)($,{path:`clients`,element:(0,I.jsx)(oq,{})}),(0,I.jsx)($,{path:`details`,element:(0,I.jsx)(Uq,{})}),(0,I.jsx)($,{path:`invite`,element:(0,I.jsx)(Iq,{})}),(0,I.jsx)($,{path:`patients`,element:(0,I.jsx)(NG,{to:`/admin/users`,replace:!0})}),(0,I.jsx)($,{path:`users/:membershipId`,element:(0,I.jsx)(Rq,{})}),(0,I.jsx)($,{path:`users`,element:(0,I.jsx)(kJ,{})}),(0,I.jsx)($,{path:`project`,element:(0,I.jsx)(Uq,{})}),(0,I.jsx)($,{path:`secrets`,element:(0,I.jsx)(oJ,{})}),(0,I.jsx)($,{path:`settings`,element:(0,I.jsx)(sJ,{})}),(0,I.jsx)($,{path:`sites`,element:(0,I.jsx)(cJ,{})}),(0,I.jsx)($,{path:`rate-limits`,element:(0,I.jsx)(nJ,{})})]}),(0,I.jsx)($,{path:`/lab/assays`,element:(0,I.jsx)(WX,{})}),(0,I.jsx)($,{path:`/lab/panels`,element:(0,I.jsx)(qX,{})}),(0,I.jsxs)($,{path:`/:resourceType/new`,element:(0,I.jsx)(kX,{}),children:[(0,I.jsx)($,{index:!0,element:(0,I.jsx)(kZ,{})}),(0,I.jsx)($,{path:`form`,element:(0,I.jsx)(kZ,{})}),(0,I.jsx)($,{path:`json`,element:(0,I.jsx)(jZ,{})}),(0,I.jsx)($,{path:`profiles`,element:(0,I.jsx)(kZ,{})})]}),(0,I.jsxs)($,{path:`/:resourceType/:id`,element:(0,I.jsx)(oQ,{}),children:[(0,I.jsx)($,{index:!0,element:(0,I.jsx)(uQ,{})}),(0,I.jsx)($,{path:`apply`,element:(0,I.jsx)(oZ,{})}),(0,I.jsx)($,{path:`apps`,element:(0,I.jsx)(sZ,{})}),(0,I.jsx)($,{path:`event`,element:(0,I.jsx)(lZ,{})}),(0,I.jsx)($,{path:`blame`,element:(0,I.jsx)(uZ,{})}),(0,I.jsx)($,{path:`bots`,element:(0,I.jsx)(UZ,{})}),(0,I.jsx)($,{path:`builder`,element:(0,I.jsx)(yZ,{})}),(0,I.jsx)($,{path:`checklist`,element:(0,I.jsx)(bZ,{})}),(0,I.jsx)($,{path:`delete`,element:(0,I.jsx)(SZ,{})}),(0,I.jsx)($,{path:`details`,element:(0,I.jsx)(wZ,{})}),(0,I.jsx)($,{path:`edit`,element:(0,I.jsx)(TZ,{})}),(0,I.jsx)($,{path:`editor`,element:(0,I.jsx)(gZ,{})}),(0,I.jsxs)($,{path:`history`,children:[(0,I.jsx)($,{index:!0,element:(0,I.jsx)(AZ,{})}),(0,I.jsx)($,{path:`:versionId/:tab`,element:(0,I.jsx)(sQ,{})}),(0,I.jsx)($,{path:`:versionId`,element:(0,I.jsx)(sQ,{})})]}),(0,I.jsxs)($,{path:`_history`,children:[(0,I.jsx)($,{index:!0,element:(0,I.jsx)(AZ,{})}),(0,I.jsx)($,{path:`:versionId/:tab`,element:(0,I.jsx)(sQ,{})}),(0,I.jsx)($,{path:`:versionId`,element:(0,I.jsx)(sQ,{})})]}),(0,I.jsx)($,{path:`json`,element:(0,I.jsx)(MZ,{})}),(0,I.jsx)($,{path:`preview`,element:(0,I.jsx)(RZ,{})}),(0,I.jsx)($,{path:`responses`,element:(0,I.jsx)(GZ,{})}),(0,I.jsx)($,{path:`report`,element:(0,I.jsx)(qZ,{})}),(0,I.jsx)($,{path:`ranges`,element:(0,I.jsx)(KZ,{})}),(0,I.jsx)($,{path:`subscriptions`,element:(0,I.jsx)(cQ,{})}),(0,I.jsx)($,{path:`timeline`,element:(0,I.jsx)(uQ,{})}),(0,I.jsx)($,{path:`tools`,element:(0,I.jsx)(gQ,{})}),(0,I.jsx)($,{path:`email`,element:(0,I.jsx)(_Q,{})}),(0,I.jsx)($,{path:`payload`,element:(0,I.jsx)(xZ,{})}),(0,I.jsx)($,{path:`profiles`,element:(0,I.jsx)(zZ,{})}),(0,I.jsx)($,{path:`accounts`,element:(0,I.jsx)(iZ,{})}),(0,I.jsx)($,{path:`export`,element:(0,I.jsx)(EZ,{})})]}),(0,I.jsx)($,{path:`/:resourceType`,element:(0,I.jsx)(UX,{})}),(0,I.jsx)($,{path:`/`,element:(0,I.jsx)(UX,{})})]})})}function wQ(){let e=Q(),t=e.getUserConfiguration(),n=e.getProject(),r=GW(),[i]=LK();return e.isLoading()?(0,I.jsx)(nM,{}):(0,I.jsxs)(CP,{logo:(0,I.jsx)(HP,{size:24}),pathname:r.pathname,searchParams:i,version:BD,menus:TQ(t),displayAddBookmark:!!t?.id,announcements:n?.superAdmin?[{message:(0,I.jsxs)(I.Fragment,{children:[`Warning: logged in as`,` `,(0,I.jsx)(kK,{to:`https://www.medplum.com/docs/self-hosting/super-admin-guide`,children:`Medplum Super Admin`}),`.`]}),color:`red`,icon:(0,I.jsx)(AA,{size:16}),role:`alert`}]:void 0,children:[(0,I.jsx)(JK,{}),(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(nM,{}),children:(0,I.jsx)(CQ,{})})]})}function TQ(e){let t=e?.menu?.map(e=>({title:e.title,links:e.link?.map(e=>({label:e.name,href:e.target,icon:DQ(e.target)}))||[]}))||[];return t.push({title:`Settings`,links:[{label:`Security`,href:`/security`,icon:(0,I.jsx)(vj,{})}]}),t}var EQ={Patient:Uj,Practitioner:mj,Organization:HA,ServiceRequest:Nj,DiagnosticReport:Ij,Questionnaire:pj,Project:fj,admin:RA,AccessPolicy:_j,Subscription:Qj,batch:Ej,Observation:Cj};function DQ(e){if(e.includes(`admin/super/db`))return(0,I.jsx)(ej,{});try{let t=new URL(e,`https://app.medplum.com`).pathname.split(`/`)[1];if(t in EQ){let e=EQ[t];return(0,I.jsx)(e,{})}}catch{}}async function OQ(){let e=ZX(),t=new $D({baseUrl:e.baseUrl,clientId:e.clientId,storagePrefix:`@medplum:`,cacheTime:6e4,autoBatchTime:100,onUnauthenticated:()=>{window.location.pathname!==`/signin`&&window.location.pathname!==`/oauth`&&(window.location.href=`/signin?next=`+encodeURIComponent(window.location.pathname+window.location.search))}}),n=Hr({headings:{sizes:{h1:{fontSize:`1.125rem`,fontWeight:`500`,lineHeight:`2.0`}}},fontSizes:{xs:`0.6875rem`,sm:`0.875rem`,md:`0.875rem`,lg:`1.0rem`,xl:`1.125rem`}}),r=TK([{path:`*`,element:(0,I.jsx)(wQ,{})}]);(0,eq.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(b.StrictMode,{children:(0,I.jsx)(pk,{medplum:t,navigate:e=>r.navigate(e),children:(0,I.jsxs)(yr,{theme:n,children:[(0,I.jsx)(xx,{position:`bottom-right`}),(0,I.jsx)(kG,{router:r})]})})}))}OQ().catch(console.error);export{o as t};
|
|
238
|
-
//# sourceMappingURL=index-
|
|
238
|
+
//# sourceMappingURL=index-1nVihVx3.js.map
|