@medplum/app 5.1.29 → 5.1.30
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-Gwv7hBLa.js → index-DFJPfvpQ.js} +7 -7
- package/dist/assets/index-DFJPfvpQ.js.map +1 -0
- package/dist/assets/{jsQR-KuOuxaXA.js → jsQR-CGGgbypu.js} +2 -2
- package/dist/assets/{jsQR-KuOuxaXA.js.map → jsQR-CGGgbypu.js.map} +1 -1
- package/dist/index.html +2 -2
- package/package.json +8 -8
- package/dist/assets/index-Gwv7hBLa.js.map +0 -1
|
@@ -50,10 +50,10 @@ ${o?`${s(`light`)}{${o}}`:``}`}function Dr({color:e,theme:t,autoContrast:n}){ret
|
|
|
50
50
|
Prefix can't start with '-' when allowNegative is true.
|
|
51
51
|
prefix: `+i+`
|
|
52
52
|
allowNegative: `+a+`
|
|
53
|
-
`),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}function g_(e){e=h_(e),e.decimalSeparator,e.allowedDecimalSeparators,e.thousandsGroupStyle;var t=e.suffix,n=e.allowNegative,r=e.allowLeadingZeros,i=e.onKeyDown;i===void 0&&(i=jg);var a=e.onBlur;a===void 0&&(a=jg);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=kg(e,[`decimalSeparator`,`allowedDecimalSeparators`,`thousandsGroupStyle`,`suffix`,`allowNegative`,`allowLeadingZeros`,`onKeyDown`,`onBlur`,`thousandSeparator`,`decimalScale`,`fixedDecimalScale`,`prefix`,`defaultValue`,`value`,`valueIsNumericString`,`onValueChange`]),h=l_(e),g=h.decimalSeparator,_=h.allowedDecimalSeparators,v=function(t){return c_(t,e)},y=function(t,n){return p_(t,n,e)},b=Pg(d)?u:d,x=f??f_(b,l,t);Pg(d)?Pg(u)||(x||=typeof u==`number`):x||=typeof d==`number`;var S=function(e){return Ig(e)?e:(typeof e==`number`&&(e=Gg(e)),x&&typeof s==`number`?Kg(e,s,!!c):e)},C=i_(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||Ng(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=Jg(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 m_(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&&qg(t,1),s&&c&&(r===`Backspace`&&d[a-1]===g?(qg(t,a-1),e.preventDefault()):r===`Delete`&&d[a]===g&&e.preventDefault()),_?.includes(r)&&d[a]===g&&qg(t,a+1);var f=o===!0?`,`:o;r===`Backspace`&&d[a-1]===f&&qg(t,a-1),r===`Delete`&&d[a]===f&&qg(t,a+1),i(e)},onBlur:function(t){var n=T;n.match(/\d/g)||(n=``),r||(n=Hg(n)),c&&s&&(n=Kg(n,s,c)),n!==T&&D({formattedValue:c_(n,e),value:n,floatValue:parseFloat(n)},{event:t,source:Ag.event}),a(t)}})}function __(e){var t=g_(e);return b.createElement(s_,Object.assign({},t))}var v_={root:`m_e2f5cd4e`,controls:`m_95e17d22`,control:`m_80b4b171`};function y_({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 b_=/^(0\.0*|-0(\.0*)?)$/,x_=/^-?0\d+(\.\d+)?\.?$/,S_=/\.\d*0$/,C_=/^-?\d+\.$/;function w_(e){return typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))}function T_(e){return typeof e==`number`?e<2**53-1:e===``||w_(e)&&Number(e)<2**53-1}function E_(e){return e.toString().replace(`.`,``).length}function D_(e,t){return(typeof e==`number`?e<2**53-1:!Number.isNaN(Number(e)))&&!Number.isNaN(e)&&E_(t)<14&&t!==``}function O_(e,t,n){return e===void 0||(t===void 0||e>=t)&&(n===void 0||e<=n)}var k_={step:1,clampBehavior:`blur`,allowDecimal:!0,allowNegative:!0,withKeyboardEvents:!0,allowLeadingZeros:!0,trimLeadingZeroesOnBlur:!0,startValue:0,allowedDecimalSeparators:[`.`,`,`]},A_=An((e,{size:t})=>({controls:{"--ni-chevron-size":ft(t,`ni-chevron-size`)}}));function j_(e,t,n){let r=e.toString(),i=C_.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=Ct(o,n,t);return i?`${s.toString().replace(/^0+(?=\d)/,``)}.`:s}var M_=B((e,t)=>{let n=R(`NumberInput`,k_,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:v_,props:n,classNames:i,styles:a,unstyled:o,attributes:ie,vars:s,varsResolver:A_}),{resolvedClassNames:se,resolvedStyles:ce}=Hr({classNames:i,styles:a,props:n}),[le,ue]=an({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(D_(e.floatValue,e.value)&&!b_.test(e.value)&&!(P&&x_.test(e.value))&&!S_.test(e.value)&&!C_.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)(ut);ve.current=()=>{if(!T_(le))return;let e,t=ge(le),n=ge(m),r=Math.max(t,n),i=10**r;if(!w_(le)&&(typeof le!=`number`||Number.isNaN(le)))e=Ct(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)(ut);ye.current=()=>{if(!T_(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(!w_(le)&&typeof le!=`number`||Number.isNaN(le))e=Ct(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=Ct(t,p,f)),ne&&typeof t==`string`&&ge(t)<15&&(t=j_(t,f,p)),le!==t&&ue(t),y?.(e)};tn(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)(fl,{...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)(y_,{direction:`up`})}),(0,I.jsx)(fl,{...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)(y_,{direction:`down`})})]});return(0,I.jsx)(fd,{component:__,allowNegative:k,className:Mn(v_.root,r),size:j,inputMode:`decimal`,...ae,readOnly:A,disabled:D,value:le,getInputRef:rn(t,fe),onValueChange:he,rightSection:h||A||!T_(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)&&O_(e.floatValue,p,f):O_(e.floatValue,p,f):!_||_(e)})});M_.classes={...fd.classes,...v_},M_.displayName=`@mantine/core/NumberInput`;var N_={root:`m_4addd315`,control:`m_326d024a`,dots:`m_4ad7767d`},[P_,F_]=et(`Pagination.Root component was not found in tree`),I_={withPadding:!0},L_=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`,I_,e),f=F_(),p=c||f.disabled;return(0,I.jsx)(fl,{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})});L_.classes=N_,L_.displayName=`@mantine/core/PaginationControl`;function R_({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 z_=e=>(0,I.jsx)(R_,{...e,path:`M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z`}),B_=e=>(0,I.jsx)(R_,{...e,path:`M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z`}),V_=e=>(0,I.jsx)(R_,{...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`}),H_=e=>(0,I.jsx)(R_,{...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`}),U_={icon:e=>(0,I.jsx)(R_,{...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`})},W_=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,icon:s,...c}=R(`PaginationDots`,U_,e),l=F_();return(0,I.jsx)(z,{ref:t,...l.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)`}})})});W_.classes=N_,W_.displayName=`@mantine/core/PaginationDots`;function G_({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=F_(),l=r===`next`?c.active===c.total:c.active===1;return(0,I.jsx)(L_,{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}`,Li(a)}var K_=G_({icon:z_,name:`PaginationNext`,action:`onNext`,type:`next`}),q_=G_({icon:B_,name:`PaginationPrevious`,action:`onPrevious`,type:`previous`}),J_=G_({icon:V_,name:`PaginationFirst`,action:`onFirst`,type:`previous`}),Y_=G_({icon:H_,name:`PaginationLast`,action:`onLast`,type:`next`});function X_({dotsIcon:e}){let t=F_(),n=t.range.map((n,r)=>n===`dots`?(0,I.jsx)(W_,{icon:e},r):(0,I.jsx)(L_,{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));return(0,I.jsx)(I.Fragment,{children:n})}X_.displayName=`@mantine/core/PaginationItems`;var Z_={siblings:1,boundaries:1},Q_=An((e,{size:t,radius:n,color:r,autoContrast:i})=>({root:{"--pagination-control-radius":n===void 0?void 0:mt(n),"--pagination-control-size":ft(t,`pagination-control-size`),"--pagination-control-fz":ht(t),"--pagination-active-bg":r?ar(r,e):void 0,"--pagination-active-color":ai(i,e)?Dr({color:r,theme:e,autoContrast:i}):void 0}})),$_=B((e,t)=>{let n=R(`PaginationRoot`,Z_,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:N_,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}=cn({page:u,initialPage:d,onChange:f,total:l,siblings:m,boundaries:h}),N=vt(v,k),P=vt(y,A),te=vt(b,M),ne=vt(x,ee);return(0,I.jsx)(P_,{value:{total:l,range:D,active:j,disabled:p,getItemProps:S,onChange:O,onNext:N,onPrevious:P,onFirst:te,onLast:ne,getStyles:E},children:(0,I.jsx)(z,{ref:t,...E(`root`),...T})})});$_.classes=N_,$_.displayName=`@mantine/core/PaginationRoot`;var ev={withControls:!0,withPages:!0,siblings:1,boundaries:1,gap:8},tv=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`,ev,e);return u<=0||f&&u===1?null:(0,I.jsx)($_,{ref:t,total:u,...m,children:(0,I.jsxs)(V,{gap:d,children:[n&&(0,I.jsx)(J_,{icon:c,...i?.(`first`)}),r&&(0,I.jsx)(q_,{icon:o,...i?.(`previous`)}),p&&(0,I.jsx)(X_,{dotsIcon:l}),r&&(0,I.jsx)(K_,{icon:a,...i?.(`next`)}),n&&(0,I.jsx)(Y_,{icon:s,...i?.(`last`)})]})})});tv.classes=N_,tv.displayName=`@mantine/core/Pagination`,tv.Root=$_,tv.Control=L_,tv.Dots=W_,tv.First=J_,tv.Last=Y_,tv.Next=K_,tv.Previous=q_,tv.Items=X_;var nv={root:`m_f61ca620`,input:`m_ccf8da4c`,innerInput:`m_f2d85dd2`,visibilityToggle:`m_b1072d44`},rv={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`})})},iv=An((e,{size:t})=>({root:{"--psi-icon-size":ft(t,`psi-icon-size`),"--psi-button-size":ft(t,`psi-button-size`)}})),av=B((e,t)=>{let n=R(`PasswordInput`,rv,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=$t(p),[ce,le]=an({value:A,defaultValue:j,finalValue:!1,onChange:M}),ue=()=>le(!ce),de=L({name:`PasswordInput`,classes:nv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:ae,vars:c,varsResolver:iv}),{resolvedClassNames:fe,resolvedStyles:pe}=Hr({classNames:r,styles:o,props:n}),{styleProps:me,rest:he}=fi(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)(mu,{...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)(ld.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)(ld,{component:`div`,error:u,leftSection:d,size:v,classNames:{...fe,input:Mn(nv.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`})})})});av.classes={...fd.classes,...nv},av.displayName=`@mantine/core/PasswordInput`;var ov={root:`m_db6d6462`,section:`m_2242eb65`,"stripes-animation":`m_81a374bd`,"stripes-animation-vertical":`m_e0fb7a86`,label:`m_91e40b74`},[sv,cv]=et(`Progress.Root component was not found in tree`),lv=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,...s}=R(`ProgressLabel`,null,e),c=cv();return(0,I.jsx)(z,{ref:t,...c.getStyles(`label`,{className:r,style:i,classNames:n,styles:a}),...s})});lv.classes=ov,lv.displayName=`@mantine/core/ProgressLabel`;var uv=An((e,{size:t,radius:n,transitionDuration:r})=>({root:{"--progress-size":ft(t,`progress-size`),"--progress-radius":n===void 0?void 0:mt(n),"--progress-transition-duration":typeof r==`number`?`${r}ms`:void 0}})),dv=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:ov,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:f,vars:c,varsResolver:uv});return(0,I.jsx)(sv,{value:{getStyles:h,autoContrast:l},children:(0,I.jsx)(z,{ref:t,mod:[{orientation:d},p],...h(`root`),...m})})});dv.classes=ov,dv.displayName=`@mantine/core/ProgressRoot`;var fv={withAria:!0},pv=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`,fv,e),m=cv(),h=Sr(),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":ar(l,h),"--progress-label-color":ai(m.autoContrast,h)?Dr({color:l,theme:h,autoContrast:m.autoContrast}):void 0}})});pv.classes=ov,pv.displayName=`@mantine/core/ProgressSection`;var mv=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}=Hr({classNames:i,styles:a,props:n});return(0,I.jsx)(dv,{ref:t,classNames:f,styles:p,vars:o,...d,children:(0,I.jsx)(pv,{value:r,color:s,striped:c,animated:l,"aria-label":u})})});mv.classes=ov,mv.displayName=`@mantine/core/Progress`,mv.Section=pv,mv.Root=dv,mv.Label=lv;var hv={root:`m_f3f1af94`,inner:`m_89c4f5e4`,icon:`m_f3ed6b2b`,radio:`m_8a3dbb89`,"radio--outline":`m_1bfe9d39`},[gv,_v]=tt(),[vv,yv]=tt(),bv={card:`m_9dc8ae12`},xv={withBorder:!0},Sv=An((e,{radius:t})=>({card:{"--card-radius":mt(t)}})),Cv=B((e,t)=>{let n=R(`RadioCard`,xv,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:bv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:Sv,rootSelector:`card`}),{dir:y}=Ji(),b=_v(),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)(vv,{value:{checked:x},children:(0,I.jsx)(fl,{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})})});Cv.displayName=`@mantine/core/RadioCard`,Cv.classes=bv;var wv=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=$t(c),[p,m]=an({value:n,defaultValue:r,finalValue:``,onChange:i});return(0,I.jsx)(gv,{value:{value:p,onChange:e=>!l&&m(typeof e==`string`?e:e.currentTarget.value),size:a,name:f,disabled:u},children:(0,I.jsx)(ld.Wrapper,{size:a,ref:t,...o,...d,labelElement:`div`,__staticSelector:`RadioGroup`,children:(0,I.jsx)(Zf,{role:`radiogroup`,children:s})})})});wv.classes=ld.Wrapper.classes,wv.displayName=`@mantine/core/RadioGroup`;function Tv({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 Ev={indicator:`m_717d7ff6`,icon:`m_3e4da632`,"indicator--outline":`m_2980836c`},Dv={icon:Tv},Ov=An((e,{radius:t,color:n,size:r,iconColor:i,variant:a,autoContrast:o})=>{let s=ir({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":ft(r,`radio-size`),"--radio-radius":t===void 0?void 0:mt(t),"--radio-color":a===`outline`?c:ar(n,e),"--radio-icon-size":ft(r,`radio-icon-size`),"--radio-icon-color":i?ar(i,e):ai(o,e)?Dr({color:n,theme:e,autoContrast:o}):void 0}}}),kv=B((e,t)=>{let n=R(`RadioIndicator`,Dv,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:Ev,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:v,vars:c,varsResolver:Ov,rootSelector:`indicator`}),x=yv(),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`)})})});kv.displayName=`@mantine/core/RadioIndicator`,kv.classes=Ev;var Av={labelPosition:`right`},jv=An((e,{size:t,radius:n,color:r,iconColor:i,variant:a,autoContrast:o})=>{let s=ir({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":ft(t,`radio-size`),"--radio-radius":n===void 0?void 0:mt(n),"--radio-color":a===`outline`?c:ar(r,e),"--radio-icon-color":i?ar(i,e):ai(o,e)?Dr({color:r,theme:e,autoContrast:o}):void 0,"--radio-icon-size":ft(t,`radio-icon-size`)}}}),Mv=B((e,t)=>{let n=R(`Radio`,Av,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=Tv,rootRef:x,iconColor:S,onChange:C,mod:w,attributes:T,checked:E,...D}=n,O=L({name:`Radio`,classes:hv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:T,vars:c,varsResolver:jv}),k=_v(),A=k?.size??u,j=n.size?u:A,{styleProps:M,rest:ee}=fi(D),N=$t(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)(Bf,{...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})]})})});Mv.classes=hv,Mv.displayName=`@mantine/core/Radio`,Mv.Group=wv,Mv.Card=Cv,Mv.Indicator=kv;var Nv={duration:100,transition:`fade`};function Pv(e,t){return{...Nv,...t,...e}}var Fv={tooltip:`m_1b3c8819`,arrow:`m_f898399f`};function Iv({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}=Sc({placement:t,middleware:[Ms({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=ba(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 Lv={refProp:`ref`,withinPortal:!0,offset:10,position:`right`,zIndex:lt(`popover`)},Rv=An((e,{radius:t,color:n})=>({tooltip:{"--tooltip-radius":t===void 0?void 0:mt(t),"--tooltip-bg":n?ar(n,e):void 0,"--tooltip-color":n?`var(--mantine-color-white)`:void 0}})),zv=B((e,t)=>{let n=R(`TooltipFloating`,Lv,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=Sr(),D=L({name:`TooltipFloating`,props:n,classes:Fv,className:s,style:o,classNames:c,styles:l,unstyled:u,attributes:w,rootSelector:`tooltip`,vars:S,varsResolver:Rv}),{handleMouseMove:O,x:k,y:A,opened:j,boundaryRef:M,floating:ee,setOpened:N}=Iv({offset:m,position:h,defaultOpened:y}),P=kn(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=rn(M,Tn(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)(Ml,{...C,withinPortal:a,children:(0,I.jsx)(z,{...T,...D(`tooltip`,{style:{...Ii(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})]})});zv.classes=Fv,zv.displayName=`@mantine/core/TooltipFloating`;var Bv=(0,b.createContext)(!1),Vv=Bv.Provider,Hv=()=>(0,b.useContext)(Bv),Uv={openDelay:0,closeDelay:0};function Wv(e){let{openDelay:t,closeDelay:n,children:r}=R(`TooltipGroup`,Uv,e);return(0,I.jsx)(Vv,{value:!0,children:(0,I.jsx)(hc,{delay:{open:t,close:n},children:r})})}Wv.displayName=`@mantine/core/TooltipGroup`,Wv.extend=e=>e;function Gv(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 Kv(e){let t=Gv(e.middlewares),n=[js(e.offset)];return t.shift&&n.push(Ms(typeof t.shift==`boolean`?{padding:8}:{padding:8,...t.shift})),t.flip&&n.push(typeof t.flip==`boolean`?Ps():Ps(t.flip)),n.push(Rs({element:e.arrowRef,padding:e.arrowOffset})),t.inline?n.push(typeof t.inline==`boolean`?Ls():Ls(t.inline)):e.inline&&n.push(Ls()),n}function qv(e){let[t,n]=(0,b.useState)(e.defaultOpened),r=typeof e.opened==`boolean`?e.opened:t,i=Hv(),a=$t(),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}={}}}=Sc({strategy:e.strategy,placement:e.position,open:r,onOpenChange:o,middleware:Kv(e),whileElementsMounted:ps}),{delay:m,currentId:h,setCurrentId:g}=gc(l,{id:a}),{getReferenceProps:_,getFloatingProps:v}=Ec([dc(l,{enabled:e.events?.hover,delay:i?m:{open:e.openDelay,close:e.closeDelay},mouseOnly:!e.events?.touch}),wc(l,{enabled:e.events?.focus,visibleOnly:!0}),Oc(l,{role:`tooltip`}),bc(l,{enabled:e.opened===void 0})]);Lt(()=>{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 Jv={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:lt(`popover`),positionDependencies:[],middlewares:{flip:!0,shift:!0,inline:!1}},Yv=An((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:mt(t),"--tooltip-bg":n?a.background:void 0,"--tooltip-color":n?a.color:void 0}}}),Xv=B((e,t)=>{let n=R(`Tooltip`,Jv,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`,Jv,n),{dir:pe}=Ji(),me=(0,b.useRef)(null),he=qv({position:Cl(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:Fv,className:y,style:v,classNames:h,styles:g,unstyled:_,attributes:ue,rootSelector:`tooltip`,vars:ie,varsResolver:Yv}),_e=kn(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=Pv(D,{duration:100,transition:`fade`});return(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(Ml,{...ae,withinPortal:f,children:(0,I.jsx)(Rl,{...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)(Sl,{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=rn(he.reference,Tn(_e),t),be=Pv(D,{duration:100,transition:`fade`});return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Ml,{...ae,withinPortal:f,children:(0,I.jsx)(Rl,{...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)(Sl,{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:Mn(y,ve.className),[a]:ye}))]})});Xv.classes=Fv,Xv.displayName=`@mantine/core/Tooltip`,Xv.Floating=zv,Xv.Group=Wv;function Zv({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 Qv({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=Sr();return(0,I.jsx)(Xv.Floating,{disabled:!c,label:c,children:(0,I.jsx)(z,{component:`circle`,...d,...l(`curve`),__vars:{"--curve-color":o?ar(o,f):void 0},fill:`none`,strokeLinecap:s?`round`:`butt`,...Zv({sum:r,size:e,thickness:i,value:t,offset:n,root:a})})})}Qv.displayName=`@mantine/core/Curve`;function $v({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 ey={root:`m_b32e4812`,svg:`m_d43b5134`,curve:`m_b1ca1fbf`,label:`m_b23f9dc4`};function ty(e,t){return Math.min(e||12,(t||120)/4)}var ny={size:120,thickness:12},ry=An((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}})),iy=B((e,t)=>{let n=R(`RingProgress`,ny,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:ey,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:ry}),y=ty(f,d),x=$v({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)(Qv,{...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})]})});iy.classes=ey,iy.displayName=`@mantine/core/RingProgress`;var ay={root:`m_cf365364`,indicator:`m_9e182ccd`,label:`m_1738fcb2`,input:`m_1714d588`,control:`m_69686b9b`,innerLabel:`m_78882f40`},oy={withItemsBorders:!0},sy=An((e,{radius:t,color:n,transitionDuration:r,size:i,transitionTimingFunction:a})=>({root:{"--sc-radius":t===void 0?void 0:mt(t),"--sc-color":n?ar(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":ft(i,`sc-padding`),"--sc-font-size":ht(i)}})),cy=B((e,t)=>{let n=R(`SegmentedControl`,oy,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:ay,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:O,vars:c,varsResolver:sy}),j=Sr(),M=l.map(e=>typeof e==`string`?{label:e,value:e}:e),ee=Cn(),[N,P]=(0,b.useState)(wt()),[te,ne]=(0,b.useState)(null),[re,ie]=(0,b.useState)({}),ae=(e,t)=>{re[t]=e,ie(re)},[oe,se]=an({value:u,defaultValue:d,finalValue:Array.isArray(l)?M.find(e=>!e.disabled)?.value??l[0]?.value??null:null,onChange:f}),ce=$t(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:Dr({color:x,theme:j,autoContrast:T})},key:`${e.value}-label`},(0,I.jsx)(`span`,{...A(`innerLabel`),children:e.label})))),ue=rn(t,e=>ne(e));return fn(()=>{P(wt())},[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)(bd,{target:re[oe],parent:te,component:`span`,transitionDuration:`var(--sc-transition-duration)`,...A(`indicator`)},N),le]})});cy.classes=ay,cy.displayName=`@mantine/core/SegmentedControl`;var ly={container:`m_925c2d2c`,root:`m_2415a157`};function uy({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=Sr(),a=t===void 0?e:t,o=Xe({"--sg-spacing-x":pt(xt(e)),"--sg-spacing-y":pt(xt(a)),"--sg-cols":xt(n)?.toString()}),s=Ve(i.breakpoints).reduce((t,r)=>(t[r]||(t[r]={}),typeof e==`object`&&e[r]!==void 0&&(t[r][`--sg-spacing-x`]=pt(e[r])),typeof a==`object`&&a[r]!==void 0&&(t[r][`--sg-spacing-y`]=pt(a[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{}),c=bt(Ve(s),i.breakpoints).filter(e=>Ve(s[e.value]).length>0).map(e=>({query:`(min-width: ${i.breakpoints[e.value]})`,styles:s[e.value]}));return(0,I.jsx)(di,{styles:o,media:c,selector:r})}function dy(e){return typeof e==`object`&&e?Ve(e):[]}function fy(e){return e.sort((e,t)=>Ke(e)-Ke(t))}function py({spacing:e,verticalSpacing:t,cols:n}){return fy(Array.from(new Set([...dy(e),...dy(t),...dy(n)])))}function my({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=t===void 0?e:t,a=Xe({"--sg-spacing-x":pt(xt(e)),"--sg-spacing-y":pt(xt(i)),"--sg-cols":xt(n)?.toString()}),o=py({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`]=pt(e[r])),typeof i==`object`&&i[r]!==void 0&&(t[r][`--sg-spacing-y`]=pt(i[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{}),c=o.map(e=>({query:`simple-grid (min-width: ${e})`,styles:s[e]}));return(0,I.jsx)(di,{styles:a,container:c,selector:r})}var hy={cols:1,spacing:`md`,type:`media`},gy=B((e,t)=>{let n=R(`SimpleGrid`,hy,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:ly,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c}),g=Fi();return f===`container`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(my,{...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)(uy,{...n,selector:`.${g}`}),(0,I.jsx)(z,{ref:t,...h(`root`,{className:g}),...m})]})});gy.classes=ly,gy.displayName=`@mantine/core/SimpleGrid`;var _y={root:`m_18320242`,"skeleton-fade":`m_299c329c`},vy={visible:!0,animate:!0},yy=An((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:mt(r)}})),by=B((e,t)=>{let n=R(`Skeleton`,vy,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,v=L({name:`Skeleton`,classes:_y,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:yy});return(0,I.jsx)(z,{ref:t,...v(`root`),mod:[{visible:f,animate:m},h],..._})});by.classes=_y,by.displayName=`@mantine/core/Skeleton`;var xy=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})});xy.displayName=`@mantine/core/Space`;var Sy={root:`m_6d731127`},Cy={gap:`md`,align:`stretch`,justify:`flex-start`},wy=An((e,{gap:t,align:n,justify:r})=>({root:{"--stack-gap":pt(t),"--stack-align":n,"--stack-justify":r}})),G=B((e,t)=>{let n=R(`Stack`,Cy,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,h=L({name:`Stack`,props:n,classes:Sy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c,varsResolver:wy});return(0,I.jsx)(z,{ref:t,...h(`root`),variant:f,...m})});G.classes=Sy,G.displayName=`@mantine/core/Stack`;var[Ty,Ey]=et(`Stepper component was not found in tree`),Dy={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`},Oy=()=>null;Oy.displayName=`@mantine/core/StepperCompleted`;var ky=(e,t)=>typeof e==`function`?(0,I.jsx)(e,{step:t||0}):e,Ay={withIcon:!0,allowStepClick:!0,iconPosition:`left`},jy=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`,Ay,e),w=Ey(),T=Sr(),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)(fl,{...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?ar(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)(Rl,{mounted:c===`stepCompleted`,transition:`pop`,duration:200,children:e=>(0,I.jsx)(`span`,{...w.getStyles(`stepCompletedIcon`,{style:e,...E}),children:_?(0,I.jsx)(ou,{color:`var(--mantine-color-white)`,size:`calc(var(--stepper-icon-size) / 2)`,...w.getStyles(`stepLoader`,E)}):ky(d,s)||(0,I.jsx)($f,{size:`60%`})})}),c===`stepCompleted`?null:(0,I.jsx)(`span`,{children:_?(0,I.jsx)(ou,{...w.getStyles(`stepLoader`,E),size:`calc(var(--stepper-icon-size) / 2)`,color:l}):ky(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:ky(p,s)}),m&&(0,I.jsx)(`span`,{...w.getStyles(`stepDescription`,E),children:ky(m,s)})]})]})});jy.classes=Dy,jy.displayName=`@mantine/core/StepperStep`;var My={orientation:`horizontal`,iconPosition:`left`,allowNextStepsSelect:!0,wrap:!0},Ny=An((e,{color:t,iconSize:n,size:r,contentPadding:i,radius:a,autoContrast:o})=>({root:{"--stepper-color":t?ar(t,e):void 0,"--stepper-icon-color":ai(o,e)?Dr({color:t,theme:e,autoContrast:o}):void 0,"--stepper-icon-size":n===void 0?ft(r,`stepper-icon-size`):F(n),"--stepper-content-padding":pt(i),"--stepper-radius":a===void 0?void 0:mt(a),"--stepper-fz":ht(r),"--stepper-spacing":pt(r)}})),Py=B((e,t)=>{let n=R(`Stepper`,My,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:Dy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:E,vars:c,varsResolver:Ny}),k=b.Children.toArray(l),A=k.filter(e=>e.type!==Oy),j=k.find(e=>e.type===Oy),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)(Ty,{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})]})})});Py.classes=Dy,Py.displayName=`@mantine/core/Stepper`,Py.Completed=Oy,Py.Step=jy;var Fy={root:`m_5f93f3bb`,input:`m_926b4011`,track:`m_9307d992`,thumb:`m_93039a1d`,trackLabel:`m_8277e082`},Iy=(0,b.createContext)(null),Ly=Iy.Provider,Ry=()=>(0,b.useContext)(Iy),zy=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]=an({value:n,defaultValue:r,finalValue:[],onChange:i});return(0,I.jsx)(Ly,{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)(ld.Wrapper,{size:a,ref:t,...o,...u,labelElement:`div`,__staticSelector:`SwitchGroup`,children:(0,I.jsx)(Zf,{role:`group`,children:s})})})});zy.classes=ld.Wrapper.classes,zy.displayName=`@mantine/core/SwitchGroup`;var By={labelPosition:`right`,withThumbIndicator:!0},Vy=An((e,{radius:t,color:n,size:r})=>({root:{"--switch-radius":t===void 0?void 0:mt(t),"--switch-height":ft(r,`switch-height`),"--switch-width":ft(r,`switch-width`),"--switch-thumb-size":ft(r,`switch-thumb-size`),"--switch-label-font-size":ft(r,`switch-label-font-size`),"--switch-track-label-padding":ft(r,`switch-track-label-padding`),"--switch-color":n?ar(n,e):void 0}})),Hy=B((e,t)=>{let n=R(`Switch`,By,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=Ry(),M=m||j?.size,ee=L({name:`Switch`,props:n,classes:Fy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:k,vars:c,varsResolver:Vy}),{styleProps:N,rest:P}=fi(A),te=$t(p),ne={checked:j?.value.includes(P.value)??v,onChange:e=>{j?.onChange(e),b?.(e)},disabled:j?.disabled??w},[re,ie]=an({value:ne.checked??v,defaultValue:y,finalValue:!1});return(0,I.jsxs)(Bf,{...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})]})]})});Hy.classes={...Fy,...zf},Hy.displayName=`@mantine/core/Switch`,Hy.Group=zy;var[Uy,Wy]=et(`Table component was not found in the tree`),Gy={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 Ky(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 qy(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=Wy();return(0,I.jsx)(z,{component:e,ref:i,...Ky(d,t),...d.getStyles(e,{className:s,classNames:o,style:c,styles:l,props:a}),...u})});return r.displayName=`@mantine/core/${n}`,r.classes=Gy,r}var Jy=qy(`th`,{columnBorder:!0}),Yy=qy(`td`,{columnBorder:!0}),Xy=qy(`tr`,{rowBorder:!0,striped:!0,highlightOnHover:!0}),Zy=qy(`thead`,{stickyHeader:!0}),Qy=qy(`tbody`),$y=qy(`tfoot`),eb=qy(`caption`,{captionSide:!0});function tb({data:e}){return(0,I.jsxs)(I.Fragment,{children:[e.caption&&(0,I.jsx)(eb,{children:e.caption}),e.head&&(0,I.jsx)(Zy,{children:(0,I.jsx)(Xy,{children:e.head.map((e,t)=>(0,I.jsx)(Jy,{children:e},t))})}),e.body&&(0,I.jsx)(Qy,{children:e.body.map((e,t)=>(0,I.jsx)(Xy,{children:e.map((e,t)=>(0,I.jsx)(Yy,{children:e},t))},t))}),e.foot&&(0,I.jsx)($y,{children:(0,I.jsx)(Xy,{children:e.foot.map((e,t)=>(0,I.jsx)(Jy,{children:e},t))})})]})}tb.displayName=`@mantine/core/TableDataRenderer`;var nb={type:`scrollarea`},rb=An((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}})),ib=B((e,t)=>{let n=R(`TableScrollContainer`,nb,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:Gy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:m,vars:c,varsResolver:rb,rootSelector:`scrollContainer`});return(0,I.jsx)(z,{component:f===`scrollarea`?cl:`div`,...f===`scrollarea`?d?{offsetScrollbars:`xy`,...p}:{offsetScrollbars:`x`,...p}:{},ref:t,...g(`scrollContainer`),...h,children:(0,I.jsx)(`div`,{...g(`scrollContainerInner`),children:l})})});ib.classes=Gy,ib.displayName=`@mantine/core/TableScrollContainer`;var ab={withRowBorders:!0,verticalSpacing:7},ob=An((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":pt(r),"--table-vertical-spacing":pt(i),"--table-border-color":a?ar(a,e):void 0,"--table-striped-color":c&&o?ar(o,e):void 0,"--table-highlight-on-hover-color":l&&s?ar(s,e):void 0,"--table-sticky-header-offset":d?F(u):void 0}})),K=B((e,t)=>{let n=R(`Table`,ab,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:Gy,classNames:r,styles:o,unstyled:s,attributes:O,rootSelector:`table`,vars:c,varsResolver:ob});return(0,I.jsx)(Uy,{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)(tb,{data:S})})})});K.classes=Gy,K.displayName=`@mantine/core/Table`,K.Td=Yy,K.Th=Jy,K.Tr=Xy,K.Thead=Zy,K.Tbody=Qy,K.Tfoot=$y,K.Caption=eb,K.ScrollContainer=ib,K.DataRenderer=tb;var[sb,cb]=et(`Tabs component was not found in the tree`),lb={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`},ub=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=cb();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})});ub.classes=lb,ub.displayName=`@mantine/core/TabsList`;var db=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=cb(),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})});db.classes=lb,db.displayName=`@mantine/core/TabsPanel`;var fb=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=Sr(),{dir:b}=Ji(),x=cb(),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)(fl,{...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?ar(d,y):void 0},onKeyDown:st({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})]})});fb.classes=lb,fb.displayName=`@mantine/core/TabsTab`;var pb=`Tabs.Tab or Tabs.Panel component was rendered with invalid value or without value`,mb={keepMounted:!0,orientation:`horizontal`,loop:!0,activateTabWithKeyboard:!0,variant:`default`,placement:`left`},hb=An((e,{radius:t,color:n,autoContrast:r})=>({root:{"--tabs-radius":mt(t),"--tabs-color":ar(n,e),"--tabs-text-color":ai(r,e)?Dr({color:n,theme:e,autoContrast:r}):void 0}})),gb=B((e,t)=>{let n=R(`Tabs`,mb,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=$t(l),[k,A]=an({value:i,defaultValue:r,finalValue:null,onChange:a}),j=L({name:`Tabs`,props:n,classes:lb,className:x,style:S,classNames:v,styles:y,unstyled:b,attributes:E,vars:C,varsResolver:hb});return(0,I.jsx)(sb,{value:{placement:g,value:k,orientation:o,id:O,loop:c,activateTabWithKeyboard:u,getTabId:nt(`${O}-tab`,pb),getPanelId:nt(`${O}-panel`,pb),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})})});gb.classes=lb,gb.displayName=`@mantine/core/Tabs`,gb.Tab=fb,gb.Panel=db,gb.List=ub;var _b=B((e,t)=>{let n=R(`TextInput`,null,e);return(0,I.jsx)(fd,{component:`input`,ref:t,...n,__staticSelector:`TextInput`})});_b.classes=fd.classes,_b.displayName=`@mantine/core/TextInput`;var vb={root:`m_7341320d`},yb=An((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":ft(t,`ti-size`),"--ti-radius":n===void 0?void 0:mt(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}}}),bb=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,f=L({name:`ThemeIcon`,classes:vb,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:u,vars:c,varsResolver:yb});return(0,I.jsx)(z,{ref:t,...f(`root`),...d})});bb.classes=vb,bb.displayName=`@mantine/core/ThemeIcon`;var xb=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],Sb=[`xs`,`sm`,`md`,`lg`,`xl`];function Cb(e,t){let n=t===void 0?`h${e}`:t;return xb.includes(n)?{fontSize:`var(--mantine-${n}-font-size)`,fontWeight:`var(--mantine-${n}-font-weight)`,lineHeight:`var(--mantine-${n}-line-height)`}:Sb.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 wb={root:`m_8a5d1357`},Tb={order:1},Eb=An((e,{order:t,size:n,lineClamp:r,textWrap:i})=>{let a=Cb(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`,Tb,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:wb,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:h,vars:l,varsResolver:Eb});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=wb,q.displayName=`@mantine/core/Title`;function Db(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 Ob(e){return(0,b.useSyncExternalStore)(e.subscribe,()=>e.getState(),()=>e.getState())}function kb(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 Ab=Db({notifications:[],queue:[],defaultPosition:`bottom-right`,limit:5}),jb=(e=Ab)=>Ob(e);function Mb(e,t){let n=e.getState(),r=kb(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=Ab){let n=e.id||wt();return Mb(t,t=>e.id&&t.some(t=>t.id===e.id)?t:[...t,{...e,id:n}]),n}function Nb(e,t=Ab){return Mb(t,t=>t.filter(t=>t.id!==e||(t.onClose?.(t),!1))),e}function Pb(e,t=Ab){return Mb(t,t=>t.map(t=>t.id===e.id?{...t,...e}:t)),e.id}function Fb(e=Ab){Mb(e,()=>[])}function Ib(e=Ab){Mb(e,t=>t.slice(0,e.getState().limit))}var Lb={show:J,hide:Nb,update:Pb,clean:Fb,cleanQueue:Ib,updateState:Mb};function Rb(e,t){return Rb=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Rb(e,t)}function zb(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,Rb(e,t)}var Bb=o(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Vb=o(((e,t)=>{var n=Bb();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}})),Hb=o(((e,t)=>{t.exports=Vb()()})),Ub={disabled:!1},Wb=b.createContext(null),Gb=function(e){return e.scrollTop},Kb=`unmounted`,qb=`exited`,Jb=`entering`,Yb=`entered`,Xb=`exiting`,Zb=function(e){zb(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=qb,r.appearStatus=Jb):o=Yb:o=t.unmountOnExit||t.mountOnEnter?Kb:qb,r.state={status:o},r.nextCallback=null,r}t.getDerivedStateFromProps=function(e,t){return e.in&&t.status===`unmounted`?{status:qb}: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=Jb):(n===`entering`||n===`entered`)&&(t=Xb)}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:Cs.default.findDOMNode(this);n&&Gb(n)}this.performEnter(e)}else this.performExit()}else this.props.unmountOnExit&&this.state.status===`exited`&&this.setState({status:Kb})},n.performEnter=function(e){var t=this,n=this.props.enter,r=this.context?this.context.isMounting:e,i=this.props.nodeRef?[r]:[Cs.default.findDOMNode(this),r],a=i[0],o=i[1],s=this.getTimeouts(),c=r?s.appear:s.enter;if(!e&&!n||Ub.disabled){this.safeSetState({status:Yb},function(){t.props.onEntered(a)});return}this.props.onEnter(a,o),this.safeSetState({status:Jb},function(){t.props.onEntering(a,o),t.onTransitionEnd(c,function(){t.safeSetState({status:Yb},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:Cs.default.findDOMNode(this);if(!t||Ub.disabled){this.safeSetState({status:qb},function(){e.props.onExited(r)});return}this.props.onExit(r),this.safeSetState({status:Xb},function(){e.props.onExiting(r),e.onTransitionEnd(n.exit,function(){e.safeSetState({status:qb},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:Cs.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=Im(t,[`children`,`in`,`mountOnEnter`,`unmountOnExit`,`appear`,`enter`,`exit`,`timeout`,`addEndListener`,`onEnter`,`onEntering`,`onEntered`,`onExit`,`onExiting`,`onExited`,`nodeRef`]);return b.createElement(Wb.Provider,{value:null},typeof n==`function`?n(e,r):b.cloneElement(b.Children.only(n),r))},t}(b.Component);Zb.contextType=Wb,Zb.propTypes={};function Qb(){}Zb.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:Qb,onEntering:Qb,onEntered:Qb,onExit:Qb,onExiting:Qb,onExited:Qb},Zb.UNMOUNTED=Kb,Zb.EXITED=qb,Zb.ENTERING=Jb,Zb.ENTERED=Yb,Zb.EXITING=Xb;function $b(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function ex(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 tx(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 nx(e,t,n){return n[t]==null?e.props[t]:n[t]}function rx(e,t){return ex(e.children,function(n){return(0,b.cloneElement)(n,{onExited:t.bind(null,n),in:!0,appear:nx(n,`appear`,e),enter:nx(n,`enter`,e),exit:nx(n,`exit`,e)})})}function ix(e,t,n){var r=ex(e.children),i=tx(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:nx(o,`exit`,e),enter:nx(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:nx(o,`exit`,e),enter:nx(o,`enter`,e)}))}}),i}var ax=Object.values||function(e){return Object.keys(e).map(function(t){return e[t]})},ox={component:`div`,childFactory:function(e){return e}},sx=function(e){zb(t,e);function t(t,n){var r=e.call(this,t,n)||this;return r.state={contextValue:{isMounting:!0},handleExited:r.handleExited.bind($b(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?rx(e,r):ix(e,n,r),firstRender:!1}},n.handleExited=function(e,t){var n=ex(this.props.children);e.key in n||(e.props.onExited&&e.props.onExited(t),this.mounted&&this.setState(function(t){var n=Fm({},t.children);return delete n[e.key],{children:n}}))},n.render=function(){var e=this.props,t=e.component,n=e.childFactory,r=Im(e,[`component`,`childFactory`]),i=this.state.contextValue,a=ax(this.state.children).map(n);return delete r.appear,delete r.enter,delete r.exit,t===null?b.createElement(Wb.Provider,{value:i},a):b.createElement(Wb.Provider,{value:i},b.createElement(t,r,a))},t}(b.Component);sx.propTypes={},sx.defaultProps=ox;var cx=[`bottom-center`,`bottom-left`,`bottom-right`,`top-center`,`top-left`,`top-right`];function lx(e,t){return e.reduce((e,n)=>(e[n.position||t].push(n),e),cx.reduce((e,t)=>(e[t]=[],e),{}))}var ux={left:`translateX(-100%)`,right:`translateX(100%)`,"top-center":`translateY(-100%)`,"bottom-center":`translateY(100%)`},dx={left:`translateX(0)`,right:`translateX(0)`,"top-center":`translateY(0)`,"bottom-center":`translateY(0)`};function fx({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:ux[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:dx[o]},l={opacity:0,maxHeight:0,transform:ux[o]},u={entering:c,entered:c,exiting:l,exited:l};return{...s,...u[e]}}function px(e,t){return typeof t==`number`?t:t===!1||e===!1?!1:e}var mx=(0,b.forwardRef)(({data:e,onHide:t,autoClose:n,...r},i)=>{let{autoClose:a,message:o,...s}=e,c=px(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)(Og,{...r,...s,onClose:d,ref:i,onMouseEnter:u,onMouseLeave:f,children:o})});mx.displayName=`@mantine/notifications/NotificationContainer`;var hx={root:`m_b37d9ac7`,notification:`m_5ed0edd0`},gx=Zb,_x={position:`bottom-right`,autoClose:4e3,transitionDuration:250,containerWidth:440,notificationMaxHeight:200,limit:5,zIndex:lt(`overlay`),store:Ab,withinPortal:!0},vx=An((e,{zIndex:t,containerWidth:n})=>({root:{"--notifications-z-index":t?.toString(),"--notifications-container-width":F(n)}})),yx=B((e,t)=>{let n=R(`Notifications`,_x,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=Sr(),S=jb(g),C=Xt(),w=ln(),T=(0,b.useRef)({}),E=(0,b.useRef)(0),D=x.respectReducedMotion&&w?1:d,O=L({name:`Notifications`,classes:hx,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,vars:c,varsResolver:vx});(0,b.useEffect)(()=>{g?.updateState(e=>({...e,limit:m||5,defaultPosition:l}))},[m,l]),Lt(()=>{S.notifications.length>E.current&&setTimeout(()=>C(),0),E.current=S.notifications.length},[S.notifications]);let k=lx(S.notifications,l),A=cx.reduce((e,t)=>(e[t]=k[t].map(({style:e,...n})=>(0,I.jsx)(gx,{timeout:D,onEnter:()=>T.current[n.id].offsetHeight,nodeRef:{current:T.current[n.id]},children:r=>(0,I.jsx)(mx,{ref:e=>{e&&(T.current[n.id]=e)},data:n,onHide:e=>Nb(e,g),autoClose:u,...O(`notification`,{style:{...fx({state:r,position:t,transitionDuration:D,maxHeight:p}),...e}})})},n.id)),e),{});return(0,I.jsxs)(Ml,{withinPortal:v,..._,children:[(0,I.jsx)(z,{...O(`root`),"data-position":`top-center`,ref:t,...y,children:(0,I.jsx)(sx,{children:A[`top-center`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`top-left`,...y,children:(0,I.jsx)(sx,{children:A[`top-left`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`top-right`,...y,children:(0,I.jsx)(sx,{children:A[`top-right`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`bottom-right`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-right`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-left`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-left`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-center`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-center`]})})]})});yx.classes=hx,yx.displayName=`@mantine/notifications/Notifications`,yx.show=Lb.show,yx.hide=Lb.hide,yx.update=Lb.update,yx.clean=Lb.clean,yx.cleanQueue=Lb.cleanQueue,yx.updateState=Lb.updateState;var bx=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}},xx=class{operator;child;constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}},Sx=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()})`}},Cx=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 wx(e,this.prefixParselets,this.infixParselets)}},wx=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)}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 Tx(e){if(e!==void 0)return Array.isArray(e)?e:[e]}var Ex=`http://hl7.org`,Dx=`ok`,Ox=`created`,kx=`gone`,Ax=`not-modified`,jx=`found`,Mx=`not-found`,Nx=`conflict`,Px=`unauthorized`,Fx=`forbidden`,Ix=`precondition-failed`,Lx=`content-too-large`,Rx=`unsupported-media-type`,zx=`multiple-matches`,Bx=`too-many-requests`,Vx=`accepted`,Hx=`server-timeout`,Ux=`business-rule`,Wx={resourceType:`OperationOutcome`,id:Dx,issue:[{severity:`information`,code:`informational`,details:{text:`All OK`}}]},Gx={resourceType:`OperationOutcome`,id:Mx,issue:[{severity:`error`,code:`not-found`,details:{text:`Not found`}}]},Kx={resourceType:`OperationOutcome`,id:Px,issue:[{severity:`error`,code:`login`,details:{text:`Unauthorized`}}]},qx={...Kx,issue:[...Kx.issue,{severity:`error`,code:`expired`,details:{text:`Token expired`}}]},Jx={...Kx,issue:[...Kx.issue,{severity:`error`,code:`invalid`,details:{text:`Token not issued for this audience`}}]},Yx={resourceType:`OperationOutcome`,id:Fx,issue:[{severity:`error`,code:`forbidden`,details:{text:`Forbidden`}}]};function Xx(e,t){return{resourceType:`OperationOutcome`,issue:[{severity:`error`,code:`invalid`,details:{text:e},...t?{expression:Tx(t)}:void 0}]}}function Zx(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 Qx(e){return e?.issue?.[0]?.details?.coding?.find(e=>e.system===`urn:ietf:rfc:3986`)?.code}function $x(e){return!e||typeof e!=`object`?!1:e instanceof Error||typeof DOMException<`u`&&e instanceof DOMException||Object.prototype.toString.call(e)===`[object Error]`}function eS(e){return typeof e==`object`&&!!e&&e.resourceType===`OperationOutcome`}function tS(e){return e.id===Dx||e.id===Ox||e.id===Ax||e.id===Vx}function nS(e){return e.id===kx}function rS(e){switch(e.id){case Dx:return 200;case Ox:return 201;case Vx:return 202;case jx:return 302;case Ax:return 304;case Px:return 401;case Fx:return 403;case Mx:return 404;case Nx:return 409;case kx:return 410;case Ix:case zx:return 412;case Lx:return 413;case Rx:return 415;case Ux:return 422;case Bx:return 429;case Hx:return 504;default:return e.issue?.[0]?.code===`exception`?500:400}}var iS=class extends Error{outcome;constructor(e,t){super(oS(e),t),this.name=`OperationOutcomeError`,this.outcome=e}};function aS(e){return e instanceof iS?e.outcome:eS(e)?e:Xx(Y(e))}function Y(e){return e?typeof e==`string`?e:$x(e)?e.message:eS(e)?oS(e):typeof e==`object`&&`code`in e&&typeof e.code==`string`?e.code:JSON.stringify(e):`Unknown error`}function oS(e){let t=e.issue?.map(sS)??[];return t.length>0?t.join(`; `):`Unknown error`}function sS(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 cS(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 lS(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,cS(e,t)])),constraints:[],innerTypes:[]};return t}var uS={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`}]},deleted:{type:[{code:`boolean`}]}}},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 dS(e){return new TS(e).parse()}var fS=lS(uS),pS=Object.create(null),mS=Object.create(null),hS={"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 gS(e){let t;return t=mS[e],t||=mS[e]=Object.create(null),t}function _S(e){let t=(Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[]).filter(e=>e?.resourceType===`StructureDefinition`);Lw(t);for(let e of t)vS(e)}function vS(e){if(!e?.name)throw Error(`Failed loading StructureDefinition from bundle`);if(e.resourceType!==`StructureDefinition`)return;let t=dS(e),n=hS[e.url],r,i;n?(r=fS,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=fS,i=e.type):(r=gS(e.url),i=e.type),r[i]=t;for(let e of t.innerTypes)e.parentType=t,r[e.name]=e;pS[e.url]=t}function yS(){return fS}function bS(e){return!!fS[e]}function xS(e,t){if(t){let n=gS(t)[e];if(n)return n}return fS[e]}function SS(e,t){let n=xS(e,t);if(!n)throw new iS(Xx(`Unknown data type: `+e));return n}function CS(e){return!!pS[e]}function wS(e){return pS[e]}var TS=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:MS(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=DS(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[DS(e,n.path)]=t;break}n=n.parent}if(!n){let n=DS(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&&!kS(this.slicingContext.path,e?.path)&&(this.slicingContext=void 0),e.slicing&&!this.slicingContext&&this.enterSlice(e,t)}enterInnerType(e){for(;this.backboneContext&&!kS(this.backboneContext?.path,e.path);)this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;let t=Bw(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:kS(this.backboneContext?.path,e.path)?this.backboneContext:this.backboneContext?.parent}}enterSlice(e,t){jS(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&&!kS(this.backboneContext.path,e?.path)){if(this.backboneContext.parent)do this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;while(this.backboneContext&&!kS(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!!(kS(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=Bw(e)),n||=EC(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=ES(e.max),n=e.base?.max?ES(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:AS(HS(r,`fixed[x]`)),pattern:AS(HS(r,`pattern[x]`)),binding:e.binding}}};function ES(e){return e===`*`?1/0:Number.parseInt(e,10)}function DS(e,t=``){return OS(e.path,t)}function OS(e,t){return e?t&&e.startsWith(t)?e.substring(t.length+1):e:``}function kS(e,t){return!e||!t?!1:t.startsWith(e+`.`)||t===e}function AS(e){return Array.isArray(e)&&e.length>0?e[0]:jC(e)?void 0:e}function jS(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 MS(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 NS(e,t,n){if(e===void 0)return[void 0];if(t===`$this`)return[e];let r=n?.withPath?PS:HS,[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 PS(e,t,n){let r=e.path;return FS(HS(e,t,n),r,t)}function FS(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 bx(1e3);var IS={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 LS(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 LC(e,i.pattern);if(i.fixed)return PC(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 RS(e){return[{type:X.boolean,value:e}]}function zS(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}:oC(e)?{type:X.Quantity,value:e}:Qw(e)?{type:e.resourceType,value:e}:GC(e)?{type:X.CodeableConcept,value:e}:WC(e)?{type:X.Coding,value:e}:{type:X.BackboneElement,value:e}}function BS(e){return e.length!==0&&!!e[0].value}function VS(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 HS(e,t,n){if(!e.value)return;let r=Xw(e.type,t,n?.profileUrl);return r?US(e,t,r):GS(e,t)}function US(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+=ZC(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]=uC(a[e],s[e])}else if(!a&&Array.isArray(s)){a=s.slice();for(let e=0;e<s.length;e++)a[e]=uC(void 0,s[e])}else a=uC(a,s)}if(!jC(a))return(o===`Element`||o===`BackboneElement`)&&(o=n.type[0].code),Array.isArray(a)?a.map(e=>WS(e,o)):WS(a,o)}function WS(e,t){return t===`Resource`&&Qw(e)&&(t=e.resourceType),{type:t,value:e}}function GS(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(zS):zS(e)}else{let e=t.endsWith(`[x]`)?t.substring(0,t.length-3):t;for(let t of Object.values(X)){let i=e+ZC(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||jC(r[0]))return}else if(jC(r))return;return r}function KS(e){let t=[];for(let n of e){let e=!1;for(let r of t)if(BS(XS(n,r))){e=!0;break}e||t.push(n)}return t}function qS(e){return RS(!BS(e))}function JS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?RS(e.every((e,n)=>BS(XS(e,t[n])))):RS(!1)}function YS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?RS(e.some((e,n)=>!BS(XS(e,t[n])))):RS(!0)}function XS(e,t){let n=e.value?.valueOf(),r=t.value?.valueOf();return typeof n==`number`&&typeof r==`number`?RS(Math.abs(n-r)<1e-8):oC(n)&&oC(r)?RS(sC(n,r)):RS(typeof n==`object`&&typeof r==`object`?cC(e,t):n===r)}function ZS(e,t){return e.length===0&&t.length===0?RS(!0):e.length===t.length?(e.sort($S),t.sort($S),RS(e.every((e,n)=>BS(QS(e,t[n]))))):RS(!1)}function QS(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`?RS(Math.abs(o-s)<.01):oC(o)&&oC(s)?RS(sC(o,s)):RS(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`?cC({...o,id:void 0},{...s,id:void 0}):typeof o==`string`&&typeof s==`string`?o.toLowerCase()===s.toLowerCase():o===s)}function $S(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 eC(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 tC(n);case`DateTime`:return nC(n);case`Time`:return typeof n==`string`&&!!/^T\d/.exec(n);case`Period`:return rC(n);case`Quantity`:return oC(n);default:return e.type===r||typeof n==`object`&&n?.resourceType===r}}function tC(e){return typeof e==`string`&&!!IS.date.exec(e)}function nC(e){return typeof e==`string`&&!!IS.dateTime.exec(e)}function rC(e){return!!(e&&typeof e==`object`&&(`start`in e&&nC(e.start)||`end`in e&&nC(e.end)))}function iC(e){if(tC(e)||nC(e))return{start:aC(e,`0000-01-01T00:00:00.000`),end:aC(e,`xxxx-12-31T23:59:59.999`)};if(rC(e))return{start:e.start?aC(e.start,`0000-01-01T00:00:00.000`):void 0,end:e.end?aC(e.end,`xxxx-12-31T23:59:59.999`):void 0}}function aC(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 oC(e){return!!(e&&typeof e==`object`&&`value`in e&&typeof e.value==`number`)}function sC(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 cC(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(lC(n)&&lC(i)){if(!cC(n,i))return!1}else if(n!==i)return!1}return!0}function lC(e){return typeof e==`object`&&!!e}function uC(e,t){if(t){if(typeof t!=`object`)throw Error(`Primitive extension must be an object`);return dC(e??{},t)}return e}function dC(e,t){return delete t.__proto__,delete t.constructor,Object.assign(e,t)}function fC(e,t){return Qw(e,t)&&`id`in e&&typeof e.id==`string`}function pC(e){let t=mC(e)??`undefined/undefined`,n=vC(e);return n===t?{reference:t}:{reference:t,display:n}}function mC(e){if($w(e))return e.reference;if(fC(e))return`${e.resourceType}/${e.id}`}function hC(e){if(e)return $w(e)?e.reference.split(`/`)[1]:e.id}function gC(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]}return Tx(e.accounts??e.account)}}function _C(e){return e.resourceType===`Patient`||e.resourceType===`Practitioner`||e.resourceType===`RelatedPerson`}function vC(e){if(_C(e)){let t=yC(e);if(t)return t}if(e.resourceType===`Appointment`&&e.serviceType?.[0])return Aw(e.serviceType[0]);if(e.resourceType===`Device`){let t=bC(e);if(t)return t}if(e.resourceType===`DocumentReference`){if(e.description)return e.description;if(e.type)return Aw(e.type)}if(e.resourceType===`MedicationRequest`&&e.medicationCodeableConcept||e.resourceType===`MedicationStatement`&&e.medicationCodeableConcept)return Aw(e.medicationCodeableConcept);if(e.resourceType===`Slot`&&(e.start||e.end))return`${bw(e.start)} - ${bw(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]),GC(t))return Aw(t);if(KC(t))return t.text}return mC(e)??``}function yC(e){let t=e.name;if(t&&t.length>0)return _w(t[0])}function bC(e){let t=e.deviceName;if(t&&t.length>0)return t[0].name}function xC(e){if(!(`photo`in e))return;let t=e.photo;if(t){if(Array.isArray(t))for(let e of t){let t=SC(e);if(t)return t}else return SC(t)}}function SC(e){if(e.url&&e.contentType?.startsWith(`image/`))return e.url}function CC(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())/864e5);return{years:u,months:d,days:f}}function wC(e,t){let{years:n,months:r,days:i}=CC(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 TC(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 EC(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 DC(e,t){let n=OC(e);return JSON.stringify(n,null,t?2:void 0)??``}function OC(e){if(e!=null&&e!==``)return typeof e==`object`?Array.isArray(e)?kC(e):AC(e):e}function kC(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=OC(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 AC(e){let t,n=0;for(let r in e){let i=e[r],a=OC(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 jC(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`object`?!MC(e):!1}function MC(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 NC(e){if(!e)return;let t=e.length-1;for(;t>=0&&jC(e[t]);)t--;return t>=0?e.slice(0,t+1):void 0}function PC(e,t,n){return e===t||jC(e)&&jC(t)?!0:jC(e)||jC(t)?!1:Array.isArray(e)&&Array.isArray(t)?FC(e,t):Array.isArray(e)||Array.isArray(t)?!1:HC(e)&&HC(t)?IC(e,t,n):!1}function FC(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!PC(e[n],t[n]))return!1;return!0}function IC(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(!PC(r,i,n))return!1}return!0}function LC(e,t){return jC(e)?!0:jC(t)?!1:Array.isArray(e)&&Array.isArray(t)?RC(e,t):Array.isArray(e)||Array.isArray(t)?!1:HC(e)&&HC(t)?zC(e,t):HC(e)||HC(t)?!1:e===t}function RC(e,t){return t.every(t=>e.some(e=>LC(e,t)))}function zC(e,t){return Object.entries(t).every(([t,n])=>t in e&&LC(e[t],n))}function BC(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function VC(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 HC(e){return typeof e==`object`&&!!e}function UC(e){return typeof e==`string`}function WC(e){return HC(e)&&`code`in e&&typeof e.code==`string`}function GC(e){return HC(e)&&`coding`in e&&Array.isArray(e.coding)&&e.coding.every(WC)}function KC(e){return HC(e)&&`text`in e&&typeof e.text==`string`}var qC=[];for(let e=0;e<256;e++)qC.push(e.toString(16).padStart(2,`0`));function JC(e){let t=XC(e),n=new Uint8Array(t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=qC[n[e]];return r.join(``)}function YC(e){let t=XC(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 XC(e){return ArrayBuffer.isView(e)?e.buffer:e}function ZC(e){return e?e.charAt(0).toUpperCase()+e.substring(1):``}function QC(e){return e.length>0&&e.startsWith(e[0].toUpperCase())}function $C(e,t){let n=e+`.`;if(t.startsWith(n))return t.slice(n.length)}function ew(e,t){return e.coding?.find(e=>e.system===t)?.code}var tw=(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 nw(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 rw(e){let t,n=!1;return function(){return n||=(t=e(),!0),t}}function iw(e,t){return e?(e.push(t),e):[t]}function aw(e){return e.sort((e,t)=>e.localeCompare(t))}function ow(e){return e.endsWith(`/`)?e:e+`/`}function sw(e){return e.startsWith(`/`)?e.slice(1):e}function cw(e,t){return new URL(sw(t),ow(e.toString())).toString()}function lw(e,t){return cw(e,t).toString().replace(`http://`,`ws://`).replace(`https://`,`wss://`)}function uw(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 dw(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 fw(e,t){if(e?.meta?.profile?.includes(t)){let n=e.meta.profile.indexOf(t);e.meta.profile.splice(n,1)}return e}var pw=Object.freeze([]);function mw(e){if(!e)return``;switch(e.type){case`Address`:return gw(e.value);case`CodeableConcept`:return Aw(e.value);case`Coding`:return jw(e.value);case`ContactPoint`:return e.value.value;case`HumanName`:return _w(e.value);case`Quantity`:return Ow(e.value);case`Reference`:return hw(e.value);default:return e.value?.toString()??``}}function hw(e){return e?e.display??e.reference??DC(e):``}function gw(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 _w(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=Nw(e.text);if(t)return t}return n.join(` `).trim()}function vw(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function yw(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 vw(o)?new Intl.DateTimeFormat(t,{hour:`numeric`,minute:`2-digit`,second:a===0?void 0:`numeric`,...n,timeZone:`UTC`}).format(o):``}function bw(e,t,n){if(!e)return``;let r=new Date(e);return vw(r)?r.toLocaleString(t,n):``}function xw(e,t,n){return!e||!e.start&&!e.end?``:bw(e.start,t,n)+` - `+bw(e.end,t,n)}var Sw={s:`every second`,min:`every minute`,h:`hourly`,d:`daily`,wk:`weekly`,mo:`monthly`,a:`annually`},Cw={s:`second`,min:`minute`,h:`hour`,d:`day`,wk:`week`,mo:`month`,a:`year`},ww={s:`seconds`,min:`minutes`,h:`hours`,d:`days`,wk:`weeks`,mo:`months`,a:`years`};function Tw(e){if(!e)return``;let t=[];return Ew(t,e.repeat),e.event&&t.push(e.event.map(e=>bw(e)).join(`, `)),ZC(t.join(` `).trim())}function Ew(e,t){if(!t?.periodUnit)return;let n=t.frequency??1,r=t.period??1,i=t.periodUnit;n===1&&r===1?e.push(Sw[i]):(n===1?e.push(`once`):e.push(n+` times`),r===1?e.push(`per `+Cw[i]):e.push(`per `+r+` `+ww[i])),t.dayOfWeek&&e.push(`on `+t.dayOfWeek.map(ZC).join(`, `)),t.timeOfDay&&e.push(`at `+t.timeOfDay.map(e=>yw(e)).join(`, `))}function Dw(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=Fw(r.value,t),`> ${Ow(r,t)}`):`>= ${Ow(r,t)}`:r?.value===void 0&&i?.value!==void 0?n&&t!==void 0?(i.value=Pw(i.value,t),`< ${Ow(i,t)}`):`<= ${Ow(i,t)}`:(r?.unit===i?.unit&&delete r?.unit,`${Ow(r,t)} - ${Ow(i,t)}`)}function Ow(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 kw(e){return e?.value===void 0?``:e.value.toLocaleString(void 0,{style:`currency`,currency:e.currency??`USD`,currencyDisplay:`narrowSymbol`})}function Aw(e){return e?Nw(e.text)||(e.coding?e.coding.map(e=>jw(e)).join(`, `):``):``}function jw(e,t){let n=Nw(e?.display);if(n){let r=t?Nw(e?.code):void 0;return`${n}${r?` (`+r+`)`:``}`}return Nw(e?.code)??``}function Mw(e){if(!e)return``;let t=[];if(e.valueQuantity)t.push(Ow(e.valueQuantity));else if(e.valueCodeableConcept)t.push(Aw(e.valueCodeableConcept));else{let n=Nw(e.valueString);n&&t.push(n)}return`component`in e&&t.push(e.component.map(e=>Mw(e)).join(` / `)),t.join(` / `).trim()}function Nw(e){return typeof e==`string`?e:void 0}function Pw(e,t,n=1){return(Iw(e,t)+n)*10**-t}function Fw(e,t,n=1){return(Iw(e,t)-n)*10**-t}function Iw(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 Lw(e){let t=Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[];for(let e of t)e?.resourceType===`StructureDefinition`&&e.kind===`resource`&&Rw(e.type)}function Rw(e){let t=eT.types[e];t||(t={searchParamsDetails:{}},eT.types[e]=t);let n;return!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`,get target(){return n??=Uw(),n}},_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 zw(e){for(let t of e.base??pw){let n=Rw(t);n.searchParams||={},n.searchParams[e.code]=e}}function Bw(e){let t=e.type?.[0]?.code;return t===`BackboneElement`||t===`Element`?Vw((e.base?.path??e.path)?.split(`.`)):t}function Vw(e){return e.length===1?e[0]:e.map(ZC).join(``)}function Hw(e){return e.kind===`resource`&&e.name!==`Resource`&&e.name!==`DomainResource`}function Uw(){return Object.values(yS()).filter(Hw).map(e=>e.name)}function Ww(e){return eT.types[e]?.searchParams}function Gw(e,t){return eT.types[e]?.searchParams?.[t]}function Kw(e){return qw(e.replaceAll(`[x]`,``).split(`.`).pop())}function qw(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(Yw).join(` `).replace(`_`,` `).replaceAll(/\s+/g,` `)}var Jw=new Set([`CDS`,`ID`,`IP`,`JWKS`,`PKCE`,`OMB`,`OID`,`SOP`,`UDI`,`UID`,`URI`,`URL`]);function Yw(e){let t=e.toUpperCase();return e===t?e:Jw.has(t)?t:t.charAt(0)+e.slice(1)}function Xw(e,t,n){let r=xS(e,n);if(r)return Zw(r.elements,t)}function Zw(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 Qw(e,t){return!(!e||typeof e!=`object`||!(`resourceType`in e)||t&&e.resourceType!==t)}function $w(e,t){return e&&typeof e==`object`&&`reference`in e&&typeof e.reference==`string`?!t||e.reference.match(RegExp(`^${t}(/|\\?)`))!==null:!1}var eT={types:{}};function tT(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 nT=()=>[];function rT(e){return e instanceof dT?e.name:e instanceof bT&&e.left instanceof dT&&e.right instanceof dT?e.left.name+`.`+e.right.name:``}var iT={empty:(e,t)=>RS(t.every(e=>jC(e.value))),hasValue:(e,t)=>RS(t.length!==0),exists:(e,t,n)=>RS(n?t.some(t=>BS(n.eval(e,[t]))):t.length>0&&t.every(e=>!jC(e.value))),all:(e,t,n)=>RS(t.every(t=>BS(n.eval(e,[t])))),allTrue:(e,t)=>{for(let e of t)if(!e.value)return RS(!1);return RS(!0)},anyTrue:(e,t)=>{for(let e of t)if(e.value)return RS(!0);return RS(!1)},allFalse:(e,t)=>{for(let e of t)if(e.value)return RS(!1);return RS(!0)},anyFalse:(e,t)=>{for(let e of t)if(!e.value)return RS(!0);return RS(!1)},subsetOf:(e,t,n)=>{if(t.length===0)return RS(!0);let r=n.eval(e,cT(e));return r.length===0?RS(!1):RS(t.every(e=>r.some(t=>t.value===e.value)))},supersetOf:(e,t,n)=>{let r=n.eval(e,cT(e));return r.length===0?RS(!0):t.length===0?RS(!1):RS(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)=>RS(t.length===iT.distinct(e,t).length),where:(e,t,n)=>t.filter(t=>BS(n.eval(e,[t]))),select:(e,t,n)=>t.flatMap(t=>n.eval({parent:e,variables:{$this:t}},[t])),repeat:nT,ofType:(e,t,n)=>{let r=rT(n);return r?t.filter(e=>eC(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,cT(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,cT(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,cT(e));return KS([...t,...r])},combine:(e,t,n)=>{if(!n)return t;let r=n.eval(e,cT(e));return[...t,...r]},htmlChecks:(e,t,n)=>[zS(!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 BS(a)?r.eval(e,t):i?i.eval(e,t):[]},toBoolean:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);if(typeof n==`boolean`)return[{type:X.boolean,value:n}];if(typeof n==`number`&&(n===0||n===1))return RS(!!n);if(typeof n==`string`){let e=n.toLowerCase();if([`true`,`t`,`yes`,`y`,`1`,`1.0`].includes(e))return RS(!0);if([`false`,`f`,`no`,`n`,`0`,`0.0`].includes(e))return RS(!1)}return[]},convertsToBoolean:(e,t)=>t.length===0?[]:RS(iT.toBoolean(e,t).length===1),toInteger:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(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?[]:RS(iT.toInteger(e,t).length===1),toDate:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.date,value:tT(n)}]:[]},convertsToDate:(e,t)=>t.length===0?[]:RS(iT.toDate(e,t).length===1),toDateTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.dateTime,value:tT(n)}]:[]},convertsToDateTime:(e,t)=>t.length===0?[]:RS(iT.toDateTime(e,t).length===1),toDecimal:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(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?[]:RS(iT.toDecimal(e,t).length===1),toQuantity:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return oC(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?[]:RS(iT.toQuantity(e,t).length===1),toString:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return n==null?[]:oC(n)?[{type:X.string,value:`${n.value} '${n.unit}'`}]:[{type:X.string,value:n.toString()}]},convertsToString:(e,t)=>t.length===0?[]:RS(iT.toString(e,t).length===1),toTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);if(typeof n==`string`){let e=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(n);if(e)return[{type:X.time,value:tT(`T`+e[1])}]}return[]},convertsToTime:(e,t)=>t.length===0?[]:RS(iT.toTime(e,t).length===1),indexOf:(e,t,n)=>aT((e,t)=>e.indexOf(t),e,t,n),substring:(e,t,n,r)=>aT((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)=>aT((e,t)=>e.startsWith(t),e,t,n),endsWith:(e,t,n)=>aT((e,t)=>e.endsWith(t),e,t,n),contains:(e,t,n)=>aT((e,t)=>e.includes(t),e,t,n),upper:(e,t)=>aT(e=>e.toUpperCase(),e,t),lower:(e,t)=>aT(e=>e.toLowerCase(),e,t),replace:(e,t,n,r)=>aT((e,t,n)=>e.replaceAll(t,n),e,t,n,r),matches:(e,t,n)=>aT((e,t)=>!!new RegExp(t).exec(e),e,t,n),replaceMatches:(e,t,n,r)=>aT((e,t,n)=>e.replaceAll(new RegExp(t,`g`),n.replaceAll(/\$\{(\w+)\}/g,`$<$1>`)),e,t,n,r),length:(e,t)=>aT(e=>e.length,e,t),toChars:(e,t)=>aT(e=>e?e.split(``):void 0,e,t),encode:nT,decode:nT,escape:nT,unescape:nT,trim:nT,split:nT,join:(e,t,n)=>{let r=n?.eval(e,cT(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)=>oT(Math.abs,e,t),ceiling:(e,t)=>oT(Math.ceil,e,t),exp:(e,t)=>oT(Math.exp,e,t),floor:(e,t)=>oT(Math.floor,e,t),ln:(e,t)=>oT(Math.log,e,t),log:(e,t,n)=>oT((e,t)=>Math.log(e)/Math.log(t),e,t,n),power:(e,t,n)=>oT(Math.pow,e,t,n),round:(e,t,...n)=>oT((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)=>oT(Math.sqrt,e,t),truncate:(e,t)=>oT(e=>Math.trunc(e),e,t),children:nT,descendants:nT,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=iT.toDateTime(e,n.eval(e,t));if(a.length===0)throw Error(`Invalid start date`);let o=iT.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=CC(a[0].value,o[0].value);return[{type:X.Quantity,value:{value:c[s],unit:s}}]},is:(e,t,n)=>{let r=rT(n);return r?t.map(e=>({type:X.boolean,value:eC(e,r)})):[]},not:(e,t)=>iT.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 zS(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=rT(n);if(!r)throw Error(`Expected a valid type identifier as the right operand of 'as', but found ${n.toString()}`);let i=VS(t);return i&&eC(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`}}:Qw(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 dT&&(i=n.name),i&&!r.reference.startsWith(i+`/`)?[]:[{type:X.id,value:hC(r)}]},extension:(e,t,n)=>{let r=n.eval(e,t)[0].value,i=t?.[0]?.value;if(i){let e=EC(i,r);if(e)return[{type:X.Extension,value:e}]}return[]}};function aT(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=sT(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(zS):[zS(a)]}function oT(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=sT(n,1),a=oC(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 sT(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 cT(e){let t=e;for(;t.parent?.variables.$this;)t=t.parent;return[t.variables.$this]}var lT=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()}return this.child.eval(e,[])}catch(e){throw Error(`FhirPathError on "${this.original}": ${e}`,{cause:e})}}toString(){return this.child.toString()}},uT=class{value;constructor(e){this.value=e}eval(){return[this.value]}toString(){let e=this.value.value;return typeof e==`string`?`'${e}'`:e.toString()}},dT=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 Qw(t,this.name)?(`path`in e||(e.path=t.resourceType),e):PS(e,this.name)}toString(){return this.name}},fT=class{eval(){return[]}toString(){return`{}`}},pT=class extends xx{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()}},mT=class extends Sx{constructor(e,t){super(`as`,e,t)}eval(e,t){return iT.as(e,this.left.eval(e,t),this.right)}},hT=class extends Sx{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=VS(n)?.value,a=VS(r)?.value,o=oC(i)?i.value:i,s=oC(a)?a.value:a,c=this.impl(o,s);return typeof c==`boolean`?RS(c):oC(i)?[{type:X.Quantity,value:{...i,value:c}}]:[zS(c)]}},gT=Object.freeze({type:`string`,value:``}),_T=class extends Sx{constructor(e,t){super(`&`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t))??gT,r=VS(this.right.eval(e,t))??gT;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}]}},vT=class extends Sx{constructor(e,t){super(`contains`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return RS(n.some(e=>e.value===r[0].value))}},yT=class extends Sx{constructor(e,t){super(`in`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t)),r=this.right.eval(e,t);return n?RS(r.some(e=>XS(n,e)[0].value)):[]}},bT=class extends Sx{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()}`}},xT=class extends Sx{constructor(e,t){super(`|`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return KS([...n,...r])}},ST=class extends Sx{constructor(e,t){super(`=`,e,t)}eval(e,t){return JS(this.left.eval(e,t),this.right.eval(e,t))}},CT=class extends Sx{constructor(e,t){super(`!=`,e,t)}eval(e,t){return YS(this.left.eval(e,t),this.right.eval(e,t))}},wT=class extends Sx{constructor(e,t){super(`~`,e,t)}eval(e,t){return ZS(this.left.eval(e,t),this.right.eval(e,t))}},TT=class extends Sx{constructor(e,t){super(`!~`,e,t)}eval(e,t){return qS(ZS(this.left.eval(e,t),this.right.eval(e,t)))}},ET=class extends Sx{constructor(e,t){super(`is`,e,t)}eval(e,t){let n=this.left.eval(e,t);if(n.length!==1)return[];let r=rT(this.right);return r?RS(eC(n[0],r)):[]}},DT=class extends Sx{constructor(e,t){super(`and`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return n?.value===!0&&r?.value===!0?RS(!0):n?.value===!1||r?.value===!1?RS(!1):[]}},OT=class extends Sx{constructor(e,t){super(`or`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return n?.value===!1&&r?.value===!1?RS(!1):n?.value||r?.value?RS(!0):[]}},kT=class extends Sx{constructor(e,t){super(`xor`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return!n||!r?[]:RS(n.value!==r.value)}},AT=class extends Sx{constructor(e,t){super(`implies`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return r?.value===!0||n?.value===!1?RS(!0):!n||!r?[]:RS(!1)}},jT=class{name;args;constructor(e,t){this.name=e,this.args=t}eval(e,t){let n=iT[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(`, `)})`}},MT=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()}]`}},NT=[`year`,`years`,`month`,`months`,`week`,`weeks`,`day`,`days`,`hour`,`hours`,`minute`,`minutes`,`second`,`seconds`,`millisecond`,`milliseconds`],PT=/^\d{4}-\d{2}[\dT:.+\-Z]*(?=[\s)\]]|$)/,FT={"'":`'`,'"':`"`,"`":"`",r:`\r`,n:`
|
|
53
|
+
`),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}function g_(e){e=h_(e),e.decimalSeparator,e.allowedDecimalSeparators,e.thousandsGroupStyle;var t=e.suffix,n=e.allowNegative,r=e.allowLeadingZeros,i=e.onKeyDown;i===void 0&&(i=jg);var a=e.onBlur;a===void 0&&(a=jg);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=kg(e,[`decimalSeparator`,`allowedDecimalSeparators`,`thousandsGroupStyle`,`suffix`,`allowNegative`,`allowLeadingZeros`,`onKeyDown`,`onBlur`,`thousandSeparator`,`decimalScale`,`fixedDecimalScale`,`prefix`,`defaultValue`,`value`,`valueIsNumericString`,`onValueChange`]),h=l_(e),g=h.decimalSeparator,_=h.allowedDecimalSeparators,v=function(t){return c_(t,e)},y=function(t,n){return p_(t,n,e)},b=Pg(d)?u:d,x=f??f_(b,l,t);Pg(d)?Pg(u)||(x||=typeof u==`number`):x||=typeof d==`number`;var S=function(e){return Ig(e)?e:(typeof e==`number`&&(e=Gg(e)),x&&typeof s==`number`?Kg(e,s,!!c):e)},C=i_(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||Ng(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=Jg(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 m_(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&&qg(t,1),s&&c&&(r===`Backspace`&&d[a-1]===g?(qg(t,a-1),e.preventDefault()):r===`Delete`&&d[a]===g&&e.preventDefault()),_?.includes(r)&&d[a]===g&&qg(t,a+1);var f=o===!0?`,`:o;r===`Backspace`&&d[a-1]===f&&qg(t,a-1),r===`Delete`&&d[a]===f&&qg(t,a+1),i(e)},onBlur:function(t){var n=T;n.match(/\d/g)||(n=``),r||(n=Hg(n)),c&&s&&(n=Kg(n,s,c)),n!==T&&D({formattedValue:c_(n,e),value:n,floatValue:parseFloat(n)},{event:t,source:Ag.event}),a(t)}})}function __(e){var t=g_(e);return b.createElement(s_,Object.assign({},t))}var v_={root:`m_e2f5cd4e`,controls:`m_95e17d22`,control:`m_80b4b171`};function y_({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 b_=/^(0\.0*|-0(\.0*)?)$/,x_=/^-?0\d+(\.\d+)?\.?$/,S_=/\.\d*0$/,C_=/^-?\d+\.$/;function w_(e){return typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))}function T_(e){return typeof e==`number`?e<2**53-1:e===``||w_(e)&&Number(e)<2**53-1}function E_(e){return e.toString().replace(`.`,``).length}function D_(e,t){return(typeof e==`number`?e<2**53-1:!Number.isNaN(Number(e)))&&!Number.isNaN(e)&&E_(t)<14&&t!==``}function O_(e,t,n){return e===void 0||(t===void 0||e>=t)&&(n===void 0||e<=n)}var k_={step:1,clampBehavior:`blur`,allowDecimal:!0,allowNegative:!0,withKeyboardEvents:!0,allowLeadingZeros:!0,trimLeadingZeroesOnBlur:!0,startValue:0,allowedDecimalSeparators:[`.`,`,`]},A_=An((e,{size:t})=>({controls:{"--ni-chevron-size":ft(t,`ni-chevron-size`)}}));function j_(e,t,n){let r=e.toString(),i=C_.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=Ct(o,n,t);return i?`${s.toString().replace(/^0+(?=\d)/,``)}.`:s}var M_=B((e,t)=>{let n=R(`NumberInput`,k_,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:v_,props:n,classNames:i,styles:a,unstyled:o,attributes:ie,vars:s,varsResolver:A_}),{resolvedClassNames:se,resolvedStyles:ce}=Hr({classNames:i,styles:a,props:n}),[le,ue]=an({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(D_(e.floatValue,e.value)&&!b_.test(e.value)&&!(P&&x_.test(e.value))&&!S_.test(e.value)&&!C_.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)(ut);ve.current=()=>{if(!T_(le))return;let e,t=ge(le),n=ge(m),r=Math.max(t,n),i=10**r;if(!w_(le)&&(typeof le!=`number`||Number.isNaN(le)))e=Ct(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)(ut);ye.current=()=>{if(!T_(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(!w_(le)&&typeof le!=`number`||Number.isNaN(le))e=Ct(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=Ct(t,p,f)),ne&&typeof t==`string`&&ge(t)<15&&(t=j_(t,f,p)),le!==t&&ue(t),y?.(e)};tn(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)(fl,{...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)(y_,{direction:`up`})}),(0,I.jsx)(fl,{...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)(y_,{direction:`down`})})]});return(0,I.jsx)(fd,{component:__,allowNegative:k,className:Mn(v_.root,r),size:j,inputMode:`decimal`,...ae,readOnly:A,disabled:D,value:le,getInputRef:rn(t,fe),onValueChange:he,rightSection:h||A||!T_(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)&&O_(e.floatValue,p,f):O_(e.floatValue,p,f):!_||_(e)})});M_.classes={...fd.classes,...v_},M_.displayName=`@mantine/core/NumberInput`;var N_={root:`m_4addd315`,control:`m_326d024a`,dots:`m_4ad7767d`},[P_,F_]=et(`Pagination.Root component was not found in tree`),I_={withPadding:!0},L_=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`,I_,e),f=F_(),p=c||f.disabled;return(0,I.jsx)(fl,{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})});L_.classes=N_,L_.displayName=`@mantine/core/PaginationControl`;function R_({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 z_=e=>(0,I.jsx)(R_,{...e,path:`M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z`}),B_=e=>(0,I.jsx)(R_,{...e,path:`M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z`}),V_=e=>(0,I.jsx)(R_,{...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`}),H_=e=>(0,I.jsx)(R_,{...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`}),U_={icon:e=>(0,I.jsx)(R_,{...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`})},W_=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,icon:s,...c}=R(`PaginationDots`,U_,e),l=F_();return(0,I.jsx)(z,{ref:t,...l.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)`}})})});W_.classes=N_,W_.displayName=`@mantine/core/PaginationDots`;function G_({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=F_(),l=r===`next`?c.active===c.total:c.active===1;return(0,I.jsx)(L_,{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}`,Li(a)}var K_=G_({icon:z_,name:`PaginationNext`,action:`onNext`,type:`next`}),q_=G_({icon:B_,name:`PaginationPrevious`,action:`onPrevious`,type:`previous`}),J_=G_({icon:V_,name:`PaginationFirst`,action:`onFirst`,type:`previous`}),Y_=G_({icon:H_,name:`PaginationLast`,action:`onLast`,type:`next`});function X_({dotsIcon:e}){let t=F_(),n=t.range.map((n,r)=>n===`dots`?(0,I.jsx)(W_,{icon:e},r):(0,I.jsx)(L_,{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));return(0,I.jsx)(I.Fragment,{children:n})}X_.displayName=`@mantine/core/PaginationItems`;var Z_={siblings:1,boundaries:1},Q_=An((e,{size:t,radius:n,color:r,autoContrast:i})=>({root:{"--pagination-control-radius":n===void 0?void 0:mt(n),"--pagination-control-size":ft(t,`pagination-control-size`),"--pagination-control-fz":ht(t),"--pagination-active-bg":r?ar(r,e):void 0,"--pagination-active-color":ai(i,e)?Dr({color:r,theme:e,autoContrast:i}):void 0}})),$_=B((e,t)=>{let n=R(`PaginationRoot`,Z_,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:N_,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}=cn({page:u,initialPage:d,onChange:f,total:l,siblings:m,boundaries:h}),N=vt(v,k),P=vt(y,A),te=vt(b,M),ne=vt(x,ee);return(0,I.jsx)(P_,{value:{total:l,range:D,active:j,disabled:p,getItemProps:S,onChange:O,onNext:N,onPrevious:P,onFirst:te,onLast:ne,getStyles:E},children:(0,I.jsx)(z,{ref:t,...E(`root`),...T})})});$_.classes=N_,$_.displayName=`@mantine/core/PaginationRoot`;var ev={withControls:!0,withPages:!0,siblings:1,boundaries:1,gap:8},tv=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`,ev,e);return u<=0||f&&u===1?null:(0,I.jsx)($_,{ref:t,total:u,...m,children:(0,I.jsxs)(V,{gap:d,children:[n&&(0,I.jsx)(J_,{icon:c,...i?.(`first`)}),r&&(0,I.jsx)(q_,{icon:o,...i?.(`previous`)}),p&&(0,I.jsx)(X_,{dotsIcon:l}),r&&(0,I.jsx)(K_,{icon:a,...i?.(`next`)}),n&&(0,I.jsx)(Y_,{icon:s,...i?.(`last`)})]})})});tv.classes=N_,tv.displayName=`@mantine/core/Pagination`,tv.Root=$_,tv.Control=L_,tv.Dots=W_,tv.First=J_,tv.Last=Y_,tv.Next=K_,tv.Previous=q_,tv.Items=X_;var nv={root:`m_f61ca620`,input:`m_ccf8da4c`,innerInput:`m_f2d85dd2`,visibilityToggle:`m_b1072d44`},rv={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`})})},iv=An((e,{size:t})=>({root:{"--psi-icon-size":ft(t,`psi-icon-size`),"--psi-button-size":ft(t,`psi-button-size`)}})),av=B((e,t)=>{let n=R(`PasswordInput`,rv,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=$t(p),[ce,le]=an({value:A,defaultValue:j,finalValue:!1,onChange:M}),ue=()=>le(!ce),de=L({name:`PasswordInput`,classes:nv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:ae,vars:c,varsResolver:iv}),{resolvedClassNames:fe,resolvedStyles:pe}=Hr({classNames:r,styles:o,props:n}),{styleProps:me,rest:he}=fi(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)(mu,{...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)(ld.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)(ld,{component:`div`,error:u,leftSection:d,size:v,classNames:{...fe,input:Mn(nv.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`})})})});av.classes={...fd.classes,...nv},av.displayName=`@mantine/core/PasswordInput`;var ov={root:`m_db6d6462`,section:`m_2242eb65`,"stripes-animation":`m_81a374bd`,"stripes-animation-vertical":`m_e0fb7a86`,label:`m_91e40b74`},[sv,cv]=et(`Progress.Root component was not found in tree`),lv=B((e,t)=>{let{classNames:n,className:r,style:i,styles:a,vars:o,...s}=R(`ProgressLabel`,null,e),c=cv();return(0,I.jsx)(z,{ref:t,...c.getStyles(`label`,{className:r,style:i,classNames:n,styles:a}),...s})});lv.classes=ov,lv.displayName=`@mantine/core/ProgressLabel`;var uv=An((e,{size:t,radius:n,transitionDuration:r})=>({root:{"--progress-size":ft(t,`progress-size`),"--progress-radius":n===void 0?void 0:mt(n),"--progress-transition-duration":typeof r==`number`?`${r}ms`:void 0}})),dv=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:ov,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:f,vars:c,varsResolver:uv});return(0,I.jsx)(sv,{value:{getStyles:h,autoContrast:l},children:(0,I.jsx)(z,{ref:t,mod:[{orientation:d},p],...h(`root`),...m})})});dv.classes=ov,dv.displayName=`@mantine/core/ProgressRoot`;var fv={withAria:!0},pv=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`,fv,e),m=cv(),h=Sr(),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":ar(l,h),"--progress-label-color":ai(m.autoContrast,h)?Dr({color:l,theme:h,autoContrast:m.autoContrast}):void 0}})});pv.classes=ov,pv.displayName=`@mantine/core/ProgressSection`;var mv=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}=Hr({classNames:i,styles:a,props:n});return(0,I.jsx)(dv,{ref:t,classNames:f,styles:p,vars:o,...d,children:(0,I.jsx)(pv,{value:r,color:s,striped:c,animated:l,"aria-label":u})})});mv.classes=ov,mv.displayName=`@mantine/core/Progress`,mv.Section=pv,mv.Root=dv,mv.Label=lv;var hv={root:`m_f3f1af94`,inner:`m_89c4f5e4`,icon:`m_f3ed6b2b`,radio:`m_8a3dbb89`,"radio--outline":`m_1bfe9d39`},[gv,_v]=tt(),[vv,yv]=tt(),bv={card:`m_9dc8ae12`},xv={withBorder:!0},Sv=An((e,{radius:t})=>({card:{"--card-radius":mt(t)}})),Cv=B((e,t)=>{let n=R(`RadioCard`,xv,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:bv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:Sv,rootSelector:`card`}),{dir:y}=Ji(),b=_v(),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)(vv,{value:{checked:x},children:(0,I.jsx)(fl,{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})})});Cv.displayName=`@mantine/core/RadioCard`,Cv.classes=bv;var wv=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=$t(c),[p,m]=an({value:n,defaultValue:r,finalValue:``,onChange:i});return(0,I.jsx)(gv,{value:{value:p,onChange:e=>!l&&m(typeof e==`string`?e:e.currentTarget.value),size:a,name:f,disabled:u},children:(0,I.jsx)(ld.Wrapper,{size:a,ref:t,...o,...d,labelElement:`div`,__staticSelector:`RadioGroup`,children:(0,I.jsx)(Zf,{role:`radiogroup`,children:s})})})});wv.classes=ld.Wrapper.classes,wv.displayName=`@mantine/core/RadioGroup`;function Tv({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 Ev={indicator:`m_717d7ff6`,icon:`m_3e4da632`,"indicator--outline":`m_2980836c`},Dv={icon:Tv},Ov=An((e,{radius:t,color:n,size:r,iconColor:i,variant:a,autoContrast:o})=>{let s=ir({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":ft(r,`radio-size`),"--radio-radius":t===void 0?void 0:mt(t),"--radio-color":a===`outline`?c:ar(n,e),"--radio-icon-size":ft(r,`radio-icon-size`),"--radio-icon-color":i?ar(i,e):ai(o,e)?Dr({color:n,theme:e,autoContrast:o}):void 0}}}),kv=B((e,t)=>{let n=R(`RadioIndicator`,Dv,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:Ev,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:v,vars:c,varsResolver:Ov,rootSelector:`indicator`}),x=yv(),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`)})})});kv.displayName=`@mantine/core/RadioIndicator`,kv.classes=Ev;var Av={labelPosition:`right`},jv=An((e,{size:t,radius:n,color:r,iconColor:i,variant:a,autoContrast:o})=>{let s=ir({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":ft(t,`radio-size`),"--radio-radius":n===void 0?void 0:mt(n),"--radio-color":a===`outline`?c:ar(r,e),"--radio-icon-color":i?ar(i,e):ai(o,e)?Dr({color:r,theme:e,autoContrast:o}):void 0,"--radio-icon-size":ft(t,`radio-icon-size`)}}}),Mv=B((e,t)=>{let n=R(`Radio`,Av,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=Tv,rootRef:x,iconColor:S,onChange:C,mod:w,attributes:T,checked:E,...D}=n,O=L({name:`Radio`,classes:hv,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:T,vars:c,varsResolver:jv}),k=_v(),A=k?.size??u,j=n.size?u:A,{styleProps:M,rest:ee}=fi(D),N=$t(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)(Bf,{...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})]})})});Mv.classes=hv,Mv.displayName=`@mantine/core/Radio`,Mv.Group=wv,Mv.Card=Cv,Mv.Indicator=kv;var Nv={duration:100,transition:`fade`};function Pv(e,t){return{...Nv,...t,...e}}var Fv={tooltip:`m_1b3c8819`,arrow:`m_f898399f`};function Iv({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}=Sc({placement:t,middleware:[Ms({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=ba(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 Lv={refProp:`ref`,withinPortal:!0,offset:10,position:`right`,zIndex:lt(`popover`)},Rv=An((e,{radius:t,color:n})=>({tooltip:{"--tooltip-radius":t===void 0?void 0:mt(t),"--tooltip-bg":n?ar(n,e):void 0,"--tooltip-color":n?`var(--mantine-color-white)`:void 0}})),zv=B((e,t)=>{let n=R(`TooltipFloating`,Lv,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=Sr(),D=L({name:`TooltipFloating`,props:n,classes:Fv,className:s,style:o,classNames:c,styles:l,unstyled:u,attributes:w,rootSelector:`tooltip`,vars:S,varsResolver:Rv}),{handleMouseMove:O,x:k,y:A,opened:j,boundaryRef:M,floating:ee,setOpened:N}=Iv({offset:m,position:h,defaultOpened:y}),P=kn(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=rn(M,Tn(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)(Ml,{...C,withinPortal:a,children:(0,I.jsx)(z,{...T,...D(`tooltip`,{style:{...Ii(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})]})});zv.classes=Fv,zv.displayName=`@mantine/core/TooltipFloating`;var Bv=(0,b.createContext)(!1),Vv=Bv.Provider,Hv=()=>(0,b.useContext)(Bv),Uv={openDelay:0,closeDelay:0};function Wv(e){let{openDelay:t,closeDelay:n,children:r}=R(`TooltipGroup`,Uv,e);return(0,I.jsx)(Vv,{value:!0,children:(0,I.jsx)(hc,{delay:{open:t,close:n},children:r})})}Wv.displayName=`@mantine/core/TooltipGroup`,Wv.extend=e=>e;function Gv(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 Kv(e){let t=Gv(e.middlewares),n=[js(e.offset)];return t.shift&&n.push(Ms(typeof t.shift==`boolean`?{padding:8}:{padding:8,...t.shift})),t.flip&&n.push(typeof t.flip==`boolean`?Ps():Ps(t.flip)),n.push(Rs({element:e.arrowRef,padding:e.arrowOffset})),t.inline?n.push(typeof t.inline==`boolean`?Ls():Ls(t.inline)):e.inline&&n.push(Ls()),n}function qv(e){let[t,n]=(0,b.useState)(e.defaultOpened),r=typeof e.opened==`boolean`?e.opened:t,i=Hv(),a=$t(),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}={}}}=Sc({strategy:e.strategy,placement:e.position,open:r,onOpenChange:o,middleware:Kv(e),whileElementsMounted:ps}),{delay:m,currentId:h,setCurrentId:g}=gc(l,{id:a}),{getReferenceProps:_,getFloatingProps:v}=Ec([dc(l,{enabled:e.events?.hover,delay:i?m:{open:e.openDelay,close:e.closeDelay},mouseOnly:!e.events?.touch}),wc(l,{enabled:e.events?.focus,visibleOnly:!0}),Oc(l,{role:`tooltip`}),bc(l,{enabled:e.opened===void 0})]);Lt(()=>{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 Jv={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:lt(`popover`),positionDependencies:[],middlewares:{flip:!0,shift:!0,inline:!1}},Yv=An((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:mt(t),"--tooltip-bg":n?a.background:void 0,"--tooltip-color":n?a.color:void 0}}}),Xv=B((e,t)=>{let n=R(`Tooltip`,Jv,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`,Jv,n),{dir:pe}=Ji(),me=(0,b.useRef)(null),he=qv({position:Cl(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:Fv,className:y,style:v,classNames:h,styles:g,unstyled:_,attributes:ue,rootSelector:`tooltip`,vars:ie,varsResolver:Yv}),_e=kn(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=Pv(D,{duration:100,transition:`fade`});return(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(Ml,{...ae,withinPortal:f,children:(0,I.jsx)(Rl,{...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)(Sl,{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=rn(he.reference,Tn(_e),t),be=Pv(D,{duration:100,transition:`fade`});return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Ml,{...ae,withinPortal:f,children:(0,I.jsx)(Rl,{...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)(Sl,{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:Mn(y,ve.className),[a]:ye}))]})});Xv.classes=Fv,Xv.displayName=`@mantine/core/Tooltip`,Xv.Floating=zv,Xv.Group=Wv;function Zv({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 Qv({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=Sr();return(0,I.jsx)(Xv.Floating,{disabled:!c,label:c,children:(0,I.jsx)(z,{component:`circle`,...d,...l(`curve`),__vars:{"--curve-color":o?ar(o,f):void 0},fill:`none`,strokeLinecap:s?`round`:`butt`,...Zv({sum:r,size:e,thickness:i,value:t,offset:n,root:a})})})}Qv.displayName=`@mantine/core/Curve`;function $v({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 ey={root:`m_b32e4812`,svg:`m_d43b5134`,curve:`m_b1ca1fbf`,label:`m_b23f9dc4`};function ty(e,t){return Math.min(e||12,(t||120)/4)}var ny={size:120,thickness:12},ry=An((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}})),iy=B((e,t)=>{let n=R(`RingProgress`,ny,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:ey,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:ry}),y=ty(f,d),x=$v({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)(Qv,{...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})]})});iy.classes=ey,iy.displayName=`@mantine/core/RingProgress`;var ay={root:`m_cf365364`,indicator:`m_9e182ccd`,label:`m_1738fcb2`,input:`m_1714d588`,control:`m_69686b9b`,innerLabel:`m_78882f40`},oy={withItemsBorders:!0},sy=An((e,{radius:t,color:n,transitionDuration:r,size:i,transitionTimingFunction:a})=>({root:{"--sc-radius":t===void 0?void 0:mt(t),"--sc-color":n?ar(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":ft(i,`sc-padding`),"--sc-font-size":ht(i)}})),cy=B((e,t)=>{let n=R(`SegmentedControl`,oy,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:ay,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:O,vars:c,varsResolver:sy}),j=Sr(),M=l.map(e=>typeof e==`string`?{label:e,value:e}:e),ee=Cn(),[N,P]=(0,b.useState)(wt()),[te,ne]=(0,b.useState)(null),[re,ie]=(0,b.useState)({}),ae=(e,t)=>{re[t]=e,ie(re)},[oe,se]=an({value:u,defaultValue:d,finalValue:Array.isArray(l)?M.find(e=>!e.disabled)?.value??l[0]?.value??null:null,onChange:f}),ce=$t(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:Dr({color:x,theme:j,autoContrast:T})},key:`${e.value}-label`},(0,I.jsx)(`span`,{...A(`innerLabel`),children:e.label})))),ue=rn(t,e=>ne(e));return fn(()=>{P(wt())},[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)(bd,{target:re[oe],parent:te,component:`span`,transitionDuration:`var(--sc-transition-duration)`,...A(`indicator`)},N),le]})});cy.classes=ay,cy.displayName=`@mantine/core/SegmentedControl`;var ly={container:`m_925c2d2c`,root:`m_2415a157`};function uy({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=Sr(),a=t===void 0?e:t,o=Xe({"--sg-spacing-x":pt(xt(e)),"--sg-spacing-y":pt(xt(a)),"--sg-cols":xt(n)?.toString()}),s=Ve(i.breakpoints).reduce((t,r)=>(t[r]||(t[r]={}),typeof e==`object`&&e[r]!==void 0&&(t[r][`--sg-spacing-x`]=pt(e[r])),typeof a==`object`&&a[r]!==void 0&&(t[r][`--sg-spacing-y`]=pt(a[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{}),c=bt(Ve(s),i.breakpoints).filter(e=>Ve(s[e.value]).length>0).map(e=>({query:`(min-width: ${i.breakpoints[e.value]})`,styles:s[e.value]}));return(0,I.jsx)(di,{styles:o,media:c,selector:r})}function dy(e){return typeof e==`object`&&e?Ve(e):[]}function fy(e){return e.sort((e,t)=>Ke(e)-Ke(t))}function py({spacing:e,verticalSpacing:t,cols:n}){return fy(Array.from(new Set([...dy(e),...dy(t),...dy(n)])))}function my({spacing:e,verticalSpacing:t,cols:n,selector:r}){let i=t===void 0?e:t,a=Xe({"--sg-spacing-x":pt(xt(e)),"--sg-spacing-y":pt(xt(i)),"--sg-cols":xt(n)?.toString()}),o=py({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`]=pt(e[r])),typeof i==`object`&&i[r]!==void 0&&(t[r][`--sg-spacing-y`]=pt(i[r])),typeof n==`object`&&n[r]!==void 0&&(t[r][`--sg-cols`]=n[r]),t),{}),c=o.map(e=>({query:`simple-grid (min-width: ${e})`,styles:s[e]}));return(0,I.jsx)(di,{styles:a,container:c,selector:r})}var hy={cols:1,spacing:`md`,type:`media`},gy=B((e,t)=>{let n=R(`SimpleGrid`,hy,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:ly,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c}),g=Fi();return f===`container`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(my,{...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)(uy,{...n,selector:`.${g}`}),(0,I.jsx)(z,{ref:t,...h(`root`,{className:g}),...m})]})});gy.classes=ly,gy.displayName=`@mantine/core/SimpleGrid`;var _y={root:`m_18320242`,"skeleton-fade":`m_299c329c`},vy={visible:!0,animate:!0},yy=An((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:mt(r)}})),by=B((e,t)=>{let n=R(`Skeleton`,vy,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,v=L({name:`Skeleton`,classes:_y,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:g,vars:c,varsResolver:yy});return(0,I.jsx)(z,{ref:t,...v(`root`),mod:[{visible:f,animate:m},h],..._})});by.classes=_y,by.displayName=`@mantine/core/Skeleton`;var xy=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})});xy.displayName=`@mantine/core/Space`;var Sy={root:`m_6d731127`},Cy={gap:`md`,align:`stretch`,justify:`flex-start`},wy=An((e,{gap:t,align:n,justify:r})=>({root:{"--stack-gap":pt(t),"--stack-align":n,"--stack-justify":r}})),G=B((e,t)=>{let n=R(`Stack`,Cy,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,h=L({name:`Stack`,props:n,classes:Sy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c,varsResolver:wy});return(0,I.jsx)(z,{ref:t,...h(`root`),variant:f,...m})});G.classes=Sy,G.displayName=`@mantine/core/Stack`;var[Ty,Ey]=et(`Stepper component was not found in tree`),Dy={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`},Oy=()=>null;Oy.displayName=`@mantine/core/StepperCompleted`;var ky=(e,t)=>typeof e==`function`?(0,I.jsx)(e,{step:t||0}):e,Ay={withIcon:!0,allowStepClick:!0,iconPosition:`left`},jy=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`,Ay,e),w=Ey(),T=Sr(),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)(fl,{...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?ar(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)(Rl,{mounted:c===`stepCompleted`,transition:`pop`,duration:200,children:e=>(0,I.jsx)(`span`,{...w.getStyles(`stepCompletedIcon`,{style:e,...E}),children:_?(0,I.jsx)(ou,{color:`var(--mantine-color-white)`,size:`calc(var(--stepper-icon-size) / 2)`,...w.getStyles(`stepLoader`,E)}):ky(d,s)||(0,I.jsx)($f,{size:`60%`})})}),c===`stepCompleted`?null:(0,I.jsx)(`span`,{children:_?(0,I.jsx)(ou,{...w.getStyles(`stepLoader`,E),size:`calc(var(--stepper-icon-size) / 2)`,color:l}):ky(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:ky(p,s)}),m&&(0,I.jsx)(`span`,{...w.getStyles(`stepDescription`,E),children:ky(m,s)})]})]})});jy.classes=Dy,jy.displayName=`@mantine/core/StepperStep`;var My={orientation:`horizontal`,iconPosition:`left`,allowNextStepsSelect:!0,wrap:!0},Ny=An((e,{color:t,iconSize:n,size:r,contentPadding:i,radius:a,autoContrast:o})=>({root:{"--stepper-color":t?ar(t,e):void 0,"--stepper-icon-color":ai(o,e)?Dr({color:t,theme:e,autoContrast:o}):void 0,"--stepper-icon-size":n===void 0?ft(r,`stepper-icon-size`):F(n),"--stepper-content-padding":pt(i),"--stepper-radius":a===void 0?void 0:mt(a),"--stepper-fz":ht(r),"--stepper-spacing":pt(r)}})),Py=B((e,t)=>{let n=R(`Stepper`,My,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:Dy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:E,vars:c,varsResolver:Ny}),k=b.Children.toArray(l),A=k.filter(e=>e.type!==Oy),j=k.find(e=>e.type===Oy),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)(Ty,{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})]})})});Py.classes=Dy,Py.displayName=`@mantine/core/Stepper`,Py.Completed=Oy,Py.Step=jy;var Fy={root:`m_5f93f3bb`,input:`m_926b4011`,track:`m_9307d992`,thumb:`m_93039a1d`,trackLabel:`m_8277e082`},Iy=(0,b.createContext)(null),Ly=Iy.Provider,Ry=()=>(0,b.useContext)(Iy),zy=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]=an({value:n,defaultValue:r,finalValue:[],onChange:i});return(0,I.jsx)(Ly,{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)(ld.Wrapper,{size:a,ref:t,...o,...u,labelElement:`div`,__staticSelector:`SwitchGroup`,children:(0,I.jsx)(Zf,{role:`group`,children:s})})})});zy.classes=ld.Wrapper.classes,zy.displayName=`@mantine/core/SwitchGroup`;var By={labelPosition:`right`,withThumbIndicator:!0},Vy=An((e,{radius:t,color:n,size:r})=>({root:{"--switch-radius":t===void 0?void 0:mt(t),"--switch-height":ft(r,`switch-height`),"--switch-width":ft(r,`switch-width`),"--switch-thumb-size":ft(r,`switch-thumb-size`),"--switch-label-font-size":ft(r,`switch-label-font-size`),"--switch-track-label-padding":ft(r,`switch-track-label-padding`),"--switch-color":n?ar(n,e):void 0}})),Hy=B((e,t)=>{let n=R(`Switch`,By,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=Ry(),M=m||j?.size,ee=L({name:`Switch`,props:n,classes:Fy,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:k,vars:c,varsResolver:Vy}),{styleProps:N,rest:P}=fi(A),te=$t(p),ne={checked:j?.value.includes(P.value)??v,onChange:e=>{j?.onChange(e),b?.(e)},disabled:j?.disabled??w},[re,ie]=an({value:ne.checked??v,defaultValue:y,finalValue:!1});return(0,I.jsxs)(Bf,{...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})]})]})});Hy.classes={...Fy,...zf},Hy.displayName=`@mantine/core/Switch`,Hy.Group=zy;var[Uy,Wy]=et(`Table component was not found in the tree`),Gy={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 Ky(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 qy(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=Wy();return(0,I.jsx)(z,{component:e,ref:i,...Ky(d,t),...d.getStyles(e,{className:s,classNames:o,style:c,styles:l,props:a}),...u})});return r.displayName=`@mantine/core/${n}`,r.classes=Gy,r}var Jy=qy(`th`,{columnBorder:!0}),Yy=qy(`td`,{columnBorder:!0}),Xy=qy(`tr`,{rowBorder:!0,striped:!0,highlightOnHover:!0}),Zy=qy(`thead`,{stickyHeader:!0}),Qy=qy(`tbody`),$y=qy(`tfoot`),eb=qy(`caption`,{captionSide:!0});function tb({data:e}){return(0,I.jsxs)(I.Fragment,{children:[e.caption&&(0,I.jsx)(eb,{children:e.caption}),e.head&&(0,I.jsx)(Zy,{children:(0,I.jsx)(Xy,{children:e.head.map((e,t)=>(0,I.jsx)(Jy,{children:e},t))})}),e.body&&(0,I.jsx)(Qy,{children:e.body.map((e,t)=>(0,I.jsx)(Xy,{children:e.map((e,t)=>(0,I.jsx)(Yy,{children:e},t))},t))}),e.foot&&(0,I.jsx)($y,{children:(0,I.jsx)(Xy,{children:e.foot.map((e,t)=>(0,I.jsx)(Jy,{children:e},t))})})]})}tb.displayName=`@mantine/core/TableDataRenderer`;var nb={type:`scrollarea`},rb=An((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}})),ib=B((e,t)=>{let n=R(`TableScrollContainer`,nb,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:Gy,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:m,vars:c,varsResolver:rb,rootSelector:`scrollContainer`});return(0,I.jsx)(z,{component:f===`scrollarea`?cl:`div`,...f===`scrollarea`?d?{offsetScrollbars:`xy`,...p}:{offsetScrollbars:`x`,...p}:{},ref:t,...g(`scrollContainer`),...h,children:(0,I.jsx)(`div`,{...g(`scrollContainerInner`),children:l})})});ib.classes=Gy,ib.displayName=`@mantine/core/TableScrollContainer`;var ab={withRowBorders:!0,verticalSpacing:7},ob=An((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":pt(r),"--table-vertical-spacing":pt(i),"--table-border-color":a?ar(a,e):void 0,"--table-striped-color":c&&o?ar(o,e):void 0,"--table-highlight-on-hover-color":l&&s?ar(s,e):void 0,"--table-sticky-header-offset":d?F(u):void 0}})),K=B((e,t)=>{let n=R(`Table`,ab,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:Gy,classNames:r,styles:o,unstyled:s,attributes:O,rootSelector:`table`,vars:c,varsResolver:ob});return(0,I.jsx)(Uy,{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)(tb,{data:S})})})});K.classes=Gy,K.displayName=`@mantine/core/Table`,K.Td=Yy,K.Th=Jy,K.Tr=Xy,K.Thead=Zy,K.Tbody=Qy,K.Tfoot=$y,K.Caption=eb,K.ScrollContainer=ib,K.DataRenderer=tb;var[sb,cb]=et(`Tabs component was not found in the tree`),lb={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`},ub=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=cb();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})});ub.classes=lb,ub.displayName=`@mantine/core/TabsList`;var db=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=cb(),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})});db.classes=lb,db.displayName=`@mantine/core/TabsPanel`;var fb=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=Sr(),{dir:b}=Ji(),x=cb(),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)(fl,{...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?ar(d,y):void 0},onKeyDown:st({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})]})});fb.classes=lb,fb.displayName=`@mantine/core/TabsTab`;var pb=`Tabs.Tab or Tabs.Panel component was rendered with invalid value or without value`,mb={keepMounted:!0,orientation:`horizontal`,loop:!0,activateTabWithKeyboard:!0,variant:`default`,placement:`left`},hb=An((e,{radius:t,color:n,autoContrast:r})=>({root:{"--tabs-radius":mt(t),"--tabs-color":ar(n,e),"--tabs-text-color":ai(r,e)?Dr({color:n,theme:e,autoContrast:r}):void 0}})),gb=B((e,t)=>{let n=R(`Tabs`,mb,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=$t(l),[k,A]=an({value:i,defaultValue:r,finalValue:null,onChange:a}),j=L({name:`Tabs`,props:n,classes:lb,className:x,style:S,classNames:v,styles:y,unstyled:b,attributes:E,vars:C,varsResolver:hb});return(0,I.jsx)(sb,{value:{placement:g,value:k,orientation:o,id:O,loop:c,activateTabWithKeyboard:u,getTabId:nt(`${O}-tab`,pb),getPanelId:nt(`${O}-panel`,pb),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})})});gb.classes=lb,gb.displayName=`@mantine/core/Tabs`,gb.Tab=fb,gb.Panel=db,gb.List=ub;var _b=B((e,t)=>{let n=R(`TextInput`,null,e);return(0,I.jsx)(fd,{component:`input`,ref:t,...n,__staticSelector:`TextInput`})});_b.classes=fd.classes,_b.displayName=`@mantine/core/TextInput`;var vb={root:`m_7341320d`},yb=An((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":ft(t,`ti-size`),"--ti-radius":n===void 0?void 0:mt(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}}}),bb=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,f=L({name:`ThemeIcon`,classes:vb,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:u,vars:c,varsResolver:yb});return(0,I.jsx)(z,{ref:t,...f(`root`),...d})});bb.classes=vb,bb.displayName=`@mantine/core/ThemeIcon`;var xb=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],Sb=[`xs`,`sm`,`md`,`lg`,`xl`];function Cb(e,t){let n=t===void 0?`h${e}`:t;return xb.includes(n)?{fontSize:`var(--mantine-${n}-font-size)`,fontWeight:`var(--mantine-${n}-font-weight)`,lineHeight:`var(--mantine-${n}-line-height)`}:Sb.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 wb={root:`m_8a5d1357`},Tb={order:1},Eb=An((e,{order:t,size:n,lineClamp:r,textWrap:i})=>{let a=Cb(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`,Tb,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:wb,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:h,vars:l,varsResolver:Eb});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=wb,q.displayName=`@mantine/core/Title`;function Db(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 Ob(e){return(0,b.useSyncExternalStore)(e.subscribe,()=>e.getState(),()=>e.getState())}function kb(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 Ab=Db({notifications:[],queue:[],defaultPosition:`bottom-right`,limit:5}),jb=(e=Ab)=>Ob(e);function Mb(e,t){let n=e.getState(),r=kb(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=Ab){let n=e.id||wt();return Mb(t,t=>e.id&&t.some(t=>t.id===e.id)?t:[...t,{...e,id:n}]),n}function Nb(e,t=Ab){return Mb(t,t=>t.filter(t=>t.id!==e||(t.onClose?.(t),!1))),e}function Pb(e,t=Ab){return Mb(t,t=>t.map(t=>t.id===e.id?{...t,...e}:t)),e.id}function Fb(e=Ab){Mb(e,()=>[])}function Ib(e=Ab){Mb(e,t=>t.slice(0,e.getState().limit))}var Lb={show:J,hide:Nb,update:Pb,clean:Fb,cleanQueue:Ib,updateState:Mb};function Rb(e,t){return Rb=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Rb(e,t)}function zb(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,Rb(e,t)}var Bb=o(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Vb=o(((e,t)=>{var n=Bb();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}})),Hb=o(((e,t)=>{t.exports=Vb()()})),Ub={disabled:!1},Wb=b.createContext(null),Gb=function(e){return e.scrollTop},Kb=`unmounted`,qb=`exited`,Jb=`entering`,Yb=`entered`,Xb=`exiting`,Zb=function(e){zb(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=qb,r.appearStatus=Jb):o=Yb:o=t.unmountOnExit||t.mountOnEnter?Kb:qb,r.state={status:o},r.nextCallback=null,r}t.getDerivedStateFromProps=function(e,t){return e.in&&t.status===`unmounted`?{status:qb}: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=Jb):(n===`entering`||n===`entered`)&&(t=Xb)}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:Cs.default.findDOMNode(this);n&&Gb(n)}this.performEnter(e)}else this.performExit()}else this.props.unmountOnExit&&this.state.status===`exited`&&this.setState({status:Kb})},n.performEnter=function(e){var t=this,n=this.props.enter,r=this.context?this.context.isMounting:e,i=this.props.nodeRef?[r]:[Cs.default.findDOMNode(this),r],a=i[0],o=i[1],s=this.getTimeouts(),c=r?s.appear:s.enter;if(!e&&!n||Ub.disabled){this.safeSetState({status:Yb},function(){t.props.onEntered(a)});return}this.props.onEnter(a,o),this.safeSetState({status:Jb},function(){t.props.onEntering(a,o),t.onTransitionEnd(c,function(){t.safeSetState({status:Yb},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:Cs.default.findDOMNode(this);if(!t||Ub.disabled){this.safeSetState({status:qb},function(){e.props.onExited(r)});return}this.props.onExit(r),this.safeSetState({status:Xb},function(){e.props.onExiting(r),e.onTransitionEnd(n.exit,function(){e.safeSetState({status:qb},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:Cs.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=Im(t,[`children`,`in`,`mountOnEnter`,`unmountOnExit`,`appear`,`enter`,`exit`,`timeout`,`addEndListener`,`onEnter`,`onEntering`,`onEntered`,`onExit`,`onExiting`,`onExited`,`nodeRef`]);return b.createElement(Wb.Provider,{value:null},typeof n==`function`?n(e,r):b.cloneElement(b.Children.only(n),r))},t}(b.Component);Zb.contextType=Wb,Zb.propTypes={};function Qb(){}Zb.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:Qb,onEntering:Qb,onEntered:Qb,onExit:Qb,onExiting:Qb,onExited:Qb},Zb.UNMOUNTED=Kb,Zb.EXITED=qb,Zb.ENTERING=Jb,Zb.ENTERED=Yb,Zb.EXITING=Xb;function $b(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function ex(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 tx(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 nx(e,t,n){return n[t]==null?e.props[t]:n[t]}function rx(e,t){return ex(e.children,function(n){return(0,b.cloneElement)(n,{onExited:t.bind(null,n),in:!0,appear:nx(n,`appear`,e),enter:nx(n,`enter`,e),exit:nx(n,`exit`,e)})})}function ix(e,t,n){var r=ex(e.children),i=tx(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:nx(o,`exit`,e),enter:nx(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:nx(o,`exit`,e),enter:nx(o,`enter`,e)}))}}),i}var ax=Object.values||function(e){return Object.keys(e).map(function(t){return e[t]})},ox={component:`div`,childFactory:function(e){return e}},sx=function(e){zb(t,e);function t(t,n){var r=e.call(this,t,n)||this;return r.state={contextValue:{isMounting:!0},handleExited:r.handleExited.bind($b(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?rx(e,r):ix(e,n,r),firstRender:!1}},n.handleExited=function(e,t){var n=ex(this.props.children);e.key in n||(e.props.onExited&&e.props.onExited(t),this.mounted&&this.setState(function(t){var n=Fm({},t.children);return delete n[e.key],{children:n}}))},n.render=function(){var e=this.props,t=e.component,n=e.childFactory,r=Im(e,[`component`,`childFactory`]),i=this.state.contextValue,a=ax(this.state.children).map(n);return delete r.appear,delete r.enter,delete r.exit,t===null?b.createElement(Wb.Provider,{value:i},a):b.createElement(Wb.Provider,{value:i},b.createElement(t,r,a))},t}(b.Component);sx.propTypes={},sx.defaultProps=ox;var cx=[`bottom-center`,`bottom-left`,`bottom-right`,`top-center`,`top-left`,`top-right`];function lx(e,t){return e.reduce((e,n)=>(e[n.position||t].push(n),e),cx.reduce((e,t)=>(e[t]=[],e),{}))}var ux={left:`translateX(-100%)`,right:`translateX(100%)`,"top-center":`translateY(-100%)`,"bottom-center":`translateY(100%)`},dx={left:`translateX(0)`,right:`translateX(0)`,"top-center":`translateY(0)`,"bottom-center":`translateY(0)`};function fx({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:ux[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:dx[o]},l={opacity:0,maxHeight:0,transform:ux[o]},u={entering:c,entered:c,exiting:l,exited:l};return{...s,...u[e]}}function px(e,t){return typeof t==`number`?t:t===!1||e===!1?!1:e}var mx=(0,b.forwardRef)(({data:e,onHide:t,autoClose:n,...r},i)=>{let{autoClose:a,message:o,...s}=e,c=px(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)(Og,{...r,...s,onClose:d,ref:i,onMouseEnter:u,onMouseLeave:f,children:o})});mx.displayName=`@mantine/notifications/NotificationContainer`;var hx={root:`m_b37d9ac7`,notification:`m_5ed0edd0`},gx=Zb,_x={position:`bottom-right`,autoClose:4e3,transitionDuration:250,containerWidth:440,notificationMaxHeight:200,limit:5,zIndex:lt(`overlay`),store:Ab,withinPortal:!0},vx=An((e,{zIndex:t,containerWidth:n})=>({root:{"--notifications-z-index":t?.toString(),"--notifications-container-width":F(n)}})),yx=B((e,t)=>{let n=R(`Notifications`,_x,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=Sr(),S=jb(g),C=Xt(),w=ln(),T=(0,b.useRef)({}),E=(0,b.useRef)(0),D=x.respectReducedMotion&&w?1:d,O=L({name:`Notifications`,classes:hx,props:n,className:i,style:a,classNames:r,styles:o,unstyled:s,vars:c,varsResolver:vx});(0,b.useEffect)(()=>{g?.updateState(e=>({...e,limit:m||5,defaultPosition:l}))},[m,l]),Lt(()=>{S.notifications.length>E.current&&setTimeout(()=>C(),0),E.current=S.notifications.length},[S.notifications]);let k=lx(S.notifications,l),A=cx.reduce((e,t)=>(e[t]=k[t].map(({style:e,...n})=>(0,I.jsx)(gx,{timeout:D,onEnter:()=>T.current[n.id].offsetHeight,nodeRef:{current:T.current[n.id]},children:r=>(0,I.jsx)(mx,{ref:e=>{e&&(T.current[n.id]=e)},data:n,onHide:e=>Nb(e,g),autoClose:u,...O(`notification`,{style:{...fx({state:r,position:t,transitionDuration:D,maxHeight:p}),...e}})})},n.id)),e),{});return(0,I.jsxs)(Ml,{withinPortal:v,..._,children:[(0,I.jsx)(z,{...O(`root`),"data-position":`top-center`,ref:t,...y,children:(0,I.jsx)(sx,{children:A[`top-center`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`top-left`,...y,children:(0,I.jsx)(sx,{children:A[`top-left`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`top-right`,...y,children:(0,I.jsx)(sx,{children:A[`top-right`]})}),(0,I.jsx)(z,{...O(`root`,{className:Be.classNames.fullWidth}),"data-position":`bottom-right`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-right`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-left`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-left`]})}),(0,I.jsx)(z,{...O(`root`),"data-position":`bottom-center`,...y,children:(0,I.jsx)(sx,{children:A[`bottom-center`]})})]})});yx.classes=hx,yx.displayName=`@mantine/notifications/Notifications`,yx.show=Lb.show,yx.hide=Lb.hide,yx.update=Lb.update,yx.clean=Lb.clean,yx.cleanQueue=Lb.cleanQueue,yx.updateState=Lb.updateState;var bx=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}},xx=class{operator;child;constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}},Sx=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()})`}},Cx=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 wx(e,this.prefixParselets,this.infixParselets)}},wx=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)}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 Tx(e){if(e!==void 0)return Array.isArray(e)?e:[e]}var Ex=`http://hl7.org`,Dx=`ok`,Ox=`created`,kx=`gone`,Ax=`not-modified`,jx=`found`,Mx=`not-found`,Nx=`conflict`,Px=`unauthorized`,Fx=`forbidden`,Ix=`precondition-failed`,Lx=`content-too-large`,Rx=`unsupported-media-type`,zx=`multiple-matches`,Bx=`too-many-requests`,Vx=`accepted`,Hx=`server-timeout`,Ux=`business-rule`,Wx={resourceType:`OperationOutcome`,id:Dx,issue:[{severity:`information`,code:`informational`,details:{text:`All OK`}}]},Gx={resourceType:`OperationOutcome`,id:Mx,issue:[{severity:`error`,code:`not-found`,details:{text:`Not found`}}]},Kx={resourceType:`OperationOutcome`,id:Px,issue:[{severity:`error`,code:`login`,details:{text:`Unauthorized`}}]},qx={...Kx,issue:[...Kx.issue,{severity:`error`,code:`expired`,details:{text:`Token expired`}}]},Jx={...Kx,issue:[...Kx.issue,{severity:`error`,code:`invalid`,details:{text:`Token not issued for this audience`}}]},Yx={resourceType:`OperationOutcome`,id:Fx,issue:[{severity:`error`,code:`forbidden`,details:{text:`Forbidden`}}]};function Xx(e,t){return{resourceType:`OperationOutcome`,issue:[{severity:`error`,code:`invalid`,details:{text:e},...t?{expression:Tx(t)}:void 0}]}}function Zx(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 Qx(e){return e?.issue?.[0]?.details?.coding?.find(e=>e.system===`urn:ietf:rfc:3986`)?.code}function $x(e){return!e||typeof e!=`object`?!1:e instanceof Error||typeof DOMException<`u`&&e instanceof DOMException||Object.prototype.toString.call(e)===`[object Error]`}function eS(e){return typeof e==`object`&&!!e&&e.resourceType===`OperationOutcome`}function tS(e){return e.id===Dx||e.id===Ox||e.id===Ax||e.id===Vx}function nS(e){return e.id===kx}function rS(e){switch(e.id){case Dx:return 200;case Ox:return 201;case Vx:return 202;case jx:return 302;case Ax:return 304;case Px:return 401;case Fx:return 403;case Mx:return 404;case Nx:return 409;case kx:return 410;case Ix:case zx:return 412;case Lx:return 413;case Rx:return 415;case Ux:return 422;case Bx:return 429;case Hx:return 504;default:return e.issue?.[0]?.code===`exception`?500:400}}var iS=class extends Error{outcome;constructor(e,t){super(oS(e),t),this.name=`OperationOutcomeError`,this.outcome=e}};function aS(e){return e instanceof iS?e.outcome:eS(e)?e:Xx(Y(e))}function Y(e){return e?typeof e==`string`?e:$x(e)?e.message:eS(e)?oS(e):typeof e==`object`&&`code`in e&&typeof e.code==`string`?e.code:JSON.stringify(e):`Unknown error`}function oS(e){let t=e.issue?.map(sS)??[];return t.length>0?t.join(`; `):`Unknown error`}function sS(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 cS(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 lS(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,cS(e,t)])),constraints:[],innerTypes:[]};return t}var uS={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`}]},deleted:{type:[{code:`boolean`}]}}},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 dS(e){return new TS(e).parse()}var fS=lS(uS),pS=Object.create(null),mS=Object.create(null),hS={"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 gS(e){let t;return t=mS[e],t||=mS[e]=Object.create(null),t}function _S(e){let t=(Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[]).filter(e=>e?.resourceType===`StructureDefinition`);Lw(t);for(let e of t)vS(e)}function vS(e){if(!e?.name)throw Error(`Failed loading StructureDefinition from bundle`);if(e.resourceType!==`StructureDefinition`)return;let t=dS(e),n=hS[e.url],r,i;n?(r=fS,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=fS,i=e.type):(r=gS(e.url),i=e.type),r[i]=t;for(let e of t.innerTypes)e.parentType=t,r[e.name]=e;pS[e.url]=t}function yS(){return fS}function bS(e){return!!fS[e]}function xS(e,t){if(t){let n=gS(t)[e];if(n)return n}return fS[e]}function SS(e,t){let n=xS(e,t);if(!n)throw new iS(Xx(`Unknown data type: `+e));return n}function CS(e){return!!pS[e]}function wS(e){return pS[e]}var TS=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:MS(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=DS(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[DS(e,n.path)]=t;break}n=n.parent}if(!n){let n=DS(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&&!kS(this.slicingContext.path,e?.path)&&(this.slicingContext=void 0),e.slicing&&!this.slicingContext&&this.enterSlice(e,t)}enterInnerType(e){for(;this.backboneContext&&!kS(this.backboneContext?.path,e.path);)this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;let t=Bw(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:kS(this.backboneContext?.path,e.path)?this.backboneContext:this.backboneContext?.parent}}enterSlice(e,t){jS(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&&!kS(this.backboneContext.path,e?.path)){if(this.backboneContext.parent)do this.innerTypes.push(this.backboneContext.type),this.backboneContext=this.backboneContext.parent;while(this.backboneContext&&!kS(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!!(kS(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=Bw(e)),n||=EC(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=ES(e.max),n=e.base?.max?ES(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:AS(HS(r,`fixed[x]`)),pattern:AS(HS(r,`pattern[x]`)),binding:e.binding}}};function ES(e){return e===`*`?1/0:Number.parseInt(e,10)}function DS(e,t=``){return OS(e.path,t)}function OS(e,t){return e?t&&e.startsWith(t)?e.substring(t.length+1):e:``}function kS(e,t){return!e||!t?!1:t.startsWith(e+`.`)||t===e}function AS(e){return Array.isArray(e)&&e.length>0?e[0]:jC(e)?void 0:e}function jS(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 MS(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 NS(e,t,n){if(e===void 0)return[void 0];if(t===`$this`)return[e];let r=n?.withPath?PS:HS,[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 PS(e,t,n){let r=e.path;return FS(HS(e,t,n),r,t)}function FS(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 bx(1e3);var IS={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 LS(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 LC(e,i.pattern);if(i.fixed)return PC(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 RS(e){return[{type:X.boolean,value:e}]}function zS(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}:oC(e)?{type:X.Quantity,value:e}:Qw(e)?{type:e.resourceType,value:e}:GC(e)?{type:X.CodeableConcept,value:e}:WC(e)?{type:X.Coding,value:e}:{type:X.BackboneElement,value:e}}function BS(e){return e.length!==0&&!!e[0].value}function VS(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 HS(e,t,n){if(!e.value)return;let r=Xw(e.type,t,n?.profileUrl);return r?US(e,t,r):GS(e,t)}function US(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+=ZC(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]=uC(a[e],s[e])}else if(!a&&Array.isArray(s)){a=s.slice();for(let e=0;e<s.length;e++)a[e]=uC(void 0,s[e])}else a=uC(a,s)}if(!jC(a))return(o===`Element`||o===`BackboneElement`)&&(o=n.type[0].code),Array.isArray(a)?a.map(e=>WS(e,o)):WS(a,o)}function WS(e,t){return t===`Resource`&&Qw(e)&&(t=e.resourceType),{type:t,value:e}}function GS(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(zS):zS(e)}else{let e=t.endsWith(`[x]`)?t.substring(0,t.length-3):t;for(let t of Object.values(X)){let i=e+ZC(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||jC(r[0]))return}else if(jC(r))return;return r}function KS(e){let t=[];for(let n of e){let e=!1;for(let r of t)if(BS(XS(n,r))){e=!0;break}e||t.push(n)}return t}function qS(e){return RS(!BS(e))}function JS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?RS(e.every((e,n)=>BS(XS(e,t[n])))):RS(!1)}function YS(e,t){return e.length===0||t.length===0?[]:e.length===t.length?RS(e.some((e,n)=>!BS(XS(e,t[n])))):RS(!0)}function XS(e,t){let n=e.value?.valueOf(),r=t.value?.valueOf();return typeof n==`number`&&typeof r==`number`?RS(Math.abs(n-r)<1e-8):oC(n)&&oC(r)?RS(sC(n,r)):RS(typeof n==`object`&&typeof r==`object`?cC(e,t):n===r)}function ZS(e,t){return e.length===0&&t.length===0?RS(!0):e.length===t.length?(e.sort($S),t.sort($S),RS(e.every((e,n)=>BS(QS(e,t[n]))))):RS(!1)}function QS(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`?RS(Math.abs(o-s)<.01):oC(o)&&oC(s)?RS(sC(o,s)):RS(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`?cC({...o,id:void 0},{...s,id:void 0}):typeof o==`string`&&typeof s==`string`?o.toLowerCase()===s.toLowerCase():o===s)}function $S(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 eC(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 tC(n);case`DateTime`:return nC(n);case`Time`:return typeof n==`string`&&!!/^T\d/.exec(n);case`Period`:return rC(n);case`Quantity`:return oC(n);default:return e.type===r||typeof n==`object`&&n?.resourceType===r}}function tC(e){return typeof e==`string`&&!!IS.date.exec(e)}function nC(e){return typeof e==`string`&&!!IS.dateTime.exec(e)}function rC(e){return!!(e&&typeof e==`object`&&(`start`in e&&nC(e.start)||`end`in e&&nC(e.end)))}function iC(e){if(tC(e)||nC(e))return{start:aC(e,`0000-01-01T00:00:00.000`),end:aC(e,`xxxx-12-31T23:59:59.999`)};if(rC(e))return{start:e.start?aC(e.start,`0000-01-01T00:00:00.000`):void 0,end:e.end?aC(e.end,`xxxx-12-31T23:59:59.999`):void 0}}function aC(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 oC(e){return!!(e&&typeof e==`object`&&`value`in e&&typeof e.value==`number`)}function sC(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 cC(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(lC(n)&&lC(i)){if(!cC(n,i))return!1}else if(n!==i)return!1}return!0}function lC(e){return typeof e==`object`&&!!e}function uC(e,t){if(t){if(typeof t!=`object`)throw Error(`Primitive extension must be an object`);return dC(e??{},t)}return e}function dC(e,t){return delete t.__proto__,delete t.constructor,Object.assign(e,t)}function fC(e,t){return Qw(e,t)&&`id`in e&&typeof e.id==`string`}function pC(e){let t=mC(e)??`undefined/undefined`,n=vC(e);return n===t?{reference:t}:{reference:t,display:n}}function mC(e){if($w(e))return e.reference;if(fC(e))return`${e.resourceType}/${e.id}`}function hC(e){if(e)return $w(e)?e.reference.split(`/`)[1]:e.id}function gC(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]}return Tx(e.accounts??e.account)}}function _C(e){return e.resourceType===`Patient`||e.resourceType===`Practitioner`||e.resourceType===`RelatedPerson`}function vC(e){if(_C(e)){let t=yC(e);if(t)return t}if(e.resourceType===`Appointment`&&e.serviceType?.[0])return Aw(e.serviceType[0]);if(e.resourceType===`Device`){let t=bC(e);if(t)return t}if(e.resourceType===`DocumentReference`){if(e.description)return e.description;if(e.type)return Aw(e.type)}if(e.resourceType===`MedicationRequest`&&e.medicationCodeableConcept||e.resourceType===`MedicationStatement`&&e.medicationCodeableConcept)return Aw(e.medicationCodeableConcept);if(e.resourceType===`Slot`&&(e.start||e.end))return`${bw(e.start)} - ${bw(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]),GC(t))return Aw(t);if(KC(t))return t.text}return mC(e)??``}function yC(e){let t=e.name;if(t&&t.length>0)return _w(t[0])}function bC(e){let t=e.deviceName;if(t&&t.length>0)return t[0].name}function xC(e){if(!(`photo`in e))return;let t=e.photo;if(t){if(Array.isArray(t))for(let e of t){let t=SC(e);if(t)return t}else return SC(t)}}function SC(e){if(e.url&&e.contentType?.startsWith(`image/`))return e.url}function CC(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())/864e5);return{years:u,months:d,days:f}}function wC(e,t){let{years:n,months:r,days:i}=CC(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 TC(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 EC(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 DC(e,t){let n=OC(e);return JSON.stringify(n,null,t?2:void 0)??``}function OC(e){if(e!=null&&e!==``)return typeof e==`object`?Array.isArray(e)?kC(e):AC(e):e}function kC(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=OC(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 AC(e){let t,n=0;for(let r in e){let i=e[r],a=OC(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 jC(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`object`?!MC(e):!1}function MC(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 NC(e){if(!e)return;let t=e.length-1;for(;t>=0&&jC(e[t]);)t--;return t>=0?e.slice(0,t+1):void 0}function PC(e,t,n){return e===t||jC(e)&&jC(t)?!0:jC(e)||jC(t)?!1:Array.isArray(e)&&Array.isArray(t)?FC(e,t):Array.isArray(e)||Array.isArray(t)?!1:HC(e)&&HC(t)?IC(e,t,n):!1}function FC(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!PC(e[n],t[n]))return!1;return!0}function IC(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(!PC(r,i,n))return!1}return!0}function LC(e,t){return jC(e)?!0:jC(t)?!1:Array.isArray(e)&&Array.isArray(t)?RC(e,t):Array.isArray(e)||Array.isArray(t)?!1:HC(e)&&HC(t)?zC(e,t):HC(e)||HC(t)?!1:e===t}function RC(e,t){return t.every(t=>e.some(e=>LC(e,t)))}function zC(e,t){return Object.entries(t).every(([t,n])=>t in e&&LC(e[t],n))}function BC(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function VC(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 HC(e){return typeof e==`object`&&!!e}function UC(e){return typeof e==`string`}function WC(e){return HC(e)&&`code`in e&&typeof e.code==`string`}function GC(e){return HC(e)&&`coding`in e&&Array.isArray(e.coding)&&e.coding.every(WC)}function KC(e){return HC(e)&&`text`in e&&typeof e.text==`string`}var qC=[];for(let e=0;e<256;e++)qC.push(e.toString(16).padStart(2,`0`));function JC(e){let t=XC(e),n=new Uint8Array(t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=qC[n[e]];return r.join(``)}function YC(e){let t=XC(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 XC(e){return ArrayBuffer.isView(e)?e.buffer:e}function ZC(e){return e?e.charAt(0).toUpperCase()+e.substring(1):``}function QC(e){return e.length>0&&e.startsWith(e[0].toUpperCase())}function $C(e,t){let n=e+`.`;if(t.startsWith(n))return t.slice(n.length)}function ew(e,t){return e.coding?.find(e=>e.system===t)?.code}var tw=(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 nw(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 rw(e){let t,n=!1;return function(){return n||=(t=e(),!0),t}}function iw(e,t){return e?(e.push(t),e):[t]}function aw(e){return e.sort((e,t)=>e.localeCompare(t))}function ow(e){return e.endsWith(`/`)?e:e+`/`}function sw(e){return e.startsWith(`/`)?e.slice(1):e}function cw(e,t){return new URL(sw(t),ow(e.toString())).toString()}function lw(e,t){return cw(e,t).toString().replace(`http://`,`ws://`).replace(`https://`,`wss://`)}function uw(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 dw(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 fw(e,t){if(e?.meta?.profile?.includes(t)){let n=e.meta.profile.indexOf(t);e.meta.profile.splice(n,1)}return e}var pw=Object.freeze([]);function mw(e){if(!e)return``;switch(e.type){case`Address`:return gw(e.value);case`CodeableConcept`:return Aw(e.value);case`Coding`:return jw(e.value);case`ContactPoint`:return e.value.value;case`HumanName`:return _w(e.value);case`Quantity`:return Ow(e.value);case`Reference`:return hw(e.value);default:return e.value?.toString()??``}}function hw(e){return e?e.display??e.reference??DC(e):``}function gw(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 _w(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=Nw(e.text);if(t)return t}return n.join(` `).trim()}function vw(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function yw(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 vw(o)?new Intl.DateTimeFormat(t,{hour:`numeric`,minute:`2-digit`,second:a===0?void 0:`numeric`,...n,timeZone:`UTC`}).format(o):``}function bw(e,t,n){if(!e)return``;let r=new Date(e);return vw(r)?r.toLocaleString(t,n):``}function xw(e,t,n){return!e||!e.start&&!e.end?``:bw(e.start,t,n)+` - `+bw(e.end,t,n)}var Sw={s:`every second`,min:`every minute`,h:`hourly`,d:`daily`,wk:`weekly`,mo:`monthly`,a:`annually`},Cw={s:`second`,min:`minute`,h:`hour`,d:`day`,wk:`week`,mo:`month`,a:`year`},ww={s:`seconds`,min:`minutes`,h:`hours`,d:`days`,wk:`weeks`,mo:`months`,a:`years`};function Tw(e){if(!e)return``;let t=[];return Ew(t,e.repeat),e.event&&t.push(e.event.map(e=>bw(e)).join(`, `)),ZC(t.join(` `).trim())}function Ew(e,t){if(!t?.periodUnit)return;let n=t.frequency??1,r=t.period??1,i=t.periodUnit;n===1&&r===1?e.push(Sw[i]):(n===1?e.push(`once`):e.push(n+` times`),r===1?e.push(`per `+Cw[i]):e.push(`per `+r+` `+ww[i])),t.dayOfWeek&&e.push(`on `+t.dayOfWeek.map(ZC).join(`, `)),t.timeOfDay&&e.push(`at `+t.timeOfDay.map(e=>yw(e)).join(`, `))}function Dw(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=Fw(r.value,t),`> ${Ow(r,t)}`):`>= ${Ow(r,t)}`:r?.value===void 0&&i?.value!==void 0?n&&t!==void 0?(i.value=Pw(i.value,t),`< ${Ow(i,t)}`):`<= ${Ow(i,t)}`:(r?.unit===i?.unit&&delete r?.unit,`${Ow(r,t)} - ${Ow(i,t)}`)}function Ow(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 kw(e){return e?.value===void 0?``:e.value.toLocaleString(void 0,{style:`currency`,currency:e.currency??`USD`,currencyDisplay:`narrowSymbol`})}function Aw(e){return e?Nw(e.text)||(e.coding?e.coding.map(e=>jw(e)).join(`, `):``):``}function jw(e,t){let n=Nw(e?.display);if(n){let r=t?Nw(e?.code):void 0;return`${n}${r?` (`+r+`)`:``}`}return Nw(e?.code)??``}function Mw(e){if(!e)return``;let t=[];if(e.valueQuantity)t.push(Ow(e.valueQuantity));else if(e.valueCodeableConcept)t.push(Aw(e.valueCodeableConcept));else{let n=Nw(e.valueString);n&&t.push(n)}return`component`in e&&t.push(e.component.map(e=>Mw(e)).join(` / `)),t.join(` / `).trim()}function Nw(e){return typeof e==`string`?e:void 0}function Pw(e,t,n=1){return(Iw(e,t)+n)*10**-t}function Fw(e,t,n=1){return(Iw(e,t)-n)*10**-t}function Iw(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 Lw(e){let t=Array.isArray(e)?e:e.entry?.map(e=>e.resource)??[];for(let e of t)e?.resourceType===`StructureDefinition`&&e.kind===`resource`&&Rw(e.type)}function Rw(e){let t=eT.types[e];t||(t={searchParamsDetails:{}},eT.types[e]=t);let n;return!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`,get target(){return n??=Uw(),n}},_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 zw(e){for(let t of e.base??pw){let n=Rw(t);n.searchParams||={},n.searchParams[e.code]=e}}function Bw(e){let t=e.type?.[0]?.code;return t===`BackboneElement`||t===`Element`?Vw((e.base?.path??e.path)?.split(`.`)):t}function Vw(e){return e.length===1?e[0]:e.map(ZC).join(``)}function Hw(e){return e.kind===`resource`&&e.name!==`Resource`&&e.name!==`DomainResource`}function Uw(){return Object.values(yS()).filter(Hw).map(e=>e.name)}function Ww(e){return eT.types[e]?.searchParams}function Gw(e,t){return eT.types[e]?.searchParams?.[t]}function Kw(e){return qw(e.replaceAll(`[x]`,``).split(`.`).pop())}function qw(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(Yw).join(` `).replace(`_`,` `).replaceAll(/\s+/g,` `)}var Jw=new Set([`CDS`,`ID`,`IP`,`JWKS`,`PKCE`,`OMB`,`OID`,`SOP`,`UDI`,`UID`,`URI`,`URL`]);function Yw(e){let t=e.toUpperCase();return e===t?e:Jw.has(t)?t:t.charAt(0)+e.slice(1)}function Xw(e,t,n){let r=xS(e,n);if(r)return Zw(r.elements,t)}function Zw(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 Qw(e,t){return!(!e||typeof e!=`object`||!(`resourceType`in e)||t&&e.resourceType!==t)}function $w(e,t){return e&&typeof e==`object`&&`reference`in e&&typeof e.reference==`string`?!t||e.reference.match(RegExp(`^${t}(/|\\?)`))!==null:!1}var eT={types:{}};function tT(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 nT=()=>[];function rT(e){return e instanceof dT?e.name:e instanceof bT&&e.left instanceof dT&&e.right instanceof dT?e.left.name+`.`+e.right.name:``}var iT={empty:(e,t)=>RS(t.every(e=>jC(e.value))),hasValue:(e,t)=>RS(t.length!==0),exists:(e,t,n)=>RS(n?t.some(t=>BS(n.eval(e,[t]))):t.length>0&&t.every(e=>!jC(e.value))),all:(e,t,n)=>RS(t.every(t=>BS(n.eval(e,[t])))),allTrue:(e,t)=>{for(let e of t)if(!e.value)return RS(!1);return RS(!0)},anyTrue:(e,t)=>{for(let e of t)if(e.value)return RS(!0);return RS(!1)},allFalse:(e,t)=>{for(let e of t)if(e.value)return RS(!1);return RS(!0)},anyFalse:(e,t)=>{for(let e of t)if(!e.value)return RS(!0);return RS(!1)},subsetOf:(e,t,n)=>{if(t.length===0)return RS(!0);let r=n.eval(e,cT(e));return r.length===0?RS(!1):RS(t.every(e=>r.some(t=>t.value===e.value)))},supersetOf:(e,t,n)=>{let r=n.eval(e,cT(e));return r.length===0?RS(!0):t.length===0?RS(!1):RS(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)=>RS(t.length===iT.distinct(e,t).length),where:(e,t,n)=>t.filter(t=>BS(n.eval(e,[t]))),select:(e,t,n)=>t.flatMap(t=>n.eval({parent:e,variables:{$this:t}},[t])),repeat:nT,ofType:(e,t,n)=>{let r=rT(n);return r?t.filter(e=>eC(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,cT(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,cT(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,cT(e));return KS([...t,...r])},combine:(e,t,n)=>{if(!n)return t;let r=n.eval(e,cT(e));return[...t,...r]},htmlChecks:(e,t,n)=>[zS(!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 BS(a)?r.eval(e,t):i?i.eval(e,t):[]},toBoolean:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);if(typeof n==`boolean`)return[{type:X.boolean,value:n}];if(typeof n==`number`&&(n===0||n===1))return RS(!!n);if(typeof n==`string`){let e=n.toLowerCase();if([`true`,`t`,`yes`,`y`,`1`,`1.0`].includes(e))return RS(!0);if([`false`,`f`,`no`,`n`,`0`,`0.0`].includes(e))return RS(!1)}return[]},convertsToBoolean:(e,t)=>t.length===0?[]:RS(iT.toBoolean(e,t).length===1),toInteger:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(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?[]:RS(iT.toInteger(e,t).length===1),toDate:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.date,value:tT(n)}]:[]},convertsToDate:(e,t)=>t.length===0?[]:RS(iT.toDate(e,t).length===1),toDateTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return typeof n==`string`&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(n)?[{type:X.dateTime,value:tT(n)}]:[]},convertsToDateTime:(e,t)=>t.length===0?[]:RS(iT.toDateTime(e,t).length===1),toDecimal:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(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?[]:RS(iT.toDecimal(e,t).length===1),toQuantity:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return oC(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?[]:RS(iT.toQuantity(e,t).length===1),toString:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);return n==null?[]:oC(n)?[{type:X.string,value:`${n.value} '${n.unit}'`}]:[{type:X.string,value:n.toString()}]},convertsToString:(e,t)=>t.length===0?[]:RS(iT.toString(e,t).length===1),toTime:(e,t)=>{if(t.length===0)return[];let[{value:n}]=sT(t,1);if(typeof n==`string`){let e=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(n);if(e)return[{type:X.time,value:tT(`T`+e[1])}]}return[]},convertsToTime:(e,t)=>t.length===0?[]:RS(iT.toTime(e,t).length===1),indexOf:(e,t,n)=>aT((e,t)=>e.indexOf(t),e,t,n),substring:(e,t,n,r)=>aT((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)=>aT((e,t)=>e.startsWith(t),e,t,n),endsWith:(e,t,n)=>aT((e,t)=>e.endsWith(t),e,t,n),contains:(e,t,n)=>aT((e,t)=>e.includes(t),e,t,n),upper:(e,t)=>aT(e=>e.toUpperCase(),e,t),lower:(e,t)=>aT(e=>e.toLowerCase(),e,t),replace:(e,t,n,r)=>aT((e,t,n)=>e.replaceAll(t,n),e,t,n,r),matches:(e,t,n)=>aT((e,t)=>!!new RegExp(t).exec(e),e,t,n),replaceMatches:(e,t,n,r)=>aT((e,t,n)=>e.replaceAll(new RegExp(t,`g`),n.replaceAll(/\$\{(\w+)\}/g,`$<$1>`)),e,t,n,r),length:(e,t)=>aT(e=>e.length,e,t),toChars:(e,t)=>aT(e=>e?e.split(``):void 0,e,t),encode:nT,decode:nT,escape:nT,unescape:nT,trim:nT,split:nT,join:(e,t,n)=>{let r=n?.eval(e,cT(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)=>oT(Math.abs,e,t),ceiling:(e,t)=>oT(Math.ceil,e,t),exp:(e,t)=>oT(Math.exp,e,t),floor:(e,t)=>oT(Math.floor,e,t),ln:(e,t)=>oT(Math.log,e,t),log:(e,t,n)=>oT((e,t)=>Math.log(e)/Math.log(t),e,t,n),power:(e,t,n)=>oT(Math.pow,e,t,n),round:(e,t,...n)=>oT((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)=>oT(Math.sqrt,e,t),truncate:(e,t)=>oT(e=>Math.trunc(e),e,t),children:nT,descendants:nT,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=iT.toDateTime(e,n.eval(e,t));if(a.length===0)throw Error(`Invalid start date`);let o=iT.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=CC(a[0].value,o[0].value);return[{type:X.Quantity,value:{value:c[s],unit:s}}]},is:(e,t,n)=>{let r=rT(n);return r?t.map(e=>({type:X.boolean,value:eC(e,r)})):[]},not:(e,t)=>iT.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 zS(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=rT(n);if(!r)throw Error(`Expected a valid type identifier as the right operand of 'as', but found ${n.toString()}`);let i=VS(t);return i&&eC(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`}}:Qw(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 dT&&(i=n.name),i&&!r.reference.startsWith(i+`/`)?[]:[{type:X.id,value:hC(r)}]},extension:(e,t,n)=>{let r=n.eval(e,t)[0].value,i=t?.[0]?.value;if(i){let e=EC(i,r);if(e)return[{type:X.Extension,value:e}]}return[]}};function aT(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=sT(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(zS):[zS(a)]}function oT(e,t,n,...r){if(n.length===0)return[];let[{value:i}]=sT(n,1),a=oC(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 sT(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 cT(e){let t=e;for(;t.parent?.variables.$this;)t=t.parent;return[t.variables.$this]}var lT=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()}return this.child.eval(e,[])}catch(e){throw Error(`FhirPathError on "${this.original}": ${e}`,{cause:e})}}toString(){return this.child.toString()}},uT=class{value;constructor(e){this.value=e}eval(){return[this.value]}toString(){let e=this.value.value;return typeof e==`string`?`'${e}'`:e.toString()}},dT=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 Qw(t,this.name)?(`path`in e||(e.path=t.resourceType),e):PS(e,this.name)}toString(){return this.name}},fT=class{eval(){return[]}toString(){return`{}`}},pT=class extends xx{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()}},mT=class extends Sx{constructor(e,t){super(`as`,e,t)}eval(e,t){return iT.as(e,this.left.eval(e,t),this.right)}},hT=class extends Sx{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=VS(n)?.value,a=VS(r)?.value,o=oC(i)?i.value:i,s=oC(a)?a.value:a,c=this.impl(o,s);return typeof c==`boolean`?RS(c):oC(i)?[{type:X.Quantity,value:{...i,value:c}}]:[zS(c)]}},gT=Object.freeze({type:`string`,value:``}),_T=class extends Sx{constructor(e,t){super(`&`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t))??gT,r=VS(this.right.eval(e,t))??gT;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}]}},vT=class extends Sx{constructor(e,t){super(`contains`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return RS(n.some(e=>e.value===r[0].value))}},yT=class extends Sx{constructor(e,t){super(`in`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t)),r=this.right.eval(e,t);return n?RS(r.some(e=>XS(n,e)[0].value)):[]}},bT=class extends Sx{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()}`}},xT=class extends Sx{constructor(e,t){super(`|`,e,t)}eval(e,t){let n=this.left.eval(e,t),r=this.right.eval(e,t);return KS([...n,...r])}},ST=class extends Sx{constructor(e,t){super(`=`,e,t)}eval(e,t){return JS(this.left.eval(e,t),this.right.eval(e,t))}},CT=class extends Sx{constructor(e,t){super(`!=`,e,t)}eval(e,t){return YS(this.left.eval(e,t),this.right.eval(e,t))}},wT=class extends Sx{constructor(e,t){super(`~`,e,t)}eval(e,t){return ZS(this.left.eval(e,t),this.right.eval(e,t))}},TT=class extends Sx{constructor(e,t){super(`!~`,e,t)}eval(e,t){return qS(ZS(this.left.eval(e,t),this.right.eval(e,t)))}},ET=class extends Sx{constructor(e,t){super(`is`,e,t)}eval(e,t){let n=this.left.eval(e,t);if(n.length!==1)return[];let r=rT(this.right);return r?RS(eC(n[0],r)):[]}},DT=class extends Sx{constructor(e,t){super(`and`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return n?.value===!0&&r?.value===!0?RS(!0):n?.value===!1||r?.value===!1?RS(!1):[]}},OT=class extends Sx{constructor(e,t){super(`or`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return n?.value===!1&&r?.value===!1?RS(!1):n?.value||r?.value?RS(!0):[]}},kT=class extends Sx{constructor(e,t){super(`xor`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return!n||!r?[]:RS(n.value!==r.value)}},AT=class extends Sx{constructor(e,t){super(`implies`,e,t)}eval(e,t){let n=VS(this.left.eval(e,t),`boolean`),r=VS(this.right.eval(e,t),`boolean`);return r?.value===!0||n?.value===!1?RS(!0):!n||!r?[]:RS(!1)}},jT=class{name;args;constructor(e,t){this.name=e,this.args=t}eval(e,t){let n=iT[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(`, `)})`}},MT=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()}]`}},NT=[`year`,`years`,`month`,`months`,`week`,`weeks`,`day`,`days`,`hour`,`hours`,`minute`,`minutes`,`second`,`seconds`,`millisecond`,`milliseconds`],PT=/^\d{4}-\d{2}[\dT:.+\-Z]*(?=[\s)\]]|$)/,FT={"'":`'`,'"':`"`,"`":"`",r:`\r`,n:`
|
|
54
54
|
`,t:` `,f:`\f`,"\\":`\\`},IT=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=FT[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 PT.test(this.str.substring(e))?(this.pos.index=e-1,this.consumeDateTime()):this.consumeUnquotedString(e);if(n===` `)LT(this.peekToken())&&(t=`Quantity`,this.consumeToken());else if(n&&/[a-zA-Z_$]/.exec(n))return this.consumeUnquotedString(e);return this.buildToken(t,this.str.substring(e,this.pos.index))}consumeUnquotedString(e){return this.pos.index=e,this.buildToken(`String`,this.consumeWhile(()=>this.symbolRegex.exec(this.curr())))}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 LT(e){return!!(e&&(e.id===`String`||e.id===`Symbol`&&NT.includes(e.value)))}var RT=[`true`,`false`],zT=[`!=`,`!~`,`<=`,`>=`,`{}`,`->`];function BT(e){return new IT(e,RT,zT).tokenize()}var VT={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},HT={parse(e){let t=e.consumeAndParse();if(!e.match(`)`))throw Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},UT={parse(e,t){let n=e.consumeAndParse();if(!e.match(`]`))throw Error("Parse error: expected `]`");return new MT(t,n)},precedence:VT.Indexer},WT={parse(e,t){if(!(t instanceof dT))throw Error(`Unexpected parentheses`);let n=[];for(;!e.match(`)`);)n.push(e.consumeAndParse()),e.match(`,`);return new jT(t.name,n)},precedence:VT.FunctionCall};function GT(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 KT(){return new Cx().registerPrefix(`String`,{parse:(e,t)=>new uT({type:X.string,value:t.value})}).registerPrefix(`DateTime`,{parse:(e,t)=>new uT({type:X.dateTime,value:tT(t.value)})}).registerPrefix(`Quantity`,{parse:(e,t)=>new uT({type:X.Quantity,value:GT(t.value)})}).registerPrefix(`Number`,{parse:(e,t)=>new uT({type:t.value.includes(`.`)?X.decimal:X.integer,value:Number.parseFloat(t.value)})}).registerPrefix(`true`,{parse:()=>new uT({type:X.boolean,value:!0})}).registerPrefix(`false`,{parse:()=>new uT({type:X.boolean,value:!1})}).registerPrefix(`Symbol`,{parse:(e,t)=>new dT(t.value)}).registerPrefix(`{}`,{parse:()=>new fT}).registerPrefix(`(`,HT).registerInfix(`[`,UT).registerInfix(`(`,WT).prefix(`+`,VT.UnaryAdd,(e,t)=>new pT(`+`,t,e=>e)).prefix(`-`,VT.UnarySubtract,(e,t)=>new hT(`-`,t,t,(e,t)=>-t)).infixLeft(`.`,VT.Dot,(e,t,n)=>new bT(e,n)).infixLeft(`/`,VT.Divide,(e,t,n)=>new hT(`/`,e,n,(e,t)=>e/t)).infixLeft(`*`,VT.Multiply,(e,t,n)=>new hT(`*`,e,n,(e,t)=>e*t)).infixLeft(`+`,VT.Add,(e,t,n)=>new hT(`+`,e,n,(e,t)=>e+t)).infixLeft(`-`,VT.Subtract,(e,t,n)=>new hT(`-`,e,n,(e,t)=>e-t)).infixLeft(`|`,VT.Union,(e,t,n)=>new xT(e,n)).infixLeft(`=`,VT.Equals,(e,t,n)=>new ST(e,n)).infixLeft(`!=`,VT.NotEquals,(e,t,n)=>new CT(e,n)).infixLeft(`~`,VT.Equivalent,(e,t,n)=>new wT(e,n)).infixLeft(`!~`,VT.NotEquivalent,(e,t,n)=>new TT(e,n)).infixLeft(`<`,VT.LessThan,(e,t,n)=>new hT(`<`,e,n,(e,t)=>e<t)).infixLeft(`<=`,VT.LessThanOrEquals,(e,t,n)=>new hT(`<=`,e,n,(e,t)=>e<=t)).infixLeft(`>`,VT.GreaterThan,(e,t,n)=>new hT(`>`,e,n,(e,t)=>e>t)).infixLeft(`>=`,VT.GreaterThanOrEquals,(e,t,n)=>new hT(`>=`,e,n,(e,t)=>e>=t)).infixLeft(`&`,VT.Ampersand,(e,t,n)=>new _T(e,n)).infixLeft(`and`,VT.And,(e,t,n)=>new DT(e,n)).infixLeft(`as`,VT.As,(e,t,n)=>new mT(e,n)).infixLeft(`contains`,VT.Contains,(e,t,n)=>new vT(e,n)).infixLeft(`div`,VT.Divide,(e,t,n)=>new hT(`div`,e,n,(e,t)=>Math.trunc(e/t))).infixLeft(`in`,VT.In,(e,t,n)=>new yT(e,n)).infixLeft(`is`,VT.Is,(e,t,n)=>new ET(e,n)).infixLeft(`mod`,VT.Modulo,(e,t,n)=>new hT(`mod`,e,n,(e,t)=>e%t)).infixLeft(`or`,VT.Or,(e,t,n)=>new OT(e,n)).infixLeft(`xor`,VT.Xor,(e,t,n)=>new kT(e,n)).infixLeft(`implies`,VT.Implies,(e,t,n)=>new AT(e,n))}var qT=KT();function JT(e){return new lT(e,qT.construct(BT(e)).consumeAndParse())}function YT(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]=zS(i[e]))}return XT(e,i,n,r).map(e=>e.value)}function XT(e,t,n={},r=void 0){let i;if(typeof e==`string`){let t=r?.get(e);i=t??JT(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=iC(n.value);e&&t.push(e)}return t}function QT(e){let t=new Set;for(let n of e){let e=mw(n);e&&t.add(e)}return Array.from(t)}function $T(e){let t=new Set;for(let n of e){let{value:e}=n;e&&(UC(e)?t.add(e):$w(e)?t.add(e.reference):fC(e)?t.add(mC(e)):typeof e.identifier==`object`&&t.add(`identifier:${e.identifier.system}|${e.identifier.value}`))}return Array.from(t)}function eE(e,t={}){let n=[];for(let r of e)tE(t,n,r);return n}function tE(e,t,n){let{type:r,value:i}=n;switch(r){case X.Identifier:nE(t,e,i);break;case X.CodeableConcept:rE(t,e,i);break;case X.Coding:iE(t,e,i);break;case X.ContactPoint:aE(t,e,i);break;default:oE(t,e,void 0,i?.toString())}}function nE(e,t,n){n?.type?.text&&oE(e,t,t.textSearchSystem,n.type.text),oE(e,t,n?.system,n?.value)}function rE(e,t,n){n?.text&&oE(e,t,t.textSearchSystem,n.text);for(let r of n?.coding??pw)iE(e,t,r)}function iE(e,t,n){n&&(n.display&&oE(e,t,t.textSearchSystem,n.display),oE(e,t,n.system,n.code))}function aE(e,t,n){n&&oE(e,t,n.system,n.value?.toLocaleLowerCase())}function oE(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`},sE={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},cE={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 lE(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 uE(i,a)}function uE(e,t){let n={resourceType:e};for(let[e,r]of t)dE(n,e,r);return n}function dE(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=iw(e.filters,{code:t,operator:Z.EQUALS,value:n});return}switch(r){case`_sort`:fE(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=vE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.include=iw(e.include,t);break}case`_revinclude`:{let t=vE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.revInclude=iw(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=eT.types[e.resourceType]?.searchParams?.[r];e.filters=t?iw(e.filters,mE(t,Z.EQUALS,i,n)):iw(e.filters,hE(r,i,n))}}}}function fE(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 pE=[Z.MISSING,Z.PRESENT];function mE(e,t,n,r){if(pE.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}=gE(r,n||Z.EQUALS);if(!yE(e,i))throw new iS(Xx(`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(!yE(e,r))throw new iS(Xx(`Invalid format for ${e.type} search parameter: ${r}`));return{code:e.code,operator:_E(n)??t,value:r};default:throw Error(`Unrecognized search parameter type: `+e.type)}}function hE(e,t,n){let r=Z.EQUALS;if(t)r=t;else if(n.length>=2){let e=n.substring(0,2);e in cE&&(n.length===2||n.at(2)?.match(/\d/))&&(r=e,n=n.substring(e.length))}return{code:e,operator:r,value:n}}function gE(e,t){let n=cE[e.substring(0,2)];return n?{operator:n,value:e.substring(2)}:{operator:t,value:e}}function _E(e){return sE[e]}function vE(e){let t=e.split(`:`);if(t.includes(`*`))throw new iS(Xx(`'*' is not supported as a value for search inclusion parameters`));if(t.length===1)throw new iS(Xx(`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 iS(Xx(`Invalid include value '${e}'`))}function yE(e,t){switch(e.type){case`date`:return nC(t);default:return!0}}function bE(e){let t=[];e.fields&&t.push(`_fields=`+e.fields.join(`,`));for(let n of e.filters??pw)t.push(xE(n));e.sortRules&&e.sortRules.length>0&&t.push(SE(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??pw)t.push(CE(`_include`,n));for(let n of e.revInclude??pw)t.push(CE(`_revinclude`,n));return t.length===0?``:(aw(t),`?`+t.join(`&`))}function xE(e){let t=e.operator in sE?`:`+e.operator:``,n=e.operator!==Z.EQUALS&&e.operator in cE?e.operator:``;return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}function SE(e){return`_sort=`+e.map(e=>e.descending?`-`+e.code:e.code).join(`,`)}function CE(e,t){return e+(t.modifier?`:`+t.modifier:``)+`=`+t.resourceType+`:`+t.searchParam+(t.targetType?`:`+t.targetType:``)}function wE(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 TE(e,t){if(t.resourceType!==e.resourceType)return!1;for(let n of t.filters??pw)if(!DE(e,t,n))return!1;return!0}var EE=new bx(1e3);function DE(e,t,n){let r=eT.types[t.resourceType]?.searchParams?.[n.code];if(!r)return!1;let i=XT(r.expression,[zS(e)],void 0,EE);if(n.operator===Z.MISSING||n.operator===Z.PRESENT)return OE(i,n);switch(r.type){case`reference`:return kE(r,i,n);case`string`:case`uri`:return ME(i,n);case`token`:return AE(i,n);case`date`:return PE(i,n);default:return!1}}function OE(e,t){let n=e.length>0;return(t.operator===Z.MISSING&&t.value===`false`||t.operator===Z.PRESENT&&t.value===`true`)===n}function kE(e,t,n){let r=IE(n.operator);if(n.value===``&&t.length===0)return n.operator===Z.EQUALS;let i=$T(t);for(let t of wE(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 AE(e,t){let n=eE(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let t of r)if(jE(e,t))return!i;return i}function jE(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 ME(e,t){let n=QT(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let t of r)if(NE(e,t))return!i;return i}function NE(e,t){return e.toLowerCase().includes(t.toLowerCase())}function PE(e,t){let n=ZT(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let n of r)if(FE(e,t.operator,n))return!i;return i}function FE(e,t,n){if(!e)return!1;let r=iC(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 IE(e){return e===Z.NOT_EQUALS||e===Z.NOT}var LE={resourceType:`*`},RE=[`DomainConfiguration`,`JsonWebKey`,`Login`],zE=[`Package`,`PackageRelease`,`PackageInstallation`,`Project`,`ProjectMembership`,`User`,`UserSecurityRequest`],BE={READ:`read`,VREAD:`vread`,UPDATE:`update`,DELETE:`delete`,HISTORY:`history`,CREATE:`create`,SEARCH:`search`},VE=[BE.READ,BE.VREAD,BE.HISTORY,BE.SEARCH];function HE(e,t){return!RE.includes(t)&&UE(e,BE.UPDATE,t)}function UE(e,t,n){return!!e.resource?.some(e=>KE(e,n,t))}function WE(e,t,n){return n?n.resource?.find(n=>GE(e,t,n)):LE}function GE(e,t,n){let r=e.resourceType;return KE(n,r,t)?r===`Binary`||!(n.compartment&&!e.meta?.compartment?.some(e=>e.reference===n.compartment?.reference)||n.criteria&&!TE(e,lE(n.criteria))):!1}function KE(e,t,n){return e.resourceType!==t&&(e.resourceType!==`*`||zE.includes(t))?!1:e.interaction?e.interaction.includes(n):!e.readonly||VE.includes(n)}function qE(){return typeof window<`u`}function JE(){return typeof Buffer<`u`?Buffer:void 0}var YE={assign(e){qE()&&globalThis.location.assign(e)},reload(){qE()&&globalThis.location.reload()},getSearch(){return qE()?globalThis.location.search:``},getPathname(){return qE()?globalThis.location.pathname:``},getLocation(){return qE()?globalThis.location.toString():``},getOrigin(){return qE()?globalThis.location.protocol+`//`+globalThis.location.host+`/`:``}};function XE(e){if(qE()){let t=window.atob(e),n=Uint8Array.from(t,e=>e.codePointAt(0));return new window.TextDecoder().decode(n)}let t=JE();if(t)return t.from(e,`base64`).toString(`utf-8`);throw Error(`Unable to decode base64`)}function ZE(e){if(qE()){let t=new window.TextEncoder().encode(e),n=String.fromCodePoint.apply(null,t);return window.btoa(n)}let t=JE();if(t)return t.from(e,`utf8`).toString(`base64`);throw Error(`Unable to encode base64`)}function QE(e){return e=e.padEnd(e.length+(4-e.length%4)%4,`=`),XE(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`))}function $E(){let e=new Uint32Array(28);return crypto.getRandomValues(e),JC(e.buffer)}async function eD(e){return crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))}function tD(){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 nD(e){let t={};e=BC(e);for(let n of e.entry??pw){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]=tD(),n.fullUrl=`urn:uuid:`+t[r],delete n.resource?.id;else if(n.fullUrl?.startsWith(`resource:`)){let e=n.fullUrl.slice(9);t[e]=tD(),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)=>rD(e,n,t),2);return iD(JSON.parse(r))}function rD(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 iD(e){let{sorted:t,cycles:n}=oD(cD(e)),r={},i=[];for(let t of e.entry??pw)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 aD={NotVisited:`NotVisited`,Visiting:`Visiting`,Visited:`Visited`};function oD(e){let t=[],n={},r=[];for(let t of Object.keys(e))n[t]=aD.NotVisited;function i(a,o){if(n[a]===aD.Visited)return!0;if(n[a]===aD.Visiting){let e=o.lastIndexOf(a);return e!==-1&&r.push(o.slice(e)),!0}n[a]=aD.Visiting,o.push(a);let s=!1;for(let t of e[a]??pw)i(t,o)||(s=!0);return n[a]=aD.Visited,o.pop(),t.unshift(a),!s}for(let t in e)n[t]===aD.NotVisited&&i(t,[]);return{sorted:t,cycles:r}}function sD(e,t){for(let n in e)if(e[n]&&typeof e[n]==`object`){let r=e[n];if($w(r)){let e=r.reference;(e.startsWith(`urn:uuid:`)||e.startsWith(`resource:`))&&t(e)}else sD(r,t)}}function cD(e){let t={};for(let n of e.entry??pw)n.fullUrl&&(t[n.fullUrl]=[]);for(let n of e.entry??pw){let e=n.fullUrl;e&&n.resource&&sD(n.resource,n=>{n!==e&&t[n]&&t[n].push(e)})}return t}var lD={CSS:`text/css`,DICOM:`application/dicom`,DICOM_JSON:`application/dicom+json`,EVENT_STREAM:`text/event-stream`,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`},uD=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??pw)try{n.call(this,e)}catch(t){console.error(`Unhandled error in "${e.type}" event listener`,t)}return!e.defaultPrevented}removeAllListeners(){this.listeners={}}listenerCount(e){return this.listeners[e]?.length??0}},dD=class{emitter=new uD;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)}},fD={"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`},pD=[`Patient`,`Encounter`,`ImagingStudy`,`DiagnosticReport`,`OperationOutcome`,`Bundle`],mD=[`DiagnosticReport-update`];function hD(e){return mD.includes(e)}function gD(e){if(mD.includes(e))throw new iS(Zx(`'context.version' is required for '${e}'.`))}var _D={"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 vD(e){return pD.includes(e)}function yD(e){return!!e.endpoint}function bD(e){if(!xD(e))throw new iS(Zx(`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};return n===`subscribe`&&(a[`hub.events`]=i.join(`,`)),yD(e)&&(a[`hub.channel.endpoint`]=e.endpoint),new URLSearchParams(a).toString()}function xD(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(!fD[e])return!1;return!(yD(e)&&!(typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))}function SD(e,t,n,r){if(typeof t!=`object`)throw new iS(Zx(`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 iS(Zx(`context[${n}] is invalid. Resource must contain a valid string ID.`));if(!t.resourceType)throw new iS(Zx(`context[${n}] is invalid. Resource must contain a resource type. No resource type found.`));let i=r.resourceType;if(i!==`*`){if(!vD(t.resourceType))throw new iS(Zx(`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 iS(Zx(`context[${n}] is invalid. context[${n}] for the '${e}' event should contain resource of type ${i}.`))}}function CD(e,t,n,r,i){if(i.set(t.key,(i.get(t.key)??0)+1),r.reference){if(!$w(t.reference))throw new iS(Zx(`context[${n}] is invalid. Expected key '${t.key}' to be a reference.`))}else SD(e,t.resource,n,r)}function wD(e,t){let n=new Map,r=_D[e];for(let i=0;i<t.length;i++){let a=t[i].key;if(!r[a])throw new iS(Zx(`Key '${a}' not found for event '${e}'. Make sure to add only valid keys.`));CD(e,t[i],i,r[a],n)}for(let[t,i]of Object.entries(r)){if(!(i.optional||n.has(t)))throw new iS(Zx(`Missing required key '${t}' on context for '${e}' event.`));if(!i.manyAllowed&&(n.get(t)??0)>1)throw new iS(Zx(`${n.get(t)} context entries with key '${t}' found for the '${e}' event when schema only allows for 1.`))}}function TD(e,t,n,r){if(!(e&&typeof e==`string`))throw new iS(Zx(`Must provide a topic.`));if(!fD[t])throw new iS(Zx(`Must provide a valid FHIRcast event name. Supported events: ${Object.keys(fD).join(`, `)}`));if(typeof n!=`object`)throw new iS(Zx(`context must be a context object or array of context objects.`));if(mD.includes(t)&&!r)throw new iS(Zx(`The '${t}' event must contain a 'context.versionId'.`));let i=Array.isArray(n)?n:[n];return wD(t,i),{timestamp:new Date().toISOString(),id:tD(),event:{"hub.topic":e,"hub.event":t,context:i,...r?{"context.versionId":r}:{}}}}var ED=class extends dD{subRequest;websocket;constructor(e){if(super(),this.subRequest=e,!e.endpoint)throw new iS(Zx(`Subscription request should contain an endpoint.`));if(!xD(e))throw new iS(Zx(`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.event){n[`hub.mode`]===`denied`&&t.close();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 DD(e){return JSON.parse(QE(e))}function OD(e){return e.split(`.`).length===3}function kD(e){let[t,n,r]=e.split(`.`);return DD(n)}function AD(e){try{return typeof kD(e).login_id==`string`}catch{return!1}}function jD(e){try{let t=kD(e).exp;return typeof t==`number`?t*1e3:void 0}catch{return}}var MD=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,lD.TEXT)}async delete(e){await this.medplum.delete(`keyvalue/v1/${e}`)}},ND=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)}},PD=class{storage;prefix=``;constructor(e,t=``){this.storage=e??globalThis.localStorage??new FD,this.prefix=t}makeKey(e){return this.prefix+e}clear(){if(this.storage===globalThis.localStorage&&this.prefix)for(let e=this.storage.length-1;e>=0;e--){let t=this.storage.key(e);t?.startsWith(this.prefix)&&this.storage.removeItem(t)}else 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?DC(t):void 0)}},FD=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]}},ID={Event:globalThis.Event===void 0?void 0:globalThis.Event,ErrorEvent:void 0,CloseEvent:void 0},LD=!1;function RD(){if(globalThis.Event===void 0)throw Error(`Unable to lazy init events for ReconnectingWebSocket. globalThis.Event is not defined yet`);ID.Event=globalThis.Event,ID.ErrorEvent=class extends Event{message;error;constructor(e,t){super(`error`,t),this.message=e.message,this.error=e}},ID.CloseEvent=class extends Event{code;reason;wasClean=!0;constructor(e=1e3,t=``,n){super(`close`,n),this.code=e,this.reason=t}}}function zD(e,t){if(!e)throw Error(t)}function BD(){}function VD(e){if(e instanceof ID.CloseEvent){let t=e;return new ID.CloseEvent(t.code,t.reason,void 0)}if(e instanceof ID.ErrorEvent){let t=e;return new ID.ErrorEvent(t.error??Error(t.message),void 0)}return new e.constructor(e.type,e)}function HD(e,t){let n=e;return n.error instanceof Error?new ID.ErrorEvent(n.error,t):new ID.ErrorEvent(Error(n.message||`WebSocket error`),t)}var UD={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},WD=!1,GD=class e extends dD{_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={}){LD||=(RD(),!0),super(),this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._binaryType=this._options.binaryType?this._options.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=UD.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=UD.reconnectionDelayGrowFactor,minReconnectionDelay:t=UD.minReconnectionDelay,maxReconnectionDelay:n=UD.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=UD.maxRetries,connectionTimeout:t=UD.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`&&!WD&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket.`),WD=!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 ID.ErrorEvent(Error(e.message),this))})}_handleTimeout(){this._debug(`timeout event`),this._handleError(new ID.ErrorEvent(Error(`TIMEOUT`),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),!this._ws)return;let n=this._ws;this._removeListeners(),n.addEventListener(`error`,BD);try{n.close(e,t),this._handleClose(new ID.CloseEvent(e,t,this))}catch{}}_acceptOpen(){this._debug(`accept open`),this._retryCount=0}_handleOpen=e=>{this._debug(`open event`);let{minUptime:t=UD.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),zD(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(VD(e))};_handleMessage=e=>{this._debug(`message event`),this.onmessage&&this.onmessage(e),this.dispatchEvent(VD(e))};_handleError=e=>{let t=HD(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(VD(t)),this._connect()};_handleClose=e=>{this._debug(`close event`),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(VD(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)}},KD=6e4,qD=[WebSocket.CLOSING,WebSocket.CLOSED],JD=class extends dD{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)}},YD=class{criteria;emitter;refCount;subscriptionProps;subscriptionId;token;tokenExpiry;state=`idle`;generation=0;lastUnrefTime;constructor(e,t){this.criteria=e,this.emitter=new JD(e),this.refCount=1,this.subscriptionProps=t?{...t}:void 0}nextGeneration(){return++this.generation}},XD=class{medplum;ws;masterSubEmitter;criteriaEntries;criteriaEntriesBySubscriptionId;wsClosed;pingTimer=void 0;tokenRefreshTimer=void 0;pingIntervalMs;waitingForPong=!1;currentProfile;constructor(e,t,n){if(!(e instanceof dO))throw new iS(Zx("First arg of constructor should be a `MedplumClient`"));let r;try{r=new URL(t).toString()}catch{throw new iS(Zx(`Not a valid URL`))}let i=n?.ReconnectingWebSocket?new n.ReconnectingWebSocket(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger}):new GD(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger});this.medplum=e,this.ws=i,this.masterSubEmitter=new JD,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){console.warn(`Received WebSocket message without a SubscriptionStatus resource; ignoring`,n);return}if(r.type===`heartbeat`){this.masterSubEmitter?.dispatchEvent({type:`heartbeat`,payload:n});return}if(r.type===`handshake`){let e=hC(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(hC(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 iS({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()},KD)}),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(PC(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!PC(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 ${mC(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 iS(Zx(`Failed to get token`));if(!i)throw new iS(Zx(`Failed to get URL from $get-ws-binding-token`));if(!a)throw new iS(Zx(`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 YD(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 JD(...Array.from(this.criteriaEntries.keys())),this.masterSubEmitter}async reconnectIfNeeded(){qD.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 bx(1e3);var QD=`5.1.29-f5d2946`,$D=lD.FHIR_JSON+`, */*; q=0.1`,eO=`https://api.medplum.com/`,tO=1e3,nO=6e4,rO=0,iO=3e5,aO=`Binary/`,oO={resourceType:`Device`,id:`system`,deviceName:[{type:`model-name`,name:`System`}]},sO=2,cO={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`},lO={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`},uO={JwtBearer:`urn:ietf:params:oauth:client-assertion-type:jwt-bearer`},dO=class extends dD{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??fO(),this.storage=e?.storage??new PD(void 0,e?.storagePrefix),this.createPdfImpl=e?.createPdf,this.baseUrl=ow(e?.baseUrl??eO),this.fhirBaseUrl=cw(this.baseUrl,e?.fhirUrlPath??`fhir/R4`),this.authorizeUrl=cw(this.baseUrl,e?.authorizeUrl??`oauth2/authorize`),this.tokenUrl=cw(this.baseUrl,e?.tokenUrl??`oauth2/token`),this.logoutUrl=cw(this.baseUrl,e?.logoutUrl??`oauth2/logout`),this.fhircastHubUrl=cw(this.baseUrl,e?.fhircastHubUrl??`fhircast/STU3`),this.cdsServicesUrl=cw(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??iO,this.logLevel=this.initializeLogLevel(e),this.maxRetries=e?.maxRetries??2,this.maxRetryTime=e?.maxRetryTime??2e3,this.cacheTime=e?.cacheTime??(qE()?nO:rO),this.requestCache=this.cacheTime>0?new bx(e?.resourceCacheSize??tO):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=cw(this.fhirBaseUrl,e);for(let e of this.requestCache?.keys()??pw)(e.endsWith(t)||e.includes(t+`?`))&&this.requestCache?.delete(e)}notifyResourceModified(e){e.operation!==`delete`&&e.resource?this.cacheResource(e.resource,void 0):e.id&&this.deleteCacheEntry(this.fhirUrl(e.resourceType,e.id).toString()),this.invalidateSearches(e.resourceType),this.dispatchResourceModified(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 ND(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,lD.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(YE.getSearch()).get(`code`);if(!t){await this.requestAuthorization(e);return}return this.processCode(t)}signOutWithRedirect(){YE.assign(this.logoutUrl)}async signInWithExternalAuth(e,t,n,r,i=!0){let a=r;i&&(a=await this.ensureCodeChallenge(r)),YE.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:cO.TokenExchange,subject_token_type:lO.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(cw(this.fhirBaseUrl,e.join(`/`)))}fhirSearchUrl(e,t){let n=this.fhirUrl(e);return t&&(n.search=uw(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 ND(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 ND(this.search(e,t,n).then(mO));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 mO(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 oO;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 ND(Promise.reject(Error(`Missing reference`)));if(n===`system`)return new ND(Promise.resolve(oO));let[r,i]=n.split(`/`);return!r||!i?new ND(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(bS(e))return Promise.resolve();let n=e+`-requestSchema`,r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new ND((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 LT(e){return!!(e&&(e.id===`String`||e.id===`Symbol`&&NT.includes(e.value)))}var RT=[`true`,`false`],zT=[`!=`,`!~`,`<=`,`>=`,`{}`,`->`];function BT(e){return new IT(e,RT,zT).tokenize()}var VT={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},HT={parse(e){let t=e.consumeAndParse();if(!e.match(`)`))throw Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},UT={parse(e,t){let n=e.consumeAndParse();if(!e.match(`]`))throw Error("Parse error: expected `]`");return new MT(t,n)},precedence:VT.Indexer},WT={parse(e,t){if(!(t instanceof dT))throw Error(`Unexpected parentheses`);let n=[];for(;!e.match(`)`);)n.push(e.consumeAndParse()),e.match(`,`);return new jT(t.name,n)},precedence:VT.FunctionCall};function GT(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 KT(){return new Cx().registerPrefix(`String`,{parse:(e,t)=>new uT({type:X.string,value:t.value})}).registerPrefix(`DateTime`,{parse:(e,t)=>new uT({type:X.dateTime,value:tT(t.value)})}).registerPrefix(`Quantity`,{parse:(e,t)=>new uT({type:X.Quantity,value:GT(t.value)})}).registerPrefix(`Number`,{parse:(e,t)=>new uT({type:t.value.includes(`.`)?X.decimal:X.integer,value:Number.parseFloat(t.value)})}).registerPrefix(`true`,{parse:()=>new uT({type:X.boolean,value:!0})}).registerPrefix(`false`,{parse:()=>new uT({type:X.boolean,value:!1})}).registerPrefix(`Symbol`,{parse:(e,t)=>new dT(t.value)}).registerPrefix(`{}`,{parse:()=>new fT}).registerPrefix(`(`,HT).registerInfix(`[`,UT).registerInfix(`(`,WT).prefix(`+`,VT.UnaryAdd,(e,t)=>new pT(`+`,t,e=>e)).prefix(`-`,VT.UnarySubtract,(e,t)=>new hT(`-`,t,t,(e,t)=>-t)).infixLeft(`.`,VT.Dot,(e,t,n)=>new bT(e,n)).infixLeft(`/`,VT.Divide,(e,t,n)=>new hT(`/`,e,n,(e,t)=>e/t)).infixLeft(`*`,VT.Multiply,(e,t,n)=>new hT(`*`,e,n,(e,t)=>e*t)).infixLeft(`+`,VT.Add,(e,t,n)=>new hT(`+`,e,n,(e,t)=>e+t)).infixLeft(`-`,VT.Subtract,(e,t,n)=>new hT(`-`,e,n,(e,t)=>e-t)).infixLeft(`|`,VT.Union,(e,t,n)=>new xT(e,n)).infixLeft(`=`,VT.Equals,(e,t,n)=>new ST(e,n)).infixLeft(`!=`,VT.NotEquals,(e,t,n)=>new CT(e,n)).infixLeft(`~`,VT.Equivalent,(e,t,n)=>new wT(e,n)).infixLeft(`!~`,VT.NotEquivalent,(e,t,n)=>new TT(e,n)).infixLeft(`<`,VT.LessThan,(e,t,n)=>new hT(`<`,e,n,(e,t)=>e<t)).infixLeft(`<=`,VT.LessThanOrEquals,(e,t,n)=>new hT(`<=`,e,n,(e,t)=>e<=t)).infixLeft(`>`,VT.GreaterThan,(e,t,n)=>new hT(`>`,e,n,(e,t)=>e>t)).infixLeft(`>=`,VT.GreaterThanOrEquals,(e,t,n)=>new hT(`>=`,e,n,(e,t)=>e>=t)).infixLeft(`&`,VT.Ampersand,(e,t,n)=>new _T(e,n)).infixLeft(`and`,VT.And,(e,t,n)=>new DT(e,n)).infixLeft(`as`,VT.As,(e,t,n)=>new mT(e,n)).infixLeft(`contains`,VT.Contains,(e,t,n)=>new vT(e,n)).infixLeft(`div`,VT.Divide,(e,t,n)=>new hT(`div`,e,n,(e,t)=>Math.trunc(e/t))).infixLeft(`in`,VT.In,(e,t,n)=>new yT(e,n)).infixLeft(`is`,VT.Is,(e,t,n)=>new ET(e,n)).infixLeft(`mod`,VT.Modulo,(e,t,n)=>new hT(`mod`,e,n,(e,t)=>e%t)).infixLeft(`or`,VT.Or,(e,t,n)=>new OT(e,n)).infixLeft(`xor`,VT.Xor,(e,t,n)=>new kT(e,n)).infixLeft(`implies`,VT.Implies,(e,t,n)=>new AT(e,n))}var qT=KT();function JT(e){return new lT(e,qT.construct(BT(e)).consumeAndParse())}function YT(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]=zS(i[e]))}return XT(e,i,n,r).map(e=>e.value)}function XT(e,t,n={},r=void 0){let i;if(typeof e==`string`){let t=r?.get(e);i=t??JT(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=iC(n.value);e&&t.push(e)}return t}function QT(e){let t=new Set;for(let n of e){let e=mw(n);e&&t.add(e)}return Array.from(t)}function $T(e){let t=new Set;for(let n of e){let{value:e}=n;e&&(UC(e)?t.add(e):$w(e)?t.add(e.reference):fC(e)?t.add(mC(e)):typeof e.identifier==`object`&&t.add(`identifier:${e.identifier.system}|${e.identifier.value}`))}return Array.from(t)}function eE(e,t={}){let n=[];for(let r of e)tE(t,n,r);return n}function tE(e,t,n){let{type:r,value:i}=n;switch(r){case X.Identifier:nE(t,e,i);break;case X.CodeableConcept:rE(t,e,i);break;case X.Coding:iE(t,e,i);break;case X.ContactPoint:aE(t,e,i);break;default:oE(t,e,void 0,i?.toString())}}function nE(e,t,n){n?.type?.text&&oE(e,t,t.textSearchSystem,n.type.text),oE(e,t,n?.system,n?.value)}function rE(e,t,n){n?.text&&oE(e,t,t.textSearchSystem,n.text);for(let r of n?.coding??pw)iE(e,t,r)}function iE(e,t,n){n&&(n.display&&oE(e,t,t.textSearchSystem,n.display),oE(e,t,n.system,n.code))}function aE(e,t,n){n&&oE(e,t,n.system,n.value?.toLocaleLowerCase())}function oE(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`},sE={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},cE={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 lE(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 uE(i,a)}function uE(e,t){let n={resourceType:e};for(let[e,r]of t)dE(n,e,r);return n}function dE(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=iw(e.filters,{code:t,operator:Z.EQUALS,value:n});return}switch(r){case`_sort`:fE(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=vE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.include=iw(e.include,t);break}case`_revinclude`:{let t=vE(n);i===`iterate`&&(t.modifier=Z.ITERATE),e.revInclude=iw(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=eT.types[e.resourceType]?.searchParams?.[r];e.filters=t?iw(e.filters,mE(t,Z.EQUALS,i,n)):iw(e.filters,hE(r,i,n))}}}}function fE(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 pE=[Z.MISSING,Z.PRESENT];function mE(e,t,n,r){if(pE.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}=gE(r,n||Z.EQUALS);if(!yE(e,i))throw new iS(Xx(`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(!yE(e,r))throw new iS(Xx(`Invalid format for ${e.type} search parameter: ${r}`));return{code:e.code,operator:_E(n)??t,value:r};default:throw Error(`Unrecognized search parameter type: `+e.type)}}function hE(e,t,n){let r=Z.EQUALS;if(t)r=t;else if(n.length>=2){let e=n.substring(0,2);e in cE&&(n.length===2||n.at(2)?.match(/\d/))&&(r=e,n=n.substring(e.length))}return{code:e,operator:r,value:n}}function gE(e,t){let n=cE[e.substring(0,2)];return n?{operator:n,value:e.substring(2)}:{operator:t,value:e}}function _E(e){return sE[e]}function vE(e){let t=e.split(`:`);if(t.includes(`*`))throw new iS(Xx(`'*' is not supported as a value for search inclusion parameters`));if(t.length===1)throw new iS(Xx(`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 iS(Xx(`Invalid include value '${e}'`))}function yE(e,t){switch(e.type){case`date`:return nC(t);default:return!0}}function bE(e){let t=[];e.fields&&t.push(`_fields=`+e.fields.join(`,`));for(let n of e.filters??pw)t.push(xE(n));e.sortRules&&e.sortRules.length>0&&t.push(SE(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??pw)t.push(CE(`_include`,n));for(let n of e.revInclude??pw)t.push(CE(`_revinclude`,n));return t.length===0?``:(aw(t),`?`+t.join(`&`))}function xE(e){let t=e.operator in sE?`:`+e.operator:``,n=e.operator!==Z.EQUALS&&e.operator in cE?e.operator:``;return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}function SE(e){return`_sort=`+e.map(e=>e.descending?`-`+e.code:e.code).join(`,`)}function CE(e,t){return e+(t.modifier?`:`+t.modifier:``)+`=`+t.resourceType+`:`+t.searchParam+(t.targetType?`:`+t.targetType:``)}function wE(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 TE(e,t){if(t.resourceType!==e.resourceType)return!1;for(let n of t.filters??pw)if(!DE(e,t,n))return!1;return!0}var EE=new bx(1e3);function DE(e,t,n){let r=eT.types[t.resourceType]?.searchParams?.[n.code];if(!r)return!1;let i=XT(r.expression,[zS(e)],void 0,EE);if(n.operator===Z.MISSING||n.operator===Z.PRESENT)return OE(i,n);switch(r.type){case`reference`:return kE(r,i,n);case`string`:case`uri`:return ME(i,n);case`token`:return AE(i,n);case`date`:return PE(i,n);default:return!1}}function OE(e,t){let n=e.length>0;return(t.operator===Z.MISSING&&t.value===`false`||t.operator===Z.PRESENT&&t.value===`true`)===n}function kE(e,t,n){let r=IE(n.operator);if(n.value===``&&t.length===0)return n.operator===Z.EQUALS;let i=$T(t);for(let t of wE(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 AE(e,t){let n=eE(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let t of r)if(jE(e,t))return!i;return i}function jE(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 ME(e,t){let n=QT(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let t of r)if(NE(e,t))return!i;return i}function NE(e,t){return e.toLowerCase().includes(t.toLowerCase())}function PE(e,t){let n=ZT(e),r=wE(t.value),i=IE(t.operator);for(let e of n)for(let n of r)if(FE(e,t.operator,n))return!i;return i}function FE(e,t,n){if(!e)return!1;let r=iC(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 IE(e){return e===Z.NOT_EQUALS||e===Z.NOT}var LE={resourceType:`*`},RE=[`DomainConfiguration`,`JsonWebKey`,`Login`],zE=[`Package`,`PackageRelease`,`PackageInstallation`,`Project`,`ProjectMembership`,`User`,`UserSecurityRequest`],BE={READ:`read`,VREAD:`vread`,UPDATE:`update`,DELETE:`delete`,HISTORY:`history`,CREATE:`create`,SEARCH:`search`},VE=[BE.READ,BE.VREAD,BE.HISTORY,BE.SEARCH];function HE(e,t){return!RE.includes(t)&&UE(e,BE.UPDATE,t)}function UE(e,t,n){return!!e.resource?.some(e=>KE(e,n,t))}function WE(e,t,n){return n?n.resource?.find(n=>GE(e,t,n)):LE}function GE(e,t,n){let r=e.resourceType;return KE(n,r,t)?r===`Binary`||!(n.compartment&&!e.meta?.compartment?.some(e=>e.reference===n.compartment?.reference)||n.criteria&&!TE(e,lE(n.criteria))):!1}function KE(e,t,n){return e.resourceType!==t&&(e.resourceType!==`*`||zE.includes(t))?!1:e.interaction?e.interaction.includes(n):!e.readonly||VE.includes(n)}function qE(){return typeof window<`u`}function JE(){return typeof Buffer<`u`?Buffer:void 0}var YE={assign(e){qE()&&globalThis.location.assign(e)},reload(){qE()&&globalThis.location.reload()},getSearch(){return qE()?globalThis.location.search:``},getPathname(){return qE()?globalThis.location.pathname:``},getLocation(){return qE()?globalThis.location.toString():``},getOrigin(){return qE()?globalThis.location.protocol+`//`+globalThis.location.host+`/`:``}};function XE(e){if(qE()){let t=window.atob(e),n=Uint8Array.from(t,e=>e.codePointAt(0));return new window.TextDecoder().decode(n)}let t=JE();if(t)return t.from(e,`base64`).toString(`utf-8`);throw Error(`Unable to decode base64`)}function ZE(e){if(qE()){let t=new window.TextEncoder().encode(e),n=String.fromCodePoint.apply(null,t);return window.btoa(n)}let t=JE();if(t)return t.from(e,`utf8`).toString(`base64`);throw Error(`Unable to encode base64`)}function QE(e){return e=e.padEnd(e.length+(4-e.length%4)%4,`=`),XE(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`))}function $E(){let e=new Uint32Array(28);return crypto.getRandomValues(e),JC(e.buffer)}async function eD(e){return crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))}function tD(){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 nD(e){let t={};e=BC(e);for(let n of e.entry??pw){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]=tD(),n.fullUrl=`urn:uuid:`+t[r],delete n.resource?.id;else if(n.fullUrl?.startsWith(`resource:`)){let e=n.fullUrl.slice(9);t[e]=tD(),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)=>rD(e,n,t),2);return iD(JSON.parse(r))}function rD(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 iD(e){let{sorted:t,cycles:n}=oD(cD(e)),r={},i=[];for(let t of e.entry??pw)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 aD={NotVisited:`NotVisited`,Visiting:`Visiting`,Visited:`Visited`};function oD(e){let t=[],n={},r=[];for(let t of Object.keys(e))n[t]=aD.NotVisited;function i(a,o){if(n[a]===aD.Visited)return!0;if(n[a]===aD.Visiting){let e=o.lastIndexOf(a);return e!==-1&&r.push(o.slice(e)),!0}n[a]=aD.Visiting,o.push(a);let s=!1;for(let t of e[a]??pw)i(t,o)||(s=!0);return n[a]=aD.Visited,o.pop(),t.unshift(a),!s}for(let t in e)n[t]===aD.NotVisited&&i(t,[]);return{sorted:t,cycles:r}}function sD(e,t){for(let n in e)if(e[n]&&typeof e[n]==`object`){let r=e[n];if($w(r)){let e=r.reference;(e.startsWith(`urn:uuid:`)||e.startsWith(`resource:`))&&t(e)}else sD(r,t)}}function cD(e){let t={};for(let n of e.entry??pw)n.fullUrl&&(t[n.fullUrl]=[]);for(let n of e.entry??pw){let e=n.fullUrl;e&&n.resource&&sD(n.resource,n=>{n!==e&&t[n]&&t[n].push(e)})}return t}var lD={CSS:`text/css`,DICOM:`application/dicom`,DICOM_JSON:`application/dicom+json`,EVENT_STREAM:`text/event-stream`,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`},uD=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??pw)try{n.call(this,e)}catch(t){console.error(`Unhandled error in "${e.type}" event listener`,t)}return!e.defaultPrevented}removeAllListeners(){this.listeners={}}listenerCount(e){return this.listeners[e]?.length??0}},dD=class{emitter=new uD;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)}},fD={Event:globalThis.Event===void 0?void 0:globalThis.Event,ErrorEvent:void 0,CloseEvent:void 0},pD=!1;function mD(){if(globalThis.Event===void 0)throw Error(`Unable to lazy init events for ReconnectingWebSocket. globalThis.Event is not defined yet`);fD.Event=globalThis.Event,fD.ErrorEvent=class extends Event{message;error;constructor(e,t){super(`error`,t),this.message=e.message,this.error=e}},fD.CloseEvent=class extends Event{code;reason;wasClean=!0;constructor(e=1e3,t=``,n){super(`close`,n),this.code=e,this.reason=t}}}function hD(e,t){if(!e)throw Error(t)}function gD(){}function _D(e){if(e instanceof fD.CloseEvent){let t=e;return new fD.CloseEvent(t.code,t.reason,void 0)}if(e instanceof fD.ErrorEvent){let t=e;return new fD.ErrorEvent(t.error??Error(t.message),void 0)}return new e.constructor(e.type,e)}function vD(e,t){let n=e;return n.error instanceof Error?new fD.ErrorEvent(n.error,t):new fD.ErrorEvent(Error(n.message||`WebSocket error`),t)}var yD={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},bD=!1,xD=class e extends dD{_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={}){pD||=(mD(),!0),super(),this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._binaryType=this._options.binaryType?this._options.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=yD.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=yD.reconnectionDelayGrowFactor,minReconnectionDelay:t=yD.minReconnectionDelay,maxReconnectionDelay:n=yD.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=yD.maxRetries,connectionTimeout:t=yD.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`&&!bD&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket.`),bD=!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 fD.ErrorEvent(Error(e.message),this))})}_handleTimeout(){this._debug(`timeout event`),this._handleError(new fD.ErrorEvent(Error(`TIMEOUT`),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),!this._ws)return;let n=this._ws;this._removeListeners(),n.addEventListener(`error`,gD);try{n.close(e,t),this._handleClose(new fD.CloseEvent(e,t,this))}catch{}}_acceptOpen(){this._debug(`accept open`),this._retryCount=0}_handleOpen=e=>{this._debug(`open event`);let{minUptime:t=yD.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),hD(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(_D(e))};_handleMessage=e=>{this._debug(`message event`),this.onmessage&&this.onmessage(e),this.dispatchEvent(_D(e))};_handleError=e=>{let t=vD(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(_D(t)),this._connect()};_handleClose=e=>{this._debug(`close event`),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(_D(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)}},SD={"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`},CD=[`Patient`,`Encounter`,`ImagingStudy`,`DiagnosticReport`,`OperationOutcome`,`Bundle`],wD=[`DiagnosticReport-update`];function TD(e){return wD.includes(e)}function ED(e){if(wD.includes(e))throw new iS(Zx(`'context.version' is required for '${e}'.`))}var DD={"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 CD.includes(e)}function kD(e){return!!e.endpoint}function AD(e){if(!jD(e))throw new iS(Zx(`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};return n===`subscribe`&&(a[`hub.events`]=i.join(`,`)),kD(e)&&(a[`hub.channel.endpoint`]=e.endpoint),new URLSearchParams(a).toString()}function jD(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(!SD[e])return!1;return!(kD(e)&&!(typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))}function MD(e,t,n,r){if(typeof t!=`object`)throw new iS(Zx(`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 iS(Zx(`context[${n}] is invalid. Resource must contain a valid string ID.`));if(!t.resourceType)throw new iS(Zx(`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 iS(Zx(`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 iS(Zx(`context[${n}] is invalid. context[${n}] for the '${e}' event should contain resource of type ${i}.`))}}function ND(e,t,n,r,i){if(i.set(t.key,(i.get(t.key)??0)+1),r.reference){if(!$w(t.reference))throw new iS(Zx(`context[${n}] is invalid. Expected key '${t.key}' to be a reference.`))}else MD(e,t.resource,n,r)}function PD(e,t){let n=new Map,r=DD[e];for(let i=0;i<t.length;i++){let a=t[i].key;if(!r[a])throw new iS(Zx(`Key '${a}' not found for event '${e}'. Make sure to add only valid keys.`));ND(e,t[i],i,r[a],n)}for(let[t,i]of Object.entries(r)){if(!(i.optional||n.has(t)))throw new iS(Zx(`Missing required key '${t}' on context for '${e}' event.`));if(!i.manyAllowed&&(n.get(t)??0)>1)throw new iS(Zx(`${n.get(t)} context entries with key '${t}' found for the '${e}' event when schema only allows for 1.`))}}function FD(e,t,n,r){if(!(e&&typeof e==`string`))throw new iS(Zx(`Must provide a topic.`));if(!SD[t])throw new iS(Zx(`Must provide a valid FHIRcast event name. Supported events: ${Object.keys(SD).join(`, `)}`));if(typeof n!=`object`)throw new iS(Zx(`context must be a context object or array of context objects.`));if(wD.includes(t)&&!r)throw new iS(Zx(`The '${t}' event must contain a 'context.versionId'.`));let i=Array.isArray(n)?n:[n];return PD(t,i),{timestamp:new Date().toISOString(),id:tD(),event:{"hub.topic":e,"hub.event":t,context:i,...r?{"context.versionId":r}:{}}}}var ID=class extends dD{subRequest;websocket;constructor(e,t){if(super(),this.subRequest=e,!e.endpoint)throw new iS(Zx(`Subscription request should contain an endpoint.`));if(!jD(e))throw new iS(Zx(`Subscription request failed validation.`));let{ReconnectingWebSocket:n=xD,...r}=t??{},i=new n(e.endpoint,void 0,r);i.addEventListener(`open`,()=>{this.dispatchEvent({type:`connect`})}),i.addEventListener(`message`,e=>{let t=JSON.parse(e.data);if(!t.event){t[`hub.mode`]===`denied`&&this.disconnect();return}let n=t;n.event[`hub.event`]!==`heartbeat`&&(this.dispatchEvent({type:`message`,payload:n}),i.send(JSON.stringify({id:t?.id,timestamp:new Date().toISOString()})))}),i.addEventListener(`close`,()=>{this.dispatchEvent({type:`disconnect`})}),this.websocket=i}disconnect(){this.websocket.close()}};function LD(e){return JSON.parse(QE(e))}function RD(e){return e.split(`.`).length===3}function zD(e){let[t,n,r]=e.split(`.`);return LD(n)}function BD(e){try{return typeof zD(e).login_id==`string`}catch{return!1}}function VD(e){try{let t=zD(e).exp;return typeof t==`number`?t*1e3:void 0}catch{return}}var HD=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,lD.TEXT)}async delete(e){await this.medplum.delete(`keyvalue/v1/${e}`)}},UD=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)}},WD=class{storage;prefix=``;constructor(e,t=``){this.storage=e??globalThis.localStorage??new GD,this.prefix=t}makeKey(e){return this.prefix+e}clear(){if(this.storage===globalThis.localStorage&&this.prefix)for(let e=this.storage.length-1;e>=0;e--){let t=this.storage.key(e);t?.startsWith(this.prefix)&&this.storage.removeItem(t)}else 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?DC(t):void 0)}},GD=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]}},KD=6e4,qD=[WebSocket.CLOSING,WebSocket.CLOSED],JD=class extends dD{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)}},YD=class{criteria;emitter;refCount;subscriptionProps;subscriptionId;token;tokenExpiry;state=`idle`;generation=0;lastUnrefTime;constructor(e,t){this.criteria=e,this.emitter=new JD(e),this.refCount=1,this.subscriptionProps=t?{...t}:void 0}nextGeneration(){return++this.generation}},XD=class{medplum;ws;masterSubEmitter;criteriaEntries;criteriaEntriesBySubscriptionId;wsClosed;pingTimer=void 0;tokenRefreshTimer=void 0;pingIntervalMs;waitingForPong=!1;currentProfile;constructor(e,t,n){if(!(e instanceof dO))throw new iS(Zx("First arg of constructor should be a `MedplumClient`"));let r;try{r=new URL(t).toString()}catch{throw new iS(Zx(`Not a valid URL`))}let i=n?.ReconnectingWebSocket?new n.ReconnectingWebSocket(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger}):new xD(r,void 0,{debug:n?.debug,debugLogger:n?.debugLogger});this.medplum=e,this.ws=i,this.masterSubEmitter=new JD,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){console.warn(`Received WebSocket message without a SubscriptionStatus resource; ignoring`,n);return}if(r.type===`heartbeat`){this.masterSubEmitter?.dispatchEvent({type:`heartbeat`,payload:n});return}if(r.type===`handshake`){let e=hC(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(hC(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 iS({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()},KD)}),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(PC(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!PC(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 ${mC(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 iS(Zx(`Failed to get token`));if(!i)throw new iS(Zx(`Failed to get URL from $get-ws-binding-token`));if(!a)throw new iS(Zx(`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 YD(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 JD(...Array.from(this.criteriaEntries.keys())),this.masterSubEmitter}async reconnectIfNeeded(){qD.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 bx(1e3);var QD=`5.1.30-9b1bd92`,$D=lD.FHIR_JSON+`, */*; q=0.1`,eO=`https://api.medplum.com/`,tO=1e3,nO=6e4,rO=0,iO=3e5,aO=`Binary/`,oO={resourceType:`Device`,id:`system`,deviceName:[{type:`model-name`,name:`System`}]},sO=2,cO={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`},lO={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`},uO={JwtBearer:`urn:ietf:params:oauth:client-assertion-type:jwt-bearer`},dO=class extends dD{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??fO(),this.storage=e?.storage??new WD(void 0,e?.storagePrefix),this.createPdfImpl=e?.createPdf,this.baseUrl=ow(e?.baseUrl??eO),this.fhirBaseUrl=cw(this.baseUrl,e?.fhirUrlPath??`fhir/R4`),this.authorizeUrl=cw(this.baseUrl,e?.authorizeUrl??`oauth2/authorize`),this.tokenUrl=cw(this.baseUrl,e?.tokenUrl??`oauth2/token`),this.logoutUrl=cw(this.baseUrl,e?.logoutUrl??`oauth2/logout`),this.fhircastHubUrl=cw(this.baseUrl,e?.fhircastHubUrl??`fhircast/STU3`),this.cdsServicesUrl=cw(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??iO,this.logLevel=this.initializeLogLevel(e),this.maxRetries=e?.maxRetries??2,this.maxRetryTime=e?.maxRetryTime??2e3,this.cacheTime=e?.cacheTime??(qE()?nO:rO),this.requestCache=this.cacheTime>0?new bx(e?.resourceCacheSize??tO):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=cw(this.fhirBaseUrl,e);for(let e of this.requestCache?.keys()??pw)(e.endsWith(t)||e.includes(t+`?`))&&this.requestCache?.delete(e)}notifyResourceModified(e){e.operation!==`delete`&&e.resource?this.cacheResource(e.resource,void 0):e.id&&this.deleteCacheEntry(this.fhirUrl(e.resourceType,e.id).toString()),this.invalidateSearches(e.resourceType),this.dispatchResourceModified(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 UD(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,lD.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(YE.getSearch()).get(`code`);if(!t){await this.requestAuthorization(e);return}return this.processCode(t)}signOutWithRedirect(){YE.assign(this.logoutUrl)}async signInWithExternalAuth(e,t,n,r,i=!0){let a=r;i&&(a=await this.ensureCodeChallenge(r)),YE.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:cO.TokenExchange,subject_token_type:lO.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(cw(this.fhirBaseUrl,e.join(`/`)))}fhirSearchUrl(e,t){let n=this.fhirUrl(e);return t&&(n.search=uw(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 UD(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 UD(this.search(e,t,n).then(mO));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 mO(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 oO;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 UD(Promise.reject(Error(`Missing reference`)));if(n===`system`)return new UD(Promise.resolve(oO));let[r,i]=n.split(`/`);return!r||!i?new UD(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(bS(e))return Promise.resolve();let n=e+`-requestSchema`,r=this.getCacheEntry(n,void 0);if(r)return r.value;let i=new UD((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 Dr({color:e,theme:t,autoContrast:n}){ret
|
|
|
93
93
|
expression,
|
|
94
94
|
target
|
|
95
95
|
}
|
|
96
|
-
}`.replaceAll(/\s+/g,` `),n=await this.graphql(t);_S(n.data.StructureDefinitionList);for(let e of n.data.SearchParameterList)zw(e)})());return this.setCacheEntry(n,i,t),i}requestProfileSchema(e,t){if(!t?.expandProfile&&CS(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 ND((async()=>{if(t?.expandProfile){let t=this.fhirUrl(`StructureDefinition`,`$expand-profile`);t.search=new URLSearchParams({url:e}).toString(),_S(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}vS(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)}async createResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);this.invalidateSearches(e.resourceType);let n=await this.post(this.fhirUrl(e.resourceType),e,void 0,t);return this.dispatchResourceModified({resourceType:e.resourceType,operation:`create`,id:n?.id,resource:n}),n}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),this.dispatchResourceModified({resourceType:e.resourceType,operation:`create`,id:i?.id,resource:i}),i}async upsertResource(e,t,n){let r=this.fhirSearchUrl(e.resourceType,t),i=await this.put(r,e,void 0,n),a=i!==void 0;return i||=e,this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),a&&this.dispatchResourceModified({resourceType:e.resourceType,operation:`update`,id:i.id,resource:i}),i}async createAttachment(e,t,n,r,i){let a=gO(e,t,n,r);if(a.contentType===lD.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:lD.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=gO(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 iS(aS(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=vO(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=pC(e),a=e.subject),e.resourceType===`ServiceRequest`&&(i=e.encounter,a=e.subject),e.resourceType===`Patient`&&(a=pC(e)),this.createResource({resourceType:`Communication`,status:`completed`,basedOn:[pC(e)],encounter:i,subject:a,sender:r?pC(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),r=n!==void 0;return n||=e,this.cacheResource(n,t),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),r&&this.dispatchResourceModified({resourceType:e.resourceType,operation:`update`,id:n.id,resource:n}),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),this.dispatchResourceModified({resourceType:e,operation:`patch`,id:t,resource:i}),i}async deleteResource(e,t,n){this.deleteCacheEntry(this.fhirUrl(e,t).toString()),this.invalidateSearches(e);let r=await this.delete(this.fhirUrl(e,t),n);return this.dispatchResourceModified({resourceType:e,operation:`delete`,id:t}),r}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,lD.JSON,t)}graphql(e,t,n,r){return this.post(this.fhirUrl(`$graphql`),{query:e,operationName:t,variables:n},lD.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`,hC(e),`$push`),{destination:typeof t==`string`?t:mC(t),body:n,contentType:r,waitForResponse:i,...o===void 0?void 0:{waitTimeout:o},...s===void 0?void 0:{returnAck:s}},lD.FHIR_JSON,c)}getCdsServices(e){return this.get(this.cdsServicesUrl,e)}callCdsService(e,t,n){return this.post(cw(this.cdsServicesUrl,e),t,lD.JSON,n)}getActiveLogin(){return this.storage.getObject(`activeLogin`)}async setActiveLogin(e){(!this.sessionDetails?.profile||mC(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=jD(e),this.medplumServer=AD(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(aO)&&(e=this.fhirUrl(n));let r=t.headers;return r||(r={},t.headers=r),r.Accept||(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||=pC(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||=pC(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 MD(this),this.keyValueClient}getBundle(e,t){return new ND((async()=>{let n=await this.get(e,t);for(let e of n.entry??pw)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 ND(Promise.resolve(e)),t)}deleteCacheEntry(e){this.requestCache&&this.requestCache.delete(e)}dispatchResourceModified(e){this.listenerCount(`resourceModified`)>0&&this.dispatchEvent({type:`resourceModified`,payload: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 iS(Gx);let a=await this.parseBody(r,i);if(r.status===200&&t.followRedirectOnOk||r.status===201&&t.followRedirectOnCreated){let e=await pO(r,a);if(e)return this.request(e,{...t,method:`GET`,body:void 0})}if(r.status===202&&t.pollStatusOnAccepted){let e=await pO(r,a)??n.statusUrl;if(e)return this.pollStatus(e,t,n)}if(r.status>=400)throw new iS(aS(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=cw(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||!yO(i))return i;let a=this.getRetryDelay(r);if(a>(t.maxRetryTime??this.maxRetryTime))return i;await tw(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 aw(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 tw(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(cw(this.fhirBaseUrl,t.url),t.options))}catch(e){t.reject(new iS(aS(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&&!tS(i.response.outcome)?r.reject(new iS(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`,$D,!0),this.options.extendedMode!==!1&&this.setRequestHeader(e,`X-Medplum`,`extended`),e.body&&this.setRequestHeader(e,`Content-Type`,lD.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}if(n instanceof Headers)return n.get(t)??void 0;if(HC(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):HC(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<sO?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 iS(Kx)}async startPkce(){let e=$E();this.storage.setString(`pkceState`,e);let t=$E().slice(0,128);this.storage.setString(`codeVerifier`,t);try{return{codeChallengeMethod:`S256`,codeChallenge:YC(await eD(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??YE.getOrigin()),n.searchParams.set(`code_challenge_method`,t.codeChallengeMethod),n.searchParams.set(`code_challenge`,t.codeChallenge),n.searchParams.set(`scope`,t.scope??`openid profile`),YE.assign(n.toString())}processCode(e,t){let n={grant_type:cO.AuthorizationCode,code:e,client_id:t?.clientId??this.clientId??``,redirect_uri:t?.redirectUri??YE.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:cO.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:cO.ClientCredentials,client_id:e,client_secret:t})}async startJwtBearerLogin(e,t,n){return this.clientId=e,this.fetchTokens({grant_type:cO.JwtBearer,client_id:e,assertion:t,scope:n})}async startJwtAssertionLogin(e){return this.fetchTokens({grant_type:cO.ClientCredentials,client_assertion_type:uO.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 iS(Zx(`Invalid topic provided. Topic must be a valid string.`));if(!(typeof t==`object`&&Array.isArray(t)&&t.length>0))throw new iS(Zx(`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,bD(n),lD.FORM_URL_ENCODED))[`hub.channel.endpoint`];if(!r)throw Error(`Invalid response!`);return n.endpoint=r,n}async fhircastUnsubscribe(e){if(!xD(e))throw new iS(Zx(`Invalid topic or subscriptionRequest. SubscriptionRequest must be an object.`));if(!(e.endpoint&&typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))throw new iS(Zx(`Provided subscription request must have an endpoint in order to unsubscribe.`));e.mode=`unsubscribe`,await this.post(this.fhircastHubUrl,bD(e),lD.FORM_URL_ENCODED)}fhircastConnect(e){return new ED(e)}async fhircastPublish(e,t,n,r){return hD(t)?this.post(this.fhircastHubUrl,TD(e,t,n,r),lD.JSON):(gD(t),this.post(this.fhircastHubUrl,TD(e,t,n),lD.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 eS(t)?new iS(t):t.error_description?new iS(Xx(t.error_description)):Error(JSON.stringify(t))}catch(e){throw e instanceof iS?(e.message=`Failed to fetch tokens: ${e.message}`,e):new iS(Xx(`Failed to fetch tokens`),{cause:e})}}async fetchTokens(e){let t=new URLSearchParams(e),n={...this.defaultHeaders,"Content-Type":lD.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(OD(t)){let e=kD(t);if(Date.now()>=e.exp*1e3)throw this.clearActiveLogin(),new iS(qx);if(e.cid){if(e.cid!==this.clientId)throw this.clearActiveLogin(),new iS(Jx)}else if(this.clientId&&e.client_id!==this.clientId)throw this.clearActiveLogin(),new iS(Jx)}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)YE.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)?YE.reload():n?this.setAccessToken(n.accessToken,n.refreshToken):this.clear()}})}catch{}}getSubscriptionManager(){return this.subscriptionManager||=new XD(this,lw(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 fO(){if(!globalThis.fetch)throw Error(`Fetch not available in this environment`);return globalThis.fetch.bind(globalThis)}async function pO(e,t){let n=e.headers.get(`content-location`);if(n)return n;let r=e.headers.get(`location`);if(r)return r;if(eS(t)&&t.issue?.[0]?.diagnostics)return t.issue[0].diagnostics}function mO(e){let t=e.entry?.map(e=>e.resource)??[];return Object.assign(t,{bundle:e})}function hO(e){return HC(e)&&`data`in e&&`contentType`in e}function gO(e,t,n,r){return hO(e)?e:{data:e,filename:t,contentType:n,onProgress:r}}function _O(e){return HC(e)&&`docDefinition`in e}function vO(e,t,n,r){return _O(e)?e:{docDefinition:e,filename:t,tableLayouts:n,fonts:r}}function yO(e){return e.status===429||e.status>=500}function bO({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=xO(t,n,e,!!i),s=nw(t,`.`,2)[1];o=SO(o,a,s),o=CO(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=nw(t,`.`,2)[1];if(n){if(!e[n]){let t=wO(n,a?.hiddenFields);e[n]={hidden:t,readonly:t||wO(n,a?.readonlyFields)}}return e[n]}}}return{path:t,elements:o,elementsByPath:c,profileUrl:r??e?.profileUrl,debugMode:i,getExtendedProps:l,accessPolicyResource:a}}function xO(e,t,n,r){let i=Object.create(null);if(n)for(let[t,r]of Object.entries(n.elementsByPath)){let n=$C(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 SO(e,t,n){if(!t?.hiddenFields?.length)return e;let r=n?n+`.`:``;return Object.fromEntries(Object.entries(e).filter(([e])=>!wO(r+e,t.hiddenFields)))}function CO(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))r[n]=wO(i+n,t.readonlyFields)?{...a,readonly:!0}:a;return r}function wO(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 TO(e){return e.type!==void 0&&e.type.length>0}function EO(e,t,n,r){let i=NS(e,t.path,{profileUrl:r});if(i){let e=n.typeSchema?.elements??n.elements;return i.some(r=>LS(r,t,n,e))??!1}return console.assert(!1,`getNestedProperty[%s] in isDiscriminatorComponentMatch missed`,t.path),!1}function DO(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=>EO(t,e,i,i.typeSchema?.url??r)))return i.name}}var OO=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=bO({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(!MC(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=kO(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);MC(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(!TO(t))continue;let e=t.type.find(e=>MC(e.profile))?.profile?.[0];if(MC(e)){let n=wS(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;MC(a)&&(i=bO({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 kO(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 AO=`__sliceName`;function jO(e,t){let n=new NO(e,e.resourceType,`resource`);return new OO(t,n).crawlResource(),n.getDefaultValue()}function MO(e,t,n){for(let[r,i]of Object.entries(t)){if(n===void 0||n===r){LO(e,r,i,t);continue}let a=$C(n,r);a!==void 0&&LO(e,a,i,t)}return e}var NO=class{rootValue;schemaStack;valueStack;constructor(e,t,n){this.schemaStack=[],this.valueStack=[],this.rootValue=BC(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=$C(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=$C(n.path,i),s=Array.isArray(e)?e:[e];for(let e of s){PO(e,a,t,n.elements,r),LO(e,a,t,n.elements);let i=IO(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=$C(this.value.path,e);if(r===void 0)throw Error(`Expected ${e} to be prefixed by ${this.value.path}`);let i=$C(n.path,this.value.path);for(let e of this.value.values){let a=IO(e,r,n.elements,i);if(Array.isArray(a))for(let e=a.length-1;e>=0;e--){let t=a[e];MC(t)||a.splice(e,1)}jC(a)&&FO(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[AO]??DO(i,[t],n.discriminator,this.schema.url))===t.name&&r.push(i);for(let n=r.length;n<t.min;n++)if(QC(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];AO in n&&delete n[AO]}}getDefaultValue(){return this.rootValue}};function PO(e,t,n,r,i){let a=IO(e,t,r,i);n.min>0&&a===void 0&&QC(n.type[0].code)&&(n.isArray?FO(e,[Object.create(null)],t,n):FO(e,Object.create(null),t,n))}function FO(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]`,ZC(e))}t===void 0?delete e[i]:e[i]=t}function IO(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]`,ZC(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(HC(a)){if(a[t]===void 0)return;a=a[t]}else return}return o}function LO(e,t,n,r){if(!(n.fixed||n.pattern))return e;if(Array.isArray(e))return e.map(e=>LO(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]`,ZC(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]=RO(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 RO(e,t){if(Array.isArray(t)&&(Array.isArray(e)||e===void 0))return(e?.length??0)>0?e:BC(t);if(HC(t)&&(HC(e)&&!Array.isArray(e)||e===void 0)){let n=BC(e)??Object.create(null);for(let e of Object.keys(t))n[e]=RO(n[e],t[e]);return n}return e}var zO=Object.prototype.hasOwnProperty;function BO(e){return e===void 0?`undefined`:e===null?`null`:Array.isArray(e)?`array`:typeof e}function VO(e,t){let n=[];for(let r in e)zO.call(e,r)&&e[r]!==void 0&&!(zO.call(t,r)&&t[r]!==void 0)&&n.push(r);return n}function HO(e,t){let n=[];for(let r in e)zO.call(e,r)&&e[r]!==void 0&&zO.call(t,r)&&t[r]!==void 0&&n.push(r);return n}function UO(e){return e.op===`add`}function WO(e){return e.op===`remove`}function GO(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function KO(e,t,n,r=JO){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(GO(e,t))}if(c>0){let e=o(s,c-1),r={op:`add`,index:s-1,value:t[c-1]};n.push(GO(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(GO(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(UO(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]}if(WO(i)){let r={op:i.op,path:n.add(String(i.index+t)).toString()};return[e.concat(r),t-1]}{let a=n.add(String(i.index+t)),o=r(i.original,i.value,a);return[e.concat(...o),t]}},[[],0]);return c}function qO(e,t,n,r=JO){let i=[];return VO(e,t).forEach(e=>{i.push({op:`remove`,path:n.add(e).toString()})}),VO(t,e).forEach(e=>{i.push({op:`add`,path:n.add(e).toString(),value:t[e]})}),HO(e,t).forEach(a=>{i.push(...r(e[a],t[a],n.add(a)))}),i}function JO(e,t,n,r=JO){if(e===t)return[];let i=BO(e),a=BO(t);return i===`array`&&a===`array`?KO(e,t,n,r):i===`object`&&a===`object`?qO(e,t,n,r):[{op:`replace`,path:n.toString(),value:t}]}function YO(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function XO(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(YO);if(n[0]!==``)throw Error(`Invalid JSON Pointer: ${t}`);return new e(n)}toString(){return this.tokens.map(XO).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){let n=this.tokens.concat(String(t));return new e(n)}parent(){let t=this.tokens.length>1?this.tokens.slice(0,-1):[``];return new e(t)}};function QO(e){function t(n,r,i){let a=e(n,r,i);return Array.isArray(a)?a:JO(n,r,i,t)}return t}function $O(e,t,n){let r=new ZO;return(n?QO(n):JO)(e,t,r)}function ek(e){return e.match(/^\((.+)\)\.identifier$/)?.[1]}function tk(e,t){return new lT(e,new bT(t,new dT(`identifier`)))}var nk={BOOLEAN:`BOOLEAN`,NUMBER:`NUMBER`,QUANTITY:`QUANTITY`,TEXT:`TEXT`,REFERENCE:`REFERENCE`,CANONICAL:`CANONICAL`,DATE:`DATE`,DATETIME:`DATETIME`,PERIOD:`PERIOD`,UUID:`UUID`};function rk(e,t){return eT.types[e]?.searchParamsDetails?.[t.code]??ak(e,t)}function ik(e,t,n){let r=eT.types[e];r||(r={},eT.types[e]=r),r.searchParamsDetails||(r.searchParamsDetails={}),r.searchParamsDetails[t]=n}function ak(e,t){let n=t.code,r=t.expression,i=uk(e,r),a={elementDefinitions:[],propertyTypes:new Set,array:!1};for(let n of i){let r=pk(n),i=rw(()=>r.join(`.`));r.length===1&&r[0]instanceof Sx&&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`)):ok(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=ek(r);if(t===void 0)throw Error(`Unexpected expression for derived identifier search parameter: ${r}`);o=tk(r,dk(e,t))}else o=dk(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:lk(t,a.propertyTypes),elementDefinitions:s,parsedExpression:o,array:a.array,referenceTargetTypes:mk(t,s)};return ik(e,n,c),c}function ok(e,t,n,r){let i=t[r];if(i instanceof mT){e.propertyTypes.add(i.right.toString());return}if(i instanceof jT){sk(e,i);return}let a=i.toString(),o=Xw(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 MT&&(s=!0,c++);let l=t[c];if(o.isArray&&!s&&(e.array=!0),c===t.length-1){if(l instanceof mT){e.elementDefinitions.push(o),e.propertyTypes.add(l.right.toString());return}if(l instanceof jT&&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??pw)e.propertyTypes.add(t.code);return}for(let n of o.type??pw){let r=n.code;ck(r)&&(r=o.type[0].code),ok(e,t,r,c)}}function sk(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 ET){e.propertyTypes.add(t.args[0].right.toString());return}throw Error(`Unhandled FHIRPath function: ${t.name}`)}function ck(e){return e===`Element`||e===`BackboneElement`}function lk(e,t){switch(e.type){case`date`:return t.size===1&&t.has(X.date)?nk.DATE:nk.DATETIME;case`number`:return nk.NUMBER;case`quantity`:return nk.QUANTITY;case`reference`:return t.has(X.canonical)?nk.CANONICAL:nk.REFERENCE;case`token`:return t.size===1&&t.has(X.boolean)?nk.BOOLEAN:nk.TEXT;default:return nk.TEXT}}function uk(e,t){let n=[];return fk(e,JT(t).child,n),n}function dk(e,t){let n=[],r=JT(t);if(fk(e,r.child,n),n.length===0)return r;let i=n[0];for(let e=1;e<n.length;e++)i=new xT(i,n[e]);return new lT(`<original-not-available>`,i)}function fk(e,t,n){t instanceof xT?(fk(e,t.left,n),fk(e,t.right,n)):t.toString().includes(e+`.`)&&n.push(t)}function pk(e){return e instanceof mT||e instanceof MT?[pk(e.left),e].flat():e instanceof Sx&&e.operator!==`.`?[e]:e instanceof bT?[pk(e.left),pk(e.right)].flat():e instanceof jT&&(e.name===`where`&&!(e.args[0]instanceof ET)||e.name===`last`)?[]:[e]}function mk(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 hk=/^\d+\.\d+\.\d+(-[0-9a-z]{7})?$/,gk=`https://meta.medplum.com/releases`,_k=new Map;function vk(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 yk(e,t,n,r){let i=new URL(`${gk}/${e}`);if(i.searchParams.set(`a`,t),i.searchParams.set(`c`,QD),r)for(let[e,t]of Object.entries(r))i.searchParams.set(e,t);let a=await fetch(i.toString());if(a.status!==200){let e;try{e=(await a.json()).message}catch(e){console.error(`Failed to parse message from body: ${Y(e)}`)}throw Error(`Received status code ${a.status} while ${n}`,{cause:Error(e)})}return await a.json()}async function bk(e,t,n){let r=t?_k.get(t):void 0;if(!r){let i=await yk(`${t?`v${t}`:`latest`}.json`,e,`fetching manifest for version '${t??`latest`}'`,n);vk(i),r=i,_k.set(r.tag_name.slice(1),r)}return r}function xk(e){return hk.test(e)}function Sk(e){if(!hk.test(e))throw TypeError(`Version is not a valid Medplum semver (eg. 1.1.1 or 1.1.1-a1bc): ${e}`)}function Ck(e,t){let n=e.split(`-`)[0].split(`.`).map(Number),r=t.split(`-`)[0].split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t}return 0}async function wk(e){let t=await bk(e);if(!t.tag_name.startsWith(`v`))throw Error(`Invalid release name found. Release tag '${t.tag_name}' did not start with 'v'`);let n=t.tag_name.slice(1);return Sk(n),n}async function Tk(e,t){return((await yk(`all.json`,e,`fetching all release versions`,t)).versions??[]).map(e=>e.version).filter(xk).toSorted(Ck).reverse()}var Ek=(0,b.createContext)(void 0);function Dk(){return(0,b.useContext)(Ek)}function Q(){return Dk().medplum}function Ok(){return Dk().navigate}function kk(){return Dk().profile}var Ak=[`change`,`storageInitialized`,`storageInitFailed`,`profileRefreshing`,`profileRefreshed`];function jk(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 Ak)t.addEventListener(n,e);return()=>{for(let n of Ak)t.removeEventListener(n,e)}},[t]);let a=(0,b.useMemo)(()=>({...r,medplum:t,navigate:n}),[r,t,n]);return(0,I.jsx)(Ek.Provider,{value:a,children:e.children})}function Mk(e){window.location.assign(e)}var Nk=new Map,Pk=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=Nk.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 Nk.set(t,e),e},[e]),Fk=3e3;function Ik(e,t,n){let r=Q(),i=kk()?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)(()=>{PC(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||!PC(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)},Fk)}},[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 Lk(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]),Ik(i,()=>{s(`reload`)}),a}function Rk(e,t){let n=Q(),[r,i]=(0,b.useState)(()=>zk(n,e)),a=(0,b.useCallback)(e=>{PC(e,r)||i(e)},[r]);return(0,b.useEffect)(()=>{let r=!0,i=zk(n,e);return!i&&$w(e)?n.readReference(e).then(e=>{r&&a(e)}).catch(e=>{r&&(a(void 0),t&&t(aS(e)))}):a(i),(()=>r=!1)},[n,e,a,t]),r}function zk(e,t){if(t){if(Qw(t))return t;if($w(t))return e.getCachedReference(t)}}var Bk={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`},Vk=`${Ex}/fhir/StructureDefinition/questionnaire-itemControl`,Hk=`${Ex}/fhir/StructureDefinition/questionnaire-referenceFilter`,Uk=`${Ex}/fhir/StructureDefinition/questionnaire-referenceResource`,Wk=`${Ex}/fhir/StructureDefinition/questionnaire-validationError`,Gk=`${Ex}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression`,Kk=`${Ex}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression`,qk=`${Ex}/fhir/StructureDefinition/questionnaire-signatureRequired`,Jk=`${Ex}/fhir/StructureDefinition/questionnaireresponse-signature`,Yk=`${Ex}/fhir/StructureDefinition/questionnaire-hidden`,Xk=`${Ex}/fhir/StructureDefinition/questionnaire-optionExclusive`;function Zk(e){return e.type===`choice`||e.type===`open-choice`}function Qk(e,t){return{...t,item:$k(e.item,t.item,t)}}function $k(e,t,n){if(!t)return t;let r=[];for(let i of t){let t=e?.find(e=>e.linkId===i.linkId);t&&!eA(t,n)||(t?.item&&i.item?r.push({...i,item:$k(t.item,i.item,n)}):r.push(i))}return r}function eA(e,t){if(EC(e,Yk)?.valueBoolean===!0)return!1;let n=tA(e,t);return n===void 0?nA(e,t):n}function tA(e,t){let n=EC(e,Gk);if(t&&n){let e=n.valueExpression?.expression;if(e){let n=zS(t);return BS(XT(e,[n],{"%resource":n}))}}}function nA(e,t){if(!e.enableWhen)return!0;let n=e.enableBehavior??`any`;for(let r of e.enableWhen){let e=uA(t?.item,r.question);if(r.operator===`exists`&&!r.answerBoolean&&!e?.length){if(n===`any`)return!0;continue}let{anyMatch:i,allMatch:a}=fA(r,e,n);if(n===`any`&&i)return!0;if(n===`all`&&!a)return!1}return n!==`any`}function rA(e,t,n=t.item){for(let r of e){let e=n?.find(e=>e.linkId===r.linkId);e&&(iA(t,r,e),r.item&&e.item&&rA(r.item,t,e.item))}}function iA(e,t,n){try{let r=sA(t,e);if(!r)return;let i=oA(t,r);if(!i)return;n.answer=[i]}catch(e){n.extension=[{url:Wk,valueString:`Expression evaluation failed: ${Y(e)}`}]}}var aA={[Bk.boolean]:[X.boolean],[Bk.date]:[X.date],[Bk.dateTime]:[X.dateTime],[Bk.time]:[X.time],[Bk.url]:[X.string,X.uri,X.url],[Bk.attachment]:[X.Attachment],[Bk.reference]:[X.Reference],[Bk.quantity]:[X.Quantity],[Bk.decimal]:[X.decimal,X.integer],[Bk.integer]:[X.decimal,X.integer]};function oA(e,t){if(e.type){if(e.type===Bk.choice||e.type===Bk.openChoice)return{[`value${ZC(t.type)}`]:t.value};if(e.type===Bk.string||e.type===Bk.text)return typeof t.value==`string`?{valueString:t.value}:void 0;if(aA[e.type]?.includes(t.type))return{[`value${ZC(e.type)}`]:t.value}}}function sA(e,t){if(!t)return;let n=EC(e,Kk);if(n){let e=n.valueExpression?.expression;if(e){let n=zS(t),r=XT(e,[n],{"%resource":n});return r.length===0?void 0:r[0]}}}function cA(e,t,n){let r=[];for(let i of e){let e=n.answerOption?.find(e=>mw(CA(e))===i);if(e){let n=CA(e);n&&r.push({[t]:n.value})}}return r}function lA(e,t,n){let r=[];for(let t of e.answerOption??pw)if(EC(t,Xk)?.valueBoolean===!0){let e=CA(t);e?.value!==void 0&&r.push(e)}if(r.length===0)return n;let i=e=>{let t=TA(e);return!!t&&r.some(e=>PC(e,t))},a=n.filter(e=>!t?.some(t=>PC(t,e))),o=a.find(i);return o?[o]:a.some(e=>!i(e))?n.filter(e=>!i(e)):n}function uA(e,t){for(let n of e??pw){if(n.linkId===t)return n.answer;if(n.item){let e=uA(n.item,t);if(e)return e}}}function dA(e,t,n){if(n===`exists`)return!!e===t.value;if(e){let[{value:r}]=XT(`%actualAnswer ${n===`=`||n===`!=`?n?.replace(`=`,`~`):n} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":t});return r}return!1}function fA(e,t,n){let r=t||[],i=wA(e),a=!1,o=!0;for(let t of r){let r=TA(t),{operator:s}=e;if(dA(r,i,s)?a=!0:o=!1,n===`any`&&a)break}return{anyMatch:a,allMatch:o}}function pA(e){let t=EC(e,Uk);if(t){if(t.valueCode!==void 0)return[t.valueCode];if(t.valueCodeableConcept)return t.valueCodeableConcept?.coding?.map(e=>e.code)}}function mA(e,t){let n=BC(e),r=EC(n,Uk);return!t||t.length===0?(r&&(n.extension=n.extension?.filter(e=>e!==r)),n):(r||(n.extension??=[],r={url:Uk},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 hA(e,t,n){let r=EC(e,Hk);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]=nw(e,`=`,2);a[t]=n}return a}function gA(e,t){return{resourceType:`QuestionnaireResponse`,questionnaire:e.url??mC(e),item:_A(e.item,t?.item),status:`in-progress`}}function _A(e,t){let n;for(let r of e??pw){if(r.type===Bk.display)continue;let e=t?.filter(e=>e.linkId===r.linkId);if(e?.length)for(let t of e)t.id=t.id??bA(),t.text=t.text??r.text,t.item=_A(r.item,t.item),t.answer=xA(r,t),n=iw(n,t);else n=iw(n,vA(r))}return n}function vA(e){return{id:bA(),linkId:e.linkId,text:e.text,item:_A(e.item,void 0),answer:xA(e)}}var yA=1;function bA(){return`id-`+yA++}function xA(e,t){if(e.type!==Bk.display&&e.type!==Bk.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 SA(e){return GS({type:`QuestionnaireItemInitial`,value:e},`value`)}function CA(e){return GS({type:`QuestionnaireItemAnswerOption`,value:e},`value`)}function wA(e){return GS({type:`QuestionnaireItemEnableWhen`,value:e},`answer`)}function TA(e){return GS({type:`QuestionnaireResponseItemAnswer`,value:e},`value`)}function EA(e){let t=Rk(e.questionnaire),n=Rk(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:DA(t)),t&&e.defaultValue&&n&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=gA(t,n),p()),t&&!e.defaultValue&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=gA(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(vA(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=lA(t,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!==Jk),t.extension.push({url:Jk,valueSignature:e})):t.extension=t.extension?.filter(e=>e.url!==Jk),p())}function f(){let e=i.current.questionnaire;if(e?.item){let t=i.current.questionnaireResponse;rA(e.item,t)}}function p(){let t=i.current.questionnaireResponse,n=i.current.questionnaire;!t||!n||(f(),r(),e.onChange?.(Qk(n,t)))}return{loading:!1,pagination:!!i.current.pages,questionnaire:i.current.questionnaire,questionnaireResponse:Qk(i.current.questionnaire,i.current.questionnaireResponse),subject:e.subject,encounter:e.encounter,activePage:i.current.activePage,pages:i.current.pages,items:OA(i.current.questionnaire,i.current.pages,i.current.activePage),responseItems:kA(i.current.questionnaireResponse,i.current.pages,i.current.activePage),onNextPage:o,onPrevPage:s,onAddGroup:c,onAddAnswer:l,onChangeAnswer:u,onChangeSignature:d}}function DA(e){if(e?.item&&EC(e?.item?.[0],Vk)?.valueCodeableConcept?.coding?.[0]?.code===`page`)return e.item.map((e,t)=>({linkId:e.linkId,title:e.text??`Page ${t+1}`,group:e}))}function OA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function kA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function AA(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 jA=250;function MA(e,t,n){return PA(`searchOne`,e,t,n)}function NA(e,t,n){return PA(`searchResources`,e,t,n)}function PA(e,t,n,r){let i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(),d=i.fhirSearchUrl(t,n).toString(),f=(0,b.useMemo)(()=>({resourceType:t,query:n}),[d]),p=r?.enabled??!0,[m]=AA(f,r?.debounceMs??jA,{leading:!0});return(0,b.useEffect)(()=>{if(!p)return()=>{};o(!0);let t=!0;return i[e](m.resourceType,m.query).then(e=>{t&&(o(!1),c(e),u(Wx))}).catch(e=>{t&&(o(!1),c(void 0),u(aS(e)))}),()=>{t=!1}},[i,e,m,p]),[s,a,l]}function FA(e){if(e instanceof iS){let t=rS(e.outcome);return t===400||t===404}return!1}var IA=[];function LA(e){let t=Q(),n=Array.from(new Set(e.filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)).join(`
|
|
96
|
+
}`.replaceAll(/\s+/g,` `),n=await this.graphql(t);_S(n.data.StructureDefinitionList);for(let e of n.data.SearchParameterList)zw(e)})());return this.setCacheEntry(n,i,t),i}requestProfileSchema(e,t){if(!t?.expandProfile&&CS(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 UD((async()=>{if(t?.expandProfile){let t=this.fhirUrl(`StructureDefinition`,`$expand-profile`);t.search=new URLSearchParams({url:e}).toString(),_S(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}vS(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)}async createResource(e,t){if(!e.resourceType)throw Error(`Missing resourceType`);this.invalidateSearches(e.resourceType);let n=await this.post(this.fhirUrl(e.resourceType),e,void 0,t);return this.dispatchResourceModified({resourceType:e.resourceType,operation:`create`,id:n?.id,resource:n}),n}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),this.dispatchResourceModified({resourceType:e.resourceType,operation:`create`,id:i?.id,resource:i}),i}async upsertResource(e,t,n){let r=this.fhirSearchUrl(e.resourceType,t),i=await this.put(r,e,void 0,n),a=i!==void 0;return i||=e,this.cacheResource(i,n),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),a&&this.dispatchResourceModified({resourceType:e.resourceType,operation:`update`,id:i.id,resource:i}),i}async createAttachment(e,t,n,r,i){let a=gO(e,t,n,r);if(a.contentType===lD.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:lD.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=gO(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 iS(aS(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=vO(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=pC(e),a=e.subject),e.resourceType===`ServiceRequest`&&(i=e.encounter,a=e.subject),e.resourceType===`Patient`&&(a=pC(e)),this.createResource({resourceType:`Communication`,status:`completed`,basedOn:[pC(e)],encounter:i,subject:a,sender:r?pC(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),r=n!==void 0;return n||=e,this.cacheResource(n,t),this.invalidateUrl(this.fhirUrl(e.resourceType,e.id,`_history`)),this.invalidateSearches(e.resourceType),r&&this.dispatchResourceModified({resourceType:e.resourceType,operation:`update`,id:n.id,resource:n}),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),this.dispatchResourceModified({resourceType:e,operation:`patch`,id:t,resource:i}),i}async deleteResource(e,t,n){this.deleteCacheEntry(this.fhirUrl(e,t).toString()),this.invalidateSearches(e);let r=await this.delete(this.fhirUrl(e,t),n);return this.dispatchResourceModified({resourceType:e,operation:`delete`,id:t}),r}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,lD.JSON,t)}graphql(e,t,n,r){return this.post(this.fhirUrl(`$graphql`),{query:e,operationName:t,variables:n},lD.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`,hC(e),`$push`),{destination:typeof t==`string`?t:mC(t),body:n,contentType:r,waitForResponse:i,...o===void 0?void 0:{waitTimeout:o},...s===void 0?void 0:{returnAck:s}},lD.FHIR_JSON,c)}getCdsServices(e){return this.get(this.cdsServicesUrl,e)}callCdsService(e,t,n){return this.post(cw(this.cdsServicesUrl,e),t,lD.JSON,n)}getActiveLogin(){return this.storage.getObject(`activeLogin`)}async setActiveLogin(e){(!this.sessionDetails?.profile||mC(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=VD(e),this.medplumServer=BD(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(aO)&&(e=this.fhirUrl(n));let r=t.headers;return r||(r={},t.headers=r),r.Accept||(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||=pC(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||=pC(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 HD(this),this.keyValueClient}getBundle(e,t){return new UD((async()=>{let n=await this.get(e,t);for(let e of n.entry??pw)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 UD(Promise.resolve(e)),t)}deleteCacheEntry(e){this.requestCache&&this.requestCache.delete(e)}dispatchResourceModified(e){this.listenerCount(`resourceModified`)>0&&this.dispatchEvent({type:`resourceModified`,payload: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 iS(Gx);let a=await this.parseBody(r,i);if(r.status===200&&t.followRedirectOnOk||r.status===201&&t.followRedirectOnCreated){let e=await pO(r,a);if(e)return this.request(e,{...t,method:`GET`,body:void 0})}if(r.status===202&&t.pollStatusOnAccepted){let e=await pO(r,a)??n.statusUrl;if(e)return this.pollStatus(e,t,n)}if(r.status>=400)throw new iS(aS(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=cw(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||!yO(i))return i;let a=this.getRetryDelay(r);if(a>(t.maxRetryTime??this.maxRetryTime))return i;await tw(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 aw(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 tw(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(cw(this.fhirBaseUrl,t.url),t.options))}catch(e){t.reject(new iS(aS(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&&!tS(i.response.outcome)?r.reject(new iS(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`,$D,!0),this.options.extendedMode!==!1&&this.setRequestHeader(e,`X-Medplum`,`extended`),e.body&&this.setRequestHeader(e,`Content-Type`,lD.FHIR_JSON,!0),this.accessToken?this.setRequestHeader(e,`Authorization`,`Bearer `+this.accessToken):this.basicAuth&&this.setRequestHeader(e,`Authorization`,`Basic `+this.basicAuth),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}if(n instanceof Headers)return n.get(t)??void 0;if(HC(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):HC(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<sO?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 iS(Kx)}async startPkce(){let e=$E();this.storage.setString(`pkceState`,e);let t=$E().slice(0,128);this.storage.setString(`codeVerifier`,t);try{return{codeChallengeMethod:`S256`,codeChallenge:YC(await eD(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??YE.getOrigin()),n.searchParams.set(`code_challenge_method`,t.codeChallengeMethod),n.searchParams.set(`code_challenge`,t.codeChallenge),n.searchParams.set(`scope`,t.scope??`openid profile`),YE.assign(n.toString())}processCode(e,t){let n={grant_type:cO.AuthorizationCode,code:e,client_id:t?.clientId??this.clientId??``,redirect_uri:t?.redirectUri??YE.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:cO.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:cO.ClientCredentials,client_id:e,client_secret:t})}async startJwtBearerLogin(e,t,n){return this.clientId=e,this.fetchTokens({grant_type:cO.JwtBearer,client_id:e,assertion:t,scope:n})}async startJwtAssertionLogin(e){return this.fetchTokens({grant_type:cO.ClientCredentials,client_assertion_type:uO.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 iS(Zx(`Invalid topic provided. Topic must be a valid string.`));if(!(typeof t==`object`&&Array.isArray(t)&&t.length>0))throw new iS(Zx(`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,AD(n),lD.FORM_URL_ENCODED))[`hub.channel.endpoint`];if(!r)throw Error(`Invalid response!`);return n.endpoint=r,n}async fhircastUnsubscribe(e){if(!jD(e))throw new iS(Zx(`Invalid topic or subscriptionRequest. SubscriptionRequest must be an object.`));if(!(e.endpoint&&typeof e.endpoint==`string`&&e.endpoint.startsWith(`ws`)))throw new iS(Zx(`Provided subscription request must have an endpoint in order to unsubscribe.`));e.mode=`unsubscribe`,await this.post(this.fhircastHubUrl,AD(e),lD.FORM_URL_ENCODED)}fhircastConnect(e,t){return new ID(e,t)}async fhircastPublish(e,t,n,r){return TD(t)?this.post(this.fhircastHubUrl,FD(e,t,n,r),lD.JSON):(ED(t),this.post(this.fhircastHubUrl,FD(e,t,n),lD.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 eS(t)?new iS(t):t.error_description?new iS(Xx(t.error_description)):Error(JSON.stringify(t))}catch(e){throw e instanceof iS?(e.message=`Failed to fetch tokens: ${e.message}`,e):new iS(Xx(`Failed to fetch tokens`),{cause:e})}}async fetchTokens(e){let t=new URLSearchParams(e),n={...this.defaultHeaders,"Content-Type":lD.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(RD(t)){let e=zD(t);if(Date.now()>=e.exp*1e3)throw this.clearActiveLogin(),new iS(qx);if(e.cid){if(e.cid!==this.clientId)throw this.clearActiveLogin(),new iS(Jx)}else if(this.clientId&&e.client_id!==this.clientId)throw this.clearActiveLogin(),new iS(Jx)}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)YE.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)?YE.reload():n?this.setAccessToken(n.accessToken,n.refreshToken):this.clear()}})}catch{}}getSubscriptionManager(){return this.subscriptionManager||=new XD(this,lw(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 fO(){if(!globalThis.fetch)throw Error(`Fetch not available in this environment`);return globalThis.fetch.bind(globalThis)}async function pO(e,t){let n=e.headers.get(`content-location`);if(n)return n;let r=e.headers.get(`location`);if(r)return r;if(eS(t)&&t.issue?.[0]?.diagnostics)return t.issue[0].diagnostics}function mO(e){let t=e.entry?.map(e=>e.resource)??[];return Object.assign(t,{bundle:e})}function hO(e){return HC(e)&&`data`in e&&`contentType`in e}function gO(e,t,n,r){return hO(e)?e:{data:e,filename:t,contentType:n,onProgress:r}}function _O(e){return HC(e)&&`docDefinition`in e}function vO(e,t,n,r){return _O(e)?e:{docDefinition:e,filename:t,tableLayouts:n,fonts:r}}function yO(e){return e.status===429||e.status>=500}function bO({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=xO(t,n,e,!!i),s=nw(t,`.`,2)[1];o=SO(o,a,s),o=CO(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=nw(t,`.`,2)[1];if(n){if(!e[n]){let t=wO(n,a?.hiddenFields);e[n]={hidden:t,readonly:t||wO(n,a?.readonlyFields)}}return e[n]}}}return{path:t,elements:o,elementsByPath:c,profileUrl:r??e?.profileUrl,debugMode:i,getExtendedProps:l,accessPolicyResource:a}}function xO(e,t,n,r){let i=Object.create(null);if(n)for(let[t,r]of Object.entries(n.elementsByPath)){let n=$C(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 SO(e,t,n){if(!t?.hiddenFields?.length)return e;let r=n?n+`.`:``;return Object.fromEntries(Object.entries(e).filter(([e])=>!wO(r+e,t.hiddenFields)))}function CO(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))r[n]=wO(i+n,t.readonlyFields)?{...a,readonly:!0}:a;return r}function wO(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 TO(e){return e.type!==void 0&&e.type.length>0}function EO(e,t,n,r){let i=NS(e,t.path,{profileUrl:r});if(i){let e=n.typeSchema?.elements??n.elements;return i.some(r=>LS(r,t,n,e))??!1}return console.assert(!1,`getNestedProperty[%s] in isDiscriminatorComponentMatch missed`,t.path),!1}function DO(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=>EO(t,e,i,i.typeSchema?.url??r)))return i.name}}var OO=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=bO({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(!MC(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=kO(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);MC(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(!TO(t))continue;let e=t.type.find(e=>MC(e.profile))?.profile?.[0];if(MC(e)){let n=wS(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;MC(a)&&(i=bO({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 kO(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 AO=`__sliceName`;function jO(e,t){let n=new NO(e,e.resourceType,`resource`);return new OO(t,n).crawlResource(),n.getDefaultValue()}function MO(e,t,n){for(let[r,i]of Object.entries(t)){if(n===void 0||n===r){LO(e,r,i,t);continue}let a=$C(n,r);a!==void 0&&LO(e,a,i,t)}return e}var NO=class{rootValue;schemaStack;valueStack;constructor(e,t,n){this.schemaStack=[],this.valueStack=[],this.rootValue=BC(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=$C(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=$C(n.path,i),s=Array.isArray(e)?e:[e];for(let e of s){PO(e,a,t,n.elements,r),LO(e,a,t,n.elements);let i=IO(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=$C(this.value.path,e);if(r===void 0)throw Error(`Expected ${e} to be prefixed by ${this.value.path}`);let i=$C(n.path,this.value.path);for(let e of this.value.values){let a=IO(e,r,n.elements,i);if(Array.isArray(a))for(let e=a.length-1;e>=0;e--){let t=a[e];MC(t)||a.splice(e,1)}jC(a)&&FO(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[AO]??DO(i,[t],n.discriminator,this.schema.url))===t.name&&r.push(i);for(let n=r.length;n<t.min;n++)if(QC(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];AO in n&&delete n[AO]}}getDefaultValue(){return this.rootValue}};function PO(e,t,n,r,i){let a=IO(e,t,r,i);n.min>0&&a===void 0&&QC(n.type[0].code)&&(n.isArray?FO(e,[Object.create(null)],t,n):FO(e,Object.create(null),t,n))}function FO(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]`,ZC(e))}t===void 0?delete e[i]:e[i]=t}function IO(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]`,ZC(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(HC(a)){if(a[t]===void 0)return;a=a[t]}else return}return o}function LO(e,t,n,r){if(!(n.fixed||n.pattern))return e;if(Array.isArray(e))return e.map(e=>LO(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]`,ZC(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]=RO(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 RO(e,t){if(Array.isArray(t)&&(Array.isArray(e)||e===void 0))return(e?.length??0)>0?e:BC(t);if(HC(t)&&(HC(e)&&!Array.isArray(e)||e===void 0)){let n=BC(e)??Object.create(null);for(let e of Object.keys(t))n[e]=RO(n[e],t[e]);return n}return e}var zO=Object.prototype.hasOwnProperty;function BO(e){return e===void 0?`undefined`:e===null?`null`:Array.isArray(e)?`array`:typeof e}function VO(e,t){let n=[];for(let r in e)zO.call(e,r)&&e[r]!==void 0&&!(zO.call(t,r)&&t[r]!==void 0)&&n.push(r);return n}function HO(e,t){let n=[];for(let r in e)zO.call(e,r)&&e[r]!==void 0&&zO.call(t,r)&&t[r]!==void 0&&n.push(r);return n}function UO(e){return e.op===`add`}function WO(e){return e.op===`remove`}function GO(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function KO(e,t,n,r=JO){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(GO(e,t))}if(c>0){let e=o(s,c-1),r={op:`add`,index:s-1,value:t[c-1]};n.push(GO(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(GO(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(UO(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]}if(WO(i)){let r={op:i.op,path:n.add(String(i.index+t)).toString()};return[e.concat(r),t-1]}{let a=n.add(String(i.index+t)),o=r(i.original,i.value,a);return[e.concat(...o),t]}},[[],0]);return c}function qO(e,t,n,r=JO){let i=[];return VO(e,t).forEach(e=>{i.push({op:`remove`,path:n.add(e).toString()})}),VO(t,e).forEach(e=>{i.push({op:`add`,path:n.add(e).toString(),value:t[e]})}),HO(e,t).forEach(a=>{i.push(...r(e[a],t[a],n.add(a)))}),i}function JO(e,t,n,r=JO){if(e===t)return[];let i=BO(e),a=BO(t);return i===`array`&&a===`array`?KO(e,t,n,r):i===`object`&&a===`object`?qO(e,t,n,r):[{op:`replace`,path:n.toString(),value:t}]}function YO(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function XO(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(YO);if(n[0]!==``)throw Error(`Invalid JSON Pointer: ${t}`);return new e(n)}toString(){return this.tokens.map(XO).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){let n=this.tokens.concat(String(t));return new e(n)}parent(){let t=this.tokens.length>1?this.tokens.slice(0,-1):[``];return new e(t)}};function QO(e){function t(n,r,i){let a=e(n,r,i);return Array.isArray(a)?a:JO(n,r,i,t)}return t}function $O(e,t,n){let r=new ZO;return(n?QO(n):JO)(e,t,r)}function ek(e){return e.match(/^\((.+)\)\.identifier$/)?.[1]}function tk(e,t){return new lT(e,new bT(t,new dT(`identifier`)))}var nk={BOOLEAN:`BOOLEAN`,NUMBER:`NUMBER`,QUANTITY:`QUANTITY`,TEXT:`TEXT`,REFERENCE:`REFERENCE`,CANONICAL:`CANONICAL`,DATE:`DATE`,DATETIME:`DATETIME`,PERIOD:`PERIOD`,UUID:`UUID`};function rk(e,t){return eT.types[e]?.searchParamsDetails?.[t.code]??ak(e,t)}function ik(e,t,n){let r=eT.types[e];r||(r={},eT.types[e]=r),r.searchParamsDetails||(r.searchParamsDetails={}),r.searchParamsDetails[t]=n}function ak(e,t){let n=t.code,r=t.expression,i=uk(e,r),a={elementDefinitions:[],propertyTypes:new Set,array:!1};for(let n of i){let r=pk(n),i=rw(()=>r.join(`.`));r.length===1&&r[0]instanceof Sx&&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`)):ok(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=ek(r);if(t===void 0)throw Error(`Unexpected expression for derived identifier search parameter: ${r}`);o=tk(r,dk(e,t))}else o=dk(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:lk(t,a.propertyTypes),elementDefinitions:s,parsedExpression:o,array:a.array,referenceTargetTypes:mk(t,s)};return ik(e,n,c),c}function ok(e,t,n,r){let i=t[r];if(i instanceof mT){e.propertyTypes.add(i.right.toString());return}if(i instanceof jT){sk(e,i);return}let a=i.toString(),o=Xw(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 MT&&(s=!0,c++);let l=t[c];if(o.isArray&&!s&&(e.array=!0),c===t.length-1){if(l instanceof mT){e.elementDefinitions.push(o),e.propertyTypes.add(l.right.toString());return}if(l instanceof jT&&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??pw)e.propertyTypes.add(t.code);return}for(let n of o.type??pw){let r=n.code;ck(r)&&(r=o.type[0].code),ok(e,t,r,c)}}function sk(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 ET){e.propertyTypes.add(t.args[0].right.toString());return}throw Error(`Unhandled FHIRPath function: ${t.name}`)}function ck(e){return e===`Element`||e===`BackboneElement`}function lk(e,t){switch(e.type){case`date`:return t.size===1&&t.has(X.date)?nk.DATE:nk.DATETIME;case`number`:return nk.NUMBER;case`quantity`:return nk.QUANTITY;case`reference`:return t.has(X.canonical)?nk.CANONICAL:nk.REFERENCE;case`token`:return t.size===1&&t.has(X.boolean)?nk.BOOLEAN:nk.TEXT;default:return nk.TEXT}}function uk(e,t){let n=[];return fk(e,JT(t).child,n),n}function dk(e,t){let n=[],r=JT(t);if(fk(e,r.child,n),n.length===0)return r;let i=n[0];for(let e=1;e<n.length;e++)i=new xT(i,n[e]);return new lT(`<original-not-available>`,i)}function fk(e,t,n){t instanceof xT?(fk(e,t.left,n),fk(e,t.right,n)):t.toString().includes(e+`.`)&&n.push(t)}function pk(e){return e instanceof mT||e instanceof MT?[pk(e.left),e].flat():e instanceof Sx&&e.operator!==`.`?[e]:e instanceof bT?[pk(e.left),pk(e.right)].flat():e instanceof jT&&(e.name===`where`&&!(e.args[0]instanceof ET)||e.name===`last`)?[]:[e]}function mk(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 hk=/^\d+\.\d+\.\d+(-[0-9a-z]{7})?$/,gk=`https://meta.medplum.com/releases`,_k=new Map;function vk(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 yk(e,t,n,r){let i=new URL(`${gk}/${e}`);if(i.searchParams.set(`a`,t),i.searchParams.set(`c`,QD),r)for(let[e,t]of Object.entries(r))i.searchParams.set(e,t);let a=await fetch(i.toString());if(a.status!==200){let e;try{e=(await a.json()).message}catch(e){console.error(`Failed to parse message from body: ${Y(e)}`)}throw Error(`Received status code ${a.status} while ${n}`,{cause:Error(e)})}return await a.json()}async function bk(e,t,n){let r=t?_k.get(t):void 0;if(!r){let i=await yk(`${t?`v${t}`:`latest`}.json`,e,`fetching manifest for version '${t??`latest`}'`,n);vk(i),r=i,_k.set(r.tag_name.slice(1),r)}return r}function xk(e){return hk.test(e)}function Sk(e){if(!hk.test(e))throw TypeError(`Version is not a valid Medplum semver (eg. 1.1.1 or 1.1.1-a1bc): ${e}`)}function Ck(e,t){let n=e.split(`-`)[0].split(`.`).map(Number),r=t.split(`-`)[0].split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t}return 0}async function wk(e){let t=await bk(e);if(!t.tag_name.startsWith(`v`))throw Error(`Invalid release name found. Release tag '${t.tag_name}' did not start with 'v'`);let n=t.tag_name.slice(1);return Sk(n),n}async function Tk(e,t){return((await yk(`all.json`,e,`fetching all release versions`,t)).versions??[]).map(e=>e.version).filter(xk).toSorted(Ck).reverse()}var Ek=(0,b.createContext)(void 0);function Dk(){return(0,b.useContext)(Ek)}function Q(){return Dk().medplum}function Ok(){return Dk().navigate}function kk(){return Dk().profile}var Ak=[`change`,`storageInitialized`,`storageInitFailed`,`profileRefreshing`,`profileRefreshed`];function jk(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 Ak)t.addEventListener(n,e);return()=>{for(let n of Ak)t.removeEventListener(n,e)}},[t]);let a=(0,b.useMemo)(()=>({...r,medplum:t,navigate:n}),[r,t,n]);return(0,I.jsx)(Ek.Provider,{value:a,children:e.children})}function Mk(e){window.location.assign(e)}var Nk=new Map,Pk=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=Nk.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 Nk.set(t,e),e},[e]),Fk=3e3;function Ik(e,t,n){let r=Q(),i=r.getProject(),a=kk()&&i?.features?.includes(`websocket-subscriptions`)?e:void 0,[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(n?.subscriptionProps),u=(0,b.useRef)(!1),d=(0,b.useRef)(void 0),f=(0,b.useRef)(void 0),p=(0,b.useRef)(void 0),m=(0,b.useRef)(t);m.current=t;let h=(0,b.useRef)(n?.onWebSocketOpen);h.current=n?.onWebSocketOpen;let g=(0,b.useRef)(n?.onWebSocketClose);g.current=n?.onWebSocketClose;let _=(0,b.useRef)(n?.onSubscriptionConnect);_.current=n?.onSubscriptionConnect;let v=(0,b.useRef)(n?.onSubscriptionDisconnect);v.current=n?.onSubscriptionDisconnect;let y=(0,b.useRef)(n?.onError);y.current=n?.onError,(0,b.useEffect)(()=>{PC(n?.subscriptionProps,c)||l(n?.subscriptionProps)},[c,n]),(0,b.useEffect)(()=>{d.current&&=(clearTimeout(d.current),void 0);let e=!1;return(f.current!==a||!PC(p.current,c))&&(e=!0),e&&f.current&&r.unsubscribeFromCriteria(f.current,p.current),f.current=a,p.current=c,e&&a?s(r.subscribeToCriteria(a,c)):a||s(void 0),()=>{d.current=setTimeout(()=>{a&&r.unsubscribeFromCriteria(a,c)},Fk)}},[r,a,c]);let x=(0,b.useCallback)(e=>{m.current?.(e.payload)},[]),S=(0,b.useCallback)(()=>{h.current?.()},[]),C=(0,b.useCallback)(()=>{g.current?.()},[]),w=(0,b.useCallback)(e=>{_.current?.(e.payload.subscriptionId)},[]),T=(0,b.useCallback)(e=>{v.current?.(e.payload.subscriptionId)},[]),E=(0,b.useCallback)(e=>{y.current?.(e.payload)},[]);(0,b.useEffect)(()=>o?(u.current||=(o.addEventListener(`message`,x),o.addEventListener(`open`,S),o.addEventListener(`close`,C),o.addEventListener(`connect`,w),o.addEventListener(`disconnect`,T),o.addEventListener(`error`,E),!0),()=>{u.current=!1,o.removeEventListener(`message`,x),o.removeEventListener(`open`,S),o.removeEventListener(`close`,C),o.removeEventListener(`connect`,w),o.removeEventListener(`disconnect`,T),o.removeEventListener(`error`,E)}):()=>void 0,[o,x,S,C,w,T,E])}function Lk(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]),Ik(i,()=>{s(`reload`)}),a}function Rk(e,t){let n=Q(),[r,i]=(0,b.useState)(()=>zk(n,e)),a=(0,b.useCallback)(e=>{PC(e,r)||i(e)},[r]);return(0,b.useEffect)(()=>{let r=!0,i=zk(n,e);return!i&&$w(e)?n.readReference(e).then(e=>{r&&a(e)}).catch(e=>{r&&(a(void 0),t&&t(aS(e)))}):a(i),(()=>r=!1)},[n,e,a,t]),r}function zk(e,t){if(t){if(Qw(t))return t;if($w(t))return e.getCachedReference(t)}}var Bk={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`},Vk=`${Ex}/fhir/StructureDefinition/questionnaire-itemControl`,Hk=`${Ex}/fhir/StructureDefinition/questionnaire-referenceFilter`,Uk=`${Ex}/fhir/StructureDefinition/questionnaire-referenceResource`,Wk=`${Ex}/fhir/StructureDefinition/questionnaire-validationError`,Gk=`${Ex}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression`,Kk=`${Ex}/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression`,qk=`${Ex}/fhir/StructureDefinition/questionnaire-signatureRequired`,Jk=`${Ex}/fhir/StructureDefinition/questionnaireresponse-signature`,Yk=`${Ex}/fhir/StructureDefinition/questionnaire-hidden`,Xk=`${Ex}/fhir/StructureDefinition/questionnaire-optionExclusive`;function Zk(e){return e.type===`choice`||e.type===`open-choice`}function Qk(e,t){return{...t,item:$k(e.item,t.item,t)}}function $k(e,t,n){if(!t)return t;let r=[];for(let i of t){let t=e?.find(e=>e.linkId===i.linkId);t&&!eA(t,n)||(t?.item&&i.item?r.push({...i,item:$k(t.item,i.item,n)}):r.push(i))}return r}function eA(e,t){if(EC(e,Yk)?.valueBoolean===!0)return!1;let n=tA(e,t);return n===void 0?nA(e,t):n}function tA(e,t){let n=EC(e,Gk);if(t&&n){let e=n.valueExpression?.expression;if(e){let n=zS(t);return BS(XT(e,[n],{"%resource":n}))}}}function nA(e,t){if(!e.enableWhen)return!0;let n=e.enableBehavior??`any`;for(let r of e.enableWhen){let e=uA(t?.item,r.question);if(r.operator===`exists`&&!r.answerBoolean&&!e?.length){if(n===`any`)return!0;continue}let{anyMatch:i,allMatch:a}=fA(r,e,n);if(n===`any`&&i)return!0;if(n===`all`&&!a)return!1}return n!==`any`}function rA(e,t,n=t.item){for(let r of e){let e=n?.find(e=>e.linkId===r.linkId);e&&(iA(t,r,e),r.item&&e.item&&rA(r.item,t,e.item))}}function iA(e,t,n){try{let r=sA(t,e);if(!r)return;let i=oA(t,r);if(!i)return;n.answer=[i]}catch(e){n.extension=[{url:Wk,valueString:`Expression evaluation failed: ${Y(e)}`}]}}var aA={[Bk.boolean]:[X.boolean],[Bk.date]:[X.date],[Bk.dateTime]:[X.dateTime],[Bk.time]:[X.time],[Bk.url]:[X.string,X.uri,X.url],[Bk.attachment]:[X.Attachment],[Bk.reference]:[X.Reference],[Bk.quantity]:[X.Quantity],[Bk.decimal]:[X.decimal,X.integer],[Bk.integer]:[X.decimal,X.integer]};function oA(e,t){if(e.type){if(e.type===Bk.choice||e.type===Bk.openChoice)return{[`value${ZC(t.type)}`]:t.value};if(e.type===Bk.string||e.type===Bk.text)return typeof t.value==`string`?{valueString:t.value}:void 0;if(aA[e.type]?.includes(t.type))return{[`value${ZC(e.type)}`]:t.value}}}function sA(e,t){if(!t)return;let n=EC(e,Kk);if(n){let e=n.valueExpression?.expression;if(e){let n=zS(t),r=XT(e,[n],{"%resource":n});return r.length===0?void 0:r[0]}}}function cA(e,t,n){let r=[];for(let i of e){let e=n.answerOption?.find(e=>mw(CA(e))===i);if(e){let n=CA(e);n&&r.push({[t]:n.value})}}return r}function lA(e,t,n){let r=[];for(let t of e.answerOption??pw)if(EC(t,Xk)?.valueBoolean===!0){let e=CA(t);e?.value!==void 0&&r.push(e)}if(r.length===0)return n;let i=e=>{let t=TA(e);return!!t&&r.some(e=>PC(e,t))},a=n.filter(e=>!t?.some(t=>PC(t,e))),o=a.find(i);return o?[o]:a.some(e=>!i(e))?n.filter(e=>!i(e)):n}function uA(e,t){for(let n of e??pw){if(n.linkId===t)return n.answer;if(n.item){let e=uA(n.item,t);if(e)return e}}}function dA(e,t,n){if(n===`exists`)return!!e===t.value;if(e){let[{value:r}]=XT(`%actualAnswer ${n===`=`||n===`!=`?n?.replace(`=`,`~`):n} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":t});return r}return!1}function fA(e,t,n){let r=t||[],i=wA(e),a=!1,o=!0;for(let t of r){let r=TA(t),{operator:s}=e;if(dA(r,i,s)?a=!0:o=!1,n===`any`&&a)break}return{anyMatch:a,allMatch:o}}function pA(e){let t=EC(e,Uk);if(t){if(t.valueCode!==void 0)return[t.valueCode];if(t.valueCodeableConcept)return t.valueCodeableConcept?.coding?.map(e=>e.code)}}function mA(e,t){let n=BC(e),r=EC(n,Uk);return!t||t.length===0?(r&&(n.extension=n.extension?.filter(e=>e!==r)),n):(r||(n.extension??=[],r={url:Uk},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 hA(e,t,n){let r=EC(e,Hk);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]=nw(e,`=`,2);a[t]=n}return a}function gA(e,t){return{resourceType:`QuestionnaireResponse`,questionnaire:e.url??mC(e),item:_A(e.item,t?.item),status:`in-progress`}}function _A(e,t){let n;for(let r of e??pw){if(r.type===Bk.display)continue;let e=t?.filter(e=>e.linkId===r.linkId);if(e?.length)for(let t of e)t.id=t.id??bA(),t.text=t.text??r.text,t.item=_A(r.item,t.item),t.answer=xA(r,t),n=iw(n,t);else n=iw(n,vA(r))}return n}function vA(e){return{id:bA(),linkId:e.linkId,text:e.text,item:_A(e.item,void 0),answer:xA(e)}}var yA=1;function bA(){return`id-`+yA++}function xA(e,t){if(e.type!==Bk.display&&e.type!==Bk.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 SA(e){return GS({type:`QuestionnaireItemInitial`,value:e},`value`)}function CA(e){return GS({type:`QuestionnaireItemAnswerOption`,value:e},`value`)}function wA(e){return GS({type:`QuestionnaireItemEnableWhen`,value:e},`answer`)}function TA(e){return GS({type:`QuestionnaireResponseItemAnswer`,value:e},`value`)}function EA(e){let t=Rk(e.questionnaire),n=Rk(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:DA(t)),t&&e.defaultValue&&n&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=gA(t,n),p()),t&&!e.defaultValue&&!i.current.questionnaireResponse&&(i.current.questionnaireResponse=gA(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(vA(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=lA(t,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!==Jk),t.extension.push({url:Jk,valueSignature:e})):t.extension=t.extension?.filter(e=>e.url!==Jk),p())}function f(){let e=i.current.questionnaire;if(e?.item){let t=i.current.questionnaireResponse;rA(e.item,t)}}function p(){let t=i.current.questionnaireResponse,n=i.current.questionnaire;!t||!n||(f(),r(),e.onChange?.(Qk(n,t)))}return{loading:!1,pagination:!!i.current.pages,questionnaire:i.current.questionnaire,questionnaireResponse:Qk(i.current.questionnaire,i.current.questionnaireResponse),subject:e.subject,encounter:e.encounter,activePage:i.current.activePage,pages:i.current.pages,items:OA(i.current.questionnaire,i.current.pages,i.current.activePage),responseItems:kA(i.current.questionnaireResponse,i.current.pages,i.current.activePage),onNextPage:o,onPrevPage:s,onAddGroup:c,onAddAnswer:l,onChangeAnswer:u,onChangeSignature:d}}function DA(e){if(e?.item&&EC(e?.item?.[0],Vk)?.valueCodeableConcept?.coding?.[0]?.code===`page`)return e.item.map((e,t)=>({linkId:e.linkId,title:e.text??`Page ${t+1}`,group:e}))}function OA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function kA(e,t,n=0){return t&&e?.item?.[n]?[e.item[n]]:e.item??[]}function AA(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 jA=250;function MA(e,t,n){return PA(`searchOne`,e,t,n)}function NA(e,t,n){return PA(`searchResources`,e,t,n)}function PA(e,t,n,r){let i=Q(),[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),[l,u]=(0,b.useState)(),d=i.fhirSearchUrl(t,n).toString(),f=(0,b.useMemo)(()=>({resourceType:t,query:n}),[d]),p=r?.enabled??!0,[m]=AA(f,r?.debounceMs??jA,{leading:!0});return(0,b.useEffect)(()=>{if(!p)return()=>{};o(!0);let t=!0;return i[e](m.resourceType,m.query).then(e=>{t&&(o(!1),c(e),u(Wx))}).catch(e=>{t&&(o(!1),c(void 0),u(aS(e)))}),()=>{t=!1}},[i,e,m,p]),[s,a,l]}function FA(e){if(e instanceof iS){let t=rS(e.outcome);return t===400||t===404}return!1}var IA=[];function LA(e){let t=Q(),n=Array.from(new Set(e.filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)).join(`
|
|
97
97
|
`),r=(0,b.useMemo)(()=>n===``?IA:n.split(`
|
|
98
98
|
`),[n]),[i,a]=(0,b.useState)({});return(0,b.useEffect)(()=>{if(r.length===0)return;let e=!1,n=new AbortController;for(let i of r)t.valueSetExpand({url:i,count:1},{signal:n.signal}).then(()=>{e||a(e=>({...e,[i]:!0}))}).catch(t=>{e||a(e=>({...e,[i]:!FA(t)}))});return()=>{e=!0,n.abort()}},[t,r]),(0,b.useMemo)(()=>{let e=[],t=[],n=!1;for(let a of r){let r=i[a];r===void 0?n=!0:r?e.push(a):t.push(a)}return{loading:n,available:e,unavailable:t}},[r,i])}function RA(e){let{loading:t,unavailable:n}=LA(e?[e]:IA);if(!e)return!0;if(!t)return!n.includes(e)}function zA(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:gw(t,e.options)}):null}var BA=[`meta`,`implicitRules`,`contained`,`extension`,`modifierExtension`],VA=[`language`,`text`],HA=(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});HA.displayName=`ElementsContext`;var UA=[`extension`,`modifierExtension`],WA=[`id`,...BA].filter(e=>!UA.includes(e));function GA(e){return Object.entries(e).filter(([e,t])=>!MC(t.type)||t.max===0||t.path.toLowerCase().endsWith(`extension.url`)&&t.fixed||UA.includes(e)&&!MC(t.slicing?.slices)?!1:!WA.includes(e)&&!(VA.includes(e)&&t.path.split(`.`).length===2||e.includes(`.`)))}function KA(e,t){return e.line&&e.line.length>t?e.line[t]:``}function qA(e,t,n){let r=e.line||[];for(;r.length<=t;)r.push(``);return r[t]=n,{...e,line:NC(r)}}function JA(e){let[t,n]=(0,b.useState)(e.defaultValue||{}),{getExtendedProps:r}=(0,b.useContext)(HA),[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(qA(t,0,e))}function h(e){d(qA(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)(wg,{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)(wg,{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)(_b,{disabled:e.disabled||o?.readonly,placeholder:`Line 1`,defaultValue:KA(t,0),onChange:e=>m(e.currentTarget.value)}),(0,I.jsx)(_b,{disabled:e.disabled||s?.readonly,placeholder:`Line 2`,defaultValue:KA(t,1),onChange:e=>h(e.currentTarget.value)}),(0,I.jsx)(_b,{disabled:e.disabled||c?.readonly,placeholder:`City`,defaultValue:t.city,onChange:e=>g(e.currentTarget.value)}),(0,I.jsx)(_b,{disabled:e.disabled||l?.readonly,placeholder:`State`,defaultValue:t.state,onChange:e=>_(e.currentTarget.value)}),(0,I.jsx)(_b,{disabled:e.disabled||u?.readonly,placeholder:`Postal Code`,defaultValue:t.postalCode,onChange:e=>v(e.currentTarget.value)})]})}function YA(e){let t=kk(),[n,r]=(0,b.useState)(e.defaultValue||{});function i(n){let i=n?{text:n,authorReference:t&&pC(t),time:new Date().toISOString()}:{};r(i),e.onChange&&e.onChange(i)}return(0,I.jsx)(_b,{disabled:e.disabled,name:e.name,placeholder:`Annotation text`,defaultValue:n.text,onChange:e=>i(e.currentTarget.value)})}var XA={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`}},$=(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,...XA[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},ZA=$(`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`}]]),QA=$(`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`}]]),$A=$(`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`}]]),ej=$(`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`}]]),tj=$(`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`}]]),nj=$(`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`}]]),rj=$(`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`}]]),ij=$(`outline`,`bolt`,`Bolt`,[[`path`,{d:`M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11`,key:`svg-0`}]]),aj=$(`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`}]]),oj=$(`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`}]]),sj=$(`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`}]]),cj=$(`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`}]]),lj=$(`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`}]]),uj=$(`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`}]]),dj=$(`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`}]]),fj=$(`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`}]]),pj=$(`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`}]]),mj=$(`outline`,`check`,`Check`,[[`path`,{d:`M5 12l5 5l10 -10`,key:`svg-0`}]]),hj=$(`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`}]]),gj=$(`outline`,`chevron-down`,`ChevronDown`,[[`path`,{d:`M6 9l6 6l6 -6`,key:`svg-0`}]]),_j=$(`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`}]]),vj=$(`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`}]]),yj=$(`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`}]]),bj=$(`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`}]]),xj=$(`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`}]]),Sj=$(`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`}]]),Cj=$(`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`}]]),wj=$(`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=$(`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`}]]),Ej=$(`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`}]]),Dj=$(`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`}]]),Oj=$(`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`}]]),kj=$(`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`}]]),Aj=$(`outline`,`equal`,`Equal`,[[`path`,{d:`M5 10h14`,key:`svg-0`}],[`path`,{d:`M5 14h14`,key:`svg-1`}]]),jj=$(`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`}]]),Mj=$(`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`}]]),Nj=$(`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`}]]),Pj=$(`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`}]]),Fj=$(`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`}]]),Ij=$(`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`}]]),Lj=$(`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`}]]),Rj=$(`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`}]]),zj=$(`outline`,`info-circle`,`InfoCircle`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M12 9h.01`,key:`svg-1`}],[`path`,{d:`M11 12h1v4h1`,key:`svg-2`}]]),Bj=$(`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`}]]),Vj=$(`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`}]]),Hj=$(`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`}]]),Uj=$(`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`}]]),Wj=$(`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`}]]),Gj=$(`outline`,`math-greater`,`MathGreater`,[[`path`,{d:`M5 18l14 -6l-14 -6`,key:`svg-0`}]]),Kj=$(`outline`,`math-lower`,`MathLower`,[[`path`,{d:`M19 18l-14 -6l14 -6`,key:`svg-0`}]]),qj=$(`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`}]]),Jj=$(`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`}]]),Yj=$(`outline`,`minus`,`Minus`,[[`path`,{d:`M5 12l14 0`,key:`svg-0`}]]),Xj=$(`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`}]]),Zj=$(`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`}]]),Qj=$(`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`}]]),$j=$(`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`}]]),eM=$(`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`}]]),tM=$(`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`}]]),nM=$(`outline`,`player-play`,`PlayerPlay`,[[`path`,{d:`M7 4v16l13 -8l-13 -8`,key:`svg-0`}]]),rM=$(`outline`,`plus`,`Plus`,[[`path`,{d:`M12 5l0 14`,key:`svg-0`}],[`path`,{d:`M5 12l14 0`,key:`svg-1`}]]),iM=$(`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`}]]),aM=$(`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`}]]),oM=$(`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`}]]),sM=$(`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`}]]),cM=$(`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`}]]),lM=$(`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`}]]),uM=$(`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`}]]),dM=$(`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`}]]),fM=$(`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`}]]),pM=$(`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`}]]),mM=$(`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`}]]),hM=$(`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`}]]),gM=$(`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`}]]),_M=$(`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`}]]),vM=$(`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`}]]),yM=$(`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`}]]),bM=$(`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`}]]),xM=$(`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`}]]),SM=$(`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`}]]),CM=$(`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`}]]),wM=$(`outline`,`x`,`X`,[[`path`,{d:`M18 6l-12 12`,key:`svg-0`}],[`path`,{d:`M6 6l12 12`,key:`svg-1`}]]),TM=$(`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`}]]),EM=class extends b.Component{state;constructor(e){super(e),this.state={lastLocation:YE.getLocation()}}static getDerivedStateFromError(e){return{error:e,lastLocation:YE.getLocation()}}componentDidUpdate(e,t){YE.getLocation()!==this.state.lastLocation&&this.setState({lastLocation:YE.getLocation(),error:void 0})}shouldComponentUpdate(e,t){return!!(this.props.children!==e.children||t.error&&!this.state.error||this.state.lastLocation!==YE.getLocation())}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.error?(0,I.jsx)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Something went wrong`,color:`red`,children:Y(this.state.error)}):this.props.children}};function DM(){return(0,I.jsx)(Wp,{style:{width:`100%`,height:`100vh`},children:(0,I.jsx)(ou,{})})}var OM={main:`_main_6s8vf_1`,announcement:`_announcement_6s8vf_7`};function kM(e){return(0,I.jsx)(I.Fragment,{children:e.announcements.map((t,n)=>(0,I.jsx)(z,{className:OM.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)(yu,{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 jM(e){return e.button===1||e.ctrlKey||e.metaKey}function MM(e){if(NM(e))return!0;if(e instanceof HTMLTableCellElement){let t=e.children;if(t.length===1&&NM(t[0]))return!0}return!1}function NM(e){return e instanceof HTMLInputElement&&e.type===`checkbox`}async function PM(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 FM(e,t){let n=new Blob([e],{type:lD.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 IM(e){let t=Ok(),{to:n,suffix:r,label:i,onClick:a,children:o,...s}=e,c=LM(n);return r&&(c+=`/`+r),(0,I.jsx)(Md,{href:c,"aria-label":i,onAuxClick:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),a?(e.preventDefault(),a(e)):n&&(jM(e)||(e.preventDefault(),t(c)))},...s,children:o})}function LM(e){if(e){if(typeof e==`string`)return RM(e);if(Qw(e))return zM(e);if($w(e))return BM(e)}return`#`}function RM(e){return e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`/`)?e:`/`+e}function zM(e){return`/${e.resourceType}/${e.id}`}function BM(e){return`/${e.reference}`}function VM(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 HM(e){let t=Rk(e.value),n=t?vC(t):e.alt??``,r=VM(n),i=Pk((t&&xC(t))??e.src??void 0),a=e.radius??`xl`,o={...e,value:void 0,link:void 0};return e.link?(0,I.jsx)(IM,{to:t,children:(0,I.jsx)(Dp,{src:i,alt:n,radius:a,...o,children:r})}):(0,I.jsx)(Dp,{src:i,alt:n,radius:a,...o,children:r})}var UM={logoButton:`_logoButton_3ecx0_1`,user:`_user_3ecx0_11`,userInfo:`_userInfo_3ecx0_25`,userName:`_userName_3ecx0_35`,userProject:`_userProject_3ecx0_40`},WM={iconBox:`_iconBox_f3xp4_1`,subtitle:`_subtitle_f3xp4_12`,interactive:`_interactive_f3xp4_16`};function GM(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:WM.iconBox,children:(0,I.jsx)(lj,{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`,className:WM.subtitle,truncate:!0,children:n})]}),i&&(0,I.jsx)(mj,{size:16,stroke:2,color:`var(--mantine-color-blue-6)`})]})}function KM(e){let{membership:t,label:n}=e;return(0,I.jsx)(GM,{projectDisplay:t.project?.display,profileDisplay:t.profile?.display,label:n})}function qM(){return`Medplum`}var JM={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`},YM=`var(--mantine-color-dimmed)`,XM=[{value:`light`,label:(0,I.jsx)(QM,{Icon:hM,label:`Light`})},{value:`auto`,label:(0,I.jsx)(QM,{Icon:Tj,label:`System`})},{value:`dark`,label:(0,I.jsx)(QM,{Icon:Xj,label:`Dark`})}],ZM=[{label:`v1`,value:`v1`},{label:`v2`,value:`v2`}];function QM({Icon:e,label:t}){return(0,I.jsx)(`span`,{"aria-label":t,style:{display:`flex`},children:(0,I.jsx)(e,{size:16,color:YM,"aria-hidden":!0})})}function $M(){return(0,I.jsx)(lm,{my:4,mx:4,className:JM.divider})}function eN(e,t){return t?e.project.reference===t.project.reference&&e.profile.reference===t.profile.reference:!1}function tN(e){return`${e.project.reference}-${e.profile.reference}`}function nN(e){let{medplum:t,profile:n,navigate:r}=Dk(),i=t.getActiveLogin(),a=t.getLogins().filter(e=>!eN(e,i)),o=t.getProject(),{colorScheme:s,setColorScheme:c}=si(),[l]=(0,b.useState)(()=>localStorage.appShellLayoutVersion??`v1`),u=e.showLayoutVersionToggle??!0,d=o?.name??t.getActiveLogin()?.project.display,f=i?.profile.display??(n?_w(n.name?.[0]):void 0);function p(e){t.setActiveLogin(e).then(()=>YE.reload()).catch(console.error)}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{className:JM.accountSection,children:(0,I.jsx)(z,{className:JM.projectOption,children:(0,I.jsx)(GM,{projectDisplay:d,profileDisplay:f,selected:!0})})}),a.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($M,{}),a.map(e=>(0,I.jsx)(W.Item,{className:JM.recentProjectItem,onClick:()=>p(e),children:(0,I.jsx)(z,{className:JM.projectOption,children:(0,I.jsx)(GM,{projectDisplay:e.project.display,profileDisplay:e.profile.display})})},tN(e)))]}),(0,I.jsx)($M,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(gM,{size:16,color:YM}),onClick:()=>r(`/signin`),children:(0,I.jsx)(H,{size:`sm`,children:`Switch to another project`})}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uM,{size:16,color:YM}),onClick:()=>r(`/${mC(n)}`),children:(0,I.jsx)(H,{size:`sm`,children:`Account settings`})}),(0,I.jsxs)(hd,{className:JM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(hd,{align:`center`,gap:`xs`,children:[(0,I.jsx)(Qj,{size:16,color:YM}),(0,I.jsx)(H,{size:`sm`,children:`Appearance`})]}),(0,I.jsx)(z,{className:JM.settingsControlWrapper,children:(0,I.jsx)(cy,{classNames:{root:Mn(JM.segmentedControl,JM.appearanceControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:s,onChange:e=>c(e),data:XM,"aria-label":`Color scheme`})})]}),u&&(0,I.jsxs)(hd,{className:JM.settingsRow,align:`center`,pl:`sm`,pr:`xs`,py:`xs`,children:[(0,I.jsxs)(hd,{align:`center`,gap:`xs`,children:[(0,I.jsx)(vM,{size:16,color:YM}),(0,I.jsx)(H,{size:`sm`,children:`Layout`})]}),(0,I.jsx)(z,{className:JM.settingsControlWrapper,children:(0,I.jsx)(cy,{classNames:{root:Mn(JM.segmentedControl,JM.layoutControl)},size:`xs`,radius:`xl`,withItemsBorders:!1,value:l,onChange:e=>{localStorage.appShellLayoutVersion=e,YE.reload()},data:ZM,"aria-label":`App shell layout version`})})]}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Wj,{size:16,color:YM}),onClick:async()=>{await t.signOut(),r(`/signin`)},children:(0,I.jsx)(H,{size:`sm`,children:`Sign out`})}),(0,I.jsx)($M,{}),(0,I.jsxs)(H,{size:`xs`,c:`dimmed`,fw:500,my:`sm`,ta:`center`,children:[qM(),` `,e.version]})]})}var rN={selectedItems:`selected-items`,options:`options`};function iN(e){let t=Pf({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=aN(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??oN,ie=u??sN,ae=d??cN,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);let n=window.setTimeout(()=>fe(),100);k(n)},[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){let t=p(e);r=s(t)}if(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)(Lf.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)(Lf,{store:t,onOptionSubmit:he,withinPortal:!0,shadow:`xl`,...C,children:[(0,I.jsx)(Lf.DropdownTarget,{children:(0,I.jsx)(gg,{label:r,description:i,error:a,className:e.className,leftSection:v,rightSection:A?(0,I.jsx)(ou,{size:16}):ve,required:g,disabled:w,children:(0,I.jsxs)(dg.Group,{"data-testid":rN.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)(Lf.EventsTarget,{children:(0,I.jsx)(gg.Field,{role:`searchbox`,name:n,value:E,placeholder:_,onFocus:pe,onBlur:()=>{t.closeDropdown(),D(``)},onKeyDown:_e,onChange:pe})})]})})}),(0,I.jsx)(Lf.Dropdown,{hidden:!be,"data-testid":rN.options,children:(0,I.jsx)(Lf.Options,{children:(0,I.jsxs)(ll,{type:`scroll`,mah:x,children:[te.map(e=>{let t=N.some(t=>t.value===e.value);return(0,I.jsx)(Lf.Option,{value:e.value,active:t,children:(0,I.jsx)(re,{...e,active:t})},e.value)}),ye&&(0,I.jsxs)(Lf.Option,{value:`$create`,children:[`+ Create `,E]}),!m&&E.trim().length>0&&te.length===0&&(0,I.jsx)(ae,{search:E})]})})})]})}function aN(e){return e?Array.isArray(e)?e:[e]:[]}function oN(e){return(0,I.jsxs)(V,{gap:`xs`,children:[e.active&&(0,I.jsx)(mj,{size:12}),(0,I.jsx)(`span`,{children:e.label})]})}function sN({item:e,disabled:t,onRemove:n}){return(0,I.jsx)(dg,{withRemoveButton:!t,onRemove:n,children:e.label})}function cN(){return(0,I.jsx)(Lf.Empty,{children:`Nothing found`})}var lN={searchInput:`_searchInput_dick8_1`};function uN(e){return{value:e.id,label:vC(e),resource:e}}function dN(e){let t=Ok(),n=Q(),r=(0,b.useCallback)(async(e,t)=>{let r=pN(e),i={signal:t};return mN(await n.graphql(r,void 0,void 0,i),e)},[n]),i=(0,b.useCallback)(e=>{e.length>0&&t(`/${mC(e[0])}`)},[t]);return(0,I.jsx)(iN,{size:`sm`,radius:`md`,className:lN.searchInput,leftSection:(0,I.jsx)(lM,{size:16}),placeholder:`Search`,itemComponent:fN,toOption:uN,onChange:i,loadOptions:r,maxValues:0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var fN=(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)(HM,{value:e}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:vC(e)}),(0,I.jsx)(H,{size:`xs`,c:`dimmed`,children:i})]})]})})});function pN(e){let t=JSON.stringify(e);return VC(e)?`{
|
|
99
99
|
Patients1: PatientList(_id: ${t}, _count: 1) {
|
|
@@ -197,7 +197,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function Dr({color:e,theme:t,autoContrast:n}){ret
|
|
|
197
197
|
subject { display }
|
|
198
198
|
}
|
|
199
199
|
}`.replaceAll(/\s+/g,` `)}function BP(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),VP(t)}function VP(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 HP(e){return{id:e.id,href:`/Patient/${e.id}`,label:e.name?_w(e.name[0]):e.id,description:e.birthDate,leftSection:(0,I.jsx)(HM,{value:e,radius:`xl`,size:24})}}function UP(e){let t=e.filter(e=>!!e.id).map(HP);return t.length>0?[{group:`Patients`,actions:t}]:[]}function WP(e,t){let n=[],r=t.map(e=>({id:`resource-type-${e.code}`,href:`/${e.code}`,label:e.display??e.code??``,description:`Resource Type`}));r.length>0&&n.push({group:`Resource Types`,actions:r});let i=[],a=[];for(let t of e)t.resourceType===`Patient`&&t.id?i.push(HP(t)):t.resourceType===`ServiceRequest`&&t.id&&a.push({id:t.id,href:`/ServiceRequest/${t.id}`,label:t.id,description:t.subject?.display});return i.length>0&&n.push({group:`Patients`,actions:i}),a.length>0&&n.push({group:`Service Requests`,actions:a}),n}function GP(e){let t=Q(),n=Ok(),r=kk(),i=JP(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)(nf.Navbar,{id:`navbar`,className:jP.navbar,children:[e.logo&&(0,I.jsx)(nf.Section,{px:`xs`,pt:`xs`,pb:`4px`,children:(0,I.jsx)(fl,{className:jP.logoButton,onClick:e.navbarToggle,"aria-expanded":f,"aria-controls":`navbar`,"aria-label":`Medplum Logo`,children:e.logo})}),(0,I.jsx)(cl,{px:`xs`,pb:`xs`,pt:`sm`,h:`100%`,children:(0,I.jsxs)(nf.Section,{grow:!0,children:[e.spotlightEnabled&&(0,I.jsx)(z,{mb:2,children:(0,I.jsx)(Xv,{label:`Search`,position:`right`,transitionProps:{duration:0},disabled:f,children:(0,I.jsxs)(fl,{className:jP.link,onClick:()=>zN.open(),"aria-label":`Search`,children:[(0,I.jsx)(lM,{size:`1.2rem`}),(0,I.jsx)(`span`,{className:jP.linkLabel,"data-opened":f||void 0,children:`Search`})]})})}),e.spotlightEnabled&&(0,I.jsx)(RP,{patientsOnly:e.patientsOnly,staticActions:e.spotlightActions}),!e.resourceTypeSearchDisabled&&(0,I.jsx)(nf.Section,{mb:`sm`,children:(0,I.jsx)(AP,{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:jP.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)(qP,{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)(KP,{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)(Xv,{label:`Add Bookmark`,position:`right`,transitionProps:{duration:0},disabled:f,children:(0,I.jsxs)(fl,{className:`${jP.link} ${jP.addBookmarkLink}`,onClick:()=>c(!0),children:[(0,I.jsx)(yj,{}),(0,I.jsx)(`span`,{className:jP.linkLabel,"data-opened":f||void 0,children:`Add Bookmark`})]})})]})}),e.userMenuEnabled&&(0,I.jsxs)(nf.Section,{px:`xs`,py:`xs`,children:[(0,I.jsx)(Xv,{label:f?`Close Sidebar`:`Open Sidebar`,position:`right`,transitionProps:{duration:0},children:(0,I.jsx)(fl,{className:jP.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)(Bj,{})})}),(0,I.jsx)(lm,{my:`xs`,className:jP.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)(fl,{className:`${jP.link} ${jP.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)(HM,{value:r,radius:`xl`,size:24}),(0,I.jsxs)(`span`,{className:jP.userLinkLabel,"data-opened":f||void 0,children:[(0,I.jsx)(H,{span:!0,inherit:!0,truncate:!0,children:_w(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:JM.dropdown,children:(0,I.jsx)(nN,{version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle})})]})]})]}),e.pathname&&e.searchParams&&(0,I.jsx)(_P,{pathname:e.pathname,searchParams:e.searchParams,visible:s,onOk:()=>c(!1),onCancel:()=>c(!1)})]})}function KP(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)(aj,{}),f=u&&s&&!c;function p(e){e.preventDefault(),e.stopPropagation(),l?.()}return(0,I.jsx)(Xv,{label:r,position:`right`,transitionProps:{duration:0},disabled:c,children:(0,I.jsxs)(IM,{to:t,onClick:i,className:jP.link,"data-active":a||void 0,children:[(0,I.jsxs)(`span`,{className:jP.iconWrapper,children:[d,f&&(0,I.jsx)(`span`,{className:jP.alertDot})]}),(0,I.jsx)(`span`,{className:jP.linkLabel,"data-opened":c||void 0,children:r}),u&&(0,I.jsx)(`span`,{className:jP.linkCount,"data-opened":c||void 0,"data-alert":s||void 0,children:o.toLocaleString()}),l&&c&&(0,I.jsx)(Xv,{label:`Dismiss`,openDelay:500,children:(0,I.jsx)(fl,{"aria-label":`Dismiss`,className:jP.dismissButton,onClick:p,children:(0,I.jsx)(wM,{size:14})})})]})})}function qP(e){let t=Lk(e.notificationCount);return(0,I.jsx)(KP,{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 JP(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=YP(e,t,n.href);a>i&&(i=a,r=n)}return r}function YP(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 XP=250,ZP=59,QP=60,$P=36;function eF(e){let[t,n]=(0,b.useState)(localStorage.navbarOpen===`true`),[r]=(0,b.useState)(e.layoutVersion??localStorage.appShellLayoutVersion??`v1`),i=Q(),a=kk(),[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*$P: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)(DM,{});let m,h,g,_;return r===`v2`?(m={height:l},h={width:t?XP:ZP,breakpoint:0,collapsed:{desktop:!a,mobile:!a}},g=c?.length?(0,I.jsx)(nf.Header,{style:{zIndex:101},children:(0,I.jsx)(kM,{announcements:c,onDismiss:d})}):void 0,_=a?(0,I.jsx)(GP,{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,spotlightActions:e.spotlightActions,userMenuEnabled:!0,version:e.version,showLayoutVersionToggle:e.showLayoutVersionToggle}):void 0):(m={height:QP+l},h={width:XP,breakpoint:`sm`,collapsed:{desktop:!a||!t,mobile:!a||!t}},g=a&&(0,I.jsx)(yN,{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)(GP,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,navbarToggle:p,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled,patientsOnly:e.spotlightPatientsOnly,spotlightActions:e.spotlightActions}):void 0),(0,I.jsxs)(nf,{header:m,navbar:h,padding:0,children:[g,_,(0,I.jsx)(nf.Main,{className:OM.main,children:(0,I.jsx)(EM,{children:(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(DM,{}),children:e.children})})})]})}var tF=`https://ccda.medplum.com`,nF=`https://ccda-validator.medplum.com/`;function rF(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&&(PM(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:tF,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(`${nF}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}`);let i=await r.json();o(i)}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&&FM(JSON.stringify(a,null,2),`ccda-validation-results`)},color:`green`,style:{marginLeft:`auto`},children:`Download Full Results`})]})]})]}):null}function iF(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)(ou,{}):(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 aF(e){let{contentType:t,data:n,url:r,title:i}=e.value??{},a=Pk(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)(iF,{"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===lD.CDA_XML&&(0,I.jsx)(rF,{url:o}),(0,I.jsx)(`div`,{"data-testid":`download-link`,style:{padding:`2px 16px 16px 16px`},children:(0,I.jsx)(Md,{href:r,"data-testid":`attachment-details`,target:`_blank`,rel:`noopener noreferrer`,download:oF(i),children:i||`Download`})})]})}function oF(e){return e?.includes(`.`)?e:void 0}var sF={root:`_root_1bd5a_1`,compact:`_compact_1bd5a_19`};function cF(e){let{children:t,compact:n}=e;return(0,I.jsx)(`dl`,{className:Mn(sF.root,{[sF.compact]:n}),children:t})}function lF(e){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`dt`,{children:e.term}),(0,I.jsx)(`dd`,{children:e.children})]})}function uF(e){let t=e.values?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(aF,{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(!MC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);let r=e.path.split(`.`).pop();n=(0,I.jsx)(lF,{term:Kw(r),children:t})}else n=(0,I.jsx)(I.Fragment,{children:t});return n}function dF(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(aS(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 fF(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)(aF,{value:n,maxWidth:200})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(mu,{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)(vj,{})})})]},`${i}-${t.length}`)),(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{}),(0,I.jsx)(`td`,{children:(0,I.jsx)(dF,{disabled:e.disabled,onUpload:e=>{r([...t,e])},children:e=>(0,I.jsx)(mu,{...e,title:`Add`,variant:`subtle`,size:`sm`,color:e.disabled?`gray`:`green`,children:(0,I.jsx)(bj,{})})})})]})]})]})}function pF(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)(aF,{value:t,maxWidth:200}),(0,I.jsx)(U,{disabled:e.disabled,onClick:e=>{AM(e),r(void 0)},children:`Remove`})]}):(0,I.jsx)(dF,{disabled:e.disabled,securityContext:e.securityContext,onUpload:r,children:e=>(0,I.jsx)(U,{...e,children:`Upload...`})})}var mF={root:`_root_1vii2_1`};function hF(e){let{children:t,...n}=e;return(0,I.jsx)(rm,{className:mF.root,...n,children:t})}var gF={paper:`_paper_1igaj_1`,fill:`_fill_1igaj_20`};function _F(e){let{width:t,fill:n,className:r,children:i,...a}=e,o=t?{maxWidth:t}:void 0;return(0,I.jsx)(_l,{className:Mn(gF.paper,n&&gF.fill,r),style:o,shadow:`sm`,radius:`sm`,withBorder:!0,...a,children:i})}function vF(e){let{children:t,...n}=e;return(0,I.jsx)(hF,{children:(0,I.jsx)(_F,{...n,children:t})})}function yF(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 bF(e){let{visibilityToggleButtonProps:t,...n}=e;return(0,I.jsx)(av,{...n,visibilityToggleButtonProps:{"aria-label":`Toggle password visibility`,tabIndex:0,...t}})}function xF(e,t){return e?.issue?.filter(e=>wF(e.expression?.[0],t))?.map(e=>e.details?.text)?.join(`
|
|
200
|
-
`)}function SF(e,t){return e?.issue?.filter(e=>wF(e.expression?.[0],t))}var CF=/\[\d+\]/;function wF(e,t){if((typeof e==`string`&&CF.test(e))!==(typeof t==`string`&&CF.test(t))&&(e=e?.replace(CF,``),t=t?.replace(CF,``)),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 TF(e){let{onSuccess:t}=e,n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1);return(0,I.jsx)(vF,{width:450,children:(0,I.jsxs)(hP,{onSubmit:e=>{i(void 0),n.post(`auth/changepassword`,e).then(()=>{o(!0),t?.()}).catch(e=>i(aS(e)))},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{children:`Change password`})]}),!a&&(0,I.jsxs)(G,{gap:`xl`,mt:`xl`,children:[(0,I.jsx)(bF,{name:`oldPassword`,label:`Old password`,required:!0,autoFocus:!0,error:xF(r,`oldPassword`)}),(0,I.jsx)(bF,{name:`newPassword`,label:`New password`,required:!0,error:xF(r,`newPassword`)}),(0,I.jsx)(bF,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:xF(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 EF=/^patient\/Condition\.(?:\*|c?r?u?d?s?)$/,DF=`?category=http://terminology.hl7.org/CodeSystem/condition-category|encounter-diagnosis`,OF=`?category=http://terminology.hl7.org/CodeSystem/condition-category|problem-list-item`,kF=`?category=http://hl7.org/fhir/us/core/CodeSystem/condition-category|health-concern`,AF=/^patient\/Observation\.(?:\*|c?r?u?d?s?)$/,jF=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category|clinical-test`,MF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|laboratory`,NF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|social-history`,PF=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-category|sdoh`,FF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|survey`,IF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|vital-signs`;function LF(e){let t=Q();return(0,I.jsx)(hP,{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)(hd,{direction:`column`,align:`center`,justify:`center`,children:[e.logo??(0,I.jsx)(yF,{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 EF.test(e)?t=[e+DF,e+OF,e+kF]:AF.test(e)&&(t=[e+jF,e+MF,e+NF,e+PF,e+FF,e+IF]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sp,{id:e,name:e,label:e,defaultChecked:!0},e),t?.map(e=>(0,I.jsx)(sp,{id:e,name:e,label:e},e))]},e+`_group`)})}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(gP,{fullWidth:!0,children:e.submitLabel??`Set Scope`})})]})})}function RF(e){let[t,n]=(0,b.useState)();return(0,I.jsxs)(hP,{onSubmit:t=>{n(void 0),e.onSubmit(t)?.catch(e=>n(Y(e)))},children:[(0,I.jsxs)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Error`,color:`red`,mb:`lg`,children:t}),e.qrCodeUrl&&(0,I.jsx)(Wp,{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)(Pm,{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)(_b,{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)(gP,{fullWidth:!0,children:e.buttonText}),e.footer]})]})}function zF(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)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(RF,{title:e.totpTitle,description:e.totpDescription,buttonText:e.totpButtonText??`Enroll`,qrCodeUrl:n,onSubmit:e=>i(e.token)})}function BF(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)(Md,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Resend code`}):t.includes(`email`)&&(c=(0,I.jsx)(Md,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Get a code by email instead`})),(0,I.jsx)(RF,{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 VF(e){let{outcome:t,issues:n,displayOkOutcomes:r,...i}=e,a=t?.issue||n;return!a||a.length===0||t&&tS(t)&&!r?null:(0,I.jsx)(Td,{icon:(0,I.jsx)(QA,{size:16}),color:`red`,...i,children:a.map(e=>(0,I.jsx)(`div`,{"data-testid":`text-field-error`,children:sS(e)},e.details?.text))})}function HF(e){let t=Q(),[n,r]=(0,b.useState)(),i=SF(n,void 0);return(0,I.jsxs)(hP,{onSubmit:async n=>{try{e.handleAuthResponse(await t.startNewProject({login:e.login,projectName:n.projectName}))}catch(e){r(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Create a new project`})]}),(0,I.jsx)(VF,{issues:i,mb:`lg`}),(0,I.jsx)(G,{gap:`sm`,children:(0,I.jsx)(_b,{name:`projectName`,label:`Project Name`,placeholder:`My Project`,required:!0,autoFocus:!0,error:xF(n,`projectName`)})}),(0,I.jsxs)(G,{gap:`xs`,mt:`md`,children:[(0,I.jsx)(gP,{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)(Md,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{href:`https://www.medplum.com/terms`,children:`Terms\xA0of\xA0Service`}),`.`]})]})]})}function UF(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 WF(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`){UF(`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 GF(e){if(e)return e;let t=YE.getOrigin();if(t&&[].includes(t))return`__GOOGLE_CLIENT_ID__`}function KF(e){typeof grecaptcha>`u`&&UF(`https://www.google.com/recaptcha/api.js?render=`+e)}function qF(e){return new Promise((t,n)=>{grecaptcha.ready(async()=>{try{t(await grecaptcha.execute(e,{action:`submit`}))}catch(e){n(e)}})})}function JF(e){let t=GF(e.googleClientId),n=e.recaptchaSiteKey,r=Q(),[i,a]=(0,b.useState)(),o=SF(i,void 0);return(0,b.useEffect)(()=>{n&&KF(n)},[n]),(0,I.jsxs)(hP,{onSubmit:async t=>{a(void 0);try{let i=``;n&&(i=await qF(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(aS(e))}},children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:e.children}),(0,I.jsx)(VF,{issues:o,mb:`lg`}),t&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(WF,{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(aS(e))}}})}),(0,I.jsx)(lm,{label:`or`,labelPosition:`center`,my:`lg`})]}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(_b,{name:`firstName`,type:`text`,label:`First name`,placeholder:`First name`,required:!0,autoFocus:!0,error:xF(i,`firstName`)}),(0,I.jsx)(_b,{name:`lastName`,type:`text`,label:`Last name`,placeholder:`Last name`,required:!0,error:xF(i,`lastName`)}),(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,error:xF(i,`email`)}),(0,I.jsx)(bF,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,error:xF(i,`password`)})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(sp,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(gP,{fullWidth:!0,children:`Register Account`}),e.onSignIn&&(0,I.jsxs)(H,{size:`sm`,mt:`lg`,c:`dimmed`,ta:`center`,"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:[`Already have an account?`,` `,(0,I.jsx)(Md,{component:`button`,type:`button`,onClick:e.onSignIn,children:`Sign In`})]}),(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)(Md,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{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)(Md,{href:`https://policies.google.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{href:`https://policies.google.com/terms`,children:`Terms\xA0of\xA0Service`}),` apply.`]})]})]})}function YF(e){let{type:t,projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,onSuccess:o,onSignIn:s}=e,c=Q(),[l,u]=(0,b.useState)(e.login),[d,f]=(0,b.useState)(),[p,m]=(0,b.useState)(!1);(0,b.useEffect)(()=>{t===`patient`&&l&&c.startNewPatient({login:l,projectId:n}).then(e=>c.processCode(e.code)).then(()=>o()).catch(e=>f(aS(e)))},[c,t,n,l,o]);function h(e){e.code&&c.processCode(e.code).then(()=>o()).catch(e=>f(aS(e))),e.login&&u(e.login),e.emailVerificationRequired&&m(!0)}let g=SF(d,void 0);return(0,I.jsxs)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:[(0,I.jsx)(VF,{issues:g,mb:`lg`}),!l&&(0,I.jsx)(JF,{projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,onSignIn:s,handleAuthResponse:h,children:e.children}),p&&(0,I.jsx)(`div`,{children:`Please check your email for a verification link. Click the link to continue setting up your account.`}),l&&!p&&t===`project`&&(0,I.jsx)(HF,{login:l,handleAuthResponse:h})]})}function XF(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&&KF(n)},[n]),(0,I.jsx)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:(0,I.jsxs)(hP,{onSubmit:async e=>{c(void 0);try{let i=``;n&&(i=await qF(n)),await o.post(`auth/resetpassword`,{...e,projectId:t,recaptchaToken:i}),u(!0),r?.()}catch(e){c(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Reset your password`})]}),(0,I.jsx)(VF,{issues:SF(s,void 0),mb:`lg`}),!l&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(G,{gap:`sm`,mb:`md`,children:(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:xF(s,`email`)})}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(gP,{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)(Md,{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)(Md,{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 ZF(e){let{id:t,secret:n,onSuccess:r,onSignIn:i}=e,a=Q(),[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(!1),u=SF(o,void 0);return(0,I.jsxs)(vF,{width:450,children:[(0,I.jsx)(VF,{issues:u}),(0,I.jsxs)(hP,{onSubmit:e=>{if(e.password!==e.confirmPassword){s(Xx(`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(aS(e)))},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{children:`Set password`})]}),!c&&(0,I.jsxs)(G,{children:[(0,I.jsx)(bF,{name:`password`,label:`New password`,required:!0,error:xF(o,`password`)}),(0,I.jsx)(bF,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:xF(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)(Md,{component:`button`,type:`button`,onClick:i,children:`sign in`}):`sign in`,`.`]})]})]})}function QF(e){let[t,n]=(0,b.useState)();return t?(0,I.jsx)(eI,{email:t,resetEmail:()=>n(void 0),...e}):(0,I.jsx)($F,{setEmail:n,...e})}function $F(e){let{setEmail:t,onRegister:n,handleAuthResponse:r,children:i,disableEmailAuth:a,...o}=e,s=Q(),c=!e.disableGoogleAuth&&GF(e.googleClientId),[l,u]=(0,b.useState)(),d=SF(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:YE.getLocation()}),n=new URL(e.authorizeUrl);return n.searchParams.set(`state`,t),YE.assign(n.toString()),!0},[s,o]),p=(0,b.useCallback)(async e=>{let n=await s.post(`auth/method`,{email:e.email});await f(n)||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(aS(e))}},[s,o,f,r]);return(0,I.jsxs)(hP,{onSubmit:p,children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:i}),(0,I.jsx)(VF,{issues:d,mb:`lg`}),c&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(WF,{googleClientId:c,handleGoogleCredential:m})}),!a&&(0,I.jsx)(lm,{label:`or`,labelPosition:`center`,my:`lg`})]}),!a&&(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,mb:`md`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:xF(l,`email`),"data-testid":`auth.email`}),(0,I.jsxs)(G,{gap:`xs`,children:[!a&&(0,I.jsx)(gP,{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)(Md,{onClick:n,children:`Register`})]})]})]})}function eI(e){let{onForgotPassword:t,handleAuthResponse:n,children:r,...i}=e,a=Q(),[o,s]=(0,b.useState)(),c=SF(o,void 0),l=(0,b.useCallback)(e=>a.startLogin({...i,password:e.password,remember:e.remember===`on`}).then(n).catch(e=>s(aS(e))),[a,i,n]);return(0,I.jsxs)(hP,{onSubmit:l,children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:r}),(0,I.jsx)(VF,{issues:c,mb:`lg`}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(_b,{label:`Email`,value:e.email,disabled:!0,rightSectionWidth:36,rightSection:(0,I.jsx)(mu,{variant:`subtle`,color:`gray`,onClick:e.resetEmail,"aria-label":`Change email`,children:(0,I.jsx)($j,{size:`1rem`,stroke:1.5})})}),(0,I.jsx)(bF,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,autoFocus:!0,error:xF(o,`password`),"data-testid":`auth.password`})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(sp,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(gP,{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)(Md,{onClick:t,children:`Reset Password`})})]})]})}function tI(e){let t=Q(),n=Pf(),[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(nI(e))}function l(n){t.post(`auth/profile`,{login:e.login,profile:n}).then(e.handleAuthResponse).catch(e=>o(aS(e)))}let u=e.memberships.filter(c).slice(0,10).map(e=>(0,I.jsx)(Lf.Option,{value:e.id,className:WM.interactive,children:(0,I.jsx)(KM,{membership:e,label:nI(e)})},e.id));return(0,I.jsxs)(G,{gap:`0`,children:[(0,I.jsxs)(hd,{justify:`center`,align:`center`,direction:`column`,wrap:`nowrap`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Choose a Project`})]}),(0,I.jsx)(VF,{outcome:a,mb:`lg`}),(0,I.jsxs)(Lf,{store:n,onOptionSubmit:l,children:[(0,I.jsx)(Lf.EventsTarget,{children:(0,I.jsx)(_b,{placeholder:`Search`,value:r,mb:`md`,autoFocus:!0,leftSection:(0,I.jsx)(lM,{size:16}),onChange:e=>{i(e.currentTarget.value),n.updateSelectedOptionIndex()}})}),(0,I.jsx)(`div`,{children:(0,I.jsx)(Lf.Options,{style:{marginLeft:`-10px`,marginRight:`-10px`,marginBottom:`-10px`},children:u.length>0?u:(0,I.jsx)(Lf.Empty,{children:`Nothing found...`})})})]}),(0,I.jsx)(H,{size:`sm`,ta:`center`,mt:`md`,children:(0,I.jsx)(Md,{component:`button`,type:`button`,onClick:()=>{window.location.href=`/signin?project=new&login=${e.login}`},children:`Create a new project`})})]})}function nI(e){return TC(e,`https://medplum.com/identifier/label`)}function rI(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)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:u?p?(0,I.jsx)(zF,{allowedMethods:_??[`totp`],qrCodeUrl:h,onEnrollEmail:ee,totpTitle:`Enroll in MFA`,totpDescription:`Scan this QR code with your authenticator app.`,onEnrollTotp:async e=>{let t=await l.post(`auth/mfa/login-enroll`,{login:u,method:`totp`,token:e});j(t)}}):y?(0,I.jsx)(BF,{methods:S??[],email:w,initialEmailMode:E,onRequestEmailCode:M,onSubmit:async e=>{let t=await l.post(`auth/mfa/verify`,{login:u,token:e});j(t)}}):e.projectId===`new`?(0,I.jsx)(HF,{login:u,handleAuthResponse:j}):O?(0,I.jsx)(tI,{login:u,memberships:O,handleAuthResponse:j}):e.chooseScopes?(0,I.jsx)(LF,{login:u,scope:e.scope,handleAuthResponse:N,...r}):(0,I.jsx)(`div`,{children:`Success`}):(0,I.jsx)(QF,{onForgotPassword:a,onRegister:o,handleAuthResponse:j,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...c,children:e.children})})}function iI(e){return(0,I.jsx)(I.Fragment,{children:Aw(e.value)})}function aI(e){return(0,I.jsx)(I.Fragment,{children:jw(e.value,e.includeCode)})}function oI(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 sI(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[t.name,t.name&&`: `,t.telecom?.map(e=>(0,I.jsx)(oI,{value:e},`telecom-${t.name}-${e.value}`))]}):null}function cI(e,t,n){let r=HS(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 lI(e,t,n){let r=US(e,t,n);return r?Array.isArray(r)?[r.map(e=>e.value),r[0].type]:[r.value,r.type]:[void 0,`undefined`]}function uI(e){let{elementDefinitionType:t}=e,n=Q(),r=(0,b.useContext)(HA),[i,a]=(0,b.useState)(SS(`Extension`)),o=(0,b.useMemo)(()=>{if(MC(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=wS(o);c(!1),e&&a(e)}).catch(e=>{c(!1),console.warn(e)}))},[n,o]),o&&(s||!CS(o)))return(0,I.jsx)(`div`,{children:`Loading...`});if(i.elements[`value[x]`]?.max!==0){let[t,n]=cI({type:`Extension`,value:e.value},`value[x]`,o??r.profileUrl);return(0,I.jsx)(wI,{propertyType:n,value:t})}return(0,I.jsx)(OI,{path:e.path,value:{type:i.type,value:e.value},compact:e.compact,ignoreMissingValues:e.ignoreMissingValues,link:e.link,profileUrl:o})}function dI(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:_w(t,e.options)}):null}function fI(e){return(0,I.jsxs)(`div`,{children:[e.value?.system,`: `,e.value?.value]})}function pI(e){return(0,I.jsx)(I.Fragment,{children:kw(e.value)})}function mI(e){return(0,I.jsx)(I.Fragment,{children:Ow(e.value,e.precision)})}function hI(e){return(0,I.jsx)(I.Fragment,{children:Dw(e.value,e.precision,e.exclusive)})}function gI(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(mI,{value:t.numerator,precision:e.precision}),`\xA0/\xA0`,(0,I.jsx)(mI,{value:t.denominator,precision:e.precision})]}):null}function _I(e){if(!e.value)return null;let t=e.value.display||e.value.reference||DC(e.value);return e.link!==!1&&e.value.reference?(0,I.jsx)(IM,{to:e.value,children:t}):(0,I.jsx)(I.Fragment,{children:t})}function vI(e,t,n,r){if(!MC(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=DO(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 yI({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(!TO(n)){console.debug(`Unsupported slice definition`,n);continue}let t;MC(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=wS(n))}n(i)}).catch(r)})}function bI(e,t,n){return t===void 0?n:(0,I.jsx)(e,{value:t,children:n})}function xI(e){let{slice:t,property:n}=e,r=t.typeSchema?.elements??t.elements,i=(0,b.useContext)(HA),a=(0,b.useMemo)(()=>{if(MC(r))return bO({parentContext:i,elements:r,path:e.path,profileUrl:t.typeSchema?.url})},[i,e.path,t.typeSchema?.url,r]);return bI(HA.Provider,a,(0,I.jsx)(I.Fragment,{children:e.value.map((r,i)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(wI,{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 SI=50;function CI(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)(HA);if((0,b.useEffect)(()=>{yI({medplum:r,property:t}).then(e=>{f(i.length),c(e);let n=vI(i.slice(0,SI),e,t.slicing,p.profileUrl);u(n),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)(wI,{path:e.path,arrayElement:!0,property:t,propertyType:n,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${a}-${r.length}`));if(e.includeDescriptionListEntry){if(!MC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);let t=e.path.split(`.`).pop();m=(0,I.jsx)(lF,{term:Kw(t),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)(xI,{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)(lF,{term:Kw(n.name),children:i},n.name)),i}),m,d>SI&&(0,I.jsx)(V,{justify:`right`,children:(0,I.jsxs)(H,{children:[`... `,d,` total values`]})})]})}function wI(e){let{property:t,propertyType:n,value:r}=e;if(t?.path?.endsWith(`.id`))return(0,I.jsxs)(hd,{gap:3,align:`center`,children:[r,!jC(r)&&(0,I.jsx)(am,{value:r,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Xv,{label:e?`Copied`:`Copy`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,children:e?(0,I.jsx)(mj,{size:`1rem`}):(0,I.jsx)(Sj,{size:`1rem`})})})})]});if(t&&(t.isArray||t.max>1)&&!e.arrayElement)return n===X.Attachment?(0,I.jsx)(uF,{values:r,maxWidth:e.maxWidth,includeDescriptionListEntry:e.includeArrayDescriptionListEntry,property:t,path:e.path}):(0,I.jsx)(CI,{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)(TI,{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 HC(r)&&!UC(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)(_I,{value:{reference:r},link:e.link});case X.dateTime:case X.instant:return(0,I.jsx)(I.Fragment,{children:bw(r)});case X.time:return(0,I.jsx)(I.Fragment,{children:yw(r)});case X.markdown:return(0,I.jsx)(`pre`,{children:r});case X.Address:return(0,I.jsx)(zA,{value:r});case X.Annotation:return(0,I.jsx)(I.Fragment,{children:r?.text});case X.Attachment:return(0,I.jsx)(aF,{value:r,maxWidth:e.maxWidth});case X.CodeableConcept:return(0,I.jsx)(iI,{value:r});case X.Coding:return(0,I.jsx)(aI,{value:r});case X.ContactDetail:return(0,I.jsx)(sI,{value:r});case X.ContactPoint:return(0,I.jsx)(oI,{value:r});case X.HumanName:return(0,I.jsx)(dI,{value:r});case X.Identifier:return(0,I.jsx)(fI,{value:r});case X.Money:return(0,I.jsx)(pI,{value:r});case X.Period:return(0,I.jsx)(I.Fragment,{children:xw(r)});case X.Quantity:case X.Duration:return(0,I.jsx)(mI,{value:r});case X.Range:return(0,I.jsx)(hI,{value:r});case X.Ratio:return(0,I.jsx)(gI,{value:r});case X.Reference:return(0,I.jsx)(_I,{value:r,link:e.link});case X.Timing:return(0,I.jsx)(I.Fragment,{children:Tw(r)});case X.Dosage:case X.UsageContext:if(!e.path)throw Error(`Displaying property of type ${e.propertyType} requires path`);return(0,I.jsx)(OI,{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)(uI,{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)(OI,{path:e.path,value:{type:t.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}function TI(e){let[t,n]=(0,b.useState)(!1),r=e.value??``,i=!jC(r),a=`•`.repeat(8);return(0,I.jsxs)(hd,{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)(am,{value:e.value,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Xv,{label:e?`Copied`:`Copy secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,"aria-label":e?`Copied`:`Copy secret`,children:e?(0,I.jsx)(mj,{size:`1rem`}):(0,I.jsx)(Sj,{size:`1rem`})})})}),(0,I.jsx)(Xv,{label:t?`Hide secret`:`Show secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:`gray`,onClick:()=>n(!t),"aria-label":t?`Hide secret`:`Show secret`,children:t?(0,I.jsx)(jj,{size:`1rem`}):(0,I.jsx)(Mj,{size:`1rem`})})})]})]})}var EI=[`extension`,`modifierExtension`],DI=BA.filter(e=>!EI.includes(e));function OI(e){let t=e.value,{value:n,type:r}=t,i=(0,b.useContext)(HA),a=e.profileUrl??i?.profileUrl,o=(0,b.useMemo)(()=>xS(r,a),[a,r]),s=(0,b.useMemo)(()=>{if(o)return bO({parentContext:i,elements:o.elements,path:e.path,profileUrl:o.url,accessPolicyResource:e.accessPolicyResource})},[o,i,e.path,e.accessPolicyResource]);if(jC(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 bI(HA.Provider,s,(0,I.jsx)(cF,{compact:e.compact,children:Object.entries(c.elements).map(([n,r])=>{if(EI.includes(n)&&jC(r.slicing?.slices)||DI.includes(n)||VA.includes(n)&&r.path.split(`.`).length===2||n.includes(`.`))return null;let[i,a]=cI(t,n,c.profileUrl);if((e.ignoreMissingValues||r.max===0)&&jC(i)||e.path.endsWith(`.extension`)&&(n===`url`||n===`id`))return null;let o=r.max>1||r.isArray,s=(0,I.jsx)(wI,{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)(lF,{term:Kw(n),children:s},n)})}))}var kI={dimmed:`_dimmed_11me5_1`,preserveBreaks:`_preserveBreaks_11me5_5`},AI=`Read Only`;function jI(e,t){return e?(0,I.jsx)(Xv.Floating,{label:e,children:t}):t}function MI(e){let{debugMode:t}=(0,b.useContext)(HA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,jI(e?.readonly?AI: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)(ld.Wrapper,{id:e.htmlFor,label:n,classNames:{label:e?.readonly?kI.dimmed:void 0},description:e.description,withAsterisk:e.withAsterisk,children:null})})]}))}function NI(e){let{debugMode:t}=(0,b.useContext)(HA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,jI(e?.readonly?AI:void 0,(0,I.jsx)(ld.Wrapper,{id:e.htmlFor,label:n,classNames:{label:Mn({[kI.dimmed]:e?.readonly},kI.preserveBreaks)},description:e.description,withAsterisk:e.withAsterisk,error:xF(e.outcome,e.errorExpression??e.htmlFor),"data-testid":e.testId,children:e.children}))}function PI(e,t,n,r,i){let a=r.type;if(a.length>1)for(let n of a){let r=t.replace(`[x]`,ZC(n.code));r in e&&delete e[r]}return e[n]=jC(i)?void 0:i,e}function FI(e){return!!e&&!jC(e.url)&&!jC(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=RI(e);l(t),n&&n(t)}return(0,I.jsx)(wP,{defaultValue:c&&LI(c),onChange:u,withHelpText:r??!0,...s})}function LI(e){return e.coding?.map(e=>({system:e.system,code:e.code,display:e.display}))}function RI(e){if(e.length!==0)return{coding:e.map(e=>({system:e.system,code:e.code,display:e.display}))}}function zI(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&&VI(t);s(r),n&&n(r)}return(0,I.jsx)(wP,{defaultValue:o?BI(o):void 0,maxValues:1,onChange:c,withHelpText:r??!0,...a})}function BI(e){return{system:e.system,code:e.code,display:e.display}}function VI(e){return{system:e.system,code:e.code,display:e.display}}function HI(e){let{path:t,outcome:n}=e,{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(HA),[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)(wg,{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:xF(n,_+`.system`)}),(0,I.jsx)(wg,{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:xF(n,_+`.use`)}),(0,I.jsx)(_b,{disabled:e.disabled||f?.readonly,placeholder:`Value`,defaultValue:a?.value,required:(l?.min??0)>0,onChange:e=>g(e.currentTarget.value),error:xF(n,_+`.value`)})]})}function UI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(_b,{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)(HI,{disabled:e.disabled||a?.readonly,name:e.name+`-telecom`,path:e.path+`.telecom`,defaultValue:t?.telecom?.[0],onChange:c,outcome:e.outcome})]})}function WI(e){if(!e)return``;let t=new Date(e);return vw(t)?t.toLocaleDateString(`sv`)+`T`+t.toLocaleTimeString(`sv`):``}function GI(e){if(!e)return``;let t=new Date(e);return vw(t)?t.toISOString():``}function KI(e){return(0,I.jsx)(_b,{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:qI(),step:1,defaultValue:WI(e.defaultValue),autoFocus:e.autoFocus,error:xF(e.outcome,e.name),onChange:t=>{if(e.onChange){let n=t.currentTarget.value;e.onChange(GI(n))}}})}function qI(){return`datetime-local`}function JI(e){let{propertyType:t}=e,n=Q(),r=(0,b.useMemo)(()=>{if(MC(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||!CS(r))?(0,I.jsx)(`div`,{children:`Loading...`}):(0,I.jsx)(FL,{profileUrl:r,path:e.path,typeName:`Extension`,defaultValue:e.defaultValue,onChange:e.onChange})}function YI(e){let{outcome:t,path:n}=e,[r,i]=(0,b.useState)(e.defaultValue),{getExtendedProps:a}=(0,b.useContext)(HA),[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)(wg,{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:xF(t,_+`.use`)}),(0,I.jsx)(_b,{disabled:e.disabled||s?.readonly,placeholder:`Prefix`,name:e.name+`-prefix`,defaultValue:r?.prefix?.join(` `),onChange:e=>p(e.currentTarget.value),error:xF(t,_+`.prefix`)}),(0,I.jsx)(_b,{disabled:e.disabled||c?.readonly,placeholder:`Given`,name:e.name+`-given`,defaultValue:r?.given?.join(` `),onChange:e=>m(e.currentTarget.value),error:xF(t,_+`.given`)}),(0,I.jsx)(_b,{disabled:e.disabled||l?.readonly,name:e.name+`-family`,placeholder:`Family`,defaultValue:r?.family,onChange:e=>h(e.currentTarget.value),error:xF(t,_+`.family`)}),(0,I.jsx)(_b,{disabled:e.disabled||u?.readonly,placeholder:`Suffix`,name:e.name+`-suffix`,defaultValue:r?.suffix?.join(` `),onChange:e=>g(e.currentTarget.value),error:xF(t,_+`.suffix`)})]})}function XI(e){let[t,n]=(0,b.useState)(e.defaultValue),{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(HA),[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)(_b,{disabled:e.disabled||s?.readonly,placeholder:`System`,required:(a?.min??0)>0,defaultValue:t?.system,onChange:e=>l({...t,system:e.currentTarget.value}),error:xF(e.outcome,u+`.system`)}),(0,I.jsx)(_b,{disabled:e.disabled||c?.readonly,placeholder:`Value`,required:(o?.min??0)>0,defaultValue:t?.value,onChange:e=>l({...t,value:e.currentTarget.value}),error:xF(e.outcome,u+`.value`)})]})}var ZI=[`USD`,`EUR`,`CAD`,`GBP`,`AUD`];function QI(e){let{onChange:t}=e,[n,r]=(0,b.useState)(e.defaultValue),{getExtendedProps:i}=(0,b.useContext)(HA),[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)(wg,{disabled:e.disabled||a?.readonly,defaultValue:n?.currency,data:ZI,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:c});return(0,I.jsx)(_b,{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)(Cj,{size:14}),rightSection:u,rightSectionWidth:92,onChange:l})}function $I(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(KI,{disabled:e.disabled||i?.readonly,name:e.name+`.start`,placeholder:`Start`,defaultValue:t?.start,onChange:e=>o({...t,start:e})}),(0,I.jsx)(KI,{disabled:e.disabled||a?.readonly,name:e.name+`.end`,placeholder:`End`,defaultValue:t?.end,onChange:e=>o({...t,end:e})})]})}function eL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(wg,{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)(_b,{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:tL(e.currentTarget.value)})}}),(0,I.jsx)(_b,{disabled:e.disabled||o?.readonly,placeholder:`Unit`,"data-testid":e.name+`-unit`,defaultValue:t?.unit,onChange:e=>s({...t,unit:e.currentTarget.value})})]})}function tL(e){if(e)return Number.parseFloat(e)}function nL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(eL,{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)(eL,{path:e.path+`.high`,disabled:e.disabled||a?.readonly,name:e.name+`-high`,defaultValue:t?.high,onChange:e=>o({...t,high:e})})]})}function rL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(eL,{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)(eL,{path:e.path+`.denominator`,disabled:e.disabled||a?.readonly,name:e.name+`-denominator`,defaultValue:t?.denominator,onChange:e=>o({...t,denominator:e})})]})}var iL={Device:`device-name`,Observation:`code`,Subscription:`criteria`,User:`email:contains`},aL=`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 oL(e){return{value:mC(e)??``,label:vC(e),resource:e}}function sL(e){return iL[e]??(aL.includes(e)?`name`:`_id`)}var cL=(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)(HM,{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})]})]})}));cL.displayName=`DefaultResourceItemComponent`;function lL(e){let t=Q(),{resourceType:n,searchCriteria:r}=e,i=e.itemComponent??cL,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(Qw(e))return Promise.resolve(e);if($w(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=sL(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)(iN,{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:oL,loadOptions:l,onChange:u,clearable:!0})}function uL(e){let t=e.onChange,n=(0,b.useCallback)(e=>{t&&t(e[0])},[t]);return(0,I.jsx)(lL,{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 dL(e){let{onChange:t}=e,n=Q(),[r,i]=(0,b.useState)(e.defaultValue),[a,o]=(0,b.useState)(()=>fL(e.targetTypes)),[s,c]=(0,b.useState)(()=>pL(e.defaultValue,a)),l=(0,b.useRef)(new bx),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(!hL(t))return Promise.resolve(t);e=!0;let r=t.value,i=l.current.get(r);if(i)return i;let a=new ND(mL(n,t.value).then(e=>{let n={...t};return e?MC(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?pC(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)(wg,{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,n=a.find(e=>e.value===t);c(n)},data:f}),!a&&(0,I.jsx)(AP,{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)(uL,{resourceType:s?.resourceType,name:e.name+`-id`,required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:d,disabled:e.disabled})]})]})}function fL(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 pL(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 mL(e,t){let n=wS(t);if(n)return{type:n.type,name:n.name,title:n.title};let r=`{
|
|
200
|
+
`)}function SF(e,t){return e?.issue?.filter(e=>wF(e.expression?.[0],t))}var CF=/\[\d+\]/;function wF(e,t){if((typeof e==`string`&&CF.test(e))!==(typeof t==`string`&&CF.test(t))&&(e=e?.replace(CF,``),t=t?.replace(CF,``)),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 TF(e){let{onSuccess:t}=e,n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1);return(0,I.jsx)(vF,{width:450,children:(0,I.jsxs)(hP,{onSubmit:e=>{i(void 0),n.post(`auth/changepassword`,e).then(()=>{o(!0),t?.()}).catch(e=>i(aS(e)))},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{children:`Change password`})]}),!a&&(0,I.jsxs)(G,{gap:`xl`,mt:`xl`,children:[(0,I.jsx)(bF,{name:`oldPassword`,label:`Old password`,required:!0,autoFocus:!0,error:xF(r,`oldPassword`)}),(0,I.jsx)(bF,{name:`newPassword`,label:`New password`,required:!0,error:xF(r,`newPassword`)}),(0,I.jsx)(bF,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:xF(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 EF=/^patient\/Condition\.(?:\*|c?r?u?d?s?)$/,DF=`?category=http://terminology.hl7.org/CodeSystem/condition-category|encounter-diagnosis`,OF=`?category=http://terminology.hl7.org/CodeSystem/condition-category|problem-list-item`,kF=`?category=http://hl7.org/fhir/us/core/CodeSystem/condition-category|health-concern`,AF=/^patient\/Observation\.(?:\*|c?r?u?d?s?)$/,jF=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category|clinical-test`,MF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|laboratory`,NF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|social-history`,PF=`?category=http://hl7.org/fhir/us/core/CodeSystem/us-core-category|sdoh`,FF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|survey`,IF=`?category=http://terminology.hl7.org/CodeSystem/observation-category|vital-signs`;function LF(e){let t=Q();return(0,I.jsx)(hP,{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)(hd,{direction:`column`,align:`center`,justify:`center`,children:[e.logo??(0,I.jsx)(yF,{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 EF.test(e)?t=[e+DF,e+OF,e+kF]:AF.test(e)&&(t=[e+jF,e+MF,e+NF,e+PF,e+FF,e+IF]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sp,{id:e,name:e,label:e,defaultChecked:!0},e),t?.map(e=>(0,I.jsx)(sp,{id:e,name:e,label:e},e))]},e+`_group`)})}),(0,I.jsx)(V,{justify:`flex-end`,mt:`xl`,children:(0,I.jsx)(gP,{fullWidth:!0,children:e.submitLabel??`Set Scope`})})]})})}function RF(e){let[t,n]=(0,b.useState)();return(0,I.jsxs)(hP,{onSubmit:t=>{n(void 0),e.onSubmit(t)?.catch(e=>n(Y(e)))},children:[(0,I.jsxs)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Error`,color:`red`,mb:`lg`,children:t}),e.qrCodeUrl&&(0,I.jsx)(Wp,{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)(Pm,{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)(_b,{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)(gP,{fullWidth:!0,children:e.buttonText}),e.footer]})]})}function zF(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)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(Wp,{style:{flexDirection:`column`},children:[(0,I.jsx)(yF,{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)(RF,{title:e.totpTitle,description:e.totpDescription,buttonText:e.totpButtonText??`Enroll`,qrCodeUrl:n,onSubmit:e=>i(e.token)})}function BF(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)(Md,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Resend code`}):t.includes(`email`)&&(c=(0,I.jsx)(Md,{component:`button`,type:`button`,size:`sm`,ta:`center`,onClick:s,children:`Get a code by email instead`})),(0,I.jsx)(RF,{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 VF(e){let{outcome:t,issues:n,displayOkOutcomes:r,...i}=e,a=t?.issue||n;return!a||a.length===0||t&&tS(t)&&!r?null:(0,I.jsx)(Td,{icon:(0,I.jsx)(QA,{size:16}),color:`red`,...i,children:a.map(e=>(0,I.jsx)(`div`,{"data-testid":`text-field-error`,children:sS(e)},e.details?.text))})}function HF(e){let t=Q(),[n,r]=(0,b.useState)(),i=SF(n,void 0);return(0,I.jsxs)(hP,{onSubmit:async n=>{try{e.handleAuthResponse(await t.startNewProject({login:e.login,projectName:n.projectName}))}catch(e){r(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Create a new project`})]}),(0,I.jsx)(VF,{issues:i,mb:`lg`}),(0,I.jsx)(G,{gap:`sm`,children:(0,I.jsx)(_b,{name:`projectName`,label:`Project Name`,placeholder:`My Project`,required:!0,autoFocus:!0,error:xF(n,`projectName`)})}),(0,I.jsxs)(G,{gap:`xs`,mt:`md`,children:[(0,I.jsx)(gP,{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)(Md,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{href:`https://www.medplum.com/terms`,children:`Terms\xA0of\xA0Service`}),`.`]})]})]})}function UF(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 WF(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`){UF(`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 GF(e){if(e)return e;let t=YE.getOrigin();if(t&&[].includes(t))return`__GOOGLE_CLIENT_ID__`}function KF(e){typeof grecaptcha>`u`&&UF(`https://www.google.com/recaptcha/api.js?render=`+e)}function qF(e){return new Promise((t,n)=>{grecaptcha.ready(async()=>{try{t(await grecaptcha.execute(e,{action:`submit`}))}catch(e){n(e)}})})}function JF(e){let t=GF(e.googleClientId),n=e.recaptchaSiteKey,r=Q(),[i,a]=(0,b.useState)(),o=SF(i,void 0);return(0,b.useEffect)(()=>{n&&KF(n)},[n]),(0,I.jsxs)(hP,{onSubmit:async t=>{a(void 0);try{let i=``;n&&(i=await qF(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(aS(e))}},children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:e.children}),(0,I.jsx)(VF,{issues:o,mb:`lg`}),t&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(WF,{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(aS(e))}}})}),(0,I.jsx)(lm,{label:`or`,labelPosition:`center`,my:`lg`})]}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(_b,{name:`firstName`,type:`text`,label:`First name`,placeholder:`First name`,required:!0,autoFocus:!0,error:xF(i,`firstName`)}),(0,I.jsx)(_b,{name:`lastName`,type:`text`,label:`Last name`,placeholder:`Last name`,required:!0,error:xF(i,`lastName`)}),(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,error:xF(i,`email`)}),(0,I.jsx)(bF,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,error:xF(i,`password`)})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(sp,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(gP,{fullWidth:!0,children:`Register Account`}),e.onSignIn&&(0,I.jsxs)(H,{size:`sm`,mt:`lg`,c:`dimmed`,ta:`center`,"data-dashlane-ignore":`true`,"data-lp-ignore":`true`,"data-no-autofill":`true`,"data-form-type":`navigation`,children:[`Already have an account?`,` `,(0,I.jsx)(Md,{component:`button`,type:`button`,onClick:e.onSignIn,children:`Sign In`})]}),(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)(Md,{href:`https://www.medplum.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{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)(Md,{href:`https://policies.google.com/privacy`,children:`Privacy\xA0Policy`}),` and `,(0,I.jsx)(Md,{href:`https://policies.google.com/terms`,children:`Terms\xA0of\xA0Service`}),` apply.`]})]})]})}function YF(e){let{type:t,projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,onSuccess:o,onSignIn:s}=e,c=Q(),[l,u]=(0,b.useState)(e.login),[d,f]=(0,b.useState)(),[p,m]=(0,b.useState)(!1);(0,b.useEffect)(()=>{t===`patient`&&l&&c.startNewPatient({login:l,projectId:n}).then(e=>c.processCode(e.code)).then(()=>o()).catch(e=>f(aS(e)))},[c,t,n,l,o]);function h(e){e.code&&c.processCode(e.code).then(()=>o()).catch(e=>f(aS(e))),e.login&&u(e.login),e.emailVerificationRequired&&m(!0)}let g=SF(d,void 0);return(0,I.jsxs)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:[(0,I.jsx)(VF,{issues:g,mb:`lg`}),!l&&(0,I.jsx)(JF,{projectId:n,clientId:r,googleClientId:i,recaptchaSiteKey:a,onSignIn:s,handleAuthResponse:h,children:e.children}),p&&(0,I.jsx)(`div`,{children:`Please check your email for a verification link. Click the link to continue setting up your account.`}),l&&!p&&t===`project`&&(0,I.jsx)(HF,{login:l,handleAuthResponse:h})]})}function XF(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&&KF(n)},[n]),(0,I.jsx)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:(0,I.jsxs)(hP,{onSubmit:async e=>{c(void 0);try{let i=``;n&&(i=await qF(n)),await o.post(`auth/resetpassword`,{...e,projectId:t,recaptchaToken:i}),u(!0),r?.()}catch(e){c(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Reset your password`})]}),(0,I.jsx)(VF,{issues:SF(s,void 0),mb:`lg`}),!l&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(G,{gap:`sm`,mb:`md`,children:(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:xF(s,`email`)})}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(gP,{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)(Md,{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)(Md,{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 ZF(e){let{id:t,secret:n,onSuccess:r,onSignIn:i}=e,a=Q(),[o,s]=(0,b.useState)(),[c,l]=(0,b.useState)(!1),u=SF(o,void 0);return(0,I.jsxs)(vF,{width:450,children:[(0,I.jsx)(VF,{issues:u}),(0,I.jsxs)(hP,{onSubmit:e=>{if(e.password!==e.confirmPassword){s(Xx(`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(aS(e)))},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{children:`Set password`})]}),!c&&(0,I.jsxs)(G,{children:[(0,I.jsx)(bF,{name:`password`,label:`New password`,required:!0,error:xF(o,`password`)}),(0,I.jsx)(bF,{name:`confirmPassword`,label:`Confirm new password`,required:!0,error:xF(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)(Md,{component:`button`,type:`button`,onClick:i,children:`sign in`}):`sign in`,`.`]})]})]})}function QF(e){let[t,n]=(0,b.useState)();return t?(0,I.jsx)(eI,{email:t,resetEmail:()=>n(void 0),...e}):(0,I.jsx)($F,{setEmail:n,...e})}function $F(e){let{setEmail:t,onRegister:n,handleAuthResponse:r,children:i,disableEmailAuth:a,...o}=e,s=Q(),c=!e.disableGoogleAuth&&GF(e.googleClientId),[l,u]=(0,b.useState)(),d=SF(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:YE.getLocation()}),n=new URL(e.authorizeUrl);return n.searchParams.set(`state`,t),YE.assign(n.toString()),!0},[s,o]),p=(0,b.useCallback)(async e=>{let n=await s.post(`auth/method`,{email:e.email});await f(n)||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(aS(e))}},[s,o,f,r]);return(0,I.jsxs)(hP,{onSubmit:p,children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:i}),(0,I.jsx)(VF,{issues:d,mb:`lg`}),c&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{style:{minHeight:40},children:(0,I.jsx)(WF,{googleClientId:c,handleGoogleCredential:m})}),!a&&(0,I.jsx)(lm,{label:`or`,labelPosition:`center`,my:`lg`})]}),!a&&(0,I.jsx)(_b,{name:`email`,type:`email`,label:`Email`,mb:`md`,placeholder:`name@domain.com`,required:!0,autoFocus:!0,error:xF(l,`email`),"data-testid":`auth.email`}),(0,I.jsxs)(G,{gap:`xs`,children:[!a&&(0,I.jsx)(gP,{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)(Md,{onClick:n,children:`Register`})]})]})]})}function eI(e){let{onForgotPassword:t,handleAuthResponse:n,children:r,...i}=e,a=Q(),[o,s]=(0,b.useState)(),c=SF(o,void 0),l=(0,b.useCallback)(e=>a.startLogin({...i,password:e.password,remember:e.remember===`on`}).then(n).catch(e=>s(aS(e))),[a,i,n]);return(0,I.jsxs)(hP,{onSubmit:l,children:[(0,I.jsx)(hd,{direction:`column`,align:`center`,justify:`center`,children:r}),(0,I.jsx)(VF,{issues:c,mb:`lg`}),(0,I.jsxs)(G,{gap:`sm`,children:[(0,I.jsx)(_b,{label:`Email`,value:e.email,disabled:!0,rightSectionWidth:36,rightSection:(0,I.jsx)(mu,{variant:`subtle`,color:`gray`,onClick:e.resetEmail,"aria-label":`Change email`,children:(0,I.jsx)($j,{size:`1rem`,stroke:1.5})})}),(0,I.jsx)(bF,{name:`password`,label:`Password`,autoComplete:`off`,required:!0,autoFocus:!0,error:xF(o,`password`),"data-testid":`auth.password`})]}),(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(sp,{id:`remember`,name:`remember`,label:`Remember me`,size:`xs`,style:{lineHeight:1},pt:`md`,pb:`xs`}),(0,I.jsx)(gP,{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)(Md,{onClick:t,children:`Reset Password`})})]})]})}function tI(e){let t=Q(),n=Pf(),[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(nI(e))}function l(n){t.post(`auth/profile`,{login:e.login,profile:n}).then(e.handleAuthResponse).catch(e=>o(aS(e)))}let u=e.memberships.filter(c).slice(0,10).map(e=>(0,I.jsx)(Lf.Option,{value:e.id,className:WM.interactive,children:(0,I.jsx)(KM,{membership:e,label:nI(e)})},e.id));return(0,I.jsxs)(G,{gap:`0`,children:[(0,I.jsxs)(hd,{justify:`center`,align:`center`,direction:`column`,wrap:`nowrap`,children:[(0,I.jsx)(yF,{size:32}),(0,I.jsx)(q,{order:3,py:`lg`,children:`Choose a Project`})]}),(0,I.jsx)(VF,{outcome:a,mb:`lg`}),(0,I.jsxs)(Lf,{store:n,onOptionSubmit:l,children:[(0,I.jsx)(Lf.EventsTarget,{children:(0,I.jsx)(_b,{placeholder:`Search`,value:r,mb:`md`,autoFocus:!0,leftSection:(0,I.jsx)(lM,{size:16}),onChange:e=>{i(e.currentTarget.value),n.updateSelectedOptionIndex()}})}),(0,I.jsx)(`div`,{children:(0,I.jsx)(Lf.Options,{style:{marginLeft:`-10px`,marginRight:`-10px`,marginBottom:`-10px`},children:u.length>0?u:(0,I.jsx)(Lf.Empty,{children:`Nothing found...`})})})]}),(0,I.jsx)(H,{size:`sm`,ta:`center`,mt:`md`,children:(0,I.jsx)(Md,{component:`button`,type:`button`,onClick:()=>{window.location.href=`/signin?project=new&login=${e.login}`},children:`Create a new project`})})]})}function nI(e){return TC(e,`https://medplum.com/identifier/label`)}function rI(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)(vF,{width:400,px:`xl`,py:`xl`,bdrs:`md`,children:u?p?(0,I.jsx)(zF,{allowedMethods:_??[`totp`],qrCodeUrl:h,onEnrollEmail:ee,totpTitle:`Enroll in MFA`,totpDescription:`Scan this QR code with your authenticator app.`,onEnrollTotp:async e=>{let t=await l.post(`auth/mfa/login-enroll`,{login:u,method:`totp`,token:e});j(t)}}):y?(0,I.jsx)(BF,{methods:S??[],email:w,initialEmailMode:E,onRequestEmailCode:M,onSubmit:async e=>{let t=await l.post(`auth/mfa/verify`,{login:u,token:e});j(t)}}):e.projectId===`new`?(0,I.jsx)(HF,{login:u,handleAuthResponse:j}):O?(0,I.jsx)(tI,{login:u,memberships:O,handleAuthResponse:j}):e.chooseScopes?(0,I.jsx)(LF,{login:u,scope:e.scope,handleAuthResponse:N,...r}):(0,I.jsx)(`div`,{children:`Success`}):(0,I.jsx)(QF,{onForgotPassword:a,onRegister:o,handleAuthResponse:j,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...c,children:e.children})})}function iI(e){return(0,I.jsx)(I.Fragment,{children:Aw(e.value)})}function aI(e){return(0,I.jsx)(I.Fragment,{children:jw(e.value,e.includeCode)})}function oI(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 sI(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[t.name,t.name&&`: `,t.telecom?.map(e=>(0,I.jsx)(oI,{value:e},`telecom-${t.name}-${e.value}`))]}):null}function cI(e,t,n){let r=HS(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 lI(e,t,n){let r=US(e,t,n);return r?Array.isArray(r)?[r.map(e=>e.value),r[0].type]:[r.value,r.type]:[void 0,`undefined`]}function uI(e){let{elementDefinitionType:t}=e,n=Q(),r=(0,b.useContext)(HA),[i,a]=(0,b.useState)(SS(`Extension`)),o=(0,b.useMemo)(()=>{if(MC(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=wS(o);c(!1),e&&a(e)}).catch(e=>{c(!1),console.warn(e)}))},[n,o]),o&&(s||!CS(o)))return(0,I.jsx)(`div`,{children:`Loading...`});if(i.elements[`value[x]`]?.max!==0){let[t,n]=cI({type:`Extension`,value:e.value},`value[x]`,o??r.profileUrl);return(0,I.jsx)(wI,{propertyType:n,value:t})}return(0,I.jsx)(OI,{path:e.path,value:{type:i.type,value:e.value},compact:e.compact,ignoreMissingValues:e.ignoreMissingValues,link:e.link,profileUrl:o})}function dI(e){let t=e.value;return t?(0,I.jsx)(I.Fragment,{children:_w(t,e.options)}):null}function fI(e){return(0,I.jsxs)(`div`,{children:[e.value?.system,`: `,e.value?.value]})}function pI(e){return(0,I.jsx)(I.Fragment,{children:kw(e.value)})}function mI(e){return(0,I.jsx)(I.Fragment,{children:Ow(e.value,e.precision)})}function hI(e){return(0,I.jsx)(I.Fragment,{children:Dw(e.value,e.precision,e.exclusive)})}function gI(e){let t=e.value;return t?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(mI,{value:t.numerator,precision:e.precision}),`\xA0/\xA0`,(0,I.jsx)(mI,{value:t.denominator,precision:e.precision})]}):null}function _I(e){if(!e.value)return null;let t=e.value.display||e.value.reference||DC(e.value);return e.link!==!1&&e.value.reference?(0,I.jsx)(IM,{to:e.value,children:t}):(0,I.jsx)(I.Fragment,{children:t})}function vI(e,t,n,r){if(!MC(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=DO(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 yI({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(!TO(n)){console.debug(`Unsupported slice definition`,n);continue}let t;MC(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=wS(n))}n(i)}).catch(r)})}function bI(e,t,n){return t===void 0?n:(0,I.jsx)(e,{value:t,children:n})}function xI(e){let{slice:t,property:n}=e,r=t.typeSchema?.elements??t.elements,i=(0,b.useContext)(HA),a=(0,b.useMemo)(()=>{if(MC(r))return bO({parentContext:i,elements:r,path:e.path,profileUrl:t.typeSchema?.url})},[i,e.path,t.typeSchema?.url,r]);return bI(HA.Provider,a,(0,I.jsx)(I.Fragment,{children:e.value.map((r,i)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(wI,{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 SI=50;function CI(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)(HA);if((0,b.useEffect)(()=>{yI({medplum:r,property:t}).then(e=>{f(i.length),c(e);let n=vI(i.slice(0,SI),e,t.slicing,p.profileUrl);u(n),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)(wI,{path:e.path,arrayElement:!0,property:t,propertyType:n,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${a}-${r.length}`));if(e.includeDescriptionListEntry){if(!MC(e.path))throw Error(`props.path is required when includeDescriptionListEntry is true`);let t=e.path.split(`.`).pop();m=(0,I.jsx)(lF,{term:Kw(t),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)(xI,{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)(lF,{term:Kw(n.name),children:i},n.name)),i}),m,d>SI&&(0,I.jsx)(V,{justify:`right`,children:(0,I.jsxs)(H,{children:[`... `,d,` total values`]})})]})}function wI(e){let{property:t,propertyType:n,value:r}=e;if(t?.path?.endsWith(`.id`))return(0,I.jsxs)(hd,{gap:3,align:`center`,children:[r,!jC(r)&&(0,I.jsx)(am,{value:r,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Xv,{label:e?`Copied`:`Copy`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,children:e?(0,I.jsx)(mj,{size:`1rem`}):(0,I.jsx)(Sj,{size:`1rem`})})})})]});if(t&&(t.isArray||t.max>1)&&!e.arrayElement)return n===X.Attachment?(0,I.jsx)(uF,{values:r,maxWidth:e.maxWidth,includeDescriptionListEntry:e.includeArrayDescriptionListEntry,property:t,path:e.path}):(0,I.jsx)(CI,{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)(TI,{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 HC(r)&&!UC(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)(_I,{value:{reference:r},link:e.link});case X.dateTime:case X.instant:return(0,I.jsx)(I.Fragment,{children:bw(r)});case X.time:return(0,I.jsx)(I.Fragment,{children:yw(r)});case X.markdown:return(0,I.jsx)(`pre`,{children:r});case X.Address:return(0,I.jsx)(zA,{value:r});case X.Annotation:return(0,I.jsx)(I.Fragment,{children:r?.text});case X.Attachment:return(0,I.jsx)(aF,{value:r,maxWidth:e.maxWidth});case X.CodeableConcept:return(0,I.jsx)(iI,{value:r});case X.Coding:return(0,I.jsx)(aI,{value:r});case X.ContactDetail:return(0,I.jsx)(sI,{value:r});case X.ContactPoint:return(0,I.jsx)(oI,{value:r});case X.HumanName:return(0,I.jsx)(dI,{value:r});case X.Identifier:return(0,I.jsx)(fI,{value:r});case X.Money:return(0,I.jsx)(pI,{value:r});case X.Period:return(0,I.jsx)(I.Fragment,{children:xw(r)});case X.Quantity:case X.Duration:return(0,I.jsx)(mI,{value:r});case X.Range:return(0,I.jsx)(hI,{value:r});case X.Ratio:return(0,I.jsx)(gI,{value:r});case X.Reference:return(0,I.jsx)(_I,{value:r,link:e.link});case X.Timing:return(0,I.jsx)(I.Fragment,{children:Tw(r)});case X.Dosage:case X.UsageContext:if(!e.path)throw Error(`Displaying property of type ${e.propertyType} requires path`);return(0,I.jsx)(OI,{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)(uI,{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)(OI,{path:e.path,value:{type:t.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}function TI(e){let[t,n]=(0,b.useState)(!1),r=e.value??``,i=!jC(r),a=`•`.repeat(8);return(0,I.jsxs)(hd,{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)(am,{value:e.value,timeout:2e3,children:({copied:e,copy:t})=>(0,I.jsx)(Xv,{label:e?`Copied`:`Copy secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:e?`teal`:`gray`,onClick:t,"aria-label":e?`Copied`:`Copy secret`,children:e?(0,I.jsx)(mj,{size:`1rem`}):(0,I.jsx)(Sj,{size:`1rem`})})})}),(0,I.jsx)(Xv,{label:t?`Hide secret`:`Show secret`,withArrow:!0,position:`right`,children:(0,I.jsx)(mu,{variant:`subtle`,color:`gray`,onClick:()=>n(!t),"aria-label":t?`Hide secret`:`Show secret`,children:t?(0,I.jsx)(jj,{size:`1rem`}):(0,I.jsx)(Mj,{size:`1rem`})})})]})]})}var EI=[`extension`,`modifierExtension`],DI=BA.filter(e=>!EI.includes(e));function OI(e){let t=e.value,{value:n,type:r}=t,i=(0,b.useContext)(HA),a=e.profileUrl??i?.profileUrl,o=(0,b.useMemo)(()=>xS(r,a),[a,r]),s=(0,b.useMemo)(()=>{if(o)return bO({parentContext:i,elements:o.elements,path:e.path,profileUrl:o.url,accessPolicyResource:e.accessPolicyResource})},[o,i,e.path,e.accessPolicyResource]);if(jC(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 bI(HA.Provider,s,(0,I.jsx)(cF,{compact:e.compact,children:Object.entries(c.elements).map(([n,r])=>{if(EI.includes(n)&&jC(r.slicing?.slices)||DI.includes(n)||VA.includes(n)&&r.path.split(`.`).length===2||n.includes(`.`))return null;let[i,a]=cI(t,n,c.profileUrl);if((e.ignoreMissingValues||r.max===0)&&jC(i)||e.path.endsWith(`.extension`)&&(n===`url`||n===`id`))return null;let o=r.max>1||r.isArray,s=(0,I.jsx)(wI,{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)(lF,{term:Kw(n),children:s},n)})}))}var kI={dimmed:`_dimmed_11me5_1`,preserveBreaks:`_preserveBreaks_11me5_5`},AI=`Read Only`;function jI(e,t){return e?(0,I.jsx)(Xv.Floating,{label:e,children:t}):t}function MI(e){let{debugMode:t}=(0,b.useContext)(HA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,jI(e?.readonly?AI: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)(ld.Wrapper,{id:e.htmlFor,label:n,classNames:{label:e?.readonly?kI.dimmed:void 0},description:e.description,withAsterisk:e.withAsterisk,children:null})})]}))}function NI(e){let{debugMode:t}=(0,b.useContext)(HA),n;return n=t&&e.fhirPath?`${e.title} - ${e.fhirPath}`:e.title,jI(e?.readonly?AI:void 0,(0,I.jsx)(ld.Wrapper,{id:e.htmlFor,label:n,classNames:{label:Mn({[kI.dimmed]:e?.readonly},kI.preserveBreaks)},description:e.description,withAsterisk:e.withAsterisk,error:xF(e.outcome,e.errorExpression??e.htmlFor),"data-testid":e.testId,children:e.children}))}function PI(e,t,n,r,i){let a=r.type;if(a.length>1)for(let n of a){let r=t.replace(`[x]`,ZC(n.code));r in e&&delete e[r]}return e[n]=jC(i)?void 0:i,e}function FI(e){return!!e&&!jC(e.url)&&!jC(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=RI(e);l(t),n&&n(t)}return(0,I.jsx)(wP,{defaultValue:c&&LI(c),onChange:u,withHelpText:r??!0,...s})}function LI(e){return e.coding?.map(e=>({system:e.system,code:e.code,display:e.display}))}function RI(e){if(e.length!==0)return{coding:e.map(e=>({system:e.system,code:e.code,display:e.display}))}}function zI(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&&VI(t);s(r),n&&n(r)}return(0,I.jsx)(wP,{defaultValue:o?BI(o):void 0,maxValues:1,onChange:c,withHelpText:r??!0,...a})}function BI(e){return{system:e.system,code:e.code,display:e.display}}function VI(e){return{system:e.system,code:e.code,display:e.display}}function HI(e){let{path:t,outcome:n}=e,{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(HA),[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)(wg,{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:xF(n,_+`.system`)}),(0,I.jsx)(wg,{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:xF(n,_+`.use`)}),(0,I.jsx)(_b,{disabled:e.disabled||f?.readonly,placeholder:`Value`,defaultValue:a?.value,required:(l?.min??0)>0,onChange:e=>g(e.currentTarget.value),error:xF(n,_+`.value`)})]})}function UI(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(_b,{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)(HI,{disabled:e.disabled||a?.readonly,name:e.name+`-telecom`,path:e.path+`.telecom`,defaultValue:t?.telecom?.[0],onChange:c,outcome:e.outcome})]})}function WI(e){if(!e)return``;let t=new Date(e);return vw(t)?t.toLocaleDateString(`sv`)+`T`+t.toLocaleTimeString(`sv`):``}function GI(e){if(!e)return``;let t=new Date(e);return vw(t)?t.toISOString():``}function KI(e){return(0,I.jsx)(_b,{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:qI(),step:1,defaultValue:WI(e.defaultValue),autoFocus:e.autoFocus,error:xF(e.outcome,e.name),onChange:t=>{if(e.onChange){let n=t.currentTarget.value;e.onChange(GI(n))}}})}function qI(){return`datetime-local`}function JI(e){let{propertyType:t}=e,n=Q(),r=(0,b.useMemo)(()=>{if(MC(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||!CS(r))?(0,I.jsx)(`div`,{children:`Loading...`}):(0,I.jsx)(FL,{profileUrl:r,path:e.path,typeName:`Extension`,defaultValue:e.defaultValue,onChange:e.onChange})}function YI(e){let{outcome:t,path:n}=e,[r,i]=(0,b.useState)(e.defaultValue),{getExtendedProps:a}=(0,b.useContext)(HA),[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)(wg,{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:xF(t,_+`.use`)}),(0,I.jsx)(_b,{disabled:e.disabled||s?.readonly,placeholder:`Prefix`,name:e.name+`-prefix`,defaultValue:r?.prefix?.join(` `),onChange:e=>p(e.currentTarget.value),error:xF(t,_+`.prefix`)}),(0,I.jsx)(_b,{disabled:e.disabled||c?.readonly,placeholder:`Given`,name:e.name+`-given`,defaultValue:r?.given?.join(` `),onChange:e=>m(e.currentTarget.value),error:xF(t,_+`.given`)}),(0,I.jsx)(_b,{disabled:e.disabled||l?.readonly,name:e.name+`-family`,placeholder:`Family`,defaultValue:r?.family,onChange:e=>h(e.currentTarget.value),error:xF(t,_+`.family`)}),(0,I.jsx)(_b,{disabled:e.disabled||u?.readonly,placeholder:`Suffix`,name:e.name+`-suffix`,defaultValue:r?.suffix?.join(` `),onChange:e=>g(e.currentTarget.value),error:xF(t,_+`.suffix`)})]})}function XI(e){let[t,n]=(0,b.useState)(e.defaultValue),{elementsByPath:r,getExtendedProps:i}=(0,b.useContext)(HA),[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)(_b,{disabled:e.disabled||s?.readonly,placeholder:`System`,required:(a?.min??0)>0,defaultValue:t?.system,onChange:e=>l({...t,system:e.currentTarget.value}),error:xF(e.outcome,u+`.system`)}),(0,I.jsx)(_b,{disabled:e.disabled||c?.readonly,placeholder:`Value`,required:(o?.min??0)>0,defaultValue:t?.value,onChange:e=>l({...t,value:e.currentTarget.value}),error:xF(e.outcome,u+`.value`)})]})}var ZI=[`USD`,`EUR`,`CAD`,`GBP`,`AUD`];function QI(e){let{onChange:t}=e,[n,r]=(0,b.useState)(e.defaultValue),{getExtendedProps:i}=(0,b.useContext)(HA),[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)(wg,{disabled:e.disabled||a?.readonly,defaultValue:n?.currency,data:ZI,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:c});return(0,I.jsx)(_b,{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)(Cj,{size:14}),rightSection:u,rightSectionWidth:92,onChange:l})}function $I(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(KI,{disabled:e.disabled||i?.readonly,name:e.name+`.start`,placeholder:`Start`,defaultValue:t?.start,onChange:e=>o({...t,start:e})}),(0,I.jsx)(KI,{disabled:e.disabled||a?.readonly,name:e.name+`.end`,placeholder:`End`,defaultValue:t?.end,onChange:e=>o({...t,end:e})})]})}function eL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(wg,{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)(_b,{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:tL(e.currentTarget.value)})}}),(0,I.jsx)(_b,{disabled:e.disabled||o?.readonly,placeholder:`Unit`,"data-testid":e.name+`-unit`,defaultValue:t?.unit,onChange:e=>s({...t,unit:e.currentTarget.value})})]})}function tL(e){if(e)return Number.parseFloat(e)}function nL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(eL,{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)(eL,{path:e.path+`.high`,disabled:e.disabled||a?.readonly,name:e.name+`-high`,defaultValue:t?.high,onChange:e=>o({...t,high:e})})]})}function rL(e){let[t,n]=(0,b.useState)(e.defaultValue),{getExtendedProps:r}=(0,b.useContext)(HA),[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)(eL,{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)(eL,{path:e.path+`.denominator`,disabled:e.disabled||a?.readonly,name:e.name+`-denominator`,defaultValue:t?.denominator,onChange:e=>o({...t,denominator:e})})]})}var iL={Device:`device-name`,Observation:`code`,Subscription:`criteria`,User:`email:contains`},aL=`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 oL(e){return{value:mC(e)??``,label:vC(e),resource:e}}function sL(e){return iL[e]??(aL.includes(e)?`name`:`_id`)}var cL=(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)(HM,{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})]})]})}));cL.displayName=`DefaultResourceItemComponent`;function lL(e){let t=Q(),{resourceType:n,searchCriteria:r}=e,i=e.itemComponent??cL,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(Qw(e))return Promise.resolve(e);if($w(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=sL(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)(iN,{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:oL,loadOptions:l,onChange:u,clearable:!0})}function uL(e){let t=e.onChange,n=(0,b.useCallback)(e=>{t&&t(e[0])},[t]);return(0,I.jsx)(lL,{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 dL(e){let{onChange:t}=e,n=Q(),[r,i]=(0,b.useState)(e.defaultValue),[a,o]=(0,b.useState)(()=>fL(e.targetTypes)),[s,c]=(0,b.useState)(()=>pL(e.defaultValue,a)),l=(0,b.useRef)(new bx),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(!hL(t))return Promise.resolve(t);e=!0;let r=t.value,i=l.current.get(r);if(i)return i;let a=new UD(mL(n,t.value).then(e=>{let n={...t};return e?MC(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?pC(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)(wg,{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,n=a.find(e=>e.value===t);c(n)},data:f}),!a&&(0,I.jsx)(AP,{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)(uL,{resourceType:s?.resourceType,name:e.name+`-id`,required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:d,disabled:e.disabled})]})]})}function fL(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 pL(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 mL(e,t){let n=wS(t);if(n)return{type:n.type,name:n.name,title:n.title};let r=`{
|
|
201
201
|
StructureDefinitionList(url: "${t}", _sort: "_lastUpdated", _count: 1) {
|
|
202
202
|
type,
|
|
203
203
|
name,
|
|
@@ -205,7 +205,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function Dr({color:e,theme:t,autoContrast:n}){ret
|
|
|
205
205
|
}
|
|
206
206
|
}`.replaceAll(/\s+/g,` `);return(await e.graphql(r)).data.StructureDefinitionList[0]}function hL(e){return e.type===`profile`&&!e?.error&&jC(e.resourceType)}function gL(e,t,n){return t===void 0?e:n===void 0?t:`${t}[${n}]`}var _L={indented:`_indented_ldk1d_1`};function vL({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)(yj,{size:`1.25rem`}),onClick:t,children:r}):(0,I.jsx)(mu,{title:r,color:`green.6`,"data-testid":n,onClick:t,children:(0,I.jsx)(yj,{size:`1.25rem`})})}function yL({propertyDisplayName:e,onClick:t,testId:n}){return(0,I.jsx)(mu,{title:e?`Remove ${e}`:`Remove`,color:`red.5`,"data-testid":n,variant:`subtle`,onClick:t,children:(0,I.jsx)(vj,{size:`1.25rem`})})}function bL(e){let{slice:t,property:n}=e,[r,i]=(0,b.useState)(e.defaultValue),a=t.typeSchema?.elements??t.elements,o=(0,b.useContext)(HA),s=(0,b.useMemo)(()=>{if(MC(a))return bO({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=jC(t.elements),d=qw(t.name),f=e.property.readonly&&r.length===0;return bI(HA.Provider,s,(0,I.jsx)(NI,{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?_L.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)(AL,{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)(yL,{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)(vL,{propertyDisplayName:d,onClick:e=>{AM(e),c([...r,void 0])},testId:e.testId&&`${e.testId}-add`})})]})}))}function xL(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)(HA),d=t.type[0]?.code;(0,b.useEffect)(()=>{yI({medplum:n,property:t}).then(e=>{o(e);let n=vI(s,e,t.slicing,u.profileUrl);SL(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=Kw(t.path),_=e.property.readonly&&a.length===0&&s.length===0;return(0,I.jsxs)(G,{className:e.indent?_L.indented:void 0,children:[_&&(0,I.jsx)(H,{c:`dimmed`,children:`(empty)`}),a.map((n,r)=>(0,I.jsx)(bL,{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)(OL,{arrayElement:!0,property:e.property,name:e.name+`.`+n,path:e.path,valuePath:gL(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)(yL,{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)(vL,{propertyDisplayName:g,onClick:e=>{AM(e);let t=[...m];t.push(void 0),f(t,p)},testId:`nonsliced-add`})})]})}function SL(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 CL(e){let[t,n]=(0,b.useState)(!1),r=jt(),i=(0,b.useRef)(null),a={...e.styles};return t||(a.input||={},a.input.WebkitTextSecurity=`disc`),(0,I.jsxs)(hd,{gap:`xs`,children:[(0,I.jsx)(ih,{...e,styles:{...a,root:{...a.root??{},flexGrow:1}},ref:i,autosize:!0,minRows:1,onFocus:()=>n(!0),onBlur:()=>n(!1)}),(0,I.jsx)(mu,{title:`Copy secret`,onClick:()=>{r.copy(i.current?.value),J({color:`green`,message:`Copied`})},children:(0,I.jsx)(Sj,{})})]})}var wL=[`sun`,`mon`,`tue`,`wed`,`thu`,`fri`,`sat`];function TL(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:Tw(t)||`No repeat`}),(0,I.jsx)(U,{disabled:e.disabled,onClick:()=>i(!0),children:`Edit`})]}),!e.disabled&&(0,I.jsx)(DL,{path:e.path,visible:r,defaultValue:t,onOk:t=>{e.onChange&&e.onChange(t),n(t),i(!1)},onCancel:()=>i(!1)})]})}var EL={repeat:{period:1,periodUnit:`d`}};function DL(e){let[t,n]=(0,b.useState)(e.defaultValue||EL),[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)(HA),[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)(tg,{title:`Timing`,closeButtonProps:{"aria-label":`Close`},opened:e.visible,onClose:()=>e.onCancel(),children:(0,I.jsxs)(G,{gap:`md`,children:[(0,I.jsx)(NI,{title:`Starts on`,htmlFor:`timing-dialog-start`,children:(0,I.jsx)(KI,{disabled:s?.readonly,name:`timing-dialog-start`,onChange:e=>p(e)})}),(0,I.jsx)(Hy,{disabled:c?.readonly,label:`Repeat`,checked:!!t.repeat,onChange:e=>m(e.currentTarget.checked?EL.repeat:void 0)}),t.repeat&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(NI,{title:`Repeat every`,htmlFor:`timing-dialog-period`,children:(0,I.jsxs)(V,{gap:`xs`,grow:!0,wrap:`nowrap`,children:[(0,I.jsx)(_b,{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)(wg,{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)(NI,{title:`Repeat on`,children:(0,I.jsx)(Zp.Group,{multiple:!0,onChange:_,value:t.repeat?.dayOfWeek,children:(0,I.jsx)(V,{justify:`space-between`,mt:`xs`,gap:`xs`,children:wL.map(e=>(0,I.jsx)(Zp,{value:e,size:`xs`,radius:`xl`,disabled:d?.readonly,checked:(t.repeat?.dayOfWeek??[]).includes(e),children:e.charAt(0).toUpperCase()},e))})})}),(0,I.jsx)(NI,{title:`At times`,children:(0,I.jsxs)(G,{mt:`xs`,children:[r.map((e,t)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(_b,{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)(yL,{testId:`timing-repeat-timeOfDay-remove-${t}`,onClick:()=>v(e=>e.toSpliced(t,1))})]},e.id)),(0,I.jsx)(z,{children:(0,I.jsx)(vL,{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 OL(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)(fF,{name:n,defaultValue:i,onChange:r,disabled:t.readonly});let s=o[0]?.code!==X.Extension;return(0,I.jsx)(xL,{property:t,name:n,path:e.path,valuePath:e.valuePath,defaultValue:i,indent:s,onChange:r,outcome:e.outcome})}return o.length>1?(0,I.jsx)(kL,{elementDefinitionTypes:o,...e}):(0,I.jsx)(AL,{name:n,defaultValue:i,onChange:t=>{if(e.onChange){let n=e.name.replace(`[x]`,ZC(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 kL(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)(wg,{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)(AL,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:t=>{e.onChange&&e.onChange(t,e.name.replace(`[x]`,ZC(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 AL(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)(HA),d=(0,b.useMemo)(()=>{if(!QC(l)||!jC(e.defaultValue))return e.defaultValue;let t=Object.create(null);if(u.path===e.path)MO(t,u.elements);else{let n=$C(u.path,e.path);if(n===void 0)return e.defaultValue;MO(t,u.elements,n)}return MC(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(){let n=xF(e.outcome,o??a);return{id:t,name:t,"data-testid":t,defaultValue:d,required:c,error:n,disabled:s}}switch(l){case X.SystemString:case X.canonical:case X.id:case X.string:case X.uri:case X.url:return e.path===`Project.secret.value[x]`||e.path===`ClientApplication.certificateTrustStore`?(0,I.jsx)(CL,{...p(),onChange:t=>{e.onChange&&e.onChange(t.currentTarget.value)}}):(0,I.jsx)(_b,{...p(),onChange:e=>{n&&n(e.currentTarget.value)}});case X.date:return(0,I.jsx)(_b,{...p(),type:`date`,onChange:e=>{n&&n(e.currentTarget.value)}});case X.time:return(0,I.jsx)(_b,{...p(),type:`time`,step:1,onChange:e=>{n&&n(e.currentTarget.value)}});case X.dateTime:case X.instant:return(0,I.jsx)(KI,{...p(),onChange:n,outcome:r});case X.decimal:case X.integer:case X.positiveInt:case X.unsignedInt:return(0,I.jsx)(_b,{...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)(DP,{...p(),error:void 0,onChange:n,binding:i?.valueSet,creatable:!0,maxValues:1});case X.boolean:return(0,I.jsx)(sp,{...p(),defaultChecked:!!d,onChange:e=>{n&&n(e.currentTarget.checked)}});case X.base64Binary:case X.markdown:case X.xhtml:return(0,I.jsx)(ih,{...p(),spellCheck:l!==X.base64Binary,onChange:e=>{n&&n(e.currentTarget.value)}});case X.Address:return(0,I.jsx)(JA,{...f()});case X.Annotation:return(0,I.jsx)(YA,{...f()});case X.Attachment:return(0,I.jsx)(pF,{...f()});case X.CodeableConcept:return(0,I.jsx)(II,{binding:i?.valueSet,...f()});case X.Coding:return(0,I.jsx)(zI,{binding:i?.valueSet,...f()});case X.ContactDetail:return(0,I.jsx)(UI,{...f()});case X.ContactPoint:return(0,I.jsx)(HI,{...f()});case X.Extension:return(0,I.jsx)(JI,{...f(),propertyType:e.elementDefinitionType});case X.HumanName:return(0,I.jsx)(YI,{...f()});case X.Identifier:return(0,I.jsx)(XI,{...f()});case X.Money:return(0,I.jsx)(QI,{...f()});case X.Period:return(0,I.jsx)($I,{...f()});case X.Duration:case X.Quantity:return(0,I.jsx)(eL,{...f()});case X.Range:return(0,I.jsx)(nL,{...f()});case X.Ratio:return(0,I.jsx)(rL,{...f()});case X.Reference:return(0,I.jsx)(dL,{...f(),targetTypes:ML(e.elementDefinitionType)});case X.Timing:return(0,I.jsx)(TL,{...f()});case X.Dosage:case X.UsageContext:default:return(0,I.jsx)(FL,{...f(),typeName:l})}}var jL=[`${Ex}/fhir/StructureDefinition/`,`https://medplum.com/fhir/StructureDefinition/`];function ML(e){return e?.targetProfile?.map(e=>{let t=jL.find(t=>e.startsWith(t));return t?e.slice(t.length):e})}function NL(e){let[t,n]=(0,b.useState)(e.defaultValue??{}),r=(0,b.useContext)(HA),i=(0,b.useMemo)(()=>GA(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]=lI(o,n,r),c=r.min!==void 0&&r.min>0,l=e.valuePath?e.valuePath+`.`+n:void 0,u=(0,I.jsx)(OL,{property:r,name:n,path:e.path+`.`+n,valuePath:l,defaultValue:i,defaultPropertyType:s,onChange:(e,i)=>{a(PI({...t},n,i??n,r,e))},outcome:e.outcome},n);return e.type===`Extension`||UA.includes(n)?u:r.type.length===1&&r.type[0].code===`boolean`?(0,I.jsx)(MI,{title:Kw(n),description:r.description,htmlFor:n,fhirPath:r.path,withAsterisk:c,readonly:r.readonly,children:u},n):(0,I.jsx)(NI,{title:Kw(n),description:r.description,withAsterisk:c,htmlFor:n,outcome:e.outcome,fhirPath:r.path,errorExpression:l,readonly:r.readonly,children:u},n)})})}var PL={nested:`_nested_1ya4k_1`};function FL(e){let[t]=(0,b.useState)(()=>e.defaultValue??{}),n=(0,b.useContext)(HA),r=e.profileUrl??n?.profileUrl,i=(0,b.useMemo)(()=>xS(e.typeName,r),[e.typeName,r]),a=i?.type??e.typeName,o=(0,b.useMemo)(()=>{if(i)return bO({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 bI(HA.Provider,o,(0,I.jsx)(z,{className:Mn({[PL.nested]:s}),children:(0,I.jsx)(NL,{path:e.path,valuePath:e.valuePath,type:a,defaultValue:t,onChange:e.onChange,outcome:e.outcome})}))}var IL={modal:`_modal_jifq4_2`,content:`_content_jifq4_9`,header:`_header_jifq4_15`,title:`_title_jifq4_24`,body:`_body_jifq4_29`,scroll:`_scroll_jifq4_38`,footer:`_footer_jifq4_47`},LL={display:`flex`,flexDirection:`column`,flex:`1 1 auto`,minHeight:0};function RL(e){let{children:t,actions:n,onSubmit:r,bodyHeight:i,classNames:a,style:o,closeButtonProps:s,centered:c=!0,padding:l=`lg`,radius:u=`md`,...d}=e,f=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:IL.scroll,children:t}),n&&(0,I.jsx)(`div`,{className:IL.footer,children:n})]});return(0,I.jsx)(tg,{...d,centered:c,padding:l,radius:u,closeButtonProps:{"aria-label":`Close`,radius:`xl`,...s},classNames:{...a,root:Mn(IL.modal,a?.root),content:Mn(IL.content,a?.content),header:Mn(IL.header,a?.header),title:Mn(IL.title,a?.title),body:Mn(IL.body,a?.body)},style:i?[o,{"--medplum-modal-body-height":i}]:o,children:r?(0,I.jsx)(hP,{onSubmit:r,style:LL,children:f}):f})}var zL={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 BL(e){let{status:t,...n}=e;return(0,I.jsx)(Ap,{color:e.color||zL[t],...n,children:t.replaceAll(`-`,` `)})}var VL={noteBody:`_noteBody_10swh_1`,noteCite:`_noteCite_10swh_5`,noteRoot:`_noteRoot_10swh_10`};function HL({value:e}){return e?(0,I.jsx)(G,{justify:`flex-start`,gap:`xs`,children:e.map(e=>e.text&&(0,I.jsx)(Pp,{classNames:{cite:VL.noteCite,root:VL.noteRoot},cite:e.authorReference?.display||e.authorString,icon:null,children:e.text},`note-${e.text}`))}):null}function UL(e){let{value:t,link:n,...r}=e,[i,a]=(0,b.useState)(),o=Rk(t,a),s;if(i&&!tS(i))s=`[${Y(i)}]`;else if(o)s=vC(o);else return null;return n?(0,I.jsx)(IM,{to:t,...r,children:s}):(0,I.jsx)(H,{component:`span`,...r,children:s})}function WL(e){return(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(HM,{size:24,radius:12,value:e.value,link:e.link}),(0,I.jsx)(UL,{value:e.value,link:e.link})]})}var GL={table:`_table_15n6u_1`,groupHeaderRow:`_groupHeaderRow_15n6u_16`,criticalRow:`_criticalRow_15n6u_21`,noteBody:`_noteBody_15n6u_32`,noteCite:`_noteCite_15n6u_36`,noteRoot:`_noteRoot_15n6u_41`};KL.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1,hideSubject:!1};function KL(e){let t=Q(),n=Rk(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)(qL,{value:n,hideSubject:e.hideSubject}),r&&!e.hideSpecimenInfo&&XL(r),n.result&&(0,I.jsx)(ZL,{hideObservationNotes:e.hideObservationNotes,value:n.result}),a.length>0&&(0,I.jsx)(HL,{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})]}),(0,I.jsx)(oR,{value:n})]})}function qL({value:e,hideSubject:t=!1}){let n=Rk(e.basedOn?.[0]),r=n?.resourceType===`ServiceRequest`?n.requester:void 0,i=!!(e.subject&&!t),a=i||!!r||!!e.resultsInterpreter?.length,o=!!(e.performer?.length||e.issued||e.status);return(0,I.jsxs)(V,{mt:`md`,gap:`xl`,align:`stretch`,wrap:`nowrap`,children:[a&&(0,I.jsxs)(G,{gap:`md`,style:{flex:1},children:[i&&(0,I.jsx)(JL,{label:`Subject`,children:(0,I.jsx)(WL,{value:e.subject,link:!0})}),r&&(0,I.jsx)(JL,{label:`Ordering`,children:(0,I.jsx)(WL,{value:r,link:!0})}),e.resultsInterpreter?.map(e=>(0,I.jsx)(JL,{label:`Interpreter`,children:(0,I.jsx)(WL,{value:e,link:!0})},e.reference))]}),a&&o&&(0,I.jsx)(lm,{orientation:`vertical`}),o&&(0,I.jsxs)(G,{gap:`md`,style:{flex:1},children:[e.performer?.map(e=>(0,I.jsx)(JL,{label:`Performer`,children:(0,I.jsx)(YL,{value:e})},e.reference)),e.issued&&(0,I.jsx)(JL,{label:`Issued`,children:(0,I.jsx)(H,{children:bw(e.issued)})}),e.status&&(0,I.jsx)(JL,{label:`Status`,children:(0,I.jsx)(BL,{status:e.status})})]})]})}function JL({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 YL({value:e}){let t=Rk(e),n=t?.resourceType===`Organization`?t.address?.[0]:void 0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(WL,{value:e,link:!0}),n&&(0,I.jsx)(H,{size:`sm`,c:`dimmed`,mt:4,ml:34,children:(0,I.jsx)(zA,{value:n})})]})}function XL(e){return(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsx)(q,{order:2,size:`h6`,children:`Specimens`}),(0,I.jsx)(_h,{type:`ordered`,children:e?.map(e=>(0,I.jsx)(_h.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:`}),` `,bw(e.collection?.collectedDateTime)]}),(0,I.jsxs)(V,{gap:5,children:[(0,I.jsx)(H,{fw:500,children:`Received:`}),` `,bw(e.receivedTime)]})]})},`specimen-${e.id}`))})]})}function ZL(e){return(0,I.jsxs)(`table`,{className:GL.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)(QL,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function QL(e){return(0,I.jsx)(I.Fragment,{children:e.value?.map(t=>(0,I.jsx)($L,{value:t,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${$w(t)?t.reference:t.id}`))})}function $L(e){let t=Rk(e.value);if(!t||e.ancestorIds?.includes(t.id))return null;let n=!e.hideObservationNotes&&t.note,r=aR(t),i=e.ancestorIds?.length??0,a=t.hasMember&&(0,I.jsx)(QL,{value:t.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,t.id]:[t.id],hideObservationNotes:e.hideObservationNotes});return iR(t)?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`tr`,{className:GL.groupHeaderRow,children:(0,I.jsx)(`td`,{colSpan:7,style:rR(i),children:(0,I.jsxs)(V,{gap:`sm`,children:[(0,I.jsx)(IM,{to:t,children:(0,I.jsx)(iI,{value:t.code})}),t.effectiveDateTime&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,fw:400,children:[`Collected: `,bw(t.effectiveDateTime)]})]})})}),n&&(0,I.jsx)(`tr`,{children:(0,I.jsx)(`td`,{colSpan:7,style:rR(i+1),children:(0,I.jsx)(HL,{value:t.note})})}),a]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`tr`,{className:Mn({[GL.criticalRow]:r}),children:[(0,I.jsx)(`td`,{rowSpan:n?2:1,style:rR(i),children:(0,I.jsx)(IM,{to:t,children:(0,I.jsx)(iI,{value:t.code})})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(tR,{value:t})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(nR,{value:t.referenceRange})}),(0,I.jsx)(`td`,{children:t.interpretation&&t.interpretation.length>0&&(0,I.jsx)(iI,{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)(iI,{value:e})},`category-${Aw(e)}`))})}),(0,I.jsx)(`td`,{children:t.performer?.map(e=>(0,I.jsx)(eR,{value:e},e.reference))}),(0,I.jsx)(`td`,{children:t.status&&(0,I.jsx)(BL,{status:t.status})})]}),a,n&&(0,I.jsx)(`tr`,{children:(0,I.jsx)(`td`,{colSpan:6,children:(0,I.jsx)(HL,{value:t.note})})})]})}function eR(e){let t=Rk(e.value);return t?(0,I.jsx)(IM,{to:e.value,children:vC(t)}):(0,I.jsx)(_I,{value:e.value})}function tR(e){let t=e.value;return(0,I.jsx)(I.Fragment,{children:Mw(t)})}function nR(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)(hI,{value:t}):null}function rR(e){return e>0?{paddingInlineStart:`calc(4px + ${e} * var(--mantine-spacing-md))`}:void 0}function iR(e){return e.hasMember?.length?!(Mw(e)||e.dataAbsentReason||e.interpretation?.length||e.referenceRange?.length):!1}function aR(e){let t=e.interpretation?.[0]?.coding?.[0]?.code;if(t!==void 0)return t===`AA`||t===`LL`||t===`HH`||t===`A`;let n=e.interpretation?.[0].text;return n===`Critical abnormal`||n===`Critical high`||n===`Critical low`||n===`Critical`||n===`Abnormal`}function oR({value:e}){let t=Q(),[n,r]=(0,b.useState)();return(0,b.useEffect)(()=>{cR(t,e).then(r).catch(console.error)},[t,e]),!n||n.length===0?null:(0,I.jsxs)(G,{gap:`xs`,mt:`md`,children:[(0,I.jsx)(lm,{}),(0,I.jsx)(H,{fw:500,size:`sm`,c:`dimmed`,children:`Performing Labs`}),n.map(e=>(0,I.jsxs)(V,{justify:`space-between`,align:`flex-start`,wrap:`nowrap`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(H,{children:e.name}),e.address?.[0]&&(0,I.jsx)(H,{size:`sm`,c:`dimmed`,children:(0,I.jsx)(zA,{value:e.address[0]})})]}),(0,I.jsx)(sR,{value:e.contact?.[0]})]},`lab-${e.id}-${e.name}`))]})}function sR({value:e}){return e?(0,I.jsxs)(`div`,{style:{textAlign:`right`},children:[e.name&&(0,I.jsx)(H,{children:e.name.text??_w(e.name)}),e.telecom?.[0]&&(0,I.jsx)(H,{size:`sm`,c:`dimmed`,children:(0,I.jsx)(oI,{value:e.telecom[0]})})]}):null}async function cR(e,t){let n=[],r=new Set;async function i(a){let o=a.reference;if(!o||r.has(o))return;r.add(o);let s=o.startsWith(`#`)?lR(t,o,`Observation`):await e.readReference(a).catch(()=>void 0);if(s){n.push(s);for(let e of s.hasMember??[])await i(e)}}for(let e of t.result??[])await i(e);let a=new Map;for(let r of n.flatMap(e=>e.performer??[])){let n=r.reference,i;if(n?.startsWith(`#`)?i=lR(t,n,`Organization`):n?.startsWith(`Organization/`)&&(i=await e.readReference(r).catch(()=>void 0)),i&&(i.address||i.contact)){let e=`${i.name}|${gw(i.address?.[0])}`;a.has(e)||a.set(e,i)}}return Array.from(a.values())}function lR(e,t,n){let r=t.slice(1);return e.contained?.find(e=>e.resourceType===n&&e.id===r)}function uR(e,t){e.sort((e,n)=>{let r=dR(e,t),i=dR(n,t);return r>i?1:r<i?-1:fR(e,t)-fR(n,t)})}function dR(e,t){if(!pR(e,t)){let t=e.priority;if(typeof t==`string`)return{stat:4,asap:3,urgent:2}[t]??0}return 0}function fR(e,t){if(!pR(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 pR(e,t){return!!t&&e.resourceType===t.resourceType&&e.id===t.id}var mR={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function hR(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:mR.removed,children:i&&(0,I.jsx)(wI,{path:n,property:r,propertyType:i.type,value:i.value,ignoreMissingValues:!0})}),(0,I.jsx)(K.Td,{className:mR.added,children:a&&(0,I.jsx)(wI,{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 gR={root:`_root_15xvr_1`,removed:`_removed_15xvr_20`,added:`_added_15xvr_25`};function _R(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=[zS(n)],t=[zS(r)],a=[],o=vR($O(n,r));for(let r of o){let i=r.path,o=yR(i),s=bR(n.resourceType,o),c=r.op===`add`?void 0:XT(o,e),l=r.op===`remove`?void 0:XT(o,t);a.push({key:`op-${r.op}-${r.path}`,name:`${ZC(r.op)} ${o}`,path:s?.path??n.resourceType+`.`+o,property:s,originalValue:xR(s,c),revisedValue:xR(s,l)})}return a},[i,n,r]);return o?(0,I.jsxs)(K,{className:gR.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)(hR,{...n},t)})})]}):null}function vR(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 yR(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 bR(e,t){try{return rk(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 xR(e,t){return t&&{type:Array.isArray(t)?t[0].type:t.type,value:SR(t,!!e?.isArray)}}function SR(e,t){let n=Tx(e).flatMap(e=>e.value);return t?n:n[0]}function CR(e){let{profileUrl:t}=e,n=Q(),r=n.getAccessPolicy(),i=Rk(e.value),[a,o]=(0,b.useState)(!1);(0,b.useEffect)(()=>{if(i){if(t)n.requestProfileSchema(t,{expandProfile:!0}).then(()=>{wS(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&&WE(i,BE.READ,r),[r,i]);return!a||!i?null:(0,I.jsx)(OI,{path:i.resourceType,value:{type:i.resourceType,value:e.forceUseInput?e.value:i},profileUrl:t,ignoreMissingValues:e.ignoreMissingValues,accessPolicyResource:s})}var wR={item:`_item_5q6yx_1`,itemPadding:`_itemPadding_5q6yx_5`};function TR(e){return(0,I.jsx)(hF,{children:e.children})}function ER(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)(_F,{"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)(HM,{value:o,link:!0,size:`md`}),(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsxs)(H,{size:`sm`,children:[(0,I.jsx)(UL,{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)(UL,{c:`inherit`,value:s,link:!0})]})]}),(0,I.jsxs)(H,{size:`xs`,children:[(0,I.jsx)(IM,{c:`dimmed`,to:e.resource,children:bw(c)}),(0,I.jsx)(H,{component:`span`,c:`dimmed`,mx:8,children:`·`}),(0,I.jsx)(IM,{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)(mu,{color:`gray`,variant:`subtle`,radius:`xl`,"aria-label":`Actions for ${mC(e.resource)}`,children:(0,I.jsx)(Dj,{})})}),i]})]}),(0,I.jsx)(EM,{children:(0,I.jsx)(`div`,{className:Mn(wR.item,{[wR.itemPadding]:r}),children:e.children})})]})}var DR={pinnedComment:`_pinnedComment_u08s5_1`};function OR(e){let t=Q(),n=t.getProfile(),r=(0,b.useRef)(null),i=Rk(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=>{uR(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(()=>Pb({id:`upload-notification`,color:`teal`,title:`Upload complete`,message:``,icon:(0,I.jsx)(mj,{size:16}),autoClose:2e3})).catch(e=>Pb({id:`upload-notification`,color:`red`,title:`Upload error`,message:Y(e),icon:(0,I.jsx)(Nj,{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){Pb({id:`upload-notification`,loading:!0,title:`Uploading...`,message:FR(e),autoClose:!1,withCloseButton:!1})}function S(e){Pb({id:`upload-notification`,color:`red`,title:`Upload error`,message:Y(e),icon:(0,I.jsx)(Nj,{size:16}),autoClose:2e3})}if(!i)return(0,I.jsx)(Wp,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(ou,{})});let C=s.filter(e=>e).slice(0,l);return(0,I.jsxs)(TR,{children:[e.createCommunication&&(0,I.jsx)(_F,{children:(0,I.jsx)(hP,{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)(HM,{value:n}),(0,I.jsx)(_b,{name:`text`,ref:r,placeholder:`Add comment`,style:{width:`100%`,maxWidth:300}}),(0,I.jsx)(mu,{type:`submit`,radius:`xl`,color:`blue`,variant:`filled`,children:(0,I.jsx)(qj,{size:16})}),(0,I.jsx)(dF,{securityContext:pC(i),onUpload:v,onUploadStart:y,onUploadProgress:x,onUploadError:S,children:e=>(0,I.jsx)(mu,{...e,radius:`xl`,color:`blue`,variant:`filled`,children:(0,I.jsx)(bj,{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)(kR,{history:a,resource:t,popupMenuItems:r},n);switch(t.resourceType){case`AuditEvent`:return(0,I.jsx)(NR,{resource:t,popupMenuItems:r},n);case`Communication`:return(0,I.jsx)(jR,{resource:t,popupMenuItems:r},n);case`DiagnosticReport`:return(0,I.jsx)(PR,{resource:t,popupMenuItems:r},n);case`Media`:return(0,I.jsx)(MR,{resource:t,popupMenuItems:r},n);default:return(0,I.jsx)(ER,{resource:t,padding:!0,children:(0,I.jsx)(CR,{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 kR(e){let{history:t,resource:n,...r}=e,i=AR(t,n);return i?(0,I.jsx)(ER,{resource:n,padding:!0,...r,children:(0,I.jsx)(_R,{original:i,revised:e.resource})}):(0,I.jsxs)(ER,{resource:n,padding:!0,...r,children:[(0,I.jsx)(`h3`,{children:`Created`}),(0,I.jsx)(CR,{value:n,ignoreMissingValues:!0,forceUseInput:!0})]})}function AR(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 jR(e){let t=!e.resource.priority||e.resource.priority===`routine`?void 0:DR.pinnedComment;return(0,I.jsx)(ER,{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 MR(e){let t=e.resource.content?.contentType,n=t&&!t.startsWith(`image/`)&&!t.startsWith(`video/`)&&t!==`application/pdf`;return(0,I.jsx)(ER,{resource:e.resource,padding:!!n,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(aF,{value:e.resource.content})})}function NR(e){return(0,I.jsx)(ER,{resource:e.resource,padding:!0,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(cl,{children:(0,I.jsx)(`pre`,{children:e.resource.outcomeDesc})})})}function PR(e){return(0,I.jsx)(ER,{resource:e.resource,padding:!0,popupMenuItems:e.popupMenuItems,children:(0,I.jsx)(KL,{value:e.resource})})}function FR(e){if(e.lengthComputable){let t=100*e.loaded/e.total;return`Uploaded: ${IR(e.loaded)} / ${IR(e.total)} ${t.toFixed(2)}%`}return`Uploaded: ${IR(e.loaded)}`}function IR(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 LR(e){let{resource:t,...n}=e;return(0,I.jsx)(OR,{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 RR(e){let{encounter:t,...n}=e;return(0,I.jsx)(OR,{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:pC(e),subject:e.subject,sender:pC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,encounter:pC(e),subject:e.subject,operator:pC(t),issued:new Date().toISOString(),content:n}),...n})}function zR(e){let t;try{t=YT(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. \
|
|
207
207
|
Received ${t.length} elements \
|
|
208
|
-
[${JSON.stringify(t,null,2)}]`);return(0,I.jsx)(wI,{value:t[0]||``,propertyType:e.propertyType})}function BR(e){let t=e.exportCsv||e.exportTransactionBundle?(0,I.jsxs)(I.Fragment,{children:[e.exportCsv&&(0,I.jsx)(VR,{text:`CSV`,exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,I.jsx)(VR,{text:`Transaction Bundle`,exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}):void 0;return(0,I.jsx)(RL,{title:`Export`,opened:e.visible,onClose:e.onCancel,actions:t,children:(0,I.jsx)(H,{children:`Limited to 1000 records`})})}function VR(e){return(0,I.jsx)(U,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var HR={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]},UR={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 WR(e,t){return{...e,filters:t,offset:0,name:void 0}}function GR(e,t){return WR(e,(e.filters??[]).filter(e=>e.code!==t))}function KR(e,t,n,r,i){i&&(e=GR(e,t));let a=[];return e.filters&&a.push(...e.filters),a.push({code:t,operator:n,value:r??``}),WR(e,a)}function qR(e,t){if(!e.filters)return e;let n=[...e.filters];return n.splice(t,1),{...e,filters:n,name:void 0}}function JR(e,t){return ZR(e,t,-1)}function YR(e,t){return ZR(e,t,0)}function XR(e,t){return ZR(e,t,1)}function ZR(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),iz(e,t,r,i)}function QR(e,t){let n=new Date;return iz(e,t,n,new Date(n.getTime()+864e5))}function $R(e,t){return nz(e,t,-1)}function ez(e,t){return nz(e,t,0)}function tz(e,t){return nz(e,t,1)}function nz(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),iz(e,t,r,i)}function rz(e,t){let n=new Date;return n.setMonth(0),n.setDate(1),n.setHours(0,0,0,0),iz(e,t,n,new Date)}function iz(e,t,n,r){return e=GR(e,t),e=az(e,t,Z.GREATER_THAN_OR_EQUALS,n),e=az(e,t,Z.LESS_THAN_OR_EQUALS,r),e}function az(e,t,n,r){return KR(e,t,n,r.toISOString())}function oz(e,t,n=!0){return KR(e,t,Z.MISSING,n.toString())}function sz(e,t){return e.offset===t?e:{...e,offset:t,name:void 0}}function cz(e,t){let n=e.count??20;return sz(e,(t-1)*n)}function lz(e,t,n){return t===uz(e)&&n!==void 0&&n===dz(e)?e:{...e,sortRules:[{code:t,descending:!!n}],name:void 0}}function uz(e){let t=e.sortRules;if(!t||t.length===0)return;let n=t[0].code;return n.startsWith(`-`)?n.substr(1):n}function dz(e){let t=e.sortRules;return!t||t.length===0?!1:!!t[0].descending}function fz(e){return HR[e.type]}function pz(e){return UR[e]??``}function mz(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(ZC).join(` `))}function hz(e){return e.startsWith(`_`)}function gz(e){return hz(e)?e:mz(e)}function _z(e,t){let n=t.name;return n===`id`?(0,I.jsx)(IM,{to:`/${e.resourceType}/${e.id}`,children:e.id}):n===`meta.versionId`?e.meta?.versionId:n===`_lastUpdated`?bw(e.meta?.lastUpdated):`${e.resourceType}.${t.name}`===t.elementDefinition?.path?vz(e,t.elementDefinition):t.searchParams?.length===1&&t.name===t.searchParams[0].code?yz(e,t.searchParams[0]):null}function vz(e,t){let n=t.path?.split(`.`)?.pop()?.replaceAll(`[x]`,``)??``,[r,i]=cI({type:e.resourceType,value:e},n);return r?(0,I.jsx)(wI,{path:t.path,property:t,propertyType:i,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function yz(e,t){let n=XT(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)(wI,{propertyType:e.type,value:e.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${t}-${n.length}`))})}function bz(e){let t=(0,b.useRef)(!1),[n,r]=(0,b.useState)({search:JSON.parse(DC(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 aw(xz(SS(t),Ww(t))).map(e=>({value:e,label:mz(e)}))},[e.visible,e.search.resourceType]);function s(e){r({search:{...n.search,fields:e}})}return(0,I.jsx)(RL,{title:`Fields`,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`})},actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{onClick:()=>e.onOk(n.search),children:`OK`})}),children:(0,I.jsx)(bg,{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})})}function xz(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(mz(t));if(t)for(let e of Object.keys(t)){let t=mz(e);!r.has(e)&&!i.has(t)&&(n.push(e),r.add(e),i.add(t))}return n}function Sz(e){let t=rk(e.resourceType,e.searchParam),n=e.name??`filter-value`;switch(t.type){case nk.REFERENCE:return(0,I.jsx)(dL,{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 nk.BOOLEAN:return(0,I.jsx)(sp,{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 nk.DATE:return(0,I.jsx)(_b,{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 nk.DATETIME:return(0,I.jsx)(KI,{name:n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case nk.NUMBER:return(0,I.jsx)(_b,{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 nk.QUANTITY:return(0,I.jsx)(eL,{name:n,path:``,defaultValue:Cz(e.defaultValue),autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(`${t.value}`):e.onChange(``)}});default:return(0,I.jsx)(_b,{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 Cz(e){if(e){let[t,n,r]=e.split(`|`);if(t)return{value:Number.parseFloat(t),system:n,unit:r}}}function wz(e){let[t,n]=(0,b.useState)(BC(e.search)),r=(0,b.useRef)(t);(0,b.useLayoutEffect)(()=>{r.current=t}),(0,b.useEffect)(()=>{n(BC(e.search))},[e.search]);function i(e){n(KR(r.current,e.code,e.operator,e.value))}let a=e.search.resourceType,o=Ww(a)??{},s=t.filters||[];return(0,I.jsxs)(RL,{title:`Filters`,size:900,opened:e.visible,onClose:e.onCancel,onSubmit:()=>e.onOk(r.current),actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`OK`})}),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)(Tz,{id:`filter-${t}-row`,resourceType:a,searchParams:o,value:e,onChange:e=>{let i=[...s];i[t]=e,n(WR(r.current,i))},onDelete:()=>n(qR(r.current,t))},`filter-${t}-row`))})]}),(0,I.jsx)(vL,{propertyDisplayName:`Filter`,onClick:()=>i({})})]})}function Tz(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&&fz(a),s=[],c=[];for(let t of Object.keys(e.searchParams)){let e={value:t,label:gz(t)};hz(t)?c.push(e):s.push(e)}return(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(wg,{"data-testid":`${e.id}-filter-field`,defaultValue:e.value.code,onChange:e=>n(e.currentTarget.value),data:[``,...s.length>0?[{group:`Fields`,items:s}]:[],...c.length>0?[{group:`Metadata`,items:c}]:[]]})}),(0,I.jsx)(`td`,{children:o&&(0,I.jsx)(wg,{"data-testid":`${e.id}-filter-operation`,defaultValue:t.operator,onChange:e=>r(e.currentTarget.value),data:[``,...o.map(e=>({value:e,label:pz(e)}))]},`${e.id}-filter-value-${e.value.code}`)}),(0,I.jsx)(`td`,{children:a&&t.operator&&(0,I.jsx)(Sz,{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)(mu,{variant:`outline`,color:`red`,radius:`xl`,"aria-label":`Delete filter`,onClick:e.onDelete,children:(0,I.jsx)(wM,{style:{width:`70%`,height:`70%`},stroke:1.5})})})]})}function Ez(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)(RL,{title:e.title,size:`xl`,opened:e.visible,onClose:e.onCancel,onSubmit:r,actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`OK`})}),children:(0,I.jsx)(Sz,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:t,autoFocus:!0,onChange:n})})}function Dz(e){let{resourceType:t,filter:n}=e,r=eT.types[t].searchParams?.[n.code];if(r){if(r.type===`reference`&&(n.operator===Z.EQUALS||n.operator===Z.NOT_EQUALS))return(0,I.jsx)(UL,{value:{reference:n.value}});let e=rk(t,r);if(n.code===`_lastUpdated`||e.type===nk.DATETIME)return(0,I.jsx)(I.Fragment,{children:bw(n.value)})}return(0,I.jsx)(I.Fragment,{children:n.value})}function Oz(e){if(!e.searchParams)return null;function t(t,n){i(lz(e.search,t.code,n))}function n(t){i(GR(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)(kz,{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:mz(e.code)},e.code))})}function kz(e){switch(e.searchParam.type){case`date`:return(0,I.jsx)(Az,{...e});case`number`:case`quantity`:return(0,I.jsx)(jz,{...e});case`reference`:return(0,I.jsx)(Mz,{...e});case`string`:return(0,I.jsx)(Nz,{...e});case`token`:return(0,I.jsx)(Pz,{...e});case`uri`:return(0,I.jsx)(Fz,{...e});default:return(0,I.jsxs)(I.Fragment,{children:[`Unknown search param type: `,e.searchParam.type]})}}function Az(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Oldest to Newest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Kj,{size:14}),onClick:()=>e.onPrompt(t,Z.ENDS_BEFORE),children:`Before...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Gj,{size:14}),onClick:()=>e.onPrompt(t,Z.STARTS_AFTER),children:`After...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(sj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Between...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(XR(e.search,n)),children:`Tomorrow`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(YR(e.search,n)),children:`Today`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(JR(e.search,n)),children:`Yesterday`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(QR(e.search,n)),children:`Next 24 Hours`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(tz(e.search,n)),children:`Next Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(ez(e.search,n)),children:`This Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange($R(e.search,n)),children:`Last Month`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(rz(e.search,n)),children:`Year to date`}),(0,I.jsx)(Iz,{...e})]})}function jz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Smallest to Largest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Gj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN),children:`Greater than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uM,{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)(Kj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN),children:`Less than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uM,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN_OR_EQUALS),children:`Less than or equal to...`}),(0,I.jsx)(Iz,{...e})]})}function Mz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(Iz,{...e})]})}function Nz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort A to Z`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(dj,{size:14}),onClick:()=>e.onPrompt(t,Z.CONTAINS),children:`Contains...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Does not contain...`}),(0,I.jsx)(Iz,{...e})]})}function Pz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.TEXT),children:`Text contains...`}),(0,I.jsx)(Iz,{...e})]})}function Fz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(Iz,{...e})]})}function Iz(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)(rj,{size:14}),onClick:()=>e.onChange(oz(e.search,n)),children:`Missing`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(nj,{size:14}),onClick:()=>e.onChange(oz(e.search,n,!1)),children:`Not missing`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(wM,{size:14}),onClick:()=>e.onClear(t),children:`Clear filters`})]})}function Lz(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 Rz={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 zz(e){let t=e.resourceType,n=[];for(let r of e.fields||[`id`,`_lastUpdated`])n.push(Bz(t,r));return n}function Bz(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=Xw(e,t),r=Gw(e,t.toLowerCase());if(n&&r)return{name:t,elementDefinition:n,searchParams:[r]};if(n){let r=Ww(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:rk(e,r).elementDefinitions?.[0],searchParams:[r]}:{name:t}}var Vz=class extends Event{definition;constructor(e){super(`change`),this.definition=e}},Hz=class extends Event{response;constructor(e){super(`load`),this.response=e}},Uz=class extends Event{resource;browserEvent;constructor(e,t){super(`click`),this.resource=e,this.browserEvent=t}};function Wz(e){let t=Q(),[n,r]=(0,b.useState)(),{search:i,onLoad:a}=e,[o,s]=(0,b.useState)(i);PC(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,bE({...o,total:d,fields:void 0}),e)).then(e=>{l({...u.current,searchResponse:e}),a&&a(new Hz(e))}).catch(e=>{l({...u.current,searchResponse:void 0}),r(aS(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 Vz(t))}function v(t,n){if(MM(t.target)||t.button===2)return;AM(t);let r=jM(t);!r&&e.onClick&&e.onClick(new Uz(n,t)),r&&e.onAuxClick&&e.onAuxClick(new Uz(n,t))}function y(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(n)return(0,I.jsx)(VF,{outcome:n});if(!bS(o.resourceType))return(0,I.jsx)(Wp,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(ou,{})});let x=e.checkboxesEnabled,S=zz(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:Rz.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)(xj,{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)(Fj,{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)(Pj,{size:16}),onClick:e.onNew,children:`New...`}),!O&&y()&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(_M,{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)(bM,{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)(oj,{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:[Jz(o,w).toLocaleString(),`-`,Yz(o,w).toLocaleString(),w.total!==void 0&&` of ${o.total===`estimate`?`~`:``}${w.total?.toLocaleString()}`]}),(0,I.jsx)(mu,{variant:E,color:D,title:`Refresh`,onClick:p,children:(0,I.jsx)(aM,{size:16})})]})]}),(0,I.jsxs)(K,{className:Rz.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)(fl,{className:Rz.control,p:2,children:(0,I.jsxs)(V,{justify:`space-between`,wrap:`nowrap`,children:[(0,I.jsx)(H,{fw:500,children:mz(e.name)}),(0,I.jsx)(Wp,{className:Rz.icon,children:(0,I.jsx)(ZA,{size:14,stroke:1.5})})]})})}),(0,I.jsx)(Oz,{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.additionalColumns?.map(e=>(0,I.jsx)(K.Th,{children:(0,I.jsx)(H,{fw:500,p:2,children:e.name})},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)(Gz,{resourceType:C,searchParams:e.searchParams,filters:o.filters})},e.name)),e.additionalColumns?.map(e=>(0,I.jsx)(K.Th,{},e.name))]})]}),(0,I.jsx)(K.Tbody,{children:T?.map(t=>t&&(0,I.jsxs)(K.Tr,{className:Rz.tr,"data-testid":`search-control-row`,onClick:e=>v(e,t),onAuxClick:e=>v(e,t),children:[x&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${t.id}`,checked:!!c.selected[t.id],onChange:e=>m(e,t.id)})}),S.map(e=>(0,I.jsx)(K.Td,{children:_z(t,e)},e.name)),e.additionalColumns?.map(e=>(0,I.jsx)(K.Td,{children:e.renderCell(t)},e.name))]},t.id))})]}),!T?.length&&(0,I.jsx)(hF,{children:(0,I.jsx)(Wp,{style:{height:150},children:(0,I.jsx)(H,{size:`xl`,c:`dimmed`,children:`No results`})})}),w&&(0,I.jsx)(Wp,{m:`md`,p:`md`,children:(0,I.jsx)(tv,{value:Kz(o),total:qz(o,w),onChange:e=>_(cz(o,e)),getControlProps:Lz})}),(0,I.jsx)(bz,{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)(wz,{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)(BR,{visible:c.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{l({...u.current,exportDialogVisible:!1})}},`search-export-dialog-${c.dialogOpenTime}`),(0,I.jsx)(Ez,{visible:c.filterDialogVisible,title:c.filterDialogSearchParam?.code?mz(c.filterDialogSearchParam.code):``,resourceType:C,searchParam:c.filterDialogSearchParam,filter:c.filterDialogFilter,defaultValue:``,onOk:e=>{_(KR(o,e.code,e.operator,e.value)),l({...u.current,filterDialogVisible:!1})},onCancel:()=>{l({...u.current,filterDialogVisible:!1})}},`search-filter-dialog-${c.dialogOpenTime}`)]})}function Gz(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:[pz(t.operator),`\xA0`,(0,I.jsx)(Dz,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function Kz(e){return Math.floor((e.offset??0)/(e.count??20))+1}function qz(e,t){let n=e.count??20,r=Xz(e,t);return Math.ceil(r/n)}function Jz(e,t){return Math.min(Xz(e,t),(e.offset??0)+1)}function Yz(e,t){return Math.max(Jz(e,t)+(t.entry?.length??0)-1,0)}function Xz(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 Zz(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(aS(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){MM(t.target)||(AM(t),t.button!==1&&e.onClick&&e.onClick(new Uz(n,t)),t.button===1&&e.onAuxClick&&e.onAuxClick(new Uz(n,t)))}if((0,b.useEffect)(()=>{t.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[t,e.resourceType]),!n)return(0,I.jsx)(ou,{});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)(zR,{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 Qz=(0,b.memo)(Zz),$z={root:`_root_1fbwr_1`,entry:`_entry_1fbwr_8`,key:`_key_1fbwr_13`,value:`_value_1fbwr_20`};function eB(e){return(0,I.jsx)(cl,{children:(0,I.jsx)(`div`,{className:$z.root,children:e.children})})}eB.Entry=function(e){return(0,I.jsx)(`div`,{className:$z.entry,children:e.children})},eB.Key=function(e){return(0,I.jsx)(`div`,{className:$z.key,children:e.children})},eB.Value=function(e){return(0,I.jsx)(`div`,{className:$z.value,children:e.children})};var tB={list:`_list_y4z6g_1`,link:`_link_y4z6g_6`};function nB(e){let{baseUrl:t,tabs:n,children:r,...i}=e,a=rB(n),o=Ok(),[s,c]=(0,b.useState)(()=>{let e=YE.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)(gb,{value:s,onChange:l,...i,children:[(0,I.jsx)(gb.List,{className:tB.list,children:a.map(e=>(0,I.jsx)(gb.Tab,{value:e.value,children:(0,I.jsx)(Md,{className:tB.link,href:`${t}/${e.value}`,onClick:iB,children:e.label})},e.value))}),r]})}function rB(e){return e.map(e=>UC(e)?{label:e,value:e.toLowerCase()}:e)}function iB(e){jM(e)||e.preventDefault()}function aB(e){let{group:t}=e;return(0,I.jsx)(_l,{withBorder:!0,radius:`md`,p:`xs`,display:`flex`,style:{alignItems:`center`,justifyContent:`center`},children:(0,I.jsxs)(V,{children:[t.measureScore&&(0,I.jsx)(cB,{group:t}),!t.measureScore&&(0,I.jsx)(sB,{group:t})]})})}function oB(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 sB(e){let{group:t}=e,n=t.population,r=n?.find(e=>Aw(e.code)===`numerator`),i=n?.find(e=>Aw(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)(iy,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:uB(s)}],label:(0,I.jsx)(hd,{justify:`center`,children:(0,I.jsxs)(H,{fw:700,fz:18,children:[a,` / `,o]})})})}function cB(e){let{group:t}=e,n=t.measureScore?.unit??t.measureScore?.code;return(0,I.jsx)(I.Fragment,{children:n===`%`?(0,I.jsx)(iy,{size:120,thickness:12,roundCaps:!0,sections:[{value:lB(t),color:uB(t?.measureScore?.value??0)}],label:(0,I.jsx)(hd,{justify:`center`,children:(0,I.jsx)(H,{fw:700,fz:18,children:(0,I.jsx)(mI,{value:t.measureScore})})})}):(0,I.jsx)(hd,{h:120,align:`center`,children:(0,I.jsx)(q,{order:3,children:(0,I.jsx)(mI,{value:t.measureScore})})})})}function lB(e){let t=e.measureScore?.value,n=e.measureScore?.unit;return t?t<=1&&n===`%`?t*100:t:0}function uB(e){return e<=33?`red`:e<=67?`yellow`:`green`}function dB(e){let t=Rk(e.measureReport),[n]=MA(`Measure`,{url:t?.measure});return t?(0,I.jsxs)(z,{children:[n&&(0,I.jsx)(oB,{measure:n}),(0,I.jsx)(gy,{cols:{base:3,sm:1},spacing:{base:`md`,sm:`sm`},children:t.group?.map((e,t)=>(0,I.jsx)(aB,{group:e},e.id??t))})]}):null}var fB=`patient-accounts`,pB=`Patient Accounts`,mB=[`Organization`,`HealthcareService`,`CareTeam`];function hB(e){let{patient:t}=e,n=Q(),r=n.isProjectAdmin()||n.isSuperAdmin(),i=(0,b.useMemo)(()=>gC(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){Lb.show({id:fB,title:pB,color:`red`,message:`Cannot update accounts: Patient resource has no ID.`,icon:(0,I.jsx)(wM,{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}]};Lb.show({id:fB,title:pB,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)),Lb.update({id:fB,title:pB,color:`green`,message:l?`Account changes saved. Compartment updates are being applied.`:`Account changes saved.`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0}),e.onSaved?.()}catch(e){Lb.update({id:fB,title:pB,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{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)(gB,{reference:e})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(WL,{value:e,link:!0})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(mu,{variant:`subtle`,color:`red`,"aria-label":`Remove ${e.reference}`,onClick:()=>g(e.reference),children:(0,I.jsx)(wM,{size:16})})})]},e.reference))})]}),(0,I.jsx)(lm,{}),(0,I.jsx)(q,{order:4,children:`Add Account`}),(0,I.jsx)(dL,{name:`newAccount`,placeholder:`Search for Organization, HealthcareService, or CareTeam...`,targetTypes:mB,onChange:e=>{e&&h(e)}}),m&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(lm,{}),(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)(Ap,{color:`green`,variant:`light`,leftSection:(0,I.jsx)(rM,{size:12}),children:`Add`}):(0,I.jsx)(Ap,{color:`red`,variant:`light`,leftSection:(0,I.jsx)(Yj,{size:12}),children:`Remove`}),(0,I.jsx)(WL,{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)(tg,{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)(rM,{size:14,color:`green`}),(0,I.jsx)(WL,{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)(Yj,{size:14,color:`red`}),(0,I.jsx)(WL,{value:e.reference})]},e.reference.reference))})]}),(0,I.jsx)(sp,{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)(Td,{color:`blue`,title:`Admin access required`,children:`You need project admin access to manage patient account assignments.`})}function gB({reference:e}){let t=e.reference?.split(`/`)[0]??`Unknown`;return(0,I.jsx)(Ap,{variant:`light`,color:{Organization:`blue`,HealthcareService:`teal`,CareTeam:`violet`}[t]??`gray`,size:`sm`,children:t})}var _B=`patient-export`,vB=`Patient Export`,yB={everything:{operation:`$everything`,extension:`json`,contentType:lD.FHIR_JSON},summary:{operation:`$summary`,extension:`json`,contentType:lD.FHIR_JSON},ccda:{operation:`$ccda-export`,extension:`xml`,contentType:lD.CDA_XML},ccdaReferral:{operation:`$ccda-export`,type:`referral`,extension:`xml`,contentType:lD.CDA_XML}};function bB(e){let t=Q(),{patient:n}=e,[r,i]=(0,b.useState)(`everything`),[a,o]=(0,b.useState)(!1),s=(0,b.useCallback)(async e=>{let i=hC(n),{operation:o,type:s,contentType:c,extension:l}=yB[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=GI(e.authoredOn)),e.startDate&&(d.start=e.startDate),e.endDate&&(d.end=e.endDate),Lb.show({id:_B,title:vB,loading:!0,message:`Exporting...`,autoClose:!1,withCloseButton:!1});try{xB(await t.post(u,d,void 0,{cache:`no-cache`,headers:{Accept:c}}),`Patient-export-${i}-${new Date().toISOString().replaceAll(`:`,`-`)}.${l}`,c),Lb.update({id:_B,title:vB,color:`green`,message:`Done`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0})}catch(e){Lb.update({id:_B,title:vB,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}},[t,n,r,a]);return(0,I.jsx)(hP,{onSubmit:s,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(NI,{title:`Export Format`,description:`Required`,withAsterisk:!0,children:(0,I.jsx)(cy,{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)(NI,{title:`Author`,description:`Optional author for composition. Default value is current user.`,children:(0,I.jsx)(dL,{name:`author`,placeholder:`Author`,targetTypes:[`Organization`,`Practitioner`,`PractitionerRole`]})}),(0,I.jsx)(NI,{title:`Authored On`,description:`Optional date for composition authored on. Default value is current date.`,children:(0,I.jsx)(KI,{name:`authoredOn`,placeholder:`Authored on`})}),(0,I.jsx)(NI,{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)(KI,{name:`startDate`,placeholder:`Start date`})}),(0,I.jsx)(NI,{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)(KI,{name:`endDate`,placeholder:`End date`})}),r===`everything`&&(0,I.jsx)(NI,{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)(sp,{label:`Inline attachments`,checked:a,onChange:e=>o(e.currentTarget.checked)})})}),(0,I.jsx)(V,{justify:`right`,children:(0,I.jsx)(gP,{children:`Request Export`})})]})})}function xB(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 SB(e){if(e.gender===`male`)return`blue`;if(e.gender===`female`)return`pink`}function CB(e){let t=Rk(e.patient);return t?(0,I.jsxs)(eB,{children:[(0,I.jsx)(HM,{value:t,size:`lg`,color:SB(t)}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Name`}),(0,I.jsx)(eB.Value,{children:(0,I.jsx)(IM,{to:t,fw:500,children:t.name?(0,I.jsx)(dI,{value:t.name[0],options:{use:!1}}):`[blank]`})})]}),t.birthDate&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`DoB`}),(0,I.jsx)(eB.Value,{children:t.birthDate})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Age`}),(0,I.jsx)(eB.Value,{children:wC(t.birthDate)})]})]}),t.gender&&(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Gender`}),(0,I.jsx)(eB.Value,{children:t.gender})]}),t.address&&(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`State`}),(0,I.jsx)(eB.Value,{children:t.address[0]?.state})]}),t.identifier?.map(e=>(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:e?.system}),(0,I.jsx)(eB.Value,{children:e?.value})]},`${e?.system}-${e?.value}`))]}):null}function wB(e){let{patient:t,...n}=e,r=(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})])},[]);return(0,I.jsx)(OR,{value:t,loadTimelineResources:r,createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,subject:pC(e),sender:pC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,subject:pC(e),operator:pC(t),issued:new Date().toISOString(),content:n}),...n})}var TB={section:`_section_pqpwm_1`,hovering:`_hovering_pqpwm_7`,editing:`_editing_pqpwm_11`};function EB(e){let t=Q(),n=Rk(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(PB(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)(hP,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(l),children:[(0,I.jsx)(_b,{label:`Plan Title`,py:`md`,defaultValue:l.title,onChange:e=>p(`title`,e.currentTarget.value)}),(0,I.jsx)(DB,{actions:l.action||[],selectedKey:a,setSelectedKey:o,hoverKey:s,setHoverKey:c,onChange:e=>p(`action`,e)}),(0,I.jsx)(gP,{children:`Save`})]})})}function DB(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:TB.section,children:[e.actions.map(n=>(0,I.jsx)(OB,{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:NB()})},children:`Add action`})})]})}function OB(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)(kB,{action:t,onChange:e.onChange,selectedKey:e.selectedKey,hoverKey:e.hoverKey,onRemove:e.onRemove})})}function kB(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=Mn(TB.section,{[TB.hovering]:u&&!l});return(0,b.useEffect)(()=>{(async()=>{if(!t.definitionCanonical)return;o(!0);let e=await i.readCanonical([`Questionnaire`,`ActivityDefinition`],t.definitionCanonical);r(jB(e)),c(e),o(!1)})().catch(console.error)},[t.definitionCanonical,i]),a?(0,I.jsx)(ou,{}):(0,I.jsxs)(_l,{"data-testid":t.id,className:f,p:0,radius:`sm`,withBorder:!0,children:[(0,I.jsxs)(hd,{w:`100%`,p:`xs`,bg:`gray.0`,gap:`md`,align:`center`,justify:`space-between`,children:[(0,I.jsx)(_b,{w:`100%`,name:`actionTitle-${t.id}`,defaultValue:t.title,placeholder:`Title`,onChange:e=>d(`title`,e.currentTarget.value)}),(0,I.jsx)(yu,{"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)(_b,{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)(wg,{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)(Md,{href:`/Questionnaire`,target:`_blank`,c:`blue`,children:`questionnaires list`})]}),(0,I.jsx)(AB,{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)(Md,{href:`/ActivityDefinition`,target:`_blank`,c:`blue`,children:`activity definitions list`})]}),(0,I.jsx)(AB,{resource:s,resourceType:`ActivityDefinition`,action:t,onChange:e.onChange,placeholder:`Search for activity definition`})]})]})]})}function AB(e){let{id:t}=e.action,{resource:n}=e;return(0,I.jsx)(uL,{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:mC(t)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function jB(e){return e===void 0?`standard`:e.resourceType.toLowerCase()}var MB=1;function NB(e){if(e){if(e.startsWith(`id-`)){let t=Number.parseInt(e.substring(3),10);Number.isNaN(t)||(MB=Math.max(MB,t+1))}return e}return`id-`+MB++}function PB(e){return{...e,action:FB(e.action)}}function FB(e){if(e)return e.map(e=>({...e,id:NB(e.id),action:FB(e.action)}))}var IB=`modulepreload`,LB=function(e){return`/`+e},RB={},zB=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,import.meta.url).href}r=o(t.map(t=>{if(t=LB(t,n),t=s(t),t in RB)return;RB[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`:IB,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)})},BB=150,VB;function HB({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-_>=BB)){_=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 UB(),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)(Td,{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)(ou,{size:`xs`,mr:`xs`}),`Loading camera...`]})]})}async function UB(){return VB||=zB(()=>import(`./jsQR-KuOuxaXA.js`).then(e=>c(e.default,1)).then(e=>e.default),[]).catch(e=>{throw VB=void 0,Error(`QR code scanning requires the optional "jsqr" dependency. Install jsqr to use QrCodeScanner. ${Y(e)}`)}),VB}var WB=30,GB=50;function KB(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!==Bk.choice&&n.type!==Bk.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!==Bk.choice&&n.type!==Bk.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=tV(r,e.index)??SA(c),u=EC(r,`${Ex}/fhir/StructureDefinition/questionnaire-validationError`),d=null;switch(a){case Bk.display:d=(0,I.jsx)(`p`,{children:e.item.text},e.item.linkId);break;case Bk.boolean:d=(0,I.jsx)(MI,{title:e.item.text,htmlFor:s,children:(0,I.jsx)(sp,{id:s,name:o,required:e.required??n.required,defaultChecked:l?.value,onChange:e=>i([{valueBoolean:e.currentTarget.checked}])})},e.item.linkId);break;case Bk.decimal:d=(0,I.jsx)(_b,{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 Bk.integer:d=(0,I.jsx)(_b,{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 Bk.date:d=(0,I.jsx)(_b,{type:`date`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDate:e.currentTarget.value}])});break;case Bk.dateTime:d=(0,I.jsx)(KI,{name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDateTime:e}])});break;case Bk.time:d=(0,I.jsx)(_b,{type:`time`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueTime:e.currentTarget.value}])});break;case Bk.string:case Bk.url:d=(0,I.jsx)(_b,{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 Bk.text:d=(0,I.jsx)(ih,{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 Bk.attachment:d=(0,I.jsx)(V,{py:4,children:(0,I.jsx)(pF,{path:``,name:s,defaultValue:l?.value,onChange:e=>i([{valueAttachment:e}])})});break;case Bk.reference:d=(0,I.jsx)(dL,{name:s,required:e.required??n.required,targetTypes:pA(n),searchCriteria:hA(n,t?.subject,t?.encounter),defaultValue:l?.value,onChange:e=>i([{valueReference:e}])});break;case Bk.quantity:d=(0,I.jsx)(eL,{path:``,name:s,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueQuantity:e}]),disableWheel:!0});break;case Bk.choice:case Bk.openChoice:{let{widget:t,multiselect:a}=aV(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)($B,{...o}):t===`drop-down`?(0,I.jsx)(qB,{...o}):(0,I.jsx)(QB,{...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 qB(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)(eV,{});let c=SA(i),l=tV(o)??c,u=nV(o),d=n.repeats||s;if(n.answerValueSet)return(0,I.jsx)(wP,{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}=oV(n);return(0,I.jsx)(bg,{data:t,placeholder:`Select items`,searchable:!0,value:u,required:r,onChange:t=>{if(t.length===0)a([{}]);else{let r=cA(t,e,n);a(r)}}})}{let e=[``];if(n.answerOption)for(let t of n.answerOption){let n=CA(t);e.push(mw(n))}return(0,I.jsx)(wg,{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=CA(r),o=`value`+ZC(i.type);a([{[o]:i.value}])},defaultValue:jw(l?.value)||l?.value,data:e})}}function JB(e,t){return e?t.valueSetExpand({url:e,count:31}).then(e=>e.expansion?.contains??[]):Promise.resolve([])}function YB(e){let t=Q(),[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(()=>!e||void 0);return(0,b.useEffect)(()=>{async function n(){if(!e){s(!0);return}a(!0),s(void 0);try{let n=await JB(e,t);r(n),s(!0)}catch(e){let t=FA(e);s(!t),t||console.error(`Error loading value set:`,e)}finally{a(!1)}}n().catch(console.error)},[e,t]),{options:n,loading:i,available:o}}function XB({valueSetUrl:e}){return(0,I.jsx)(yP,{text:`Suggestions unavailable`,color:`yellow.9`,message:`Value set ${e} is unavailable`})}function ZB(e,t){return e.map((e,n)=>[`${t}-valueset-${n}`,{type:`Coding`,value:{system:e.system,code:e.code,display:e.display}}])}function QB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o}=e,s=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),c=SA(i),{options:l,loading:u,available:d}=YB(n.answerValueSet),f=[],p;if(n.answerValueSet)f.push(...ZB(l,t));else if(n.answerOption){let e=n.answerOption.slice(0,GB).map((e,n)=>{let r=`${t}-option-${n}`,i=CA(e);return i?.value?(c&&DC(i)===DC(c)&&(p=r),[r,i]):null}).filter(e=>e!==null);f.push(...e)}let m=rV(f,tV(o));if(u)return(0,I.jsx)(H,{children:`Loading options...`});if(f.length===0)return d===!1?(0,I.jsx)(XB,{valueSetUrl:n.answerValueSet}):(0,I.jsx)(eV,{});let h=f.slice(0,WB);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Mv.Group,{name:t,value:m??p,required:r,onChange:e=>{let t=f.find(t=>t[0]===e);if(t){let e=t[1],n=`value`+ZC(e.type);a([{[n]:e.value}])}},children:h.map(([e,t])=>(0,I.jsx)(Mv,{id:e,value:e,py:4,required:r,label:(0,I.jsx)(wI,{property:s,propertyType:t.type,value:t.value})},e))}),(n.answerValueSet&&f.length>WB||n.answerOption&&f.length>GB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mt:`xs`,children:[`Showing first `,WB,` options`]})]})}function $B(e){let{name:t,item:n,onChangeAnswer:r,response:i}=e,a=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),{options:o,loading:s,available:c}=YB(n.answerValueSet),l=n.answerValueSet?(i?.answer?.map(e=>e.valueCoding)||[]).filter(e=>e!==void 0):nV(i),u=[];if(n.answerValueSet)u.push(...ZB(o,t));else if(n.answerOption){let e=n.answerOption.slice(0,GB).map((e,n)=>{let r=`${t}-option-${n}`,i=CA(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 c===!1?(0,I.jsx)(XB,{valueSetUrl:n.answerValueSet}):(0,I.jsx)(eV,{});let d=u.slice(0,WB),f=(e,t)=>{if(n.answerValueSet){let n=l,i;i=t?[...n,e.value]:n.filter(t=>!PC(t,e.value)),i.length===0?r([{}]):r(i.map(e=>({valueCoding:e})))}else{let i=l,a=mw(e),o;if(o=t?[...i,a]:i.filter(e=>e!==a),o.length===0)r([{}]);else{let t=cA(o,`value`+ZC(e.type),n);r(t)}}};return(0,I.jsxs)(V,{style:{flexDirection:`column`,alignItems:`flex-start`},children:[d.map(([e,t])=>{let r=mw(t),i=n.answerValueSet?l.some(e=>PC(e,t.value)):l.includes(r);return(0,I.jsx)(sp,{id:e,label:(0,I.jsx)(wI,{property:a,propertyType:t.type,value:t.value}),checked:i,onChange:e=>f(t,e.currentTarget.checked)},e)}),(n.answerValueSet&&u.length>WB||n.answerOption&&u.length>GB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Showing first `,WB,` options`]})]})}function eV(){return(0,I.jsx)(_b,{disabled:!0,placeholder:`No Answers Defined`})}function tV(e,t=0){return CA(e?.answer?.[t]??{})}function nV(e){let t=e?.answer;return t?t.map(e=>CA(e)).map(e=>jw(e?.value)||e?.value).filter(Boolean):[]}function rV(e,t){return e.find(e=>PC(e[1].value,t?.value))?.[0]}var iV=[`drop-down`,`radio-button`,`check-box`];function aV(e){let t=`radio-button`,n=!1;e.answerValueSet&&(t=`drop-down`);for(let r of e.extension??[]){if(r.url!==Vk)continue;let e=r.valueCodeableConcept?.coding?.[0]?.code;iV.includes(e)&&(t=e),e===`multi-select`&&(n=!0)}return t===`radio-button`&&n&&(t=`check-box`),{widget:t,multiselect:n}}function oV(e){if(e.answerOption?.length===0)return{propertyName:``,data:[]};let t=e.answerOption[0];return{propertyName:`value`+ZC(CA(t).type),data:(e.answerOption??[]).map(e=>{let t=mw(CA(e));return{value:t,label:t}})}}var sV={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 cV(e){let t=Q(),n=Rk(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(_V(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)(hP,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(a),children:[(0,I.jsx)(lV,{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)(gP,{children:`Save`})]})})}function lV(e){let t=e.item,n=e.item,r=Qw(e.item),i=r||n.type===Bk.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=xV(e.item.item,t,n);e.onChange({...e.item,item:r})}let v=Mn(sV.section,{[sV.editing]:o,[sV.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:sV.questionBody,children:o?(0,I.jsxs)(I.Fragment,{children:[r&&(0,I.jsx)(_b,{size:`xl`,defaultValue:t.title,onBlur:e=>m(`title`,e.currentTarget.value)}),!r&&(0,I.jsx)(ih,{autosize:!0,minRows:2,defaultValue:n.text,onBlur:e=>m(`text`,e.currentTarget.value)}),n.type===`reference`&&(0,I.jsx)(fV,{item:n,onChange:h}),Zk(n)&&(0,I.jsx)(uV,{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:sV.preserveBreaks,children:n.text}),!i&&(0,I.jsx)(KB,{item:n,index:0,required:!1,responseItem:{linkId:n.linkId}})]})}),n.item?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(lV,{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:sV.topActions,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(_b,{size:`xs`,className:sV.linkIdInput,defaultValue:n.linkId,onBlur:e=>m(`linkId`,e.currentTarget.value)}),!i&&(0,I.jsx)(wg,{size:`xs`,className:sV.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:sV.movementActions,children:(0,I.jsxs)(z,{className:sV.columnAlignment,children:[!e.isFirst&&(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,I.jsx)(tj,{"data-testid":`up-button`,size:15,className:sV.movementIcons})}),!e.isLast&&(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,I.jsx)(ej,{"data-testid":`down-button`,size:15,className:sV.movementIcons})})]})}),(0,I.jsxs)(`div`,{className:sV.bottomActions,children:[i&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f({id:gV(),linkId:hV(`q`),type:`string`,text:`Question`})},children:`Add item`}),(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f({id:gV(),linkId:hV(`g`),type:`group`,text:`Group`},!0)},children:`Add group`})]}),r&&(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f(bV(),!0)},children:`Add Page`}),o&&!r&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onRepeatable&&e.onRepeatable(n)},children:n.repeats?`Remove Repeatable`:`Make Repeatable`}),(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onRemove&&e.onRemove()},children:`Remove`})]})]})]})}function uV(e){let t=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),n=e.item.answerOption??[];return(0,I.jsxs)(`div`,{children:[e.item.answerValueSet===void 0?(0,I.jsx)(dV,{options:n,property:t,item:e.item,onChange:e.onChange}):(0,I.jsx)(_b,{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)(Md,{href:`#`,onClick:t=>{AM(t),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...n,{id:gV()}]})},children:`Add choice`}),(0,I.jsx)(xy,{w:`lg`}),(0,I.jsx)(Md,{href:`#`,onClick:t=>{AM(t),e.onChange({...e.item,answerOption:[],answerValueSet:``})},children:`Add value set`})]})]})}function dV(e){return(0,I.jsx)(`div`,{children:e.options.map(t=>{let[n,r]=cI({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)(OL,{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)(Md,{href:`#`,onClick:n=>{AM(n),e.onChange({...e.item,answerOption:e.options.filter(e=>e.id!==t.id)})},children:`Remove`})})]},t.id)})})}function fV(e){let t=pA(e.item)??[];return(0,I.jsxs)(I.Fragment,{children:[t.map((n,r)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(AP,{name:`resourceType`,placeholder:`Resource Type`,defaultValue:n,onChange:r=>{e.onChange(mA(e.item,t.map(e=>e===n?r:e)))}}),(0,I.jsx)(Md,{href:`#`,onClick:r=>{AM(r),e.onChange(mA(e.item,t.filter(e=>e!==n)))},children:`Remove`})]},`${n}-${r}`)),(0,I.jsx)(Md,{href:`#`,onClick:n=>{AM(n),e.onChange(mA(e.item,[...t,``]))},children:`Add Resource Type`})]})}var pV=1,mV=1;function hV(e){return e+pV++}function gV(){return`id-`+mV++}function _V(e){return{...e,id:e.id||gV(),item:vV(e.item)}}function vV(e){if(e)return e.forEach(e=>{e.id?.match(/^id-\d+$/)&&(mV=Math.max(mV,Number.parseInt(e.id.substring(3),10)+1)),e.linkId?.match(/^q\d+$/)&&(pV=Math.max(pV,Number.parseInt(e.linkId.substring(1),10)+1))}),e.map(e=>({...e,id:e.id||gV(),item:vV(e.item),answerOption:yV(e.answerOption)}))}function yV(e){if(e)return e.map(e=>({...e,id:e.id||gV()}))}function bV(){return{id:gV(),linkId:hV(`s`),type:`group`,text:`New Page`,extension:[{url:Vk,valueCodeableConcept:{coding:[{system:`http://hl7.org/fhir/questionnaire-item-control`,code:`page`}]}}]}}function xV(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 SV=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)}},CV=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}startPoint;control2;control1;endPoint;startWidth;endWidth;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 SV(s.x+h,s.y+g),c2:new SV(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}},wV=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 TV(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 EV=class e extends wV{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?TV(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()}canvas;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._drawLine.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})}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 SV(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=CV.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()}_getDotSize(e){return e.dotSize>0?e.dotSize:(e.minWidth+e.maxWidth)/2}_drawDot(e,t){let n=this._ctx,r=this._getDotSize(t);n.beginPath(),this._drawCurveSegment(e.x,e.y,r),n.closePath(),n.fillStyle=t.penColor,n.fill()}_drawLine(e,t,n){let r=this._ctx;r.save(),r.beginPath(),r.moveTo(e.x,e.y),r.lineTo(t.x,t.y),r.lineWidth=this._getDotSize(n)*2,r.lineCap=`round`,r.strokeStyle=n.penColor,r.stroke(),r.restore(),this._isEmpty=!1}_fromData(e,t,n,r){for(let i of e){let{points:e}=i,a=this._getPointGroupOptions(i);if(e.length>2)for(let n=0;n<e.length;n+=1){let r=e[n],i=new SV(r.x,r.y,r.pressure,r.time);n===0&&this._reset(a);let o=this._addPoint(i,a);o&&t(o,a)}else e.length===2?(this._reset(a),r(e[0],e[1],a)):(this._reset(a),n(e[0],a))}}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)},(e,t,n)=>{let r=document.createElement(`line`);r.setAttribute(`x1`,e.x.toString()),r.setAttribute(`y1`,e.y.toString()),r.setAttribute(`x2`,t.x.toString()),r.setAttribute(`y2`,t.y.toString()),r.setAttribute(`stroke`,n.penColor),r.setAttribute(`stroke-width`,(this._getDotSize(n)*2).toString()),r.setAttribute(`stroke-linecap`,`round`),o.appendChild(r)}),o.outerHTML}};function DV(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:Ex+`/fhir/signature-type`,code:`ProofOfOrigin`,display:`Proof of Origin`}],when:new Date().toISOString(),who:a??pC(t.getProfile()),data:l.current?.toDataURL().split(`,`)[1]})}if(c.current){let t=new EV(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)(_l,{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)(bM,{size:16}),variant:`subtle`,color:`gray`,children:`Clear`})]})}function OV(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)(jV,{formState:e.formState,context:t,items:e.item.item??[],responseItems:e.responseItem.item??[]})]},e.item.linkId)}function kV(e){return(0,I.jsxs)(I.Fragment,{children:[e.responseItems.map(t=>(0,I.jsx)(OV,{formState:e.formState,context:e.context,item:e.item,responseItem:t},`group-${t.id}`)),(0,I.jsx)(Md,{onClick:()=>e.formState.onAddGroup(e.context,e.item),children:`Add Group: ${e.item.text}`})]})}function AV(e){let{formState:t,context:n,item:r,responseItem:i}=e,a=r.type===Bk.choice||r.type===Bk.openChoice,o=!a,s=!a&&i.answer&&i.answer.length>0?i.answer:[{}];return(0,I.jsxs)(NI,{title:e.item.text,withAsterisk:e.item.required,children:[(0,I.jsx)(G,{gap:`xs`,children:s?.map((e,a)=>(0,I.jsx)(KB,{formState:t,context:n,item:r,responseItem:i,index:a},`${r.linkId}-${a}`))}),o&&(0,I.jsx)(Md,{onClick:()=>t.onAddAnswer(n,r),children:`Add Item`})]},e.item.linkId)}function jV(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(!eA(e,t.questionnaireResponse))return null;let s=e.type===Bk.group,c=a&&s&&o;if(s&&(o=!0),e.type===Bk.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===Bk.group&&e.repeats?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(lm,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(kV,{formState:t,context:n,item:e,responseItems:l})]},`repeating-group-${e.id}-${r}`):e.type===Bk.group?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(lm,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(OV,{formState:t,context:n,item:e,responseItem:l[0]})]},`group-${e.id}-${r}`):e.type===Bk.boolean?(0,I.jsx)(KB,{formState:t,context:n,item:e,responseItem:l[0],index:0},`boolean-item-${e.id}-${r}`):e.repeats?(0,I.jsx)(AV,{formState:t,context:n,item:e,responseItem:l[0]},`repeating-item-${e.id}-${r}`):(0,I.jsx)(NI,{htmlFor:e.linkId,title:e.text,withAsterisk:e.required,children:(0,I.jsx)(KB,{formState:t,context:n,item:e,responseItem:l[0],index:0})},`repeating-item-${e.id}-${r}`)})})}function MV(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)(Py,{active:o,allowNextStepsSelect:!1,p:6,children:a.map((e,t)=>(0,I.jsx)(Py.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)(gP,{children:n??`Submit`})]})]})}function NV(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=EA({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&&!!EC(s.questionnaire,qk),[s]),u=(0,b.useMemo)(()=>!s.loading&&!!s.questionnaireResponse.extension?.find(e=>e.url===Jk),[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=pC(e))}n({...o,questionnaire:a.url??mC(a),subject:s,source:d,authored:new Date().toISOString(),status:`completed`})},[t,l,u]);return s.loading?null:(0,I.jsxs)(hP,{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)(lm,{color:`var(--mantine-color-gray-2)`})]}),s.pagination?(0,I.jsx)(MV,{formState:s,submitButtonText:e.submitButtonText,excludeButtons:e.excludeButtons,children:(0,I.jsx)(jV,{formState:s,context:[],items:s.items,responseItems:s.responseItems})}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(jV,{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)(DV,{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)(gP,{children:e.submitButtonText??`Submit`})})]})]})}var PV={section:`_section_4m5it_1`},FV=[`gender`,`age`,`gestationalAge`,`context`,`appliesTo`,`category`],IV={definition:{resourceType:`ObservationDefinition`,code:{text:``}},onSubmit:()=>{}};function LV(e){e=Object.assign(IV,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)(()=>{let e=BV(t,s);r(VV(e.qualifiedInterval||[],a))},[t]),(0,I.jsxs)(hP,{testid:`reference-range-editor`,onSubmit:c,children:[(0,I.jsx)(G,{children:n.map(e=>(0,I.jsx)(RV,{unit:UV(t.quantitativeDetails?.unit),onChange:d,onAdd:f,onRemove:p,onRemoveGroup:u,intervalGroup:e},`group-${e.id}`))}),(0,I.jsx)(mu,{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)(yj,{})}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`Save`})})]});function c(){let r=n.flatMap(e=>e.intervals).filter(e=>!WV(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 RV(e){let{intervalGroup:t,unit:n}=e;return(0,I.jsx)(hF,{"data-testid":t.id,className:PV.section,children:(0,I.jsxs)(G,{gap:`lg`,children:[(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(mu,{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)(vj,{})},`remove-group-button-${t.id}`)}),(0,I.jsx)(zV,{intervalGroup:t,onChange:e.onChange}),(0,I.jsx)(lm,{}),t.intervals.map(n=>(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsxs)(V,{children:[(0,I.jsx)(_b,{"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)(mu,{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)(vj,{})},`remove-interval-${n.id}`)]}),(0,I.jsx)(nL,{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)(mu,{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)(yj,{})})]})})}function zV(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)(wg,{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)(nL,{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)(wg,{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)(wg,{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 BV(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 VV(e,t){let n=1,r={};for(let t of e){let e=HV(t);e in r||(r[e]={id:`group-id-${n++}`,filters:Object.fromEntries(FV.map(e=>[e,t[e]])),intervals:[]}),r[e].intervals.push(t)}return t(n),Object.values(r)}function HV(e){return[`gender=${e.gender}`,`age=${Dw(e.age)}`,`gestationalAge=${Dw(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(e=>e.text).join(`+`)}`,`category=${e.category}`].join(`:`)}function UV(e){return e&&(ew(e,`http://unitsofmeasure.org`)||e.text)}function WV(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}function GV(e){let t=Q(),n=Rk(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)(Cm,{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)(Cm.Col,{span:1,p:`md`,children:r?.status===`completed`?(0,I.jsx)(hj,{}):(0,I.jsx)(pM,{color:`gray`})}),(0,I.jsxs)(Cm.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)(UL,{value:r?.meta?.author}),`\xA0on\xA0`,bw(r?.meta?.lastUpdated)]}),(0,I.jsxs)(`div`,{children:[`Status: `,(0,I.jsx)(BL,{status:r?.status||`unknown`})]})]}),(0,I.jsxs)(Cm.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===mC(t.resource))return t.resource}}function KV(e,t){return JV(qV(e,t),e,t)}function qV(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:YV(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 JV(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 YV(e){return e&&!e.snake&&e.prev?e.prev:e}function XV(e){let t=(e.entry??[]).filter(e=>!!e.resource).map(e=>({meta:e.resource?.meta,lines:DC(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 ZV(n,t),QV(n),n}function ZV(e,t){for(let n=1;n<t.length;n++){let r=KV(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 QV(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 $V={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 eH(e,t){return`/${e.resourceType}/${e.id}/_history/${t}`}function tH(e){let t=Math.floor((Date.now()-Date.parse(e))/1e3),n=Math.floor(t/31536e3);if(n>0)return nH(n,`year`);let r=Math.floor(t/2592e3);if(r>0)return nH(r,`month`);let i=Math.floor(t/86400);if(i>0)return nH(i,`day`);let a=Math.floor(t/3600);if(a>0)return nH(a,`hour`);let o=Math.floor(t/60);return o>0?nH(o,`minute`):nH(t,`second`)}function nH(e,t){return`${e} ${e===1?t:t+`s`} ago`}function rH(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=XV(n);return(0,I.jsx)(`div`,{className:$V.container,children:(0,I.jsx)(`table`,{className:$V.root,children:(0,I.jsx)(`tbody`,{children:a.map((e,t)=>(0,I.jsxs)(`tr`,{className:e.span>0?$V.startRow:$V.normalRow,children:[e.span>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`td`,{className:$V.author,rowSpan:e.span,children:[(0,I.jsx)(UL,{value:e.meta.author,link:!0,fz:`xs`}),e.meta.onBehalfOf&&(0,I.jsxs)(`div`,{className:$V.onBehalfOf,children:[`on behalf of `,(0,I.jsx)(UL,{value:e.meta.onBehalfOf,link:!0,fz:`xs`,c:`dimmed`})]})]}),(0,I.jsx)(`td`,{className:$V.dateTime,rowSpan:e.span,children:(0,I.jsx)(IM,{to:eH(i,e.meta.versionId),fz:`xs`,children:tH(e.meta.lastUpdated)})})]}),(0,I.jsx)(`td`,{className:$V.lineNumber,children:t+1}),(0,I.jsx)(`td`,{className:$V.line,children:(0,I.jsx)(`pre`,{className:$V.pre,children:e.value})})]},`row-`+t))})})})}var iH={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function aH(e){let t=e.original,n=e.revised;e.ignoreMeta&&(t={...t,meta:void 0},n={...n,meta:void 0});let r=KV(DC(t,!0).match(/[^\r\n]+/g)??[`{`,`}`],DC(n,!0).match(/[^\r\n]+/g)??[`{`,`}`]);return(0,I.jsx)(`pre`,{style:{color:`gray`},children:r.map((e,t)=>(0,I.jsx)(oH,{delta:e},`delta`+t))})}function oH(e){return(0,I.jsxs)(I.Fragment,{children:[`...`,(0,I.jsx)(`br`,{}),e.delta.original.lines.length>0&&(0,I.jsx)(`div`,{className:iH.removed,children:e.delta.original.lines.join(`
|
|
208
|
+
[${JSON.stringify(t,null,2)}]`);return(0,I.jsx)(wI,{value:t[0]||``,propertyType:e.propertyType})}function BR(e){let t=e.exportCsv||e.exportTransactionBundle?(0,I.jsxs)(I.Fragment,{children:[e.exportCsv&&(0,I.jsx)(VR,{text:`CSV`,exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,I.jsx)(VR,{text:`Transaction Bundle`,exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}):void 0;return(0,I.jsx)(RL,{title:`Export`,opened:e.visible,onClose:e.onCancel,actions:t,children:(0,I.jsx)(H,{children:`Limited to 1000 records`})})}function VR(e){return(0,I.jsx)(U,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var HR={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]},UR={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 WR(e,t){return{...e,filters:t,offset:0,name:void 0}}function GR(e,t){return WR(e,(e.filters??[]).filter(e=>e.code!==t))}function KR(e,t,n,r,i){i&&(e=GR(e,t));let a=[];return e.filters&&a.push(...e.filters),a.push({code:t,operator:n,value:r??``}),WR(e,a)}function qR(e,t){if(!e.filters)return e;let n=[...e.filters];return n.splice(t,1),{...e,filters:n,name:void 0}}function JR(e,t){return ZR(e,t,-1)}function YR(e,t){return ZR(e,t,0)}function XR(e,t){return ZR(e,t,1)}function ZR(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),iz(e,t,r,i)}function QR(e,t){let n=new Date;return iz(e,t,n,new Date(n.getTime()+864e5))}function $R(e,t){return nz(e,t,-1)}function ez(e,t){return nz(e,t,0)}function tz(e,t){return nz(e,t,1)}function nz(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),iz(e,t,r,i)}function rz(e,t){let n=new Date;return n.setMonth(0),n.setDate(1),n.setHours(0,0,0,0),iz(e,t,n,new Date)}function iz(e,t,n,r){return e=GR(e,t),e=az(e,t,Z.GREATER_THAN_OR_EQUALS,n),e=az(e,t,Z.LESS_THAN_OR_EQUALS,r),e}function az(e,t,n,r){return KR(e,t,n,r.toISOString())}function oz(e,t,n=!0){return KR(e,t,Z.MISSING,n.toString())}function sz(e,t){return e.offset===t?e:{...e,offset:t,name:void 0}}function cz(e,t){let n=e.count??20;return sz(e,(t-1)*n)}function lz(e,t,n){return t===uz(e)&&n!==void 0&&n===dz(e)?e:{...e,sortRules:[{code:t,descending:!!n}],name:void 0}}function uz(e){let t=e.sortRules;if(!t||t.length===0)return;let n=t[0].code;return n.startsWith(`-`)?n.substr(1):n}function dz(e){let t=e.sortRules;return!t||t.length===0?!1:!!t[0].descending}function fz(e){return HR[e.type]}function pz(e){return UR[e]??``}function mz(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(ZC).join(` `))}function hz(e){return e.startsWith(`_`)}function gz(e){return hz(e)?e:mz(e)}function _z(e,t){let n=t.name;return n===`id`?(0,I.jsx)(IM,{to:`/${e.resourceType}/${e.id}`,children:e.id}):n===`meta.versionId`?e.meta?.versionId:n===`_lastUpdated`?bw(e.meta?.lastUpdated):`${e.resourceType}.${t.name}`===t.elementDefinition?.path?vz(e,t.elementDefinition):t.searchParams?.length===1&&t.name===t.searchParams[0].code?yz(e,t.searchParams[0]):null}function vz(e,t){let n=t.path?.split(`.`)?.pop()?.replaceAll(`[x]`,``)??``,[r,i]=cI({type:e.resourceType,value:e},n);return r?(0,I.jsx)(wI,{path:t.path,property:t,propertyType:i,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function yz(e,t){let n=XT(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)(wI,{propertyType:e.type,value:e.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${t}-${n.length}`))})}function bz(e){let t=(0,b.useRef)(!1),[n,r]=(0,b.useState)({search:JSON.parse(DC(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 aw(xz(SS(t),Ww(t))).map(e=>({value:e,label:mz(e)}))},[e.visible,e.search.resourceType]);function s(e){r({search:{...n.search,fields:e}})}return(0,I.jsx)(RL,{title:`Fields`,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`})},actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(U,{onClick:()=>e.onOk(n.search),children:`OK`})}),children:(0,I.jsx)(bg,{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})})}function xz(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(mz(t));if(t)for(let e of Object.keys(t)){let t=mz(e);!r.has(e)&&!i.has(t)&&(n.push(e),r.add(e),i.add(t))}return n}function Sz(e){let t=rk(e.resourceType,e.searchParam),n=e.name??`filter-value`;switch(t.type){case nk.REFERENCE:return(0,I.jsx)(dL,{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 nk.BOOLEAN:return(0,I.jsx)(sp,{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 nk.DATE:return(0,I.jsx)(_b,{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 nk.DATETIME:return(0,I.jsx)(KI,{name:n,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case nk.NUMBER:return(0,I.jsx)(_b,{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 nk.QUANTITY:return(0,I.jsx)(eL,{name:n,path:``,defaultValue:Cz(e.defaultValue),autoFocus:e.autoFocus,onChange:t=>{t?e.onChange(`${t.value}`):e.onChange(``)}});default:return(0,I.jsx)(_b,{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 Cz(e){if(e){let[t,n,r]=e.split(`|`);if(t)return{value:Number.parseFloat(t),system:n,unit:r}}}function wz(e){let[t,n]=(0,b.useState)(BC(e.search)),r=(0,b.useRef)(t);(0,b.useLayoutEffect)(()=>{r.current=t}),(0,b.useEffect)(()=>{n(BC(e.search))},[e.search]);function i(e){n(KR(r.current,e.code,e.operator,e.value))}let a=e.search.resourceType,o=Ww(a)??{},s=t.filters||[];return(0,I.jsxs)(RL,{title:`Filters`,size:900,opened:e.visible,onClose:e.onCancel,onSubmit:()=>e.onOk(r.current),actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`OK`})}),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)(Tz,{id:`filter-${t}-row`,resourceType:a,searchParams:o,value:e,onChange:e=>{let i=[...s];i[t]=e,n(WR(r.current,i))},onDelete:()=>n(qR(r.current,t))},`filter-${t}-row`))})]}),(0,I.jsx)(vL,{propertyDisplayName:`Filter`,onClick:()=>i({})})]})}function Tz(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&&fz(a),s=[],c=[];for(let t of Object.keys(e.searchParams)){let e={value:t,label:gz(t)};hz(t)?c.push(e):s.push(e)}return(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(wg,{"data-testid":`${e.id}-filter-field`,defaultValue:e.value.code,onChange:e=>n(e.currentTarget.value),data:[``,...s.length>0?[{group:`Fields`,items:s}]:[],...c.length>0?[{group:`Metadata`,items:c}]:[]]})}),(0,I.jsx)(`td`,{children:o&&(0,I.jsx)(wg,{"data-testid":`${e.id}-filter-operation`,defaultValue:t.operator,onChange:e=>r(e.currentTarget.value),data:[``,...o.map(e=>({value:e,label:pz(e)}))]},`${e.id}-filter-value-${e.value.code}`)}),(0,I.jsx)(`td`,{children:a&&t.operator&&(0,I.jsx)(Sz,{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)(mu,{variant:`outline`,color:`red`,radius:`xl`,"aria-label":`Delete filter`,onClick:e.onDelete,children:(0,I.jsx)(wM,{style:{width:`70%`,height:`70%`},stroke:1.5})})})]})}function Ez(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)(RL,{title:e.title,size:`xl`,opened:e.visible,onClose:e.onCancel,onSubmit:r,actions:(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`OK`})}),children:(0,I.jsx)(Sz,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:t,autoFocus:!0,onChange:n})})}function Dz(e){let{resourceType:t,filter:n}=e,r=eT.types[t].searchParams?.[n.code];if(r){if(r.type===`reference`&&(n.operator===Z.EQUALS||n.operator===Z.NOT_EQUALS))return(0,I.jsx)(UL,{value:{reference:n.value}});let e=rk(t,r);if(n.code===`_lastUpdated`||e.type===nk.DATETIME)return(0,I.jsx)(I.Fragment,{children:bw(n.value)})}return(0,I.jsx)(I.Fragment,{children:n.value})}function Oz(e){if(!e.searchParams)return null;function t(t,n){i(lz(e.search,t.code,n))}function n(t){i(GR(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)(kz,{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:mz(e.code)},e.code))})}function kz(e){switch(e.searchParam.type){case`date`:return(0,I.jsx)(Az,{...e});case`number`:case`quantity`:return(0,I.jsx)(jz,{...e});case`reference`:return(0,I.jsx)(Mz,{...e});case`string`:return(0,I.jsx)(Nz,{...e});case`token`:return(0,I.jsx)(Pz,{...e});case`uri`:return(0,I.jsx)(Fz,{...e});default:return(0,I.jsxs)(I.Fragment,{children:[`Unknown search param type: `,e.searchParam.type]})}}function Az(e){let{searchParam:t}=e,n=t.code;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Oldest to Newest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Kj,{size:14}),onClick:()=>e.onPrompt(t,Z.ENDS_BEFORE),children:`Before...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Gj,{size:14}),onClick:()=>e.onPrompt(t,Z.STARTS_AFTER),children:`After...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(sj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Between...`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(XR(e.search,n)),children:`Tomorrow`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(YR(e.search,n)),children:`Today`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(JR(e.search,n)),children:`Yesterday`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(QR(e.search,n)),children:`Next 24 Hours`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(tz(e.search,n)),children:`Next Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(ez(e.search,n)),children:`This Month`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange($R(e.search,n)),children:`Last Month`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(pj,{size:14}),onClick:()=>e.onChange(rz(e.search,n)),children:`Year to date`}),(0,I.jsx)(Iz,{...e})]})}function jz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort Smallest to Largest`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Gj,{size:14}),onClick:()=>e.onPrompt(t,Z.GREATER_THAN),children:`Greater than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uM,{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)(Kj,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN),children:`Less than...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uM,{size:14}),onClick:()=>e.onPrompt(t,Z.LESS_THAN_OR_EQUALS),children:`Less than or equal to...`}),(0,I.jsx)(Iz,{...e})]})}function Mz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(Iz,{...e})]})}function Nz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(dM,{size:14}),onClick:()=>e.onSort(t,!1),children:`Sort A to Z`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(fM,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(dj,{size:14}),onClick:()=>e.onPrompt(t,Z.CONTAINS),children:`Contains...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(uj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Does not contain...`}),(0,I.jsx)(Iz,{...e})]})}function Pz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{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)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.TEXT),children:`Text contains...`}),(0,I.jsx)(Iz,{...e})]})}function Fz(e){let{searchParam:t}=e;return(0,I.jsxs)(W.Dropdown,{children:[(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Aj,{size:14}),onClick:()=>e.onPrompt(t,Z.EQUALS),children:`Equals...`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(kj,{size:14}),onClick:()=>e.onPrompt(t,Z.NOT),children:`Does not equal...`}),(0,I.jsx)(Iz,{...e})]})}function Iz(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)(rj,{size:14}),onClick:()=>e.onChange(oz(e.search,n)),children:`Missing`}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(nj,{size:14}),onClick:()=>e.onChange(oz(e.search,n,!1)),children:`Not missing`}),(0,I.jsx)(W.Divider,{}),(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(wM,{size:14}),onClick:()=>e.onClear(t),children:`Clear filters`})]})}function Lz(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 Rz={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 zz(e){let t=e.resourceType,n=[];for(let r of e.fields||[`id`,`_lastUpdated`])n.push(Bz(t,r));return n}function Bz(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=Xw(e,t),r=Gw(e,t.toLowerCase());if(n&&r)return{name:t,elementDefinition:n,searchParams:[r]};if(n){let r=Ww(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:rk(e,r).elementDefinitions?.[0],searchParams:[r]}:{name:t}}var Vz=class extends Event{definition;constructor(e){super(`change`),this.definition=e}},Hz=class extends Event{response;constructor(e){super(`load`),this.response=e}},Uz=class extends Event{resource;browserEvent;constructor(e,t){super(`click`),this.resource=e,this.browserEvent=t}};function Wz(e){let t=Q(),[n,r]=(0,b.useState)(),{search:i,onLoad:a}=e,[o,s]=(0,b.useState)(i);PC(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,bE({...o,total:d,fields:void 0}),e)).then(e=>{l({...u.current,searchResponse:e}),a&&a(new Hz(e))}).catch(e=>{l({...u.current,searchResponse:void 0}),r(aS(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 Vz(t))}function v(t,n){if(MM(t.target)||t.button===2)return;AM(t);let r=jM(t);!r&&e.onClick&&e.onClick(new Uz(n,t)),r&&e.onAuxClick&&e.onAuxClick(new Uz(n,t))}function y(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(n)return(0,I.jsx)(VF,{outcome:n});if(!bS(o.resourceType))return(0,I.jsx)(Wp,{style:{width:`100%`,height:`100%`},children:(0,I.jsx)(ou,{})});let x=e.checkboxesEnabled,S=zz(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:Rz.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)(xj,{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)(Fj,{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)(Pj,{size:16}),onClick:e.onNew,children:`New...`}),!O&&y()&&(0,I.jsx)(U,{size:`compact-md`,variant:E,color:D,leftSection:(0,I.jsx)(_M,{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)(bM,{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)(oj,{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:[Jz(o,w).toLocaleString(),`-`,Yz(o,w).toLocaleString(),w.total!==void 0&&` of ${o.total===`estimate`?`~`:``}${w.total?.toLocaleString()}`]}),(0,I.jsx)(mu,{variant:E,color:D,title:`Refresh`,onClick:p,children:(0,I.jsx)(aM,{size:16})})]})]}),(0,I.jsxs)(K,{className:Rz.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)(fl,{className:Rz.control,p:2,children:(0,I.jsxs)(V,{justify:`space-between`,wrap:`nowrap`,children:[(0,I.jsx)(H,{fw:500,children:mz(e.name)}),(0,I.jsx)(Wp,{className:Rz.icon,children:(0,I.jsx)(ZA,{size:14,stroke:1.5})})]})})}),(0,I.jsx)(Oz,{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.additionalColumns?.map(e=>(0,I.jsx)(K.Th,{children:(0,I.jsx)(H,{fw:500,p:2,children:e.name})},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)(Gz,{resourceType:C,searchParams:e.searchParams,filters:o.filters})},e.name)),e.additionalColumns?.map(e=>(0,I.jsx)(K.Th,{},e.name))]})]}),(0,I.jsx)(K.Tbody,{children:T?.map(t=>t&&(0,I.jsxs)(K.Tr,{className:Rz.tr,"data-testid":`search-control-row`,onClick:e=>v(e,t),onAuxClick:e=>v(e,t),children:[x&&(0,I.jsx)(K.Td,{children:(0,I.jsx)(`input`,{type:`checkbox`,value:`checked`,"data-testid":`row-checkbox`,"aria-label":`Checkbox for ${t.id}`,checked:!!c.selected[t.id],onChange:e=>m(e,t.id)})}),S.map(e=>(0,I.jsx)(K.Td,{children:_z(t,e)},e.name)),e.additionalColumns?.map(e=>(0,I.jsx)(K.Td,{children:e.renderCell(t)},e.name))]},t.id))})]}),!T?.length&&(0,I.jsx)(hF,{children:(0,I.jsx)(Wp,{style:{height:150},children:(0,I.jsx)(H,{size:`xl`,c:`dimmed`,children:`No results`})})}),w&&(0,I.jsx)(Wp,{m:`md`,p:`md`,children:(0,I.jsx)(tv,{value:Kz(o),total:qz(o,w),onChange:e=>_(cz(o,e)),getControlProps:Lz})}),(0,I.jsx)(bz,{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)(wz,{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)(BR,{visible:c.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{l({...u.current,exportDialogVisible:!1})}},`search-export-dialog-${c.dialogOpenTime}`),(0,I.jsx)(Ez,{visible:c.filterDialogVisible,title:c.filterDialogSearchParam?.code?mz(c.filterDialogSearchParam.code):``,resourceType:C,searchParam:c.filterDialogSearchParam,filter:c.filterDialogFilter,defaultValue:``,onOk:e=>{_(KR(o,e.code,e.operator,e.value)),l({...u.current,filterDialogVisible:!1})},onCancel:()=>{l({...u.current,filterDialogVisible:!1})}},`search-filter-dialog-${c.dialogOpenTime}`)]})}function Gz(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:[pz(t.operator),`\xA0`,(0,I.jsx)(Dz,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function Kz(e){return Math.floor((e.offset??0)/(e.count??20))+1}function qz(e,t){let n=e.count??20,r=Xz(e,t);return Math.ceil(r/n)}function Jz(e,t){return Math.min(Xz(e,t),(e.offset??0)+1)}function Yz(e,t){return Math.max(Jz(e,t)+(t.entry?.length??0)-1,0)}function Xz(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 Zz(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(aS(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){MM(t.target)||(AM(t),t.button!==1&&e.onClick&&e.onClick(new Uz(n,t)),t.button===1&&e.onAuxClick&&e.onAuxClick(new Uz(n,t)))}if((0,b.useEffect)(()=>{t.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[t,e.resourceType]),!n)return(0,I.jsx)(ou,{});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)(zR,{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 Qz=(0,b.memo)(Zz),$z={root:`_root_1fbwr_1`,entry:`_entry_1fbwr_8`,key:`_key_1fbwr_13`,value:`_value_1fbwr_20`};function eB(e){return(0,I.jsx)(cl,{children:(0,I.jsx)(`div`,{className:$z.root,children:e.children})})}eB.Entry=function(e){return(0,I.jsx)(`div`,{className:$z.entry,children:e.children})},eB.Key=function(e){return(0,I.jsx)(`div`,{className:$z.key,children:e.children})},eB.Value=function(e){return(0,I.jsx)(`div`,{className:$z.value,children:e.children})};var tB={list:`_list_y4z6g_1`,link:`_link_y4z6g_6`};function nB(e){let{baseUrl:t,tabs:n,children:r,...i}=e,a=rB(n),o=Ok(),[s,c]=(0,b.useState)(()=>{let e=YE.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)(gb,{value:s,onChange:l,...i,children:[(0,I.jsx)(gb.List,{className:tB.list,children:a.map(e=>(0,I.jsx)(gb.Tab,{value:e.value,children:(0,I.jsx)(Md,{className:tB.link,href:`${t}/${e.value}`,onClick:iB,children:e.label})},e.value))}),r]})}function rB(e){return e.map(e=>UC(e)?{label:e,value:e.toLowerCase()}:e)}function iB(e){jM(e)||e.preventDefault()}function aB(e){let{group:t}=e;return(0,I.jsx)(_l,{withBorder:!0,radius:`md`,p:`xs`,display:`flex`,style:{alignItems:`center`,justifyContent:`center`},children:(0,I.jsxs)(V,{children:[t.measureScore&&(0,I.jsx)(cB,{group:t}),!t.measureScore&&(0,I.jsx)(sB,{group:t})]})})}function oB(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 sB(e){let{group:t}=e,n=t.population,r=n?.find(e=>Aw(e.code)===`numerator`),i=n?.find(e=>Aw(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)(iy,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:uB(s)}],label:(0,I.jsx)(hd,{justify:`center`,children:(0,I.jsxs)(H,{fw:700,fz:18,children:[a,` / `,o]})})})}function cB(e){let{group:t}=e,n=t.measureScore?.unit??t.measureScore?.code;return(0,I.jsx)(I.Fragment,{children:n===`%`?(0,I.jsx)(iy,{size:120,thickness:12,roundCaps:!0,sections:[{value:lB(t),color:uB(t?.measureScore?.value??0)}],label:(0,I.jsx)(hd,{justify:`center`,children:(0,I.jsx)(H,{fw:700,fz:18,children:(0,I.jsx)(mI,{value:t.measureScore})})})}):(0,I.jsx)(hd,{h:120,align:`center`,children:(0,I.jsx)(q,{order:3,children:(0,I.jsx)(mI,{value:t.measureScore})})})})}function lB(e){let t=e.measureScore?.value,n=e.measureScore?.unit;return t?t<=1&&n===`%`?t*100:t:0}function uB(e){return e<=33?`red`:e<=67?`yellow`:`green`}function dB(e){let t=Rk(e.measureReport),[n]=MA(`Measure`,{url:t?.measure});return t?(0,I.jsxs)(z,{children:[n&&(0,I.jsx)(oB,{measure:n}),(0,I.jsx)(gy,{cols:{base:3,sm:1},spacing:{base:`md`,sm:`sm`},children:t.group?.map((e,t)=>(0,I.jsx)(aB,{group:e},e.id??t))})]}):null}var fB=`patient-accounts`,pB=`Patient Accounts`,mB=[`Organization`,`HealthcareService`,`CareTeam`];function hB(e){let{patient:t}=e,n=Q(),r=n.isProjectAdmin()||n.isSuperAdmin(),i=(0,b.useMemo)(()=>gC(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){Lb.show({id:fB,title:pB,color:`red`,message:`Cannot update accounts: Patient resource has no ID.`,icon:(0,I.jsx)(wM,{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}]};Lb.show({id:fB,title:pB,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)),Lb.update({id:fB,title:pB,color:`green`,message:l?`Account changes saved. Compartment updates are being applied.`:`Account changes saved.`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0}),e.onSaved?.()}catch(e){Lb.update({id:fB,title:pB,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{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)(gB,{reference:e})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(WL,{value:e,link:!0})}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(mu,{variant:`subtle`,color:`red`,"aria-label":`Remove ${e.reference}`,onClick:()=>g(e.reference),children:(0,I.jsx)(wM,{size:16})})})]},e.reference))})]}),(0,I.jsx)(lm,{}),(0,I.jsx)(q,{order:4,children:`Add Account`}),(0,I.jsx)(dL,{name:`newAccount`,placeholder:`Search for Organization, HealthcareService, or CareTeam...`,targetTypes:mB,onChange:e=>{e&&h(e)}}),m&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(lm,{}),(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)(Ap,{color:`green`,variant:`light`,leftSection:(0,I.jsx)(rM,{size:12}),children:`Add`}):(0,I.jsx)(Ap,{color:`red`,variant:`light`,leftSection:(0,I.jsx)(Yj,{size:12}),children:`Remove`}),(0,I.jsx)(WL,{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)(tg,{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)(rM,{size:14,color:`green`}),(0,I.jsx)(WL,{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)(Yj,{size:14,color:`red`}),(0,I.jsx)(WL,{value:e.reference})]},e.reference.reference))})]}),(0,I.jsx)(sp,{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)(Td,{color:`blue`,title:`Admin access required`,children:`You need project admin access to manage patient account assignments.`})}function gB({reference:e}){let t=e.reference?.split(`/`)[0]??`Unknown`;return(0,I.jsx)(Ap,{variant:`light`,color:{Organization:`blue`,HealthcareService:`teal`,CareTeam:`violet`}[t]??`gray`,size:`sm`,children:t})}var _B=`patient-export`,vB=`Patient Export`,yB={everything:{operation:`$everything`,extension:`json`,contentType:lD.FHIR_JSON},summary:{operation:`$summary`,extension:`json`,contentType:lD.FHIR_JSON},ccda:{operation:`$ccda-export`,extension:`xml`,contentType:lD.CDA_XML},ccdaReferral:{operation:`$ccda-export`,type:`referral`,extension:`xml`,contentType:lD.CDA_XML}};function bB(e){let t=Q(),{patient:n}=e,[r,i]=(0,b.useState)(`everything`),[a,o]=(0,b.useState)(!1),s=(0,b.useCallback)(async e=>{let i=hC(n),{operation:o,type:s,contentType:c,extension:l}=yB[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=GI(e.authoredOn)),e.startDate&&(d.start=e.startDate),e.endDate&&(d.end=e.endDate),Lb.show({id:_B,title:vB,loading:!0,message:`Exporting...`,autoClose:!1,withCloseButton:!1});try{xB(await t.post(u,d,void 0,{cache:`no-cache`,headers:{Accept:c}}),`Patient-export-${i}-${new Date().toISOString().replaceAll(`:`,`-`)}.${l}`,c),Lb.update({id:_B,title:vB,color:`green`,message:`Done`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,autoClose:!0,withCloseButton:!0})}catch(e){Lb.update({id:_B,title:vB,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{size:`1rem`}),loading:!1,autoClose:!1,withCloseButton:!0})}},[t,n,r,a]);return(0,I.jsx)(hP,{onSubmit:s,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(NI,{title:`Export Format`,description:`Required`,withAsterisk:!0,children:(0,I.jsx)(cy,{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)(NI,{title:`Author`,description:`Optional author for composition. Default value is current user.`,children:(0,I.jsx)(dL,{name:`author`,placeholder:`Author`,targetTypes:[`Organization`,`Practitioner`,`PractitionerRole`]})}),(0,I.jsx)(NI,{title:`Authored On`,description:`Optional date for composition authored on. Default value is current date.`,children:(0,I.jsx)(KI,{name:`authoredOn`,placeholder:`Authored on`})}),(0,I.jsx)(NI,{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)(KI,{name:`startDate`,placeholder:`Start date`})}),(0,I.jsx)(NI,{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)(KI,{name:`endDate`,placeholder:`End date`})}),r===`everything`&&(0,I.jsx)(NI,{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)(sp,{label:`Inline attachments`,checked:a,onChange:e=>o(e.currentTarget.checked)})})}),(0,I.jsx)(V,{justify:`right`,children:(0,I.jsx)(gP,{children:`Request Export`})})]})})}function xB(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 SB(e){if(e.gender===`male`)return`blue`;if(e.gender===`female`)return`pink`}function CB(e){let t=Rk(e.patient);return t?(0,I.jsxs)(eB,{children:[(0,I.jsx)(HM,{value:t,size:`lg`,color:SB(t)}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Name`}),(0,I.jsx)(eB.Value,{children:(0,I.jsx)(IM,{to:t,fw:500,children:t.name?(0,I.jsx)(dI,{value:t.name[0],options:{use:!1}}):`[blank]`})})]}),t.birthDate&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`DoB`}),(0,I.jsx)(eB.Value,{children:t.birthDate})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Age`}),(0,I.jsx)(eB.Value,{children:wC(t.birthDate)})]})]}),t.gender&&(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Gender`}),(0,I.jsx)(eB.Value,{children:t.gender})]}),t.address&&(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`State`}),(0,I.jsx)(eB.Value,{children:t.address[0]?.state})]}),t.identifier?.map(e=>(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:e?.system}),(0,I.jsx)(eB.Value,{children:e?.value})]},`${e?.system}-${e?.value}`))]}):null}function wB(e){let{patient:t,...n}=e,r=(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})])},[]);return(0,I.jsx)(OR,{value:t,loadTimelineResources:r,createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,subject:pC(e),sender:pC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,subject:pC(e),operator:pC(t),issued:new Date().toISOString(),content:n}),...n})}var TB={section:`_section_pqpwm_1`,hovering:`_hovering_pqpwm_7`,editing:`_editing_pqpwm_11`};function EB(e){let t=Q(),n=Rk(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(PB(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)(hP,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(l),children:[(0,I.jsx)(_b,{label:`Plan Title`,py:`md`,defaultValue:l.title,onChange:e=>p(`title`,e.currentTarget.value)}),(0,I.jsx)(DB,{actions:l.action||[],selectedKey:a,setSelectedKey:o,hoverKey:s,setHoverKey:c,onChange:e=>p(`action`,e)}),(0,I.jsx)(gP,{children:`Save`})]})})}function DB(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:TB.section,children:[e.actions.map(n=>(0,I.jsx)(OB,{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:NB()})},children:`Add action`})})]})}function OB(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)(kB,{action:t,onChange:e.onChange,selectedKey:e.selectedKey,hoverKey:e.hoverKey,onRemove:e.onRemove})})}function kB(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=Mn(TB.section,{[TB.hovering]:u&&!l});return(0,b.useEffect)(()=>{(async()=>{if(!t.definitionCanonical)return;o(!0);let e=await i.readCanonical([`Questionnaire`,`ActivityDefinition`],t.definitionCanonical);r(jB(e)),c(e),o(!1)})().catch(console.error)},[t.definitionCanonical,i]),a?(0,I.jsx)(ou,{}):(0,I.jsxs)(_l,{"data-testid":t.id,className:f,p:0,radius:`sm`,withBorder:!0,children:[(0,I.jsxs)(hd,{w:`100%`,p:`xs`,bg:`gray.0`,gap:`md`,align:`center`,justify:`space-between`,children:[(0,I.jsx)(_b,{w:`100%`,name:`actionTitle-${t.id}`,defaultValue:t.title,placeholder:`Title`,onChange:e=>d(`title`,e.currentTarget.value)}),(0,I.jsx)(yu,{"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)(_b,{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)(wg,{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)(Md,{href:`/Questionnaire`,target:`_blank`,c:`blue`,children:`questionnaires list`})]}),(0,I.jsx)(AB,{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)(Md,{href:`/ActivityDefinition`,target:`_blank`,c:`blue`,children:`activity definitions list`})]}),(0,I.jsx)(AB,{resource:s,resourceType:`ActivityDefinition`,action:t,onChange:e.onChange,placeholder:`Search for activity definition`})]})]})]})}function AB(e){let{id:t}=e.action,{resource:n}=e;return(0,I.jsx)(uL,{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:mC(t)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function jB(e){return e===void 0?`standard`:e.resourceType.toLowerCase()}var MB=1;function NB(e){if(e){if(e.startsWith(`id-`)){let t=Number.parseInt(e.substring(3),10);Number.isNaN(t)||(MB=Math.max(MB,t+1))}return e}return`id-`+MB++}function PB(e){return{...e,action:FB(e.action)}}function FB(e){if(e)return e.map(e=>({...e,id:NB(e.id),action:FB(e.action)}))}var IB=`modulepreload`,LB=function(e){return`/`+e},RB={},zB=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,import.meta.url).href}r=o(t.map(t=>{if(t=LB(t,n),t=s(t),t in RB)return;RB[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`:IB,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)})},BB=150,VB;function HB({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-_>=BB)){_=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 UB(),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)(Td,{color:`red`,children:l}),(0,I.jsxs)(z,{pos:`relative`,style:{aspectRatio:`4 / 3`,display:l?`none`:`block`,width:`100%`,maxHeight:`70vh`,overflow:`hidden`,borderRadius:`var(--mantine-radius-default)`,background:`black`},children:[(0,I.jsx)(`video`,{ref:r,width:640,height:480,muted:!0,style:{display:`block`,width:`100%`,height:`100%`,objectFit:`cover`}}),s&&!l&&(0,I.jsx)(Wp,{pos:`absolute`,top:0,left:0,right:0,bottom:0,style:{pointerEvents:`none`},children:(0,I.jsxs)(G,{gap:`xs`,align:`center`,children:[(0,I.jsx)(ou,{size:`sm`,color:`gray.3`}),(0,I.jsx)(H,{c:`gray.3`,size:`sm`,children:`Loading camera...`})]})})]}),(0,I.jsx)(`canvas`,{ref:i,hidden:!0})]})}async function UB(){return VB||=zB(()=>import(`./jsQR-CGGgbypu.js`).then(e=>c(e.default,1)).then(e=>e.default),[]).catch(e=>{throw VB=void 0,Error(`QR code scanning requires the optional "jsqr" dependency. Install jsqr to use QrCodeScanner. ${Y(e)}`)}),VB}var WB=30,GB=50;function KB(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!==Bk.choice&&n.type!==Bk.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!==Bk.choice&&n.type!==Bk.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=tV(r,e.index)??SA(c),u=EC(r,`${Ex}/fhir/StructureDefinition/questionnaire-validationError`),d=null;switch(a){case Bk.display:d=(0,I.jsx)(`p`,{children:e.item.text},e.item.linkId);break;case Bk.boolean:d=(0,I.jsx)(MI,{title:e.item.text,htmlFor:s,children:(0,I.jsx)(sp,{id:s,name:o,required:e.required??n.required,defaultChecked:l?.value,onChange:e=>i([{valueBoolean:e.currentTarget.checked}])})},e.item.linkId);break;case Bk.decimal:d=(0,I.jsx)(_b,{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 Bk.integer:d=(0,I.jsx)(_b,{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 Bk.date:d=(0,I.jsx)(_b,{type:`date`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDate:e.currentTarget.value}])});break;case Bk.dateTime:d=(0,I.jsx)(KI,{name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueDateTime:e}])});break;case Bk.time:d=(0,I.jsx)(_b,{type:`time`,id:s,name:o,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueTime:e.currentTarget.value}])});break;case Bk.string:case Bk.url:d=(0,I.jsx)(_b,{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 Bk.text:d=(0,I.jsx)(ih,{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 Bk.attachment:d=(0,I.jsx)(V,{py:4,children:(0,I.jsx)(pF,{path:``,name:s,defaultValue:l?.value,onChange:e=>i([{valueAttachment:e}])})});break;case Bk.reference:d=(0,I.jsx)(dL,{name:s,required:e.required??n.required,targetTypes:pA(n),searchCriteria:hA(n,t?.subject,t?.encounter),defaultValue:l?.value,onChange:e=>i([{valueReference:e}])});break;case Bk.quantity:d=(0,I.jsx)(eL,{path:``,name:s,required:e.required??n.required,defaultValue:l?.value,onChange:e=>i([{valueQuantity:e}]),disableWheel:!0});break;case Bk.choice:case Bk.openChoice:{let{widget:t,multiselect:a}=aV(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)($B,{...o}):t===`drop-down`?(0,I.jsx)(qB,{...o}):(0,I.jsx)(QB,{...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 qB(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)(eV,{});let c=SA(i),l=tV(o)??c,u=nV(o),d=n.repeats||s;if(n.answerValueSet)return(0,I.jsx)(wP,{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}=oV(n);return(0,I.jsx)(bg,{data:t,placeholder:`Select items`,searchable:!0,value:u,required:r,onChange:t=>{if(t.length===0)a([{}]);else{let r=cA(t,e,n);a(r)}}})}{let e=[``];if(n.answerOption)for(let t of n.answerOption){let n=CA(t);e.push(mw(n))}return(0,I.jsx)(wg,{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=CA(r),o=`value`+ZC(i.type);a([{[o]:i.value}])},defaultValue:jw(l?.value)||l?.value,data:e})}}function JB(e,t){return e?t.valueSetExpand({url:e,count:31}).then(e=>e.expansion?.contains??[]):Promise.resolve([])}function YB(e){let t=Q(),[n,r]=(0,b.useState)([]),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(()=>!e||void 0);return(0,b.useEffect)(()=>{async function n(){if(!e){s(!0);return}a(!0),s(void 0);try{let n=await JB(e,t);r(n),s(!0)}catch(e){let t=FA(e);s(!t),t||console.error(`Error loading value set:`,e)}finally{a(!1)}}n().catch(console.error)},[e,t]),{options:n,loading:i,available:o}}function XB({valueSetUrl:e}){return(0,I.jsx)(yP,{text:`Suggestions unavailable`,color:`yellow.9`,message:`Value set ${e} is unavailable`})}function ZB(e,t){return e.map((e,n)=>[`${t}-valueset-${n}`,{type:`Coding`,value:{system:e.system,code:e.code,display:e.display}}])}function QB(e){let{name:t,item:n,required:r,initial:i,onChangeAnswer:a,response:o}=e,s=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),c=SA(i),{options:l,loading:u,available:d}=YB(n.answerValueSet),f=[],p;if(n.answerValueSet)f.push(...ZB(l,t));else if(n.answerOption){let e=n.answerOption.slice(0,GB).map((e,n)=>{let r=`${t}-option-${n}`,i=CA(e);return i?.value?(c&&DC(i)===DC(c)&&(p=r),[r,i]):null}).filter(e=>e!==null);f.push(...e)}let m=rV(f,tV(o));if(u)return(0,I.jsx)(H,{children:`Loading options...`});if(f.length===0)return d===!1?(0,I.jsx)(XB,{valueSetUrl:n.answerValueSet}):(0,I.jsx)(eV,{});let h=f.slice(0,WB);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Mv.Group,{name:t,value:m??p,required:r,onChange:e=>{let t=f.find(t=>t[0]===e);if(t){let e=t[1],n=`value`+ZC(e.type);a([{[n]:e.value}])}},children:h.map(([e,t])=>(0,I.jsx)(Mv,{id:e,value:e,py:4,required:r,label:(0,I.jsx)(wI,{property:s,propertyType:t.type,value:t.value})},e))}),(n.answerValueSet&&f.length>WB||n.answerOption&&f.length>GB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,mt:`xs`,children:[`Showing first `,WB,` options`]})]})}function $B(e){let{name:t,item:n,onChangeAnswer:r,response:i}=e,a=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),{options:o,loading:s,available:c}=YB(n.answerValueSet),l=n.answerValueSet?(i?.answer?.map(e=>e.valueCoding)||[]).filter(e=>e!==void 0):nV(i),u=[];if(n.answerValueSet)u.push(...ZB(o,t));else if(n.answerOption){let e=n.answerOption.slice(0,GB).map((e,n)=>{let r=`${t}-option-${n}`,i=CA(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 c===!1?(0,I.jsx)(XB,{valueSetUrl:n.answerValueSet}):(0,I.jsx)(eV,{});let d=u.slice(0,WB),f=(e,t)=>{if(n.answerValueSet){let n=l,i;i=t?[...n,e.value]:n.filter(t=>!PC(t,e.value)),i.length===0?r([{}]):r(i.map(e=>({valueCoding:e})))}else{let i=l,a=mw(e),o;if(o=t?[...i,a]:i.filter(e=>e!==a),o.length===0)r([{}]);else{let t=cA(o,`value`+ZC(e.type),n);r(t)}}};return(0,I.jsxs)(V,{style:{flexDirection:`column`,alignItems:`flex-start`},children:[d.map(([e,t])=>{let r=mw(t),i=n.answerValueSet?l.some(e=>PC(e,t.value)):l.includes(r);return(0,I.jsx)(sp,{id:e,label:(0,I.jsx)(wI,{property:a,propertyType:t.type,value:t.value}),checked:i,onChange:e=>f(t,e.currentTarget.checked)},e)}),(n.answerValueSet&&u.length>WB||n.answerOption&&u.length>GB)&&(0,I.jsxs)(H,{size:`sm`,c:`dimmed`,children:[`Showing first `,WB,` options`]})]})}function eV(){return(0,I.jsx)(_b,{disabled:!0,placeholder:`No Answers Defined`})}function tV(e,t=0){return CA(e?.answer?.[t]??{})}function nV(e){let t=e?.answer;return t?t.map(e=>CA(e)).map(e=>jw(e?.value)||e?.value).filter(Boolean):[]}function rV(e,t){return e.find(e=>PC(e[1].value,t?.value))?.[0]}var iV=[`drop-down`,`radio-button`,`check-box`];function aV(e){let t=`radio-button`,n=!1;e.answerValueSet&&(t=`drop-down`);for(let r of e.extension??[]){if(r.url!==Vk)continue;let e=r.valueCodeableConcept?.coding?.[0]?.code;iV.includes(e)&&(t=e),e===`multi-select`&&(n=!0)}return t===`radio-button`&&n&&(t=`check-box`),{widget:t,multiselect:n}}function oV(e){if(e.answerOption?.length===0)return{propertyName:``,data:[]};let t=e.answerOption[0];return{propertyName:`value`+ZC(CA(t).type),data:(e.answerOption??[]).map(e=>{let t=mw(CA(e));return{value:t,label:t}})}}var sV={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 cV(e){let t=Q(),n=Rk(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(_V(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)(hP,{testid:`questionnaire-form`,onSubmit:()=>e.onSubmit(a),children:[(0,I.jsx)(lV,{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)(gP,{children:`Save`})]})})}function lV(e){let t=e.item,n=e.item,r=Qw(e.item),i=r||n.type===Bk.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=xV(e.item.item,t,n);e.onChange({...e.item,item:r})}let v=Mn(sV.section,{[sV.editing]:o,[sV.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:sV.questionBody,children:o?(0,I.jsxs)(I.Fragment,{children:[r&&(0,I.jsx)(_b,{size:`xl`,defaultValue:t.title,onBlur:e=>m(`title`,e.currentTarget.value)}),!r&&(0,I.jsx)(ih,{autosize:!0,minRows:2,defaultValue:n.text,onBlur:e=>m(`text`,e.currentTarget.value)}),n.type===`reference`&&(0,I.jsx)(fV,{item:n,onChange:h}),Zk(n)&&(0,I.jsx)(uV,{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:sV.preserveBreaks,children:n.text}),!i&&(0,I.jsx)(KB,{item:n,index:0,required:!1,responseItem:{linkId:n.linkId}})]})}),n.item?.map((t,n)=>(0,I.jsx)(`div`,{children:(0,I.jsx)(lV,{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:sV.topActions,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(_b,{size:`xs`,className:sV.linkIdInput,defaultValue:n.linkId,onBlur:e=>m(`linkId`,e.currentTarget.value)}),!i&&(0,I.jsx)(wg,{size:`xs`,className:sV.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:sV.movementActions,children:(0,I.jsxs)(z,{className:sV.columnAlignment,children:[!e.isFirst&&(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,I.jsx)(tj,{"data-testid":`up-button`,size:15,className:sV.movementIcons})}),!e.isLast&&(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,I.jsx)(ej,{"data-testid":`down-button`,size:15,className:sV.movementIcons})})]})}),(0,I.jsxs)(`div`,{className:sV.bottomActions,children:[i&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f({id:gV(),linkId:hV(`q`),type:`string`,text:`Question`})},children:`Add item`}),(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f({id:gV(),linkId:hV(`g`),type:`group`,text:`Group`},!0)},children:`Add group`})]}),r&&(0,I.jsx)(Md,{href:`#`,onClick:e=>{e.preventDefault(),f(bV(),!0)},children:`Add Page`}),o&&!r&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onRepeatable&&e.onRepeatable(n)},children:n.repeats?`Remove Repeatable`:`Make Repeatable`}),(0,I.jsx)(Md,{href:`#`,onClick:t=>{t.preventDefault(),e.onRemove&&e.onRemove()},children:`Remove`})]})]})]})}function uV(e){let t=Xw(`QuestionnaireItemAnswerOption`,`value[x]`),n=e.item.answerOption??[];return(0,I.jsxs)(`div`,{children:[e.item.answerValueSet===void 0?(0,I.jsx)(dV,{options:n,property:t,item:e.item,onChange:e.onChange}):(0,I.jsx)(_b,{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)(Md,{href:`#`,onClick:t=>{AM(t),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...n,{id:gV()}]})},children:`Add choice`}),(0,I.jsx)(xy,{w:`lg`}),(0,I.jsx)(Md,{href:`#`,onClick:t=>{AM(t),e.onChange({...e.item,answerOption:[],answerValueSet:``})},children:`Add value set`})]})]})}function dV(e){return(0,I.jsx)(`div`,{children:e.options.map(t=>{let[n,r]=cI({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)(OL,{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)(Md,{href:`#`,onClick:n=>{AM(n),e.onChange({...e.item,answerOption:e.options.filter(e=>e.id!==t.id)})},children:`Remove`})})]},t.id)})})}function fV(e){let t=pA(e.item)??[];return(0,I.jsxs)(I.Fragment,{children:[t.map((n,r)=>(0,I.jsxs)(V,{children:[(0,I.jsx)(AP,{name:`resourceType`,placeholder:`Resource Type`,defaultValue:n,onChange:r=>{e.onChange(mA(e.item,t.map(e=>e===n?r:e)))}}),(0,I.jsx)(Md,{href:`#`,onClick:r=>{AM(r),e.onChange(mA(e.item,t.filter(e=>e!==n)))},children:`Remove`})]},`${n}-${r}`)),(0,I.jsx)(Md,{href:`#`,onClick:n=>{AM(n),e.onChange(mA(e.item,[...t,``]))},children:`Add Resource Type`})]})}var pV=1,mV=1;function hV(e){return e+pV++}function gV(){return`id-`+mV++}function _V(e){return{...e,id:e.id||gV(),item:vV(e.item)}}function vV(e){if(e)return e.forEach(e=>{e.id?.match(/^id-\d+$/)&&(mV=Math.max(mV,Number.parseInt(e.id.substring(3),10)+1)),e.linkId?.match(/^q\d+$/)&&(pV=Math.max(pV,Number.parseInt(e.linkId.substring(1),10)+1))}),e.map(e=>({...e,id:e.id||gV(),item:vV(e.item),answerOption:yV(e.answerOption)}))}function yV(e){if(e)return e.map(e=>({...e,id:e.id||gV()}))}function bV(){return{id:gV(),linkId:hV(`s`),type:`group`,text:`New Page`,extension:[{url:Vk,valueCodeableConcept:{coding:[{system:`http://hl7.org/fhir/questionnaire-item-control`,code:`page`}]}}]}}function xV(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 SV=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)}},CV=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}startPoint;control2;control1;endPoint;startWidth;endWidth;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 SV(s.x+h,s.y+g),c2:new SV(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}},wV=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 TV(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 EV=class e extends wV{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?TV(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()}canvas;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._drawLine.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})}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 SV(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=CV.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()}_getDotSize(e){return e.dotSize>0?e.dotSize:(e.minWidth+e.maxWidth)/2}_drawDot(e,t){let n=this._ctx,r=this._getDotSize(t);n.beginPath(),this._drawCurveSegment(e.x,e.y,r),n.closePath(),n.fillStyle=t.penColor,n.fill()}_drawLine(e,t,n){let r=this._ctx;r.save(),r.beginPath(),r.moveTo(e.x,e.y),r.lineTo(t.x,t.y),r.lineWidth=this._getDotSize(n)*2,r.lineCap=`round`,r.strokeStyle=n.penColor,r.stroke(),r.restore(),this._isEmpty=!1}_fromData(e,t,n,r){for(let i of e){let{points:e}=i,a=this._getPointGroupOptions(i);if(e.length>2)for(let n=0;n<e.length;n+=1){let r=e[n],i=new SV(r.x,r.y,r.pressure,r.time);n===0&&this._reset(a);let o=this._addPoint(i,a);o&&t(o,a)}else e.length===2?(this._reset(a),r(e[0],e[1],a)):(this._reset(a),n(e[0],a))}}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)},(e,t,n)=>{let r=document.createElement(`line`);r.setAttribute(`x1`,e.x.toString()),r.setAttribute(`y1`,e.y.toString()),r.setAttribute(`x2`,t.x.toString()),r.setAttribute(`y2`,t.y.toString()),r.setAttribute(`stroke`,n.penColor),r.setAttribute(`stroke-width`,(this._getDotSize(n)*2).toString()),r.setAttribute(`stroke-linecap`,`round`),o.appendChild(r)}),o.outerHTML}};function DV(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:Ex+`/fhir/signature-type`,code:`ProofOfOrigin`,display:`Proof of Origin`}],when:new Date().toISOString(),who:a??pC(t.getProfile()),data:l.current?.toDataURL().split(`,`)[1]})}if(c.current){let t=new EV(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)(_l,{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)(bM,{size:16}),variant:`subtle`,color:`gray`,children:`Clear`})]})}function OV(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)(jV,{formState:e.formState,context:t,items:e.item.item??[],responseItems:e.responseItem.item??[]})]},e.item.linkId)}function kV(e){return(0,I.jsxs)(I.Fragment,{children:[e.responseItems.map(t=>(0,I.jsx)(OV,{formState:e.formState,context:e.context,item:e.item,responseItem:t},`group-${t.id}`)),(0,I.jsx)(Md,{onClick:()=>e.formState.onAddGroup(e.context,e.item),children:`Add Group: ${e.item.text}`})]})}function AV(e){let{formState:t,context:n,item:r,responseItem:i}=e,a=r.type===Bk.choice||r.type===Bk.openChoice,o=!a,s=!a&&i.answer&&i.answer.length>0?i.answer:[{}];return(0,I.jsxs)(NI,{title:e.item.text,withAsterisk:e.item.required,children:[(0,I.jsx)(G,{gap:`xs`,children:s?.map((e,a)=>(0,I.jsx)(KB,{formState:t,context:n,item:r,responseItem:i,index:a},`${r.linkId}-${a}`))}),o&&(0,I.jsx)(Md,{onClick:()=>t.onAddAnswer(n,r),children:`Add Item`})]},e.item.linkId)}function jV(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(!eA(e,t.questionnaireResponse))return null;let s=e.type===Bk.group,c=a&&s&&o;if(s&&(o=!0),e.type===Bk.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===Bk.group&&e.repeats?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(lm,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(kV,{formState:t,context:n,item:e,responseItems:l})]},`repeating-group-${e.id}-${r}`):e.type===Bk.group?(0,I.jsxs)(b.Fragment,{children:[c&&(0,I.jsx)(lm,{color:`var(--mantine-color-gray-2)`}),(0,I.jsx)(OV,{formState:t,context:n,item:e,responseItem:l[0]})]},`group-${e.id}-${r}`):e.type===Bk.boolean?(0,I.jsx)(KB,{formState:t,context:n,item:e,responseItem:l[0],index:0},`boolean-item-${e.id}-${r}`):e.repeats?(0,I.jsx)(AV,{formState:t,context:n,item:e,responseItem:l[0]},`repeating-item-${e.id}-${r}`):(0,I.jsx)(NI,{htmlFor:e.linkId,title:e.text,withAsterisk:e.required,children:(0,I.jsx)(KB,{formState:t,context:n,item:e,responseItem:l[0],index:0})},`repeating-item-${e.id}-${r}`)})})}function MV(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)(Py,{active:o,allowNextStepsSelect:!1,p:6,children:a.map((e,t)=>(0,I.jsx)(Py.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)(gP,{children:n??`Submit`})]})]})}function NV(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=EA({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&&!!EC(s.questionnaire,qk),[s]),u=(0,b.useMemo)(()=>!s.loading&&!!s.questionnaireResponse.extension?.find(e=>e.url===Jk),[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=pC(e))}n({...o,questionnaire:a.url??mC(a),subject:s,source:d,authored:new Date().toISOString(),status:`completed`})},[t,l,u]);return s.loading?null:(0,I.jsxs)(hP,{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)(lm,{color:`var(--mantine-color-gray-2)`})]}),s.pagination?(0,I.jsx)(MV,{formState:s,submitButtonText:e.submitButtonText,excludeButtons:e.excludeButtons,children:(0,I.jsx)(jV,{formState:s,context:[],items:s.items,responseItems:s.responseItems})}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(jV,{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)(DV,{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)(gP,{children:e.submitButtonText??`Submit`})})]})]})}var PV={section:`_section_4m5it_1`},FV=[`gender`,`age`,`gestationalAge`,`context`,`appliesTo`,`category`],IV={definition:{resourceType:`ObservationDefinition`,code:{text:``}},onSubmit:()=>{}};function LV(e){e=Object.assign(IV,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)(()=>{let e=BV(t,s);r(VV(e.qualifiedInterval||[],a))},[t]),(0,I.jsxs)(hP,{testid:`reference-range-editor`,onSubmit:c,children:[(0,I.jsx)(G,{children:n.map(e=>(0,I.jsx)(RV,{unit:UV(t.quantitativeDetails?.unit),onChange:d,onAdd:f,onRemove:p,onRemoveGroup:u,intervalGroup:e},`group-${e.id}`))}),(0,I.jsx)(mu,{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)(yj,{})}),(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(gP,{children:`Save`})})]});function c(){let r=n.flatMap(e=>e.intervals).filter(e=>!WV(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 RV(e){let{intervalGroup:t,unit:n}=e;return(0,I.jsx)(hF,{"data-testid":t.id,className:PV.section,children:(0,I.jsxs)(G,{gap:`lg`,children:[(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsx)(mu,{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)(vj,{})},`remove-group-button-${t.id}`)}),(0,I.jsx)(zV,{intervalGroup:t,onChange:e.onChange}),(0,I.jsx)(lm,{}),t.intervals.map(n=>(0,I.jsxs)(G,{gap:`xs`,children:[(0,I.jsxs)(V,{children:[(0,I.jsx)(_b,{"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)(mu,{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)(vj,{})},`remove-interval-${n.id}`)]}),(0,I.jsx)(nL,{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)(mu,{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)(yj,{})})]})})}function zV(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)(wg,{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)(nL,{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)(wg,{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)(wg,{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 BV(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 VV(e,t){let n=1,r={};for(let t of e){let e=HV(t);e in r||(r[e]={id:`group-id-${n++}`,filters:Object.fromEntries(FV.map(e=>[e,t[e]])),intervals:[]}),r[e].intervals.push(t)}return t(n),Object.values(r)}function HV(e){return[`gender=${e.gender}`,`age=${Dw(e.age)}`,`gestationalAge=${Dw(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(e=>e.text).join(`+`)}`,`category=${e.category}`].join(`:`)}function UV(e){return e&&(ew(e,`http://unitsofmeasure.org`)||e.text)}function WV(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}function GV(e){let t=Q(),n=Rk(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)(Cm,{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)(Cm.Col,{span:1,p:`md`,children:r?.status===`completed`?(0,I.jsx)(hj,{}):(0,I.jsx)(pM,{color:`gray`})}),(0,I.jsxs)(Cm.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)(UL,{value:r?.meta?.author}),`\xA0on\xA0`,bw(r?.meta?.lastUpdated)]}),(0,I.jsxs)(`div`,{children:[`Status: `,(0,I.jsx)(BL,{status:r?.status||`unknown`})]})]}),(0,I.jsxs)(Cm.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===mC(t.resource))return t.resource}}function KV(e,t){return JV(qV(e,t),e,t)}function qV(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:YV(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 JV(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 YV(e){return e&&!e.snake&&e.prev?e.prev:e}function XV(e){let t=(e.entry??[]).filter(e=>!!e.resource).map(e=>({meta:e.resource?.meta,lines:DC(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 ZV(n,t),QV(n),n}function ZV(e,t){for(let n=1;n<t.length;n++){let r=KV(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 QV(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 $V={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 eH(e,t){return`/${e.resourceType}/${e.id}/_history/${t}`}function tH(e){let t=Math.floor((Date.now()-Date.parse(e))/1e3),n=Math.floor(t/31536e3);if(n>0)return nH(n,`year`);let r=Math.floor(t/2592e3);if(r>0)return nH(r,`month`);let i=Math.floor(t/86400);if(i>0)return nH(i,`day`);let a=Math.floor(t/3600);if(a>0)return nH(a,`hour`);let o=Math.floor(t/60);return o>0?nH(o,`minute`):nH(t,`second`)}function nH(e,t){return`${e} ${e===1?t:t+`s`} ago`}function rH(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=XV(n);return(0,I.jsx)(`div`,{className:$V.container,children:(0,I.jsx)(`table`,{className:$V.root,children:(0,I.jsx)(`tbody`,{children:a.map((e,t)=>(0,I.jsxs)(`tr`,{className:e.span>0?$V.startRow:$V.normalRow,children:[e.span>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`td`,{className:$V.author,rowSpan:e.span,children:[(0,I.jsx)(UL,{value:e.meta.author,link:!0,fz:`xs`}),e.meta.onBehalfOf&&(0,I.jsxs)(`div`,{className:$V.onBehalfOf,children:[`on behalf of `,(0,I.jsx)(UL,{value:e.meta.onBehalfOf,link:!0,fz:`xs`,c:`dimmed`})]})]}),(0,I.jsx)(`td`,{className:$V.dateTime,rowSpan:e.span,children:(0,I.jsx)(IM,{to:eH(i,e.meta.versionId),fz:`xs`,children:tH(e.meta.lastUpdated)})})]}),(0,I.jsx)(`td`,{className:$V.lineNumber,children:t+1}),(0,I.jsx)(`td`,{className:$V.line,children:(0,I.jsx)(`pre`,{className:$V.pre,children:e.value})})]},`row-`+t))})})})}var iH={removed:`_removed_el5zk_1`,added:`_added_el5zk_6`};function aH(e){let t=e.original,n=e.revised;e.ignoreMeta&&(t={...t,meta:void 0},n={...n,meta:void 0});let r=KV(DC(t,!0).match(/[^\r\n]+/g)??[`{`,`}`],DC(n,!0).match(/[^\r\n]+/g)??[`{`,`}`]);return(0,I.jsx)(`pre`,{style:{color:`gray`},children:r.map((e,t)=>(0,I.jsx)(oH,{delta:e},`delta`+t))})}function oH(e){return(0,I.jsxs)(I.Fragment,{children:[`...`,(0,I.jsx)(`br`,{}),e.delta.original.lines.length>0&&(0,I.jsx)(`div`,{className:iH.removed,children:e.delta.original.lines.join(`
|
|
209
209
|
`)}),e.delta.revised.lines.length>0&&(0,I.jsx)(`div`,{className:iH.added,children:e.delta.revised.lines.join(`
|
|
210
210
|
`)}),`...`,(0,I.jsx)(`br`,{})]})}var sH={splitButton:`_splitButton_1i0gi_1`,menuControl:`_menuControl_1i0gi_6`};function cH(e){let{outcome:t}=e,n=Q(),r=Rk(e.defaultValue),i=r?.resourceType,[a,o]=(0,b.useState)(!1),[s,c]=(0,b.useState)(),l=n.getAccessPolicy(),u=Sr();(0,b.useEffect)(()=>{if(r){if(e.profileUrl){let t=e.profileUrl;n.requestProfileSchema(e.profileUrl,{expandProfile:!0}).then(()=>{let e=wS(t);if(e){o(!0);let t=jO(r,e);c(t)}else 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&&WE(r,BE.READ,l),[l,r]),f=(0,b.useMemo)(()=>n.isSuperAdmin()||!l||!MC(s?.resourceType)?!0:HE(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)(NI,{title:`Resource Type`,htmlFor:`resourceType`,outcome:t,children:(0,I.jsx)(_b,{name:`resourceType`,defaultValue:s.resourceType,disabled:!0})}),(0,I.jsx)(NI,{title:`ID`,htmlFor:`id`,outcome:t,children:(0,I.jsx)(_b,{name:`id`,defaultValue:s.id,disabled:!0})})]}),(0,I.jsx)(FL,{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:Mn((e.onPatch||e.onDelete)&&sH.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)(mu,{variant:`filled`,color:u.primaryColor,size:36,className:sH.menuControl,"aria-label":`More actions`,children:(0,I.jsx)(gj,{size:14,stroke:1.5})})}),(0,I.jsxs)(W.Dropdown,{children:[e.onPatch&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Oj,{size:14,stroke:1.5}),onClick:()=>{e.onPatch(s)},children:`Patch`}),e.onDelete&&(0,I.jsx)(W.Item,{color:`red`,leftSection:(0,I.jsx)(bM,{size:14,stroke:1.5,color:`red`}),onClick:()=>{e.onDelete(s)},children:`Delete`})]})]})]})]}):(0,I.jsxs)(Td,{color:`red`,title:`Permission denied`,icon:(0,I.jsx)(QA,{}),children:[`Your access level prevents you from editing and creating `,s.resourceType,` resources.`]})}function lH(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)(uH,{entry:e},`entry-`+t))})]}):(0,I.jsx)(`div`,{children:`Loading...`})}function uH(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)(WL,{value:n.meta?.author,link:!0})}),(0,I.jsx)(K.Td,{children:n.meta?.onBehalfOf&&(0,I.jsx)(WL,{value:n.meta.onBehalfOf,link:!0})}),(0,I.jsx)(K.Td,{children:bw(n.meta?.lastUpdated)}),(0,I.jsx)(K.Td,{children:(0,I.jsx)(IM,{to:dH(n),children:n.meta?.versionId})})]}):(0,I.jsx)(K.Tr,{children:(0,I.jsx)(K.Td,{colSpan:4,children:Y(t?.outcome)})})}function dH(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}var fH=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,pH=/^[\\/]{2}/;function mH(e,t){return t+e.replace(/\\/g,`/`)}var hH=`popstate`;function gH(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function _H(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return SH(``,{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:CH(t)}return TH(t,n,null,e)}function vH(e,t){if(e===!1||e==null)throw Error(t)}function yH(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function bH(){return Math.random().toString(36).substring(2,10)}function xH(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 SH(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?wH(t):t,state:n,key:t&&t.key||r||bH(),mask:i}}function CH({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 wH(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 TH(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=gH(e)?e:SH(h.location,e,t);n&&n(r,e),l=u()+1;let d=xH(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=gH(e)?e:SH(h.location,e,t);n&&n(r,e),l=u();let i=xH(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 EH(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(hH,d),c=e,()=>{i.removeEventListener(hH,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 EH(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),vH(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:CH(t);return i=i.replace(/ $/,`%20`),!n&&pH.test(i)&&(i=r+i),new URL(i,r)}var DH=class{#e=new Map;constructor(e){if(e)for(let[t,n]of e)this.set(t,n)}get(e){if(this.#e.has(e))return this.#e.get(e);if(e.defaultValue!==void 0)return e.defaultValue;throw Error(`No value found for context`)}set(e,t){this.#e.set(e,t)}},OH=new Set([`lazy`,`caseSensitive`,`path`,`id`,`index`,`children`]);function kH(e){return OH.has(e)}var AH=new Set([`lazy`,`caseSensitive`,`path`,`id`,`index`,`middleware`,`children`]);function jH(e){return AH.has(e)}function MH(e){return e.index===!0}function NH(e){let t={};return e.Component&&Object.assign(t,{element:b.createElement(e.Component),Component:void 0}),e.HydrateFallback&&Object.assign(t,{hydrateFallbackElement:b.createElement(e.HydrateFallback),HydrateFallback:void 0}),e.ErrorBoundary&&Object.assign(t,{errorElement:b.createElement(e.ErrorBoundary),ErrorBoundary:void 0}),t}function PH(e,t=NH,n=[],r={},i=!1){return e.map((e,a)=>{let o=[...n,String(a)],s=typeof e.id==`string`?e.id:o.join(`-`);if(vH(e.index!==!0||!e.children,`Cannot specify children on an index route`),vH(i||!r[s],`Found a route id collision on id "${s}". Route id's must be globally unique within Data Router usages`),MH(e)){let n={...e,id:s};return r[s]=FH(n,t(n)),n}{let n={...e,id:s,children:void 0};return r[s]=FH(n,t(n)),e.children&&(n.children=PH(e.children,t,o,r,i)),n}})}function FH(e,t){return Object.assign(e,{...t,...typeof t.lazy==`object`&&t.lazy!=null?{lazy:{...e.lazy,...t.lazy}}:{}})}function IH(e,t,n=`/`){return LH(e,t,n,!1)}function LH(e,t,n,r,i){let a=aU((typeof t==`string`?wH(t):t).pathname||`/`,n);if(a==null)return null;let o=i??zH(e),s=null,c=iU(a);for(let e=0;s==null&&e<o.length;++e)s=eU(o[e],c,r);return s}function RH(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,loaderData:t[n.id],handle:n.handle}}function zH(e){let t=BH(e);return HH(t),t}function BH(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;vH(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=hU([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(vH(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),BH(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:QH(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=rU(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 VH(e.path))a(e,t,!0,n)}),t}function VH(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=VH(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 HH(e){e.sort((e,t)=>e.score===t.score?$H(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var UH=/^:[\w-]+$/,WH=/^:[\w-]+/,GH=3.5,KH=3,qH=2,JH=1,YH=10,XH=-2,ZH=e=>e===`*`;function QH(e,t){let n=e.split(`/`),r=n.length;return n.some(ZH)&&(r+=XH),t&&(r+=qH),n.filter(e=>!ZH(e)).reduce((e,t)=>e+(UH.test(t)?KH:WH.test(t)?GH:t===``?JH:YH),r)}function $H(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 eU(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?nU(u,l,s.matcher,s.compiledParams):tU(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=tU({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:hU([a,d.pathname]),pathnameBase:_U(hU([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=hU([a,d.pathnameBase]))}return o}function tU(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=rU(e.path,e.caseSensitive,e.end);return nU(e,t,n,r)}function nU(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 e[t]=n&&!i?void 0:(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function rU(e,t=!1,n=!0){yH(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)?`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function iU(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return yH(!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 aU(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 oU({basename:e,pathname:t}){return t===`/`?e:hU([e,t])}var sU=e=>fH.test(e);function cU(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?wH(e):e,a;return n?(n=mU(n),a=n.startsWith(`/`)?lU(n.substring(1),`/`):lU(n,t)):a=t,{pathname:a,search:vU(r),hash:yU(i)}}function lU(e,t){let n=gU(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function uU(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 dU(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function fU(e){let t=dU(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function pU(e,t,n,r=!1){let i;typeof e==`string`?i=wH(e):(i={...e},vH(!i.pathname||!i.pathname.includes(`?`),uU(`?`,`pathname`,`search`,i)),vH(!i.pathname||!i.pathname.includes(`#`),uU(`#`,`pathname`,`hash`,i)),vH(!i.search||!i.search.includes(`#`),uU(`#`,`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=cU(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var mU=e=>e.replace(/[\\/]{2,}/g,`/`),hU=e=>mU(e.join(`/`)),gU=e=>e.replace(/\/+$/,``),_U=e=>gU(e).replace(/^\/*/,`/`),vU=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,yU=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,bU=[`EvalError`,`RangeError`,`ReferenceError`,`SyntaxError`,`TypeError`,`URIError`],xU=class{status;statusText;data;error;internal;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 SU(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function CU(e){return hU(e.map(e=>e.route.path).filter(Boolean))||`/`}function wU(e,t){let n=new URL(typeof e==`string`||e instanceof URL?e:e.url),r=typeof t==`string`?wH(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);let i=e.toString();n.search=i?`?${i}`:``}else n.search=``;return n.hash=r.hash||``,n}var TU=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function EU(e,t){let n=e;if(typeof n!=`string`||!fH.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(TU)try{let e=new URL(window.location.href),r=pH.test(n)?new URL(mH(n,e.protocol)):new URL(n),a=aU(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{yH(!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 DU=Symbol(`Uninstrumented`),OU=new WeakMap;function kU(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){e.lazy!=null&&n.lazy.push(e.lazy),e[`lazy.loader`]!=null&&n[`lazy.loader`].push(e[`lazy.loader`]),e[`lazy.action`]!=null&&n[`lazy.action`].push(e[`lazy.action`]),e[`lazy.middleware`]!=null&&n[`lazy.middleware`].push(e[`lazy.middleware`]),e.middleware!=null&&n.middleware.push(e.middleware),e.loader!=null&&n.loader.push(e.loader),e.action!=null&&n.action.push(e.action)}}));let r={};if(typeof t.lazy==`function`&&n.lazy.length>0){let e=t.lazy;r.lazy=async(...t)=>FU(await IU(n.lazy,void 0,()=>e(...t),LU))}if(typeof t.lazy==`object`){let e=t.lazy;if(typeof e.middleware==`function`&&n[`lazy.middleware`].length>0){let t=e.middleware;r.lazy=Object.assign(r.lazy||{},{middleware:async(...e)=>FU(await IU(n[`lazy.middleware`],void 0,()=>t(...e),LU))})}if(typeof e.loader==`function`&&n[`lazy.loader`].length>0){let t=e.loader;r.lazy=Object.assign(r.lazy||{},{loader:async(...e)=>FU(await IU(n[`lazy.loader`],void 0,()=>t(...e),LU))})}if(typeof e.action==`function`&&n[`lazy.action`].length>0){let t=e.action;r.lazy=Object.assign(r.lazy||{},{action:async(...e)=>FU(await IU(n[`lazy.action`],void 0,()=>t(...e),LU))})}}if(typeof t.loader==`function`&&n.loader.length>0){let e=jU(t.loader),i=async(...t)=>FU(await IU(n.loader,RU(t[0]),()=>e(...t),LU));e.hydrate===!0&&(i.hydrate=!0),MU(i,e),r.loader=i}if(typeof t.action==`function`&&n.action.length>0){let e=jU(t.action),i=async(...t)=>FU(await IU(n.action,RU(t[0]),()=>e(...t),LU));MU(i,e),r.action=i}return t.middleware&&t.middleware.length>0&&n.middleware.length>0&&(r.middleware=t.middleware.map(e=>{let t=jU(e),r=async(...e)=>FU(await IU(n.middleware,RU(e[0]),()=>t(...e),LU));return MU(r,t),r})),r}function AU(e,t){let n={navigate:[],fetch:[]};if(t.forEach(e=>e({instrument(e){e.navigate!=null&&n.navigate.push(e.navigate),e.fetch!=null&&n.fetch.push(e.fetch)}})),n.navigate.length>0){let t=jU(e.navigate),r=async(...r)=>{let[i,a]=r,o,s={to:typeof i==`number`||typeof i==`string`?i:i?CH(i):`.`,...zU(e,a??{})};return FU(await IU(n.navigate,s,async()=>{if(typeof i==`number`)return await t(...r);let n=NU(e,e=>{o=e});try{return await t(...r)}finally{n()}},e=>({...LU(e),meta:o})))};MU(r,t),e.navigate=r}if(n.fetch.length>0){let t=jU(e.fetch),r=async(...r)=>{let[i,a,o,s]=r,c;return FU(await IU(n.fetch,{href:o??`.`,fetcherKey:i,...zU(e,s??{})},async()=>{let n=NU(e,e=>{c=e});try{return await t(...r)}finally{n()}},e=>({...LU(e),meta:c})))};MU(r,t),e.fetch=r}return e}function jU(e){return e[DU]??e}function MU(e,t){e[DU]=t}function NU(e,t){return OU.set(e,t),()=>{OU.get(e)===t&&OU.delete(e)}}function PU(e){let t=OU.get(e);return OU.delete(e),t}function FU(e){if(e.type===`error`)throw e.value;return e.value}async function IU(e,t,n,r,i={result:null,innerResult:null},a=e.length-1){let o=e[a];if(o){let s,c=async()=>(s?console.error(`You cannot call instrumented handlers more than once`):s=IU(e,t,n,r,i,a-1),await s,vH(i.innerResult,`Expected an inner result`),i.innerResult);try{await o(c,t)}catch(e){console.error(`An instrumentation function threw an error:`,e)}s||await c(),await s}else{try{i.result={type:`success`,value:await n()}}catch(e){i.result={type:`error`,value:e}}i.innerResult=r(i.result,t)}return i.result?i.result:(i.result={type:`error`,value:Error(`No result assigned in instrumentation chain.`)},i.innerResult=r(i.result,t),i.result)}function LU(e){return e.type===`error`&&e.value instanceof Error?{status:`error`,error:e.value}:{status:`success`,error:void 0}}function RU(e){let{request:t,context:n,params:r}=e;return{...e,request:BU(t),params:{...r},context:VU(n)}}function zU(e,t){return{currentUrl:CH(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 BU(e){return{method:e.method,url:e.url,headers:{get:(...t)=>e.headers.get(...t)}}}function VU(e){return{get:t=>e.get(t)}}var HU=[`POST`,`PUT`,`PATCH`,`DELETE`],UU=new Set(HU),WU=[`GET`,...HU],GU=new Set(WU),KU=new Set([301,302,303,307,308]),qU=new Set([307,308]),JU={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},YU={state:`idle`,data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0},XU={state:`unblocked`,proceed:void 0,reset:void 0,location:void 0},ZU=`remix-router-transitions`,QU=Symbol(`ResetLoaderData`),$U=class{#e;#t;#n;#r;constructor(e){this.#e=e,this.#t=zH(e)}get stableRoutes(){return this.#e}get activeRoutes(){return this.#n??this.#e}get branches(){return this.#r??this.#t}get hasHMRRoutes(){return this.#n!=null}setRoutes(e){this.#e=e,this.#t=zH(e)}setHmrRoutes(e){this.#n=e,this.#r=zH(e)}commitHmrRoutes(){this.#n&&(this.#e=this.#n,this.#t=this.#r,this.#n=void 0,this.#r=void 0)}};function eW(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;vH(e.routes.length>0,`You must provide a non-empty routes array to createRouter`);let r=e.hydrationRouteProperties||[],i=e.mapRouteProperties,a=i||(()=>({}));if(e.instrumentations){let t=e.instrumentations;a=e=>({...i?.(e),...kU(t.map(e=>e.route).filter(Boolean),e)})}let o={},s=new $U(PH(e.routes,a,void 0,o)),c=e.basename||`/`;c.startsWith(`/`)||(c=`/${c}`);let l=e.dataStrategy||_W,u={...e.future},d=null,f=new Set,p=null,m=null,h=null,g=null,_=e.hydrationData!=null,v=LH(s.activeRoutes,e.history.location,c,!1,s.branches),y=!1,b=null,x,S;if(v==null&&!e.patchRoutesOnNavigation){let t=VW(404,{pathname:e.history.location.pathname}),{matches:n,route:r}=BW(s.activeRoutes);x=!0,S=!x,v=n,b={[r.id]:t}}else if(v&&!e.hydrationData&&F(v,s.activeRoutes,e.history.location.pathname).active&&(v=null),!v){x=!1,S=!x,v=[];let t=F(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=>aW(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=oW(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:JU,restoreScrollPosition:e.hydrationData==null&&null,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}yH(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=Ue({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,XU),me({blockers:e})}}),E?.resolve(),E=null;return}return ve(t,n)}),n){fG(t,A);let e=()=>pG(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&&nG(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?LW(w.loaderData,n.loaderData,n.matches||[],n.errors):w.loaderData,c=w.blockers;c.size>0&&!M&&(c=new Map(c),c.forEach((e,t)=>c.set(t,XU)));let l=!M&&Je(t,n.matches||w.matches),u=D===!0||w.navigation.formMethod!=null&&nG(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:JU,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||=mG();let n=E.promise;return e.history.go(t),n}let r=PU(C),{path:i,submission:a,error:o}=rW(!1,nW(w.location,w.matches,c,t,n?.fromRouteId,n?.relative),n),s;n?.mask&&(s={pathname:``,search:``,hash:``,...typeof n.mask==`string`?wH(n.mask):{...w.location.mask,...n.mask}});let l=w.location,u=SH(l,i,n&&n.state,void 0,s);u={...u,...e.history.encodeLocation(u)};let d=n&&n.replace!=null?n.replace:void 0,f=`PUSH`;d===!0?f=`REPLACE`:d===!1||a!=null&&nG(a.formMethod)&&a.formAction===w.location.pathname+w.location.search&&(f=`REPLACE`);let p=n&&`preventScrollReset`in n?n.preventScrollReset===!0:void 0,m=(n&&n.flushSync)===!0,h=Ue({currentLocation:l,nextLocation:u,historyAction:f});if(h){He(h,{state:`blocked`,location:u,proceed(){He(h,{state:`proceeding`,proceed:void 0,reset:void 0,location:u}),ge(t,n)},reset(){let e=new Map(w.blockers);e.set(h,XU),me({blockers:e})}});return}await ve(f,u,{submission:a,pendingError:o,preventScrollReset:p,replace:n&&n.replace,enableViewTransition:n&&n.viewTransition,flushSync:m,callSiteDefaultShouldRevalidate:n&&n.defaultShouldRevalidate,instrumentationNavigateMetaReceiver:r})}function _e(){ue||=mG(),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,qe(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:LH(i,n,c,!1,s.branches),o=(r&&r.flushSync)===!0;if(a&&w.initialized&&!ee&&WW(w.location,n)&&!(r&&r.submission&&nG(r.submission.formMethod))){he(n,{matches:a},{flushSync:o});return}let l=F(a,i,n.pathname);if(l.active&&l.matches&&(a=l.matches),r?.instrumentationNavigateMetaReceiver){let t=aG(e.history,n,a);r.instrumentationNavigateMetaReceiver(t)}if(!a){let{error:e,notFoundMatches:t,route:r}=We(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=MW(e.history,n,O.signal,r&&r.submission),f=e.getContext?await e.getContext():new DH,p;if(r&&r.pendingError)p=[zW(a).route.id,{type:`error`,error:r.pendingError}];else if(r&&r.submission&&nG(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(YW(t)&&SU(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=sG(n,a,t,r.submission),o=!1,l.active=!1,d=MW(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,...RW(p),loaderData:g,errors:_,...v?{fetchers:v}:{}}))}async function ye(t,n,i,l,u,d,f,p,m={}){if(ke(),me({navigation:cG(n,l,u,i)},{flushSync:m.flushSync===!0}),f){let e=await Ye(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}=BW(s.activeRoutes);return{matches:t,pendingActionResult:[n.id,{type:`error`,error:e.error}]}}let t=zW(e.partialMatches).route.id;return{matches:e.partialMatches,pendingActionResult:[t,{type:`error`,error:e.error}]}}if(e.matches)l=e.matches;else{let{notFoundMatches:e,error:t,route:r}=We(n.pathname);return{matches:e,pendingActionResult:[r.id,{type:`error`,error:t}]}}}let h,g=iG(l,n);if(!g.route.action&&!g.route.lazy)h={type:`error`,error:VW(405,{method:t.method,pathname:n.pathname,routeId:g.route.id})};else{let e=await De(t,n,CW(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(XW(h)){let n;return n=m&&m.replace!=null?m.replace:jW(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(YW(h)){let e=zW(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||sG(n,i,l,p),x=p||m||oG(b),S=!M&&!g;if(d){if(S){let e=xe(v);me({navigation:b,...e===void 0?{}:{actionData:e}},{flushSync:_})}let e=await Ye(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}=BW(s.activeRoutes);return{matches:t,loaderData:{},errors:{[n.id]:e.error}}}let t=zW(e.partialMatches).route.id;return{matches:e.partialMatches,loaderData:{},errors:{[t]:e.error}}}if(e.matches)i=e.matches;else{let{error:e,notFoundMatches:t,route:r}=We(n.pathname);return{matches:t,loaderData:{},errors:{[r.id]:e}}}}let C=s.activeRoutes,{dsMatches:T,revalidatingFetchers:E}=iW(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&&YW(v[1])?{[v[0]]:v[1].error}:null,...RW(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=HW(k);if(j)return await Ee(t,j.result,!0,{replace:h}),{shortCircuited:!0};if(j=HW(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}=IW(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&&!YW(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=lG(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=PU(C),l=s.activeRoutes,u=nW(w.location,w.matches,c,r,n,i?.relative),d=LH(l,u,c,!1,s.branches),f=F(d,l,u);if(f.active&&f.matches&&(d=f.matches),o&&o(aG(e.history,u,d)),!d){je(t,n,VW(404,{pathname:u}),{flushSync:a});return}let{path:p,submission:m,error:h}=rW(!0,u,i);if(h){je(t,n,h,{flushSync:a});return}let g=e.getContext?await e.getContext():new DH,_=(i&&i.preventScrollReset)===!0;if(m&&nG(m.formMethod)){await we(t,n,p,d,g,f.active,a,_,m,i&&i.defaultShouldRevalidate);return}ae.set(t,{routeId:n,path:p}),await Te(t,n,p,d,g,f.active,a,_,m)}async function we(t,n,i,l,u,d,f,p,m,h){ke(),ae.delete(t),Ae(t,uG(m,w.fetchers.get(t)),{flushSync:f});let g=new AbortController,_=MW(e.history,i,g.signal,m);if(d){let e=await Ye(l,new URL(_.url).pathname,_.signal,t);if(e.type===`aborted`)return;if(e.type===`error`){je(t,n,e.error,{flushSync:f});return}if(e.matches)l=e.matches;else{je(t,n,VW(404,{pathname:i}),{flushSync:f});return}}let v=iG(l,i);if(!v.route.action&&!v.route.lazy){je(t,n,VW(405,{method:m.formMethod,pathname:i,routeId:n}),{flushSync:f});return}P.set(t,g);let y=te,b=CW(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(XW(S)||YW(S)){Ae(t,dG(void 0));return}}else{if(XW(S)){if(P.delete(t),ne>y){Ae(t,dG(void 0));return}return ie.add(t),Ae(t,lG(m)),Ee(_,S,!1,{fetcherSubmission:m,preventScrollReset:p})}if(YW(S)){je(t,n,S.error);return}}let C=w.navigation.location||w.location,E=MW(e.history,C,g.signal),D=s.activeRoutes,k=w.navigation.state===`idle`?w.matches:LH(D,w.navigation.location,c,!1,s.branches);vH(k,`Didn't find any matches after fetcher action`);let A=++te;re.set(t,A);let{dsMatches:j,revalidatingFetchers:M}=iW(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=lG(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=lG(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,dG(S.data)),{...e,fetchers:n}},ge=HW(ue);if(ge)return w=pe(w),Ee(E,ge.result,!1,{preventScrollReset:p});if(ge=HW(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,dG(S.data));let{loaderData:ve,errors:ye}=IW(w,k,ue,void 0,M,de,_e);ze(A,_e),w.navigation.state===`loading`&&A>ne?(vH(T,`Expected pending action`),O&&O.abort(),he(w.navigation.location,{matches:k,loaderData:ve,errors:ye,fetchers:_e})):(me({errors:ye,loaderData:LW(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,lG(f,p?p.data:void 0),{flushSync:u});let m=new AbortController,h=MW(e.history,i,m.signal);if(l){let e=await Ye(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}if(e.matches)s=e.matches;else{je(t,n,VW(404,{pathname:i}),{flushSync:u});return}}let g=iG(s,i);P.set(t,m);let _=te,v=await De(h,i,CW(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,dG(void 0));return}if(XW(y)){if(ne>_){Ae(t,dG(void 0));return}ie.add(t),await Ee(h,y,!1,{preventScrollReset:d});return}if(YW(y)){je(t,n,y.error);return}Ae(t,dG(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`);vH(d,`Expected a Location header on the redirect Response`),d=jW(d,new URL(r.url),c,e.history);let f=SH(w.location,d,{_isRedirect:!0});if(n){let e=!1;if(i.response.headers.has(`X-Remix-Reload-Document`))e=!0;else if(sU(d)){let n=EH(t,d,!0);e=n.origin!==t.location.origin||aU(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=oG(w.navigation));let _=o||s;qU.has(i.response.status)&&_&&nG(_.formMethod)?await ve(p,f,{submission:{..._,formAction:d},preventScrollReset:l||D,enableViewTransition:a?k:void 0}):await ve(p,f,{overrideNavigation:sG(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 wW(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(!nG(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(JW(r)){let i=r.result;o[t]={type:`redirect`,response:OW(i,e,t,n,c)}}else o[t]=await DW(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}}return Promise.resolve({[e.key]:{type:`error`,error:VW(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=zW(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)||YU}function Ne(e,t){Ie(e,t?.reason),Ae(e,dG(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);vH(e,`Expected fetcher: ${n}`);let r=dG(e.data);t.set(n,r)}}function Re(e){let t=[],n=!1;for(let r of ie){let i=e.get(r);vH(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);vH(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)||XU;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)||XU;vH(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 Ue({currentLocation:e,nextLocation:t,historyAction:n}){if(ce.size===0)return;ce.size>1&&yH(!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 We(e){let t=VW(404,{pathname:e}),n=s.activeRoutes,{matches:r,route:i}=BW(n);return{notFoundMatches:r,route:i,error:t}}function Ge(e,t,n){if(m=e,g=t,h=n||null,!_&&w.navigation===JU){_=!0;let e=Je(w.location,w.matches);e!=null&&me({restoreScrollPosition:e})}return()=>{m=null,g=null,h=null}}function Ke(e,t){return h&&h(e,t.map(e=>RH(e,w.loaderData)))||e.key}function qe(e,t){if(m&&g){let n=Ke(e,t);m[n]=g()}}function Je(e,t){if(m){let n=Ke(e,t),r=m[n];if(typeof r==`number`)return r}return null}function F(t,n,r){if(e.patchRoutesOnNavigation){let e=s.branches;if(!t)return{active:!0,matches:LH(n,r,c,!0,e)||[]};if(Object.keys(t[0].params).length>0)return{active:!0,matches:LH(n,r,c,!0,e)}}return{active:!1,matches:null}}async function Ye(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||uW(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=LH(s.activeRoutes,n,c,!1,u),f=null;if(d&&(Object.keys(d[0].params).length===0||(f=LH(s.activeRoutes,n,c,!0,u),!(f&&l.length<f.length&&Xe(l,f.slice(0,l.length))))))return{type:`success`,matches:d};if(f||=LH(s.activeRoutes,n,c,!0,u),!f||Xe(l,f))return{type:`success`,matches:null};l=f}}function Xe(e,t){return e.length===t.length&&e.every((e,n)=>e.route.id===t[n].route.id)}function Ze(e){o={},s.setHmrRoutes(PH(e,a,void 0,o))}function Qe(e,t,n=!1){uW(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:Ge,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:Qe,_internalFetchControllers:P,_internalSetRoutes:Ze,_internalSetStateDoNotUseOrYouWillBreakYourApp(e){me(e)}},e.instrumentations&&(C=AU(C,e.instrumentations.map(e=>e.router).filter(Boolean))),C}function tW(e){return e!=null&&(`formData`in e&&e.formData!=null||`body`in e&&e.body!==void 0)}function nW(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=pU(r||`.`,fU(o),aU(e.pathname,n)||e.pathname,a===`path`);if(r??(c.search=e.search,c.hash=e.hash),(r==null||r===``||r===`.`)&&s){let e=rG(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=oU({basename:n,pathname:c.pathname})),CH(c)}function rW(e,t,n){if(!n||!tW(n))return{path:t};if(n.formMethod&&!tG(n.formMethod))return{path:t,error:VW(405,{method:n.formMethod})};let r=()=>({path:t,error:VW(400,{type:`invalid-body`})}),i=(n.formMethod||`get`).toUpperCase(),a=UW(t);if(n.body!==void 0){if(n.formEncType===`text/plain`){if(!nG(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}\n`,``):String(n.body);return{path:t,submission:{formMethod:i,formAction:a,formEncType:n.formEncType,formData:void 0,json:void 0,text:e}}}if(n.formEncType===`application/json`){if(!nG(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()}}}vH(typeof FormData==`function`,`FormData is not available in this environment`);let o,s;if(n.formData)o=NW(n.formData),s=n.formData;else if(n.body instanceof FormData)o=NW(n.body),s=n.body;else if(n.body instanceof URLSearchParams)o=n.body,s=PW(o);else if(n.body==null)o=new URLSearchParams,s=new FormData;else try{o=new URLSearchParams(n.body),s=PW(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(nG(c.formMethod))return{path:t,submission:c};let l=wH(t);return e&&l.search&&rG(l.search)&&o.append(`index`,``),l.search=`?${o}`,{path:CH(l),submission:c}}function iW(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x){let S=b?YW(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&&YW(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=CU(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(!aW(s))f=!1;else if(u){let{shouldLoad:e}=oW(s,a.loaderData,a.errors);f=e}else sW(a.loaderData,a.matches[o],i)&&(f=!0);if(f!==null)return SW(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?cW(a.matches[o],i)&&(p=!0):p=!0;let m={...O,defaultShouldRevalidate:p};return SW(n,r,e,c,k,i,l,t,lW(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=LH(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=iG(b,e.path),C=new AbortController,w=MW(i,e.path,C.signal),T=null;if(f.has(s))f.delete(s),T=CW(n,r,w,e.path,b,S,l,t);else if(m)d&&(T=CW(n,r,w,e.path,b,S,l,t));else{let i;i=typeof x==`boolean`?x:!D&&d;let a={...O,defaultShouldRevalidate:i};lW(S,a)&&(T=CW(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 aW(e){return e.loader!=null||e.middleware!=null&&e.middleware.length>0}function oW(e,t,n){if(e.lazy)return{shouldLoad:!0,renderFallback:!0};if(!aW(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 sW(e,t,n){let r=!t||n.route.id!==t.route.id,i=!e.hasOwnProperty(n.route.id);return r||i}function cW(e,t){let n=e.route.path;return e.pathname!==t.pathname||n!=null&&n.endsWith(`*`)&&e.params[`*`]!==t.params[`*`]}function lW(e,t){if(e.route.shouldRevalidate){let n=e.route.shouldRevalidate(t);if(typeof n==`boolean`)return n}return t.defaultShouldRevalidate}function uW(e,t,n,r,i,a){let o;if(e){let t=r[e];vH(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=>dW(e,t));t?c.push({existingRoute:t,newRoute:e}):s.push(e)}),s.length>0){let t=PH(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]=PH([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 dW(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?!1:(!e.children||e.children.length===0)&&(!t.children||t.children.length===0)?!0:e.children?.every((e,n)=>t.children?.some(t=>dW(e,t)))??!1}var fW=new WeakMap,pW=({key:e,route:t,manifest:n,mapRouteProperties:r})=>{let i=n[t.id];if(vH(i,`No route found in manifest`),!i.lazy||typeof i.lazy!=`object`)return;let a=i.lazy[e];if(!a)return;let o=fW.get(i);o||(o={},fW.set(i,o));let s=o[e];if(s)return s;let c=(async()=>{let t=kH(e),n=i[e]!==void 0;if(t)yH(!t,`Route property `+e+` is not a supported lazy route property. This property will be ignored.`),o[e]=Promise.resolve();else if(n)yH(!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},mW=new WeakMap;function hW(e,t,n,r,i){let a=n[e.id];if(vH(a,`No route found in manifest`),!e.lazy)return{lazyRoutePromise:void 0,lazyHandlerPromise:void 0};if(typeof e.lazy==`function`){let t=mW.get(a);if(t)return{lazyRoutePromise:t,lazyHandlerPromise:t};let n=(async()=>{vH(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=jH(e),o=a[e]!==void 0;i?yH(!i,`Route property `+e+` is not a supported property to be returned from a lazy route function. This property will be ignored.`):o?yH(!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 mW.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=pW({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 gW(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 _W(e){return e.matches.some(e=>e.route.middleware)?vW(e,()=>gW(e)):gW(e)}function vW(e,t){return yW(e,t,e=>{if(eG(e))throw e;return e},KW,n);async function n(t,n,r){if(r)return Object.assign(r.value,{[n]:{type:`error`,result:t}});{let{matches:r}=e,i=Math.min(Math.max(r.findIndex(e=>e.route.id===n),0),Math.max(r.findIndex(e=>e.shouldCallHandler()),0)),a=r[i].route.id;for(let e of r.slice(0,i+1))try{await e._lazyPromises?.route}catch{a=e.route.id;break}return{[zW(r,a).route.id]:{type:`error`,result:t}}}}}async function yW(e,t,n,r,i){let{matches:a,...o}=e;return await bW(o,a.flatMap(e=>e.route.middleware?e.route.middleware.map(t=>[e.route.id,t]):[]),t,n,r,i)}async function bW(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 bW(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 xW(e,t,n,r,i){let a=pW({key:`middleware`,route:r.route,manifest:t,mapRouteProperties:e}),o=hW(r.route,nG(n.method)?`action`:`loader`,t,e,i);return{middleware:a,route:o.lazyRoutePromise,handler:o.lazyHandlerPromise}}function SW(e,t,n,r,i,a,o,s,c,l=null,u){let d=!1,f=xW(e,t,n,a,o);return{...a,_lazyPromises:f,shouldLoad:c,shouldRevalidateArgs:l,shouldCallHandler(e){return d=!0,l?typeof u==`boolean`?lW(a,{...l,defaultShouldRevalidate:u}):typeof e==`boolean`?lW(a,{...l,defaultShouldRevalidate:e}):lW(a,l):c},resolve(e){let{lazy:t,loader:o,middleware:l}=a.route,u=d||c||e&&!nG(n.method)&&(t||o),p=l&&l.length>0&&!o&&!t;return u&&(nG(n.method)||!p)?TW({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 CW(e,t,n,r,i,a,o,s,c=null){return i.map(l=>l.route.id===a.route.id?SW(e,t,n,r,CU(i),l,o,s,!0,c):{...l,shouldLoad:!1,shouldRevalidateArgs:c,shouldCallHandler:()=>!1,_lazyPromises:xW(e,t,n,l,o),resolve:()=>Promise.resolve({type:`data`,result:void 0})})}async function wW(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:wU(t,n),pattern:CU(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 vW(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 TW({request:e,path:t,pattern:n,match:r,lazyHandlerPromise:i,lazyRoutePromise:a,handlerOverride:o,scopedContext:s}){let c,l,u=nG(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:wU(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 VW(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 VW(404,{pathname:t.pathname+t.search})}}catch(e){return{type:`error`,result:e}}finally{l&&e.signal.removeEventListener(`abort`,l)}return c}async function EW(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 DW(e){let{result:t,type:n}=e;if(QW(t)){let e;try{e=await EW(t)}catch(e){return{type:`error`,error:e}}return n===`error`?{type:`error`,error:new xU(t.status,t.statusText,e),statusCode:t.status,headers:t.headers}:{type:`data`,data:e,statusCode:t.status,headers:t.headers}}return n===`error`?ZW(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:GW(t),statusCode:SU(t)?t.status:void 0,headers:t.init?.headers?new Headers(t.init.headers):void 0}:{type:`error`,error:t,statusCode:SU(t)?t.status:void 0}:ZW(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 OW(e,t,n,r,i){let a=e.headers.get(`Location`);if(vH(a,`Redirects returned/thrown from loaders/actions must have a Location header`),!sU(a)){let o=r.slice(0,r.findIndex(e=>e.route.id===n)+1);a=nW(new URL(t.url),o,i,a),e.headers.set(`Location`,a)}return e}var kW=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function AW(e){try{return kW.includes(new URL(e).protocol)}catch{return!1}}function jW(e,t,n,r){if(sU(e)){let r=e,i=pH.test(r)?new URL(mH(r,t.protocol)):new URL(r);if(AW(i.toString()))throw Error(`Invalid redirect location`);let a=aU(i.pathname,n)!=null;if(i.origin===t.origin&&a)return mU(i.pathname)+i.search+i.hash}try{if(AW(r.createURL(e).toString()))throw Error(`Invalid redirect location`)}catch{}return e}function MW(e,t,n,r){let i=e.createURL(UW(t)).toString(),a={signal:n};if(r&&nG(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)):a.body=t===`text/plain`?r.text:t===`application/x-www-form-urlencoded`&&r.formData?NW(r.formData):r.formData}return new Request(i,a)}function NW(e){let t=new URLSearchParams;for(let[n,r]of e.entries())t.append(n,typeof r==`string`?r:r.name);return t}function PW(e){let t=new FormData;for(let[n,r]of e.entries())t.append(n,r);return t}function FW(e,t,n,r=!1,i=!1){let a={},o=null,s,c=!1,l={},u=n&&YW(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(vH(!XW(f),`Cannot handle redirect results in processLoaderData`),YW(f)){let t=f.error;if(u!==void 0&&(t=u,u=void 0),o||={},i)o[d]=t;else{let n=zW(e,d);o[n.route.id]??(o[n.route.id]=t)}r||(a[d]=QU),c||(c=!0,s=SU(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 IW(e,t,n,r,i,a,o){let{loaderData:s,errors:c}=FW(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(vH(s,`Did not find corresponding fetcher result`),YW(s)){let t=zW(e.matches,r?.route.id);c&&c[t.route.id]||(c={...c,[t.route.id]:s.error}),o.delete(n)}else if(XW(s))vH(!1,`Unhandled fetcher revalidation redirect`);else{let e=dG(s.data);o.set(n,e)}}),{loaderData:s,errors:c}}function LW(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!==QU).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 RW(e){return e?YW(e[1])?{actionData:{}}:{actionData:{[e[0]]:e[1].data}}:{}}function zW(e,t){return(t?e.slice(0,e.findIndex(e=>e.route.id===t)+1):[...e]).reverse().find(e=>e.route.ErrorBoundary!=null||e.route.errorElement!=null)||e[0]}function BW(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 VW(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 xU(e||500,o,Error(s),!0)}function HW(e){let t=Object.entries(e);for(let e=t.length-1;e>=0;e--){let[n,r]=t[e];if(XW(r))return{key:n,result:r}}}function UW(e){return CH({...typeof e==`string`?wH(e):e,hash:``})}function WW(e,t){return e.pathname!==t.pathname||e.search!==t.search?!1:e.hash===``?t.hash!==``:e.hash===t.hash||t.hash!==``}function GW(e){return new xU(e.init?.status??500,e.init?.statusText??`Internal Server Error`,e.data)}function KW(e){return typeof e==`object`&&!!e&&Object.entries(e).every(([e,t])=>typeof e==`string`&&qW(t))}function qW(e){return typeof e==`object`&&!!e&&`type`in e&&`result`in e&&(e.type===`data`||e.type===`error`)}function JW(e){return QW(e.result)&&KU.has(e.result.status)}function YW(e){return e.type===`error`}function XW(e){return(e&&e.type)===`redirect`}function ZW(e){return typeof e==`object`&&!!e&&`type`in e&&`data`in e&&`init`in e&&e.type===`DataWithResponseInit`}function QW(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.headers==`object`&&e.body!==void 0}function $W(e){return KU.has(e)}function eG(e){return QW(e)&&$W(e.status)&&e.headers.has(`Location`)}function tG(e){return GU.has(e.toUpperCase())}function nG(e){return UU.has(e.toUpperCase())}function rG(e){return new URLSearchParams(e).getAll(`index`).some(e=>e===``)}function iG(e,t){let n=typeof t==`string`?wH(t).search:t.search;if(e[e.length-1].route.index&&rG(n||``))return e[e.length-1];let r=dU(e);return r[r.length-1]}function aG(e,t,n){return{url:wU(e.createURL(t),t),pattern:n?CU(n):``,params:n?.[0]?.params?{...n[0].params}:{}}}function oG(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 sG(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 cG(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 lG(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 uG(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 dG(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 fG(e,t){try{let n=e.sessionStorage.getItem(ZU);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 pG(e,t){if(t.size>0){let n={};for(let[e,r]of t)n[e]=[...r];try{e.sessionStorage.setItem(ZU,JSON.stringify(n))}catch(e){yH(!1,`Failed to save applied view transitions in sessionStorage (${e}).`)}}}function mG(){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 hG=b.createContext(null);hG.displayName=`DataRouter`;var gG=b.createContext(null);gG.displayName=`DataRouterState`;var _G=b.createContext(!1);function vG(){return b.useContext(_G)}var yG=b.createContext({isTransitioning:!1});yG.displayName=`ViewTransition`;var bG=b.createContext(new Map);bG.displayName=`Fetchers`;var xG=b.createContext(null);xG.displayName=`Await`;var SG=b.createContext(null);SG.displayName=`Navigation`;var CG=b.createContext(null);CG.displayName=`Location`;var wG=b.createContext({outlet:null,matches:[],isDataRoute:!1});wG.displayName=`Route`;var TG=b.createContext(null);TG.displayName=`RouteError`;var EG=`REACT_ROUTER_ERROR`,DG=`REDIRECT`,OG=`ROUTE_ERROR_RESPONSE`;function kG(e){if(e.startsWith(`${EG}:${DG}:{`))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 AG(e){if(e.startsWith(`${EG}:${OG}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new xU(t.status,t.statusText,t.data)}catch{}}function jG(e,{relative:t}={}){vH(MG(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=b.useContext(SG),{hash:i,pathname:a,search:o}=BG(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:hU([n,a])),r.createHref({pathname:s,search:o,hash:i})}function MG(){return b.useContext(CG)!=null}function NG(){return vH(MG(),`useLocation() may be used only in the context of a <Router> component.`),b.useContext(CG).location}var PG=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function FG(){let{isDataRoute:e}=b.useContext(wG);return e?rK():IG()}function IG(){vH(MG(),`useNavigate() may be used only in the context of a <Router> component.`);let e=b.useContext(hG),{basename:t,navigator:n}=b.useContext(SG),{matches:r}=b.useContext(wG),{pathname:i}=NG(),a=JSON.stringify(fU(r)),o=b.useRef(!1);return b.useLayoutEffect(()=>{o.current=!0}),b.useCallback((r,s={})=>{if(yH(o.current,PG),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=pU(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:hU([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var LG=b.createContext(null);function RG(e){let t=b.useContext(wG).outlet;return b.useMemo(()=>t&&b.createElement(LG.Provider,{value:e},t),[t,e])}function zG(){let{matches:e}=b.useContext(wG);return e[e.length-1]?.params??{}}function BG(e,{relative:t}={}){let{matches:n}=b.useContext(wG),{pathname:r}=NG(),i=JSON.stringify(fU(n));return b.useMemo(()=>pU(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function VG(e,t){return HG(e,t)}function HG(e,t,n){vH(MG(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=b.useContext(SG),{matches:i}=b.useContext(wG),a=i[i.length-1],o=a?a.params:{};a&&a.pathname;let s=a?a.pathnameBase:`/`;a&&a.route;let c=NG(),l;if(t){let e=typeof t==`string`?wH(t):t;vH(s===`/`||e.pathname?.startsWith(s),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${s}" but pathname "${e.pathname}" was given in the \`location\` prop.`),l=e}else l=c;let u=l.pathname||`/`,d=u;if(s!==`/`){let e=s.replace(/^\//,``).split(`/`);d=`/`+u.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let f=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):IH(e,{pathname:d}),p=YG(f&&f.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:hU([s,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?s:hU([s,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&p?b.createElement(CG.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...l},navigationType:`POP`}},p):p}function UG(){let e=nK(),t=SU(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null;return b.createElement(b.Fragment,null,b.createElement(`h2`,null,`Unexpected Application Error!`),b.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?b.createElement(`pre`,{style:{padding:`0.5rem`,backgroundColor:`rgba(200,200,200, 0.5)`}},n):null,null)}var WG=b.createElement(UG,null),GG=class extends b.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static contextType=_G;static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=AG(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:b.createElement(wG.Provider,{value:this.props.routeContext},b.createElement(TG.Provider,{value:e,children:this.props.component}));return this.context?b.createElement(qG,{error:e},t):t}},KG=new WeakMap;function qG({children:e,error:t}){let{basename:n}=b.useContext(SG);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=kG(t.digest);if(e){let r=KG.get(t);if(r)throw r;let i=EU(e.location,n),a=i.absoluteURL||i.to;if(AW(a))throw Error(`Invalid redirect location`);if(TU&&!KG.get(t)){if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw KG.set(t,n),n}}return b.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function JG({routeContext:e,match:t,children:n}){let r=b.useContext(hG);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),b.createElement(wG.Provider,{value:e},n)}function YG(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);vH(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:CU(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||WG,o&&(s<0&&c===0?(aK(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?b.createElement(n.route.Component,null):n.route.element?n.route.element:e,b.createElement(JG,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?b.createElement(GG,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function XG(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function ZG(e){let t=b.useContext(hG);return vH(t,XG(e)),t}function QG(e){let t=b.useContext(gG);return vH(t,XG(e)),t}function $G(e){let t=b.useContext(wG);return vH(t,XG(e)),t}function eK(e){let t=$G(e),n=t.matches[t.matches.length-1];return vH(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function tK(){return eK(`useRouteId`)}function nK(){let e=b.useContext(TG),t=QG(`useRouteError`),n=eK(`useRouteError`);return e===void 0?t.errors?.[n]:e}function rK(){let{router:e}=ZG(`useNavigate`),t=eK(`useNavigate`),n=b.useRef(!1);return b.useLayoutEffect(()=>{n.current=!0}),b.useCallback(async(r,i={})=>{yH(n.current,PG),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var iK={};function aK(e,t,n){!t&&!iK[e]&&(iK[e]=!0,yH(!1,n))}var oK={};function sK(e,t){!e&&!oK[t]&&(oK[t]=!0,console.warn(t))}var cK=[`HydrateFallback`,`hydrateFallbackElement`],lK=class{status=`pending`;promise;resolve;reject;constructor(){this.promise=new Promise((e,t)=>{this.resolve=t=>{this.status===`pending`&&(this.status=`resolved`,e(t))},this.reject=e=>{this.status===`pending`&&(this.status=`rejected`,t(e))}})}};function uK({router:e,flushSync:t,onError:n,useTransitions:r}){r=vG()||r;let[i,a]=b.useState(e.state),[o,s]=(0,b.useOptimistic)(i),[c,l]=b.useState(),[u,d]=b.useState({isTransitioning:!1}),[f,p]=b.useState(),[m,h]=b.useState(),[g,_]=b.useState(),v=b.useRef(new Map),y=b.useCallback((i,{deletedFetchers:o,newErrors:c,flushSync:u,viewTransitionOpts:g})=>{c&&n&&Object.values(c).forEach(e=>n(e,{location:i.location,params:i.matches[0]?.params??{},pattern:CU(i.matches)})),i.fetchers.forEach((e,t)=>{e.data!==void 0&&v.current.set(t,e.data)}),o.forEach(e=>v.current.delete(e)),sK(u===!1||t!=null,'You provided the `flushSync` option to a router update, but you are not using the `<RouterProvider>` from `react-router/dom` so `ReactDOM.flushSync()` is unavailable. Please update your app to `import { RouterProvider } from "react-router/dom"` and ensure you have `react-dom` installed as a dependency to use the `flushSync` option.');let y=e.window!=null&&e.window.document!=null&&typeof e.window.document.startViewTransition==`function`;if(sK(g==null||y,"You provided the `viewTransition` option to a router update, but you do not appear to be running in a DOM environment as `window.startViewTransition` is not available."),!g||!y){t&&u?t(()=>a(i)):r===!1?a(i):b.startTransition(()=>{r===!0&&s(e=>dK(e,i)),a(i)});return}if(t&&u){t(()=>{m&&(f?.resolve(),m.skipTransition()),d({isTransitioning:!0,flushSync:!0,currentLocation:g.currentLocation,nextLocation:g.nextLocation})});let n=e.window.document.startViewTransition(()=>{t(()=>a(i))});n.finished.finally(()=>{t(()=>{p(void 0),h(void 0),l(void 0),d({isTransitioning:!1})})}),t(()=>h(n));return}m?(f?.resolve(),m.skipTransition(),_({state:i,currentLocation:g.currentLocation,nextLocation:g.nextLocation})):(l(i),d({isTransitioning:!0,flushSync:!1,currentLocation:g.currentLocation,nextLocation:g.nextLocation}))},[e.window,t,m,f,r,s,n]);b.useLayoutEffect(()=>e.subscribe(y),[e,y]),b.useEffect(()=>{u.isTransitioning&&!u.flushSync&&p(new lK)},[u]),b.useEffect(()=>{if(f&&c&&e.window){let t=c,n=f.promise,i=e.window.document.startViewTransition(async()=>{r===!1?a(t):b.startTransition(()=>{r===!0&&s(e=>dK(e,t)),a(t)}),await n});i.finished.finally(()=>{p(void 0),h(void 0),l(void 0),d({isTransitioning:!1})}),h(i)}},[c,f,e.window,r,s]),b.useEffect(()=>{f&&c&&o.location.key===c.location.key&&f.resolve()},[f,m,o.location,c]),b.useEffect(()=>{!u.isTransitioning&&g&&(l(g.state),d({isTransitioning:!0,flushSync:!1,currentLocation:g.currentLocation,nextLocation:g.nextLocation}),_(void 0))},[u.isTransitioning,g]);let x=b.useMemo(()=>({createHref:e.createHref,encodeLocation:e.encodeLocation,go:t=>e.navigate(t),push:(t,n,r)=>e.navigate(t,{state:n,preventScrollReset:r?.preventScrollReset}),replace:(t,n,r)=>e.navigate(t,{replace:!0,state:n,preventScrollReset:r?.preventScrollReset})}),[e]),S=e.basename||`/`,C=b.useMemo(()=>({router:e,navigator:x,static:!1,basename:S,onError:n}),[e,x,S,n]);return b.createElement(b.Fragment,null,b.createElement(hG.Provider,{value:C},b.createElement(gG.Provider,{value:o},b.createElement(bG.Provider,{value:v.current},b.createElement(yG.Provider,{value:u},b.createElement(_K,{basename:S,location:o.location,navigationType:o.historyAction,navigator:x,useTransitions:r},b.createElement(fK,{routes:e.routes,manifest:e.manifest,future:e.future,state:o,isStatic:!1,onError:n})))))),null)}function dK(e,t){return{...e,navigation:t.navigation.state===`idle`?e.navigation:t.navigation,revalidation:t.revalidation===`idle`?e.revalidation:t.revalidation,actionData:t.navigation.state===`submitting`?e.actionData:t.actionData,fetchers:t.fetchers}}var fK=b.memo(pK);function pK({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return HG(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function mK({to:e,replace:t,state:n,relative:r}){vH(MG(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=b.useContext(SG);yH(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=b.useContext(wG),{pathname:o}=NG(),s=FG(),c=pU(e,fU(a),o,r===`path`),l=JSON.stringify(c);return b.useEffect(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function hK(e){return RG(e.context)}function gK(e){vH(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function _K({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){vH(!MG(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=b.useMemo(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=wH(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,mask:m}=n,h=b.useMemo(()=>{let e=aU(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return yH(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:b.createElement(SG.Provider,{value:c},b.createElement(CG.Provider,{children:t,value:h}))}function vK({children:e,location:t}){return VG(yK(e),t)}b.Component;function yK(e,t=[]){let n=[];return b.Children.forEach(e,(e,r)=>{if(!b.isValidElement(e))return;let i=[...t,r];if(e.type===b.Fragment){n.push.apply(n,yK(e.props.children,i));return}vH(e.type===gK,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`);let a=e.props;vH(!a.index||!a.children,`An index route cannot have child routes.`);let o={id:a.id||i.join(`-`),caseSensitive:a.caseSensitive,element:a.element,Component:a.Component,index:a.index,path:a.path,middleware:a.middleware,loader:a.loader,action:a.action,hydrateFallbackElement:a.hydrateFallbackElement,HydrateFallback:a.HydrateFallback,errorElement:a.errorElement,ErrorBoundary:a.ErrorBoundary,shouldRevalidate:a.shouldRevalidate,handle:a.handle,lazy:a.lazy};a.children&&(o.children=yK(a.children,i)),n.push(o)}),n}var bK=`application/x-www-form-urlencoded`;function xK(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function SK(e){return xK(e)&&e.tagName.toLowerCase()===`button`}function CK(e){return xK(e)&&e.tagName.toLowerCase()===`form`}function wK(e){return xK(e)&&e.tagName.toLowerCase()===`input`}function TK(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function EK(e,t){return e.button===0&&(!t||t===`_self`)&&!TK(e)}function DK(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function OK(e,t){let n=DK(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var kK=null;function AK(){if(kK===null)try{new FormData(document.createElement(`form`),0),kK=!1}catch{kK=!0}return kK}var jK=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function MK(e){return e!=null&&!jK.has(e)?(yH(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${bK}"`),null):e}function NK(e,t){let n,r,i,a,o;if(CK(e)){let o=e.getAttribute(`action`);r=o?aU(o,t):null,n=e.getAttribute(`method`)||`get`,i=MK(e.getAttribute(`enctype`))||bK,a=new FormData(e)}else if(SK(e)||wK(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?aU(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||`get`,i=MK(e.getAttribute(`formenctype`))||MK(o.getAttribute(`enctype`))||bK,a=new FormData(o,e),!AK()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(xK(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=`get`,r=null,i=bK,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}function PK(e,t){if(e===!1||e==null)throw Error(t)}function FK(e,t){let n=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n.pathname=n.pathname.endsWith(`/`)?`${n.pathname}_.${t}`:`${n.pathname}.${t}`,n}async function IK(e,t){if(e.id in t)return t[e.id];try{let n=await zB(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function LK(e){return e!=null&&typeof e.page==`string`}function RK(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function zK(e,t,n){return WK((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await IK(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(RK).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function BK(e,t,n,r,i,a){let o=(e,t)=>!n[t]||e.route.id!==n[t].route.id,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function VK(e,t,{includeHydrateFallback:n}={}){return HK(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function HK(e){return[...new Set(e)]}function UK(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function WK(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!LK(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(UK(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function GK(){let e=b.useContext(hG);return PK(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function KK(){let e=b.useContext(gG);return PK(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var qK=b.createContext(void 0);qK.displayName=`FrameworkContext`;function JK(){let e=b.useContext(qK);return PK(e,`You must render this element inside a <HydratedRouter> element`),e}function YK(e,t){let n=b.useContext(qK),[r,i]=b.useState(!1),[a,o]=b.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=b.useRef(null);b.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),b.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:XK(s,p),onBlur:XK(c,m),onMouseEnter:XK(l,p),onMouseLeave:XK(u,m),onTouchStart:XK(d,p)}]:[a,f,{}]:[!1,f,{}]}function XK(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function ZK({page:e,...t}){let n=vG(),{nonce:r}=JK(),{router:i}=GK(),a=b.useMemo(()=>IH(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),n?b.createElement($K,{page:e,matches:a,...t}):b.createElement(eq,{page:e,matches:a,...t})):null}function QK(e){let{manifest:t,routeModules:n}=JK(),[r,i]=b.useState([]);return b.useEffect(()=>{let r=!1;return zK(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function $K({page:e,matches:t,...n}){let r=NG(),i=b.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=FK(e,`rsc`),i=!1,a=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?i=!0:a.push(e.route.id);return i&&a.length>0&&n.searchParams.set(`_routes`,a.join(`,`)),[n.pathname+n.search]},[e,r,t]);return b.createElement(b.Fragment,null,i.map(e=>b.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function eq({page:e,matches:t,...n}){let r=NG(),{manifest:i,routeModules:a}=JK(),{loaderData:o,matches:s}=KK(),c=b.useMemo(()=>BK(e,t,s,i,r,`data`),[e,t,s,i,r]),l=b.useMemo(()=>BK(e,t,s,i,r,`assets`),[e,t,s,i,r]),u=b.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,s=!1;if(t.forEach(e=>{let t=i.routes[e.route.id];!t||!t.hasLoader||(!c.some(t=>t.route.id===e.route.id)&&e.route.id in o&&a[e.route.id]?.shouldRevalidate||t.hasClientLoader?s=!0:n.add(e.route.id))}),n.size===0)return[];let l=FK(e,`data`);return s&&n.size>0&&l.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[l.pathname+l.search]},[o,r,i,c,t,e,a]),d=b.useMemo(()=>VK(l,i),[l,i]),f=QK(l);return b.createElement(b.Fragment,null,u.map(e=>b.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),d.map(e=>b.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),f.map(({key:e,link:t})=>b.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function tq(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var nq=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{nq&&(window.__reactRouterVersion=`8.3.0`)}catch{}function rq(e,t){return eW({basename:t?.basename,getContext:t?.getContext,future:t?.future,history:_H({window:t?.window}),hydrationData:t?.hydrationData||iq(),routes:e,mapRouteProperties:NH,hydrationRouteProperties:cK,dataStrategy:t?.dataStrategy,patchRoutesOnNavigation:t?.patchRoutesOnNavigation,window:t?.window,instrumentations:t?.instrumentations}).initialize()}function iq(){let e=window?.__staticRouterHydrationData;return e&&e.errors&&(e={...e,errors:aq(e.errors)}),e}function aq(e){if(!e)return null;let t=Object.entries(e),n={};for(let[e,r]of t)if(r&&r.__type===`RouteErrorResponse`)n[e]=new xU(r.status,r.statusText,r.data,r.internal===!0);else if(r&&r.__type===`Error`){if(typeof r.__subType==`string`&&bU.includes(r.__subType)){let t=window[r.__subType];if(typeof t==`function`)try{let i=new t(r.message);i.stack=``,n[e]=i}catch{}}if(n[e]==null){let t=Error(r.message);t.stack=``,n[e]=t}}else n[e]=r;return n}var oq=b.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:g,useTransitions:_}=b.useContext(SG),v=typeof l==`string`&&fH.test(l),y=EU(l,h);l=y.to;let x=jG(l,{relative:r}),S=NG(),C=null;if(o){let e=pU(o,[],S.mask?S.mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:hU([h,e.pathname])),C=g.createHref(e)}let[w,T,E]=YK(n,p),D=dq(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,defaultShouldRevalidate:f,useTransitions:_});function O(t){e&&e(t),t.defaultPrevented||D(t)}let k=!(y.isExternal||i),A=b.createElement(`a`,{...p,...E,href:(k?C:void 0)||y.absoluteURL||x,onClick:k?O:e,ref:tq(m,T),target:c,"data-discover":!v&&t===`render`?`true`:void 0});return w&&!v?b.createElement(b.Fragment,null,A,b.createElement(ZK,{page:x})):A});oq.displayName=`Link`;var sq=b.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=BG(a,{relative:c.relative}),d=NG(),f=b.useContext(gG),{navigator:p,basename:m}=b.useContext(SG),h=f!=null&&_q(u)&&o===!0,g=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,_=d.pathname,v=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(_=_.toLowerCase(),v=v?v.toLowerCase():null,g=g.toLowerCase()),v&&m&&(v=aU(v,m)||v);let y=g!==`/`&&g.endsWith(`/`)?g.length-1:g.length,x=_===g||!r&&_.startsWith(g)&&_.charAt(y)===`/`,S=v!=null&&(v===g||!r&&v.startsWith(g)&&v.charAt(y)===`/`),C={isActive:x,isPending:S,isTransitioning:h},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let E=typeof i==`function`?i(C):i;return b.createElement(oq,{...c,"aria-current":w,className:T,ref:l,style:E,to:a,viewTransition:o},typeof s==`function`?s(C):s)});sq.displayName=`NavLink`;var cq=b.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=`get`,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m)=>{let{useTransitions:h}=b.useContext(SG),g=hq(),_=gq(s,{relative:l}),v=o.toLowerCase()===`get`?`get`:`post`,y=typeof s==`string`&&fH.test(s);return b.createElement(`form`,{ref:m,method:v,action:_,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>g(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f});h&&n!==!1?b.startTransition(()=>p()):p()},...p,"data-discover":!y&&e===`render`?`true`:void 0})});cq.displayName=`Form`;function lq(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function uq(e){let t=b.useContext(hG);return vH(t,lq(e)),t}function dq(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=FG(),d=NG(),f=BG(e,{relative:o});return b.useCallback(p=>{if(EK(p,t)){p.preventDefault();let t=n===void 0?CH(d)===CH(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?b.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function fq(e){yH(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=b.useRef(DK(e)),n=b.useRef(!1),r=NG(),i=b.useMemo(()=>OK(r.search,n.current?null:t.current),[r.search]),a=FG();return[i,b.useCallback((e,t)=>{let r=DK(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var pq=0,mq=()=>`__${String(++pq)}__`;function hq(){let{router:e}=uq(`useSubmit`),{basename:t}=b.useContext(SG),n=tK(),r=e.fetch,i=e.navigate;return b.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=NK(e,t);a.navigate===!1?await r(a.fetcherKey||mq(),n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function gq(e,{relative:t}={}){let{basename:n}=b.useContext(SG),r=b.useContext(wG);vH(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...BG(e||`.`,{relative:t})},o=NG();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:hU([n,a.pathname])),CH(a)}function _q(e,{relative:t}={}){let n=b.useContext(yG);vH(n!=null,"`useViewTransitionState` must be used within `react-router/dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=uq(`useViewTransitionState`),i=BG(e,{relative:t});if(!n.isTransitioning)return!1;let a=aU(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=aU(n.nextLocation.pathname,r)||n.nextLocation.pathname;return tU(i.pathname,o)!=null||tU(i.pathname,a)!=null}function vq(){let{pathname:e}=NG();return(0,b.useEffect)(()=>{window.scrollTo(0,0)},[e]),null}function yq(e){let{serviceRequest:t,...n}=e;return(0,I.jsx)(OR,{value:t,loadTimelineResources:async(e,t,n)=>{let r=`${t}/${n}`;return Promise.allSettled([e.readHistory(`ServiceRequest`,n),e.search(`Communication`,{"based-on":r,_count:100}),e.search(`DiagnosticReport`,{"based-on":r,_count:100}),e.search(`Media`,{"based-on":r,_count:100}),e.search(`DocumentReference`,{related:r,_count:100}),e.search(`Task`,{_filter:`based-on eq ${r} or focus eq ${r} or subject eq ${r}`,_count:100})])},createCommunication:(e,t,n)=>({resourceType:`Communication`,status:`completed`,basedOn:[pC(e)],subject:e.subject,sender:pC(t),sent:new Date().toISOString(),payload:[{contentString:n}]}),createMedia:(e,t,n)=>({resourceType:`Media`,status:`completed`,basedOn:[pC(e)],subject:e.subject,operator:pC(t),issued:new Date().toISOString(),content:n}),...n})}function bq(e){let t=Q(),{client:n,patient:r,encounter:i,children:a,...o}=e,s=Rk(r),c=Rk(i);function l(){let a=r,o=i;if(n.launchIdentifierSystems?.length){let e=n.launchIdentifierSystems.find(e=>e.resourceType===`Patient`);if(a&&s&&e?.system){let t=s.identifier?.find(t=>t.system===e.system);t&&(a={...r,identifier:t})}let t=n.launchIdentifierSystems.find(e=>e.resourceType===`Encounter`);if(o&&c&&t?.system){let e=c.identifier?.find(e=>e.system===t.system);e&&(o={...i,identifier:e})}}t.createResource({resourceType:`SmartAppLaunch`,patient:a,encounter:o,fhirContext:e.fhirContext}).then(e=>{let r=new URL(n.launchUri);r.searchParams.set(`iss`,ow(t.fhirUrl().toString())),r.searchParams.set(`launch`,e.id),window.open(r.toString(),`_blank`)}).catch(e=>J({color:`red`,message:Y(e),autoClose:!1}))}return(0,I.jsx)(Md,{onClick:()=>l(),...o,children:a})}var xq=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Sq=o(((e,t)=>{t.exports=xq()})),Cq=o((e=>{var t=Sq(),n=m(),r=Xi();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.memo_cache_sentinel`),k=Symbol.iterator;function A(e){return typeof e!=`object`||!e?null:(e=k&&e[k]||e[`@@iterator`],typeof e==`function`?e:null)}var j=Symbol.for(`react.client.reference`);function M(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===j?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return t=e.displayName||null,t===null?M(e.type)||`Memo`:t;case E:t=e._payload,e=e._init;try{return M(e(t))}catch{}}return null}var ee=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te={pending:!1,data:null,method:null,action:null},ne=[],re=-1;function ie(e){return{current:e}}function ae(e){0>re||(e.current=ne[re],ne[re]=null,re--)}function oe(e,t){re++,ne[re]=e.current,e.current=t}var se=ie(null),ce=ie(null),le=ie(null),ue=ie(null);function de(e,t){switch(oe(le,t),oe(ce,e),oe(se,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Zd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Zd(t),e=Qd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ae(se),oe(se,e)}function fe(){ae(se),ae(ce),ae(le)}function pe(e){e.memoizedState!==null&&oe(ue,e);var t=se.current,n=Qd(t,e.type);t!==n&&(oe(ce,e),oe(se,n))}function me(e){ce.current===e&&(ae(se),ae(ce)),ue.current===e&&(ae(ue),cp._currentValue=te)}var he,ge;function _e(e){if(he===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);he=t&&t[1]||``,ge=-1<e.stack.indexOf(`
|
|
211
211
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
@@ -240,5 +240,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
240
240
|
|
|
241
241
|
`)}}J({color:`green`,message:`Stream complete`})}catch(e){J({color:`red`,message:Y(e),autoClose:!1})}finally{v(!1)}},[e,n,O,p]);if(!r||s===void 0)return null;let ee=y?S:`sync`;return(0,I.jsxs)(Cm,{m:0,gutter:0,style:{overflow:`hidden`},children:[(0,I.jsx)(Cm.Col,{span:8,children:(0,I.jsxs)(_l,{m:2,pb:`xs`,pr:`xs`,pt:`xs`,shadow:`md`,mih:400,children:[(0,I.jsx)(qZ,{iframeRef:h,language:`typescript`,module:a,testId:`code-frame`,defaultValue:s,minHeight:`528px`}),(0,I.jsxs)(V,{justify:`flex-end`,gap:`xs`,children:[(0,I.jsx)(U,{type:`button`,onClick:k,loading:_,leftSection:(0,I.jsx)(Ej,{size:`1rem`}),children:`Save`}),(0,I.jsx)(U,{type:`button`,onClick:A,loading:_,leftSection:(0,I.jsx)(bj,{size:`1rem`}),children:`Deploy`}),(0,I.jsxs)(V,{wrap:`nowrap`,gap:0,children:[(0,I.jsx)(U,{type:`button`,onClick:ee===`sse`?M:j,loading:_,leftSection:ee===`sse`?(0,I.jsx)(ij,{size:`1rem`}):(0,I.jsx)(nM,{size:`1rem`}),className:y?GZ.splitButton:void 0,children:ee===`sse`?`Execute SSE`:`Execute`}),y&&(0,I.jsxs)(W,{transitionProps:{transition:`pop`},position:`bottom-end`,withinPortal:!0,children:[(0,I.jsx)(W.Target,{children:(0,I.jsx)(mu,{variant:`filled`,color:t.primaryColor,size:36,className:GZ.menuControl,"aria-label":`Execute options`,loading:_,children:(0,I.jsx)(gj,{size:14,stroke:1.5})})}),(0,I.jsx)(W.Dropdown,{children:ee===`sse`?(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(nM,{size:14,stroke:1.5}),onClick:e=>(C(`sync`),j(e)),children:`Execute`}):(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(ij,{size:14,stroke:1.5}),onClick:e=>(C(`sse`),M(e)),children:`Execute SSE`})})]})]})]})]})}),(0,I.jsxs)(Cm.Col,{span:4,children:[(0,I.jsxs)(_l,{m:2,pb:`xs`,pr:`xs`,pt:`xs`,shadow:`md`,children:[(0,I.jsx)(wg,{data:[{label:`FHIR`,value:lD.FHIR_JSON},{label:`HL7`,value:lD.HL7_V2}],onChange:e=>m(e.currentTarget.value)}),p===lD.FHIR_JSON?(0,I.jsx)(sh,{value:l,onChange:e=>u(e),autosize:!0,minRows:15}):(0,I.jsx)(`textarea`,{className:GZ.hl7Input,value:d,onChange:e=>f(e.currentTarget.value),rows:15})]}),(0,I.jsx)(_l,{m:2,p:`xs`,shadow:`md`,children:w===void 0?(0,I.jsx)(KZ,{iframeRef:g,className:`medplum-bot-output-frame`,testId:`output-frame`,minHeight:`200px`}):(0,I.jsx)(ZZ,{events:w,loading:_})})]})]})}function ZZ(e){let{events:t,loading:n}=e;return(0,I.jsxs)(G,{gap:`xs`,"data-testid":`sse-output`,children:[(0,I.jsxs)(V,{justify:`space-between`,children:[(0,I.jsx)(H,{fw:500,size:`sm`,children:`Event stream`}),(0,I.jsxs)(Ap,{color:n?`blue`:`gray`,variant:`light`,children:[n?`Listening`:`Closed`,` · `,t.length]})]}),(0,I.jsx)(cl.Autosize,{mah:400,type:`auto`,children:t.length===0?(0,I.jsx)(H,{c:`dimmed`,size:`sm`,children:n?`Waiting for events…`:`No events received.`}):(0,I.jsx)(G,{gap:`xs`,children:t.map(e=>(0,I.jsx)(em,{block:!0,className:GZ.eventData,children:e.data},e.key))})})]})}function QZ(e){let t,n=[];for(let r of e.split(`
|
|
242
242
|
`)){if(r===``||r.startsWith(`:`))continue;let e=r.indexOf(`:`),i=e===-1?r:r.slice(0,e),a=e===-1?``:r.slice(e+1);a.startsWith(` `)&&(a=a.slice(1)),i===`event`?t=a:i===`data`&&n.push(a)}if(t!==void 0||n.length!==0)return{event:t,data:n.join(`
|
|
243
|
-
`)}}async function $Z(e,t){if(t.sourceCode?.url){let n=t.sourceCode.url?.split(`/`)?.find(VC);return(await e.download(e.fhirUrl(`Binary`,n))).text()}return t.code??``}function eQ(e){let t=e.meta;return t&&={...t,lastUpdated:void 0,versionId:void 0,author:void 0},{...e,meta:t}}function tQ(){let e=Q(),{resourceType:t,id:n}=zG(),r={reference:t+`/`+n},i=(0,b.useCallback)(t=>{e.updateResource(eQ(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)(vF,{children:(0,I.jsx)(EB,{value:r,onSubmit:i})});case`Questionnaire`:return(0,I.jsx)(vF,{children:(0,I.jsx)(cV,{questionnaire:r,onSubmit:i})});default:return null}}function nQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t}),r=FG();return n?(0,I.jsx)(vF,{children:(0,I.jsx)(GV,{value:n,onStart:(e,t)=>r(`/forms/${hC(t)}`)?.catch(console.error),onEdit:(e,t,n)=>r(`/${n.reference}}`)?.catch(console.error)})}):null}function rQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=(0,b.useRef)(0),[a,o]=(0,b.useState)([]);(0,b.useEffect)(()=>{r&&o((r.payload??pw).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(eQ({...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)(vF,{children:(0,I.jsxs)(G,{children:[a.filter(({item:e})=>`contentString`in e).map(({key:e,item:t})=>(0,I.jsx)(ih,{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 iQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=FG();return(0,I.jsxs)(vF,{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 aQ={selectProfileBtn:`_selectProfileBtn_tbaz6_1`,chevron:`_chevron_tbaz6_13`};function oQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t}),[r,i]=(0,b.useState)(),a=Pf({onDropdownClose:()=>a.resetSelectedOption()}),o=(0,b.useMemo)(()=>{if(MC(n?.meta?.profile))return[(0,I.jsx)(Lf.Option,{value:``,children:`None`},``),...n.meta.profile.map(e=>(0,I.jsx)(Lf.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 MC(o)&&(s=(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsxs)(G,{align:`flex-end`,gap:`xs`,children:[(0,I.jsxs)(Lf,{store:a,width:250,position:`bottom-end`,withinPortal:!1,onOptionSubmit:e=>{i(e),a.closeDropdown()},children:[(0,I.jsx)(Lf.Target,{children:(0,I.jsx)(fl,{onClick:()=>a.toggleDropdown(),children:(0,I.jsxs)(em,{fw:`bold`,fs:`sm`,className:aQ.selectProfileBtn,children:[(0,I.jsx)(`span`,{children:`Pick profile`}),(0,I.jsx)(gj,{stroke:1.5,className:aQ.chevron})]})})}),(0,I.jsx)(Lf.Dropdown,{w:`max-content`,children:(0,I.jsx)(Lf.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)(vF,{children:(0,I.jsxs)(G,{gap:`xl`,children:[s,(0,I.jsx)(CR,{value:n,profileUrl:r})]})})}function sQ(){let e=Q(),{resourceType:t,id:n}=zG(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(),s=FG(),[c,l]=(0,b.useState)();(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>{i(BC(e)),o(BC(e))}).catch(e=>{l(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n]);let u=(0,b.useCallback)(r=>{l(void 0),e.updateResource(eQ(r)).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n,s]),d=(0,b.useCallback)(i=>{l(void 0);let a=$O(r,eQ(i));e.patchResource(t,n,a).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(aS(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)(vF,{children:(0,I.jsx)(cH,{defaultValue:a,onSubmit:u,onPatch:d,onDelete:f,outcome:c})}):null}function cQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?(0,I.jsx)(vF,{maw:700,children:n.resourceType===`Patient`?(0,I.jsx)(bB,{patient:n}):(0,I.jsx)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Unsupported export type`,color:`red`,children:`This page is only supported for Patient resources`})}):null}function lQ({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(FI))}).catch(console.error)},[i,n,r]),(0,I.jsx)(gb,{value:t?.url,onChange:e=>{let t=a?.find(t=>t.url===e);t&&n(t)},children:(0,I.jsx)(gb.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)(gb.Tab,{value:t.url,title:r,rightSection:n&&(0,I.jsx)(bb,{variant:`outline`,color:`green`,size:`xs`,style:{borderStyle:`none`},children:(0,I.jsx)(TM,{size:`90%`})}),children:t.title||t.name},t.url)})})})}function uQ(e,t){let n=Q(),r=FG();return{defaultValue:{resourceType:e},handleSubmit:e=>{t&&t(void 0),n.createResource(e).then(e=>r(`/`+e.resourceType+`/`+e.id)).catch(e=>{t&&t(aS(e)),J({color:`red`,message:Y(e),autoClose:!1,styles:{description:{whiteSpace:`pre-line`}}})})}}}function dQ(){let{resourceType:e}=zG(),t=NG(),[n,r]=(0,b.useState)(),{defaultValue:i,handleSubmit:a}=uQ(e,r),[o,s]=(0,b.useState)(),c=t.pathname.toLowerCase().endsWith(`profiles`),l=(0,b.useCallback)(e=>{let t=eQ(e);o&&dw(t,o.url),a(t)},[o,a]);return c?(0,I.jsx)(vF,{children:(0,I.jsxs)(G,{children:[(0,I.jsx)(lQ,{resource:i,currentProfile:o,onChange:s}),o?(0,I.jsx)(cH,{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)(vF,{children:(0,I.jsx)(cH,{defaultValue:i,onSubmit:a,outcome:n})})}function fQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=e.readHistory(t,n).read();return(0,I.jsx)(vF,{children:(0,I.jsx)(lH,{history:r})})}function pQ(){let{resourceType:e}=zG(),[t,n]=(0,b.useState)(),{defaultValue:r,handleSubmit:i}=uQ(e,n),a=(0,b.useCallback)(e=>{i(JSON.parse(e[`new-resource`]))},[i]);return(0,I.jsxs)(vF,{children:[t&&(0,I.jsx)(VF,{outcome:t}),(0,I.jsxs)(hP,{onSubmit:a,children:[(0,I.jsx)(sh,{name:`new-resource`,"data-testid":`create-resource-json`,autosize:!0,minRows:24,defaultValue:DC(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 mQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=FG(),[a,o]=(0,b.useState)(),s=(0,b.useCallback)(r=>{e.updateResource(eQ(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)(vF,{children:[a&&(0,I.jsx)(VF,{outcome:a}),(0,I.jsxs)(hP,{onSubmit:s,children:[(0,I.jsx)(sh,{name:`resource`,"data-testid":`resource-json`,autosize:!0,minRows:24,defaultValue:DC(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 hQ(e){let{resourceType:t,id:n}=e;return(0,I.jsxs)(vF,{children:[(0,I.jsxs)(Td,{icon:(0,I.jsx)(QA,{size:16}),mb:`xl`,children:[`This is just a preview! Access your form here:`,(0,I.jsx)(`br`,{}),(0,I.jsx)(Md,{href:`/forms/${n}`,children:`/forms/${n}`})]}),(0,I.jsx)(NV,{questionnaire:{reference:t+`/`+n},onSubmit:()=>alert(`You submitted the preview`)})]})}var gQ={propertyTable:`_propertyTable_1xts4_1`,propertiesTitle:`_propertiesTitle_1xts4_17`};function _Q(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 vQ(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=_Q(e))}),{code:t,description:n,value:r}});return(0,I.jsxs)(K,{className:gQ.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 yQ(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(),i=await n.get(r);s(i)}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)(vF,{children:(0,I.jsxs)(G,{gap:`xl`,children:[(0,I.jsx)(wP,{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)(cF,{children:[(0,I.jsx)(lF,{term:`Code`,children:i.code}),i.system&&(0,I.jsx)(lF,{term:`System`,children:i.system}),i.display&&(0,I.jsx)(lF,{term:`Display`,children:i.display})]}),c&&(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(ou,{size:`sm`}),(0,I.jsx)(H,{size:`sm`,c:`dimmed`,children:`Loading properties...`})]}),!c&&u&&(0,I.jsxs)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Lookup Failed`,color:`red`,children:[`Failed to retrieve code information: `,Y(u)]}),!c&&!u&&m&&(0,I.jsx)(EM,{children:(0,I.jsxs)(G,{gap:`xs`,mt:`lg`,children:[(0,I.jsx)(H,{fw:500,size:`sm`,c:`dimmed`,className:gQ.propertiesTitle,children:`Properties`}),(0,I.jsx)(vQ,{properties:p})]})})]}):null]})})}function bQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?n.resourceType===`Questionnaire`?(0,I.jsx)(hQ,{resourceType:e,id:t}):n.resourceType===`ValueSet`?(0,I.jsx)(yQ,{valueSet:n}):null:null}function xQ(){let e=Q(),{resourceType:t,id:n}=zG(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)();return(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>i(BC(e))).catch(e=>{J({color:`red`,message:Y(e)})})},[e,t,n]),r?(0,I.jsxs)(vF,{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)(lQ,{resource:r,currentProfile:a,onChange:o}),a?(0,I.jsx)(SQ,{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 SQ=({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=eQ(t);o?dw(i,e.url):fw(i,e.url),r.updateResource(i).then(e=>{n(e),J({color:`green`,message:`Success`})}).catch(e=>{a(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[r,e.url,n,o]);return(0,I.jsxs)(G,{children:[(0,I.jsx)(Hy,{size:`md`,checked:o,label:`Conform resource to ${e.title}`,onChange:e=>s(e.currentTarget.checked),"data-testid":`profile-toggle`}),o?(0,I.jsx)(cH,{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`})})})]})},CQ={"Create Only":`create`,"Update Only":`update`,"Delete Only":`delete`,"All Interactions":void 0},wQ=Object.keys(CQ);function TQ(){let e=Q(),{id:t}=zG(),n=Rk({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=>EQ(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},${mC(n)}`:mC(n)}`,channel:{type:`rest-hook`,endpoint:mC(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)(vF,{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)(UL,{value:{reference:e.channel?.endpoint},link:!0})}),(0,I.jsxs)(`p`,{children:[`Criteria: `,e.criteria]})]},e.id))]}),(0,I.jsx)(lm,{}),(0,I.jsxs)(G,{mt:10,children:[(0,I.jsx)(td,{size:`lg`,htmlFor:`bot`,children:`Connect to bot`}),(0,I.jsxs)(V,{children:[(0,I.jsx)(uL,{name:`bot`,resourceType:`Bot`,onChange:e=>i(e)}),(0,I.jsx)(U,{onClick:u,children:`Connect`})]}),(0,I.jsx)(V,{children:(0,I.jsx)(wg,{name:`subscription-trigger-event`,defaultValue:`Create Only`,label:`Subscription Trigger Event`,data:wQ,onChange:e=>o(CQ[e.target.value])})})]}),(0,I.jsx)(`div`,{style:{display:`none`},children:s})]})}function EQ(e,t){if(!t)return!1;let n=e.criteria||``,r=e.channel?.endpoint||``;return n.startsWith(`QuestionnaireResponse?`)&&r.startsWith(`Bot/`)&&(n.includes(mC(t))||(t.url?n.includes(t.url):!1))}function DQ(){let{id:e}=zG(),t=FG(),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)(vF,{children:(0,I.jsx)(Wz,{search:r,onClick:e=>t(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0,hideToolbar:!0})})}function OQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=(0,b.useCallback)(t=>{e.updateResource(eQ(t)).then(()=>{J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})},[e]);return r?(0,I.jsx)(vF,{children:(0,I.jsx)(LV,{onSubmit:i,definition:r})}):null}function kQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?(0,I.jsx)(vF,{children:e===`MeasureReport`?(0,I.jsx)(dB,{measureReport:n}):(0,I.jsx)(KL,{value:n})}):null}var AQ={container:`_container_1ue98_1`,entry:`_entry_1ue98_14`,active:`_active_1ue98_21`};function jQ(e){let t=Q(),n=Rk(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:mC(e);t.search(`ServiceRequest`,`subject=`+r).then(e=>{let t=(e.entry??[]).map(e=>e.resource);uR(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:AQ.container,children:r.map(e=>(0,I.jsxs)(`div`,{className:Mn(AQ.entry,{[AQ.active]:e.id===n?.id}),children:[(0,I.jsx)(`p`,{children:(0,I.jsx)(IM,{to:e,children:MQ(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:NQ(e)})]},e.id))}):null}function MQ(e){if(e.identifier){for(let t of e.identifier)if(t.value)return t.value}return e.id||``}function NQ(e){return e.authoredOn?e.authoredOn.substring(0,10):e.meta?.lastUpdated?e.meta.lastUpdated.substring(0,10):``}var PQ={container:`_container_1l2dh_1`};function FQ(e){let t=Rk(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:PQ.container,children:(0,I.jsx)(wg,{defaultValue:e.defaultValue,onChange:t=>e.onChange(t.currentTarget.value),data:n})})}function IQ(e){let t=Rk(e.specimen);return t?(0,I.jsxs)(eB,{children:[(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Type`}),(0,I.jsx)(eB.Value,{children:`Specimen`})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Collected`}),(0,I.jsx)(eB.Value,{children:bw(t.collection?.collectedDateTime)})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Specimen Age`}),(0,I.jsx)(eB.Value,{children:LQ(t)})]}),t.collection?.collectedDateTime&&t.receivedTime?(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Specimen Stability`}),(0,I.jsx)(eB.Value,{children:RQ(t)})]}):(0,I.jsx)(I.Fragment,{})]}):null}function LQ(e){let t=e.collection?.collectedDateTime;if(t)return zQ(BQ(new Date(t),new Date))}function RQ(e){if(!(!e.collection?.collectedDateTime||!e.receivedTime))return zQ(BQ(new Date(e.collection.collectedDateTime),new Date(e.receivedTime)))}function zQ(e){return e.toString().padStart(3,`0`)+`D`}function BQ(e,t){let n=t.getTime()-e.getTime();return Math.floor(n/864e5)}function VQ(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 HQ(){let e=Q(),{resourceType:t,id:n}=zG(),r={reference:t+`/`+n},[i,a]=(0,b.useState)(),o=Rk(r,a),s=VQ(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(eQ(t)).then(()=>{a(void 0),J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})}if(i)return nS(i)?(0,I.jsxs)(vF,{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)(VF,{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&&Eq(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)(FQ,{valueSet:{reference:p},defaultValue:o.orderDetail?.[0]?.text,onChange:u},mC(o)+`-`+o.orderDetail?.[0]?.text),o&&(0,I.jsx)(jQ,{value:o}),o&&(0,I.jsxs)(_l,{children:[d&&(0,I.jsx)(CB,{patient:d}),f&&(0,I.jsx)(IQ,{specimen:f}),t!==`Patient`&&(0,I.jsx)(dZ,{resource:r}),(0,I.jsx)(cl,{children:(0,I.jsx)(nB,{baseUrl:`/${t}/${n}`,tabs:s})})]}),(0,I.jsx)(hK,{})]})}function UQ(){let e=FG(),{resourceType:t,id:n,versionId:r,tab:i}=zG(),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)(DM,{});let f=c?.entry??[],p=f.findIndex(e=>e.resource?.meta?.versionId===r);if(p===-1)return(0,I.jsxs)(vF,{children:[(0,I.jsx)(q,{children:`Version not found`}),(0,I.jsx)(IM,{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)(rm,{maw:1200,children:(0,I.jsx)(_F,{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)(gy,{cols:2,mb:`lg`,children:[(0,I.jsx)(tv,{total:f.length,value:v,getControlProps:Lz,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)(cy,{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)(cF,{compact:!0,children:[(0,I.jsx)(lF,{term:`Version ID`,children:m.meta?.versionId}),(0,I.jsx)(lF,{term:`Author`,children:(0,I.jsx)(WL,{value:m.meta?.author,link:!0},m.meta?.author?.reference)}),(0,I.jsx)(lF,{term:`Date/Time`,children:bw(m.meta?.lastUpdated)})]})}),_===`diff`&&(0,I.jsx)(aH,{original:h??{},revised:m}),_===`raw`&&(0,I.jsx)(`pre`,{style:{fontSize:`9pt`},children:JSON.stringify(m,void 0,2)})]})})})}function WQ(){let{resourceType:e,id:t}=zG(),n=FG(),[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)(vF,{children:(0,I.jsx)(Wz,{search:r,onClick:e=>n(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0})})}function GQ(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),p=(0,b.useCallback)(async()=>{if(n?.id)try{await t.post(t.fhirUrl(n.resourceType,n.id,`$resend`),{subscription:a&&s?mC(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]);return(0,I.jsx)(tg,{opened:r,onClose:i,title:`Resend Subscriptions`,children:(0,I.jsx)(hP,{onSubmit:p,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(sp,{label:`Choose subscription (all subscriptions by default)`,onChange:e=>o(e.currentTarget.checked)}),a&&(0,I.jsx)(uL,{name:`subscription`,resourceType:`Subscription`,placeholder:`Subscription`,onChange:c}),(0,I.jsx)(wg,{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)(sp,{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 KQ(){let e=Q(),t=Ok(),{resourceType:n,id:r}=zG(),i={reference:n+`/`+r},[a,o]=(0,b.useState)(),s=bn(!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(),Pb({id:r,title:`AWS Textract Successful`,message:`Text successfully extracted.`,color:`green`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,withCloseButton:!0})}).catch(e=>Pb({id:r,title:`AWS Textract Error`,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{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=NZ()&&(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)(eM,{size:14}),onClick:()=>l(r,i),"aria-label":`Pin ${mC(r)}`,children:`Pin`}),s&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(tM,{size:14}),onClick:()=>u(r,i),"aria-label":`Unpin ${mC(r)}`,children:`Unpin`}),_&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>d(r),"aria-label":`Details ${mC(r)}`,children:`Details`}),c&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>h(r),"aria-label":`Details ${mC(r)}`,children:`Details`}),v&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Oj,{size:14}),onClick:()=>f(r),"aria-label":`Edit ${mC(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)(oM,{size:14}),onClick:()=>m(r),"aria-label":`Resend Subscriptions ${mC(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)(yM,{size:14}),onClick:()=>g(r,i),"aria-label":`AWS Textract ${mC(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)(bM,{size:14}),onClick:()=>p(r),"aria-label":`Delete ${mC(r)}`,children:`Delete`})]})]})}return(0,I.jsxs)(I.Fragment,{children:[n===`Encounter`&&(0,I.jsx)(RR,{encounter:i,getMenu:_}),n===`Patient`&&(0,I.jsx)(wB,{patient:i,getMenu:_}),n===`ServiceRequest`&&(0,I.jsx)(yq,{serviceRequest:i,getMenu:_}),n!==`Encounter`&&n!==`Patient`&&n!==`ServiceRequest`&&(0,I.jsx)(LR,{resource:i,getMenu:_}),(0,I.jsx)(GQ,{resource:a,opened:s[0],onClose:s[1].close},`resend-subscriptions-${a?.id}`)]})}var qQ=5,JQ=`The Medplum Agent is frequently patched with new features and bugfixes. Downgrading your agent can result in picking up old bugs or losing features you may be relying on. Are you sure you want to downgrade?`;function YQ(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)(),[d,f]=(0,b.useState)(),[p,m]=(0,b.useState)(!1);if((0,b.useEffect)(()=>{t&&(s||wk(`app-tools-page`).then(c).catch(console.error),l||Tk(`app-tools-page`).then(u).catch(e=>{console.error(e),u([])}),a())},[t,s,l,a]),!r||i)return(0,I.jsx)(DM,{});if(r===`unknown`)return(0,I.jsx)(`p`,{children:`Unable to determine the current version of the agent. Check the network connectivity of the agent.`});if(!(s&&l))return(0,I.jsx)(DM,{});let h=d??s,g=l.filter(e=>Ck(e,r)>0),_=l.filter(e=>Ck(e,r)<0),v=g.slice(0,qQ),y=_.slice(0,qQ),x=v.includes(s)?[...v,...y]:[s,...v,...y],S=Ck(h,r)<0,C=Ck(h,r)===0;function w(e){return{value:e,label:e===s?`${e} (Latest)`:e,resource:e}}let T=l;async function E(e){if(!e)return x;let t=e.toLowerCase();return T.filter(e=>e.toLowerCase().includes(t))}function D(){S&&!window.confirm(JQ)||(o(p,h),n())}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iN,{label:`Target Version`,placeholder:`Search versions...`,defaultValue:h,toOption:w,loadOptions:E,onChange:([e])=>{e&&f(e)},maxValues:1,clearable:!1}),C?(0,I.jsxs)(`p`,{children:[`This agent is already on version `,h,`.`]}):(0,I.jsxs)(`p`,{children:[`Are you sure you want to `,S?`downgrade`:`upgrade`,` this agent from version `,r,` to version`,` `,h,`?`]}),(0,I.jsxs)(V,{children:[(0,I.jsx)(U,{onClick:D,"aria-label":`Confirm upgrade`,children:`Confirm Upgrade`}),(0,I.jsx)(sp,{label:`Force`,onChange:e=>m(e.currentTarget.checked)})]})]})}var XQ=[`live`,`ping`,`hl7ConnectionsOpen`,`hl7ClientCount`,`hl7QueueDepth`,`webSocketQueueDepth`,`outstandingHeartbeats`];function ZQ(e){return e==null?``:typeof e==`object`?JSON.stringify(e):typeof e==`number`?e.toLocaleString():e.toString()}function QQ(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 $Q(e){let{stats:t}=e,n=new Set([...XQ,`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:[XQ.map(e=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:e}),(0,I.jsx)(K.Td,{children:ZQ(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:ZQ(t)})]},e))]})}),(0,I.jsx)(QQ,{title:`Channel Stats`,entries:t.channelStats}),(0,I.jsx)(QQ,{title:`Client Stats`,entries:t.clientStats})]})}function e$(){let e=Q(),{id:t}=zG(),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}]=bn(!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),v(e.parameter?.find(e=>e.name===`lastUpdated`)?.valueInstant);let t=e.parameter?.find(e=>e.name===`version`)?.valueString;t===void 0||t===`unknown`||xk(t)?g(t):n$(`Invalid version received from $status operation`)}).catch(e=>n$(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}`,lD.PING,!0).then(e=>x(e)).catch(e=>n$(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=>{t$(`Agent config reloaded successfully.`)}).catch(e=>n$(Y(e))).finally(()=>o(!1))},[e,t]),oe=(0,b.useCallback)((n,r)=>{c(!0);let i=e.fhirUrl(`Agent`,t,`$upgrade`);i.searchParams.set(`force`,String(n)),i.searchParams.set(`version`,r),e.get(i,{cache:`reload`}).then(e=>{t$(`Agent upgraded successfully.`)}).catch(e=>n$(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=>n$(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){n$(Y(e))}}).catch(e=>n$(Y(e))).finally(()=>f(!1))},[e,t]);return(0,I.jsxs)(vF,{children:[(0,I.jsx)(tg,{opened:N,onClose:te,title:`Upgrade Agent`,centered:!0,children:(0,I.jsx)(YQ,{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)(UL,{value:n,link:!0})]}),(0,I.jsx)(lm,{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)(BL,{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:bw(_,void 0,{timeZoneName:`longOffset`})})]})]})}),(0,I.jsx)(lm,{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)(lm,{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)(lm,{my:`lg`}),(0,I.jsxs)(hP,{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)(em,{block:!0,mb:15,children:w}):null,(0,I.jsxs)(V,{children:[(0,I.jsx)(M_,{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)(lm,{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)($Q,{stats:M}),(0,I.jsx)(lm,{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)(hP,{onSubmit:ie,children:(0,I.jsxs)(V,{children:[(0,I.jsx)(_b,{id:`host`,name:`host`,placeholder:`ex. 127.0.0.1`,label:`IP Address / Hostname`,rightSection:(0,I.jsx)(mu,{size:24,radius:`xl`,variant:`filled`,type:`submit`,"aria-label":`Ping`,loading:S,disabled:ne&&!S,children:(0,I.jsx)(cM,{style:{width:`1rem`,height:`1rem`},stroke:1.5})})}),(0,I.jsx)(M_,{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 t$(e){J({color:`green`,title:`Success`,icon:(0,I.jsx)(mj,{size:`1rem`}),message:e})}function n$(e){J({color:`red`,title:`Error`,message:e,autoClose:!1})}function r$(){let e=Q(),{id:t}=zG(),n=Rk({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)(vF,{children:(0,I.jsx)(Td,{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)(vF,{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)(_b,{label:`New Email`,type:`email`,required:!0,placeholder:`new@example.com`,value:r,onChange:e=>i(e.currentTarget.value)}),(0,I.jsx)(sp,{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)(sp,{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 i$(){let e=FG(),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)(vF,{children:[(0,I.jsx)(q,{children:`Security`}),(0,I.jsxs)(cF,{children:[(0,I.jsx)(lF,{term:`ID`,children:(0,I.jsx)(Md,{href:`/${mC(n.profile)}`,children:n.profile.id})}),(0,I.jsx)(lF,{term:`Resource Type`,children:n.profile.resourceType}),(0,I.jsx)(lF,{term:`Name`,children:_w(n.profile.name?.[0])})]})]}),(0,I.jsxs)(vF,{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:`Project`}),(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.project?.display??`Unknown`}),(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:bw(e.lastUpdated)}),(0,I.jsx)(`td`,{children:(0,I.jsx)(Md,{href:`#`,onClick:()=>i(e.id),children:`Revoke`})})]},e.id))})]})]}),(0,I.jsxs)(vF,{children:[(0,I.jsx)(q,{children:`Password`}),(0,I.jsx)(U,{onClick:()=>e(`/changepassword`)?.catch(console.error),children:`Change password`})]}),(0,I.jsxs)(vF,{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 a$(){let{id:e,secret:t}=zG(),n=FG();return(0,I.jsx)(ZF,{id:e,secret:t,onSignIn:()=>n(`/signin`)?.catch(console.error)})}function o$(){let e=kk(),t=FG(),[n]=fq(),r=jZ(),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)(rI,{onSuccess:()=>i(),onForgotPassword:()=>t(`/resetpassword`)?.catch(console.error),onRegister:MZ()?()=>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)(yF,{size:32}),n.get(`project`)!==`new`&&(0,I.jsxs)(q,{order:3,py:`lg`,ta:`center`,children:[`Sign in to `,qM()]}),n.get(`project`)===`new`&&(0,I.jsx)(q,{order:3,py:`lg`,ta:`center`,children:`Sign in again to create a new project`})]})}function s$(){let e=FG(),t=NG(),[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)(Qz,{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 c$(){let{id:e,secret:t}=zG(),n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1),s=SF(r,void 0);return(0,I.jsxs)(vF,{width:450,children:[(0,I.jsx)(VF,{issues:s}),(0,I.jsxs)(hP,{onSubmit:async()=>{i(void 0);try{let r=Qx(await n.post(`auth/verifyemail`,{id:e,secret:t}));r?YE.assign(r):o(!0)}catch(e){i(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{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)(gP,{children:`Verify email`})})]}),a&&(0,I.jsxs)(`div`,{"data-testid":`success`,children:[`Email verified. You can now\xA0`,(0,I.jsx)(IM,{to:`/signin`,children:`sign in`}),`.`]})]})]})}function l$(){return(0,I.jsx)(vK,{children:(0,I.jsxs)(gK,{errorElement:(0,I.jsx)(uZ,{}),children:[(0,I.jsx)(gK,{path:`/signin`,element:(0,I.jsx)(o$,{})}),(0,I.jsx)(gK,{path:`/oauth`,element:(0,I.jsx)(FZ,{})}),(0,I.jsx)(gK,{path:`/resetpassword`,element:(0,I.jsx)(LZ,{})}),(0,I.jsx)(gK,{path:`/setpassword/:id/:secret`,element:(0,I.jsx)(a$,{})}),(0,I.jsx)(gK,{path:`/verifyemail/:id/:secret`,element:(0,I.jsx)(c$,{})}),(0,I.jsx)(gK,{path:`/register`,element:(0,I.jsx)(IZ,{})}),(0,I.jsx)(gK,{path:`/changepassword`,element:(0,I.jsx)(sZ,{})}),(0,I.jsx)(gK,{path:`/security`,element:(0,I.jsx)(i$,{})}),(0,I.jsx)(gK,{path:`/mfa`,element:(0,I.jsx)(kZ,{})}),(0,I.jsx)(gK,{path:`/batch`,element:(0,I.jsx)(aZ,{})}),(0,I.jsx)(gK,{path:`/bulk/:resourceType`,element:(0,I.jsx)(oZ,{})}),(0,I.jsx)(gK,{path:`/smart`,element:(0,I.jsx)(s$,{})}),(0,I.jsx)(gK,{path:`/forms/:id`,element:(0,I.jsx)(fZ,{})}),(0,I.jsx)(gK,{path:`/admin/super`,element:(0,I.jsx)(iY,{})}),(0,I.jsx)(gK,{path:`/admin/super/asyncjob/:tab`,element:(0,I.jsx)(WJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/asyncjob`,element:(0,I.jsx)(WJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/db/:tab`,element:(0,I.jsx)(dJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/db`,element:(0,I.jsx)(dJ,{})}),(0,I.jsx)(gK,{path:`/admin/config`,element:(0,I.jsx)(SJ,{})}),(0,I.jsxs)(gK,{path:`/admin`,element:(0,I.jsx)(TJ,{}),children:[(0,I.jsx)(gK,{path:`bots/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`bots/new`,element:(0,I.jsx)(Rq,{})}),(0,I.jsx)(gK,{path:`bots`,element:(0,I.jsx)(Fq,{})}),(0,I.jsx)(gK,{path:`clients/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`clients/new`,element:(0,I.jsx)(zq,{})}),(0,I.jsx)(gK,{path:`clients`,element:(0,I.jsx)(Iq,{})}),(0,I.jsx)(gK,{path:`details`,element:(0,I.jsx)(CJ,{})}),(0,I.jsx)(gK,{path:`invite`,element:(0,I.jsx)(fJ,{})}),(0,I.jsx)(gK,{path:`patients`,element:(0,I.jsx)(mK,{to:`/admin/users`,replace:!0})}),(0,I.jsx)(gK,{path:`users/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`users`,element:(0,I.jsx)(lY,{})}),(0,I.jsx)(gK,{path:`project`,element:(0,I.jsx)(CJ,{})}),(0,I.jsx)(gK,{path:`secrets`,element:(0,I.jsx)(BJ,{})}),(0,I.jsx)(gK,{path:`settings`,element:(0,I.jsx)(VJ,{})}),(0,I.jsx)(gK,{path:`sites`,element:(0,I.jsx)(HJ,{})}),(0,I.jsx)(gK,{path:`rate-limits`,element:(0,I.jsx)(IJ,{})})]}),(0,I.jsx)(gK,{path:`/lab/assays`,element:(0,I.jsx)(wZ,{})}),(0,I.jsx)(gK,{path:`/lab/panels`,element:(0,I.jsx)(DZ,{})}),(0,I.jsxs)(gK,{path:`/:resourceType/new`,element:(0,I.jsx)(lZ,{}),children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(dQ,{})}),(0,I.jsx)(gK,{path:`form`,element:(0,I.jsx)(dQ,{})}),(0,I.jsx)(gK,{path:`json`,element:(0,I.jsx)(pQ,{})}),(0,I.jsx)(gK,{path:`profiles`,element:(0,I.jsx)(dQ,{})})]}),(0,I.jsxs)(gK,{path:`/:resourceType/:id`,element:(0,I.jsx)(HQ,{}),children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(KQ,{})}),(0,I.jsx)(gK,{path:`apply`,element:(0,I.jsx)(BZ,{})}),(0,I.jsx)(gK,{path:`apps`,element:(0,I.jsx)(VZ,{})}),(0,I.jsx)(gK,{path:`event`,element:(0,I.jsx)(UZ,{})}),(0,I.jsx)(gK,{path:`blame`,element:(0,I.jsx)(WZ,{})}),(0,I.jsx)(gK,{path:`bots`,element:(0,I.jsx)(TQ,{})}),(0,I.jsx)(gK,{path:`builder`,element:(0,I.jsx)(tQ,{})}),(0,I.jsx)(gK,{path:`checklist`,element:(0,I.jsx)(nQ,{})}),(0,I.jsx)(gK,{path:`delete`,element:(0,I.jsx)(iQ,{})}),(0,I.jsx)(gK,{path:`details`,element:(0,I.jsx)(oQ,{})}),(0,I.jsx)(gK,{path:`edit`,element:(0,I.jsx)(sQ,{})}),(0,I.jsx)(gK,{path:`editor`,element:(0,I.jsx)(XZ,{})}),(0,I.jsxs)(gK,{path:`history`,children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(fQ,{})}),(0,I.jsx)(gK,{path:`:versionId/:tab`,element:(0,I.jsx)(UQ,{})}),(0,I.jsx)(gK,{path:`:versionId`,element:(0,I.jsx)(UQ,{})})]}),(0,I.jsxs)(gK,{path:`_history`,children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(fQ,{})}),(0,I.jsx)(gK,{path:`:versionId/:tab`,element:(0,I.jsx)(UQ,{})}),(0,I.jsx)(gK,{path:`:versionId`,element:(0,I.jsx)(UQ,{})})]}),(0,I.jsx)(gK,{path:`json`,element:(0,I.jsx)(mQ,{})}),(0,I.jsx)(gK,{path:`preview`,element:(0,I.jsx)(bQ,{})}),(0,I.jsx)(gK,{path:`responses`,element:(0,I.jsx)(DQ,{})}),(0,I.jsx)(gK,{path:`report`,element:(0,I.jsx)(kQ,{})}),(0,I.jsx)(gK,{path:`ranges`,element:(0,I.jsx)(OQ,{})}),(0,I.jsx)(gK,{path:`subscriptions`,element:(0,I.jsx)(WQ,{})}),(0,I.jsx)(gK,{path:`timeline`,element:(0,I.jsx)(KQ,{})}),(0,I.jsx)(gK,{path:`tools`,element:(0,I.jsx)(e$,{})}),(0,I.jsx)(gK,{path:`email`,element:(0,I.jsx)(r$,{})}),(0,I.jsx)(gK,{path:`payload`,element:(0,I.jsx)(rQ,{})}),(0,I.jsx)(gK,{path:`profiles`,element:(0,I.jsx)(xQ,{})}),(0,I.jsx)(gK,{path:`accounts`,element:(0,I.jsx)(RZ,{})}),(0,I.jsx)(gK,{path:`export`,element:(0,I.jsx)(cQ,{})})]}),(0,I.jsx)(gK,{path:`/:resourceType`,element:(0,I.jsx)(CZ,{})}),(0,I.jsx)(gK,{path:`/`,element:(0,I.jsx)(CZ,{})})]})})}function u$(){let e=Q(),t=e.getUserConfiguration(),n=e.getProject(),r=NG(),[i]=fq();return e.isLoading()?(0,I.jsx)(DM,{}):(0,I.jsxs)(eF,{logo:(0,I.jsx)(yF,{size:24}),pathname:r.pathname,searchParams:i,version:QD,menus:d$(t),displayAddBookmark:!!t?.id,announcements:n?.superAdmin?[{message:(0,I.jsxs)(I.Fragment,{children:[`Warning: logged in as`,` `,(0,I.jsx)(oq,{to:`https://www.medplum.com/docs/self-hosting/super-admin-guide`,children:`Medplum Super Admin`}),`.`]}),color:`red`,icon:(0,I.jsx)($A,{size:16}),role:`alert`}]:void 0,children:[(0,I.jsx)(vq,{}),(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(DM,{}),children:(0,I.jsx)(l$,{})})]})}function d$(e){let t=e?.menu?.map(e=>({title:e.title,links:e.link?.map(e=>({label:e.name,href:e.target,icon:p$(e.target)}))||[]}))||[];return t.push({title:`Settings`,links:[{label:`Security`,href:`/security`,icon:(0,I.jsx)(Uj,{})}]}),t}var f$={Patient:mM,Practitioner:Rj,Organization:fj,ServiceRequest:iM,DiagnosticReport:sM,Questionnaire:Lj,Project:Ij,admin:cj,AccessPolicy:Hj,Subscription:CM,batch:Zj,Observation:Jj};function p$(e){if(e.includes(`admin/super/db`))return(0,I.jsx)(wj,{});try{let t=new URL(e,`https://app.medplum.com`).pathname.split(`/`)[1];if(t in f$){let e=f$[t];return(0,I.jsx)(e,{})}}catch{}}async function m$(){let e=jZ(),t=new dO({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=ci({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=rq([{path:`*`,element:(0,I.jsx)(u$,{})}]);(0,wq.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(b.StrictMode,{children:(0,I.jsx)(jk,{medplum:t,navigate:e=>r.navigate(e),children:(0,I.jsxs)(Vr,{theme:n,children:[(0,I.jsx)(yx,{position:`bottom-right`}),(0,I.jsx)(uK,{router:r})]})})}))}m$().catch(console.error);export{o as t};
|
|
244
|
-
//# sourceMappingURL=index-
|
|
243
|
+
`)}}async function $Z(e,t){if(t.sourceCode?.url){let n=t.sourceCode.url?.split(`/`)?.find(VC);return(await e.download(e.fhirUrl(`Binary`,n))).text()}return t.code??``}function eQ(e){let t=e.meta;return t&&={...t,lastUpdated:void 0,versionId:void 0,author:void 0},{...e,meta:t}}function tQ(){let e=Q(),{resourceType:t,id:n}=zG(),r={reference:t+`/`+n},i=(0,b.useCallback)(t=>{e.updateResource(eQ(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)(vF,{children:(0,I.jsx)(EB,{value:r,onSubmit:i})});case`Questionnaire`:return(0,I.jsx)(vF,{children:(0,I.jsx)(cV,{questionnaire:r,onSubmit:i})});default:return null}}function nQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t}),r=FG();return n?(0,I.jsx)(vF,{children:(0,I.jsx)(GV,{value:n,onStart:(e,t)=>r(`/forms/${hC(t)}`)?.catch(console.error),onEdit:(e,t,n)=>r(`/${n.reference}}`)?.catch(console.error)})}):null}function rQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=(0,b.useRef)(0),[a,o]=(0,b.useState)([]);(0,b.useEffect)(()=>{r&&o((r.payload??pw).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(eQ({...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)(vF,{children:(0,I.jsxs)(G,{children:[a.filter(({item:e})=>`contentString`in e).map(({key:e,item:t})=>(0,I.jsx)(ih,{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 iQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=FG();return(0,I.jsxs)(vF,{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 aQ={selectProfileBtn:`_selectProfileBtn_tbaz6_1`,chevron:`_chevron_tbaz6_13`};function oQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t}),[r,i]=(0,b.useState)(),a=Pf({onDropdownClose:()=>a.resetSelectedOption()}),o=(0,b.useMemo)(()=>{if(MC(n?.meta?.profile))return[(0,I.jsx)(Lf.Option,{value:``,children:`None`},``),...n.meta.profile.map(e=>(0,I.jsx)(Lf.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 MC(o)&&(s=(0,I.jsx)(V,{justify:`flex-end`,children:(0,I.jsxs)(G,{align:`flex-end`,gap:`xs`,children:[(0,I.jsxs)(Lf,{store:a,width:250,position:`bottom-end`,withinPortal:!1,onOptionSubmit:e=>{i(e),a.closeDropdown()},children:[(0,I.jsx)(Lf.Target,{children:(0,I.jsx)(fl,{onClick:()=>a.toggleDropdown(),children:(0,I.jsxs)(em,{fw:`bold`,fs:`sm`,className:aQ.selectProfileBtn,children:[(0,I.jsx)(`span`,{children:`Pick profile`}),(0,I.jsx)(gj,{stroke:1.5,className:aQ.chevron})]})})}),(0,I.jsx)(Lf.Dropdown,{w:`max-content`,children:(0,I.jsx)(Lf.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)(vF,{children:(0,I.jsxs)(G,{gap:`xl`,children:[s,(0,I.jsx)(CR,{value:n,profileUrl:r})]})})}function sQ(){let e=Q(),{resourceType:t,id:n}=zG(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(),s=FG(),[c,l]=(0,b.useState)();(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>{i(BC(e)),o(BC(e))}).catch(e=>{l(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n]);let u=(0,b.useCallback)(r=>{l(void 0),e.updateResource(eQ(r)).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[e,t,n,s]),d=(0,b.useCallback)(i=>{l(void 0);let a=$O(r,eQ(i));e.patchResource(t,n,a).then(()=>{s(`/${t}/${n}/details`)?.catch(console.error),J({id:`succes`,color:`green`,message:`Success`})}).catch(e=>{l(aS(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)(vF,{children:(0,I.jsx)(cH,{defaultValue:a,onSubmit:u,onPatch:d,onDelete:f,outcome:c})}):null}function cQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?(0,I.jsx)(vF,{maw:700,children:n.resourceType===`Patient`?(0,I.jsx)(bB,{patient:n}):(0,I.jsx)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Unsupported export type`,color:`red`,children:`This page is only supported for Patient resources`})}):null}function lQ({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(FI))}).catch(console.error)},[i,n,r]),(0,I.jsx)(gb,{value:t?.url,onChange:e=>{let t=a?.find(t=>t.url===e);t&&n(t)},children:(0,I.jsx)(gb.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)(gb.Tab,{value:t.url,title:r,rightSection:n&&(0,I.jsx)(bb,{variant:`outline`,color:`green`,size:`xs`,style:{borderStyle:`none`},children:(0,I.jsx)(TM,{size:`90%`})}),children:t.title||t.name},t.url)})})})}function uQ(e,t){let n=Q(),r=FG();return{defaultValue:{resourceType:e},handleSubmit:e=>{t&&t(void 0),n.createResource(e).then(e=>r(`/`+e.resourceType+`/`+e.id)).catch(e=>{t&&t(aS(e)),J({color:`red`,message:Y(e),autoClose:!1,styles:{description:{whiteSpace:`pre-line`}}})})}}}function dQ(){let{resourceType:e}=zG(),t=NG(),[n,r]=(0,b.useState)(),{defaultValue:i,handleSubmit:a}=uQ(e,r),[o,s]=(0,b.useState)(),c=t.pathname.toLowerCase().endsWith(`profiles`),l=(0,b.useCallback)(e=>{let t=eQ(e);o&&dw(t,o.url),a(t)},[o,a]);return c?(0,I.jsx)(vF,{children:(0,I.jsxs)(G,{children:[(0,I.jsx)(lQ,{resource:i,currentProfile:o,onChange:s}),o?(0,I.jsx)(cH,{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)(vF,{children:(0,I.jsx)(cH,{defaultValue:i,onSubmit:a,outcome:n})})}function fQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=e.readHistory(t,n).read();return(0,I.jsx)(vF,{children:(0,I.jsx)(lH,{history:r})})}function pQ(){let{resourceType:e}=zG(),[t,n]=(0,b.useState)(),{defaultValue:r,handleSubmit:i}=uQ(e,n),a=(0,b.useCallback)(e=>{i(JSON.parse(e[`new-resource`]))},[i]);return(0,I.jsxs)(vF,{children:[t&&(0,I.jsx)(VF,{outcome:t}),(0,I.jsxs)(hP,{onSubmit:a,children:[(0,I.jsx)(sh,{name:`new-resource`,"data-testid":`create-resource-json`,autosize:!0,minRows:24,defaultValue:DC(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 mQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=FG(),[a,o]=(0,b.useState)(),s=(0,b.useCallback)(r=>{e.updateResource(eQ(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)(vF,{children:[a&&(0,I.jsx)(VF,{outcome:a}),(0,I.jsxs)(hP,{onSubmit:s,children:[(0,I.jsx)(sh,{name:`resource`,"data-testid":`resource-json`,autosize:!0,minRows:24,defaultValue:DC(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 hQ(e){let{resourceType:t,id:n}=e;return(0,I.jsxs)(vF,{children:[(0,I.jsxs)(Td,{icon:(0,I.jsx)(QA,{size:16}),mb:`xl`,children:[`This is just a preview! Access your form here:`,(0,I.jsx)(`br`,{}),(0,I.jsx)(Md,{href:`/forms/${n}`,children:`/forms/${n}`})]}),(0,I.jsx)(NV,{questionnaire:{reference:t+`/`+n},onSubmit:()=>alert(`You submitted the preview`)})]})}var gQ={propertyTable:`_propertyTable_1xts4_1`,propertiesTitle:`_propertiesTitle_1xts4_17`};function _Q(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 vQ(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=_Q(e))}),{code:t,description:n,value:r}});return(0,I.jsxs)(K,{className:gQ.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 yQ(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(),i=await n.get(r);s(i)}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)(vF,{children:(0,I.jsxs)(G,{gap:`xl`,children:[(0,I.jsx)(wP,{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)(cF,{children:[(0,I.jsx)(lF,{term:`Code`,children:i.code}),i.system&&(0,I.jsx)(lF,{term:`System`,children:i.system}),i.display&&(0,I.jsx)(lF,{term:`Display`,children:i.display})]}),c&&(0,I.jsxs)(V,{gap:`xs`,children:[(0,I.jsx)(ou,{size:`sm`}),(0,I.jsx)(H,{size:`sm`,c:`dimmed`,children:`Loading properties...`})]}),!c&&u&&(0,I.jsxs)(Td,{icon:(0,I.jsx)(QA,{size:16}),title:`Lookup Failed`,color:`red`,children:[`Failed to retrieve code information: `,Y(u)]}),!c&&!u&&m&&(0,I.jsx)(EM,{children:(0,I.jsxs)(G,{gap:`xs`,mt:`lg`,children:[(0,I.jsx)(H,{fw:500,size:`sm`,c:`dimmed`,className:gQ.propertiesTitle,children:`Properties`}),(0,I.jsx)(vQ,{properties:p})]})})]}):null]})})}function bQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?n.resourceType===`Questionnaire`?(0,I.jsx)(hQ,{resourceType:e,id:t}):n.resourceType===`ValueSet`?(0,I.jsx)(yQ,{valueSet:n}):null:null}function xQ(){let e=Q(),{resourceType:t,id:n}=zG(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)();return(0,b.useEffect)(()=>{e.readResource(t,n).then(e=>i(BC(e))).catch(e=>{J({color:`red`,message:Y(e)})})},[e,t,n]),r?(0,I.jsxs)(vF,{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)(lQ,{resource:r,currentProfile:a,onChange:o}),a?(0,I.jsx)(SQ,{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 SQ=({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=eQ(t);o?dw(i,e.url):fw(i,e.url),r.updateResource(i).then(e=>{n(e),J({color:`green`,message:`Success`})}).catch(e=>{a(aS(e)),J({color:`red`,message:Y(e),autoClose:!1})})},[r,e.url,n,o]);return(0,I.jsxs)(G,{children:[(0,I.jsx)(Hy,{size:`md`,checked:o,label:`Conform resource to ${e.title}`,onChange:e=>s(e.currentTarget.checked),"data-testid":`profile-toggle`}),o?(0,I.jsx)(cH,{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`})})})]})},CQ={"Create Only":`create`,"Update Only":`update`,"Delete Only":`delete`,"All Interactions":void 0},wQ=Object.keys(CQ);function TQ(){let e=Q(),{id:t}=zG(),n=Rk({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=>EQ(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},${mC(n)}`:mC(n)}`,channel:{type:`rest-hook`,endpoint:mC(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)(vF,{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)(UL,{value:{reference:e.channel?.endpoint},link:!0})}),(0,I.jsxs)(`p`,{children:[`Criteria: `,e.criteria]})]},e.id))]}),(0,I.jsx)(lm,{}),(0,I.jsxs)(G,{mt:10,children:[(0,I.jsx)(td,{size:`lg`,htmlFor:`bot`,children:`Connect to bot`}),(0,I.jsxs)(V,{children:[(0,I.jsx)(uL,{name:`bot`,resourceType:`Bot`,onChange:e=>i(e)}),(0,I.jsx)(U,{onClick:u,children:`Connect`})]}),(0,I.jsx)(V,{children:(0,I.jsx)(wg,{name:`subscription-trigger-event`,defaultValue:`Create Only`,label:`Subscription Trigger Event`,data:wQ,onChange:e=>o(CQ[e.target.value])})})]}),(0,I.jsx)(`div`,{style:{display:`none`},children:s})]})}function EQ(e,t){if(!t)return!1;let n=e.criteria||``,r=e.channel?.endpoint||``;return n.startsWith(`QuestionnaireResponse?`)&&r.startsWith(`Bot/`)&&(n.includes(mC(t))||(t.url?n.includes(t.url):!1))}function DQ(){let{id:e}=zG(),t=FG(),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)(vF,{children:(0,I.jsx)(Wz,{search:r,onClick:e=>t(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0,hideToolbar:!0})})}function OQ(){let e=Q(),{resourceType:t,id:n}=zG(),r=Rk({reference:t+`/`+n}),i=(0,b.useCallback)(t=>{e.updateResource(eQ(t)).then(()=>{J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})},[e]);return r?(0,I.jsx)(vF,{children:(0,I.jsx)(LV,{onSubmit:i,definition:r})}):null}function kQ(){let{resourceType:e,id:t}=zG(),n=Rk({reference:e+`/`+t});return n?(0,I.jsx)(vF,{children:e===`MeasureReport`?(0,I.jsx)(dB,{measureReport:n}):(0,I.jsx)(KL,{value:n})}):null}var AQ={container:`_container_1ue98_1`,entry:`_entry_1ue98_14`,active:`_active_1ue98_21`};function jQ(e){let t=Q(),n=Rk(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:mC(e);t.search(`ServiceRequest`,`subject=`+r).then(e=>{let t=(e.entry??[]).map(e=>e.resource);uR(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:AQ.container,children:r.map(e=>(0,I.jsxs)(`div`,{className:Mn(AQ.entry,{[AQ.active]:e.id===n?.id}),children:[(0,I.jsx)(`p`,{children:(0,I.jsx)(IM,{to:e,children:MQ(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:NQ(e)})]},e.id))}):null}function MQ(e){if(e.identifier){for(let t of e.identifier)if(t.value)return t.value}return e.id||``}function NQ(e){return e.authoredOn?e.authoredOn.substring(0,10):e.meta?.lastUpdated?e.meta.lastUpdated.substring(0,10):``}var PQ={container:`_container_1l2dh_1`};function FQ(e){let t=Rk(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:PQ.container,children:(0,I.jsx)(wg,{defaultValue:e.defaultValue,onChange:t=>e.onChange(t.currentTarget.value),data:n})})}function IQ(e){let t=Rk(e.specimen);return t?(0,I.jsxs)(eB,{children:[(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Type`}),(0,I.jsx)(eB.Value,{children:`Specimen`})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Collected`}),(0,I.jsx)(eB.Value,{children:bw(t.collection?.collectedDateTime)})]}),(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Specimen Age`}),(0,I.jsx)(eB.Value,{children:LQ(t)})]}),t.collection?.collectedDateTime&&t.receivedTime?(0,I.jsxs)(eB.Entry,{children:[(0,I.jsx)(eB.Key,{children:`Specimen Stability`}),(0,I.jsx)(eB.Value,{children:RQ(t)})]}):(0,I.jsx)(I.Fragment,{})]}):null}function LQ(e){let t=e.collection?.collectedDateTime;if(t)return zQ(BQ(new Date(t),new Date))}function RQ(e){if(!(!e.collection?.collectedDateTime||!e.receivedTime))return zQ(BQ(new Date(e.collection.collectedDateTime),new Date(e.receivedTime)))}function zQ(e){return e.toString().padStart(3,`0`)+`D`}function BQ(e,t){let n=t.getTime()-e.getTime();return Math.floor(n/864e5)}function VQ(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 HQ(){let e=Q(),{resourceType:t,id:n}=zG(),r={reference:t+`/`+n},[i,a]=(0,b.useState)(),o=Rk(r,a),s=VQ(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(eQ(t)).then(()=>{a(void 0),J({color:`green`,message:`Success`})}).catch(e=>{J({color:`red`,message:Y(e),autoClose:!1})})}if(i)return nS(i)?(0,I.jsxs)(vF,{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)(VF,{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&&Eq(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)(FQ,{valueSet:{reference:p},defaultValue:o.orderDetail?.[0]?.text,onChange:u},mC(o)+`-`+o.orderDetail?.[0]?.text),o&&(0,I.jsx)(jQ,{value:o}),o&&(0,I.jsxs)(_l,{children:[d&&(0,I.jsx)(CB,{patient:d}),f&&(0,I.jsx)(IQ,{specimen:f}),t!==`Patient`&&(0,I.jsx)(dZ,{resource:r}),(0,I.jsx)(cl,{children:(0,I.jsx)(nB,{baseUrl:`/${t}/${n}`,tabs:s})})]}),(0,I.jsx)(hK,{})]})}function UQ(){let e=FG(),{resourceType:t,id:n,versionId:r,tab:i}=zG(),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)(DM,{});let f=c?.entry??[],p=f.findIndex(e=>e.resource?.meta?.versionId===r);if(p===-1)return(0,I.jsxs)(vF,{children:[(0,I.jsx)(q,{children:`Version not found`}),(0,I.jsx)(IM,{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)(rm,{maw:1200,children:(0,I.jsx)(_F,{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)(gy,{cols:2,mb:`lg`,children:[(0,I.jsx)(tv,{total:f.length,value:v,getControlProps:Lz,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)(cy,{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)(cF,{compact:!0,children:[(0,I.jsx)(lF,{term:`Version ID`,children:m.meta?.versionId}),(0,I.jsx)(lF,{term:`Author`,children:(0,I.jsx)(WL,{value:m.meta?.author,link:!0},m.meta?.author?.reference)}),(0,I.jsx)(lF,{term:`Date/Time`,children:bw(m.meta?.lastUpdated)})]})}),_===`diff`&&(0,I.jsx)(aH,{original:h??{},revised:m}),_===`raw`&&(0,I.jsx)(`pre`,{style:{fontSize:`9pt`},children:JSON.stringify(m,void 0,2)})]})})})}function WQ(){let{resourceType:e,id:t}=zG(),n=FG(),[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)(vF,{children:(0,I.jsx)(Wz,{search:r,onClick:e=>n(`/${e.resource.resourceType}/${e.resource.id}`)?.catch(console.error),onChange:e=>i(e.definition),hideFilters:!0})})}function GQ(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),p=(0,b.useCallback)(async()=>{if(n?.id)try{await t.post(t.fhirUrl(n.resourceType,n.id,`$resend`),{subscription:a&&s?mC(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]);return(0,I.jsx)(tg,{opened:r,onClose:i,title:`Resend Subscriptions`,children:(0,I.jsx)(hP,{onSubmit:p,children:(0,I.jsxs)(G,{children:[(0,I.jsx)(sp,{label:`Choose subscription (all subscriptions by default)`,onChange:e=>o(e.currentTarget.checked)}),a&&(0,I.jsx)(uL,{name:`subscription`,resourceType:`Subscription`,placeholder:`Subscription`,onChange:c}),(0,I.jsx)(wg,{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)(sp,{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 KQ(){let e=Q(),t=Ok(),{resourceType:n,id:r}=zG(),i={reference:n+`/`+r},[a,o]=(0,b.useState)(),s=bn(!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(),Pb({id:r,title:`AWS Textract Successful`,message:`Text successfully extracted.`,color:`green`,icon:(0,I.jsx)(mj,{size:`1rem`}),loading:!1,withCloseButton:!0})}).catch(e=>Pb({id:r,title:`AWS Textract Error`,color:`red`,message:Y(e),icon:(0,I.jsx)(wM,{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=NZ()&&(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)(eM,{size:14}),onClick:()=>l(r,i),"aria-label":`Pin ${mC(r)}`,children:`Pin`}),s&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(tM,{size:14}),onClick:()=>u(r,i),"aria-label":`Unpin ${mC(r)}`,children:`Unpin`}),_&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>d(r),"aria-label":`Details ${mC(r)}`,children:`Details`}),c&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Vj,{size:14}),onClick:()=>h(r),"aria-label":`Details ${mC(r)}`,children:`Details`}),v&&(0,I.jsx)(W.Item,{leftSection:(0,I.jsx)(Oj,{size:14}),onClick:()=>f(r),"aria-label":`Edit ${mC(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)(oM,{size:14}),onClick:()=>m(r),"aria-label":`Resend Subscriptions ${mC(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)(yM,{size:14}),onClick:()=>g(r,i),"aria-label":`AWS Textract ${mC(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)(bM,{size:14}),onClick:()=>p(r),"aria-label":`Delete ${mC(r)}`,children:`Delete`})]})]})}return(0,I.jsxs)(I.Fragment,{children:[n===`Encounter`&&(0,I.jsx)(RR,{encounter:i,getMenu:_}),n===`Patient`&&(0,I.jsx)(wB,{patient:i,getMenu:_}),n===`ServiceRequest`&&(0,I.jsx)(yq,{serviceRequest:i,getMenu:_}),n!==`Encounter`&&n!==`Patient`&&n!==`ServiceRequest`&&(0,I.jsx)(LR,{resource:i,getMenu:_}),(0,I.jsx)(GQ,{resource:a,opened:s[0],onClose:s[1].close},`resend-subscriptions-${a?.id}`)]})}var qQ=5,JQ=`The Medplum Agent is frequently patched with new features and bugfixes. Downgrading your agent can result in picking up old bugs or losing features you may be relying on. Are you sure you want to downgrade?`;function YQ(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)(),[d,f]=(0,b.useState)(),[p,m]=(0,b.useState)(!1);if((0,b.useEffect)(()=>{t&&(s||wk(`app-tools-page`).then(c).catch(console.error),l||Tk(`app-tools-page`).then(u).catch(e=>{console.error(e),u([])}),a())},[t,s,l,a]),!r||i)return(0,I.jsx)(DM,{});if(r===`unknown`)return(0,I.jsx)(`p`,{children:`Unable to determine the current version of the agent. Check the network connectivity of the agent.`});if(!(s&&l))return(0,I.jsx)(DM,{});let h=d??s,g=l.filter(e=>Ck(e,r)>0),_=l.filter(e=>Ck(e,r)<0),v=g.slice(0,qQ),y=_.slice(0,qQ),x=v.includes(s)?[...v,...y]:[s,...v,...y],S=Ck(h,r)<0,C=Ck(h,r)===0;function w(e){return{value:e,label:e===s?`${e} (Latest)`:e,resource:e}}let T=l;async function E(e){if(!e)return x;let t=e.toLowerCase();return T.filter(e=>e.toLowerCase().includes(t))}function D(){S&&!window.confirm(JQ)||(o(p,h),n())}return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iN,{label:`Target Version`,placeholder:`Search versions...`,defaultValue:h,toOption:w,loadOptions:E,onChange:([e])=>{e&&f(e)},maxValues:1,clearable:!1}),C?(0,I.jsxs)(`p`,{children:[`This agent is already on version `,h,`.`]}):(0,I.jsxs)(`p`,{children:[`Are you sure you want to `,S?`downgrade`:`upgrade`,` this agent from version `,r,` to version`,` `,h,`?`]}),(0,I.jsxs)(V,{children:[(0,I.jsx)(U,{onClick:D,"aria-label":`Confirm upgrade`,children:`Confirm Upgrade`}),(0,I.jsx)(sp,{label:`Force`,onChange:e=>m(e.currentTarget.checked)})]})]})}var XQ=[`live`,`ping`,`hl7ConnectionsOpen`,`hl7ClientCount`,`hl7QueueDepth`,`webSocketQueueDepth`,`outstandingHeartbeats`];function ZQ(e){return e==null?``:typeof e==`object`?JSON.stringify(e):typeof e==`number`?e.toLocaleString():e.toString()}function QQ(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 $Q(e){let{stats:t}=e,n=new Set([...XQ,`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:[XQ.map(e=>(0,I.jsxs)(K.Tr,{children:[(0,I.jsx)(K.Td,{children:e}),(0,I.jsx)(K.Td,{children:ZQ(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:ZQ(t)})]},e))]})}),(0,I.jsx)(QQ,{title:`Channel Stats`,entries:t.channelStats}),(0,I.jsx)(QQ,{title:`Client Stats`,entries:t.clientStats})]})}function e$(){let e=Q(),{id:t}=zG(),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}]=bn(!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),v(e.parameter?.find(e=>e.name===`lastUpdated`)?.valueInstant);let t=e.parameter?.find(e=>e.name===`version`)?.valueString;t===void 0||t===`unknown`||xk(t)?g(t):n$(`Invalid version received from $status operation`)}).catch(e=>n$(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}`,lD.PING,!0).then(e=>x(e)).catch(e=>n$(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=>{t$(`Agent config reloaded successfully.`)}).catch(e=>n$(Y(e))).finally(()=>o(!1))},[e,t]),oe=(0,b.useCallback)((n,r)=>{c(!0);let i=e.fhirUrl(`Agent`,t,`$upgrade`);i.searchParams.set(`force`,String(n)),i.searchParams.set(`version`,r),e.get(i,{cache:`reload`}).then(e=>{t$(`Agent upgraded successfully.`)}).catch(e=>n$(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=>n$(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){n$(Y(e))}}).catch(e=>n$(Y(e))).finally(()=>f(!1))},[e,t]);return(0,I.jsxs)(vF,{children:[(0,I.jsx)(tg,{opened:N,onClose:te,title:`Upgrade Agent`,centered:!0,children:(0,I.jsx)(YQ,{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)(UL,{value:n,link:!0})]}),(0,I.jsx)(lm,{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)(BL,{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:bw(_,void 0,{timeZoneName:`longOffset`})})]})]})}),(0,I.jsx)(lm,{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)(lm,{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)(lm,{my:`lg`}),(0,I.jsxs)(hP,{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)(em,{block:!0,mb:15,children:w}):null,(0,I.jsxs)(V,{children:[(0,I.jsx)(M_,{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)(lm,{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)($Q,{stats:M}),(0,I.jsx)(lm,{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)(hP,{onSubmit:ie,children:(0,I.jsxs)(V,{children:[(0,I.jsx)(_b,{id:`host`,name:`host`,placeholder:`ex. 127.0.0.1`,label:`IP Address / Hostname`,rightSection:(0,I.jsx)(mu,{size:24,radius:`xl`,variant:`filled`,type:`submit`,"aria-label":`Ping`,loading:S,disabled:ne&&!S,children:(0,I.jsx)(cM,{style:{width:`1rem`,height:`1rem`},stroke:1.5})})}),(0,I.jsx)(M_,{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 t$(e){J({color:`green`,title:`Success`,icon:(0,I.jsx)(mj,{size:`1rem`}),message:e})}function n$(e){J({color:`red`,title:`Error`,message:e,autoClose:!1})}function r$(){let e=Q(),{id:t}=zG(),n=Rk({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)(vF,{children:(0,I.jsx)(Td,{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)(vF,{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)(_b,{label:`New Email`,type:`email`,required:!0,placeholder:`new@example.com`,value:r,onChange:e=>i(e.currentTarget.value)}),(0,I.jsx)(sp,{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)(sp,{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 i$(){let e=FG(),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)(vF,{children:[(0,I.jsx)(q,{children:`Security`}),(0,I.jsxs)(cF,{children:[(0,I.jsx)(lF,{term:`ID`,children:(0,I.jsx)(Md,{href:`/${mC(n.profile)}`,children:n.profile.id})}),(0,I.jsx)(lF,{term:`Resource Type`,children:n.profile.resourceType}),(0,I.jsx)(lF,{term:`Name`,children:_w(n.profile.name?.[0])})]})]}),(0,I.jsxs)(vF,{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:`Project`}),(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.project?.display??`Unknown`}),(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:bw(e.lastUpdated)}),(0,I.jsx)(`td`,{children:(0,I.jsx)(Md,{href:`#`,onClick:()=>i(e.id),children:`Revoke`})})]},e.id))})]})]}),(0,I.jsxs)(vF,{children:[(0,I.jsx)(q,{children:`Password`}),(0,I.jsx)(U,{onClick:()=>e(`/changepassword`)?.catch(console.error),children:`Change password`})]}),(0,I.jsxs)(vF,{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 a$(){let{id:e,secret:t}=zG(),n=FG();return(0,I.jsx)(ZF,{id:e,secret:t,onSignIn:()=>n(`/signin`)?.catch(console.error)})}function o$(){let e=kk(),t=FG(),[n]=fq(),r=jZ(),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)(rI,{onSuccess:()=>i(),onForgotPassword:()=>t(`/resetpassword`)?.catch(console.error),onRegister:MZ()?()=>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)(yF,{size:32}),n.get(`project`)!==`new`&&(0,I.jsxs)(q,{order:3,py:`lg`,ta:`center`,children:[`Sign in to `,qM()]}),n.get(`project`)===`new`&&(0,I.jsx)(q,{order:3,py:`lg`,ta:`center`,children:`Sign in again to create a new project`})]})}function s$(){let e=FG(),t=NG(),[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)(Qz,{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 c$(){let{id:e,secret:t}=zG(),n=Q(),[r,i]=(0,b.useState)(),[a,o]=(0,b.useState)(!1),s=SF(r,void 0);return(0,I.jsxs)(vF,{width:450,children:[(0,I.jsx)(VF,{issues:s}),(0,I.jsxs)(hP,{onSubmit:async()=>{i(void 0);try{let r=Qx(await n.post(`auth/verifyemail`,{id:e,secret:t}));r?YE.assign(r):o(!0)}catch(e){i(aS(e))}},children:[(0,I.jsxs)(hd,{direction:`column`,align:`center`,justify:`center`,children:[(0,I.jsx)(yF,{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)(gP,{children:`Verify email`})})]}),a&&(0,I.jsxs)(`div`,{"data-testid":`success`,children:[`Email verified. You can now\xA0`,(0,I.jsx)(IM,{to:`/signin`,children:`sign in`}),`.`]})]})]})}function l$(){return(0,I.jsx)(vK,{children:(0,I.jsxs)(gK,{errorElement:(0,I.jsx)(uZ,{}),children:[(0,I.jsx)(gK,{path:`/signin`,element:(0,I.jsx)(o$,{})}),(0,I.jsx)(gK,{path:`/oauth`,element:(0,I.jsx)(FZ,{})}),(0,I.jsx)(gK,{path:`/resetpassword`,element:(0,I.jsx)(LZ,{})}),(0,I.jsx)(gK,{path:`/setpassword/:id/:secret`,element:(0,I.jsx)(a$,{})}),(0,I.jsx)(gK,{path:`/verifyemail/:id/:secret`,element:(0,I.jsx)(c$,{})}),(0,I.jsx)(gK,{path:`/register`,element:(0,I.jsx)(IZ,{})}),(0,I.jsx)(gK,{path:`/changepassword`,element:(0,I.jsx)(sZ,{})}),(0,I.jsx)(gK,{path:`/security`,element:(0,I.jsx)(i$,{})}),(0,I.jsx)(gK,{path:`/mfa`,element:(0,I.jsx)(kZ,{})}),(0,I.jsx)(gK,{path:`/batch`,element:(0,I.jsx)(aZ,{})}),(0,I.jsx)(gK,{path:`/bulk/:resourceType`,element:(0,I.jsx)(oZ,{})}),(0,I.jsx)(gK,{path:`/smart`,element:(0,I.jsx)(s$,{})}),(0,I.jsx)(gK,{path:`/forms/:id`,element:(0,I.jsx)(fZ,{})}),(0,I.jsx)(gK,{path:`/admin/super`,element:(0,I.jsx)(iY,{})}),(0,I.jsx)(gK,{path:`/admin/super/asyncjob/:tab`,element:(0,I.jsx)(WJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/asyncjob`,element:(0,I.jsx)(WJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/db/:tab`,element:(0,I.jsx)(dJ,{})}),(0,I.jsx)(gK,{path:`/admin/super/db`,element:(0,I.jsx)(dJ,{})}),(0,I.jsx)(gK,{path:`/admin/config`,element:(0,I.jsx)(SJ,{})}),(0,I.jsxs)(gK,{path:`/admin`,element:(0,I.jsx)(TJ,{}),children:[(0,I.jsx)(gK,{path:`bots/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`bots/new`,element:(0,I.jsx)(Rq,{})}),(0,I.jsx)(gK,{path:`bots`,element:(0,I.jsx)(Fq,{})}),(0,I.jsx)(gK,{path:`clients/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`clients/new`,element:(0,I.jsx)(zq,{})}),(0,I.jsx)(gK,{path:`clients`,element:(0,I.jsx)(Iq,{})}),(0,I.jsx)(gK,{path:`details`,element:(0,I.jsx)(CJ,{})}),(0,I.jsx)(gK,{path:`invite`,element:(0,I.jsx)(fJ,{})}),(0,I.jsx)(gK,{path:`patients`,element:(0,I.jsx)(mK,{to:`/admin/users`,replace:!0})}),(0,I.jsx)(gK,{path:`users/:membershipId`,element:(0,I.jsx)(vJ,{})}),(0,I.jsx)(gK,{path:`users`,element:(0,I.jsx)(lY,{})}),(0,I.jsx)(gK,{path:`project`,element:(0,I.jsx)(CJ,{})}),(0,I.jsx)(gK,{path:`secrets`,element:(0,I.jsx)(BJ,{})}),(0,I.jsx)(gK,{path:`settings`,element:(0,I.jsx)(VJ,{})}),(0,I.jsx)(gK,{path:`sites`,element:(0,I.jsx)(HJ,{})}),(0,I.jsx)(gK,{path:`rate-limits`,element:(0,I.jsx)(IJ,{})})]}),(0,I.jsx)(gK,{path:`/lab/assays`,element:(0,I.jsx)(wZ,{})}),(0,I.jsx)(gK,{path:`/lab/panels`,element:(0,I.jsx)(DZ,{})}),(0,I.jsxs)(gK,{path:`/:resourceType/new`,element:(0,I.jsx)(lZ,{}),children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(dQ,{})}),(0,I.jsx)(gK,{path:`form`,element:(0,I.jsx)(dQ,{})}),(0,I.jsx)(gK,{path:`json`,element:(0,I.jsx)(pQ,{})}),(0,I.jsx)(gK,{path:`profiles`,element:(0,I.jsx)(dQ,{})})]}),(0,I.jsxs)(gK,{path:`/:resourceType/:id`,element:(0,I.jsx)(HQ,{}),children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(KQ,{})}),(0,I.jsx)(gK,{path:`apply`,element:(0,I.jsx)(BZ,{})}),(0,I.jsx)(gK,{path:`apps`,element:(0,I.jsx)(VZ,{})}),(0,I.jsx)(gK,{path:`event`,element:(0,I.jsx)(UZ,{})}),(0,I.jsx)(gK,{path:`blame`,element:(0,I.jsx)(WZ,{})}),(0,I.jsx)(gK,{path:`bots`,element:(0,I.jsx)(TQ,{})}),(0,I.jsx)(gK,{path:`builder`,element:(0,I.jsx)(tQ,{})}),(0,I.jsx)(gK,{path:`checklist`,element:(0,I.jsx)(nQ,{})}),(0,I.jsx)(gK,{path:`delete`,element:(0,I.jsx)(iQ,{})}),(0,I.jsx)(gK,{path:`details`,element:(0,I.jsx)(oQ,{})}),(0,I.jsx)(gK,{path:`edit`,element:(0,I.jsx)(sQ,{})}),(0,I.jsx)(gK,{path:`editor`,element:(0,I.jsx)(XZ,{})}),(0,I.jsxs)(gK,{path:`history`,children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(fQ,{})}),(0,I.jsx)(gK,{path:`:versionId/:tab`,element:(0,I.jsx)(UQ,{})}),(0,I.jsx)(gK,{path:`:versionId`,element:(0,I.jsx)(UQ,{})})]}),(0,I.jsxs)(gK,{path:`_history`,children:[(0,I.jsx)(gK,{index:!0,element:(0,I.jsx)(fQ,{})}),(0,I.jsx)(gK,{path:`:versionId/:tab`,element:(0,I.jsx)(UQ,{})}),(0,I.jsx)(gK,{path:`:versionId`,element:(0,I.jsx)(UQ,{})})]}),(0,I.jsx)(gK,{path:`json`,element:(0,I.jsx)(mQ,{})}),(0,I.jsx)(gK,{path:`preview`,element:(0,I.jsx)(bQ,{})}),(0,I.jsx)(gK,{path:`responses`,element:(0,I.jsx)(DQ,{})}),(0,I.jsx)(gK,{path:`report`,element:(0,I.jsx)(kQ,{})}),(0,I.jsx)(gK,{path:`ranges`,element:(0,I.jsx)(OQ,{})}),(0,I.jsx)(gK,{path:`subscriptions`,element:(0,I.jsx)(WQ,{})}),(0,I.jsx)(gK,{path:`timeline`,element:(0,I.jsx)(KQ,{})}),(0,I.jsx)(gK,{path:`tools`,element:(0,I.jsx)(e$,{})}),(0,I.jsx)(gK,{path:`email`,element:(0,I.jsx)(r$,{})}),(0,I.jsx)(gK,{path:`payload`,element:(0,I.jsx)(rQ,{})}),(0,I.jsx)(gK,{path:`profiles`,element:(0,I.jsx)(xQ,{})}),(0,I.jsx)(gK,{path:`accounts`,element:(0,I.jsx)(RZ,{})}),(0,I.jsx)(gK,{path:`export`,element:(0,I.jsx)(cQ,{})})]}),(0,I.jsx)(gK,{path:`/:resourceType`,element:(0,I.jsx)(CZ,{})}),(0,I.jsx)(gK,{path:`/`,element:(0,I.jsx)(CZ,{})})]})})}function u$(){let e=Q(),t=e.getUserConfiguration(),n=e.getProject(),r=NG(),[i]=fq();return e.isLoading()?(0,I.jsx)(DM,{}):(0,I.jsxs)(eF,{logo:(0,I.jsx)(yF,{size:24}),pathname:r.pathname,searchParams:i,version:QD,menus:d$(t),displayAddBookmark:!!t?.id,announcements:n?.superAdmin?[{message:(0,I.jsxs)(I.Fragment,{children:[`Warning: logged in as`,` `,(0,I.jsx)(oq,{to:`https://www.medplum.com/docs/self-hosting/super-admin-guide`,target:`_blank`,rel:`noopener noreferrer`,children:`Medplum Super Admin`}),`.`]}),color:`red`,icon:(0,I.jsx)($A,{size:16}),role:`alert`}]:void 0,children:[(0,I.jsx)(vq,{}),(0,I.jsx)(b.Suspense,{fallback:(0,I.jsx)(DM,{}),children:(0,I.jsx)(l$,{})})]})}function d$(e){let t=e?.menu?.map(e=>({title:e.title,links:e.link?.map(e=>({label:e.name,href:e.target,icon:p$(e.target)}))||[]}))||[];return t.push({title:`Settings`,links:[{label:`Security`,href:`/security`,icon:(0,I.jsx)(Uj,{})}]}),t}var f$={Patient:mM,Practitioner:Rj,Organization:fj,ServiceRequest:iM,DiagnosticReport:sM,Questionnaire:Lj,Project:Ij,admin:cj,AccessPolicy:Hj,Subscription:CM,batch:Zj,Observation:Jj};function p$(e){if(e.includes(`admin/super/db`))return(0,I.jsx)(wj,{});try{let t=new URL(e,`https://app.medplum.com`).pathname.split(`/`)[1];if(t in f$){let e=f$[t];return(0,I.jsx)(e,{})}}catch{}}async function m$(){let e=jZ(),t=new dO({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=ci({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=rq([{path:`*`,element:(0,I.jsx)(u$,{})}]);(0,wq.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(b.StrictMode,{children:(0,I.jsx)(jk,{medplum:t,navigate:e=>r.navigate(e),children:(0,I.jsxs)(Vr,{theme:n,children:[(0,I.jsx)(yx,{position:`bottom-right`}),(0,I.jsx)(uK,{router:r})]})})}))}m$().catch(console.error);export{o as t};
|
|
244
|
+
//# sourceMappingURL=index-DFJPfvpQ.js.map
|