@medplum/react 2.1.19 → 2.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +5 -5
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/cjs/index.d.ts +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.mjs +4 -4
- package/dist/esm/index.mjs.map +3 -3
- package/package.json +14 -9
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as wn,useMemo as Ki,useState as _i}from"react";import{createContext as Zi,useContext as Yi}from"react";import{jsx as ji}from"react/jsx-runtime";import{deepEquals as ou,isReference as Nn,isResource as tu,normalizeOperationOutcome as ru}from"@medplum/core";import{useCallback as au,useEffect as On,useState as nu}from"react";import{allOk as lu,normalizeOperationOutcome as fu}from"@medplum/core";import{useEffect as su,useState as Mt}from"react";var Ln=Zi(void 0);function Yo(){return Yi(Ln)}function v(){return Yo().medplum}function Ue(){return Yo().navigate}function Ft(){return Yo().profile}function kv(e){let o=e.medplum,t=e.navigate??eu,[r,a]=_i({profile:o.getProfile(),loading:!o.isInitialized});wn(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),wn(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=Ki(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return ji(Ln.Provider,{value:n,children:e.children})}function eu(e){window.location.assign(e)}function G(e,o){let t=v(),[r,a]=nu(En(t,e)),n=au(l=>{ou(l,r)||a(l)},[r,a]);return On(()=>{n(En(t,e))},[t,e,n]),On(()=>{let l=!0;return Nn(e)&&t.readReference(e).then(s=>{l&&n(s)}).catch(s=>{l&&(n(void 0),o&&o(ru(s)))}),()=>l=!1},[t,r,e,n,o]),r}function En(e,o){if(o){if(tu(o))return o;if(Nn(o))return e.getCachedReference(o)}}function wv(e,o){return Ur("search",e,o)}function Hn(e,o){return Ur("searchOne",e,o)}function Vn(e,o){return Ur("searchResources",e,o)}function Ur(e,o,t){let r=v(),[a,n]=Mt(),[l,s]=Mt(!1),[f,i]=Mt(),[u,d]=Mt();return su(()=>{let c=r.fhirSearchUrl(o,t).toString();c!==a&&(n(c),r[e](o,t).then(x=>{s(!1),i(x),d(lu)}).catch(x=>{s(!1),i(void 0),d(fu(x))}))},[r,e,o,t,a,i]),[f,l,u]}import{formatAddress as iu}from"@medplum/core";import{Fragment as uu,jsx as cu}from"react/jsx-runtime";function qn(e){let o=e.value;return o?cu(uu,{children:iu(o)}):null}import{Group as du,NativeSelect as Gn,TextInput as jo}from"@mantine/core";import{useRef as mu,useState as pu}from"react";import{jsx as eo,jsxs as xu}from"react/jsx-runtime";function Un(e,o){return e.line&&e.line.length>o?e.line[o]:""}function Qn(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function zn(e){let[o,t]=pu(e.defaultValue||{}),r=mu();r.current=o;function a(c){t(c),e.onChange&&e.onChange(c)}function n(c){a({...r.current,use:c})}function l(c){a({...r.current,type:c})}function s(c){a(Qn(r.current||{},0,c))}function f(c){a(Qn(r.current||{},1,c))}function i(c){a({...r.current,city:c})}function u(c){a({...r.current,state:c})}function d(c){a({...r.current,postalCode:c})}return xu(du,{spacing:"xs",grow:!0,noWrap:!0,children:[eo(Gn,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),eo(Gn,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>l(c.currentTarget.value),data:["","postal","physical","both"]}),eo(jo,{placeholder:"Line 1",defaultValue:Un(o,0),onChange:c=>s(c.currentTarget.value)}),eo(jo,{placeholder:"Line 2",defaultValue:Un(o,1),onChange:c=>f(c.currentTarget.value)}),eo(jo,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),eo(jo,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),eo(jo,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:c=>d(c.currentTarget.value)})]})}import{TextInput as Iu}from"@mantine/core";import{createReference as gu}from"@medplum/core";import{useRef as hu,useState as Cu}from"react";import{jsx as yu}from"react/jsx-runtime";function Wn(e){let o=Ft(),[t,r]=Cu(e.defaultValue||{}),a=hu();a.current=t;function n(l){let s=l?{text:l,authorReference:o&&gu(o),time:new Date().toISOString()}:{};r(s),e.onChange&&e.onChange(s)}return yu(Iu,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as od,useMantineTheme as td}from"@mantine/core";import{showNotification as rd}from"@mantine/notifications";import{Suspense as ad,useEffect as nd,useState as ld}from"react";import{Alert as Tu}from"@mantine/core";import{normalizeErrorString as ku}from"@medplum/core";import{forwardRef as vu,createElement as Jn}from"react";import oo from"prop-types";var Xn={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"};var Su=Object.defineProperty,Ru=Object.defineProperties,bu=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Zn=Object.prototype.propertyIsEnumerable,$n=(e,o,t)=>o in e?Su(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Kn=(e,o)=>{for(var t in o||(o={}))_n.call(o,t)&&$n(e,t,o[t]);if(wt)for(var t of wt(o))Zn.call(o,t)&&$n(e,t,o[t]);return e},Pu=(e,o)=>Ru(e,bu(o)),Du=(e,o)=>{var t={};for(var r in e)_n.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&wt)for(var r of wt(e))o.indexOf(r)<0&&Zn.call(e,r)&&(t[r]=e[r]);return t},m=(e,o,t)=>{let r=vu((a,n)=>{var l=a,{color:s="currentColor",size:f=24,stroke:i=2,children:u}=l,d=Du(l,["color","size","stroke","children"]);return Jn("svg",Kn(Pu(Kn({ref:n},Xn),{width:f,height:f,stroke:s,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),d),[...t.map(([c,x])=>Jn(c,x)),...u||[]])});return r.propTypes={color:oo.string,size:oo.oneOfType([oo.string,oo.number]),stroke:oo.oneOfType([oo.string,oo.number])},r.displayName=`${o}`,r};var Qr=m("adjustments-horizontal","IconAdjustmentsHorizontal",[["path",{d:"M14 6m-2 0a2 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:"M8 12m-2 0a2 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:"M17 18m-2 0a2 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"}]]);var to=m("alert-circle","IconAlertCircle",[["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"}]]);var zr=m("arrow-down","IconArrowDown",[["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"}]]);var Wr=m("arrow-up","IconArrowUp",[["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"}]]);var Xr=m("bleach-off","IconBleachOff",[["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"}]]);var Jr=m("bleach","IconBleach",[["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"}]]);var $r=m("box-multiple","IconBoxMultiple",[["path",{d:"M7 3m0 2a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z",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"}]]);var Kr=m("brackets-contain","IconBracketsContain",[["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"}]]);var _r=m("bucket-off","IconBucketOff",[["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"}]]);var Zr=m("bucket","IconBucket",[["path",{d:"M12 7m-8 0a8 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"}]]);var Oe=m("calendar","IconCalendar",[["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-12z",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"}]]);var et=m("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Yr=m("checkbox","IconCheckbox",[["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"}]]);var jr=m("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Qe=m("circle-minus","IconCircleMinus",[["path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l6 0",key:"svg-1"}]]);var go=m("circle-plus","IconCirclePlus",[["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"}]]);var ot=m("cloud-upload","IconCloudUpload",[["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"}]]);var ea=m("columns","IconColumns",[["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"}]]);var oa=m("copy","IconCopy",[["path",{d:"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z",key:"svg-0"}],["path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2",key:"svg-1"}]]);var ta=m("currency-dollar","IconCurrencyDollar",[["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"}]]);var ra=m("dots","IconDots",[["path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}]]);var aa=m("edit","IconEdit",[["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.415z",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]]);var ho=m("equal-not","IconEqualNot",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}],["path",{d:"M5 19l14 -14",key:"svg-2"}]]);var Co=m("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Ot=m("file-alert","IconFileAlert",[["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 2z",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]]);var na=m("file-plus","IconFilePlus",[["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 2z",key:"svg-1"}],["path",{d:"M12 11l0 6",key:"svg-2"}],["path",{d:"M9 14l6 0",key:"svg-3"}]]);var la=m("filter","IconFilter",[["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.227z",key:"svg-0"}]]);var fa=m("list-details","IconListDetails",[["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 4m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-4"}],["path",{d:"M3 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-5"}]]);var sa=m("logout","IconLogout",[["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"}]]);var Et=m("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Lt=m("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var ia=m("message","IconMessage",[["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 -3h12z",key:"svg-2"}]]);var ua=m("pin","IconPin",[["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"}]]);var ca=m("pinned-off","IconPinnedOff",[["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"}]]);var da=m("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var ma=m("refresh","IconRefresh",[["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"}]]);var pa=m("search","IconSearch",[["path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]]);var yo=m("settings","IconSettings",[["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.065z",key:"svg-0"}],["path",{d:"M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-1"}]]);var tt=m("sort-ascending","IconSortAscending",[["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"}]]);var rt=m("sort-descending","IconSortDescending",[["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"}]]);var xa=m("square","IconSquare",[["path",{d:"M3 3m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",key:"svg-0"}]]);var Ia=m("switch-horizontal","IconSwitchHorizontal",[["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"}]]);var ga=m("table-export","IconTableExport",[["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"}]]);var at=m("trash","IconTrash",[["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"}]]);var ha=m("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Bu}from"react";import{jsx as Yn}from"react/jsx-runtime";var vo=class extends Bu{constructor(t){super(t);this.state={}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){console.error("Uncaught error:",t,r)}render(){return this.state.error?Yn(Tu,{icon:Yn(to,{size:16}),title:"Something went wrong",color:"red",children:ku(this.state.error)}):this.props.children}};import{Center as Au,Loader as Mu}from"@mantine/core";import{jsx as jn}from"react/jsx-runtime";function Ca(){return jn(Au,{style:{width:"100%",height:"100vh"},children:jn(Mu,{})})}import{Avatar as cc,createStyles as dc,Group as Vt,Header as mc,Menu as Ee,Stack as pc,Text as nt,UnstyledButton as ul}from"@mantine/core";import{formatHumanName as xc,getReferenceString as cl}from"@medplum/core";import{useState as Ic}from"react";import{formatHumanName as Fu}from"@medplum/core";import{Fragment as wu,jsx as Ou}from"react/jsx-runtime";function Nt(e){let o=e.value;return o?Ou(wu,{children:Fu(o,e.options)}):null}import{Avatar as ol}from"@mantine/core";import{getDisplayString as Qu,getImageSrc as zu}from"@medplum/core";import{Anchor as Eu}from"@mantine/core";import{isReference as Lu,isResource as Nu}from"@medplum/core";function O(e){e.preventDefault(),e.stopPropagation()}function Ht(e){if(el(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&el(o[0]))return!0}return!1}function el(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as Uu}from"react/jsx-runtime";function j(e){let o=Ue(),{to:t,suffix:r,label:a,onClick:n,children:l,...s}=e,f=Hu(t);return r&&(f+="/"+r),Uu(Eu,{href:f,"aria-label":a,onClick:i=>{O(i),n?n(i):t&&o(f)},...s,children:l})}function Hu(e){if(e){if(typeof e=="string")return Vu(e);if(Nu(e))return qu(e);if(Lu(e))return Gu(e)}return"#"}function Vu(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function qu(e){return`/${e.resourceType}/${e.id}`}function Gu(e){return`/${e.reference}`}import{jsx as ya}from"react/jsx-runtime";function le(e){let o=G(e.value),t=o?Qu(o):e.alt??"",r=(o&&zu(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?ya(j,{to:o,children:ya(ol,{src:r,alt:t,radius:a,...n})}):ya(ol,{src:r,alt:t,radius:a,...n})}import{createStyles as Zu,Group as Yu,Text as rl}from"@mantine/core";import{formatHumanName as ju,getDisplayString as sl,getReferenceString as ec,isUUID as oc}from"@medplum/core";import{forwardRef as tc,useCallback as al}from"react";import{Loader as Wu,MultiSelect as Xu}from"@mantine/core";import{showNotification as Ju}from"@mantine/notifications";import{normalizeErrorString as $u}from"@medplum/core";import{useCallback as So,useEffect as Ku,useRef as Ro,useState as bo}from"react";import{jsx as tl}from"react/jsx-runtime";function Po(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:s,...f}=e,i=_u(o),u=Ro(null),[d,c]=bo(),[x,C]=bo(),[I,R]=bo(),[D,b]=bo(),[T,Q]=bo(i.map(r)),[y,w]=bo([]),$=Ro();$.current=d;let Z=Ro();Z.current=x;let Fe=Ro();Fe.current=I;let je=Ro();je.current=D;let te=Ro();te.current=y;let g=So(()=>{C(void 0);let Y=u.current?.value.trim()||"";if(Y===$.current)return;c(Y);let _=new AbortController;R(_),a(Y,_.signal).then(he=>{_.signal.aborted||(w(he.map(r)),R(void 0),je.current&&(he.length>0&&n(he.slice(0,1)),b(!1)))}).catch(he=>{_.signal.aborted||he.message.includes("aborted")||Ju({color:"red",message:$u(he)})})},[a,n,r]),L=So(()=>{Fe.current&&(Fe.current.abort(),R(void 0)),Z.current!==void 0&&window.clearTimeout(Z.current);let Y=window.setTimeout(()=>g(),100);C(Y)},[g]),ke=So(Y=>{let _=[],he=[];for(let Fn of Y){let At=te.current?.find($i=>$i.value===Fn),Zo=At?.resource;!Zo&&s!==!1&&l&&(Zo=l(Fn),At=r(Zo)),Zo&&_.push(Zo),At&&he.push(At)}n(_),Q(he)},[s,n,l,r]),h=So(Y=>{Y.key==="Enter"&&(!Z.current&&!Fe.current?(O(Y),te.current&&te.current.length>0&&(w(te.current.slice(0,1)),ke([te.current[0].value]))):b(!0))},[ke]),H=So(Y=>{let _=r(l(Y));return w([...te.current,_]),_},[l,w,r]),we=So((Y,_)=>!_,[]);return Ku(()=>()=>{Fe.current&&Fe.current.abort()},[]),tl(Xu,{...f,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:h,onSearchChange:L,data:[...T,...y],onFocus:g,onChange:ke,onCreate:H,rightSectionWidth:40,rightSection:I?tl(Wu,{size:16}):null,filter:we,creatable:!0,withinPortal:!0})}function _u(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Do,jsxs as fl}from"react/jsx-runtime";var rc=Zu(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function ac(e){return e.id}function nc(e){return{value:e.id,label:sl(e),resource:e}}function il(e){let{classes:o}=rc(),t=Ue(),r=v(),a=al(async(l,s)=>{let f=fc(l),i={signal:s},u=await r.graphql(f,void 0,void 0,i);return sc(u,l)},[r]),n=al(l=>{l.length>0&&t(`/${ec(l[0])}`)},[t]);return Do(Po,{size:"sm",radius:"md",className:o.searchInput,icon:Do(pa,{size:16}),placeholder:"Search",itemComponent:lc,toKey:ac,toOption:nc,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var lc=tc(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Do("div",{ref:t,...o,children:fl(Yu,{noWrap:!0,children:[Do(le,{value:e}),fl("div",{children:[Do(rl,{children:sl(e)}),Do(rl,{size:"xs",color:"dimmed",children:r})]})]})})});function fc(e){let o=JSON.stringify(e);return oc(e)?`{
|
|
1
|
+
import{useEffect as wn,useMemo as Ki,useState as _i}from"react";import{createContext as Zi,useContext as Yi}from"react";import{jsx as ji}from"react/jsx-runtime";import{deepEquals as ou,isReference as Nn,isResource as tu,normalizeOperationOutcome as ru}from"@medplum/core";import{useCallback as au,useEffect as On,useState as nu}from"react";import{allOk as lu,normalizeOperationOutcome as fu}from"@medplum/core";import{useEffect as su,useState as Mt}from"react";var Ln=Zi(void 0);function Yo(){return Yi(Ln)}function v(){return Yo().medplum}function Ue(){return Yo().navigate}function Ft(){return Yo().profile}function Av(e){let o=e.medplum,t=e.navigate??eu,[r,a]=_i({profile:o.getProfile(),loading:!o.isInitialized});wn(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),wn(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=Ki(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return ji(Ln.Provider,{value:n,children:e.children})}function eu(e){window.location.assign(e)}function G(e,o){let t=v(),[r,a]=nu(En(t,e)),n=au(l=>{ou(l,r)||a(l)},[r,a]);return On(()=>{n(En(t,e))},[t,e,n]),On(()=>{let l=!0;return Nn(e)&&t.readReference(e).then(s=>{l&&n(s)}).catch(s=>{l&&(n(void 0),o&&o(ru(s)))}),()=>l=!1},[t,r,e,n,o]),r}function En(e,o){if(o){if(tu(o))return o;if(Nn(o))return e.getCachedReference(o)}}function Ev(e,o){return Ur("search",e,o)}function Hn(e,o){return Ur("searchOne",e,o)}function Vn(e,o){return Ur("searchResources",e,o)}function Ur(e,o,t){let r=v(),[a,n]=Mt(),[l,s]=Mt(!1),[f,i]=Mt(),[u,d]=Mt();return su(()=>{let c=r.fhirSearchUrl(o,t).toString();c!==a&&(n(c),r[e](o,t).then(x=>{s(!1),i(x),d(lu)}).catch(x=>{s(!1),i(void 0),d(fu(x))}))},[r,e,o,t,a,i]),[f,l,u]}import{formatAddress as iu}from"@medplum/core";import{Fragment as uu,jsx as cu}from"react/jsx-runtime";function qn(e){let o=e.value;return o?cu(uu,{children:iu(o)}):null}import{Group as du,NativeSelect as Gn,TextInput as jo}from"@mantine/core";import{useRef as mu,useState as pu}from"react";import{jsx as eo,jsxs as xu}from"react/jsx-runtime";function Un(e,o){return e.line&&e.line.length>o?e.line[o]:""}function Qn(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function zn(e){let[o,t]=pu(e.defaultValue||{}),r=mu();r.current=o;function a(c){t(c),e.onChange&&e.onChange(c)}function n(c){a({...r.current,use:c})}function l(c){a({...r.current,type:c})}function s(c){a(Qn(r.current||{},0,c))}function f(c){a(Qn(r.current||{},1,c))}function i(c){a({...r.current,city:c})}function u(c){a({...r.current,state:c})}function d(c){a({...r.current,postalCode:c})}return xu(du,{spacing:"xs",grow:!0,noWrap:!0,children:[eo(Gn,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),eo(Gn,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>l(c.currentTarget.value),data:["","postal","physical","both"]}),eo(jo,{placeholder:"Line 1",defaultValue:Un(o,0),onChange:c=>s(c.currentTarget.value)}),eo(jo,{placeholder:"Line 2",defaultValue:Un(o,1),onChange:c=>f(c.currentTarget.value)}),eo(jo,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),eo(jo,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),eo(jo,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:c=>d(c.currentTarget.value)})]})}import{TextInput as Iu}from"@mantine/core";import{createReference as gu}from"@medplum/core";import{useRef as hu,useState as Cu}from"react";import{jsx as yu}from"react/jsx-runtime";function Wn(e){let o=Ft(),[t,r]=Cu(e.defaultValue||{}),a=hu();a.current=t;function n(l){let s=l?{text:l,authorReference:o&&gu(o),time:new Date().toISOString()}:{};r(s),e.onChange&&e.onChange(s)}return yu(Iu,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as od,useMantineTheme as td}from"@mantine/core";import{showNotification as rd}from"@mantine/notifications";import{Suspense as ad,useEffect as nd,useState as ld}from"react";import{Alert as ku}from"@mantine/core";import{normalizeErrorString as Tu}from"@medplum/core";import{forwardRef as vu,createElement as Jn}from"react";import oo from"prop-types";var Xn={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"};var Su=Object.defineProperty,Ru=Object.defineProperties,bu=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Zn=Object.prototype.propertyIsEnumerable,$n=(e,o,t)=>o in e?Su(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Kn=(e,o)=>{for(var t in o||(o={}))_n.call(o,t)&&$n(e,t,o[t]);if(wt)for(var t of wt(o))Zn.call(o,t)&&$n(e,t,o[t]);return e},Pu=(e,o)=>Ru(e,bu(o)),Du=(e,o)=>{var t={};for(var r in e)_n.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&wt)for(var r of wt(e))o.indexOf(r)<0&&Zn.call(e,r)&&(t[r]=e[r]);return t},m=(e,o,t)=>{let r=vu((a,n)=>{var l=a,{color:s="currentColor",size:f=24,stroke:i=2,children:u}=l,d=Du(l,["color","size","stroke","children"]);return Jn("svg",Kn(Pu(Kn({ref:n},Xn),{width:f,height:f,stroke:s,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),d),[...t.map(([c,x])=>Jn(c,x)),...u||[]])});return r.propTypes={color:oo.string,size:oo.oneOfType([oo.string,oo.number]),stroke:oo.oneOfType([oo.string,oo.number])},r.displayName=`${o}`,r};var Qr=m("adjustments-horizontal","IconAdjustmentsHorizontal",[["path",{d:"M14 6m-2 0a2 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:"M8 12m-2 0a2 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:"M17 18m-2 0a2 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"}]]);var to=m("alert-circle","IconAlertCircle",[["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"}]]);var zr=m("arrow-down","IconArrowDown",[["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"}]]);var Wr=m("arrow-up","IconArrowUp",[["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"}]]);var Xr=m("bleach-off","IconBleachOff",[["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"}]]);var Jr=m("bleach","IconBleach",[["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"}]]);var $r=m("box-multiple","IconBoxMultiple",[["path",{d:"M7 3m0 2a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z",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"}]]);var Kr=m("brackets-contain","IconBracketsContain",[["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"}]]);var _r=m("bucket-off","IconBucketOff",[["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"}]]);var Zr=m("bucket","IconBucket",[["path",{d:"M12 7m-8 0a8 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"}]]);var we=m("calendar","IconCalendar",[["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-12z",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"}]]);var et=m("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Yr=m("checkbox","IconCheckbox",[["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"}]]);var jr=m("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Qe=m("circle-minus","IconCircleMinus",[["path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l6 0",key:"svg-1"}]]);var go=m("circle-plus","IconCirclePlus",[["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"}]]);var ot=m("cloud-upload","IconCloudUpload",[["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"}]]);var ea=m("columns","IconColumns",[["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"}]]);var oa=m("copy","IconCopy",[["path",{d:"M7 7m0 2.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.667z",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"}]]);var ta=m("currency-dollar","IconCurrencyDollar",[["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"}]]);var ra=m("dots","IconDots",[["path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}]]);var aa=m("edit","IconEdit",[["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.415z",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]]);var ho=m("equal-not","IconEqualNot",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}],["path",{d:"M5 19l14 -14",key:"svg-2"}]]);var Co=m("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Ot=m("file-alert","IconFileAlert",[["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 2z",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]]);var na=m("file-plus","IconFilePlus",[["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 2z",key:"svg-1"}],["path",{d:"M12 11l0 6",key:"svg-2"}],["path",{d:"M9 14l6 0",key:"svg-3"}]]);var la=m("filter","IconFilter",[["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.227z",key:"svg-0"}]]);var fa=m("list-details","IconListDetails",[["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 4m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-4"}],["path",{d:"M3 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-5"}]]);var sa=m("logout","IconLogout",[["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"}]]);var Et=m("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Lt=m("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var ia=m("message","IconMessage",[["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 -3h12z",key:"svg-2"}]]);var ua=m("pin","IconPin",[["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"}]]);var ca=m("pinned-off","IconPinnedOff",[["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"}]]);var da=m("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var ma=m("refresh","IconRefresh",[["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"}]]);var pa=m("search","IconSearch",[["path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]]);var yo=m("settings","IconSettings",[["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.065z",key:"svg-0"}],["path",{d:"M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-1"}]]);var tt=m("sort-ascending","IconSortAscending",[["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"}]]);var rt=m("sort-descending","IconSortDescending",[["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"}]]);var xa=m("square","IconSquare",[["path",{d:"M3 3m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",key:"svg-0"}]]);var Ia=m("switch-horizontal","IconSwitchHorizontal",[["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"}]]);var ga=m("table-export","IconTableExport",[["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"}]]);var at=m("trash","IconTrash",[["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"}]]);var ha=m("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Bu}from"react";import{jsx as Yn}from"react/jsx-runtime";var vo=class extends Bu{constructor(t){super(t);this.state={}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){console.error("Uncaught error:",t,r)}render(){return this.state.error?Yn(ku,{icon:Yn(to,{size:16}),title:"Something went wrong",color:"red",children:Tu(this.state.error)}):this.props.children}};import{Center as Au,Loader as Mu}from"@mantine/core";import{jsx as jn}from"react/jsx-runtime";function Ca(){return jn(Au,{style:{width:"100%",height:"100vh"},children:jn(Mu,{})})}import{Avatar as cc,createStyles as dc,Group as Vt,Header as mc,Menu as Oe,Stack as pc,Text as nt,UnstyledButton as ul}from"@mantine/core";import{formatHumanName as xc,getReferenceString as cl}from"@medplum/core";import{useState as Ic}from"react";import{formatHumanName as Fu}from"@medplum/core";import{Fragment as wu,jsx as Ou}from"react/jsx-runtime";function Nt(e){let o=e.value;return o?Ou(wu,{children:Fu(o,e.options)}):null}import{Avatar as ol}from"@mantine/core";import{getDisplayString as Qu,getImageSrc as zu}from"@medplum/core";import{Anchor as Eu}from"@mantine/core";import{isReference as Lu,isResource as Nu}from"@medplum/core";function O(e){e.preventDefault(),e.stopPropagation()}function Ht(e){if(el(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&el(o[0]))return!0}return!1}function el(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as Uu}from"react/jsx-runtime";function j(e){let o=Ue(),{to:t,suffix:r,label:a,onClick:n,children:l,...s}=e,f=Hu(t);return r&&(f+="/"+r),Uu(Eu,{href:f,"aria-label":a,onClick:i=>{O(i),n?n(i):t&&o(f)},...s,children:l})}function Hu(e){if(e){if(typeof e=="string")return Vu(e);if(Nu(e))return qu(e);if(Lu(e))return Gu(e)}return"#"}function Vu(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function qu(e){return`/${e.resourceType}/${e.id}`}function Gu(e){return`/${e.reference}`}import{jsx as ya}from"react/jsx-runtime";function le(e){let o=G(e.value),t=o?Qu(o):e.alt??"",r=(o&&zu(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?ya(j,{to:o,children:ya(ol,{src:r,alt:t,radius:a,...n})}):ya(ol,{src:r,alt:t,radius:a,...n})}import{createStyles as Zu,Group as Yu,Text as rl}from"@mantine/core";import{formatHumanName as ju,getDisplayString as sl,getReferenceString as ec,isUUID as oc}from"@medplum/core";import{forwardRef as tc,useCallback as al}from"react";import{Loader as Wu,MultiSelect as Xu}from"@mantine/core";import{showNotification as Ju}from"@mantine/notifications";import{normalizeErrorString as $u}from"@medplum/core";import{useCallback as So,useEffect as Ku,useRef as Ro,useState as bo}from"react";import{jsx as tl}from"react/jsx-runtime";function Po(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:s,...f}=e,i=_u(o),u=Ro(null),[d,c]=bo(),[x,h]=bo(),[I,R]=bo(),[D,b]=bo(),[k,Q]=bo(i.map(r)),[y,F]=bo([]),$=Ro();$.current=d;let Z=Ro();Z.current=x;let Me=Ro();Me.current=I;let je=Ro();je.current=D;let te=Ro();te.current=y;let g=So(()=>{h(void 0);let Y=u.current?.value.trim()||"";if(Y===$.current)return;c(Y);let _=new AbortController;R(_),a(Y,_.signal).then(Ie=>{_.signal.aborted||(F(Ie.map(r)),R(void 0),je.current&&(Ie.length>0&&n(Ie.slice(0,1)),b(!1)))}).catch(Ie=>{_.signal.aborted||Ie.message.includes("aborted")||Ju({color:"red",message:$u(Ie)})})},[a,n,r]),L=So(()=>{Me.current&&(Me.current.abort(),R(void 0)),Z.current!==void 0&&window.clearTimeout(Z.current);let Y=window.setTimeout(()=>g(),100);h(Y)},[g]),De=So(Y=>{let _=[],Ie=[];for(let Fn of Y){let At=te.current?.find($i=>$i.value===Fn),Zo=At?.resource;!Zo&&s!==!1&&l&&(Zo=l(Fn),At=r(Zo)),Zo&&_.push(Zo),At&&Ie.push(At)}n(_),Q(Ie)},[s,n,l,r]),C=So(Y=>{Y.key==="Enter"&&(!Z.current&&!Me.current?(O(Y),te.current&&te.current.length>0&&(F(te.current.slice(0,1)),De([te.current[0].value]))):b(!0))},[De]),H=So(Y=>{let _=r(l(Y));return F([...te.current,_]),_},[l,F,r]),Fe=So((Y,_)=>!_,[]);return Ku(()=>()=>{Me.current&&Me.current.abort()},[]),tl(Xu,{...f,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:C,onSearchChange:L,data:[...k,...y],onFocus:g,onChange:De,onCreate:H,rightSectionWidth:40,rightSection:I?tl(Wu,{size:16}):null,filter:Fe,creatable:!0,withinPortal:!0})}function _u(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Do,jsxs as fl}from"react/jsx-runtime";var rc=Zu(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function ac(e){return e.id}function nc(e){return{value:e.id,label:sl(e),resource:e}}function il(e){let{classes:o}=rc(),t=Ue(),r=v(),a=al(async(l,s)=>{let f=fc(l),i={signal:s},u=await r.graphql(f,void 0,void 0,i);return sc(u,l)},[r]),n=al(l=>{l.length>0&&t(`/${ec(l[0])}`)},[t]);return Do(Po,{size:"sm",radius:"md",className:o.searchInput,icon:Do(pa,{size:16}),placeholder:"Search",itemComponent:lc,toKey:ac,toOption:nc,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var lc=tc(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Do("div",{ref:t,...o,children:fl(Yu,{noWrap:!0,children:[Do(le,{value:e}),fl("div",{children:[Do(rl,{children:sl(e)}),Do(rl,{size:"xs",color:"dimmed",children:r})]})]})})});function fc(e){let o=JSON.stringify(e);return oc(e)?`{
|
|
2
2
|
Patients1: PatientList(_id: ${o}, _count: 1) {
|
|
3
3
|
resourceType
|
|
4
4
|
id
|
|
@@ -61,8 +61,8 @@ import{useEffect as wn,useMemo as Ki,useState as _i}from"react";import{createCon
|
|
|
61
61
|
display
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
}`.replace(/\s+/g," ")}function sc(e,o){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),uc(ic(t),o).slice(0,5)}function ic(e){let o=new Set,t=[];for(let r of e)o.has(r.id)||(o.add(r.id),t.push(r));return t}function uc(e,o){return e.sort((t,r)=>nl(r,o)-nl(t,o))}function nl(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,ll(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,ll(ju(r),o));return t}function ll(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as J,jsxs as ze}from"react/jsx-runtime";var gc=dc(e=>({logoButton:{padding:`${e.spacing.xs} ${e.spacing.sm}`,borderRadius:e.radius.sm,transition:"background-color 100ms ease","&:hover":{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}},user:{padding:`${e.spacing.xs} ${e.spacing.sm}`,borderRadius:e.radius.sm,transition:"background-color 100ms ease","&:hover":{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}},userName:{fontWeight:500,lineHeight:1,marginRight:3,[e.fn.smallerThan("xs")]:{display:"none"}},userActive:{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}}));function dl(e){let o=Yo(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:s}=gc(),[f,i]=Ic(!1);return J(mc,{height:60,p:8,style:{zIndex:101},children:ze(Vt,{position:"apart",children:[ze(Vt,{spacing:"xs",children:[J(ul,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&J(il,{pathname:e.pathname,searchParams:e.searchParams})]}),ze(Ee,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:f,onClose:()=>i(!1),children:[J(Ee.Target,{children:J(ul,{className:s(l.user,{[l.userActive]:f}),onClick:()=>i(u=>!u),children:ze(Vt,{spacing:7,children:[J(le,{value:r,radius:"xl",size:24}),J(nt,{size:"sm",className:l.userName,children:xc(r?.name?.[0])}),J(jr,{size:12,stroke:1.5})]})})}),ze(Ee.Dropdown,{children:[ze(pc,{align:"center",p:"xl",children:[J(le,{size:"xl",radius:100,value:o.profile}),J(Nt,{value:o.profile?.name?.[0]}),J(nt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&J(Ee.Divider,{}),n.map(u=>u.profile.reference!==cl(o.profile)&&J(Ee.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:ze(Vt,{children:[J(cc,{radius:"xl"}),ze("div",{style:{flex:1},children:[J(nt,{size:"sm",weight:500,children:u.profile.display}),J(nt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),J(Ee.Divider,{}),J(Ee.Item,{icon:J(Ia,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),J(Ee.Item,{icon:J(yo,{size:14,stroke:1.5}),onClick:()=>a(`/${cl(r)}`),children:"Account settings"}),J(Ee.Item,{icon:J(sa,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),J(nt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as Qc,createStyles as zc,Navbar as Sa,ScrollArea as Wc,Space as Xc,Text as Jc}from"@mantine/core";import{Fragment as $c,useState as Kc}from"react";import{Button as vc,Group as Sc,Modal as Rc,NativeSelect as bc,Stack as Pc,TextInput as Dc}from"@mantine/core";import{showNotification as pl}from"@mantine/notifications";import{deepClone as Tc,normalizeErrorString as kc}from"@medplum/core";function ml(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?hc(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Cc(o,t);return o}function hc(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Cc(e,o){e[o.name]=o.value}import{jsx as yc}from"react/jsx-runtime";function W(e){return yc("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=ml(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as ro,jsxs as Ac}from"react/jsx-runtime";function xl(e){let o=v(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,s=`${e.pathname}?${e.searchParams.toString()}`,f=Tc(t);f.menu?.find(({title:u})=>u===n)?.link?.push({name:l,target:s}),o.updateResource(f).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),pl({color:"green",message:"Success"}),e.onOk()}).catch(u=>{pl({color:"red",message:kc(u)})})}return ro(Rc,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:ro(W,{onSubmit:r,children:Ac(Pc,{children:[ro(Bc,{config:t}),ro(Dc,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),ro(Sc,{position:"right",children:ro(vc,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Bc(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return ro(bc,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as qc,useState as Gc}from"react";import{useState as Lc}from"react";import{useCallback as Mc}from"react";import{jsx as Ec}from"react/jsx-runtime";function va(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Fc(e){return typeof e.display=="string"?e.display:va(e)}function wc(e){return{value:va(e),label:Fc(e),resource:e}}function Oc(e){return{code:e,display:e}}function To(e){let o=v(),{binding:t,creatable:r,clearable:a,...n}=e,l=Mc(async(s,f)=>{if(!t)return[];let u=(await o.searchValueSet(t,s,{signal:f})).expansion?.contains,d=[];for(let c of u)c.code&&!d.some(x=>x.code===c.code)&&d.push(c);return d},[o,t]);return Ec(Po,{...n,creatable:r??!0,clearable:a??!0,toKey:va,toOption:wc,loadOptions:l,onCreate:Oc,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}import{jsx as Vc}from"react/jsx-runtime";function qt(e){let[o,t]=Lc(e.defaultValue);function r(a){let n=a[0],l=Hc(n);t(l),e.onChange&&e.onChange(l)}return Vc(To,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Nc(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Nc(e){return e?{code:e}:void 0}function Hc(e){return e?.code}import{jsx as Uc}from"react/jsx-runtime";function ko(e){let[o,t]=Gc(e.defaultValue),r=e.onChange,a=qc(n=>{t(n),r&&r(n)},[r]);return Uc(qt,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as ed,jsx as Pe,jsxs as lt}from"react/jsx-runtime";var Il=zc(e=>({menuTitle:{margin:"20px 0 4px 6px",fontSize:"9px",fontWeight:"normal",textTransform:"uppercase",letterSpacing:"2px"},link:{...e.fn.focusStyles(),display:"flex",alignItems:"center",textDecoration:"none",fontSize:e.fontSizes.sm,color:e.colorScheme==="dark"?e.colors.dark[1]:e.colors.gray[7],padding:"8px 12px",borderRadius:e.radius.sm,fontWeight:500,"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[6]:e.colors.gray[0],color:e.colorScheme==="dark"?e.white:e.black,textDecoration:"none","& svg":{color:e.colorScheme==="dark"?e.white:e.black}},"& svg":{color:e.colorScheme==="dark"?e.colors.dark[2]:e.colors.gray[6],marginRight:e.spacing.sm,strokeWidth:1.5,width:18,height:18}},linkActive:{"&, &:hover":{backgroundColor:e.fn.variant({variant:"light",color:e.primaryColor}).background,color:e.fn.variant({variant:"light",color:e.primaryColor}).color,"& svg":{color:e.fn.variant({variant:"light",color:e.primaryColor}).color}}}}));function gl(e){let{classes:o}=Il(),t=Ue(),r=Yc(e.pathname,e.searchParams,e.menus),[a,n]=Kc(!1);function l(f,i){f.stopPropagation(),f.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function s(f){f&&t(`/${f}`)}return lt(ed,{children:[Pe(Sa,{width:{sm:250},p:"xs",children:lt(Wc,{children:[!e.resourceTypeSearchDisabled&&Pe(Sa.Section,{mb:"sm",children:Pe(ko,{name:"resourceType",placeholder:"Resource Type",onChange:f=>s(f)},window.location.pathname)}),lt(Sa.Section,{grow:!0,children:[e.menus?.map(f=>lt($c,{children:[Pe(Jc,{className:o.menuTitle,children:f.title}),f.links?.map(i=>lt(_c,{to:i.href,active:i.href===r?.href,onClick:u=>l(u,i.href),children:[Pe(Zc,{to:i.href,icon:i.icon}),Pe("span",{children:i.label})]},i.href))]},`menu-${f.title}`)),e.displayAddBookmark&&Pe(Qc,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Pe(da,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Pe(xl,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function _c(e){let{classes:o,cx:t}=Il();return Pe(j,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function Zc(e){return e.icon?e.icon:Pe(Xc,{w:30})}function Yc(e,o,t){if(!e||!o||!t)return;let r,a=0;for(let n of t)if(n.links)for(let l of n.links){let s=jc(e,o,l.href);s>a&&(a=s,r=l)}return r}function jc(e,o,t){let r=new URL(t,"https://example.com");if(e!==r.pathname)return 0;let a=["_count","_offset"];for(let[l,s]of r.searchParams.entries())if(!a.includes(l)&&o.get(l)!==s)return 0;let n=1;for(let[l,s]of o.entries())a.includes(l)||r.searchParams.get(l)===s&&n++;return n}import{jsx as ao}from"react/jsx-runtime";function BD(e){let o=td(),[t,r]=ld(localStorage.navbarOpen==="true"),a=v(),n=Ft();nd(()=>{function i(){rd({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",i),()=>a.removeEventListener("offline",i)},[a]);function l(i){localStorage.navbarOpen=i.toString(),r(i)}function s(){l(!1)}function f(){l(!t)}return a.isLoading()?ao(Ca,{}):ao(od,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&ao(dl,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:f}),navbar:n&&t?ao(gl,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:s,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:ao(vo,{children:ao(ad,{fallback:ao(Ca,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as fd}from"@mantine/core";import{jsx as no,jsxs as id}from"react/jsx-runtime";function Be(e){let{contentType:o,url:t,title:r}=e.value??{};return t?id("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&no("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&no("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:no("source",{type:o,src:t})}),o==="application/pdf"&&no("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:no("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),no("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:no(fd,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:sd(r),children:r||"Download"})})]}):null}function sd(e){return e?.includes(".")?e:void 0}import{jsx as Ra}from"react/jsx-runtime";function hl(e){return Ra("div",{children:e.values?.map((o,t)=>Ra("div",{children:Ra(Be,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as Cl}from"@mantine/core";import{useRef as xd,useState as Id}from"react";import{useRef as ud}from"react";import{normalizeOperationOutcome as cd}from"@medplum/core";import{Fragment as md,jsx as dd,jsxs as pd}from"react/jsx-runtime";function Bo(e){let o=v(),t=ud(null);function r(l){O(l),t.current?.click()}function a(l){O(l);let s=l.target.files;s&&Array.from(s).forEach(n)}function n(l){if(!l||!l.name)return;e.onUploadStart&&e.onUploadStart();let f=l.name,i=l.type||"application/octet-stream";o.createBinary(l,f,i,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:f})}).catch(u=>{e.onUploadError&&e.onUploadError(cd(u))})}return pd(md,{children:[dd("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as Ce,jsxs as ft}from"react/jsx-runtime";function yl(e){let[o,t]=Id(e.defaultValue??[]),r=xd();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return ft("table",{style:{width:"100%"},children:[ft("colgroup",{children:[Ce("col",{width:"97%"}),Ce("col",{width:"3%"})]}),ft("tbody",{children:[o.map((n,l)=>ft("tr",{children:[Ce("td",{children:Ce(Be,{value:n,maxWidth:200})}),Ce("td",{children:Ce(Cl,{title:"Remove",size:"sm",onClick:s=>{O(s);let f=o.slice();f.splice(l,1),a(f)},children:Ce(Qe,{})})})]},`${l}-${o.length}`)),ft("tr",{children:[Ce("td",{}),Ce("td",{children:Ce(Bo,{onUpload:n=>{a([...r.current,n])},children:n=>Ce(Cl,{...n,title:"Add",size:"sm",color:"green",children:Ce(ot,{size:16})})})})]})]})]})}import{Button as vl}from"@mantine/core";import{useState as gd}from"react";import{Fragment as hd,jsx as Gt,jsxs as Cd}from"react/jsx-runtime";function Ut(e){let[o,t]=gd(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?Cd(hd,{children:[Gt(Be,{value:o,maxWidth:200}),Gt(vl,{onClick:a=>{O(a),r(void 0)},children:"Remove"})]}):Gt(Bo,{onUpload:r,children:a=>Gt(vl,{...a,children:"Upload..."})})}import{getPropertyDisplayName as nm,tryGetDataType as lm}from"@medplum/core";var Qt=["meta","implicitRules","contained","extension","modifierExtension"],zt=["language","text"];import{createStyles as yd}from"@mantine/core";import{Fragment as Sd,jsx as ba,jsxs as Rd}from"react/jsx-runtime";var vd=yd(e=>({root:{display:"grid",gridTemplateColumns:"30% 70%",margin:0,"& > dt, & > dd":{padding:`${e.spacing.sm} ${e.spacing.sm}`,borderTop:`0.1px solid ${e.colors.gray[3]}`,margin:0}},compact:{gridTemplateColumns:"20% 80%","& > dt, & > dd":{padding:`0 ${e.spacing.xs} ${e.spacing.xs} 0`,border:0}}}));function Sl(e){let{children:o,compact:t}=e,{classes:r,cx:a}=vd();return ba("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function Rl(e){return Rd(Sd,{children:[ba("dt",{children:e.term}),ba("dd",{children:e.children})]})}import{ActionIcon as Kd,Box as _d,CopyButton as Zd,Tooltip as Yd}from"@mantine/core";import{formatDateTime as jd,formatPeriod as em,formatTiming as om,isEmpty as tm,PropertyType as E}from"@medplum/core";import{formatCodeableConcept as bd}from"@medplum/core";import{Fragment as Pd,jsx as Dd}from"react/jsx-runtime";function Ao(e){return Dd(Pd,{children:bd(e.value)})}import{formatCoding as Td}from"@medplum/core";import{Fragment as kd,jsx as Bd}from"react/jsx-runtime";function bl(e){return Bd(kd,{children:Td(e.value)})}import{Fragment as Ad,jsx as Md}from"react/jsx-runtime";function Wt(e){let o=e.value;if(!o)return null;let t=[];return o.value&&t.push(o.value),(o.use||o.system)&&(t.push(" ["),o.use&&t.push(o.use),o.use&&o.system&&t.push(" "),o.system&&t.push(o.system),t.push("]")),Md(Ad,{children:t.join("").trim()})}import{Fragment as wd,jsx as Fd,jsxs as Od}from"react/jsx-runtime";function Pl(e){let o=e.value;return o?Od(wd,{children:[o.name,o.name&&": ",o.telecom?.map(t=>Fd(Wt,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as Ed}from"react/jsx-runtime";function Dl(e){return Ed("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as Ld}from"@medplum/core";import{Fragment as Nd,jsx as Hd}from"react/jsx-runtime";function Tl(e){return Hd(Nd,{children:Ld(e.value)})}import{formatQuantity as Vd}from"@medplum/core";import{Fragment as qd,jsx as Gd}from"react/jsx-runtime";function We(e){return Gd(qd,{children:Vd(e.value)})}import{formatRange as Ud}from"@medplum/core";import{Fragment as Qd,jsx as zd}from"react/jsx-runtime";function Xt(e){return zd(Qd,{children:Ud(e.value)})}import{Fragment as Wd,jsx as kl,jsxs as Xd}from"react/jsx-runtime";function Bl(e){let o=e.value;return o?Xd(Wd,{children:[kl(We,{value:o.numerator}),"\xA0/\xA0",kl(We,{value:o.denominator})]}):null}import{stringify as Jd}from"@medplum/core";import{Fragment as $d,jsx as Al}from"react/jsx-runtime";function lo(e){if(!e.value)return null;let o=e.value.display||e.value.reference||Jd(e.value);return e.link!==!1&&e.value.reference?Al(j,{to:e.value,children:o}):Al($d,{children:o})}import{Fragment as Ml,jsx as Jt}from"react/jsx-runtime";function Fl(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?Jt(Ml,{children:t.map((a,n)=>Jt("div",{children:Jt(re,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):Jt(Ml,{})}import{Fragment as Mo,jsx as V,jsxs as rm}from"react/jsx-runtime";function re(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return rm(_d,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!tm(r)&&V(Zd,{value:r,timeout:2e3,children:({copied:n,copy:l})=>V(Yd,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:V(Kd,{color:n?"teal":"gray",onClick:l,children:n?V(et,{size:"1rem"}):V(oa,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===E.Attachment?V(hl,{values:r,maxWidth:e.maxWidth}):V(Fl,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case E.boolean:return V(Mo,{children:r===void 0?"":(!!r).toString()});case E.SystemString:case E.string:return V("div",{style:{whiteSpace:"pre-wrap"},children:r});case E.code:case E.date:case E.decimal:case E.integer:case E.positiveInt:case E.unsignedInt:case E.uri:case E.url:return V(Mo,{children:r});case E.canonical:return V(lo,{value:{reference:r},link:e.link});case E.dateTime:case E.instant:return V(Mo,{children:jd(r)});case E.markdown:return V("pre",{children:r});case E.Address:return V(qn,{value:r});case E.Annotation:return V(Mo,{children:r?.text});case E.Attachment:return V(Be,{value:r,maxWidth:e.maxWidth});case E.CodeableConcept:return V(Ao,{value:r});case E.Coding:return V(bl,{value:r});case E.ContactDetail:return V(Pl,{value:r});case E.ContactPoint:return V(Wt,{value:r});case E.HumanName:return V(Nt,{value:r});case E.Identifier:return V(Dl,{value:r});case E.Money:return V(Tl,{value:r});case E.Period:return V(Mo,{children:em(r)});case E.Quantity:case E.Duration:return V(We,{value:r});case E.Range:return V(Xt,{value:r});case E.Ratio:return V(Bl,{value:r});case E.Reference:return V(lo,{value:r,link:e.link});case E.Timing:return V(Mo,{children:om(r)});case E.Dosage:case E.UsageContext:return V(st,{value:{type:t,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});default:if(!o)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);return V(st,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as am}from"@medplum/core";function pe(e,o){let t=am(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}import{jsx as $t,jsxs as fm}from"react/jsx-runtime";function st(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=lm(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?$t("div",{children:t.name}):$t(Sl,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,s]=n;if(Qt.includes(l)||zt.includes(l)&&s.path.split(".").length===2)return null;let[f,i]=pe(o,l);return e.ignoreMissingValues&&(!f||Array.isArray(f)&&f.length===0)?null:$t(Rl,{term:nm(l),children:$t(re,{property:s,propertyType:i,value:f,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):fm("div",{children:[r,"\xA0not implemented"]})}import{Stack as Wp}from"@mantine/core";import{getPropertyDisplayName as If,tryGetDataType as Xp}from"@medplum/core";import{useState as Jp}from"react";import{Group as sm,Input as im}from"@mantine/core";import{jsx as Pa,jsxs as um}from"react/jsx-runtime";function Kt(e){return um(sm,{noWrap:!0,children:[Pa("div",{children:e.children}),Pa("div",{children:Pa(im.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,children:(()=>null)()})})]})}import{Input as cm}from"@mantine/core";function ae(e,o){return e?.issue?.filter(t=>wl(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
-
`)}function _t(e,o){return e?.issue?.filter(t=>wl(t.expression?.[0],o))}function wl(e,o){if(e===o)return!0;if(!e||!o)return!1;let t=e.indexOf(".");if(t>=0&&e.substring(t+1)===o)return!0;let r=o.indexOf(".");return r>=0&&o.substring(r+1)===e}import{jsx as dm}from"react/jsx-runtime";function xe(e){return dm(cm.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,error:ae(e.outcome,e.htmlFor),children:e.children})}import{capitalize as mm}from"@medplum/core";function it(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let s=o.replace("[x]",mm(l.code));s in e&&delete e[s]}return e[t]=a,e}import{Checkbox as Lp,Group as Np,NativeSelect as Hp,Textarea as Vp,TextInput as Fa}from"@mantine/core";import{capitalize as qp,PropertyType as F}from"@medplum/core";import{useState as Gp}from"react";import{useState as pm}from"react";import{jsx as gm}from"react/jsx-runtime";function Ol(e){let[o,t]=pm(e.defaultValue);function r(a){let n=Im(a);t(n),e.onChange&&e.onChange(n)}return gm(To,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&xm(o),maxSelectedValues:1,onChange:r})}function xm(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Im(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as hm}from"react";import{jsx as vm}from"react/jsx-runtime";function Zt(e){let[o,t]=hm(e.defaultValue);function r(a){let n=a[0],l=n&&ym(n);t(l),e.onChange&&e.onChange(l)}return vm(To,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Cm(o),maxSelectedValues:1,onChange:r})}function Cm(e){return{system:e.system,code:e.code,display:e.display}}function ym(e){return{system:e.system,code:e.code,display:e.display}}import{Group as Tm,TextInput as km}from"@mantine/core";import{useRef as Bm,useState as Am}from"react";import{Group as Sm,NativeSelect as El,TextInput as Rm}from"@mantine/core";import{useRef as bm,useState as Pm}from"react";import{jsx as Da,jsxs as Dm}from"react/jsx-runtime";function Yt(e){let[o,t]=Pm(e.defaultValue),r=bm();r.current=o;function a(f){f&&Object.keys(f).length===0&&(f=void 0),t(f),e.onChange&&e.onChange(f)}function n(f){let i={...r.current,system:f};f||delete i.system,a(i)}function l(f){let i={...r.current,use:f};f||delete i.use,a(i)}function s(f){let i={...r.current,value:f};f||delete i.value,a(i)}return Dm(Sm,{spacing:"xs",grow:!0,noWrap:!0,children:[Da(El,{"data-testid":"system",defaultValue:o?.system,onChange:f=>n(f.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),Da(El,{"data-testid":"use",defaultValue:o?.use,onChange:f=>l(f.currentTarget.value),data:["","home","work","temp","old","mobile"]}),Da(Rm,{placeholder:"Value",defaultValue:o?.value,onChange:f=>s(f.currentTarget.value)})]})}import{jsx as Ll,jsxs as Mm}from"react/jsx-runtime";function Nl(e){let[o,t]=Am(e.defaultValue),r=Bm();r.current=o;function a(s){t(s),e.onChange&&e.onChange(s)}function n(s){let f={...r.current,name:s};s||delete f.name,a(f)}function l(s){let f={...r.current,telecom:s&&[s]};s||delete f.telecom,a(f)}return Mm(Tm,{spacing:"xs",grow:!0,noWrap:!0,children:[Ll(km,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:s=>n(s.currentTarget.value)}),Ll(Yt,{name:e.name+"-telecom",defaultValue:o?.telecom?.[0],onChange:l})]})}import{TextInput as Fm}from"@mantine/core";import{isValidDate as Hl}from"@medplum/core";function Vl(e){if(!e)return"";let o=new Date(e);return Hl(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function ql(e){if(!e)return"";let o=new Date(e);return Hl(o)?o.toISOString():""}import{jsx as Om}from"react/jsx-runtime";function De(e){return Om(Fm,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:wm(),defaultValue:Vl(e.defaultValue),autoFocus:e.autoFocus,error:ae(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(ql(t))}}})}function wm(){return"datetime-local"}import{JsonInput as Em}from"@mantine/core";import{stringify as Lm}from"@medplum/core";import{jsx as Nm}from"react/jsx-runtime";function Gl(e){return Nm(Em,{id:e.name,name:e.name,"data-testid":"extension-input",defaultValue:Lm(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as Hm,NativeSelect as Vm,TextInput as jt}from"@mantine/core";import{useRef as qm,useState as Gm}from"react";import{jsx as ut,jsxs as Um}from"react/jsx-runtime";function Ul(e){let[o,t]=Gm(e.defaultValue),r=qm();r.current=o;function a(u){t(u),e.onChange&&e.onChange(u)}function n(u){a({...r.current,use:u||void 0})}function l(u){a({...r.current,prefix:u?u.split(" "):void 0})}function s(u){a({...r.current,given:u?u.split(" "):void 0})}function f(u){a({...r.current,family:u||void 0})}function i(u){a({...r.current,suffix:u?u.split(" "):void 0})}return Um(Hm,{spacing:"xs",grow:!0,noWrap:!0,children:[ut(Vm,{defaultValue:o?.use,name:e.name+"-use","data-testid":"use",onChange:u=>n(u.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"]}),ut(jt,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:o?.prefix?.join(" "),onChange:u=>l(u.currentTarget.value)}),ut(jt,{placeholder:"Given",name:e.name+"-given",defaultValue:o?.given?.join(" "),onChange:u=>s(u.currentTarget.value)}),ut(jt,{name:e.name+"-family",placeholder:"Family",defaultValue:o?.family,onChange:u=>f(u.currentTarget.value)}),ut(jt,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:o?.suffix?.join(" "),onChange:u=>i(u.currentTarget.value)})]})}import{Group as Qm,TextInput as Ql}from"@mantine/core";import{useState as zm}from"react";import{jsx as zl,jsxs as Wm}from"react/jsx-runtime";function Wl(e){let[o,t]=zm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Wm(Qm,{spacing:"xs",grow:!0,noWrap:!0,children:[zl(Ql,{placeholder:"System",defaultValue:o?.system,onChange:a=>r({...o,system:a.currentTarget.value})}),zl(Ql,{placeholder:"Value",defaultValue:o?.value,onChange:a=>r({...o,value:a.currentTarget.value})})]})}import{NativeSelect as Xm,TextInput as Jm}from"@mantine/core";import{useCallback as Ta,useState as $m}from"react";import{jsx as ka}from"react/jsx-runtime";var Km=["USD","EUR","CAD","GBP","AUD"];function Xl(e){let{onChange:o}=e,[t,r]=$m(e.defaultValue),a=Ta(f=>{r(f),o&&o(f)},[o]),n=Ta(f=>{a({...t,currency:f.currentTarget.value})},[t,a]),l=Ta(f=>{a({...t,value:f.currentTarget.valueAsNumber})},[t,a]),s=ka(Xm,{defaultValue:t?.currency,data:Km,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return ka(Jm,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:ka(ta,{size:14}),rightSection:s,rightSectionWidth:92,onChange:l})}import{Group as _m}from"@mantine/core";import{useState as Zm}from"react";import{jsx as Jl,jsxs as Ym}from"react/jsx-runtime";function $l(e){let[o,t]=Zm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Ym(_m,{spacing:"xs",grow:!0,noWrap:!0,children:[Jl(De,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),Jl(De,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as jm,NativeSelect as ep,TextInput as Kl}from"@mantine/core";import{useState as op}from"react";import{jsx as Ba,jsxs as rp}from"react/jsx-runtime";function ye(e){let[o,t]=op(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return rp(jm,{spacing:"xs",grow:!0,noWrap:!0,children:[Ba(ep,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),Ba(Kl,{id:e.name,name:e.name,required:e.required,"data-autofocus":e.autoFocus,"data-testid":e.name+"-value",type:"number",placeholder:"Value",defaultValue:o?.value,autoFocus:e.autoFocus,step:"any",onWheel:a=>{e.disableWheel&&a.currentTarget.blur()},onChange:a=>{r({...o,value:tp(a.currentTarget.value)})}}),Ba(Kl,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function tp(e){if(e)return parseFloat(e)}import{Group as ap}from"@mantine/core";import{useState as np}from"react";import{jsx as _l,jsxs as lp}from"react/jsx-runtime";function ct(e){let[o,t]=np(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return lp(ap,{spacing:"xs",grow:!0,noWrap:!0,children:[_l(ye,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),_l(ye,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as fp}from"@mantine/core";import{useState as sp}from"react";import{jsx as Zl,jsxs as ip}from"react/jsx-runtime";function Yl(e){let[o,t]=sp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return ip(fp,{spacing:"xs",grow:!0,noWrap:!0,children:[Zl(ye,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Zl(ye,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as Cp,NativeSelect as yp}from"@mantine/core";import{createReference as vp}from"@medplum/core";import{useState as rf}from"react";import{Group as up,Text as jl}from"@mantine/core";import{getDisplayString as cp,getReferenceString as tf}from"@medplum/core";import{forwardRef as dp,useCallback as ef,useState as mp}from"react";import{jsx as dt,jsxs as of}from"react/jsx-runtime";var pp={Observation:"code",User:"email:contains"},xp=["AccessPolicy","Account","ActivityDefinition","Bot","CapabilityStatement","ClientApplication","CodeSystem","CompartmentDefinition","ConceptMap","EffectEvidenceSynthesis","Endpoint","EventDefinition","Evidence","EvidenceVariable","ExampleScenario","GraphDefinition","HealthcareService","ImplementationGuide","InsurancePlan","Library","Location","Measure","MedicinalProduct","MessageDefinition","NamingSystem","OperationDefinition","Organization","Patient","Person","PlanDefinition","Practitioner","Project","Questionnaire","RelatedPerson","ResearchDefinition","ResearchElementDefinition","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function Ip(e){return{value:tf(e),label:cp(e),resource:e}}function er(e){let o=v(),t=e.resourceType,[r,a]=mp(),n=G(e.defaultValue,a),l=e.onChange,s=ef(async(i,u)=>{let d=hp(t),c=new URLSearchParams({[d]:i,_count:"10"});return await o.searchResources(t,c,{signal:u})},[o,t]),f=ef(i=>{l&&l(i[0])},[l]);return e.defaultValue&&!r&&!n?null:dt(Po,{name:e.name,required:e.required,itemComponent:gp,defaultValue:n,placeholder:e.placeholder,maxSelectedValues:1,toKey:tf,toOption:Ip,loadOptions:s,onChange:f,clearable:!0})}var gp=dp(({label:e,resource:o,...t},r)=>dt("div",{ref:r,...t,children:of(up,{noWrap:!0,children:[dt(le,{value:o}),of("div",{children:[dt(jl,{children:e}),dt(jl,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function hp(e){return pp[e]??(xp.includes(e)?"name":"_id")}import{jsx as Aa,jsxs as bp}from"react/jsx-runtime";function Fo(e){let o=Sp(e.targetTypes),t=Rp(e.defaultValue,o),[r,a]=rf(e.defaultValue),[n,l]=rf(t);function s(f){a(f),e.onChange&&e.onChange(f)}return bp(Cp,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&Aa(yp,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:n,autoFocus:e.autoFocus,onChange:f=>l(f.currentTarget.value),data:o}),!o&&Aa(ko,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:l,name:e.name+"-resourceType",placeholder:"Resource Type"}),Aa(er,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,onChange:f=>{s(f?vp(f):void 0)}})]})}function Sp(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function Rp(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}import{ActionIcon as af,Group as nf,Stack as Pp}from"@mantine/core";import{useRef as Dp,useState as Tp}from"react";import{jsx as Le,jsxs as lf}from"react/jsx-runtime";function ff(e){let[o,t]=Tp(e.defaultValue&&Array.isArray(e.defaultValue)?e.defaultValue:[]),r=Dp();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return lf(Pp,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,l)=>lf(nf,{noWrap:!0,children:[Le("div",{style:{flexGrow:1},children:Le(Ne,{arrayElement:!0,property:e.property,name:e.name+"."+l,defaultValue:n,onChange:s=>{let f=[...r.current];f[l]=s,a(f)}})}),Le("div",{children:Le(af,{title:"Remove",size:"sm",onClick:s=>{O(s);let f=[...r.current];f.splice(l,1),a(f)},children:Le(Qe,{})})})]},`${l}-${o.length}`)),Le(nf,{noWrap:!0,style:{justifyContent:"flex-end"},children:Le("div",{children:Le(af,{title:"Add",size:"sm",color:"green",onClick:n=>{O(n);let l=[...r.current];l.push(void 0),a(l)},children:Le(go,{})})})})]})}import{Button as cf,Chip as sf,Group as or,Modal as kp,NativeSelect as Bp,Stack as Ap,Switch as Mp,TextInput as Fp}from"@mantine/core";import{formatTiming as wp}from"@medplum/core";import{useRef as df,useState as Ma}from"react";import{Fragment as pf,jsx as ne,jsxs as mt}from"react/jsx-runtime";var Op=["sun","mon","tue","wed","thu","fri","sat"];function mf(e){let[o,t]=Ma(e.defaultValue),[r,a]=Ma(!1),n=df();return n.current=o,mt(pf,{children:[mt(or,{spacing:"xs",grow:!0,noWrap:!0,children:[ne("span",{children:wp(n.current)||"No repeat"}),ne(cf,{onClick:()=>a(!0),children:"Edit"})]}),ne(Ep,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var uf={repeat:{period:1,periodUnit:"d"}};function Ep(e){let[o,t]=Ma(e.defaultValue||uf),r=df();r.current=o;function a(i){t({...r.current,event:[i]})}function n(i){t({...r.current,repeat:i})}function l(i){n({...r.current?.repeat,period:i})}function s(i){n({...r.current?.repeat,periodUnit:i})}function f(i){n({...r.current?.repeat,dayOfWeek:i})}return ne(kp,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:mt(Ap,{children:[ne(xe,{title:"Starts on",htmlFor:"timing-dialog-start",children:ne(De,{name:"timing-dialog-start",onChange:i=>a(i)})}),ne(Mp,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?uf.repeat:void 0)}),o.repeat&&mt(pf,{children:[ne(xe,{title:"Repeat every",htmlFor:"timing-dialog-period",children:mt(or,{spacing:"xs",grow:!0,noWrap:!0,children:[ne(Fp,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:i=>l(parseInt(i.currentTarget.value,10)||1)}),ne(Bp,{id:"timing-dialog-periodUnit",name:"timing-dialog-periodUnit",defaultValue:o.repeat.periodUnit,onChange:i=>s(i.currentTarget.value),data:[{label:"second",value:"s"},{label:"minute",value:"min"},{label:"hour",value:"h"},{label:"day",value:"d"},{label:"week",value:"wk"},{label:"month",value:"mo"},{label:"year",value:"a"}]})]})}),o.repeat.periodUnit==="wk"&&ne(xe,{title:"Repeat on",children:ne(sf.Group,{multiple:!0,onChange:f,children:ne(or,{position:"apart",mt:"md",spacing:"xs",children:Op.map(i=>ne(sf,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),ne(or,{position:"right",children:ne(cf,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as N,jsxs as zp}from"react/jsx-runtime";function Ne(e){let o=e.property,t=e.defaultPropertyType??o.type[0].code,r=e.name,a=e.defaultValue;if(o.max>1&&!e.arrayElement)return t===F.Attachment?N(yl,{name:r,defaultValue:a,onChange:e.onChange}):N(ff,{property:o,name:r,defaultValue:a,onChange:e.onChange});let n=o.type;return n.length>1?N(Up,{elementDefinitionTypes:n,...e}):N(xf,{elementDefinitionType:n[0],...e})}function Up(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=Gp(t);return zp(Np,{spacing:"xs",grow:!0,noWrap:!0,children:[N(Hp,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(l=>l.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),N(xf,{...e,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",qp(r.code)))}})]})}function xf(e){let o=e.property,t=e.elementDefinitionType.code,r=e.name,a=e.defaultValue,n=o.min!==void 0&&o.min>0;switch(t){case F.SystemString:case F.canonical:case F.string:case F.time:case F.uri:case F.url:return N(Fa,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:ae(e.outcome,r)});case F.date:return N(Fa,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:ae(e.outcome,r)});case F.dateTime:case F.instant:return N(De,{name:r,defaultValue:a,onChange:e.onChange,outcome:e.outcome});case F.decimal:case F.integer:case F.positiveInt:case F.unsignedInt:return N(Fa,{type:"number",step:t===F.decimal?"any":"1",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.valueAsNumber)}});case F.code:return N(qt,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case F.boolean:return N(Lp,{id:r,name:r,"data-testid":r,defaultChecked:!!a,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.checked)}});case F.markdown:return N(Vp,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)}});case F.Address:return N(zn,{name:r,defaultValue:a,onChange:e.onChange});case F.Annotation:return N(Wn,{name:r,defaultValue:a,onChange:e.onChange});case F.Attachment:return N(Ut,{name:r,defaultValue:a,onChange:e.onChange});case F.CodeableConcept:return N(Ol,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case F.Coding:return N(Zt,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case F.ContactDetail:return N(Nl,{name:r,defaultValue:a,onChange:e.onChange});case F.ContactPoint:return N(Yt,{name:r,defaultValue:a,onChange:e.onChange});case F.Extension:return N(Gl,{name:r,defaultValue:a,onChange:e.onChange});case F.HumanName:return N(Ul,{name:r,defaultValue:a,onChange:e.onChange});case F.Identifier:return N(Wl,{name:r,defaultValue:a,onChange:e.onChange});case F.Money:return N(Xl,{name:r,defaultValue:a,onChange:e.onChange});case F.Period:return N($l,{name:r,defaultValue:a,onChange:e.onChange});case F.Duration:case F.Quantity:return N(ye,{name:r,defaultValue:a,onChange:e.onChange});case F.Range:return N(ct,{name:r,defaultValue:a,onChange:e.onChange});case F.Ratio:return N(Yl,{name:r,defaultValue:a,onChange:e.onChange});case F.Reference:return N(Fo,{name:r,defaultValue:a,targetTypes:Qp(o),onChange:e.onChange});case F.Timing:return N(mf,{name:r,defaultValue:a,onChange:e.onChange});case F.Dosage:case F.UsageContext:return N(pt,{typeName:t,defaultValue:a,onChange:e.onChange,outcome:e.outcome});default:return N(pt,{typeName:o.type[0].code,defaultValue:a,onChange:e.onChange,outcome:e.outcome})}}function Qp(e){return e?.type?.[0]?.targetProfile?.map(o=>o.split("/").pop())}import{jsx as xt,jsxs as $p}from"react/jsx-runtime";function pt(e){let[o,t]=Jp(e.defaultValue??{});function r(s){t(s),e.onChange&&e.onChange(s)}let a=e.typeName,n=Xp(a);if(!n)return $p("div",{children:[a,"\xA0not implemented"]});let l={type:a,value:o};return xt(Wp,{children:Object.entries(n.elements).map(([s,f])=>{if(s==="id"||Qt.includes(s)||zt.includes(s)&&f.path.split(".").length===2||!f.type)return null;let[i,u]=pe(l,s),d=f.min!==void 0&&f.min>0;return f.type.length===1&&f.type[0].code==="boolean"?xt(Kt,{title:If(s),description:f.description,htmlFor:s,children:xt(Ne,{property:f,name:s,defaultValue:i,defaultPropertyType:u,outcome:e.outcome,onChange:(c,x)=>{r(it(o,s,x??s,f,c))}})},s):xt(xe,{title:If(s),description:f.description,withAsterisk:d,htmlFor:s,outcome:e.outcome,children:xt(Ne,{property:f,name:s,defaultValue:i,defaultPropertyType:u,onChange:(c,x)=>{r(it(o,s,x??s,f,c))}})},s)})})}import{Button as wa,createStyles as Kp,Group as hf}from"@mantine/core";import{useMemo as _p,useState as Zp}from"react";function gf(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function tr(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as fe,jsxs as It}from"react/jsx-runtime";var Yp=Kp(e=>({table:{width:350,"& th":{fontWeight:"normal",fontSize:11,padding:8,textAlign:"center"},"& td":{padding:"2px 4px"},"& td button":{width:44,height:44,color:e.colors[e.primaryColor][5],fontSize:16,fontWeight:500,textAlign:"center",padding:0,backgroundColor:e.colors[e.primaryColor][0],border:0,borderRadius:"50%",cursor:"pointer"},"& td button:hover":{backgroundColor:e.colors[e.primaryColor][1]},"& td button:disabled":{backgroundColor:"transparent",cursor:"default",color:e.colors.gray[4],fontWeight:"normal"}}}));function Cf(e){let{classes:o}=Yp(),{onChangeMonth:t,onClick:r}=e,[a,n]=Zp(tr);function l(f){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+f),t(u),u})}let s=_p(()=>jp(a,e.slots),[a,e.slots]);return It("div",{children:[It(hf,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[fe("p",{style:{flex:1},children:gf(a)}),It(hf,{position:"right",spacing:"xs",children:[fe(wa,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),fe(wa,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),It("table",{className:o.table,children:[fe("thead",{children:It("tr",{children:[fe("th",{children:"SUN"}),fe("th",{children:"MON"}),fe("th",{children:"TUE"}),fe("th",{children:"WED"}),fe("th",{children:"THU"}),fe("th",{children:"FRI"}),fe("th",{children:"SAT"})]})}),fe("tbody",{children:s.map((f,i)=>fe("tr",{children:f.map((u,d)=>fe("td",{children:u&&fe(wa,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+d))},"week-"+i))})]})]})}function jp(e,o){let t=new Date(e.getFullYear(),e.getMonth()),r=[],a=[];for(let n=0;n<t.getDay();n++)a.push(void 0);for(;t.getMonth()===e.getMonth();)a.push({date:new Date(t.getTime()),available:ex(t,o)}),t.getDay()===6&&(r.push(a),a=[]),t.setDate(t.getDate()+1);if(t.getDay()!==0){for(let n=t.getDay();n<7;n++)a.push(void 0);r.push(a)}return r}function ex(e,o){for(let t of o){let r=new Date(t.start);if(r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate())return!0}return!1}import{Container as ox,createStyles as tx}from"@mantine/core";import{jsx as ax}from"react/jsx-runtime";var rx=tx(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Xe(e){let{children:o,...t}=e,{classes:r}=rx();return ax(ox,{className:r.root,...t,children:o})}import{ActionIcon as Hf,Center as jx,createStyles as eI,Group as oI,Loader as tI,Menu as He,ScrollArea as rI,TextInput as aI}from"@mantine/core";import{showNotification as nI,updateNotification as lr}from"@mantine/notifications";import{getReferenceString as ht,normalizeErrorString as Vf}from"@medplum/core";import{useCallback as fr,useEffect as lI,useRef as qf,useState as Gf}from"react";import{createStyles as Cx,Group as ar,List as Rf,Stack as bf,Text as ve,Title as Pf}from"@mantine/core";import{capitalize as yx,formatCodeableConcept as vx,formatDateTime as Ea,formatObservationValue as Sx,isReference as Rx}from"@medplum/core";import{useEffect as bx,useState as Px}from"react";import{Blockquote as nx,createStyles as lx,Stack as fx}from"@mantine/core";import{jsx as yf}from"react/jsx-runtime";var sx=lx(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function Oa({value:e}){let{classes:o}=sx();return e?yf(fx,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&yf(nx,{classNames:{cite:o.noteCite,body:o.noteBody,root:o.noteRoot},cite:t.authorReference?.display||t.authorString,icon:null,children:t.text},`note-${t.text}`))}):null}import{Group as px}from"@mantine/core";import{Text as ix}from"@mantine/core";import{getDisplayString as ux,isOk as cx,normalizeErrorString as dx}from"@medplum/core";import{useState as mx}from"react";import{jsx as vf}from"react/jsx-runtime";function Ae(e){let{value:o,link:t,...r}=e,[a,n]=mx(),l=G(o,n),s;if(a&&!cx(a))s=`[${dx(a)}]`;else if(l)s=ux(l);else return null;return t?vf(j,{to:o,...r,children:s}):vf(ix,{component:"span",...r,children:s})}import{jsx as Sf,jsxs as xx}from"react/jsx-runtime";function Je(e){return xx(px,{spacing:"xs",children:[Sf(le,{size:24,radius:12,value:e.value,link:e.link}),Sf(Ae,{value:e.value,link:e.link})]})}import{Badge as Ix}from"@mantine/core";import{jsx as hx}from"react/jsx-runtime";var gx={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"};function rr(e){return hx(Ix,{color:gx[e.status],children:e.status})}import{Fragment as gt,jsx as S,jsxs as se}from"react/jsx-runtime";var Df=Cx(e=>({table:{border:`0.1px solid ${e.colors.gray[5]}`,borderCollapse:"collapse","& td, & th":{border:`0.1px solid ${e.colors.gray[5]}`,padding:4}},criticalRow:{background:e.colorScheme==="dark"?e.colors.red[7]:e.colors.red[1],border:`0.1px solid ${e.colors.red[5]}`,color:e.colors.red[5],fontWeight:500,"& td":{border:`0.1px solid ${e.colors.red[5]}`}},noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));La.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function La(e){let o=v(),t=G(e.value),[r,a]=Px();if(bx(()=>{t?.specimen&&Promise.allSettled(t.specimen.map(l=>o.readReference(l))).then(l=>l.filter(s=>s.status==="fulfilled").map(s=>s.value)).then(a).catch(console.error)},[o,t]),!t)return null;let n=r?.flatMap(l=>l.note||[])||[];if(t.presentedForm&&t.presentedForm.length>0){let l=t.presentedForm[0];l.contentType?.startsWith("text/plain")&&l.data&&n.push({text:window.atob(l.data)})}return se(bf,{children:[S(Pf,{children:"Diagnostic Report"}),S(Dx,{value:t}),r&&!e.hideSpecimenInfo&&Tx(r),t.result&&S(kx,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&S(Oa,{value:n})]})}function Dx({value:e}){return se(ar,{mt:"md",spacing:30,children:[e.subject&&se("div",{children:[S(ve,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),S(ve,{children:S(Je,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>se("div",{children:[S(ve,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),S(ve,{children:S(Je,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>se("div",{children:[S(ve,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),S(ve,{children:S(Je,{value:o,link:!0})})]},o.reference)),e.issued&&se("div",{children:[S(ve,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),S(ve,{children:Ea(e.issued)})]}),e.status&&se("div",{children:[S(ve,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),S(ve,{children:yx(e.status)})]})]})}function Tx(e){return se(bf,{spacing:"xs",children:[S(Pf,{order:2,size:"h6",children:"Specimens"}),S(Rf,{type:"ordered",children:e?.map(o=>S(Rf.Item,{ml:"sm",children:se(ar,{spacing:20,children:[se(ar,{spacing:5,children:[S(ve,{fw:500,children:"Collected:"})," ",Ea(o.collection?.collectedDateTime)]}),se(ar,{spacing:5,children:[S(ve,{fw:500,children:"Received:"})," ",Ea(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function kx(e){let{classes:o}=Df();return se("table",{className:o.table,children:[S("thead",{children:se("tr",{children:[S("th",{children:"Test"}),S("th",{children:"Value"}),S("th",{children:"Reference Range"}),S("th",{children:"Interpretation"}),S("th",{children:"Category"}),S("th",{children:"Performer"}),S("th",{children:"Status"})]})}),S("tbody",{children:S(Tf,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function Tf(e){return S(gt,{children:e.value?.map(o=>S(Bx,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${Rx(o)?o.reference:o.id}`))})}function Bx(e){let{classes:o,cx:t}=Df(),r=G(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=Fx(r);return se(gt,{children:[se("tr",{className:t({[o.criticalRow]:n}),children:[S("td",{rowSpan:a?2:1,children:S(j,{to:r,children:S(Ao,{value:r.code})})}),S("td",{children:S(Ax,{value:r})}),S("td",{children:S(Mx,{value:r.referenceRange})}),S("td",{children:r.interpretation&&r.interpretation.length>0&&S(Ao,{value:r.interpretation[0]})}),S("td",{children:r.category&&r.category.length>0&&S(gt,{children:r.category.map(l=>S("div",{children:S(Ao,{value:l})},`category-${vx(l)}`))})}),S("td",{children:r.performer?.map(l=>S(lo,{value:l},l.reference))}),S("td",{children:r.status&&S(rr,{status:r.status})})]}),r.hasMember&&S(Tf,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&S("tr",{children:S("td",{colSpan:6,children:S(Oa,{value:r.note})})})]})}function Ax(e){let o=e.value;return S(gt,{children:Sx(o)})}function Mx(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?S(gt,{children:o.text}):S(Xt,{value:o}):null}function Fx(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as wx,Paper as Ox,useComponentDefaultProps as Ex}from"@mantine/core";import{jsx as Hx}from"react/jsx-runtime";var Lx=wx((e,{width:o,fill:t})=>({paper:{maxWidth:o,margin:`${e.spacing.xl} auto`,padding:t?0:e.spacing.md,"@media (max-width: 800px)":{padding:t?0:8},"& img":{width:"100%",maxWidth:"100%"},"& video":{width:"100%",maxWidth:"100%"}}})),Nx={shadow:"xs",radius:"md",withBorder:!0};function wo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Ex("Panel",Nx,e),{classes:s,cx:f}=Lx({width:r,fill:a},{name:"Panel",unstyled:n});return Hx(Ox,{className:f(s.paper,o),...l,children:t})}import{createStyles as Vx}from"@mantine/core";import{getDataType as qx,getPropertyDisplayName as Gx,stringify as kf,toTypedValue as Bf}from"@medplum/core";import{useEffect as Ux,useState as Qx}from"react";import{jsx as Ie,jsxs as nr}from"react/jsx-runtime";var zx=Vx(e=>({root:{borderCollapse:"collapse",width:"100%","& tr":{borderTop:`0.1px solid ${e.colors.gray[3]}`},"& th, & td":{padding:`${e.spacing.sm} ${e.spacing.sm}`,verticalAlign:"top"}},removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function Mf(e){let{classes:o}=zx(),t=v(),[r,a]=Qx(!1);if(Ux(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=qx(e.original.resourceType);return nr("table",{className:o.root,children:[nr("colgroup",{children:[Ie("col",{style:{width:"30%"}}),Ie("col",{style:{width:"35%"}}),Ie("col",{style:{width:"35%"}})]}),Ie("thead",{children:nr("tr",{children:[Ie("th",{children:"Property"}),Ie("th",{children:"Before"}),Ie("th",{children:"After"})]})}),Ie("tbody",{children:Object.entries(n.elements).map(([l,s])=>{if(l==="id"||l==="meta")return null;let[f,i]=pe(Bf(e.original),l),[u,d]=pe(Bf(e.revised),l);return Af(f)&&Af(u)||kf(f)===kf(u)?null:nr("tr",{children:[Ie("td",{children:Gx(l)}),Ie("td",{className:o.removed,children:Ie(re,{property:s,propertyType:i,value:f,ignoreMissingValues:!0})}),Ie("td",{className:o.added,children:Ie(re,{property:s,propertyType:d,value:u,ignoreMissingValues:!0})})]},l)})})]})}function Af(e){return!e||Array.isArray(e)&&e.length===0||typeof e=="object"&&Object.keys(e).length===0}import{useEffect as Wx,useState as Xx}from"react";import{jsx as Jx}from"react/jsx-runtime";function Na(e){let o=v(),t=G(e.value),[r,a]=Xx(!1);return Wx(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:Jx(st,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as $x,Group as Kx,Menu as Ff,Text as Ha}from"@mantine/core";import{formatDateTime as _x,getReferenceString as Zx}from"@medplum/core";import{Fragment as Yx,jsx as Se,jsxs as Oo}from"react/jsx-runtime";function wf(e){return Se(Xe,{children:e.children})}function $e(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,s=e.dateTime??o.meta?.lastUpdated;return Oo(wo,{"data-testid":"timeline-item",fill:!0,...n,children:[Oo(Kx,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Se(le,{value:l,link:!0,size:"md"}),Oo("div",{style:{flex:1},children:[Se(Ha,{size:"sm",children:Se(Ae,{color:"dark",weight:500,value:l,link:!0})}),Oo(Ha,{size:"xs",children:[Se(j,{color:"dimmed",to:e.resource,children:_x(s)}),Se(Ha,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Se(j,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&Oo(Ff,{position:"bottom-end",shadow:"md",width:200,children:[Se(Ff.Target,{children:Se($x,{radius:"xl","aria-label":`Actions for ${Zx(e.resource)}`,children:Se(ra,{})})}),a]})]}),Oo(vo,{children:[r&&Se("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Se(Yx,{children:e.children})]})]})}function Lf(e,o){e.sort((t,r)=>{let a=Of(t,o),n=Of(r,o);return a>n?1:a<n?-1:Ef(t,o)-Ef(r,o)})}function Of(e,o){if(!Nf(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Ef(e,o){if(!Nf(e,o)){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 t=e.meta?.lastUpdated;return t?new Date(t).getTime():0}function Nf(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as xI,jsx as P,jsxs as Ct}from"react/jsx-runtime";var fI=eI(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function Ke(e){let o=v(),t=Ue(),r=o.getProfile(),a=qf(null),n=G(e.value),[l,s]=Gf(),[f,i]=Gf([]),u=e.loadTimelineResources,d=qf(f);d.current=f;let c=fr(g=>{Lf(g,n),g.reverse(),i(g)},[n]),x=fr(g=>{let L=[];for(let ke of g){if(ke.status!=="fulfilled")continue;let h=ke.value;if(h.type==="history"&&s(h),h.entry)for(let H of h.entry)L.push(H.resource)}c(L)},[c]),C=fr(g=>c([...d.current,g]),[c]),I=fr(()=>{let g,L;"resourceType"in e.value?(g=e.value.resourceType,L=e.value.id):[g,L]=e.value.reference?.split("/"),u(o,g,L).then(x).catch(console.log)},[o,e.value,u,x]);lI(()=>I(),[I]);function R(g){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,g)).then(L=>C(L)).catch(console.log)}function D(g){!n||!e.createMedia||o.createResource(e.createMedia(n,r,g)).then(L=>C(L)).then(()=>lr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:P(et,{size:16}),autoClose:2e3})).catch(L=>lr({id:"upload-notification",color:"red",title:"Upload error",message:Vf(L),icon:P(Ot,{size:16}),autoClose:2e3}))}function b(g,L){return o.updateResource({...g,priority:L})}function T(g){b(g,"stat").then(I).catch(console.log)}function Q(g){b(g,"routine").then(I).catch(console.log)}function y(g){t(`/${g.resourceType}/${g.id}`)}function w(g){t(`/${g.resourceType}/${g.id}/edit`)}function $(g){t(`/${g.resourceType}/${g.id}/delete`)}function Z(g){t(`/${g.resourceType}/${g.id}/_history/${g.meta?.versionId}`)}function Fe(){nI({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function je(g){lr({id:"upload-notification",loading:!0,title:"Uploading...",message:pI(g),autoClose:!1,withCloseButton:!1})}function te(g){lr({id:"upload-notification",color:"red",title:"Upload error",message:Vf(g),icon:P(Ot,{size:16}),autoClose:2e3})}return n?Ct(wf,{children:[e.createCommunication&&P(wo,{children:P(W,{testid:"timeline-form",onSubmit:g=>{R(g.text);let L=a.current;L&&(L.value="",L.focus())},children:Ct(oI,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[P(le,{value:r}),P(aI,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),P(Hf,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:P(ia,{size:16})}),P(Bo,{onUpload:D,onUploadStart:Fe,onUploadProgress:je,onUploadError:te,children:g=>P(Hf,{...g,radius:"xl",color:"blue",variant:"filled",children:P(ot,{size:16})})})]})})}),f.map(g=>{if(!g)return null;let L=`${g.resourceType}/${g.id}/${g.meta?.versionId}`;if(g.resourceType===n.resourceType&&g.id===n.id)return P(sI,{history:l,resource:g,onDetails:Z},L);switch(g.resourceType){case"AuditEvent":return P(dI,{resource:g,onDetails:y},L);case"Communication":return P(uI,{resource:g,onPin:g.priority!=="stat"?T:void 0,onUnpin:g.priority==="stat"?Q:void 0,onDetails:y,onEdit:w,onDelete:$},L);case"DiagnosticReport":return P(mI,{resource:g,onDetails:y,onEdit:w,onDelete:$},L);case"Media":return P(cI,{resource:g,onDetails:y,onEdit:w,onDelete:$},L);default:return P($e,{resource:g,padding:!0,children:P(Na,{value:g,ignoreMissingValues:!0})},L)}})]}):P(jx,{style:{width:"100%",height:"100%"},children:P(tI,{})})}function Eo(e){return Ct(He.Dropdown,{children:[P(He.Label,{children:"Resource"}),e.onPin&&P(He.Item,{icon:P(ua,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${ht(e.resource)}`,children:"Pin"}),e.onUnpin&&P(He.Item,{icon:P(ca,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${ht(e.resource)}`,children:"Unpin"}),e.onDetails&&P(He.Item,{icon:P(fa,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${ht(e.resource)}`,children:"Details"}),e.onEdit&&P(He.Item,{icon:P(aa,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${ht(e.resource)}`,children:"Edit"}),e.onDelete&&Ct(xI,{children:[P(He.Divider,{}),P(He.Label,{children:"Danger zone"}),P(He.Item,{color:"red",icon:P(at,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${ht(e.resource)}`,children:"Delete"})]})]})}function sI(e){let o=iI(e.history,e.resource);return o?P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(Mf,{original:o,revised:e.resource})}):Ct($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:[P("h3",{children:"Created"}),P(Na,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function iI(e,o){let t=e.entry,r=t.findIndex(a=>a.resource?.meta?.versionId===o.meta?.versionId);if(!(r>=t.length-1))return t[r+1].resource}function uI(e){let{classes:o}=fI(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return P($e,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:P(Eo,{...e}),children:P("p",{children:e.resource.payload?.[0]?.contentString})})}function cI(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return P($e,{resource:e.resource,padding:!!t,popupMenuItems:P(Eo,{...e}),children:P(Be,{value:e.resource.content})})}function dI(e){return P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(rI,{children:P("pre",{children:e.resource.outcomeDesc})})})}function mI(e){return P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(La,{value:e.resource})})}function pI(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Va(e.loaded)} / ${Va(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Va(e.loaded)}`}function Va(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as II}from"react/jsx-runtime";function JF(e){return II(Ke,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as Uf}from"react/jsx-runtime";function sr(e){let{children:o,...t}=e;return Uf(Xe,{children:Uf(wo,{...t,children:o})})}import{createReference as ir}from"@medplum/core";import{jsx as gI}from"react/jsx-runtime";function nw(e){return gI(Ke,{value:e.encounter,loadTimelineResources:async(o,t,r)=>Promise.allSettled([o.readHistory("Encounter",r),o.search("Communication","encounter=Encounter/"+r),o.search("Media","encounter=Encounter/"+r)]),createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",encounter:ir(o),subject:o.subject,sender:ir(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:ir(o),subject:o.subject,operator:ir(t),issued:new Date().toISOString(),content:r})})}import{Button as Lg,Loader as Ng,Table as Hg}from"@mantine/core";import{normalizeOperationOutcome as Vg}from"@medplum/core";import{memo as qg,useEffect as Rs,useRef as bs,useState as gr}from"react";import{evalFhirPath as hI}from"@medplum/core";import{jsx as CI}from"react/jsx-runtime";function Qf(e){let o;try{o=hI(e.path,e.resource)}catch(t){return console.warn("FhirPathDisplay:",t),null}if(o.length>1)throw new Error(`Component "path" for "FhirPathDisplay" must resolve to a single element. Received ${o.length} elements [${JSON.stringify(o,null,2)}]`);return CI(re,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as Cg,Button as qo,Center as xr,createStyles as yg,Group as Ir,Loader as vg,Menu as ys,Pagination as Sg,Table as Rg,Text as _a,UnstyledButton as bg}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as en,formatSearchQuery as Pg}from"@medplum/core";import{memo as Dg,useCallback as vs,useEffect as Ss,useRef as Tg,useState as Za}from"react";import{Box as yI,Button as vI,Modal as SI,Text as RI}from"@mantine/core";import{jsx as ur,jsxs as Wf}from"react/jsx-runtime";function Xf(e){return Wf(SI,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Wf(yI,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&ur(zf,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&ur(zf,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),ur(RI,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function zf(e){return ur(vI,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as OI,Group as EI,Modal as LI,MultiSelect as NI,Stack as HI}from"@mantine/core";import{getDataType as VI,getSearchParameters as qI,stringify as GI}from"@medplum/core";import{useEffect as UI,useMemo as QI,useRef as zI,useState as fs}from"react";import{capitalize as bI,DEFAULT_SEARCH_COUNT as PI,evalFhirPathTyped as DI,formatDateTime as TI,Operator as A}from"@medplum/core";import{Fragment as wI,jsx as qa}from"react/jsx-runtime";var kI={string:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],fulltext:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],token:[A.EQUALS,A.NOT],reference:[A.EQUALS,A.NOT],numeric:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],quantity:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],date:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY],datetime:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY]},BI={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",contains:"contains",exact:"exact",text:"text",not:"not",above:"above",below:"below",in:"in","not-in":"not in","of-type":"of type",missing:"missing",identifier:"identifier",iterate:"iterate"};function yt(e,o){return{...e,filters:o,offset:0,name:void 0}}function vw(e){return yt(e,[])}function cr(e,o){return yt(e,(e.filters??[]).filter(t=>t.code!==o))}function Lo(e,o,t,r,a){a&&(e=cr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),yt(e,n)}function Sw(e,o){if(e.fields?.includes(o))return e;let t=[];return e.fields&&t.push(...e.fields),t.push(o),{...e,fields:t,name:void 0}}function $f(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function Kf(e,o){return Ga(e,o,-1)}function _f(e,o){return Ga(e,o,0)}function Zf(e,o){return Ga(e,o,1)}function Ga(e,o,t){let r=new Date;r.setDate(r.getDate()+t),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setDate(a.getDate()+1),a.setTime(a.getTime()-1),Qa(e,o,r,a)}function Yf(e,o){return Ua(e,o,-1)}function jf(e,o){return Ua(e,o,0)}function es(e,o){return Ua(e,o,1)}function Ua(e,o,t){let r=new Date;r.setMonth(r.getMonth()+t),r.setDate(1),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setMonth(a.getMonth()+1),a.setDate(1),a.setHours(0,0,0,0),a.setTime(a.getTime()-1),Qa(e,o,r,a)}function os(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Qa(e,o,t,new Date)}function Qa(e,o,t,r){return e=cr(e,o),e=Jf(e,o,A.GREATER_THAN_OR_EQUALS,t),e=Jf(e,o,A.LESS_THAN_OR_EQUALS,r),e}function Jf(e,o,t,r){return Lo(e,o,t,r.toISOString())}function za(e,o,t=!0){return Lo(e,o,A.MISSING,t.toString())}function AI(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function ts(e,o){let t=e.count??PI,r=(o-1)*t;return AI(e,r)}function Wa(e,o,t){return o===rs(e)&&t!==void 0&&t===as(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function Rw(e,o){let t=!1;return rs(e)===o&&(t=!as(e)),Wa(e,o,t)}function rs(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function as(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function ns(e){return kI[e.type]}function vt(e){return BI[e]??""}function Re(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(bI).join(" "))}function ls(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?TI(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?MI(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?FI(e,o.searchParams[0]):null}function MI(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=pe({type:e.resourceType,value:e},t);return r?qa(re,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function FI(e,o){let t=DI(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:qa(wI,{children:t.map((r,a)=>qa(re,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as St,jsxs as XI}from"react/jsx-runtime";function ss(e){let o=zI(!1),[t,r]=fs({search:JSON.parse(GI(e.search))}),[a,n]=fs(!1);UI(()=>{r({search:e.search})},[e.search]);let l=QI(()=>{if(!e.visible)return[];let f=e.search.resourceType,i=VI(f),u=qI(f);return WI(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:Re(d)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function s(f){r({search:{...t.search,fields:f}})}return St(LI,{title:"Fields",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>{e.onCancel()},size:"auto",withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{o.current=a},onClick:()=>{o.current||e.onCancel(),o.current=!1},children:St("div",{"data-testid":"overlay-child"})},children:XI(HI,{children:[St(NI,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:l,value:t.search.fields??[],onChange:s,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),St(EI,{position:"right",children:St(OI,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function WI(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(Re(n));if(o)for(let n of Object.keys(o)){let l=Re(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as Rt,Group as eg,Modal as og,NativeSelect as cs}from"@mantine/core";import{getSearchParameters as tg,stringify as ds}from"@medplum/core";import{useEffect as rg,useRef as ps,useState as $a}from"react";import{formatDateTime as JI,getSearchParameterDetails as $I,globalSchema as KI,Operator as is,SearchParameterType as _I}from"@medplum/core";import{Fragment as us,jsx as Xa}from"react/jsx-runtime";function dr(e){let{resourceType:o,filter:t}=e,r=KI.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===is.EQUALS||t.operator===is.NOT_EQUALS))return Xa(Ae,{value:{reference:t.value}});let a=$I(o,r);if(t.code==="_lastUpdated"||a.type===_I.DATETIME)return Xa(us,{children:JI(t.value)})}return Xa(us,{children:t.value})}import{Checkbox as ZI,TextInput as Ja}from"@mantine/core";import{getSearchParameterDetails as YI,SearchParameterType as No}from"@medplum/core";import{jsx as fo}from"react/jsx-runtime";function mr(e){let o=YI(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case No.REFERENCE:return fo(Fo,{name:t,defaultValue:e.defaultValue?{reference:e.defaultValue}:void 0,targetTypes:e.searchParam.target,autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(r.reference):e.onChange("")}});case No.BOOLEAN:return fo(ZI,{name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultChecked:e.defaultValue==="true",autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.checked.toString())});case No.DATE:return fo(Ja,{type:"date",name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value)});case No.DATETIME:return fo(De,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case No.NUMBER:return fo(Ja,{type:"number",name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value)});case No.QUANTITY:return fo(ye,{name:t,defaultValue:jI(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return fo(Ja,{name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value),placeholder:"Search value"})}}function jI(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as q,jsxs as Ve}from"react/jsx-runtime";function xs(e){let[o,t]=$a(JSON.parse(ds(e.search))),[r,a]=$a(-1),n=ps(o);n.current=o,rg(()=>{t(JSON.parse(ds(e.search)))},[e.search]);function l(u){t(Lo(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let s=e.search.resourceType,f=tg(s)??{},i=o.filters||[];return Ve(og,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[q("div",{children:Ve("table",{children:[Ve("colgroup",{children:[q("col",{style:{width:200}}),q("col",{style:{width:200}}),q("col",{style:{width:380}}),q("col",{style:{width:120}})]}),q("thead",{children:Ve("tr",{children:[q("th",{children:"Field"}),q("th",{children:"Operation"}),q("th",{children:"Value"}),q("th",{children:"Actions"})]})}),Ve("tbody",{children:[i.map((u,d)=>d===r?q(ms,{resourceType:s,searchParams:f,defaultValue:u,okText:"Save",onOk:c=>{let x=[...i];x[d]=c,t(yt(n.current,x)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):q(ag,{resourceType:s,searchParams:f,filter:u,onEdit:()=>a(d),onDelete:()=>t($f(n.current,d))},`filter-${u.code}-${u.operator}-${u.value}-display`)),q(ms,{resourceType:s,searchParams:f,okText:"Add",onOk:l})]})]})}),q(eg,{position:"right",mt:"xl",children:q(Rt,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function ag(e){let{filter:o}=e;return Ve("tr",{children:[q("td",{children:Re(o.code)}),q("td",{children:vt(o.operator)}),q("td",{children:q(dr,{resourceType:e.resourceType,filter:o})}),Ve("td",{children:[q(Rt,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),q(Rt,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function ms(e){let[o,t]=$a(e.defaultValue??{}),r=ps(o);r.current=o;function a(i){t({...r.current,code:i})}function n(i){t({...r.current,operator:i})}function l(i){t({...r.current,value:i})}let s=e.searchParams[o.code],f=s&&ns(s);return Ve("tr",{children:[q("td",{children:q(cs,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:Re(i)}))]})}),q("td",{children:f&&q(cs,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...f.map(i=>({value:i,label:vt(i)}))]})}),q("td",{children:s&&o.operator&&q(mr,{resourceType:e.resourceType,searchParam:s,defaultValue:o.value,onChange:l})}),Ve("td",{children:[o.code&&o.operator&&q(Rt,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&q(Rt,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as ng,Grid as Ka,Modal as lg}from"@mantine/core";import{useState as fg}from"react";import{jsx as Ho,jsxs as sg}from"react/jsx-runtime";function Is(e){let[o,t]=fg(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return Ho(lg,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:Ho(W,{onSubmit:r,children:sg(Ka,{children:[Ho(Ka.Col,{span:10,children:Ho(mr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),Ho(Ka.Col,{span:2,children:Ho(ng,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as k}from"@mantine/core";import{Operator as ee}from"@medplum/core";import{Fragment as hs,jsx as p,jsxs as Vo}from"react/jsx-runtime";function gs(e){if(!e.searchParams)return null;function o(n,l){a(Wa(e.search,n.code,l))}function t(n){a(cr(e.search,n.code))}function r(n,l){e.onPrompt(n,{code:n.code,operator:l,value:""})}function a(n){e.onChange(n)}return e.searchParams.length===1?p(ig,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):p(k.Dropdown,{children:e.searchParams.map(n=>p(k.Item,{children:Re(n.code)},n.code))})}function ig(e){switch(e.searchParam.type){case"date":return p(ug,{...e});case"number":case"quantity":return p(cg,{...e});case"reference":return p(dg,{...e});case"string":case"token":case"uri":return p(mg,{...e});default:return Vo(hs,{children:["Unknown search param type: ",e.searchParam.type]})}}function ug(e){let{searchParam:o}=e,t=o.code;return Vo(k.Dropdown,{children:[p(k.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),p(k.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),p(k.Divider,{}),p(k.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(k.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT_EQUALS),children:"Does not equal..."}),p(k.Divider,{}),p(k.Item,{icon:p(Lt,{size:14}),onClick:()=>e.onPrompt(o,ee.ENDS_BEFORE),children:"Before..."}),p(k.Item,{icon:p(Et,{size:14}),onClick:()=>e.onPrompt(o,ee.STARTS_AFTER),children:"After..."}),p(k.Item,{icon:p(Kr,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Between..."}),p(k.Divider,{}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(Zf(e.search,t)),children:"Tomorrow"}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(_f(e.search,t)),children:"Today"}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(Kf(e.search,t)),children:"Yesterday"}),p(k.Divider,{}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(es(e.search,t)),children:"Next Month"}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(jf(e.search,t)),children:"This Month"}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(Yf(e.search,t)),children:"Last Month"}),p(k.Divider,{}),p(k.Item,{icon:p(Oe,{size:14}),onClick:()=>e.onChange(os(e.search,t)),children:"Year to date"}),p(pr,{...e})]})}function cg(e){let{searchParam:o}=e;return Vo(k.Dropdown,{children:[p(k.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),p(k.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),p(k.Divider,{}),p(k.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(k.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT_EQUALS),children:"Does not equal..."}),p(k.Divider,{}),p(k.Item,{icon:p(Et,{size:14}),onClick:()=>e.onPrompt(o,ee.GREATER_THAN),children:"Greater than..."}),p(k.Item,{icon:p(yo,{size:14}),onClick:()=>e.onPrompt(o,ee.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),p(k.Item,{icon:p(Lt,{size:14}),onClick:()=>e.onPrompt(o,ee.LESS_THAN),children:"Less than..."}),p(k.Item,{icon:p(yo,{size:14}),onClick:()=>e.onPrompt(o,ee.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),p(pr,{...e})]})}function dg(e){let{searchParam:o}=e;return Vo(k.Dropdown,{children:[p(k.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(k.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT),children:"Does not equal..."}),p(pr,{...e})]})}function mg(e){let{searchParam:o}=e;return Vo(k.Dropdown,{children:[p(k.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),p(k.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),p(k.Divider,{}),p(k.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(k.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT),children:"Does not equal..."}),p(k.Divider,{}),p(k.Item,{icon:p(Zr,{size:14}),onClick:()=>e.onPrompt(o,ee.CONTAINS),children:"Contains..."}),p(k.Item,{icon:p(_r,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Does not contain..."}),p(pr,{...e})]})}function pr(e){let{searchParam:o}=e,t=o.code;return Vo(hs,{children:[p(k.Divider,{}),p(k.Item,{icon:p(Jr,{size:14}),onClick:()=>e.onChange(za(e.search,t)),children:"Missing"}),p(k.Item,{icon:p(Xr,{size:14}),onClick:()=>e.onChange(za(e.search,t,!1)),children:"Not missing"}),p(k.Divider,{}),p(k.Item,{icon:p(ha,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as pg,getSearchParameter as xg,getSearchParameterDetails as Ig,getSearchParameters as gg}from"@medplum/core";function Cs(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(hg(o,r));return t}function hg(e,o){if(o==="_lastUpdated")return{name:"_lastUpdated",searchParams:[{resourceType:"SearchParameter",base:["Resource"],code:"_lastUpdated",name:"_lastUpdated",type:"date",expression:"Resource.meta.lastUpdated"}]};if(o==="meta.versionId")return{name:"meta.versionId",searchParams:[{resourceType:"SearchParameter",base:["Resource"],code:"_versionId",name:"_versionId",type:"token",expression:"Resource.meta.versionId"}]};let t=pg(e,o),r=xg(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=gg(e),n;if(a){let l=new RegExp(`${e}\\.${o.replaceAll("[x]","")}([^\\w-]|$)`);n=Object.values(a).filter(s=>!!s.expression&&l.test(s?.expression)),n.length===0&&(n=void 0)}return{name:o,elementDefinition:t,searchParams:n}}if(r){let a=Ig(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as Eg,jsx as B,jsxs as ge}from"react/jsx-runtime";var Ya=class extends Event{constructor(t){super("change");this.definition=t}},ja=class extends Event{constructor(t){super("load");this.response=t}},so=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},kg=yg(e=>({root:{maxWidth:"100%",overflow:"auto",textAlign:"left",marginBottom:"20px"},table:{cursor:"pointer"},tr:{"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[7]:e.colors.gray[0]}},th:{padding:"0 !important"},control:{width:"100%",padding:`${e.spacing.xs} ${e.spacing.md}`,"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[6]:e.colors.gray[0]}},icon:{width:21,height:21,borderRadius:21}}));function Bg(e){let{classes:o}=kg(),t=v(),[r,a]=Za(!1),[n,l]=Za(),{search:s,onLoad:f}=e,[i,u]=Za({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),d=Tg(i);d.current=i;let c=s.total??"accurate",x=vs(h=>{l(void 0),t.search(s.resourceType,Pg({...s,total:c,fields:void 0}),h).then(H=>{u({...d.current,searchResponse:H}),f&&f(new ja(H))}).catch(H=>{u({...d.current,searchResponse:void 0}),l(H)})},[t,s,c,f]),C=vs(()=>{u({...d.current,searchResponse:void 0}),x({cache:"reload"})},[x]);Ss(()=>{x()},[x]);function I(h,H){h.stopPropagation();let Y=h.target.checked,_={...d.current.selected};Y?_[H]=!0:delete _[H],u({...d.current,selected:_})}function R(h){h.stopPropagation();let we=h.target.checked,Y={},_=d.current.searchResponse;we&&_?.entry&&_.entry.forEach(he=>{he.resource?.id&&(Y[he.resource.id]=!0)}),u({...d.current,selected:Y})}function D(){let h=d.current;if(!h.searchResponse?.entry||h.searchResponse.entry.length===0)return!1;for(let H of h.searchResponse.entry)if(H.resource?.id&&!h.selected[H.resource.id])return!1;return!0}function b(h){e.onChange&&e.onChange(new Ya(h))}function T(h,H){if(Ht(h.target)||h.button===2)return;O(h);let we=h.button===1||h.ctrlKey||h.metaKey;!we&&e.onClick&&e.onClick(new so(H,h)),we&&e.onAuxClick&&e.onAuxClick(new so(H,h))}function Q(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(Ss(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return B(xr,{style:{width:"100%",height:"100%"},children:B(vg,{})});let y=e.checkboxesEnabled,w=Cs(s),$=s.resourceType,Z=i.searchResponse,je=Z?.entry?.map(h=>h.resource),te="subtle",g="gray",L=16,ke=window.innerWidth<768;return ge("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&ge(Ir,{position:"apart",mb:"xl",children:[ge(Ir,{spacing:2,children:[B(qo,{compact:!0,variant:te,color:g,leftIcon:B(ea,{size:L}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),B(qo,{compact:!0,variant:te,color:g,leftIcon:B(la,{size:L}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(na,{size:L}),onClick:e.onNew,children:"New..."}),!ke&&Q()&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(ga,{size:L}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!ke&&e.onDelete&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(at,{size:L}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!ke&&e.onBulk&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B($r,{size:L}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),ge(Ir,{spacing:2,children:[Z&&ge(_a,{size:"xs",color:"dimmed",children:[wg(s,Z.total),"-",Og(s,Z.total)," of"," ",`${c==="estimate"?"~":""}${Z.total?.toLocaleString()}`]}),B(Cg,{title:"Refresh",onClick:C,children:B(ma,{size:"1.125rem"})})]})]}),ge(Rg,{className:o.table,children:[ge("thead",{children:[ge("tr",{children:[y&&B("th",{children:B("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:D(),onChange:h=>R(h)})}),w.map(h=>B("th",{children:ge(ys,{shadow:"md",width:240,position:"bottom-end",children:[B(ys.Target,{children:B(bg,{className:o.control,children:ge(Ir,{position:"apart",noWrap:!0,children:[B(_a,{weight:500,size:"sm",children:Re(h.name)}),B(xr,{className:o.icon,children:B(Qr,{size:14,stroke:1.5})})]})})}),B(gs,{search:e.search,searchParams:h.searchParams,onPrompt:(H,we)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:we})},onChange:H=>{b(H)}})]})},h.name))]}),!e.hideFilters&&ge("tr",{children:[y&&B("th",{}),w.map(h=>B("th",{children:h.searchParams&&B(Ag,{resourceType:$,searchParams:h.searchParams,filters:e.search.filters})},h.name))]})]}),B("tbody",{children:je?.map(h=>h&&ge("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>T(H,h),onAuxClick:H=>T(H,h),children:[y&&B("td",{children:B("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${h.id}`,checked:!!i.selected[h.id],onChange:H=>I(H,h.id)})}),w.map(H=>B("td",{children:ls(h,H)},H.name))]},h.id))})]}),je?.length===0&&B(Xe,{children:B(xr,{style:{height:150},children:B(_a,{size:"xl",color:"dimmed",children:"No results"})})}),Z?.total!==void 0&&Z.total>0&&B(xr,{m:"md",p:"md",children:B(Sg,{value:Mg(s),total:Fg(s,Z.total),onChange:h=>b(ts(s,h)),getControlProps:h=>{switch(h){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&B("div",{"data-testid":"search-error",children:B("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),B(ss,{search:e.search,visible:d.current.fieldEditorVisible,onOk:h=>{b(h),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),B(xs,{search:e.search,visible:d.current.filterEditorVisible,onOk:h=>{b(h),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),B(Xf,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),B(Is,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?Re(i.filterDialogSearchParam.code):"",resourceType:$,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:h=>{b(Lo(e.search,h.code,h.operator,h.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var qO=Dg(Bg);function Ag(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?B("span",{children:"no filters"}):B(Eg,{children:o.map(t=>ge("div",{children:[vt(t.operator),"\xA0",B(dr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function Mg(e){return Math.floor((e.offset??0)/(e.count??en))+1}function Fg(e,o){let t=e.count??en;return Math.ceil(o/t)}function wg(e,o){return Math.min(o,(e.offset??0)+1)}function Og(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??en))}import{jsx as ce,jsxs as hr}from"react/jsx-runtime";function Gg(e){let o=v(),[t,r]=gr(!1),[a,n]=gr(),{query:l,fields:s}=e,[f,i]=gr(),[u,d]=gr({}),c=bs();c.current=f;let x=bs({});x.current=u,Rs(()=>{n(void 0),o.graphql(l).then(i).catch(T=>n(Vg(T)))},[o,l]);function C(T,Q){T.stopPropagation();let w=T.target.checked,$={...x.current};w?$[Q]=!0:delete $[Q],d($)}function I(T){T.stopPropagation();let y=T.target.checked,w={},$=c.current?.data.ResourceList;y&&$&&$.forEach(Z=>{Z.id&&(w[Z.id]=!0)}),d(w)}function R(){let T=c.current?.data.ResourceList;if(!T||T.length===0)return!1;for(let Q of T)if(Q.id&&!x.current[Q.id])return!1;return!0}function D(T,Q){Ht(T.target)||(O(T),T.button!==1&&e.onClick&&e.onClick(new so(Q,T)),T.button===1&&e.onAuxClick&&e.onAuxClick(new so(Q,T)))}if(Rs(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return ce(Ng,{});let b=e.checkboxesEnabled;return hr("div",{onContextMenu:T=>O(T),"data-testid":"search-control",children:[hr(Hg,{children:[ce("thead",{children:hr("tr",{children:[b&&ce("th",{children:ce("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:R(),onChange:T=>I(T)})}),s.map(T=>ce("th",{children:T.name},T.name))]})}),ce("tbody",{children:f?.data.ResourceList.map(T=>T&&hr("tr",{"data-testid":"search-control-row",onClick:Q=>D(Q,T),onAuxClick:Q=>D(Q,T),children:[b&&ce("td",{children:ce("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${T.id}`,checked:!!u[T.id],onChange:Q=>C(Q,T.id)})}),s.map(Q=>ce("td",{children:ce(Qf,{propertyType:Q.propertyType,path:Q.fhirPath,resource:T})},Q.name))]},T.id))})]}),f?.data.ResourceList.length===0&&ce("div",{"data-testid":"empty-search",children:"No results"}),a&&ce("div",{"data-testid":"search-error",children:ce("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&ce(Lg,{onClick:()=>e.onBulk(Object.keys(x.current)),children:"Bulk..."})]})}var YO=qg(Gg);import{jsx as Go,jsxs as Ug}from"react/jsx-runtime";function _e(e){return Ug("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Go("title",{children:"Medplum Logo"}),Go("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Go("path",{fill:e.fill??"#946af9",d:"M311 63c-17 0-33 4-48 11-16-7-32-11-49-11-87 0-158 96-158 214s71 214 158 214c17 0 33-4 49-11 15 7 31 11 48 11 87 0 158-96 158-214S398 63 311 63z"}),Go("path",{fill:e.fill??"#7857c5",d:"M231 489l-17 2c-87 0-158-96-158-214S127 63 214 63l17 1c-39 12-70 102-70 213s31 201 70 212z"}),Go("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Go("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as $g,SimpleGrid as Kg}from"@mantine/core";import{Box as Ps,Flex as on,Group as Qg,Paper as zg,RingProgress as Ts,Text as io,Title as tn}from"@mantine/core";import{formatCodeableConcept as Ds}from"@medplum/core";import{Fragment as Ms,jsx as K,jsxs as bt}from"react/jsx-runtime";function ks(e){let{group:o}=e;return K(zg,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:bt(Qg,{children:[o.measureScore&&K(Xg,{group:o}),!o.measureScore&&K(Wg,{group:o})]})})}function Bs(e){let{measure:o}=e;return bt(Ms,{children:[K(io,{fz:"md",fw:500,mb:8,children:o.title}),K(io,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function Wg(e){let{group:o}=e,t=o.population,r=t?.find(f=>Ds(f.code)==="numerator"),a=t?.find(f=>Ds(f.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return bt(Ps,{children:[K(tn,{order:3,children:"Not Applicable"}),K(io,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return bt(Ps,{children:[K(tn,{order:3,children:"Insufficient Data"}),K(io,{children:`Numerator: ${n}`}),K(io,{children:`Denominator: ${l}`})]});let s=n/l*100;return K(Ts,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:As(s)}],label:K(on,{justify:"center",children:bt(io,{fw:700,fz:18,children:[n," / ",l]})})})}function Xg(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return K(Ms,{children:t==="%"?K(Ts,{size:120,thickness:12,roundCaps:!0,sections:[{value:Jg(o),color:As(o?.measureScore?.value??0)}],label:K(on,{justify:"center",children:K(io,{fw:700,fz:18,children:K(We,{value:o.measureScore})})})}):K(on,{h:120,align:"center",children:K(tn,{order:3,children:K(We,{value:o.measureScore})})})})}function Jg(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function As(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as rn,jsxs as _g}from"react/jsx-runtime";function cE(e){let o=G(e.measureReport),[t]=Hn("Measure",{url:o?.measure});return o?_g($g,{children:[t&&rn(Bs,{measure:t}),rn(Kg,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>rn(ks,{group:r},r.id??a))})]}):null}import{Alert as Zg}from"@mantine/core";import{operationOutcomeIssueToString as Yg}from"@medplum/core";import{jsx as an}from"react/jsx-runtime";function Uo(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:an(Zg,{icon:an(to,{size:16}),color:"red",children:o.map(t=>an("div",{"data-testid":"text-field-error",children:Yg(t)},t.details?.text))})}import{createReference as Cr}from"@medplum/core";import{useCallback as jg}from"react";import{jsx as eh}from"react/jsx-runtime";function bE(e){let o=jg((t,r,a)=>{let n=`${r}/${a}`,l=100;return Promise.allSettled([t.readHistory("Patient",a),t.search("Communication",{subject:n,_count:l}),t.search("Device",{patient:n,_count:l}),t.search("DeviceRequest",{patient:n,_count:l}),t.search("DiagnosticReport",{subject:n,_count:l}),t.search("Media",{subject:n,_count:l}),t.search("ServiceRequest",{subject:n,_count:l}),t.search("Task",{subject:n,_count:l})])},[]);return eh(Ke,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Cr(t),sender:Cr(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Cr(t),operator:Cr(r),issued:new Date().toISOString(),content:a})})}import{Anchor as ws,Button as oh,createStyles as th,NativeSelect as rh,Stack as ah,TextInput as ln}from"@mantine/core";import{getReferenceString as nh}from"@medplum/core";import{useEffect as Fs,useRef as Os,useState as Pt}from"react";import{jsx as U,jsxs as Qo}from"react/jsx-runtime";var Es=th(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[1]}`,borderRadius:e.radius.sm,transition:"all 0.1s"},hovering:{border:`1.5px solid ${e.colors.blue[5]}`},editing:{border:`1.5px solid ${e.colors.gray[1]}`,borderLeft:`4px solid ${e.colors.blue[5]}`},bottomActions:{position:"absolute",right:4,bottom:0,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}}}));function QE(e){let o=v(),t=G(e.value),[r,a]=Pt(!1),[n,l]=Pt(),[s,f]=Pt(),[i,u]=Pt();function d(){f(void 0)}function c(){l(void 0)}let x=Os();if(x.current=i,Fs(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),Fs(()=>(u(ch(t??{resourceType:"PlanDefinition"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]),!r||!i)return null;function C(I,R){u({...x.current,[I]:R})}return U("div",{children:Qo(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[U(ln,{label:"Plan Title",defaultValue:i.title,onChange:I=>C("title",I.currentTarget.value)}),U(Ls,{actions:i.action||[],selectedKey:n,setSelectedKey:l,hoverKey:s,setHoverKey:f,onChange:I=>C("action",I)}),U(oh,{type:"submit",children:"Save"})]})})}function Ls(e){let{classes:o}=Es(),t=Os();t.current=e.actions;function r(l){e.onChange(t.current.map(s=>s.id===l.id?l:s))}function a(l){e.onChange([...t.current,l]),e.setSelectedKey(l.id)}function n(l){e.onChange(t.current.filter(s=>s!==l))}return Qo("div",{className:o.section,children:[e.actions.map(l=>U("div",{children:U(lh,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),U("div",{className:o.bottomActions,children:U(ws,{href:"#",onClick:l=>{O(l),a({id:Hs()})},children:"Add action"})})]})}function lh(e){let{classes:o,cx:t}=Es(),{action:r}=e,a=uh(r),n=e.selectedKey===e.action.id,l=e.hoverKey===e.action.id;function s(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function f(u){O(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return Qo("div",{"data-testid":r.id,className:i,onClick:s,onMouseOver:f,children:[n?U(sh,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):U(fh,{action:r,actionType:a}),U("div",{className:o.bottomActions,children:U(ws,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var fn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function fh(e){let{action:o,actionType:t}=e,[r,a]=Ns(o);return Qo("div",{children:[Qo("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&U("div",{children:U(lo,{value:{reference:o.definitionCanonical}})}),r&&U("div",{children:U(re,{property:fn,propertyType:a,value:r})})]})}function sh(e){let{action:o}=e,[t,r]=Pt(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return Qo(ah,{spacing:"xl",children:[U(ln,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),U(ln,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),U(rh,{label:"Type of Action",description:"The type of the action to be performed.",name:`actionType-${o.id}`,defaultValue:t,onChange:n=>r(n.currentTarget.value),data:["","appointment","lab","questionnaire","task"]}),o.action&&o.action.length>0&&U(Ls,{actions:o.action,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:n=>a("action",n)}),(()=>{switch(t){case"appointment":return U(yr,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return U(yr,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return U(yr,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return U(yr,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),U(xe,{title:"Timing",description:"When the action should take place.",children:U(ih,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function yr(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return U(er,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:nh(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function ih(e){let o=e.action,t="timing",[r,a]=Ns(o);return U(Ne,{property:fn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(it(o,t,l??t,fn,n))}})}function uh(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function Ns(e){return pe({type:"PlanDefinitionAction",value:e},"timing")}var nn=1;function Hs(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(nn=Math.max(nn,o+1))}return e}return"id-"+nn++}function ch(e){return{...e,action:Vs(e.action)}}function Vs(e){if(e)return e.map(o=>({...o,id:Hs(o.id),action:Vs(o.action)}))}import{Anchor as be,Box as pn,Button as Nh,createStyles as Hh,Group as Vh,NativeSelect as qh,Space as Gh,Textarea as Uh,TextInput as xn,Title as Qh}from"@mantine/core";import{getElementDefinition as zh,isResource as Wh}from"@medplum/core";import{useEffect as ei,useRef as Xh,useState as Pr}from"react";import{Checkbox as Sh,Group as Rh,MultiSelect as bh,NativeSelect as Ph,Radio as $s,Textarea as Dh,TextInput as zo}from"@mantine/core";import{capitalize as dn,deepEquals as Th,formatCodeableConcept as kh,formatCoding as br,getElementDefinition as Bh,getTypedPropertyValue as Ze,stringify as Ks}from"@medplum/core";import{deepClone as dh,evalFhirPathTyped as mh,formatCoding as ph,getExtension as un,getTypedPropertyValue as sn,getReferenceString as xh,stringify as Ih}from"@medplum/core";var vr=(D=>(D.group="group",D.display="display",D.question="question",D.boolean="boolean",D.decimal="decimal",D.integer="integer",D.date="date",D.dateTime="dateTime",D.time="time",D.string="string",D.text="text",D.url="url",D.choice="choice",D.openChoice="open-choice",D.attachment="attachment",D.reference="reference",D.quantity="quantity",D))(vr||{});function qs(e){return e.type==="choice"||e.type==="open-choice"}function Gs(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=Qs(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=hh(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function Us(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>ph(l.valueCoding)===r||l[o]===r),n=sn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Qs(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Qs(t.item,o);if(r)return r}}}function gh(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=mh(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function hh(e,o,t){let r=o||[],a=sn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let s of r){let f=sn({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(gh(f,a,i)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function Sr(e){let o=un(e,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource");if(o){if(o.valueCode!==void 0)return[o.valueCode];if(o.valueCodeableConcept)return o.valueCodeableConcept?.coding?.map(t=>t.code)}}function Rr(e,o){let t=dh(e),r=un(t,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource");return!o||o.length===0?(r&&(t.extension=t.extension?.filter(a=>a!==r)),t):(r||(t.extension||(t.extension=[]),r={url:"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource"},t.extension.push(r)),o.length===1?(r.valueCode=o[0],delete r.valueCodeableConcept):(r.valueCodeableConcept={coding:o.map(a=>({code:a}))},delete r.valueCode),t)}function zs(e){return{resourceType:"QuestionnaireResponse",questionnaire:xh(e),item:Ws(e.item)}}function Ws(e){return e?.map(cn)??[]}function cn(e){return{id:yh(),linkId:e.linkId,text:e.text,item:Ws(e.item),answer:e.initial?.map(vh)??[]}}var Ch=1;function yh(){return"id-"+Ch++}function vh(e){return{...e}}function Xs(e){return e.value.display||e.value.reference||Ih(e.value)}function Js(e){let o=e?.item?.[0];return o&&un(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{jsx as z}from"react/jsx-runtime";function Dt(e){let o=e.item,t=e.response;function r(f){let i;Array.isArray(f)?i=f:e.index>=(e.response?.answer?.length??0)?i=(e.response?.answer??[]).concat([f]):i=(e.response?.answer??[]).map((d,c)=>c===e.index?f:d)??[],e.onChange({id:t?.id,linkId:t?.linkId,text:o.text,answer:i})}let a=o.type;if(!a)return null;let n=o.linkId;if(!n)return null;let l=o.initial&&o.initial.length>0?o.initial[0]:void 0,s=mn(t,e.index)??Ze({type:"QuestionnaireItemInitial",value:l},"value");switch(a){case"display":return z("p",{children:e.item.text},e.item.linkId);case"boolean":return z(Kt,{title:e.item.text,htmlFor:e.item.linkId,children:z(Sh,{id:e.item.linkId,name:e.item.linkId,defaultChecked:s?.value,onChange:f=>r({valueBoolean:f.currentTarget.checked})})},e.item.linkId);case"decimal":return z(zo,{type:"number",step:"any",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDecimal:f.currentTarget.valueAsNumber})});case"integer":return z(zo,{type:"number",step:1,id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueInteger:f.currentTarget.valueAsNumber})});case"date":return z(zo,{type:"date",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDate:f.currentTarget.value})});case"dateTime":return z(De,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDateTime:f})});case"time":return z(zo,{type:"time",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueTime:f.currentTarget.value})});case"string":case"url":return z(zo,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"text":return z(Dh,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"attachment":return z(Rh,{py:4,children:z(Ut,{name:n,defaultValue:s?.value,onChange:f=>r({valueAttachment:f})})});case"reference":return z(Fo,{name:n,required:o.required,targetTypes:Sr(o),defaultValue:s?.value,onChange:f=>r({valueReference:f})});case"quantity":return z(ye,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueQuantity:f}),disableWheel:!0});case"choice":case"open-choice":return Eh(o)&&!o.answerValueSet?z(Ah,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)}):z(Mh,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)});default:return null}}function Ah(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return z(Ys,{});let n=Ze({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let f of t.answerOption){let i=Ze({type:"QuestionnaireItemAnswerOption",value:f},"value");l.push(_s(i))}let s=mn(a)??n;if(t.repeats){let{propertyName:f,data:i}=Lh(e.item),u=wh(a);return z(bh,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[_s(n)],onChange:d=>{let c=Us(d,f,t);e.onChangeAnswer(c)}})}return z(Ph,{id:o,name:o,onChange:f=>{let i=f.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],d=Ze({type:"QuestionnaireItemAnswerOption",value:u},"value"),c="value"+dn(d.type);e.onChangeAnswer({[c]:d.value})},defaultValue:br(s?.value)||s?.value,data:l})}function Mh(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?z(Ys,{}):t.answerValueSet?z(Zt,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):z(Fh,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Fh(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Bh("QuestionnaireItemAnswerOption","value[x]"),s=Ze({type:"QuestionnaireItemInitial",value:r},"value"),f=[],i;if(t.answerOption)for(let c=0;c<t.answerOption.length;c++){let x=t.answerOption[c],C=`${o}-option-${c}`,I=Ze({type:"QuestionnaireItemAnswerOption",value:x},"value");s&&Ks(I)===Ks(s)&&(i=C),f.push([C,I])}let u=mn(n),d=Oh(f,u);return z($s.Group,{name:o,value:d??i,onChange:c=>{let x=f.find(C=>C[0]===c);if(x){let C=x[1],I="value"+dn(C.type);a({[I]:C.value})}},children:f.map(([c,x])=>z($s,{id:c,value:c,py:4,label:z(re,{property:l,propertyType:x.type,value:x.value})},c))})}function Ys(){return z(zo,{disabled:!0,placeholder:"No Answers Defined"})}function js(e){return Ze({type:"QuestionnaireItemAnswer",value:e},"value")}function mn(e,o=0){let t=e.answer;return js(t?.[o]??{})}function wh(e){let o=e.answer;return o?o.map(r=>js(r)).map(r=>br(r?.value)||r?.value):[]}function Oh(e,o){return e.find(t=>Th(t[1].value,o?.value))?.[0]}function _s(e){if(e)return e.type==="CodeableConcept"?kh(e.value):e.type==="Coding"?br(e.value):e.type==="Reference"?Xs(e):e.value.toString()}function Eh(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Lh(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=Ze({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+dn(t.type),a=(e.answerOption??[]).map(n=>({value:Zs(n,r),label:Zs(n,r)}));return{propertyName:r,data:a}}function Zs(e,o){return br(e.valueCoding)||e[o]?.toString()}import{Fragment as Wo,jsx as M,jsxs as de}from"react/jsx-runtime";var Jh=Hh(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[1]}`,borderRadius:e.radius.sm,transition:"all 0.1s"},hovering:{border:`1.5px solid ${e.colors.blue[5]}`},editing:{border:`1.5px solid ${e.colors.gray[1]}`,borderLeft:`4px solid ${e.colors.blue[5]}`},questionBody:{maxWidth:600},topActions:{position:"absolute",right:32,top:1,padding:4,color:e.colors.gray[5],fontSize:e.fontSizes.xs},bottomActions:{position:"absolute",right:4,bottom:0,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}},movementActions:{position:"absolute",right:8,top:0,paddingTop:8,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}},movementIcons:{color:e.colors.gray[5]},columnAlignment:{display:"flex",flexDirection:"column"},linkIdInput:{width:100,marginBottom:4},typeSelect:{width:100}}));function S0(e){let o=v(),t=G(e.questionnaire),[r,a]=Pr(!1),[n,l]=Pr(),[s,f]=Pr(),[i,u]=Pr();function d(){u(void 0)}function c(){f(void 0)}return ei(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),ei(()=>(l(Zh(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]),!r||!n?null:M("div",{children:de(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[M(oi,{item:n,selectedKey:s,setSelectedKey:f,hoverKey:i,setHoverKey:u,onChange:l}),M(Nh,{type:"submit",children:"Save"})]})})}function oi(e){let{classes:o,cx:t}=Jh(),r=e.item,a=e.item,n=Wh(e.item),l=n||a.type==="group",s=a.linkId??"[untitled]",f=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=Xh();u.current=e.item;function d(y){O(y),e.setSelectedKey(e.item.id)}function c(y){O(y),e.setHoverKey(e.item.id)}function x(y){let w=u.current;e.onChange({...w,item:w.item?.map($=>$.id===y.id?y:$)})}function C(y){e.onChange({...e.item,item:[...e.item.item??[],y]})}function I(y){e.onChange({...e.item,item:e.item.item?.filter(w=>w!==y)})}function R(y,w){e.onChange({...u.current,[y]:w})}function D(y){e.onChange({...e.item,...y})}function b(y){e.onChange({...e.item,item:e.item.item?.map(w=>w===y?{...w,repeats:!w.repeats}:w)})}function T(y,w){let $=eC(e.item.item,y,w);e.onChange({...e.item,item:$})}let Q=t(o.section,{[o.editing]:f,[o.hovering]:i&&!f});return de("div",{"data-testid":a.linkId,className:Q,onClick:d,onMouseOver:c,children:[M("div",{className:o.questionBody,children:f?de(Wo,{children:[n&&M(xn,{size:"xl",defaultValue:r.title,onChange:y=>R("title",y.currentTarget.value)}),!n&&M(Uh,{autosize:!0,minRows:2,defaultValue:a.text,onChange:y=>R("text",y.currentTarget.value)}),a.type==="reference"&&M(_h,{item:a,onChange:D}),qs(a)&&M($h,{item:a,onChange:y=>D(y)})]}):de(Wo,{children:[r.title&&M(Qh,{children:r.title}),a.text&&M("div",{children:a.text}),!l&&M(Dt,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((y,w)=>M("div",{children:M(oi,{item:y,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:w===0,isLast:w===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:x,onRemove:()=>I(y),onRepeatable:b,onMoveUp:()=>T(w,-1),onMoveDown:()=>T(w,1)})},y.id)),!l&&M("div",{className:o.topActions,children:f?de(Wo,{children:[M(xn,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onChange:y=>R("linkId",y.currentTarget.value)}),!l&&M(qh,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:y=>R("type",y.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"}]})]}):M("div",{children:s})}),!n&&M(pn,{className:o.movementActions,children:de(pn,{className:o.columnAlignment,children:[!e.isFirst&&M(be,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:M(Wr,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&M(be,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:M(zr,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),de("div",{className:o.bottomActions,children:[l&&de(Wo,{children:[M(be,{href:"#",onClick:y=>{y.preventDefault(),C({id:uo(),linkId:hn("q"),type:"string",text:"Question"})},children:"Add item"}),M(be,{href:"#",onClick:y=>{y.preventDefault(),C({id:uo(),linkId:hn("g"),type:"group",text:"Group"})},children:"Add group"})]}),n&&M(be,{href:"#",onClick:y=>{y.preventDefault(),C(jh())},children:"Add Page"}),f&&!n&&de(Wo,{children:[M(be,{href:"#",onClick:y=>{y.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),M(be,{href:"#",onClick:y=>{y.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function $h(e){let o=zh("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return de("div",{children:[e.item.answerValueSet!==void 0?M(xn,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):M(Kh,{options:t,property:o,item:e.item,onChange:e.onChange}),de(pn,{display:"flex",children:[M(be,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:uo()}]})},children:"Add choice"}),M(Gh,{w:"lg"}),M(be,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Kh(e){return M("div",{children:e.options.map(o=>{let[t,r]=pe({type:"QuestionnaireItemAnswerOption",value:o},"value");return de("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[M("div",{children:M(Ne,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let l=[...e.options],s=l.findIndex(f=>f.id===o.id);l[s]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:l})}},o.id)}),M("div",{children:M(be,{href:"#",onClick:a=>{O(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function _h(e){let o=Sr(e.item)??[];return de(Wo,{children:[o.map((t,r)=>de(Vh,{children:[M(ko,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(Rr(e.item,o.map(n=>n===t?a:n)))}}),M(be,{href:"#",onClick:a=>{O(a),e.onChange(Rr(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),M(be,{href:"#",onClick:t=>{O(t),e.onChange(Rr(e.item,[...o,""]))},children:"Add Resource Type"})]})}var In=1,gn=1;function hn(e){return e+In++}function uo(){return"id-"+gn++}function Zh(e){return{...e,id:e.id||uo(),item:ti(e.item)}}function ti(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(gn=Math.max(gn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(In=Math.max(In,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||uo(),item:ti(o.item),answerOption:Yh(o.answerOption)}))}function Yh(e){if(e)return e.map(o=>({...o,id:o.id||uo()}))}function jh(){return{id:uo(),linkId:hn("s"),type:"group",text:"New Page",extension:[{url:"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",valueCodeableConcept:{coding:[{system:"http://hl7.org/fhir/questionnaire-item-control",code:"page"}]}}]}}function eC(e,o,t){let r=e??[],a=o+t;if(a<0||a>=r.length)return r;let n=[...r];return[n[o],n[a]]=[n[a],n[o]],n}import{Title as pC}from"@mantine/core";import{createReference as xC,getReferenceString as IC}from"@medplum/core";import{useEffect as si,useState as vn}from"react";import{Button as yn,Group as uC,Stack as cC,Stepper as ni}from"@mantine/core";import{Anchor as oC}from"@mantine/core";import{useState as tC}from"react";import{jsx as Dr,jsxs as aC}from"react/jsx-runtime";function Tr(e){let{item:o,response:t,onChange:r}=e,[a,n]=tC(rC(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return Dr("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?Dr(Dt,{item:o,response:t,onChange:s=>r([s]),index:0},o.linkId):aC(xe,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((s,f)=>Dr(Dt,{item:o,response:t,onChange:i=>r([i]),index:f},`${o.linkId}-${f}`)),l&&Dr(oC,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function rC(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}import{Anchor as nC,Stack as lC,Title as fC}from"@mantine/core";import{useState as sC}from"react";import{Fragment as iC,jsx as co,jsxs as ai}from"react/jsx-runtime";function Cn(e){let[o,t]=sC(e.response);if(o.length===0)return null;function r(n,l){let s=o.map((f,i)=>i===l?n[0]:f);t(s),e.onChange(s)}function a(){let n=cn(e.item);t([...o,n])}return ai(iC,{children:[o.map((n,l)=>co(ri,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,l)},n.id)),e.item.repeats&&co(nC,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function ri(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let s=o.item?.map(i=>n.find(d=>d.id===i.id)??i)?.concat(n.slice(1)),f={...o,item:s};r([f])}return e.checkForQuestionEnabled(e.item)?ai("div",{children:[e.item.text&&co(fC,{order:3,mb:"md",children:e.item.text}),co(lC,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?co(Cn,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):co(ri,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):co(Tr,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as mC,jsx as qe,jsxs as fi}from"react/jsx-runtime";function li(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:l,numberOfPages:s,renderPages:f,submitButtonText:i,checkForQuestionEnabled:u}=e,d=o.map(c=>{let x=t?.item?.filter(I=>I.linkId===c.linkId)??[],C=c.type==="group"?qe(Cn,{item:c,response:x,onChange:a,checkForQuestionEnabled:u},c.linkId):qe(Tr,{item:c,response:x?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return f?qe(ni.Step,{label:c.text,children:C},c.linkId):C});return fi(mC,{children:[f&&qe(ni,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!f&&qe(cC,{children:d}),qe(dC,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:l,submitButtonText:i})]})}function dC(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return fi(uC,{position:"right",mt:"xl",spacing:"xs",children:[o&&qe(yn,{onClick:e.prevStep,children:"Back"}),t&&qe(yn,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&qe(yn,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as ii,jsxs as hC}from"react/jsx-runtime";function ui(e){let o=v(),t=o.getProfile(),[r,a]=vn(!1),n=G(e.questionnaire),[l,s]=vn(),[f,i]=vn(0);si(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),si(()=>{s(n?zs(n):void 0)},[n]);function u(I){let R=l?.item??[],b={resourceType:"QuestionnaireResponse",item:ci(R,Array.isArray(I)?I:[I])};s(b)}function d(I){return Gs(I,l?.item??[])}if(!r||!n)return null;let c=Js(n),x=()=>i(I=>I+1),C=()=>i(I=>I-1);return hC(W,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:IC(n),subject:e.subject,source:xC(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&ii(pC,{children:n.title}),ii(li,{items:n.item??[],response:l,onChange:u,renderPages:c>1,activePage:f,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:x,prevStep:C})]})}function gC(e,o){let t=ci(e.item??[],o.item??[]);return{...o,item:t.length>0?t:void 0,answer:o.answer&&o.answer.length>0?o.answer:e.answer}}function ci(e,o){let t=[],r=new Set;for(let a of e){let n=a.id,l=o.find(s=>s.id===n);l?(t.push(gC(a,l)),r.add(l.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}import{ActionIcon as kr,Button as CC,createStyles as yC,Divider as vC,Group as Tt,NativeSelect as Sn,Stack as Br,Text as SC,TextInput as RC}from"@mantine/core";import{formatRange as di,getCodeBySystem as bC}from"@medplum/core";import{useEffect as PC,useState as Rn}from"react";import{jsx as X,jsxs as Xo}from"react/jsx-runtime";var DC=yC(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[3]}`,borderRadius:e.radius.sm,transition:"all 0.1s"}})),TC=["gender","age","gestationalAge","context","appliesTo","category"],kC={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function f1(e){e=Object.assign(kC,e);let o=e.definition,[t,r]=Rn([]),[a,n]=Rn(1),[l,s]=Rn(1);return PC(()=>{let C=MC(o,s);r(FC(C.qualifiedInterval||[],n))},[o]),Xo(W,{testid:"reference-range-editor",onSubmit:f,children:[X(Br,{children:t.map(C=>X(BC,{unit:OC(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:x,onRemoveGroup:u,intervalGroup:C},`group-${C.id}`))}),X(kr,{title:"Add Group",size:"sm",onClick:C=>{O(C),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(I=>I+1)},children:X(go,{})}),X(Tt,{position:"right",children:X(CC,{type:"submit",children:"Save"})})]});function f(){let C=t.flatMap(I=>I.intervals).filter(I=>!EC(I));e.onSubmit({...o,qualifiedInterval:C})}function i(C){r(I=>[...I,C])}function u(C){r(I=>I.filter(R=>R.id!==C.id))}function d(C,I){r(R=>{R=[...R];let D=R.find(T=>T.id===C),b=D?.intervals.findIndex(T=>T.id===I.id);return b!==void 0&&D?.intervals[b]&&(D.intervals[b]=I),R})}function c(C,I){I.id===void 0&&(I.id=`id-${l}`,s(R=>R+1)),r(R=>{R=[...R];let D=R.findIndex(b=>b.id===C);if(D!==-1){let b={...R[D]};I={...I,...b.filters},b.intervals=[...b.intervals,I],R[D]=b}return R})}function x(C,I){r(R=>{R=[...R];let D=R.find(b=>b.id===C);return D&&(D.intervals=D.intervals.filter(b=>b.id!==I.id)),R})}}function BC(e){let{intervalGroup:o,unit:t}=e,{classes:r}=DC();return X(Xe,{"data-testid":o.id,className:r.section,children:Xo(Br,{spacing:"lg",children:[X(Tt,{position:"right",children:X(kr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{O(a),e.onRemoveGroup(o)},children:X(Qe,{})},`remove-group-button-${o.id}`)}),X(AC,{intervalGroup:o,onChange:e.onChange}),X(vC,{}),o.intervals.map(a=>Xo(Br,{spacing:"xs",children:[Xo(Tt,{children:[X(RC,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{O(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),X(kr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{O(n),e.onRemove(o.id,a)},children:X(Qe,{})},`remove-interval-${a.id}`)]}),X(ct,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),X(kr,{title:"Add Interval",size:"sm",onClick:a=>{O(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:X(go,{})})]})})}function AC(e){let{intervalGroup:o,onChange:t}=e;o.filters.age||(o.filters.age={});for(let r of["low","high"])o.filters.age[r]?.unit||(o.filters.age[r]={...o.filters.age[r],unit:"years",system:"http://unitsofmeasure.org"});return Xo(Br,{style:{maxWidth:"50%"},children:[X(Tt,{children:X(Sn,{data:["","male","female"],label:"Gender:",defaultValue:o.filters.gender||"",onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""&&(n=void 0),t(o.id,{...a,gender:n})}}})}),Xo(Tt,{spacing:"xs",children:[X(SC,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),X("div",{id:`div-age-${o.id}`,children:X(ct,{name:`age-${o.id}`,defaultValue:o.filters.age,onChange:r=>{for(let a of o.intervals)t(o.id,{...a,age:r})}},`age-${o.id}`)})]}),X(Sn,{data:["","pre-puberty","follicular","midcycle","luteal","postmenopausal"],label:"Endocrine:",defaultValue:o.filters.context?.text||"",onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""?(n=void 0,t(o.id,{...a,context:void 0})):t(o.id,{...a,context:{text:n,coding:[{code:n,system:"http://terminology.hl7.org/CodeSystem/referencerange-meaning"}]}})}}}),X(Sn,{data:["","reference","critical","absolute"],label:"Category: ",defaultValue:o.filters.category,onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""?t(o.id,{...a,category:void 0}):t(o.id,{...a,category:n})}}})]})}function MC(e,o){let t=e.qualifiedInterval||[],r=Math.max(...t.map(a=>{let n=parseInt(a.id?.substring(3)||"",10);return isNaN(n)?Number.NEGATIVE_INFINITY:n}))+1;return Number.isFinite(r)||(r=1),e={...e,qualifiedInterval:t.map(a=>({...a,id:a.id||`id-${r++}`}))},o(r),e}function FC(e,o){let t=1,r={};for(let a of e){let n=wC(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(TC.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function wC(e){return[`gender=${e.gender}`,`age=${di(e.age)}`,`gestationalAge=${di(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function OC(e){return e&&(bC(e,"http://unitsofmeasure.org")||e.text)}function EC(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as mi,Grid as Ar,Text as LC}from"@mantine/core";import{formatDateTime as NC,getReferenceString as HC}from"@medplum/core";import{Fragment as VC,useEffect as qC,useState as pi}from"react";import{jsx as Me,jsxs as kt}from"react/jsx-runtime";function g1(e){let o=v(),t=G(e.value),[r,a]=pi(!1),[n,l]=pi();if(qC(()=>{t&&!r&&(o.executeBatch(s(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Me(Ar,{children:t.action?.map((i,u)=>{let d=i.resource&&f(i.resource),c=d?.input?.[0]?.valueReference,x=d?.output?.[0]?.valueReference;return kt(VC,{children:[Me(Ar.Col,{span:1,p:"md",children:d?.status==="completed"?Me(Yr,{}):Me(xa,{color:"gray"})}),kt(Ar.Col,{span:9,p:"xs",children:[Me(LC,{weight:500,children:i.title}),i.description&&Me("div",{children:i.description}),kt("div",{children:["Last edited by\xA0",Me(Ae,{value:d?.meta?.author}),"\xA0on\xA0",NC(d?.meta?.lastUpdated)]}),kt("div",{children:["Status: ",Me(rr,{status:d?.status||"unknown"})]})]}),kt(Ar.Col,{span:2,p:"md",children:[c&&!x&&Me(mi,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&x&&Me(mi,{onClick:()=>e.onEdit(d,c,x),children:"Edit"})]})]},`action-${u}`)})});function s(i){let u=[];if(i.action)for(let d of i.action)d.resource?.reference&&u.push({request:{method:"GET",url:d.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function f(i){for(let u of n?.entry)if(u.resource&&i.reference===HC(u.resource))return u.resource}}import{createStyles as JC}from"@mantine/core";import{useEffect as $C,useState as KC}from"react";import{stringify as zC}from"@medplum/core";function Mr(e,o){let t=GC(e,o);return UC(t,e,o)}function GC(e,o){let t=e.length,r=o.length,a=t+r+1,n=1+2*a,l=n/2|0,s=new Array(n);s[l+1]={i:0,j:-1,prev:void 0,snake:!0};for(let f=0;f<a;f++){for(let i=-f;i<=f;i+=2){let u=l+i,d=u+1,c=u-1,x=s[d],C=s[c],I,R=0;i===-f||i!==f&&C.i<x.i?(R=x.i,I=x):(R=C.i+1,I=C),s[c]=void 0;let D=R-i,b={i:R,j:D,prev:QC(I),snake:!1};for(;R<t&&D<r&&e[R]===o[D];)R++,D++;if(R>b.i&&(b={i:R,j:D,prev:b,snake:!0}),s[u]=b,R>=t&&D>=r)return s[u]}s[l+f-1]=void 0}}function UC(e,o,t){let r=[],a=e;for(a.snake&&(a=a.prev);a?.prev&&a.prev.j>=0;){let n=a.i,l=a.j;a=a.prev;let s=a.i,f=a.j,i={position:s,lines:o.slice(s,n)},u={position:f,lines:t.slice(f,l)},d;i.lines.length===0&&u.lines.length>0?d="insert":i.lines.length>0&&u.lines.length===0?d="delete":d="change",r.push({original:i,revised:u,type:d}),a.snake&&(a=a.prev)}return r}function QC(e){return e&&!e.snake&&e.prev?e.prev:e}function xi(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:zC(r.resource,!0).match(/[^\r\n]+/g)})).sort((r,a)=>r.meta.lastUpdated.localeCompare(a.meta.lastUpdated)),t=o[0].lines.map(r=>({id:o[0].meta.versionId,meta:o[0].meta,value:r,span:1}));return WC(t,o),XC(t),t}function WC(e,o){for(let t=1;t<o.length;t++){let r=Mr(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,l=a.original.lines,s=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,l.length),a.type==="insert"||a.type==="change")for(let f=0;f<a.revised.lines.length;f++)e.splice(n+f,0,{id:o[t].meta.versionId,meta:o[t].meta,value:s[f],span:1})}}}function XC(e){let o=0;for(;o<e.length;){let t=o;for(;t<e.length&&e[t].id===e[o].id;)e[t].span=-1,t++;e[o].span=t-o,o=t}}function Ii(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function gi(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Jo(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Jo(r,"month");let a=Math.floor(o/86400);if(a>0)return Jo(a,"day");let n=Math.floor(o/3600);if(n>0)return Jo(n,"hour");let l=Math.floor(o/60);return l>0?Jo(l,"minute"):Jo(o,"second")}function Jo(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as ZC,jsx as Te,jsxs as hi}from"react/jsx-runtime";var _C=JC(e=>({container:{overflowX:"auto"},root:{border:`0.1px solid ${e.colors.gray[3]}`,borderCollapse:"collapse",borderRadius:e.radius.sm,borderSpacing:0,fontSize:e.fontSizes.xs,width:"100%","& td":{padding:"2px 4px 0 4px",verticalAlign:"top",whiteSpace:"nowrap"}},startRow:{borderTop:`0.1px solid ${e.colors.gray[3]}`},normalRow:{borderTop:0},author:{lineHeight:"10px"},dateTime:{borderRight:`0.1px solid ${e.colors.gray[3]}`,lineHeight:"20px"},lineNumber:{backgroundColor:e.colors.gray[1],border:0,color:e.colors.gray[5],fontFamily:e.fontFamilyMonospace,padding:`${e.spacing.xs} ${e.spacing.sm}`,textAlign:"right"},line:{fontFamily:e.fontFamilyMonospace,fontSize:e.fontSizes.sm,padding:`${e.spacing.xs} ${e.spacing.sm}`},pre:{margin:0}}));function F1(e){let{classes:o}=_C(),t=v(),[r,a]=KC(e.history);if($C(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(a).catch(console.log)},[t,e.history,e.resourceType,e.id]),!r)return Te("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=xi(r);return Te("div",{className:o.container,children:Te("table",{className:o.root,children:Te("tbody",{children:l.map((s,f)=>hi("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&hi(ZC,{children:[Te("td",{className:o.author,rowSpan:s.span,children:Te(Je,{value:s.meta.author,link:!0})}),Te("td",{className:o.dateTime,rowSpan:s.span,children:Te(j,{to:Ii(n,s.meta.versionId),children:gi(s.meta.lastUpdated)})})]}),Te("td",{className:o.lineNumber,children:f+1}),Te("td",{className:o.line,children:Te("pre",{className:o.pre,children:s.value})})]},"row-"+f))})})})}import{createStyles as YC}from"@mantine/core";import{stringify as Ci}from"@medplum/core";import{Fragment as oy,jsx as $o,jsxs as ty}from"react/jsx-runtime";var jC=YC(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function V1(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Ci(o,!0).match(/[^\r\n]+/g),a=Ci(t,!0).match(/[^\r\n]+/g),n=Mr(r,a);return $o("pre",{style:{color:"gray"},children:n.map((l,s)=>$o(ey,{delta:l},"delta"+s))})}function ey(e){let{classes:o}=jC();return ty(oy,{children:["...",$o("br",{}),e.delta.original.lines.length>0&&$o("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
64
|
+
}`.replace(/\s+/g," ")}function sc(e,o){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),uc(ic(t),o).slice(0,5)}function ic(e){let o=new Set,t=[];for(let r of e)o.has(r.id)||(o.add(r.id),t.push(r));return t}function uc(e,o){return e.sort((t,r)=>nl(r,o)-nl(t,o))}function nl(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,ll(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,ll(ju(r),o));return t}function ll(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as J,jsxs as ze}from"react/jsx-runtime";var gc=dc(e=>({logoButton:{padding:`${e.spacing.xs} ${e.spacing.sm}`,borderRadius:e.radius.sm,transition:"background-color 100ms ease","&:hover":{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}},user:{padding:`${e.spacing.xs} ${e.spacing.sm}`,borderRadius:e.radius.sm,transition:"background-color 100ms ease","&:hover":{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}},userName:{fontWeight:500,lineHeight:1,marginRight:3,[e.fn.smallerThan("xs")]:{display:"none"}},userActive:{backgroundColor:e.fn.lighten(e.fn.variant({variant:"filled",color:e.primaryColor}).background,.8)}}));function dl(e){let o=Yo(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:s}=gc(),[f,i]=Ic(!1);return J(mc,{height:60,p:8,style:{zIndex:101},children:ze(Vt,{position:"apart",children:[ze(Vt,{spacing:"xs",children:[J(ul,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&J(il,{pathname:e.pathname,searchParams:e.searchParams})]}),ze(Oe,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:f,onClose:()=>i(!1),children:[J(Oe.Target,{children:J(ul,{className:s(l.user,{[l.userActive]:f}),onClick:()=>i(u=>!u),children:ze(Vt,{spacing:7,children:[J(le,{value:r,radius:"xl",size:24}),J(nt,{size:"sm",className:l.userName,children:xc(r?.name?.[0])}),J(jr,{size:12,stroke:1.5})]})})}),ze(Oe.Dropdown,{children:[ze(pc,{align:"center",p:"xl",children:[J(le,{size:"xl",radius:100,value:o.profile}),J(Nt,{value:o.profile?.name?.[0]}),J(nt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&J(Oe.Divider,{}),n.map(u=>u.profile.reference!==cl(o.profile)&&J(Oe.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:ze(Vt,{children:[J(cc,{radius:"xl"}),ze("div",{style:{flex:1},children:[J(nt,{size:"sm",weight:500,children:u.profile.display}),J(nt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),J(Oe.Divider,{}),J(Oe.Item,{icon:J(Ia,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),J(Oe.Item,{icon:J(yo,{size:14,stroke:1.5}),onClick:()=>a(`/${cl(r)}`),children:"Account settings"}),J(Oe.Item,{icon:J(sa,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),J(nt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as Qc,createStyles as zc,Navbar as Sa,ScrollArea as Wc,Space as Xc,Text as Jc}from"@mantine/core";import{Fragment as $c,useState as Kc}from"react";import{Button as vc,Group as Sc,Modal as Rc,NativeSelect as bc,Stack as Pc,TextInput as Dc}from"@mantine/core";import{showNotification as pl}from"@mantine/notifications";import{deepClone as kc,normalizeErrorString as Tc}from"@medplum/core";function ml(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?hc(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Cc(o,t);return o}function hc(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Cc(e,o){e[o.name]=o.value}import{jsx as yc}from"react/jsx-runtime";function W(e){return yc("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=ml(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as ro,jsxs as Ac}from"react/jsx-runtime";function xl(e){let o=v(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,s=`${e.pathname}?${e.searchParams.toString()}`,f=kc(t);f.menu?.find(({title:u})=>u===n)?.link?.push({name:l,target:s}),o.updateResource(f).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),pl({color:"green",message:"Success"}),e.onOk()}).catch(u=>{pl({color:"red",message:Tc(u)})})}return ro(Rc,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:ro(W,{onSubmit:r,children:Ac(Pc,{children:[ro(Bc,{config:t}),ro(Dc,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),ro(Sc,{position:"right",children:ro(vc,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Bc(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return ro(bc,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as qc,useState as Gc}from"react";import{useState as Lc}from"react";import{useCallback as Mc}from"react";import{jsx as Ec}from"react/jsx-runtime";function va(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Fc(e){return typeof e.display=="string"?e.display:va(e)}function wc(e){return{value:va(e),label:Fc(e),resource:e}}function Oc(e){return{code:e,display:e}}function ko(e){let o=v(),{binding:t,creatable:r,clearable:a,...n}=e,l=Mc(async(s,f)=>{if(!t)return[];let u=(await o.searchValueSet(t,s,{signal:f})).expansion?.contains,d=[];for(let c of u)c.code&&!d.some(x=>x.code===c.code)&&d.push(c);return d},[o,t]);return Ec(Po,{...n,creatable:r??!0,clearable:a??!0,toKey:va,toOption:wc,loadOptions:l,onCreate:Oc,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}import{jsx as Vc}from"react/jsx-runtime";function qt(e){let[o,t]=Lc(e.defaultValue);function r(a){let n=a[0],l=Hc(n);t(l),e.onChange&&e.onChange(l)}return Vc(ko,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Nc(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Nc(e){return e?{code:e}:void 0}function Hc(e){return e?.code}import{jsx as Uc}from"react/jsx-runtime";function To(e){let[o,t]=Gc(e.defaultValue),r=e.onChange,a=qc(n=>{t(n),r&&r(n)},[r]);return Uc(qt,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as ed,jsx as Re,jsxs as lt}from"react/jsx-runtime";var Il=zc(e=>({menuTitle:{margin:"20px 0 4px 6px",fontSize:"9px",fontWeight:"normal",textTransform:"uppercase",letterSpacing:"2px"},link:{...e.fn.focusStyles(),display:"flex",alignItems:"center",textDecoration:"none",fontSize:e.fontSizes.sm,color:e.colorScheme==="dark"?e.colors.dark[1]:e.colors.gray[7],padding:"8px 12px",borderRadius:e.radius.sm,fontWeight:500,"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[6]:e.colors.gray[0],color:e.colorScheme==="dark"?e.white:e.black,textDecoration:"none","& svg":{color:e.colorScheme==="dark"?e.white:e.black}},"& svg":{color:e.colorScheme==="dark"?e.colors.dark[2]:e.colors.gray[6],marginRight:e.spacing.sm,strokeWidth:1.5,width:18,height:18}},linkActive:{"&, &:hover":{backgroundColor:e.fn.variant({variant:"light",color:e.primaryColor}).background,color:e.fn.variant({variant:"light",color:e.primaryColor}).color,"& svg":{color:e.fn.variant({variant:"light",color:e.primaryColor}).color}}}}));function gl(e){let{classes:o}=Il(),t=Ue(),r=Yc(e.pathname,e.searchParams,e.menus),[a,n]=Kc(!1);function l(f,i){f.stopPropagation(),f.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function s(f){f&&t(`/${f}`)}return lt(ed,{children:[Re(Sa,{width:{sm:250},p:"xs",children:lt(Wc,{children:[!e.resourceTypeSearchDisabled&&Re(Sa.Section,{mb:"sm",children:Re(To,{name:"resourceType",placeholder:"Resource Type",onChange:f=>s(f)},window.location.pathname)}),lt(Sa.Section,{grow:!0,children:[e.menus?.map(f=>lt($c,{children:[Re(Jc,{className:o.menuTitle,children:f.title}),f.links?.map(i=>lt(_c,{to:i.href,active:i.href===r?.href,onClick:u=>l(u,i.href),children:[Re(Zc,{to:i.href,icon:i.icon}),Re("span",{children:i.label})]},i.href))]},`menu-${f.title}`)),e.displayAddBookmark&&Re(Qc,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Re(da,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Re(xl,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function _c(e){let{classes:o,cx:t}=Il();return Re(j,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function Zc(e){return e.icon?e.icon:Re(Xc,{w:30})}function Yc(e,o,t){if(!e||!o||!t)return;let r,a=0;for(let n of t)if(n.links)for(let l of n.links){let s=jc(e,o,l.href);s>a&&(a=s,r=l)}return r}function jc(e,o,t){let r=new URL(t,"https://example.com");if(e!==r.pathname)return 0;let a=["_count","_offset"];for(let[l,s]of r.searchParams.entries())if(!a.includes(l)&&o.get(l)!==s)return 0;let n=1;for(let[l,s]of o.entries())a.includes(l)||r.searchParams.get(l)===s&&n++;return n}import{jsx as ao}from"react/jsx-runtime";function MD(e){let o=td(),[t,r]=ld(localStorage.navbarOpen==="true"),a=v(),n=Ft();nd(()=>{function i(){rd({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",i),()=>a.removeEventListener("offline",i)},[a]);function l(i){localStorage.navbarOpen=i.toString(),r(i)}function s(){l(!1)}function f(){l(!t)}return a.isLoading()?ao(Ca,{}):ao(od,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&ao(dl,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:f}),navbar:n&&t?ao(gl,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:s,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:ao(vo,{children:ao(ad,{fallback:ao(Ca,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as fd}from"@mantine/core";import{jsx as no,jsxs as id}from"react/jsx-runtime";function ke(e){let{contentType:o,url:t,title:r}=e.value??{};return t?id("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&no("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&no("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:no("source",{type:o,src:t})}),o==="application/pdf"&&no("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:no("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),no("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:no(fd,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:sd(r),children:r||"Download"})})]}):null}function sd(e){return e?.includes(".")?e:void 0}import{jsx as Ra}from"react/jsx-runtime";function hl(e){return Ra("div",{children:e.values?.map((o,t)=>Ra("div",{children:Ra(ke,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as Cl}from"@mantine/core";import{useRef as xd,useState as Id}from"react";import{useRef as ud}from"react";import{normalizeOperationOutcome as cd}from"@medplum/core";import{Fragment as md,jsx as dd,jsxs as pd}from"react/jsx-runtime";function Bo(e){let o=v(),t=ud(null);function r(l){O(l),t.current?.click()}function a(l){O(l);let s=l.target.files;s&&Array.from(s).forEach(n)}function n(l){if(!l||!l.name)return;e.onUploadStart&&e.onUploadStart();let f=l.name,i=l.type||"application/octet-stream";o.createBinary(l,f,i,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:f})}).catch(u=>{e.onUploadError&&e.onUploadError(cd(u))})}return pd(md,{children:[dd("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as ge,jsxs as ft}from"react/jsx-runtime";function yl(e){let[o,t]=Id(e.defaultValue??[]),r=xd();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return ft("table",{style:{width:"100%"},children:[ft("colgroup",{children:[ge("col",{width:"97%"}),ge("col",{width:"3%"})]}),ft("tbody",{children:[o.map((n,l)=>ft("tr",{children:[ge("td",{children:ge(ke,{value:n,maxWidth:200})}),ge("td",{children:ge(Cl,{title:"Remove",size:"sm",onClick:s=>{O(s);let f=o.slice();f.splice(l,1),a(f)},children:ge(Qe,{})})})]},`${l}-${o.length}`)),ft("tr",{children:[ge("td",{}),ge("td",{children:ge(Bo,{onUpload:n=>{a([...r.current,n])},children:n=>ge(Cl,{...n,title:"Add",size:"sm",color:"green",children:ge(ot,{size:16})})})})]})]})]})}import{Button as vl}from"@mantine/core";import{useState as gd}from"react";import{Fragment as hd,jsx as Gt,jsxs as Cd}from"react/jsx-runtime";function Ut(e){let[o,t]=gd(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?Cd(hd,{children:[Gt(ke,{value:o,maxWidth:200}),Gt(vl,{onClick:a=>{O(a),r(void 0)},children:"Remove"})]}):Gt(Bo,{onUpload:r,children:a=>Gt(vl,{...a,children:"Upload..."})})}import{getPropertyDisplayName as nm,tryGetDataType as lm}from"@medplum/core";var Qt=["meta","implicitRules","contained","extension","modifierExtension"],zt=["language","text"];import{createStyles as yd}from"@mantine/core";import{Fragment as Sd,jsx as ba,jsxs as Rd}from"react/jsx-runtime";var vd=yd(e=>({root:{display:"grid",gridTemplateColumns:"30% 70%",margin:0,"& > dt, & > dd":{padding:`${e.spacing.sm} ${e.spacing.sm}`,borderTop:`0.1px solid ${e.colors.gray[3]}`,margin:0}},compact:{gridTemplateColumns:"20% 80%","& > dt, & > dd":{padding:`0 ${e.spacing.xs} ${e.spacing.xs} 0`,border:0}}}));function Sl(e){let{children:o,compact:t}=e,{classes:r,cx:a}=vd();return ba("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function Rl(e){return Rd(Sd,{children:[ba("dt",{children:e.term}),ba("dd",{children:e.children})]})}import{ActionIcon as Kd,Box as _d,CopyButton as Zd,Tooltip as Yd}from"@mantine/core";import{PropertyType as E,formatDateTime as jd,formatPeriod as em,formatTiming as om,isEmpty as tm}from"@medplum/core";import{formatCodeableConcept as bd}from"@medplum/core";import{Fragment as Pd,jsx as Dd}from"react/jsx-runtime";function Ao(e){return Dd(Pd,{children:bd(e.value)})}import{formatCoding as kd}from"@medplum/core";import{Fragment as Td,jsx as Bd}from"react/jsx-runtime";function bl(e){return Bd(Td,{children:kd(e.value)})}import{Fragment as Ad,jsx as Md}from"react/jsx-runtime";function Wt(e){let o=e.value;if(!o)return null;let t=[];return o.value&&t.push(o.value),(o.use||o.system)&&(t.push(" ["),o.use&&t.push(o.use),o.use&&o.system&&t.push(" "),o.system&&t.push(o.system),t.push("]")),Md(Ad,{children:t.join("").trim()})}import{Fragment as wd,jsx as Fd,jsxs as Od}from"react/jsx-runtime";function Pl(e){let o=e.value;return o?Od(wd,{children:[o.name,o.name&&": ",o.telecom?.map(t=>Fd(Wt,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as Ed}from"react/jsx-runtime";function Dl(e){return Ed("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as Ld}from"@medplum/core";import{Fragment as Nd,jsx as Hd}from"react/jsx-runtime";function kl(e){return Hd(Nd,{children:Ld(e.value)})}import{formatQuantity as Vd}from"@medplum/core";import{Fragment as qd,jsx as Gd}from"react/jsx-runtime";function We(e){return Gd(qd,{children:Vd(e.value)})}import{formatRange as Ud}from"@medplum/core";import{Fragment as Qd,jsx as zd}from"react/jsx-runtime";function Xt(e){return zd(Qd,{children:Ud(e.value)})}import{Fragment as Wd,jsx as Tl,jsxs as Xd}from"react/jsx-runtime";function Bl(e){let o=e.value;return o?Xd(Wd,{children:[Tl(We,{value:o.numerator}),"\xA0/\xA0",Tl(We,{value:o.denominator})]}):null}import{stringify as Jd}from"@medplum/core";import{Fragment as $d,jsx as Al}from"react/jsx-runtime";function lo(e){if(!e.value)return null;let o=e.value.display||e.value.reference||Jd(e.value);return e.link!==!1&&e.value.reference?Al(j,{to:e.value,children:o}):Al($d,{children:o})}import{Fragment as Ml,jsx as Jt}from"react/jsx-runtime";function Fl(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?Jt(Ml,{children:t.map((a,n)=>Jt("div",{children:Jt(re,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):Jt(Ml,{})}import{Fragment as Mo,jsx as V,jsxs as rm}from"react/jsx-runtime";function re(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return rm(_d,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!tm(r)&&V(Zd,{value:r,timeout:2e3,children:({copied:n,copy:l})=>V(Yd,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:V(Kd,{color:n?"teal":"gray",onClick:l,children:n?V(et,{size:"1rem"}):V(oa,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===E.Attachment?V(hl,{values:r,maxWidth:e.maxWidth}):V(Fl,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case E.boolean:return V(Mo,{children:r===void 0?"":(!!r).toString()});case E.SystemString:case E.string:return V("div",{style:{whiteSpace:"pre-wrap"},children:r});case E.code:case E.date:case E.decimal:case E.id:case E.integer:case E.positiveInt:case E.unsignedInt:case E.uri:case E.url:return V(Mo,{children:r});case E.canonical:return V(lo,{value:{reference:r},link:e.link});case E.dateTime:case E.instant:return V(Mo,{children:jd(r)});case E.markdown:return V("pre",{children:r});case E.Address:return V(qn,{value:r});case E.Annotation:return V(Mo,{children:r?.text});case E.Attachment:return V(ke,{value:r,maxWidth:e.maxWidth});case E.CodeableConcept:return V(Ao,{value:r});case E.Coding:return V(bl,{value:r});case E.ContactDetail:return V(Pl,{value:r});case E.ContactPoint:return V(Wt,{value:r});case E.HumanName:return V(Nt,{value:r});case E.Identifier:return V(Dl,{value:r});case E.Money:return V(kl,{value:r});case E.Period:return V(Mo,{children:em(r)});case E.Quantity:case E.Duration:return V(We,{value:r});case E.Range:return V(Xt,{value:r});case E.Ratio:return V(Bl,{value:r});case E.Reference:return V(lo,{value:r,link:e.link});case E.Timing:return V(Mo,{children:om(r)});case E.Dosage:case E.UsageContext:return V(st,{value:{type:t,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});default:if(!o)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);return V(st,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as am}from"@medplum/core";function Te(e,o){let t=am(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}import{jsx as $t,jsxs as fm}from"react/jsx-runtime";function st(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=lm(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?$t("div",{children:t.name}):$t(Sl,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,s]=n;if(Qt.includes(l)||zt.includes(l)&&s.path.split(".").length===2)return null;let[f,i]=Te(o,l);return e.ignoreMissingValues&&(!f||Array.isArray(f)&&f.length===0)?null:$t(Rl,{term:nm(l),children:$t(re,{property:s,propertyType:i,value:f,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):fm("div",{children:[r,"\xA0not implemented"]})}import{Stack as Wp}from"@mantine/core";import{getPropertyDisplayName as If,tryGetDataType as Xp}from"@medplum/core";import{useState as Jp}from"react";import{Group as sm,Input as im}from"@mantine/core";import{jsx as Pa,jsxs as um}from"react/jsx-runtime";function Kt(e){return um(sm,{noWrap:!0,children:[Pa("div",{children:e.children}),Pa("div",{children:Pa(im.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as cm}from"@mantine/core";function ae(e,o){return e?.issue?.filter(t=>wl(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
+
`)}function _t(e,o){return e?.issue?.filter(t=>wl(t.expression?.[0],o))}function wl(e,o){if(e===o)return!0;if(!e||!o)return!1;let t=e.indexOf(".");if(t>=0&&e.substring(t+1)===o)return!0;let r=o.indexOf(".");return r>=0&&o.substring(r+1)===e}import{jsx as dm}from"react/jsx-runtime";function pe(e){return dm(cm.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,error:ae(e.outcome,e.htmlFor),children:e.children})}import{capitalize as mm}from"@medplum/core";function it(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let s=o.replace("[x]",mm(l.code));s in e&&delete e[s]}return e[t]=a,e}import{Checkbox as Lp,Group as Np,NativeSelect as Hp,Textarea as Vp,TextInput as Fa}from"@mantine/core";import{capitalize as qp,PropertyType as w}from"@medplum/core";import{useState as Gp}from"react";import{useState as pm}from"react";import{jsx as gm}from"react/jsx-runtime";function Ol(e){let[o,t]=pm(e.defaultValue);function r(a){let n=Im(a);t(n),e.onChange&&e.onChange(n)}return gm(ko,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&xm(o),maxSelectedValues:1,onChange:r})}function xm(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Im(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as hm}from"react";import{jsx as vm}from"react/jsx-runtime";function Zt(e){let[o,t]=hm(e.defaultValue);function r(a){let n=a[0],l=n&&ym(n);t(l),e.onChange&&e.onChange(l)}return vm(ko,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Cm(o),maxSelectedValues:1,onChange:r})}function Cm(e){return{system:e.system,code:e.code,display:e.display}}function ym(e){return{system:e.system,code:e.code,display:e.display}}import{Group as km,TextInput as Tm}from"@mantine/core";import{useRef as Bm,useState as Am}from"react";import{Group as Sm,NativeSelect as El,TextInput as Rm}from"@mantine/core";import{useRef as bm,useState as Pm}from"react";import{jsx as Da,jsxs as Dm}from"react/jsx-runtime";function Yt(e){let[o,t]=Pm(e.defaultValue),r=bm();r.current=o;function a(f){f&&Object.keys(f).length===0&&(f=void 0),t(f),e.onChange&&e.onChange(f)}function n(f){let i={...r.current,system:f};f||delete i.system,a(i)}function l(f){let i={...r.current,use:f};f||delete i.use,a(i)}function s(f){let i={...r.current,value:f};f||delete i.value,a(i)}return Dm(Sm,{spacing:"xs",grow:!0,noWrap:!0,children:[Da(El,{"data-testid":"system",defaultValue:o?.system,onChange:f=>n(f.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),Da(El,{"data-testid":"use",defaultValue:o?.use,onChange:f=>l(f.currentTarget.value),data:["","home","work","temp","old","mobile"]}),Da(Rm,{placeholder:"Value",defaultValue:o?.value,onChange:f=>s(f.currentTarget.value)})]})}import{jsx as Ll,jsxs as Mm}from"react/jsx-runtime";function Nl(e){let[o,t]=Am(e.defaultValue),r=Bm();r.current=o;function a(s){t(s),e.onChange&&e.onChange(s)}function n(s){let f={...r.current,name:s};s||delete f.name,a(f)}function l(s){let f={...r.current,telecom:s&&[s]};s||delete f.telecom,a(f)}return Mm(km,{spacing:"xs",grow:!0,noWrap:!0,children:[Ll(Tm,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:s=>n(s.currentTarget.value)}),Ll(Yt,{name:e.name+"-telecom",defaultValue:o?.telecom?.[0],onChange:l})]})}import{TextInput as Fm}from"@mantine/core";import{isValidDate as Hl}from"@medplum/core";function Vl(e){if(!e)return"";let o=new Date(e);return Hl(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function ql(e){if(!e)return"";let o=new Date(e);return Hl(o)?o.toISOString():""}import{jsx as Om}from"react/jsx-runtime";function be(e){return Om(Fm,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:wm(),defaultValue:Vl(e.defaultValue),autoFocus:e.autoFocus,error:ae(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(ql(t))}}})}function wm(){return"datetime-local"}import{JsonInput as Em}from"@mantine/core";import{stringify as Lm}from"@medplum/core";import{jsx as Nm}from"react/jsx-runtime";function Gl(e){return Nm(Em,{id:e.name,name:e.name,"data-testid":"extension-input",defaultValue:Lm(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as Hm,NativeSelect as Vm,TextInput as jt}from"@mantine/core";import{useRef as qm,useState as Gm}from"react";import{jsx as ut,jsxs as Um}from"react/jsx-runtime";function Ul(e){let[o,t]=Gm(e.defaultValue),r=qm();r.current=o;function a(u){t(u),e.onChange&&e.onChange(u)}function n(u){a({...r.current,use:u||void 0})}function l(u){a({...r.current,prefix:u?u.split(" "):void 0})}function s(u){a({...r.current,given:u?u.split(" "):void 0})}function f(u){a({...r.current,family:u||void 0})}function i(u){a({...r.current,suffix:u?u.split(" "):void 0})}return Um(Hm,{spacing:"xs",grow:!0,noWrap:!0,children:[ut(Vm,{defaultValue:o?.use,name:e.name+"-use","data-testid":"use",onChange:u=>n(u.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"]}),ut(jt,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:o?.prefix?.join(" "),onChange:u=>l(u.currentTarget.value)}),ut(jt,{placeholder:"Given",name:e.name+"-given",defaultValue:o?.given?.join(" "),onChange:u=>s(u.currentTarget.value)}),ut(jt,{name:e.name+"-family",placeholder:"Family",defaultValue:o?.family,onChange:u=>f(u.currentTarget.value)}),ut(jt,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:o?.suffix?.join(" "),onChange:u=>i(u.currentTarget.value)})]})}import{Group as Qm,TextInput as Ql}from"@mantine/core";import{useState as zm}from"react";import{jsx as zl,jsxs as Wm}from"react/jsx-runtime";function Wl(e){let[o,t]=zm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Wm(Qm,{spacing:"xs",grow:!0,noWrap:!0,children:[zl(Ql,{placeholder:"System",defaultValue:o?.system,onChange:a=>r({...o,system:a.currentTarget.value})}),zl(Ql,{placeholder:"Value",defaultValue:o?.value,onChange:a=>r({...o,value:a.currentTarget.value})})]})}import{NativeSelect as Xm,TextInput as Jm}from"@mantine/core";import{useCallback as ka,useState as $m}from"react";import{jsx as Ta}from"react/jsx-runtime";var Km=["USD","EUR","CAD","GBP","AUD"];function Xl(e){let{onChange:o}=e,[t,r]=$m(e.defaultValue),a=ka(f=>{r(f),o&&o(f)},[o]),n=ka(f=>{a({...t,currency:f.currentTarget.value})},[t,a]),l=ka(f=>{a({...t,value:f.currentTarget.valueAsNumber})},[t,a]),s=Ta(Xm,{defaultValue:t?.currency,data:Km,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return Ta(Jm,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:Ta(ta,{size:14}),rightSection:s,rightSectionWidth:92,onChange:l})}import{Group as _m}from"@mantine/core";import{useState as Zm}from"react";import{jsx as Jl,jsxs as Ym}from"react/jsx-runtime";function $l(e){let[o,t]=Zm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Ym(_m,{spacing:"xs",grow:!0,noWrap:!0,children:[Jl(be,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),Jl(be,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as jm,NativeSelect as ep,TextInput as Kl}from"@mantine/core";import{useState as op}from"react";import{jsx as Ba,jsxs as rp}from"react/jsx-runtime";function he(e){let[o,t]=op(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return rp(jm,{spacing:"xs",grow:!0,noWrap:!0,children:[Ba(ep,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),Ba(Kl,{id:e.name,name:e.name,required:e.required,"data-autofocus":e.autoFocus,"data-testid":e.name+"-value",type:"number",placeholder:"Value",defaultValue:o?.value,autoFocus:e.autoFocus,step:"any",onWheel:a=>{e.disableWheel&&a.currentTarget.blur()},onChange:a=>{r({...o,value:tp(a.currentTarget.value)})}}),Ba(Kl,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function tp(e){if(e)return parseFloat(e)}import{Group as ap}from"@mantine/core";import{useState as np}from"react";import{jsx as _l,jsxs as lp}from"react/jsx-runtime";function ct(e){let[o,t]=np(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return lp(ap,{spacing:"xs",grow:!0,noWrap:!0,children:[_l(he,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),_l(he,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as fp}from"@mantine/core";import{useState as sp}from"react";import{jsx as Zl,jsxs as ip}from"react/jsx-runtime";function Yl(e){let[o,t]=sp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return ip(fp,{spacing:"xs",grow:!0,noWrap:!0,children:[Zl(he,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Zl(he,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as Cp,NativeSelect as yp}from"@mantine/core";import{createReference as vp}from"@medplum/core";import{useState as rf}from"react";import{Group as up,Text as jl}from"@mantine/core";import{getDisplayString as cp,getReferenceString as tf}from"@medplum/core";import{forwardRef as dp,useCallback as ef,useState as mp}from"react";import{jsx as dt,jsxs as of}from"react/jsx-runtime";var pp={Observation:"code",User:"email:contains"},xp=["AccessPolicy","Account","ActivityDefinition","Bot","CapabilityStatement","ClientApplication","CodeSystem","CompartmentDefinition","ConceptMap","EffectEvidenceSynthesis","Endpoint","EventDefinition","Evidence","EvidenceVariable","ExampleScenario","GraphDefinition","HealthcareService","ImplementationGuide","InsurancePlan","Library","Location","Measure","MedicinalProduct","MessageDefinition","NamingSystem","OperationDefinition","Organization","Patient","Person","PlanDefinition","Practitioner","Project","Questionnaire","RelatedPerson","ResearchDefinition","ResearchElementDefinition","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function Ip(e){return{value:tf(e),label:cp(e),resource:e}}function er(e){let o=v(),t=e.resourceType,[r,a]=mp(),n=G(e.defaultValue,a),l=e.onChange,s=ef(async(i,u)=>{let d=hp(t),c=new URLSearchParams({[d]:i,_count:"10"});return await o.searchResources(t,c,{signal:u})},[o,t]),f=ef(i=>{l&&l(i[0])},[l]);return e.defaultValue&&!r&&!n?null:dt(Po,{name:e.name,required:e.required,itemComponent:gp,defaultValue:n,placeholder:e.placeholder,maxSelectedValues:1,toKey:tf,toOption:Ip,loadOptions:s,onChange:f,clearable:!0})}var gp=dp(({label:e,resource:o,...t},r)=>dt("div",{ref:r,...t,children:of(up,{noWrap:!0,children:[dt(le,{value:o}),of("div",{children:[dt(jl,{children:e}),dt(jl,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function hp(e){return pp[e]??(xp.includes(e)?"name":"_id")}import{jsx as Aa,jsxs as bp}from"react/jsx-runtime";function Fo(e){let o=Sp(e.targetTypes),t=Rp(e.defaultValue,o),[r,a]=rf(e.defaultValue),[n,l]=rf(t);function s(f){a(f),e.onChange&&e.onChange(f)}return bp(Cp,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&Aa(yp,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:n,autoFocus:e.autoFocus,onChange:f=>l(f.currentTarget.value),data:o}),!o&&Aa(To,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:l,name:e.name+"-resourceType",placeholder:"Resource Type"}),Aa(er,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,onChange:f=>{s(f?vp(f):void 0)}})]})}function Sp(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function Rp(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}import{ActionIcon as af,Group as nf,Stack as Pp}from"@mantine/core";import{useRef as Dp,useState as kp}from"react";import{jsx as Ee,jsxs as lf}from"react/jsx-runtime";function ff(e){let[o,t]=kp(e.defaultValue&&Array.isArray(e.defaultValue)?e.defaultValue:[]),r=Dp();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return lf(Pp,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,l)=>lf(nf,{noWrap:!0,children:[Ee("div",{style:{flexGrow:1},children:Ee(Le,{arrayElement:!0,property:e.property,name:e.name+"."+l,defaultValue:n,onChange:s=>{let f=[...r.current];f[l]=s,a(f)}})}),Ee("div",{children:Ee(af,{title:"Remove",size:"sm",onClick:s=>{O(s);let f=[...r.current];f.splice(l,1),a(f)},children:Ee(Qe,{})})})]},`${l}-${o.length}`)),Ee(nf,{noWrap:!0,style:{justifyContent:"flex-end"},children:Ee("div",{children:Ee(af,{title:"Add",size:"sm",color:"green",onClick:n=>{O(n);let l=[...r.current];l.push(void 0),a(l)},children:Ee(go,{})})})})]})}import{Button as cf,Chip as sf,Group as or,Modal as Tp,NativeSelect as Bp,Stack as Ap,Switch as Mp,TextInput as Fp}from"@mantine/core";import{formatTiming as wp}from"@medplum/core";import{useRef as df,useState as Ma}from"react";import{Fragment as pf,jsx as ne,jsxs as mt}from"react/jsx-runtime";var Op=["sun","mon","tue","wed","thu","fri","sat"];function mf(e){let[o,t]=Ma(e.defaultValue),[r,a]=Ma(!1),n=df();return n.current=o,mt(pf,{children:[mt(or,{spacing:"xs",grow:!0,noWrap:!0,children:[ne("span",{children:wp(n.current)||"No repeat"}),ne(cf,{onClick:()=>a(!0),children:"Edit"})]}),ne(Ep,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var uf={repeat:{period:1,periodUnit:"d"}};function Ep(e){let[o,t]=Ma(e.defaultValue||uf),r=df();r.current=o;function a(i){t({...r.current,event:[i]})}function n(i){t({...r.current,repeat:i})}function l(i){n({...r.current?.repeat,period:i})}function s(i){n({...r.current?.repeat,periodUnit:i})}function f(i){n({...r.current?.repeat,dayOfWeek:i})}return ne(Tp,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:mt(Ap,{children:[ne(pe,{title:"Starts on",htmlFor:"timing-dialog-start",children:ne(be,{name:"timing-dialog-start",onChange:i=>a(i)})}),ne(Mp,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?uf.repeat:void 0)}),o.repeat&&mt(pf,{children:[ne(pe,{title:"Repeat every",htmlFor:"timing-dialog-period",children:mt(or,{spacing:"xs",grow:!0,noWrap:!0,children:[ne(Fp,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:i=>l(parseInt(i.currentTarget.value,10)||1)}),ne(Bp,{id:"timing-dialog-periodUnit",name:"timing-dialog-periodUnit",defaultValue:o.repeat.periodUnit,onChange:i=>s(i.currentTarget.value),data:[{label:"second",value:"s"},{label:"minute",value:"min"},{label:"hour",value:"h"},{label:"day",value:"d"},{label:"week",value:"wk"},{label:"month",value:"mo"},{label:"year",value:"a"}]})]})}),o.repeat.periodUnit==="wk"&&ne(pe,{title:"Repeat on",children:ne(sf.Group,{multiple:!0,onChange:f,children:ne(or,{position:"apart",mt:"md",spacing:"xs",children:Op.map(i=>ne(sf,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),ne(or,{position:"right",children:ne(cf,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as N,jsxs as zp}from"react/jsx-runtime";function Le(e){let o=e.property,t=e.defaultPropertyType??o.type[0].code,r=e.name,a=e.defaultValue;if(o.max>1&&!e.arrayElement)return t===w.Attachment?N(yl,{name:r,defaultValue:a,onChange:e.onChange}):N(ff,{property:o,name:r,defaultValue:a,onChange:e.onChange});let n=o.type;return n.length>1?N(Up,{elementDefinitionTypes:n,...e}):N(xf,{elementDefinitionType:n[0],...e})}function Up(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=Gp(t);return zp(Np,{spacing:"xs",grow:!0,noWrap:!0,children:[N(Hp,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(l=>l.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),N(xf,{...e,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",qp(r.code)))}})]})}function xf(e){let o=e.property,t=e.elementDefinitionType.code,r=e.name,a=e.defaultValue,n=o.min!==void 0&&o.min>0;switch(t){case w.SystemString:case w.canonical:case w.string:case w.time:case w.uri:case w.url:return N(Fa,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:ae(e.outcome,r)});case w.date:return N(Fa,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:ae(e.outcome,r)});case w.dateTime:case w.instant:return N(be,{name:r,defaultValue:a,onChange:e.onChange,outcome:e.outcome});case w.decimal:case w.integer:case w.positiveInt:case w.unsignedInt:return N(Fa,{type:"number",step:t===w.decimal?"any":"1",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.valueAsNumber)}});case w.code:return N(qt,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.boolean:return N(Lp,{id:r,name:r,"data-testid":r,defaultChecked:!!a,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.checked)}});case w.markdown:return N(Vp,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)}});case w.Address:return N(zn,{name:r,defaultValue:a,onChange:e.onChange});case w.Annotation:return N(Wn,{name:r,defaultValue:a,onChange:e.onChange});case w.Attachment:return N(Ut,{name:r,defaultValue:a,onChange:e.onChange});case w.CodeableConcept:return N(Ol,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.Coding:return N(Zt,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.ContactDetail:return N(Nl,{name:r,defaultValue:a,onChange:e.onChange});case w.ContactPoint:return N(Yt,{name:r,defaultValue:a,onChange:e.onChange});case w.Extension:return N(Gl,{name:r,defaultValue:a,onChange:e.onChange});case w.HumanName:return N(Ul,{name:r,defaultValue:a,onChange:e.onChange});case w.Identifier:return N(Wl,{name:r,defaultValue:a,onChange:e.onChange});case w.Money:return N(Xl,{name:r,defaultValue:a,onChange:e.onChange});case w.Period:return N($l,{name:r,defaultValue:a,onChange:e.onChange});case w.Duration:case w.Quantity:return N(he,{name:r,defaultValue:a,onChange:e.onChange});case w.Range:return N(ct,{name:r,defaultValue:a,onChange:e.onChange});case w.Ratio:return N(Yl,{name:r,defaultValue:a,onChange:e.onChange});case w.Reference:return N(Fo,{name:r,defaultValue:a,targetTypes:Qp(o),onChange:e.onChange});case w.Timing:return N(mf,{name:r,defaultValue:a,onChange:e.onChange});case w.Dosage:case w.UsageContext:return N(pt,{typeName:t,defaultValue:a,onChange:e.onChange,outcome:e.outcome});default:return N(pt,{typeName:o.type[0].code,defaultValue:a,onChange:e.onChange,outcome:e.outcome})}}function Qp(e){return e?.type?.[0]?.targetProfile?.map(o=>o.split("/").pop())}import{jsx as xt,jsxs as $p}from"react/jsx-runtime";function pt(e){let[o,t]=Jp(e.defaultValue??{});function r(s){t(s),e.onChange&&e.onChange(s)}let a=e.typeName,n=Xp(a);if(!n)return $p("div",{children:[a,"\xA0not implemented"]});let l={type:a,value:o};return xt(Wp,{children:Object.entries(n.elements).map(([s,f])=>{if(s==="id"||Qt.includes(s)||zt.includes(s)&&f.path.split(".").length===2||!f.type)return null;let[i,u]=Te(l,s),d=f.min!==void 0&&f.min>0;return f.type.length===1&&f.type[0].code==="boolean"?xt(Kt,{title:If(s),description:f.description,htmlFor:s,children:xt(Le,{property:f,name:s,defaultValue:i,defaultPropertyType:u,outcome:e.outcome,onChange:(c,x)=>{r(it(o,s,x??s,f,c))}})},s):xt(pe,{title:If(s),description:f.description,withAsterisk:d,htmlFor:s,outcome:e.outcome,children:xt(Le,{property:f,name:s,defaultValue:i,defaultPropertyType:u,onChange:(c,x)=>{r(it(o,s,x??s,f,c))}})},s)})})}import{Button as wa,createStyles as Kp,Group as hf}from"@mantine/core";import{useMemo as _p,useState as Zp}from"react";function gf(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function tr(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as fe,jsxs as It}from"react/jsx-runtime";var Yp=Kp(e=>({table:{width:350,"& th":{fontWeight:"normal",fontSize:11,padding:8,textAlign:"center"},"& td":{padding:"2px 4px"},"& td button":{width:44,height:44,color:e.colors[e.primaryColor][5],fontSize:16,fontWeight:500,textAlign:"center",padding:0,backgroundColor:e.colors[e.primaryColor][0],border:0,borderRadius:"50%",cursor:"pointer"},"& td button:hover":{backgroundColor:e.colors[e.primaryColor][1]},"& td button:disabled":{backgroundColor:"transparent",cursor:"default",color:e.colors.gray[4],fontWeight:"normal"}}}));function Cf(e){let{classes:o}=Yp(),{onChangeMonth:t,onClick:r}=e,[a,n]=Zp(tr);function l(f){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+f),t(u),u})}let s=_p(()=>jp(a,e.slots),[a,e.slots]);return It("div",{children:[It(hf,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[fe("p",{style:{flex:1},children:gf(a)}),It(hf,{position:"right",spacing:"xs",children:[fe(wa,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),fe(wa,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),It("table",{className:o.table,children:[fe("thead",{children:It("tr",{children:[fe("th",{children:"SUN"}),fe("th",{children:"MON"}),fe("th",{children:"TUE"}),fe("th",{children:"WED"}),fe("th",{children:"THU"}),fe("th",{children:"FRI"}),fe("th",{children:"SAT"})]})}),fe("tbody",{children:s.map((f,i)=>fe("tr",{children:f.map((u,d)=>fe("td",{children:u&&fe(wa,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+d))},"week-"+i))})]})]})}function jp(e,o){let t=new Date(e.getFullYear(),e.getMonth()),r=[],a=[];for(let n=0;n<t.getDay();n++)a.push(void 0);for(;t.getMonth()===e.getMonth();)a.push({date:new Date(t.getTime()),available:ex(t,o)}),t.getDay()===6&&(r.push(a),a=[]),t.setDate(t.getDate()+1);if(t.getDay()!==0){for(let n=t.getDay();n<7;n++)a.push(void 0);r.push(a)}return r}function ex(e,o){for(let t of o){let r=new Date(t.start);if(r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate())return!0}return!1}import{Container as ox,createStyles as tx}from"@mantine/core";import{jsx as ax}from"react/jsx-runtime";var rx=tx(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Xe(e){let{children:o,...t}=e,{classes:r}=rx();return ax(ox,{className:r.root,...t,children:o})}import{ActionIcon as Hf,Center as oI,createStyles as tI,Group as rI,Loader as aI,Menu as He,ScrollArea as nI,TextInput as lI}from"@mantine/core";import{showNotification as fI,updateNotification as lr}from"@mantine/notifications";import{getReferenceString as ht,normalizeErrorString as Vf}from"@medplum/core";import{useCallback as fr,useEffect as sI,useRef as qf,useState as Gf}from"react";import{createStyles as Cx,Group as ar,List as Rf,Stack as bf,Text as Ce,Title as Pf}from"@mantine/core";import{capitalize as yx,formatCodeableConcept as vx,formatDateTime as Ea,formatObservationValue as Sx,isReference as Rx}from"@medplum/core";import{useEffect as bx,useState as Px}from"react";import{Blockquote as nx,createStyles as lx,Stack as fx}from"@mantine/core";import{jsx as yf}from"react/jsx-runtime";var sx=lx(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function Oa({value:e}){let{classes:o}=sx();return e?yf(fx,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&yf(nx,{classNames:{cite:o.noteCite,body:o.noteBody,root:o.noteRoot},cite:t.authorReference?.display||t.authorString,icon:null,children:t.text},`note-${t.text}`))}):null}import{Group as px}from"@mantine/core";import{Text as ix}from"@mantine/core";import{getDisplayString as ux,isOk as cx,normalizeErrorString as dx}from"@medplum/core";import{useState as mx}from"react";import{jsx as vf}from"react/jsx-runtime";function Be(e){let{value:o,link:t,...r}=e,[a,n]=mx(),l=G(o,n),s;if(a&&!cx(a))s=`[${dx(a)}]`;else if(l)s=ux(l);else return null;return t?vf(j,{to:o,...r,children:s}):vf(ix,{component:"span",...r,children:s})}import{jsx as Sf,jsxs as xx}from"react/jsx-runtime";function Je(e){return xx(px,{spacing:"xs",children:[Sf(le,{size:24,radius:12,value:e.value,link:e.link}),Sf(Be,{value:e.value,link:e.link})]})}import{Badge as Ix}from"@mantine/core";import{jsx as hx}from"react/jsx-runtime";var gx={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"};function rr(e){return hx(Ix,{color:gx[e.status],children:e.status})}import{Fragment as gt,jsx as S,jsxs as se}from"react/jsx-runtime";var Df=Cx(e=>({table:{border:`0.1px solid ${e.colors.gray[5]}`,borderCollapse:"collapse","& td, & th":{border:`0.1px solid ${e.colors.gray[5]}`,padding:4}},criticalRow:{background:e.colorScheme==="dark"?e.colors.red[7]:e.colors.red[1],border:`0.1px solid ${e.colors.red[5]}`,color:e.colors.red[5],fontWeight:500,"& td":{border:`0.1px solid ${e.colors.red[5]}`}},noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));La.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function La(e){let o=v(),t=G(e.value),[r,a]=Px();if(bx(()=>{t?.specimen&&Promise.allSettled(t.specimen.map(l=>o.readReference(l))).then(l=>l.filter(s=>s.status==="fulfilled").map(s=>s.value)).then(a).catch(console.error)},[o,t]),!t)return null;let n=r?.flatMap(l=>l.note||[])||[];if(t.presentedForm&&t.presentedForm.length>0){let l=t.presentedForm[0];l.contentType?.startsWith("text/plain")&&l.data&&n.push({text:window.atob(l.data)})}return se(bf,{children:[S(Pf,{children:"Diagnostic Report"}),S(Dx,{value:t}),r&&!e.hideSpecimenInfo&&kx(r),t.result&&S(Tx,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&S(Oa,{value:n})]})}function Dx({value:e}){return se(ar,{mt:"md",spacing:30,children:[e.subject&&se("div",{children:[S(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),S(Ce,{children:S(Je,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>se("div",{children:[S(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),S(Ce,{children:S(Je,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>se("div",{children:[S(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),S(Ce,{children:S(Je,{value:o,link:!0})})]},o.reference)),e.issued&&se("div",{children:[S(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),S(Ce,{children:Ea(e.issued)})]}),e.status&&se("div",{children:[S(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),S(Ce,{children:yx(e.status)})]})]})}function kx(e){return se(bf,{spacing:"xs",children:[S(Pf,{order:2,size:"h6",children:"Specimens"}),S(Rf,{type:"ordered",children:e?.map(o=>S(Rf.Item,{ml:"sm",children:se(ar,{spacing:20,children:[se(ar,{spacing:5,children:[S(Ce,{fw:500,children:"Collected:"})," ",Ea(o.collection?.collectedDateTime)]}),se(ar,{spacing:5,children:[S(Ce,{fw:500,children:"Received:"})," ",Ea(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Tx(e){let{classes:o}=Df();return se("table",{className:o.table,children:[S("thead",{children:se("tr",{children:[S("th",{children:"Test"}),S("th",{children:"Value"}),S("th",{children:"Reference Range"}),S("th",{children:"Interpretation"}),S("th",{children:"Category"}),S("th",{children:"Performer"}),S("th",{children:"Status"})]})}),S("tbody",{children:S(kf,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function kf(e){return S(gt,{children:e.value?.map(o=>S(Bx,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${Rx(o)?o.reference:o.id}`))})}function Bx(e){let{classes:o,cx:t}=Df(),r=G(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=Fx(r);return se(gt,{children:[se("tr",{className:t({[o.criticalRow]:n}),children:[S("td",{rowSpan:a?2:1,children:S(j,{to:r,children:S(Ao,{value:r.code})})}),S("td",{children:S(Ax,{value:r})}),S("td",{children:S(Mx,{value:r.referenceRange})}),S("td",{children:r.interpretation&&r.interpretation.length>0&&S(Ao,{value:r.interpretation[0]})}),S("td",{children:r.category&&r.category.length>0&&S(gt,{children:r.category.map(l=>S("div",{children:S(Ao,{value:l})},`category-${vx(l)}`))})}),S("td",{children:r.performer?.map(l=>S(lo,{value:l},l.reference))}),S("td",{children:r.status&&S(rr,{status:r.status})})]}),r.hasMember&&S(kf,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&S("tr",{children:S("td",{colSpan:6,children:S(Oa,{value:r.note})})})]})}function Ax(e){let o=e.value;return S(gt,{children:Sx(o)})}function Mx(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?S(gt,{children:o.text}):S(Xt,{value:o}):null}function Fx(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as wx,Paper as Ox,useComponentDefaultProps as Ex}from"@mantine/core";import{jsx as Hx}from"react/jsx-runtime";var Lx=wx((e,{width:o,fill:t})=>({paper:{maxWidth:o,margin:`${e.spacing.xl} auto`,padding:t?0:e.spacing.md,"@media (max-width: 800px)":{padding:t?0:8},"& img":{width:"100%",maxWidth:"100%"},"& video":{width:"100%",maxWidth:"100%"}}})),Nx={shadow:"xs",radius:"md",withBorder:!0};function wo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Ex("Panel",Nx,e),{classes:s,cx:f}=Lx({width:r,fill:a},{name:"Panel",unstyled:n});return Hx(Ox,{className:f(s.paper,o),...l,children:t})}import{createStyles as Vx}from"@mantine/core";import{capitalize as qx,evalFhirPathTyped as Tf,getSearchParameterDetails as Gx,toTypedValue as Bf}from"@medplum/core";import{useEffect as Ux,useState as Qx}from"react";import{createPatch as zx}from"rfc6902";import{jsx as Ne,jsxs as nr}from"react/jsx-runtime";var Wx=Vx(e=>({root:{borderCollapse:"collapse",width:"100%","& tr":{borderTop:`0.1px solid ${e.colors.gray[3]}`},"& th, & td":{padding:`${e.spacing.sm} ${e.spacing.sm}`,verticalAlign:"top"}},removed:{color:e.colors.red[7],fontFamily:"monospace",textDecoration:"line-through",whiteSpace:"pre-wrap"},added:{color:e.colors.green[7],fontFamily:"monospace",whiteSpace:"pre-wrap"}}));function Mf(e){let{classes:o}=Wx(),t=v(),[r,a]=Qx(!1);if(Ux(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=zx(e.original,e.revised),l=[Bf(e.original)],s=[Bf(e.revised)];return nr("table",{className:o.root,children:[Ne("thead",{children:nr("tr",{children:[Ne("th",{}),Ne("th",{children:"Before"}),Ne("th",{children:"After"})]})}),Ne("tbody",{children:n.map(f=>{if(f.path.startsWith("/meta"))return null;let i=f.path,u=Xx(i),c=Gx(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],x=!!c?.isArray,h=f.op==="add"?void 0:Tf(u,l)?.[0],I=f.op==="remove"?void 0:Tf(u,s)?.[0];return nr("tr",{children:[nr("td",{children:[qx(f.op)," ",u]}),Ne("td",{className:o.removed,children:h&&Ne(re,{property:c,propertyType:h.type,value:Af(h.value,x),ignoreMissingValues:!0})}),Ne("td",{className:o.added,children:I&&Ne(re,{property:c,propertyType:I.type,value:Af(I.value,x),ignoreMissingValues:!0})})]},`op-${f.op}-${f.path}`)})})]})}function Xx(e){let o=e.split("/").filter(Boolean),t="";for(let r=0;r<o.length;r++){let a=o[r];a==="-"?t+=".last()":/^\d+$/.test(a)?t+=`[${a}]`:(r>0&&(t+="."),t+=a)}return t}function Af(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as Jx,useState as $x}from"react";import{jsx as Kx}from"react/jsx-runtime";function Na(e){let o=v(),t=G(e.value),[r,a]=$x(!1);return Jx(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:Kx(st,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as _x,Group as Zx,Menu as Ff,Text as Ha}from"@mantine/core";import{formatDateTime as Yx,getReferenceString as jx}from"@medplum/core";import{Fragment as eI,jsx as ye,jsxs as Oo}from"react/jsx-runtime";function wf(e){return ye(Xe,{children:e.children})}function $e(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,s=e.dateTime??o.meta?.lastUpdated;return Oo(wo,{"data-testid":"timeline-item",fill:!0,...n,children:[Oo(Zx,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[ye(le,{value:l,link:!0,size:"md"}),Oo("div",{style:{flex:1},children:[ye(Ha,{size:"sm",children:ye(Be,{color:"dark",weight:500,value:l,link:!0})}),Oo(Ha,{size:"xs",children:[ye(j,{color:"dimmed",to:e.resource,children:Yx(s)}),ye(Ha,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),ye(j,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&Oo(Ff,{position:"bottom-end",shadow:"md",width:200,children:[ye(Ff.Target,{children:ye(_x,{radius:"xl","aria-label":`Actions for ${jx(e.resource)}`,children:ye(ra,{})})}),a]})]}),Oo(vo,{children:[r&&ye("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&ye(eI,{children:e.children})]})]})}function Lf(e,o){e.sort((t,r)=>{let a=Of(t,o),n=Of(r,o);return a>n?1:a<n?-1:Ef(t,o)-Ef(r,o)})}function Of(e,o){if(!Nf(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Ef(e,o){if(!Nf(e,o)){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 t=e.meta?.lastUpdated;return t?new Date(t).getTime():0}function Nf(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as gI,jsx as P,jsxs as Ct}from"react/jsx-runtime";var iI=tI(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function Ke(e){let o=v(),t=Ue(),r=o.getProfile(),a=qf(null),n=G(e.value),[l,s]=Gf(),[f,i]=Gf([]),u=e.loadTimelineResources,d=qf(f);d.current=f;let c=fr(g=>{Lf(g,n),g.reverse(),i(g)},[n]),x=fr(g=>{let L=[];for(let De of g){if(De.status!=="fulfilled")continue;let C=De.value;if(C.type==="history"&&s(C),C.entry)for(let H of C.entry)L.push(H.resource)}c(L)},[c]),h=fr(g=>c([...d.current,g]),[c]),I=fr(()=>{let g,L;"resourceType"in e.value?(g=e.value.resourceType,L=e.value.id):[g,L]=e.value.reference?.split("/"),u(o,g,L).then(x).catch(console.log)},[o,e.value,u,x]);sI(()=>I(),[I]);function R(g){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,g)).then(L=>h(L)).catch(console.log)}function D(g){!n||!e.createMedia||o.createResource(e.createMedia(n,r,g)).then(L=>h(L)).then(()=>lr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:P(et,{size:16}),autoClose:2e3})).catch(L=>lr({id:"upload-notification",color:"red",title:"Upload error",message:Vf(L),icon:P(Ot,{size:16}),autoClose:2e3}))}function b(g,L){return o.updateResource({...g,priority:L})}function k(g){b(g,"stat").then(I).catch(console.log)}function Q(g){b(g,"routine").then(I).catch(console.log)}function y(g){t(`/${g.resourceType}/${g.id}`)}function F(g){t(`/${g.resourceType}/${g.id}/edit`)}function $(g){t(`/${g.resourceType}/${g.id}/delete`)}function Z(g){t(`/${g.resourceType}/${g.id}/_history/${g.meta?.versionId}`)}function Me(){fI({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function je(g){lr({id:"upload-notification",loading:!0,title:"Uploading...",message:II(g),autoClose:!1,withCloseButton:!1})}function te(g){lr({id:"upload-notification",color:"red",title:"Upload error",message:Vf(g),icon:P(Ot,{size:16}),autoClose:2e3})}return n?Ct(wf,{children:[e.createCommunication&&P(wo,{children:P(W,{testid:"timeline-form",onSubmit:g=>{R(g.text);let L=a.current;L&&(L.value="",L.focus())},children:Ct(rI,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[P(le,{value:r}),P(lI,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),P(Hf,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:P(ia,{size:16})}),P(Bo,{onUpload:D,onUploadStart:Me,onUploadProgress:je,onUploadError:te,children:g=>P(Hf,{...g,radius:"xl",color:"blue",variant:"filled",children:P(ot,{size:16})})})]})})}),f.map(g=>{if(!g)return null;let L=`${g.resourceType}/${g.id}/${g.meta?.versionId}`;if(g.resourceType===n.resourceType&&g.id===n.id)return P(uI,{history:l,resource:g,onDetails:Z},L);switch(g.resourceType){case"AuditEvent":return P(pI,{resource:g,onDetails:y},L);case"Communication":return P(dI,{resource:g,onPin:g.priority!=="stat"?k:void 0,onUnpin:g.priority==="stat"?Q:void 0,onDetails:y,onEdit:F,onDelete:$},L);case"DiagnosticReport":return P(xI,{resource:g,onDetails:y,onEdit:F,onDelete:$},L);case"Media":return P(mI,{resource:g,onDetails:y,onEdit:F,onDelete:$},L);default:return P($e,{resource:g,padding:!0,children:P(Na,{value:g,ignoreMissingValues:!0})},L)}})]}):P(oI,{style:{width:"100%",height:"100%"},children:P(aI,{})})}function Eo(e){return Ct(He.Dropdown,{children:[P(He.Label,{children:"Resource"}),e.onPin&&P(He.Item,{icon:P(ua,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${ht(e.resource)}`,children:"Pin"}),e.onUnpin&&P(He.Item,{icon:P(ca,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${ht(e.resource)}`,children:"Unpin"}),e.onDetails&&P(He.Item,{icon:P(fa,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${ht(e.resource)}`,children:"Details"}),e.onEdit&&P(He.Item,{icon:P(aa,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${ht(e.resource)}`,children:"Edit"}),e.onDelete&&Ct(gI,{children:[P(He.Divider,{}),P(He.Label,{children:"Danger zone"}),P(He.Item,{color:"red",icon:P(at,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${ht(e.resource)}`,children:"Delete"})]})]})}function uI(e){let o=cI(e.history,e.resource);return o?P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(Mf,{original:o,revised:e.resource})}):Ct($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:[P("h3",{children:"Created"}),P(Na,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function cI(e,o){let t=e.entry,r=t.findIndex(a=>a.resource?.meta?.versionId===o.meta?.versionId);if(!(r>=t.length-1))return t[r+1].resource}function dI(e){let{classes:o}=iI(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return P($e,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:P(Eo,{...e}),children:P("p",{children:e.resource.payload?.[0]?.contentString})})}function mI(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return P($e,{resource:e.resource,padding:!!t,popupMenuItems:P(Eo,{...e}),children:P(ke,{value:e.resource.content})})}function pI(e){return P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(nI,{children:P("pre",{children:e.resource.outcomeDesc})})})}function xI(e){return P($e,{resource:e.resource,padding:!0,popupMenuItems:P(Eo,{...e}),children:P(La,{value:e.resource})})}function II(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Va(e.loaded)} / ${Va(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Va(e.loaded)}`}function Va(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as hI}from"react/jsx-runtime";function KF(e){return hI(Ke,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as Uf}from"react/jsx-runtime";function sr(e){let{children:o,...t}=e;return Uf(Xe,{children:Uf(wo,{...t,children:o})})}import{createReference as ir}from"@medplum/core";import{jsx as CI}from"react/jsx-runtime";function fw(e){return CI(Ke,{value:e.encounter,loadTimelineResources:async(o,t,r)=>Promise.allSettled([o.readHistory("Encounter",r),o.search("Communication","encounter=Encounter/"+r),o.search("Media","encounter=Encounter/"+r)]),createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",encounter:ir(o),subject:o.subject,sender:ir(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:ir(o),subject:o.subject,operator:ir(t),issued:new Date().toISOString(),content:r})})}import{Button as Hg,Loader as Vg,Table as qg}from"@mantine/core";import{normalizeOperationOutcome as Gg}from"@medplum/core";import{memo as Ug,useEffect as Rs,useRef as bs,useState as gr}from"react";import{evalFhirPath as yI}from"@medplum/core";import{jsx as vI}from"react/jsx-runtime";function Qf(e){let o;try{o=yI(e.path,e.resource)}catch(t){return console.warn("FhirPathDisplay:",t),null}if(o.length>1)throw new Error(`Component "path" for "FhirPathDisplay" must resolve to a single element. Received ${o.length} elements [${JSON.stringify(o,null,2)}]`);return vI(re,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as vg,Button as qo,Center as xr,createStyles as Sg,Group as Ir,Loader as Rg,Menu as ys,Pagination as bg,Table as Pg,Text as _a,UnstyledButton as Dg}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as en,formatSearchQuery as kg}from"@medplum/core";import{memo as Tg,useCallback as vs,useEffect as Ss,useRef as Bg,useState as Za}from"react";import{Box as SI,Button as RI,Modal as bI,Text as PI}from"@mantine/core";import{jsx as ur,jsxs as Wf}from"react/jsx-runtime";function Xf(e){return Wf(bI,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Wf(SI,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&ur(zf,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&ur(zf,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),ur(PI,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function zf(e){return ur(RI,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as LI,Group as NI,Modal as HI,MultiSelect as VI,Stack as qI}from"@mantine/core";import{getDataType as GI,getSearchParameters as UI,stringify as QI}from"@medplum/core";import{useEffect as zI,useMemo as WI,useRef as XI,useState as fs}from"react";import{capitalize as DI,DEFAULT_SEARCH_COUNT as kI,evalFhirPathTyped as TI,formatDateTime as BI,Operator as A}from"@medplum/core";import{Fragment as EI,jsx as qa}from"react/jsx-runtime";var AI={string:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],fulltext:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],token:[A.EQUALS,A.NOT],reference:[A.EQUALS,A.NOT],numeric:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],quantity:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],date:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY],datetime:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY]},MI={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",contains:"contains",exact:"exact",text:"text",not:"not",above:"above",below:"below",in:"in","not-in":"not in","of-type":"of type",missing:"missing",identifier:"identifier",iterate:"iterate"};function yt(e,o){return{...e,filters:o,offset:0,name:void 0}}function Rw(e){return yt(e,[])}function cr(e,o){return yt(e,(e.filters??[]).filter(t=>t.code!==o))}function Lo(e,o,t,r,a){a&&(e=cr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),yt(e,n)}function bw(e,o){if(e.fields?.includes(o))return e;let t=[];return e.fields&&t.push(...e.fields),t.push(o),{...e,fields:t,name:void 0}}function $f(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function Kf(e,o){return Ga(e,o,-1)}function _f(e,o){return Ga(e,o,0)}function Zf(e,o){return Ga(e,o,1)}function Ga(e,o,t){let r=new Date;r.setDate(r.getDate()+t),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setDate(a.getDate()+1),a.setTime(a.getTime()-1),Qa(e,o,r,a)}function Yf(e,o){return Ua(e,o,-1)}function jf(e,o){return Ua(e,o,0)}function es(e,o){return Ua(e,o,1)}function Ua(e,o,t){let r=new Date;r.setMonth(r.getMonth()+t),r.setDate(1),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setMonth(a.getMonth()+1),a.setDate(1),a.setHours(0,0,0,0),a.setTime(a.getTime()-1),Qa(e,o,r,a)}function os(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Qa(e,o,t,new Date)}function Qa(e,o,t,r){return e=cr(e,o),e=Jf(e,o,A.GREATER_THAN_OR_EQUALS,t),e=Jf(e,o,A.LESS_THAN_OR_EQUALS,r),e}function Jf(e,o,t,r){return Lo(e,o,t,r.toISOString())}function za(e,o,t=!0){return Lo(e,o,A.MISSING,t.toString())}function FI(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function ts(e,o){let t=e.count??kI,r=(o-1)*t;return FI(e,r)}function Wa(e,o,t){return o===rs(e)&&t!==void 0&&t===as(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function Pw(e,o){let t=!1;return rs(e)===o&&(t=!as(e)),Wa(e,o,t)}function rs(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function as(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function ns(e){return AI[e.type]}function vt(e){return MI[e]??""}function ve(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(DI).join(" "))}function ls(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?BI(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?wI(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?OI(e,o.searchParams[0]):null}function wI(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=Te({type:e.resourceType,value:e},t);return r?qa(re,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function OI(e,o){let t=TI(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:qa(EI,{children:t.map((r,a)=>qa(re,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as St,jsxs as $I}from"react/jsx-runtime";function ss(e){let o=XI(!1),[t,r]=fs({search:JSON.parse(QI(e.search))}),[a,n]=fs(!1);zI(()=>{r({search:e.search})},[e.search]);let l=WI(()=>{if(!e.visible)return[];let f=e.search.resourceType,i=GI(f),u=UI(f);return JI(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:ve(d)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function s(f){r({search:{...t.search,fields:f}})}return St(HI,{title:"Fields",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>{e.onCancel()},size:"auto",withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{o.current=a},onClick:()=>{o.current||e.onCancel(),o.current=!1},children:St("div",{"data-testid":"overlay-child"})},children:$I(qI,{children:[St(VI,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:l,value:t.search.fields??[],onChange:s,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),St(NI,{position:"right",children:St(LI,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function JI(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(ve(n));if(o)for(let n of Object.keys(o)){let l=ve(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as Rt,Group as tg,Modal as rg,NativeSelect as cs}from"@mantine/core";import{getSearchParameters as ag,stringify as ds}from"@medplum/core";import{useEffect as ng,useRef as ps,useState as $a}from"react";import{formatDateTime as KI,getSearchParameterDetails as _I,globalSchema as ZI,Operator as is,SearchParameterType as YI}from"@medplum/core";import{Fragment as us,jsx as Xa}from"react/jsx-runtime";function dr(e){let{resourceType:o,filter:t}=e,r=ZI.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===is.EQUALS||t.operator===is.NOT_EQUALS))return Xa(Be,{value:{reference:t.value}});let a=_I(o,r);if(t.code==="_lastUpdated"||a.type===YI.DATETIME)return Xa(us,{children:KI(t.value)})}return Xa(us,{children:t.value})}import{Checkbox as jI,TextInput as Ja}from"@mantine/core";import{getSearchParameterDetails as eg,SearchParameterType as No}from"@medplum/core";import{jsx as fo}from"react/jsx-runtime";function mr(e){let o=eg(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case No.REFERENCE:return fo(Fo,{name:t,defaultValue:e.defaultValue?{reference:e.defaultValue}:void 0,targetTypes:e.searchParam.target,autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(r.reference):e.onChange("")}});case No.BOOLEAN:return fo(jI,{name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultChecked:e.defaultValue==="true",autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.checked.toString())});case No.DATE:return fo(Ja,{type:"date",name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value)});case No.DATETIME:return fo(be,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case No.NUMBER:return fo(Ja,{type:"number",name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value)});case No.QUANTITY:return fo(he,{name:t,defaultValue:og(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return fo(Ja,{name:t,"data-autofocus":e.autoFocus,"data-testid":t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:r=>e.onChange(r.currentTarget.value),placeholder:"Search value"})}}function og(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as q,jsxs as Ve}from"react/jsx-runtime";function xs(e){let[o,t]=$a(JSON.parse(ds(e.search))),[r,a]=$a(-1),n=ps(o);n.current=o,ng(()=>{t(JSON.parse(ds(e.search)))},[e.search]);function l(u){t(Lo(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let s=e.search.resourceType,f=ag(s)??{},i=o.filters||[];return Ve(rg,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[q("div",{children:Ve("table",{children:[Ve("colgroup",{children:[q("col",{style:{width:200}}),q("col",{style:{width:200}}),q("col",{style:{width:380}}),q("col",{style:{width:120}})]}),q("thead",{children:Ve("tr",{children:[q("th",{children:"Field"}),q("th",{children:"Operation"}),q("th",{children:"Value"}),q("th",{children:"Actions"})]})}),Ve("tbody",{children:[i.map((u,d)=>d===r?q(ms,{resourceType:s,searchParams:f,defaultValue:u,okText:"Save",onOk:c=>{let x=[...i];x[d]=c,t(yt(n.current,x)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):q(lg,{resourceType:s,searchParams:f,filter:u,onEdit:()=>a(d),onDelete:()=>t($f(n.current,d))},`filter-${u.code}-${u.operator}-${u.value}-display`)),q(ms,{resourceType:s,searchParams:f,okText:"Add",onOk:l})]})]})}),q(tg,{position:"right",mt:"xl",children:q(Rt,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function lg(e){let{filter:o}=e;return Ve("tr",{children:[q("td",{children:ve(o.code)}),q("td",{children:vt(o.operator)}),q("td",{children:q(dr,{resourceType:e.resourceType,filter:o})}),Ve("td",{children:[q(Rt,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),q(Rt,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function ms(e){let[o,t]=$a(e.defaultValue??{}),r=ps(o);r.current=o;function a(i){t({...r.current,code:i})}function n(i){t({...r.current,operator:i})}function l(i){t({...r.current,value:i})}let s=e.searchParams[o.code],f=s&&ns(s);return Ve("tr",{children:[q("td",{children:q(cs,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:ve(i)}))]})}),q("td",{children:f&&q(cs,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...f.map(i=>({value:i,label:vt(i)}))]})}),q("td",{children:s&&o.operator&&q(mr,{resourceType:e.resourceType,searchParam:s,defaultValue:o.value,onChange:l})}),Ve("td",{children:[o.code&&o.operator&&q(Rt,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&q(Rt,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as fg,Grid as Ka,Modal as sg}from"@mantine/core";import{useState as ig}from"react";import{jsx as Ho,jsxs as ug}from"react/jsx-runtime";function Is(e){let[o,t]=ig(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return Ho(sg,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:Ho(W,{onSubmit:r,children:ug(Ka,{children:[Ho(Ka.Col,{span:10,children:Ho(mr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),Ho(Ka.Col,{span:2,children:Ho(fg,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as T}from"@mantine/core";import{Operator as ee}from"@medplum/core";import{Fragment as hs,jsx as p,jsxs as Vo}from"react/jsx-runtime";function gs(e){if(!e.searchParams)return null;function o(n,l){a(Wa(e.search,n.code,l))}function t(n){a(cr(e.search,n.code))}function r(n,l){e.onPrompt(n,{code:n.code,operator:l,value:""})}function a(n){e.onChange(n)}return e.searchParams.length===1?p(cg,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):p(T.Dropdown,{children:e.searchParams.map(n=>p(T.Item,{children:ve(n.code)},n.code))})}function cg(e){switch(e.searchParam.type){case"date":return p(dg,{...e});case"number":case"quantity":return p(mg,{...e});case"reference":return p(pg,{...e});case"string":case"token":case"uri":return p(xg,{...e});default:return Vo(hs,{children:["Unknown search param type: ",e.searchParam.type]})}}function dg(e){let{searchParam:o}=e,t=o.code;return Vo(T.Dropdown,{children:[p(T.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),p(T.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),p(T.Divider,{}),p(T.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(T.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT_EQUALS),children:"Does not equal..."}),p(T.Divider,{}),p(T.Item,{icon:p(Lt,{size:14}),onClick:()=>e.onPrompt(o,ee.ENDS_BEFORE),children:"Before..."}),p(T.Item,{icon:p(Et,{size:14}),onClick:()=>e.onPrompt(o,ee.STARTS_AFTER),children:"After..."}),p(T.Item,{icon:p(Kr,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Between..."}),p(T.Divider,{}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(Zf(e.search,t)),children:"Tomorrow"}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(_f(e.search,t)),children:"Today"}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(Kf(e.search,t)),children:"Yesterday"}),p(T.Divider,{}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(es(e.search,t)),children:"Next Month"}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(jf(e.search,t)),children:"This Month"}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(Yf(e.search,t)),children:"Last Month"}),p(T.Divider,{}),p(T.Item,{icon:p(we,{size:14}),onClick:()=>e.onChange(os(e.search,t)),children:"Year to date"}),p(pr,{...e})]})}function mg(e){let{searchParam:o}=e;return Vo(T.Dropdown,{children:[p(T.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),p(T.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),p(T.Divider,{}),p(T.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(T.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT_EQUALS),children:"Does not equal..."}),p(T.Divider,{}),p(T.Item,{icon:p(Et,{size:14}),onClick:()=>e.onPrompt(o,ee.GREATER_THAN),children:"Greater than..."}),p(T.Item,{icon:p(yo,{size:14}),onClick:()=>e.onPrompt(o,ee.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),p(T.Item,{icon:p(Lt,{size:14}),onClick:()=>e.onPrompt(o,ee.LESS_THAN),children:"Less than..."}),p(T.Item,{icon:p(yo,{size:14}),onClick:()=>e.onPrompt(o,ee.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),p(pr,{...e})]})}function pg(e){let{searchParam:o}=e;return Vo(T.Dropdown,{children:[p(T.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(T.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT),children:"Does not equal..."}),p(pr,{...e})]})}function xg(e){let{searchParam:o}=e;return Vo(T.Dropdown,{children:[p(T.Item,{icon:p(tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),p(T.Item,{icon:p(rt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),p(T.Divider,{}),p(T.Item,{icon:p(Co,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Equals..."}),p(T.Item,{icon:p(ho,{size:14}),onClick:()=>e.onPrompt(o,ee.NOT),children:"Does not equal..."}),p(T.Divider,{}),p(T.Item,{icon:p(Zr,{size:14}),onClick:()=>e.onPrompt(o,ee.CONTAINS),children:"Contains..."}),p(T.Item,{icon:p(_r,{size:14}),onClick:()=>e.onPrompt(o,ee.EQUALS),children:"Does not contain..."}),p(pr,{...e})]})}function pr(e){let{searchParam:o}=e,t=o.code;return Vo(hs,{children:[p(T.Divider,{}),p(T.Item,{icon:p(Jr,{size:14}),onClick:()=>e.onChange(za(e.search,t)),children:"Missing"}),p(T.Item,{icon:p(Xr,{size:14}),onClick:()=>e.onChange(za(e.search,t,!1)),children:"Not missing"}),p(T.Divider,{}),p(T.Item,{icon:p(ha,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Ig,getSearchParameter as gg,getSearchParameterDetails as hg,getSearchParameters as Cg}from"@medplum/core";function Cs(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(yg(o,r));return t}function yg(e,o){if(o==="_lastUpdated")return{name:"_lastUpdated",searchParams:[{resourceType:"SearchParameter",base:["Resource"],code:"_lastUpdated",name:"_lastUpdated",type:"date",expression:"Resource.meta.lastUpdated"}]};if(o==="meta.versionId")return{name:"meta.versionId",searchParams:[{resourceType:"SearchParameter",base:["Resource"],code:"_versionId",name:"_versionId",type:"token",expression:"Resource.meta.versionId"}]};let t=Ig(e,o),r=gg(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=Cg(e),n;if(a){let l=new RegExp(`${e}\\.${o.replaceAll("[x]","")}([^\\w-]|$)`);n=Object.values(a).filter(s=>!!s.expression&&l.test(s?.expression)),n.length===0&&(n=void 0)}return{name:o,elementDefinition:t,searchParams:n}}if(r){let a=hg(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as Ng,jsx as B,jsxs as xe}from"react/jsx-runtime";var Ya=class extends Event{constructor(t){super("change");this.definition=t}},ja=class extends Event{constructor(t){super("load");this.response=t}},so=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},Ag=Sg(e=>({root:{maxWidth:"100%",overflow:"auto",textAlign:"left",marginBottom:"20px"},table:{cursor:"pointer"},tr:{"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[7]:e.colors.gray[0]}},th:{padding:"0 !important"},control:{width:"100%",padding:`${e.spacing.xs} ${e.spacing.md}`,"&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[6]:e.colors.gray[0]}},icon:{width:21,height:21,borderRadius:21}}));function Mg(e){let{classes:o}=Ag(),t=v(),[r,a]=Za(!1),[n,l]=Za(),{search:s,onLoad:f}=e,[i,u]=Za({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),d=Bg(i);d.current=i;let c=s.total??"accurate",x=vs(C=>{l(void 0),t.search(s.resourceType,kg({...s,total:c,fields:void 0}),C).then(H=>{u({...d.current,searchResponse:H}),f&&f(new ja(H))}).catch(H=>{u({...d.current,searchResponse:void 0}),l(H)})},[t,s,c,f]),h=vs(()=>{u({...d.current,searchResponse:void 0}),x({cache:"reload"})},[x]);Ss(()=>{x()},[x]);function I(C,H){C.stopPropagation();let Y=C.target.checked,_={...d.current.selected};Y?_[H]=!0:delete _[H],u({...d.current,selected:_})}function R(C){C.stopPropagation();let Fe=C.target.checked,Y={},_=d.current.searchResponse;Fe&&_?.entry&&_.entry.forEach(Ie=>{Ie.resource?.id&&(Y[Ie.resource.id]=!0)}),u({...d.current,selected:Y})}function D(){let C=d.current;if(!C.searchResponse?.entry||C.searchResponse.entry.length===0)return!1;for(let H of C.searchResponse.entry)if(H.resource?.id&&!C.selected[H.resource.id])return!1;return!0}function b(C){e.onChange&&e.onChange(new Ya(C))}function k(C,H){if(Ht(C.target)||C.button===2)return;O(C);let Fe=C.button===1||C.ctrlKey||C.metaKey;!Fe&&e.onClick&&e.onClick(new so(H,C)),Fe&&e.onAuxClick&&e.onAuxClick(new so(H,C))}function Q(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(Ss(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return B(xr,{style:{width:"100%",height:"100%"},children:B(Rg,{})});let y=e.checkboxesEnabled,F=Cs(s),$=s.resourceType,Z=i.searchResponse,je=Z?.entry?.map(C=>C.resource),te="subtle",g="gray",L=16,De=window.innerWidth<768;return xe("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&xe(Ir,{position:"apart",mb:"xl",children:[xe(Ir,{spacing:2,children:[B(qo,{compact:!0,variant:te,color:g,leftIcon:B(ea,{size:L}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),B(qo,{compact:!0,variant:te,color:g,leftIcon:B(la,{size:L}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(na,{size:L}),onClick:e.onNew,children:"New..."}),!De&&Q()&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(ga,{size:L}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!De&&e.onDelete&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B(at,{size:L}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!De&&e.onBulk&&B(qo,{compact:!0,variant:te,color:g,leftIcon:B($r,{size:L}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),xe(Ir,{spacing:2,children:[Z&&xe(_a,{size:"xs",color:"dimmed",children:[Eg(s,Z.total),"-",Lg(s,Z.total)," of"," ",`${c==="estimate"?"~":""}${Z.total?.toLocaleString()}`]}),B(vg,{title:"Refresh",onClick:h,children:B(ma,{size:"1.125rem"})})]})]}),xe(Pg,{className:o.table,children:[xe("thead",{children:[xe("tr",{children:[y&&B("th",{children:B("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:D(),onChange:C=>R(C)})}),F.map(C=>B("th",{children:xe(ys,{shadow:"md",width:240,position:"bottom-end",children:[B(ys.Target,{children:B(Dg,{className:o.control,children:xe(Ir,{position:"apart",noWrap:!0,children:[B(_a,{weight:500,size:"sm",children:ve(C.name)}),B(xr,{className:o.icon,children:B(Qr,{size:14,stroke:1.5})})]})})}),B(gs,{search:e.search,searchParams:C.searchParams,onPrompt:(H,Fe)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:Fe})},onChange:H=>{b(H)}})]})},C.name))]}),!e.hideFilters&&xe("tr",{children:[y&&B("th",{}),F.map(C=>B("th",{children:C.searchParams&&B(Fg,{resourceType:$,searchParams:C.searchParams,filters:e.search.filters})},C.name))]})]}),B("tbody",{children:je?.map(C=>C&&xe("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>k(H,C),onAuxClick:H=>k(H,C),children:[y&&B("td",{children:B("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${C.id}`,checked:!!i.selected[C.id],onChange:H=>I(H,C.id)})}),F.map(H=>B("td",{children:ls(C,H)},H.name))]},C.id))})]}),je?.length===0&&B(Xe,{children:B(xr,{style:{height:150},children:B(_a,{size:"xl",color:"dimmed",children:"No results"})})}),Z?.total!==void 0&&Z.total>0&&B(xr,{m:"md",p:"md",children:B(bg,{value:wg(s),total:Og(s,Z.total),onChange:C=>b(ts(s,C)),getControlProps:C=>{switch(C){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&B("div",{"data-testid":"search-error",children:B("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),B(ss,{search:e.search,visible:d.current.fieldEditorVisible,onOk:C=>{b(C),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),B(xs,{search:e.search,visible:d.current.filterEditorVisible,onOk:C=>{b(C),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),B(Xf,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),B(Is,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?ve(i.filterDialogSearchParam.code):"",resourceType:$,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:C=>{b(Lo(e.search,C.code,C.operator,C.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var UO=Tg(Mg);function Fg(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?B("span",{children:"no filters"}):B(Ng,{children:o.map(t=>xe("div",{children:[vt(t.operator),"\xA0",B(dr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function wg(e){return Math.floor((e.offset??0)/(e.count??en))+1}function Og(e,o){let t=e.count??en;return Math.ceil(o/t)}function Eg(e,o){return Math.min(o,(e.offset??0)+1)}function Lg(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??en))}import{jsx as ce,jsxs as hr}from"react/jsx-runtime";function Qg(e){let o=v(),[t,r]=gr(!1),[a,n]=gr(),{query:l,fields:s}=e,[f,i]=gr(),[u,d]=gr({}),c=bs();c.current=f;let x=bs({});x.current=u,Rs(()=>{n(void 0),o.graphql(l).then(i).catch(k=>n(Gg(k)))},[o,l]);function h(k,Q){k.stopPropagation();let F=k.target.checked,$={...x.current};F?$[Q]=!0:delete $[Q],d($)}function I(k){k.stopPropagation();let y=k.target.checked,F={},$=c.current?.data.ResourceList;y&&$&&$.forEach(Z=>{Z.id&&(F[Z.id]=!0)}),d(F)}function R(){let k=c.current?.data.ResourceList;if(!k||k.length===0)return!1;for(let Q of k)if(Q.id&&!x.current[Q.id])return!1;return!0}function D(k,Q){Ht(k.target)||(O(k),k.button!==1&&e.onClick&&e.onClick(new so(Q,k)),k.button===1&&e.onAuxClick&&e.onAuxClick(new so(Q,k)))}if(Rs(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return ce(Vg,{});let b=e.checkboxesEnabled;return hr("div",{onContextMenu:k=>O(k),"data-testid":"search-control",children:[hr(qg,{children:[ce("thead",{children:hr("tr",{children:[b&&ce("th",{children:ce("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:R(),onChange:k=>I(k)})}),s.map(k=>ce("th",{children:k.name},k.name))]})}),ce("tbody",{children:f?.data.ResourceList.map(k=>k&&hr("tr",{"data-testid":"search-control-row",onClick:Q=>D(Q,k),onAuxClick:Q=>D(Q,k),children:[b&&ce("td",{children:ce("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${k.id}`,checked:!!u[k.id],onChange:Q=>h(Q,k.id)})}),s.map(Q=>ce("td",{children:ce(Qf,{propertyType:Q.propertyType,path:Q.fhirPath,resource:k})},Q.name))]},k.id))})]}),f?.data.ResourceList.length===0&&ce("div",{"data-testid":"empty-search",children:"No results"}),a&&ce("div",{"data-testid":"search-error",children:ce("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&ce(Hg,{onClick:()=>e.onBulk(Object.keys(x.current)),children:"Bulk..."})]})}var eE=Ug(Qg);import{jsx as Go,jsxs as zg}from"react/jsx-runtime";function _e(e){return zg("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Go("title",{children:"Medplum Logo"}),Go("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Go("path",{fill:e.fill??"#946af9",d:"M311 63c-17 0-33 4-48 11-16-7-32-11-49-11-87 0-158 96-158 214s71 214 158 214c17 0 33-4 49-11 15 7 31 11 48 11 87 0 158-96 158-214S398 63 311 63z"}),Go("path",{fill:e.fill??"#7857c5",d:"M231 489l-17 2c-87 0-158-96-158-214S127 63 214 63l17 1c-39 12-70 102-70 213s31 201 70 212z"}),Go("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Go("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as _g,SimpleGrid as Zg}from"@mantine/core";import{Box as Ps,Flex as on,Group as Wg,Paper as Xg,RingProgress as ks,Text as io,Title as tn}from"@mantine/core";import{formatCodeableConcept as Ds}from"@medplum/core";import{Fragment as Ms,jsx as K,jsxs as bt}from"react/jsx-runtime";function Ts(e){let{group:o}=e;return K(Xg,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:bt(Wg,{children:[o.measureScore&&K($g,{group:o}),!o.measureScore&&K(Jg,{group:o})]})})}function Bs(e){let{measure:o}=e;return bt(Ms,{children:[K(io,{fz:"md",fw:500,mb:8,children:o.title}),K(io,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function Jg(e){let{group:o}=e,t=o.population,r=t?.find(f=>Ds(f.code)==="numerator"),a=t?.find(f=>Ds(f.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return bt(Ps,{children:[K(tn,{order:3,children:"Not Applicable"}),K(io,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return bt(Ps,{children:[K(tn,{order:3,children:"Insufficient Data"}),K(io,{children:`Numerator: ${n}`}),K(io,{children:`Denominator: ${l}`})]});let s=n/l*100;return K(ks,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:As(s)}],label:K(on,{justify:"center",children:bt(io,{fw:700,fz:18,children:[n," / ",l]})})})}function $g(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return K(Ms,{children:t==="%"?K(ks,{size:120,thickness:12,roundCaps:!0,sections:[{value:Kg(o),color:As(o?.measureScore?.value??0)}],label:K(on,{justify:"center",children:K(io,{fw:700,fz:18,children:K(We,{value:o.measureScore})})})}):K(on,{h:120,align:"center",children:K(tn,{order:3,children:K(We,{value:o.measureScore})})})})}function Kg(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function As(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as rn,jsxs as Yg}from"react/jsx-runtime";function mE(e){let o=G(e.measureReport),[t]=Hn("Measure",{url:o?.measure});return o?Yg(_g,{children:[t&&rn(Bs,{measure:t}),rn(Zg,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>rn(Ts,{group:r},r.id??a))})]}):null}import{Alert as jg}from"@mantine/core";import{operationOutcomeIssueToString as eh}from"@medplum/core";import{jsx as an}from"react/jsx-runtime";function Uo(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:an(jg,{icon:an(to,{size:16}),color:"red",children:o.map(t=>an("div",{"data-testid":"text-field-error",children:eh(t)},t.details?.text))})}import{createReference as Cr}from"@medplum/core";import{useCallback as oh}from"react";import{jsx as th}from"react/jsx-runtime";function DE(e){let o=oh((t,r,a)=>{let n=`${r}/${a}`,l=100;return Promise.allSettled([t.readHistory("Patient",a),t.search("Communication",{subject:n,_count:l}),t.search("Device",{patient:n,_count:l}),t.search("DeviceRequest",{patient:n,_count:l}),t.search("DiagnosticReport",{subject:n,_count:l}),t.search("Media",{subject:n,_count:l}),t.search("ServiceRequest",{subject:n,_count:l}),t.search("Task",{subject:n,_count:l})])},[]);return th(Ke,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Cr(t),sender:Cr(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Cr(t),operator:Cr(r),issued:new Date().toISOString(),content:a})})}import{Anchor as ws,Button as rh,createStyles as ah,NativeSelect as nh,Stack as lh,TextInput as ln}from"@mantine/core";import{getReferenceString as fh}from"@medplum/core";import{useEffect as Fs,useRef as Os,useState as Pt}from"react";import{jsx as U,jsxs as Qo}from"react/jsx-runtime";var Es=ah(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[1]}`,borderRadius:e.radius.sm,transition:"all 0.1s"},hovering:{border:`1.5px solid ${e.colors.blue[5]}`},editing:{border:`1.5px solid ${e.colors.gray[1]}`,borderLeft:`4px solid ${e.colors.blue[5]}`},bottomActions:{position:"absolute",right:4,bottom:0,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}}}));function WE(e){let o=v(),t=G(e.value),[r,a]=Pt(!1),[n,l]=Pt(),[s,f]=Pt(),[i,u]=Pt();function d(){f(void 0)}function c(){l(void 0)}let x=Os();if(x.current=i,Fs(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),Fs(()=>(u(mh(t??{resourceType:"PlanDefinition"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]),!r||!i)return null;function h(I,R){u({...x.current,[I]:R})}return U("div",{children:Qo(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[U(ln,{label:"Plan Title",defaultValue:i.title,onChange:I=>h("title",I.currentTarget.value)}),U(Ls,{actions:i.action||[],selectedKey:n,setSelectedKey:l,hoverKey:s,setHoverKey:f,onChange:I=>h("action",I)}),U(rh,{type:"submit",children:"Save"})]})})}function Ls(e){let{classes:o}=Es(),t=Os();t.current=e.actions;function r(l){e.onChange(t.current.map(s=>s.id===l.id?l:s))}function a(l){e.onChange([...t.current,l]),e.setSelectedKey(l.id)}function n(l){e.onChange(t.current.filter(s=>s!==l))}return Qo("div",{className:o.section,children:[e.actions.map(l=>U("div",{children:U(sh,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),U("div",{className:o.bottomActions,children:U(ws,{href:"#",onClick:l=>{O(l),a({id:Hs()})},children:"Add action"})})]})}function sh(e){let{classes:o,cx:t}=Es(),{action:r}=e,a=dh(r),n=e.selectedKey===e.action.id,l=e.hoverKey===e.action.id;function s(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function f(u){O(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return Qo("div",{"data-testid":r.id,className:i,onClick:s,onMouseOver:f,children:[n?U(uh,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):U(ih,{action:r,actionType:a}),U("div",{className:o.bottomActions,children:U(ws,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var fn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function ih(e){let{action:o,actionType:t}=e,[r,a]=Ns(o);return Qo("div",{children:[Qo("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&U("div",{children:U(lo,{value:{reference:o.definitionCanonical}})}),r&&U("div",{children:U(re,{property:fn,propertyType:a,value:r})})]})}function uh(e){let{action:o}=e,[t,r]=Pt(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return Qo(lh,{spacing:"xl",children:[U(ln,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),U(ln,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),U(nh,{label:"Type of Action",description:"The type of the action to be performed.",name:`actionType-${o.id}`,defaultValue:t,onChange:n=>r(n.currentTarget.value),data:["","appointment","lab","questionnaire","task"]}),o.action&&o.action.length>0&&U(Ls,{actions:o.action,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:n=>a("action",n)}),(()=>{switch(t){case"appointment":return U(yr,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return U(yr,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return U(yr,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return U(yr,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),U(pe,{title:"Timing",description:"When the action should take place.",children:U(ch,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function yr(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return U(er,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:fh(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function ch(e){let o=e.action,t="timing",[r,a]=Ns(o);return U(Le,{property:fn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(it(o,t,l??t,fn,n))}})}function dh(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function Ns(e){return Te({type:"PlanDefinitionAction",value:e},"timing")}var nn=1;function Hs(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(nn=Math.max(nn,o+1))}return e}return"id-"+nn++}function mh(e){return{...e,action:Vs(e.action)}}function Vs(e){if(e)return e.map(o=>({...o,id:Hs(o.id),action:Vs(o.action)}))}import{Anchor as Se,Box as pn,Button as Vh,createStyles as qh,Group as Gh,NativeSelect as Uh,Space as Qh,Textarea as zh,TextInput as xn,Title as Wh}from"@mantine/core";import{getElementDefinition as Xh,isResource as Jh}from"@medplum/core";import{useEffect as ei,useRef as $h,useState as Pr}from"react";import{Checkbox as bh,Group as Ph,MultiSelect as Dh,NativeSelect as kh,Radio as $s,Textarea as Th,TextInput as zo}from"@mantine/core";import{capitalize as dn,deepEquals as Bh,formatCodeableConcept as Ah,formatCoding as br,getElementDefinition as Mh,getTypedPropertyValue as Ze,stringify as Ks}from"@medplum/core";import{deepClone as ph,evalFhirPathTyped as xh,formatCoding as Ih,getExtension as un,getTypedPropertyValue as sn,getReferenceString as gh,stringify as hh}from"@medplum/core";var vr=(D=>(D.group="group",D.display="display",D.question="question",D.boolean="boolean",D.decimal="decimal",D.integer="integer",D.date="date",D.dateTime="dateTime",D.time="time",D.string="string",D.text="text",D.url="url",D.choice="choice",D.openChoice="open-choice",D.attachment="attachment",D.reference="reference",D.quantity="quantity",D))(vr||{});function qs(e){return e.type==="choice"||e.type==="open-choice"}function Gs(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=Qs(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=yh(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function Us(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>Ih(l.valueCoding)===r||l[o]===r),n=sn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Qs(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Qs(t.item,o);if(r)return r}}}function Ch(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=xh(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function yh(e,o,t){let r=o||[],a=sn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let s of r){let f=sn({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(Ch(f,a,i)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function Sr(e){let o=un(e,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource");if(o){if(o.valueCode!==void 0)return[o.valueCode];if(o.valueCodeableConcept)return o.valueCodeableConcept?.coding?.map(t=>t.code)}}function Rr(e,o){let t=ph(e),r=un(t,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource");return!o||o.length===0?(r&&(t.extension=t.extension?.filter(a=>a!==r)),t):(r||(t.extension||(t.extension=[]),r={url:"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource"},t.extension.push(r)),o.length===1?(r.valueCode=o[0],delete r.valueCodeableConcept):(r.valueCodeableConcept={coding:o.map(a=>({code:a}))},delete r.valueCode),t)}function zs(e){return{resourceType:"QuestionnaireResponse",questionnaire:gh(e),item:Ws(e.item)}}function Ws(e){return e?.map(cn)??[]}function cn(e){return{id:Sh(),linkId:e.linkId,text:e.text,item:Ws(e.item),answer:e.initial?.map(Rh)??[]}}var vh=1;function Sh(){return"id-"+vh++}function Rh(e){return{...e}}function Xs(e){return e.value.display||e.value.reference||hh(e.value)}function Js(e){let o=e?.item?.[0];return o&&un(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{jsx as z}from"react/jsx-runtime";function Dt(e){let o=e.item,t=e.response;function r(f){let i;Array.isArray(f)?i=f:e.index>=(e.response?.answer?.length??0)?i=(e.response?.answer??[]).concat([f]):i=(e.response?.answer??[]).map((d,c)=>c===e.index?f:d)??[],e.onChange({id:t?.id,linkId:t?.linkId,text:o.text,answer:i})}let a=o.type;if(!a)return null;let n=o.linkId;if(!n)return null;let l=o.initial&&o.initial.length>0?o.initial[0]:void 0,s=mn(t,e.index)??Ze({type:"QuestionnaireItemInitial",value:l},"value");switch(a){case"display":return z("p",{children:e.item.text},e.item.linkId);case"boolean":return z(Kt,{title:e.item.text,htmlFor:e.item.linkId,children:z(bh,{id:e.item.linkId,name:e.item.linkId,defaultChecked:s?.value,onChange:f=>r({valueBoolean:f.currentTarget.checked})})},e.item.linkId);case"decimal":return z(zo,{type:"number",step:"any",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDecimal:f.currentTarget.valueAsNumber})});case"integer":return z(zo,{type:"number",step:1,id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueInteger:f.currentTarget.valueAsNumber})});case"date":return z(zo,{type:"date",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDate:f.currentTarget.value})});case"dateTime":return z(be,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDateTime:f})});case"time":return z(zo,{type:"time",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueTime:f.currentTarget.value})});case"string":case"url":return z(zo,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"text":return z(Th,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"attachment":return z(Ph,{py:4,children:z(Ut,{name:n,defaultValue:s?.value,onChange:f=>r({valueAttachment:f})})});case"reference":return z(Fo,{name:n,required:o.required,targetTypes:Sr(o),defaultValue:s?.value,onChange:f=>r({valueReference:f})});case"quantity":return z(he,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueQuantity:f}),disableWheel:!0});case"choice":case"open-choice":return Nh(o)&&!o.answerValueSet?z(Fh,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)}):z(wh,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)});default:return null}}function Fh(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return z(Ys,{});let n=Ze({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let f of t.answerOption){let i=Ze({type:"QuestionnaireItemAnswerOption",value:f},"value");l.push(_s(i))}let s=mn(a)??n;if(t.repeats){let{propertyName:f,data:i}=Hh(e.item),u=Eh(a);return z(Dh,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[_s(n)],onChange:d=>{let c=Us(d,f,t);e.onChangeAnswer(c)}})}return z(kh,{id:o,name:o,onChange:f=>{let i=f.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],d=Ze({type:"QuestionnaireItemAnswerOption",value:u},"value"),c="value"+dn(d.type);e.onChangeAnswer({[c]:d.value})},defaultValue:br(s?.value)||s?.value,data:l})}function wh(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?z(Ys,{}):t.answerValueSet?z(Zt,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):z(Oh,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Oh(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Mh("QuestionnaireItemAnswerOption","value[x]"),s=Ze({type:"QuestionnaireItemInitial",value:r},"value"),f=[],i;if(t.answerOption)for(let c=0;c<t.answerOption.length;c++){let x=t.answerOption[c],h=`${o}-option-${c}`,I=Ze({type:"QuestionnaireItemAnswerOption",value:x},"value");s&&Ks(I)===Ks(s)&&(i=h),f.push([h,I])}let u=mn(n),d=Lh(f,u);return z($s.Group,{name:o,value:d??i,onChange:c=>{let x=f.find(h=>h[0]===c);if(x){let h=x[1],I="value"+dn(h.type);a({[I]:h.value})}},children:f.map(([c,x])=>z($s,{id:c,value:c,py:4,label:z(re,{property:l,propertyType:x.type,value:x.value})},c))})}function Ys(){return z(zo,{disabled:!0,placeholder:"No Answers Defined"})}function js(e){return Ze({type:"QuestionnaireItemAnswer",value:e},"value")}function mn(e,o=0){let t=e.answer;return js(t?.[o]??{})}function Eh(e){let o=e.answer;return o?o.map(r=>js(r)).map(r=>br(r?.value)||r?.value):[]}function Lh(e,o){return e.find(t=>Bh(t[1].value,o?.value))?.[0]}function _s(e){if(e)return e.type==="CodeableConcept"?Ah(e.value):e.type==="Coding"?br(e.value):e.type==="Reference"?Xs(e):e.value.toString()}function Nh(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Hh(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=Ze({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+dn(t.type),a=(e.answerOption??[]).map(n=>({value:Zs(n,r),label:Zs(n,r)}));return{propertyName:r,data:a}}function Zs(e,o){return br(e.valueCoding)||e[o]?.toString()}import{Fragment as Wo,jsx as M,jsxs as de}from"react/jsx-runtime";var Kh=qh(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[1]}`,borderRadius:e.radius.sm,transition:"all 0.1s"},hovering:{border:`1.5px solid ${e.colors.blue[5]}`},editing:{border:`1.5px solid ${e.colors.gray[1]}`,borderLeft:`4px solid ${e.colors.blue[5]}`},questionBody:{maxWidth:600},topActions:{position:"absolute",right:32,top:1,padding:4,color:e.colors.gray[5],fontSize:e.fontSizes.xs},bottomActions:{position:"absolute",right:4,bottom:0,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}},movementActions:{position:"absolute",right:8,top:0,paddingTop:8,fontSize:e.fontSizes.xs,"& a":{marginLeft:8}},movementIcons:{color:e.colors.gray[5]},columnAlignment:{display:"flex",flexDirection:"column"},linkIdInput:{width:100,marginBottom:4},typeSelect:{width:100}}));function b0(e){let o=v(),t=G(e.questionnaire),[r,a]=Pr(!1),[n,l]=Pr(),[s,f]=Pr(),[i,u]=Pr();function d(){u(void 0)}function c(){f(void 0)}ei(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),ei(()=>(l(jh(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]);let x=(h,I)=>{l(h),e.autoSave&&!I&&e.onSubmit&&e.onSubmit(h)};return!r||!n?null:M("div",{children:de(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[M(oi,{item:n,selectedKey:s,setSelectedKey:f,hoverKey:i,setHoverKey:u,onChange:x}),M(Vh,{type:"submit",children:"Save"})]})})}function oi(e){let{classes:o,cx:t}=Kh(),r=e.item,a=e.item,n=Jh(e.item),l=n||a.type==="group",s=a.linkId??"[untitled]",f=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=$h();u.current=e.item;function d(y){O(y),e.setSelectedKey(e.item.id)}function c(y){O(y),e.setHoverKey(e.item.id)}function x(y){let F=u.current;e.onChange({...F,item:F.item?.map($=>$.id===y.id?y:$)})}function h(y,F){e.onChange({...e.item,item:[...e.item.item??[],y]},F)}function I(y){e.onChange({...e.item,item:e.item.item?.filter(F=>F!==y)})}function R(y,F){e.onChange({...u.current,[y]:F})}function D(y){e.onChange({...e.item,...y})}function b(y){e.onChange({...e.item,item:e.item.item?.map(F=>F===y?{...F,repeats:!F.repeats}:F)})}function k(y,F){let $=tC(e.item.item,y,F);e.onChange({...e.item,item:$})}let Q=t(o.section,{[o.editing]:f,[o.hovering]:i&&!f});return de("div",{"data-testid":a.linkId,className:Q,onClick:d,onMouseOver:c,children:[M("div",{className:o.questionBody,children:f?de(Wo,{children:[n&&M(xn,{size:"xl",defaultValue:r.title,onBlur:y=>R("title",y.currentTarget.value)}),!n&&M(zh,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:y=>R("text",y.currentTarget.value)}),a.type==="reference"&&M(Yh,{item:a,onChange:D}),qs(a)&&M(_h,{item:a,onChange:y=>D(y)})]}):de(Wo,{children:[r.title&&M(Wh,{children:r.title}),a.text&&M("div",{children:a.text}),!l&&M(Dt,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((y,F)=>M("div",{children:M(oi,{item:y,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:F===0,isLast:F===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:x,onRemove:()=>I(y),onRepeatable:b,onMoveUp:()=>k(F,-1),onMoveDown:()=>k(F,1)})},y.id)),!l&&M("div",{className:o.topActions,children:f?de(Wo,{children:[M(xn,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:y=>R("linkId",y.currentTarget.value)}),!l&&M(Uh,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:y=>R("type",y.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"}]})]}):M("div",{children:s})}),!n&&M(pn,{className:o.movementActions,children:de(pn,{className:o.columnAlignment,children:[!e.isFirst&&M(Se,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:M(Wr,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&M(Se,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:M(zr,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),de("div",{className:o.bottomActions,children:[l&&de(Wo,{children:[M(Se,{href:"#",onClick:y=>{y.preventDefault(),h({id:uo(),linkId:hn("q"),type:"string",text:"Question"})},children:"Add item"}),M(Se,{href:"#",onClick:y=>{y.preventDefault(),h({id:uo(),linkId:hn("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&M(Se,{href:"#",onClick:y=>{y.preventDefault(),h(oC(),!0)},children:"Add Page"}),f&&!n&&de(Wo,{children:[M(Se,{href:"#",onClick:y=>{y.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),M(Se,{href:"#",onClick:y=>{y.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function _h(e){let o=Xh("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return de("div",{children:[e.item.answerValueSet!==void 0?M(xn,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):M(Zh,{options:t,property:o,item:e.item,onChange:e.onChange}),de(pn,{display:"flex",children:[M(Se,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:uo()}]})},children:"Add choice"}),M(Qh,{w:"lg"}),M(Se,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Zh(e){return M("div",{children:e.options.map(o=>{let[t,r]=Te({type:"QuestionnaireItemAnswerOption",value:o},"value");return de("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[M("div",{children:M(Le,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let l=[...e.options],s=l.findIndex(f=>f.id===o.id);l[s]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:l})}},o.id)}),M("div",{children:M(Se,{href:"#",onClick:a=>{O(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Yh(e){let o=Sr(e.item)??[];return de(Wo,{children:[o.map((t,r)=>de(Gh,{children:[M(To,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(Rr(e.item,o.map(n=>n===t?a:n)))}}),M(Se,{href:"#",onClick:a=>{O(a),e.onChange(Rr(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),M(Se,{href:"#",onClick:t=>{O(t),e.onChange(Rr(e.item,[...o,""]))},children:"Add Resource Type"})]})}var In=1,gn=1;function hn(e){return e+In++}function uo(){return"id-"+gn++}function jh(e){return{...e,id:e.id||uo(),item:ti(e.item)}}function ti(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(gn=Math.max(gn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(In=Math.max(In,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||uo(),item:ti(o.item),answerOption:eC(o.answerOption)}))}function eC(e){if(e)return e.map(o=>({...o,id:o.id||uo()}))}function oC(){return{id:uo(),linkId:hn("s"),type:"group",text:"New Page",extension:[{url:"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",valueCodeableConcept:{coding:[{system:"http://hl7.org/fhir/questionnaire-item-control",code:"page"}]}}]}}function tC(e,o,t){let r=e??[],a=o+t;if(a<0||a>=r.length)return r;let n=[...r];return[n[o],n[a]]=[n[a],n[o]],n}import{Title as IC}from"@mantine/core";import{createReference as gC,getReferenceString as hC}from"@medplum/core";import{useEffect as si,useState as vn}from"react";import{Button as yn,Group as dC,Stack as mC,Stepper as ni}from"@mantine/core";import{Anchor as rC}from"@mantine/core";import{useState as aC}from"react";import{jsx as Dr,jsxs as lC}from"react/jsx-runtime";function kr(e){let{item:o,response:t,onChange:r}=e,[a,n]=aC(nC(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return Dr("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?Dr(Dt,{item:o,response:t,onChange:s=>r([s]),index:0},o.linkId):lC(pe,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((s,f)=>Dr(Dt,{item:o,response:t,onChange:i=>r([i]),index:f},`${o.linkId}-${f}`)),l&&Dr(rC,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function nC(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}import{Anchor as fC,Stack as sC,Title as iC}from"@mantine/core";import{useState as uC}from"react";import{Fragment as cC,jsx as co,jsxs as ai}from"react/jsx-runtime";function Cn(e){let[o,t]=uC(e.response);if(o.length===0)return null;function r(n,l){let s=o.map((f,i)=>i===l?n[0]:f);t(s),e.onChange(s)}function a(){let n=cn(e.item);t([...o,n])}return ai(cC,{children:[o.map((n,l)=>co(ri,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,l)},n.id)),e.item.repeats&&co(fC,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function ri(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let s=o.item?.map(i=>n.find(d=>d.id===i.id)??i)?.concat(n.slice(1)),f={...o,item:s};r([f])}return e.checkForQuestionEnabled(e.item)?ai("div",{children:[e.item.text&&co(iC,{order:3,mb:"md",children:e.item.text}),co(sC,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?co(Cn,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):co(ri,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):co(kr,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as xC,jsx as qe,jsxs as fi}from"react/jsx-runtime";function li(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:l,numberOfPages:s,renderPages:f,submitButtonText:i,checkForQuestionEnabled:u}=e,d=o.map(c=>{let x=t?.item?.filter(I=>I.linkId===c.linkId)??[],h=c.type==="group"?qe(Cn,{item:c,response:x,onChange:a,checkForQuestionEnabled:u},c.linkId):qe(kr,{item:c,response:x?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return f?qe(ni.Step,{label:c.text,children:h},c.linkId):h});return fi(xC,{children:[f&&qe(ni,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!f&&qe(mC,{children:d}),qe(pC,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:l,submitButtonText:i})]})}function pC(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return fi(dC,{position:"right",mt:"xl",spacing:"xs",children:[o&&qe(yn,{onClick:e.prevStep,children:"Back"}),t&&qe(yn,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&qe(yn,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as ii,jsxs as yC}from"react/jsx-runtime";function ui(e){let o=v(),t=o.getProfile(),[r,a]=vn(!1),n=G(e.questionnaire),[l,s]=vn(),[f,i]=vn(0);si(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),si(()=>{s(n?zs(n):void 0)},[n]);function u(I){let R=l?.item??[],b={resourceType:"QuestionnaireResponse",item:ci(R,Array.isArray(I)?I:[I])};s(b)}function d(I){return Gs(I,l?.item??[])}if(!r||!n)return null;let c=Js(n),x=()=>i(I=>I+1),h=()=>i(I=>I-1);return yC(W,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:hC(n),subject:e.subject,source:gC(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&ii(IC,{children:n.title}),ii(li,{items:n.item??[],response:l,onChange:u,renderPages:c>1,activePage:f,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:x,prevStep:h})]})}function CC(e,o){let t=ci(e.item??[],o.item??[]);return{...o,item:t.length>0?t:void 0,answer:o.answer&&o.answer.length>0?o.answer:e.answer}}function ci(e,o){let t=[],r=new Set;for(let a of e){let n=a.id,l=o.find(s=>s.id===n);l?(t.push(CC(a,l)),r.add(l.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}import{ActionIcon as Tr,Button as vC,createStyles as SC,Divider as RC,Group as kt,NativeSelect as Sn,Stack as Br,Text as bC,TextInput as PC}from"@mantine/core";import{formatRange as di,getCodeBySystem as DC}from"@medplum/core";import{useEffect as kC,useState as Rn}from"react";import{jsx as X,jsxs as Xo}from"react/jsx-runtime";var TC=SC(e=>({section:{position:"relative",margin:"4px 4px 8px 0",padding:"6px 12px 16px 6px",border:`1.5px solid ${e.colors.gray[3]}`,borderRadius:e.radius.sm,transition:"all 0.1s"}})),BC=["gender","age","gestationalAge","context","appliesTo","category"],AC={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function i1(e){e=Object.assign(AC,e);let o=e.definition,[t,r]=Rn([]),[a,n]=Rn(1),[l,s]=Rn(1);return kC(()=>{let h=wC(o,s);r(OC(h.qualifiedInterval||[],n))},[o]),Xo(W,{testid:"reference-range-editor",onSubmit:f,children:[X(Br,{children:t.map(h=>X(MC,{unit:LC(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:x,onRemoveGroup:u,intervalGroup:h},`group-${h.id}`))}),X(Tr,{title:"Add Group",size:"sm",onClick:h=>{O(h),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(I=>I+1)},children:X(go,{})}),X(kt,{position:"right",children:X(vC,{type:"submit",children:"Save"})})]});function f(){let h=t.flatMap(I=>I.intervals).filter(I=>!NC(I));e.onSubmit({...o,qualifiedInterval:h})}function i(h){r(I=>[...I,h])}function u(h){r(I=>I.filter(R=>R.id!==h.id))}function d(h,I){r(R=>{R=[...R];let D=R.find(k=>k.id===h),b=D?.intervals.findIndex(k=>k.id===I.id);return b!==void 0&&D?.intervals[b]&&(D.intervals[b]=I),R})}function c(h,I){I.id===void 0&&(I.id=`id-${l}`,s(R=>R+1)),r(R=>{R=[...R];let D=R.findIndex(b=>b.id===h);if(D!==-1){let b={...R[D]};I={...I,...b.filters},b.intervals=[...b.intervals,I],R[D]=b}return R})}function x(h,I){r(R=>{R=[...R];let D=R.find(b=>b.id===h);return D&&(D.intervals=D.intervals.filter(b=>b.id!==I.id)),R})}}function MC(e){let{intervalGroup:o,unit:t}=e,{classes:r}=TC();return X(Xe,{"data-testid":o.id,className:r.section,children:Xo(Br,{spacing:"lg",children:[X(kt,{position:"right",children:X(Tr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{O(a),e.onRemoveGroup(o)},children:X(Qe,{})},`remove-group-button-${o.id}`)}),X(FC,{intervalGroup:o,onChange:e.onChange}),X(RC,{}),o.intervals.map(a=>Xo(Br,{spacing:"xs",children:[Xo(kt,{children:[X(PC,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{O(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),X(Tr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{O(n),e.onRemove(o.id,a)},children:X(Qe,{})},`remove-interval-${a.id}`)]}),X(ct,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),X(Tr,{title:"Add Interval",size:"sm",onClick:a=>{O(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:X(go,{})})]})})}function FC(e){let{intervalGroup:o,onChange:t}=e;o.filters.age||(o.filters.age={});for(let r of["low","high"])o.filters.age[r]?.unit||(o.filters.age[r]={...o.filters.age[r],unit:"years",system:"http://unitsofmeasure.org"});return Xo(Br,{style:{maxWidth:"50%"},children:[X(kt,{children:X(Sn,{data:["","male","female"],label:"Gender:",defaultValue:o.filters.gender||"",onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""&&(n=void 0),t(o.id,{...a,gender:n})}}})}),Xo(kt,{spacing:"xs",children:[X(bC,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),X("div",{id:`div-age-${o.id}`,children:X(ct,{name:`age-${o.id}`,defaultValue:o.filters.age,onChange:r=>{for(let a of o.intervals)t(o.id,{...a,age:r})}},`age-${o.id}`)})]}),X(Sn,{data:["","pre-puberty","follicular","midcycle","luteal","postmenopausal"],label:"Endocrine:",defaultValue:o.filters.context?.text||"",onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""?(n=void 0,t(o.id,{...a,context:void 0})):t(o.id,{...a,context:{text:n,coding:[{code:n,system:"http://terminology.hl7.org/CodeSystem/referencerange-meaning"}]}})}}}),X(Sn,{data:["","reference","critical","absolute"],label:"Category: ",defaultValue:o.filters.category,onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""?t(o.id,{...a,category:void 0}):t(o.id,{...a,category:n})}}})]})}function wC(e,o){let t=e.qualifiedInterval||[],r=Math.max(...t.map(a=>{let n=parseInt(a.id?.substring(3)||"",10);return isNaN(n)?Number.NEGATIVE_INFINITY:n}))+1;return Number.isFinite(r)||(r=1),e={...e,qualifiedInterval:t.map(a=>({...a,id:a.id||`id-${r++}`}))},o(r),e}function OC(e,o){let t=1,r={};for(let a of e){let n=EC(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(BC.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function EC(e){return[`gender=${e.gender}`,`age=${di(e.age)}`,`gestationalAge=${di(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function LC(e){return e&&(DC(e,"http://unitsofmeasure.org")||e.text)}function NC(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as mi,Grid as Ar,Text as HC}from"@mantine/core";import{formatDateTime as VC,getReferenceString as qC}from"@medplum/core";import{Fragment as GC,useEffect as UC,useState as pi}from"react";import{jsx as Ae,jsxs as Tt}from"react/jsx-runtime";function C1(e){let o=v(),t=G(e.value),[r,a]=pi(!1),[n,l]=pi();if(UC(()=>{t&&!r&&(o.executeBatch(s(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Ae(Ar,{children:t.action?.map((i,u)=>{let d=i.resource&&f(i.resource),c=d?.input?.[0]?.valueReference,x=d?.output?.[0]?.valueReference;return Tt(GC,{children:[Ae(Ar.Col,{span:1,p:"md",children:d?.status==="completed"?Ae(Yr,{}):Ae(xa,{color:"gray"})}),Tt(Ar.Col,{span:9,p:"xs",children:[Ae(HC,{weight:500,children:i.title}),i.description&&Ae("div",{children:i.description}),Tt("div",{children:["Last edited by\xA0",Ae(Be,{value:d?.meta?.author}),"\xA0on\xA0",VC(d?.meta?.lastUpdated)]}),Tt("div",{children:["Status: ",Ae(rr,{status:d?.status||"unknown"})]})]}),Tt(Ar.Col,{span:2,p:"md",children:[c&&!x&&Ae(mi,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&x&&Ae(mi,{onClick:()=>e.onEdit(d,c,x),children:"Edit"})]})]},`action-${u}`)})});function s(i){let u=[];if(i.action)for(let d of i.action)d.resource?.reference&&u.push({request:{method:"GET",url:d.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function f(i){for(let u of n?.entry)if(u.resource&&i.reference===qC(u.resource))return u.resource}}import{createStyles as KC}from"@mantine/core";import{useEffect as _C,useState as ZC}from"react";import{stringify as XC}from"@medplum/core";function Mr(e,o){let t=QC(e,o);return zC(t,e,o)}function QC(e,o){let t=e.length,r=o.length,a=t+r+1,n=1+2*a,l=n/2|0,s=new Array(n);s[l+1]={i:0,j:-1,prev:void 0,snake:!0};for(let f=0;f<a;f++){for(let i=-f;i<=f;i+=2){let u=l+i,d=u+1,c=u-1,x=s[d],h=s[c],I,R=0;i===-f||i!==f&&h.i<x.i?(R=x.i,I=x):(R=h.i+1,I=h),s[c]=void 0;let D=R-i,b={i:R,j:D,prev:WC(I),snake:!1};for(;R<t&&D<r&&e[R]===o[D];)R++,D++;if(R>b.i&&(b={i:R,j:D,prev:b,snake:!0}),s[u]=b,R>=t&&D>=r)return s[u]}s[l+f-1]=void 0}}function zC(e,o,t){let r=[],a=e;for(a.snake&&(a=a.prev);a?.prev&&a.prev.j>=0;){let n=a.i,l=a.j;a=a.prev;let s=a.i,f=a.j,i={position:s,lines:o.slice(s,n)},u={position:f,lines:t.slice(f,l)},d;i.lines.length===0&&u.lines.length>0?d="insert":i.lines.length>0&&u.lines.length===0?d="delete":d="change",r.push({original:i,revised:u,type:d}),a.snake&&(a=a.prev)}return r}function WC(e){return e&&!e.snake&&e.prev?e.prev:e}function xi(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:XC(r.resource,!0).match(/[^\r\n]+/g)})).sort((r,a)=>r.meta.lastUpdated.localeCompare(a.meta.lastUpdated)),t=o[0].lines.map(r=>({id:o[0].meta.versionId,meta:o[0].meta,value:r,span:1}));return JC(t,o),$C(t),t}function JC(e,o){for(let t=1;t<o.length;t++){let r=Mr(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,l=a.original.lines,s=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,l.length),a.type==="insert"||a.type==="change")for(let f=0;f<a.revised.lines.length;f++)e.splice(n+f,0,{id:o[t].meta.versionId,meta:o[t].meta,value:s[f],span:1})}}}function $C(e){let o=0;for(;o<e.length;){let t=o;for(;t<e.length&&e[t].id===e[o].id;)e[t].span=-1,t++;e[o].span=t-o,o=t}}function Ii(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function gi(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Jo(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Jo(r,"month");let a=Math.floor(o/86400);if(a>0)return Jo(a,"day");let n=Math.floor(o/3600);if(n>0)return Jo(n,"hour");let l=Math.floor(o/60);return l>0?Jo(l,"minute"):Jo(o,"second")}function Jo(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as jC,jsx as Pe,jsxs as hi}from"react/jsx-runtime";var YC=KC(e=>({container:{overflowX:"auto"},root:{border:`0.1px solid ${e.colors.gray[3]}`,borderCollapse:"collapse",borderRadius:e.radius.sm,borderSpacing:0,fontSize:e.fontSizes.xs,width:"100%","& td":{padding:"2px 4px 0 4px",verticalAlign:"top",whiteSpace:"nowrap"}},startRow:{borderTop:`0.1px solid ${e.colors.gray[3]}`},normalRow:{borderTop:0},author:{lineHeight:"10px"},dateTime:{borderRight:`0.1px solid ${e.colors.gray[3]}`,lineHeight:"20px"},lineNumber:{backgroundColor:e.colors.gray[1],border:0,color:e.colors.gray[5],fontFamily:e.fontFamilyMonospace,padding:`${e.spacing.xs} ${e.spacing.sm}`,textAlign:"right"},line:{fontFamily:e.fontFamilyMonospace,fontSize:e.fontSizes.sm,padding:`${e.spacing.xs} ${e.spacing.sm}`},pre:{margin:0}}));function O1(e){let{classes:o}=YC(),t=v(),[r,a]=ZC(e.history);if(_C(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(a).catch(console.log)},[t,e.history,e.resourceType,e.id]),!r)return Pe("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=xi(r);return Pe("div",{className:o.container,children:Pe("table",{className:o.root,children:Pe("tbody",{children:l.map((s,f)=>hi("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&hi(jC,{children:[Pe("td",{className:o.author,rowSpan:s.span,children:Pe(Je,{value:s.meta.author,link:!0})}),Pe("td",{className:o.dateTime,rowSpan:s.span,children:Pe(j,{to:Ii(n,s.meta.versionId),children:gi(s.meta.lastUpdated)})})]}),Pe("td",{className:o.lineNumber,children:f+1}),Pe("td",{className:o.line,children:Pe("pre",{className:o.pre,children:s.value})})]},"row-"+f))})})})}import{createStyles as ey}from"@mantine/core";import{stringify as Ci}from"@medplum/core";import{Fragment as ry,jsx as $o,jsxs as ay}from"react/jsx-runtime";var oy=ey(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function G1(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Ci(o,!0).match(/[^\r\n]+/g),a=Ci(t,!0).match(/[^\r\n]+/g),n=Mr(r,a);return $o("pre",{style:{color:"gray"},children:n.map((l,s)=>$o(ty,{delta:l},"delta"+s))})}function ty(e){let{classes:o}=oy();return ay(ry,{children:["...",$o("br",{}),e.delta.original.lines.length>0&&$o("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
66
66
|
`)}),e.delta.revised.lines.length>0&&$o("div",{className:o.added,children:e.delta.revised.lines.join(`
|
|
67
|
-
`)}),"...",$o("br",{})]})}import{Button as yi,Group as ry,Stack as ay,TextInput as vi}from"@mantine/core";import{deepClone as ny}from"@medplum/core";import{useEffect as ly,useState as Si}from"react";import{jsx as Ye,jsxs as bn}from"react/jsx-runtime";function K1(e){let o=v(),t=G(e.defaultValue),[r,a]=Si(!1),[n,l]=Si();return ly(()=>{t&&(l(ny(t)),o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log))},[o,t]),!r||!n?Ye("div",{children:"Loading..."}):bn("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(n)},children:[bn(ay,{mb:"xl",children:[Ye(xe,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:Ye(vi,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),Ye(xe,{title:"ID",htmlFor:"id",outcome:e.outcome,children:Ye(vi,{name:"id",defaultValue:n.id,disabled:!0})})]}),Ye(pt,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:l}),bn(ry,{position:"right",mt:"xl",children:[Ye(yi,{type:"submit",children:"OK"}),e.onDelete&&Ye(yi,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}import{Table as fy}from"@mantine/core";import{formatDateTime as sy,normalizeErrorString as iy}from"@medplum/core";import{useEffect as uy,useState as cy}from"react";import{jsx as me,jsxs as Pn}from"react/jsx-runtime";function aL(e){let o=v(),[t,r]=cy(e.history);return uy(()=>{!e.history&&e.resourceType&&e.id&&o.readHistory(e.resourceType,e.id).then(r).catch(console.log)},[o,e.history,e.resourceType,e.id]),t?Pn(fy,{withBorder:!0,withColumnBorders:!0,children:[me("thead",{children:Pn("tr",{children:[me("th",{children:"Author"}),me("th",{children:"Date"}),me("th",{children:"Version"})]})}),me("tbody",{children:t.entry?.map((a,n)=>me(dy,{entry:a},"entry-"+n))})]}):me("div",{children:"Loading..."})}function dy(e){let{response:o,resource:t}=e.entry;return t?Pn("tr",{children:[me("td",{children:me(Je,{value:t.meta?.author,link:!0})}),me("td",{children:sy(t.meta?.lastUpdated)}),me("td",{children:me(j,{to:my(t),children:t.meta?.versionId})})]}):me("tr",{children:me("td",{colSpan:3,children:iy(o?.outcome)})})}function my(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as py,createStyles as xy,Stack as Iy,Text as gy}from"@mantine/core";import{getReferenceString as hy,isReference as Cy}from"@medplum/core";import{useState as Fr}from"react";import{jsx as ie,jsxs as Ko}from"react/jsx-runtime";var yy=xy(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function IL(e){let{classes:o}=yy(),t=G(e.schedule),r=G(e.questionnaire),[a,n]=Fr(tr()),[l,s]=Fr(),[f,i]=Fr(),[u,d]=Fr(),[c]=Vn("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",Cy(e.schedule)?e.schedule.reference:hy(e.schedule)],["start","gt"+vy(a)],["start","lt"+Sy(a)]]));if(!t||!c||!r)return null;let x=t.actor?.[0];return Ko("div",{className:o.container,"data-testid":"scheduler",children:[Ko("div",{className:o.info,children:[x&&ie(le,{value:x,size:"xl"}),x&&ie(gy,{size:"xl",weight:500,children:ie(Ae,{value:x})}),ie("p",{children:"1 hour"}),l&&ie("p",{children:l.toLocaleDateString()}),f&&ie("p",{children:Ri(new Date(f.start))})]}),Ko("div",{className:o.selection,children:[!l&&Ko("div",{children:[ie("h3",{children:"Select date"}),ie(Cf,{slots:c,onChangeMonth:n,onClick:s})]}),l&&!f&&Ko("div",{children:[ie("h3",{children:"Select time"}),ie(Iy,{children:c.map(C=>{let I=new Date(C.start);return I.getTime()>l.getTime()&&I.getTime()<l.getTime()+24*3600*1e3&&ie("div",{children:ie(py,{variant:"outline",style:{width:150},onClick:()=>i(C),children:Ri(I)})},C.id)})})]}),l&&f&&!u&&ie(ui,{questionnaire:r,submitButtonText:"Next",onSubmit:d}),l&&f&&u&&Ko("div",{children:[ie("h3",{children:"You're all set!"}),ie("p",{children:"Check your email for a calendar invite."})]})]})]})}function vy(e){return bi(e.getTime())}function Sy(e){return bi(e.getTime()+31*24*60*60*1e3)}function bi(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Ri(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as wr}from"@medplum/core";import{jsx as Ry}from"react/jsx-runtime";function RL(e){return Ry(Ke,{value:e.serviceRequest,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory("ServiceRequest",r),o.search("Communication",{"based-on":a,_count:n}),o.search("DiagnosticReport",{"based-on":a,_count:n}),o.search("Media",{"based-on":a,_count:n}),o.search("DocumentReference",{related:a,_count:n}),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])},createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",basedOn:[wr(o)],subject:o.subject,sender:wr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[wr(o)],subject:o.subject,operator:wr(t),issued:new Date().toISOString(),content:r})})}import{normalizeOperationOutcome as Wy}from"@medplum/core";import{useEffect as Xy,useState as Fi}from"react";import{Anchor as Pi,Button as by,Center as Py,Group as Dy,Stack as Ty,Text as ky,TextInput as By,Title as Ay}from"@mantine/core";import{normalizeOperationOutcome as My}from"@medplum/core";import{useState as Fy}from"react";import{jsx as mo,jsxs as Or}from"react/jsx-runtime";function Er(e){let o=v(),[t,r]=Fy();return Or(W,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(My(n))}},children:[Or(Py,{sx:{flexDirection:"column"},children:[mo(_e,{size:32}),mo(Ay,{children:"Create project"})]}),Or(Ty,{spacing:"xl",children:[mo(By,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:ae(t,"firstName")}),Or(ky,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",mo(Pi,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",mo(Pi,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),mo(Dy,{position:"right",mt:"xl",noWrap:!0,children:mo(by,{type:"submit",children:"Create project"})})]})}import{Anchor as Vr,Button as Ly,Center as Ny,Checkbox as Hy,Divider as Vy,Group as ki,PasswordInput as qy,Stack as Gy,Text as Bi,TextInput as Tn}from"@mantine/core";import{normalizeOperationOutcome as Ai}from"@medplum/core";import{useEffect as Uy,useState as Qy}from"react";import{useEffect as wy,useRef as Oy,useState as Dn}from"react";function Lr(e,o){let t=document.getElementsByTagName("head")[0],r=document.createElement("script");r.async=!0,r.src=e,r.onload=o??null,t.appendChild(r)}import{jsx as Ey}from"react/jsx-runtime";function Nr(e){let o=v(),{googleClientId:t,handleGoogleCredential:r}=e,a=Oy(null),[n,l]=Dn(typeof google<"u"),[s,f]=Dn(!1),[i,u]=Dn(!1);return wy(()=>{if(typeof google>"u"){Lr("https://accounts.google.com/gsi/client",()=>l(!0));return}s||(google.accounts.id.initialize({client_id:t,callback:r}),f(!0)),a.current&&!i&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,s,n,a,i,r]),t?Ey("div",{ref:a}):null}function Hr(e){if(e)return e;if(typeof window<"u"){let o=window.location.protocol+"//"+window.location.host;if(("undefined"?.split(",")??[]).includes(o))return"__GOOGLE_CLIENT_ID__"}}function Di(e){typeof grecaptcha>"u"&&Lr("https://www.google.com/recaptcha/api.js?render="+e)}function Ti(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as zy,jsx as ue,jsxs as _o}from"react/jsx-runtime";function Mi(e){let o=Hr(e.googleClientId),t=e.recaptchaSiteKey,r=v(),[a,n]=Qy(),l=_t(a,void 0);return Uy(()=>{t&&Di(t)},[t]),_o(W,{style:{maxWidth:400},onSubmit:async s=>{try{let f="";t&&(f=await Ti(t)),e.handleAuthResponse(await r.startNewUser({projectId:e.projectId,clientId:e.clientId,firstName:s.firstName,lastName:s.lastName,email:s.email,password:s.password,remember:s.remember==="true",recaptchaSiteKey:t,recaptchaToken:f}))}catch(f){n(Ai(f))}},children:[ue(Ny,{sx:{flexDirection:"column"},children:e.children}),ue(Uo,{issues:l}),o&&_o(zy,{children:[ue(ki,{position:"center",p:"xl",style:{height:70},children:ue(Nr,{googleClientId:o,handleGoogleCredential:async s=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:s.clientId,googleCredential:s.credential,createUser:!0}))}catch(f){n(Ai(f))}}})}),ue(Vy,{label:"or",labelPosition:"center",my:"lg"})]}),_o(Gy,{spacing:"xl",children:[ue(Tn,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:ae(a,"firstName")}),ue(Tn,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:ae(a,"lastName")}),ue(Tn,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:ae(a,"email")}),ue(qy,{name:"password",label:"Password",autoComplete:"off",required:!0,error:ae(a,"password")}),_o(Bi,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",ue(Vr,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",ue(Vr,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),_o(Bi,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",ue(Vr,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",ue(Vr,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),_o(ki,{position:"apart",mt:"xl",noWrap:!0,children:[ue(Hy,{name:"remember",label:"Remember me",size:"xs"}),ue(Ly,{type:"submit",children:"Create account"})]})]})}import{jsx as kn,jsxs as Jy}from"react/jsx-runtime";function p2(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,s=v(),[f,i]=Fi(),[u,d]=Fi();Xy(()=>{o==="patient"&&f&&s.startNewPatient({login:f,projectId:t}).then(x=>s.processCode(x.code)).then(()=>l()).catch(x=>d(Wy(x)))},[s,o,t,f,l]);function c(x){x.code?s.processCode(x.code).then(()=>l()).catch(console.log):x.login&&i(x.login)}return Jy(sr,{width:450,children:[u&&kn("pre",{children:JSON.stringify(u,null,2)}),!f&&kn(Mi,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:c,children:e.children}),f&&o==="project"&&kn(Er,{login:f,handleAuthResponse:c})]})}import{showNotification as Xi}from"@mantine/notifications";import{normalizeErrorString as Ji}from"@medplum/core";import{useCallback as An,useEffect as bv,useState as Mn}from"react";import{Anchor as wi,Button as Oi,Center as Ei,Checkbox as $y,Divider as Ky,Group as Bn,PasswordInput as _y,Stack as Zy,TextInput as Yy}from"@mantine/core";import{normalizeOperationOutcome as jy}from"@medplum/core";import{useCallback as qr,useState as Li}from"react";import{Fragment as tv,jsx as oe,jsxs as Bt}from"react/jsx-runtime";function Ni(e){let[o,t]=Li();return o?oe(ov,{email:o,...e}):oe(ev,{setEmail:t,...e})}function ev(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,s=v(),f=!e.disableGoogleAuth&&Hr(e.googleClientId),i=qr(async c=>{if(!c.authorizeUrl)return!1;let x=JSON.stringify({...await s.ensureCodeChallenge(l),domain:c.domain}),C=new URL(c.authorizeUrl);return C.searchParams.set("state",x),window.location.assign(C.toString()),!0},[s,l]),u=qr(async c=>{let x=await s.post("auth/method",{email:c.email});await i(x)||o(c.email)},[s,i,o]),d=qr(async c=>{let x=await s.startGoogleLogin({...l,googleCredential:c.credential});await i(x)||r(x)},[s,l,i,r]);return Bt(W,{style:{maxWidth:400},onSubmit:u,children:[oe(Ei,{sx:{flexDirection:"column"},children:a}),f&&Bt(tv,{children:[oe(Bn,{position:"center",p:"xl",style:{height:70},children:oe(Nr,{googleClientId:f,handleGoogleCredential:d})}),!n&&oe(Ky,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&oe(Yy,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Bt(Bn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[oe("div",{children:t&&oe(wi,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&oe(Oi,{type:"submit",children:"Next"})]})]})}function ov(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=v(),[l,s]=Li(),f=_t(l,void 0),i=qr(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(d=>s(jy(d)))},[n,a,t]);return Bt(W,{style:{maxWidth:400},onSubmit:i,children:[oe(Ei,{sx:{flexDirection:"column"},children:r}),oe(Uo,{issues:f}),oe(Zy,{spacing:"xl",children:oe(_y,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:ae(l,"password")})}),Bt(Bn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&oe(wi,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),oe($y,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),oe(Oi,{type:"submit",children:"Sign in"})]})]})}import{Avatar as rv,Center as av,Group as nv,Stack as lv,Text as Hi,Title as fv,UnstyledButton as sv}from"@mantine/core";import{normalizeOperationOutcome as iv}from"@medplum/core";import{useState as uv}from"react";import{jsx as po,jsxs as Gr}from"react/jsx-runtime";function Vi(e){let o=v(),[t,r]=uv();return Gr(lv,{children:[Gr(av,{sx:{flexDirection:"column"},children:[po(_e,{size:32}),po(fv,{order:3,children:"Choose profile"})]}),po(Uo,{outcome:t}),e.memberships.map(a=>po(sv,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(iv(n)))},children:Gr(nv,{children:[po(rv,{radius:"xl"}),Gr("div",{style:{flex:1},children:[po(Hi,{size:"sm",weight:500,children:a.profile?.display}),po(Hi,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as cv,Center as dv,Checkbox as mv,Group as pv,Stack as qi,Title as xv}from"@mantine/core";import{jsx as xo,jsxs as Gi}from"react/jsx-runtime";function Ui(e){let o=v();return xo(W,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:Gi(qi,{children:[Gi(dv,{sx:{flexDirection:"column"},children:[xo(_e,{size:32}),xo(xv,{children:"Choose scope"})]}),xo(qi,{children:(e.scope??"openid").split(" ").map(t=>xo(mv,{id:t,name:t,label:t,defaultChecked:!0},t))}),xo(pv,{position:"right",mt:"xl",children:xo(cv,{type:"submit",children:"Set scope"})})]})})}import{Alert as Iv,Button as gv,Center as hv,Group as Cv,Stack as Qi,TextInput as yv,Title as vv}from"@mantine/core";import{normalizeErrorString as Sv}from"@medplum/core";import{useState as Rv}from"react";import{jsx as Ge,jsxs as zi}from"react/jsx-runtime";function Wi(e){let o=v(),[t,r]=Rv();return Ge(W,{style:{maxWidth:400},onSubmit:a=>{r(void 0),o.post("auth/mfa/verify",{login:e.login,token:a.token}).then(e.handleAuthResponse).catch(n=>r(Sv(n)))},children:zi(Qi,{children:[zi(hv,{sx:{flexDirection:"column"},children:[Ge(_e,{size:32}),Ge(vv,{children:"Enter MFA code"})]}),t&&Ge(Iv,{icon:Ge(to,{size:16}),title:"Error",color:"red",children:t}),Ge(Qi,{children:Ge(yv,{name:"token",label:"MFA code",required:!0})}),Ge(Cv,{position:"right",mt:"xl",children:Ge(gv,{type:"submit",children:"Submit code"})})]})})}import{jsx as Io}from"react/jsx-runtime";function gN(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...s}=e,f=v(),[i,u]=Mn(),[d,c]=Mn(!1),[x,C]=Mn(),I=An(b=>{l?l(b):f.processCode(b).then(()=>{r&&r()}).catch(T=>Xi({color:"red",message:Ji(T)}))},[f,l,r]),R=An(b=>{c(!!b.mfaRequired),b.login&&u(b.login),b.memberships&&C(b.memberships),b.code&&(t?C(void 0):I(b.code))},[t,I]),D=An(b=>{I(b.code)},[I]);return bv(()=>{o&&!i&&f.get("auth/login/"+o).then(R).catch(b=>Xi({color:"red",message:Ji(b)}))},[f,o,i,R]),Io(sr,{width:450,children:(()=>i?d?Io(Wi,{login:i,handleAuthResponse:R}):x?Io(Vi,{login:i,memberships:x,handleAuthResponse:R}):e.projectId==="new"?Io(Er,{login:i,handleAuthResponse:R}):e.chooseScopes?Io(Ui,{login:i,scope:e.scope,handleAuthResponse:D}):Io("div",{children:"Success"}):Io(Ni,{onForgotPassword:a,onRegister:n,handleAuthResponse:R,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children}))()})}export{qn as AddressDisplay,zn as AddressInput,Wn as AnnotationInput,BD as AppShell,Po as AsyncAutocomplete,hl as AttachmentArrayDisplay,yl as AttachmentArrayInput,Bo as AttachmentButton,Be as AttachmentDisplay,Ut as AttachmentInput,st as BackboneElementDisplay,pt as BackboneElementInput,Cf as CalendarInput,Kt as CheckboxFormSection,qt as CodeInput,Ao as CodeableConceptDisplay,Ol as CodeableConceptInput,bl as CodingDisplay,Zt as CodingInput,Pl as ContactDetailDisplay,Nl as ContactDetailInput,Wt as ContactPointDisplay,Yt as ContactPointInput,Xe as Container,De as DateTimeInput,JF as DefaultResourceTimeline,Sl as DescriptionList,Rl as DescriptionListEntry,La as DiagnosticReportDisplay,sr as Document,Up as ElementDefinitionInputSelector,xf as ElementDefinitionTypeInput,nw as EncounterTimeline,vo as ErrorBoundary,Gg as FhirPathTable,W as Form,xe as FormSection,dl as Header,Nt as HumanNameDisplay,Ul as HumanNameInput,Dl as IdentifierDisplay,Wl as IdentifierInput,Ca as Loading,_e as Logo,cE as MeasureReportDisplay,j as MedplumLink,kv as MedplumProvider,YO as MemoizedFhirPathTable,qO as MemoizedSearchControl,Tl as MoneyDisplay,Xl as MoneyInput,gl as Navbar,kx as ObservationTable,Uo as OperationOutcomeAlert,wo as Panel,bE as PatientTimeline,QE as PlanDefinitionBuilder,We as QuantityDisplay,ye as QuantityInput,S0 as QuestionnaireBuilder,ui as QuestionnaireForm,vr as QuestionnaireItemType,Xt as RangeDisplay,ct as RangeInput,lo as ReferenceDisplay,Fo as ReferenceInput,f1 as ReferenceRangeEditor,BC as ReferenceRangeGroupEditor,p2 as RegisterForm,g1 as RequestGroupDisplay,Fl as ResourceArrayDisplay,ff as ResourceArrayInput,le as ResourceAvatar,Je as ResourceBadge,F1 as ResourceBlame,V1 as ResourceDiff,K1 as ResourceForm,aL as ResourceHistoryTable,er as ResourceInput,Ae as ResourceName,re as ResourcePropertyDisplay,Ne as ResourcePropertyInput,Na as ResourceTable,Ke as ResourceTimeline,IL as Scheduler,Ya as SearchChangeEvent,so as SearchClickEvent,Bg as SearchControl,ss as SearchFieldEditor,xs as SearchFilterEditor,ja as SearchLoadEvent,RL as ServiceRequestTimeline,gN as SignInForm,rr as StatusBadge,wf as Timeline,$e as TimelineItem,mf as TimingInput,Qa as addDateFilterBetween,Sw as addField,Lo as addFilter,Yf as addLastMonthFilter,za as addMissingFilter,es as addNextMonthFilter,jf as addThisMonthFilter,_f as addTodayFilter,Zf as addTomorrowFilter,os as addYearToDateFilter,Kf as addYesterdayFilter,Re as buildFieldNameString,zs as buildInitialResponse,cn as buildInitialResponseItem,vw as clearFilters,cr as clearFiltersOnField,Vl as convertIsoToLocal,ql as convertLocalToIso,Lr as createScriptTag,$f as deleteFilter,Xs as formatReferenceString,ae as getErrorsForInput,Cs as getFieldDefinitions,_t as getIssuesForExpression,Us as getNewMultiSelectValues,Js as getNumberOfPages,vt as getOpString,Sr as getQuestionnaireItemReferenceTargetTypes,Ti as getRecaptcha,ns as getSearchOperators,rs as getSortField,Di as initRecaptcha,qs as isChoiceQuestion,Gs as isQuestionEnabled,as as isSortDescending,ml as parseForm,Ln as reactContext,ls as renderValue,yt as setFilters,AI as setOffset,ts as setPage,Rr as setQuestionnaireItemReferenceTargetTypes,Wa as setSort,Lf as sortByDateAndPriority,Rw as toggleSort,v as useMedplum,Yo as useMedplumContext,Ue as useMedplumNavigate,Ft as useMedplumProfile,G as useResource,wv as useSearch,Hn as useSearchOne,Vn as useSearchResources};
|
|
67
|
+
`)}),"...",$o("br",{})]})}import{Button as yi,Group as ny,Stack as ly,TextInput as vi}from"@mantine/core";import{deepClone as fy}from"@medplum/core";import{useEffect as sy,useState as Si}from"react";import{jsx as Ye,jsxs as bn}from"react/jsx-runtime";function Z1(e){let o=v(),t=G(e.defaultValue),[r,a]=Si(!1),[n,l]=Si();return sy(()=>{t&&(l(fy(t)),o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log))},[o,t]),!r||!n?Ye("div",{children:"Loading..."}):bn("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(n)},children:[bn(ly,{mb:"xl",children:[Ye(pe,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:Ye(vi,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),Ye(pe,{title:"ID",htmlFor:"id",outcome:e.outcome,children:Ye(vi,{name:"id",defaultValue:n.id,disabled:!0})})]}),Ye(pt,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:l}),bn(ny,{position:"right",mt:"xl",children:[Ye(yi,{type:"submit",children:"OK"}),e.onDelete&&Ye(yi,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}import{Table as iy}from"@mantine/core";import{formatDateTime as uy,normalizeErrorString as cy}from"@medplum/core";import{useEffect as dy,useState as my}from"react";import{jsx as me,jsxs as Pn}from"react/jsx-runtime";function lL(e){let o=v(),[t,r]=my(e.history);return dy(()=>{!e.history&&e.resourceType&&e.id&&o.readHistory(e.resourceType,e.id).then(r).catch(console.log)},[o,e.history,e.resourceType,e.id]),t?Pn(iy,{withBorder:!0,withColumnBorders:!0,children:[me("thead",{children:Pn("tr",{children:[me("th",{children:"Author"}),me("th",{children:"Date"}),me("th",{children:"Version"})]})}),me("tbody",{children:t.entry?.map((a,n)=>me(py,{entry:a},"entry-"+n))})]}):me("div",{children:"Loading..."})}function py(e){let{response:o,resource:t}=e.entry;return t?Pn("tr",{children:[me("td",{children:me(Je,{value:t.meta?.author,link:!0})}),me("td",{children:uy(t.meta?.lastUpdated)}),me("td",{children:me(j,{to:xy(t),children:t.meta?.versionId})})]}):me("tr",{children:me("td",{colSpan:3,children:cy(o?.outcome)})})}function xy(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as Iy,createStyles as gy,Stack as hy,Text as Cy}from"@mantine/core";import{getReferenceString as yy,isReference as vy}from"@medplum/core";import{useState as Fr}from"react";import{jsx as ie,jsxs as Ko}from"react/jsx-runtime";var Sy=gy(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function hL(e){let{classes:o}=Sy(),t=G(e.schedule),r=G(e.questionnaire),[a,n]=Fr(tr()),[l,s]=Fr(),[f,i]=Fr(),[u,d]=Fr(),[c]=Vn("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",vy(e.schedule)?e.schedule.reference:yy(e.schedule)],["start","gt"+Ry(a)],["start","lt"+by(a)]]));if(!t||!c||!r)return null;let x=t.actor?.[0];return Ko("div",{className:o.container,"data-testid":"scheduler",children:[Ko("div",{className:o.info,children:[x&&ie(le,{value:x,size:"xl"}),x&&ie(Cy,{size:"xl",weight:500,children:ie(Be,{value:x})}),ie("p",{children:"1 hour"}),l&&ie("p",{children:l.toLocaleDateString()}),f&&ie("p",{children:Ri(new Date(f.start))})]}),Ko("div",{className:o.selection,children:[!l&&Ko("div",{children:[ie("h3",{children:"Select date"}),ie(Cf,{slots:c,onChangeMonth:n,onClick:s})]}),l&&!f&&Ko("div",{children:[ie("h3",{children:"Select time"}),ie(hy,{children:c.map(h=>{let I=new Date(h.start);return I.getTime()>l.getTime()&&I.getTime()<l.getTime()+24*3600*1e3&&ie("div",{children:ie(Iy,{variant:"outline",style:{width:150},onClick:()=>i(h),children:Ri(I)})},h.id)})})]}),l&&f&&!u&&ie(ui,{questionnaire:r,submitButtonText:"Next",onSubmit:d}),l&&f&&u&&Ko("div",{children:[ie("h3",{children:"You're all set!"}),ie("p",{children:"Check your email for a calendar invite."})]})]})]})}function Ry(e){return bi(e.getTime())}function by(e){return bi(e.getTime()+31*24*60*60*1e3)}function bi(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Ri(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as wr}from"@medplum/core";import{jsx as Py}from"react/jsx-runtime";function PL(e){return Py(Ke,{value:e.serviceRequest,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory("ServiceRequest",r),o.search("Communication",{"based-on":a,_count:n}),o.search("DiagnosticReport",{"based-on":a,_count:n}),o.search("Media",{"based-on":a,_count:n}),o.search("DocumentReference",{related:a,_count:n}),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])},createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",basedOn:[wr(o)],subject:o.subject,sender:wr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[wr(o)],subject:o.subject,operator:wr(t),issued:new Date().toISOString(),content:r})})}import{normalizeOperationOutcome as Jy}from"@medplum/core";import{useEffect as $y,useState as Fi}from"react";import{Anchor as Pi,Button as Dy,Center as ky,Group as Ty,Stack as By,Text as Ay,TextInput as My,Title as Fy}from"@mantine/core";import{normalizeOperationOutcome as wy}from"@medplum/core";import{useState as Oy}from"react";import{jsx as mo,jsxs as Or}from"react/jsx-runtime";function Er(e){let o=v(),[t,r]=Oy();return Or(W,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(wy(n))}},children:[Or(ky,{sx:{flexDirection:"column"},children:[mo(_e,{size:32}),mo(Fy,{children:"Create project"})]}),Or(By,{spacing:"xl",children:[mo(My,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:ae(t,"firstName")}),Or(Ay,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",mo(Pi,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",mo(Pi,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),mo(Ty,{position:"right",mt:"xl",noWrap:!0,children:mo(Dy,{type:"submit",children:"Create project"})})]})}import{Anchor as Vr,Button as Hy,Center as Vy,Checkbox as qy,Divider as Gy,Group as Ti,PasswordInput as Uy,Stack as Qy,Text as Bi,TextInput as kn}from"@mantine/core";import{normalizeOperationOutcome as Ai}from"@medplum/core";import{useEffect as zy,useState as Wy}from"react";import{useEffect as Ey,useRef as Ly,useState as Dn}from"react";function Lr(e,o){let t=document.getElementsByTagName("head")[0],r=document.createElement("script");r.async=!0,r.src=e,r.onload=o??null,t.appendChild(r)}import{jsx as Ny}from"react/jsx-runtime";function Nr(e){let o=v(),{googleClientId:t,handleGoogleCredential:r}=e,a=Ly(null),[n,l]=Dn(typeof google<"u"),[s,f]=Dn(!1),[i,u]=Dn(!1);return Ey(()=>{if(typeof google>"u"){Lr("https://accounts.google.com/gsi/client",()=>l(!0));return}s||(google.accounts.id.initialize({client_id:t,callback:r}),f(!0)),a.current&&!i&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,s,n,a,i,r]),t?Ny("div",{ref:a}):null}function Hr(e){if(e)return e;if(typeof window<"u"){let o=window.location.protocol+"//"+window.location.host;if(("undefined"?.split(",")??[]).includes(o))return"__GOOGLE_CLIENT_ID__"}}function Di(e){typeof grecaptcha>"u"&&Lr("https://www.google.com/recaptcha/api.js?render="+e)}function ki(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as Xy,jsx as ue,jsxs as _o}from"react/jsx-runtime";function Mi(e){let o=Hr(e.googleClientId),t=e.recaptchaSiteKey,r=v(),[a,n]=Wy(),l=_t(a,void 0);return zy(()=>{t&&Di(t)},[t]),_o(W,{style:{maxWidth:400},onSubmit:async s=>{try{let f="";t&&(f=await ki(t)),e.handleAuthResponse(await r.startNewUser({projectId:e.projectId,clientId:e.clientId,firstName:s.firstName,lastName:s.lastName,email:s.email,password:s.password,remember:s.remember==="true",recaptchaSiteKey:t,recaptchaToken:f}))}catch(f){n(Ai(f))}},children:[ue(Vy,{sx:{flexDirection:"column"},children:e.children}),ue(Uo,{issues:l}),o&&_o(Xy,{children:[ue(Ti,{position:"center",p:"xl",style:{height:70},children:ue(Nr,{googleClientId:o,handleGoogleCredential:async s=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:s.clientId,googleCredential:s.credential,createUser:!0}))}catch(f){n(Ai(f))}}})}),ue(Gy,{label:"or",labelPosition:"center",my:"lg"})]}),_o(Qy,{spacing:"xl",children:[ue(kn,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:ae(a,"firstName")}),ue(kn,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:ae(a,"lastName")}),ue(kn,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:ae(a,"email")}),ue(Uy,{name:"password",label:"Password",autoComplete:"off",required:!0,error:ae(a,"password")}),_o(Bi,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",ue(Vr,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",ue(Vr,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),_o(Bi,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",ue(Vr,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",ue(Vr,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),_o(Ti,{position:"apart",mt:"xl",noWrap:!0,children:[ue(qy,{name:"remember",label:"Remember me",size:"xs"}),ue(Hy,{type:"submit",children:"Create account"})]})]})}import{jsx as Tn,jsxs as Ky}from"react/jsx-runtime";function I2(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,s=v(),[f,i]=Fi(),[u,d]=Fi();$y(()=>{o==="patient"&&f&&s.startNewPatient({login:f,projectId:t}).then(x=>s.processCode(x.code)).then(()=>l()).catch(x=>d(Jy(x)))},[s,o,t,f,l]);function c(x){x.code?s.processCode(x.code).then(()=>l()).catch(console.log):x.login&&i(x.login)}return Ky(sr,{width:450,children:[u&&Tn("pre",{children:JSON.stringify(u,null,2)}),!f&&Tn(Mi,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:c,children:e.children}),f&&o==="project"&&Tn(Er,{login:f,handleAuthResponse:c})]})}import{showNotification as Xi}from"@mantine/notifications";import{normalizeErrorString as Ji}from"@medplum/core";import{useCallback as An,useEffect as Dv,useState as Mn}from"react";import{Anchor as wi,Button as Oi,Center as Ei,Checkbox as _y,Divider as Zy,Group as Bn,PasswordInput as Yy,Stack as jy,TextInput as ev}from"@mantine/core";import{normalizeOperationOutcome as ov}from"@medplum/core";import{useCallback as qr,useState as Li}from"react";import{Fragment as av,jsx as oe,jsxs as Bt}from"react/jsx-runtime";function Ni(e){let[o,t]=Li();return o?oe(rv,{email:o,...e}):oe(tv,{setEmail:t,...e})}function tv(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,s=v(),f=!e.disableGoogleAuth&&Hr(e.googleClientId),i=qr(async c=>{if(!c.authorizeUrl)return!1;let x=JSON.stringify({...await s.ensureCodeChallenge(l),domain:c.domain}),h=new URL(c.authorizeUrl);return h.searchParams.set("state",x),window.location.assign(h.toString()),!0},[s,l]),u=qr(async c=>{let x=await s.post("auth/method",{email:c.email});await i(x)||o(c.email)},[s,i,o]),d=qr(async c=>{let x=await s.startGoogleLogin({...l,googleCredential:c.credential});await i(x)||r(x)},[s,l,i,r]);return Bt(W,{style:{maxWidth:400},onSubmit:u,children:[oe(Ei,{sx:{flexDirection:"column"},children:a}),f&&Bt(av,{children:[oe(Bn,{position:"center",p:"xl",style:{height:70},children:oe(Nr,{googleClientId:f,handleGoogleCredential:d})}),!n&&oe(Zy,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&oe(ev,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Bt(Bn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[oe("div",{children:t&&oe(wi,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&oe(Oi,{type:"submit",children:"Next"})]})]})}function rv(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=v(),[l,s]=Li(),f=_t(l,void 0),i=qr(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(d=>s(ov(d)))},[n,a,t]);return Bt(W,{style:{maxWidth:400},onSubmit:i,children:[oe(Ei,{sx:{flexDirection:"column"},children:r}),oe(Uo,{issues:f}),oe(jy,{spacing:"xl",children:oe(Yy,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:ae(l,"password")})}),Bt(Bn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&oe(wi,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),oe(_y,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),oe(Oi,{type:"submit",children:"Sign in"})]})]})}import{Avatar as nv,Center as lv,Group as fv,Stack as sv,Text as Hi,Title as iv,UnstyledButton as uv}from"@mantine/core";import{normalizeOperationOutcome as cv}from"@medplum/core";import{useState as dv}from"react";import{jsx as po,jsxs as Gr}from"react/jsx-runtime";function Vi(e){let o=v(),[t,r]=dv();return Gr(sv,{children:[Gr(lv,{sx:{flexDirection:"column"},children:[po(_e,{size:32}),po(iv,{order:3,children:"Choose profile"})]}),po(Uo,{outcome:t}),e.memberships.map(a=>po(uv,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(cv(n)))},children:Gr(fv,{children:[po(nv,{radius:"xl"}),Gr("div",{style:{flex:1},children:[po(Hi,{size:"sm",weight:500,children:a.profile?.display}),po(Hi,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as mv,Center as pv,Checkbox as xv,Group as Iv,Stack as qi,Title as gv}from"@mantine/core";import{jsx as xo,jsxs as Gi}from"react/jsx-runtime";function Ui(e){let o=v();return xo(W,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:Gi(qi,{children:[Gi(pv,{sx:{flexDirection:"column"},children:[xo(_e,{size:32}),xo(gv,{children:"Choose scope"})]}),xo(qi,{children:(e.scope??"openid").split(" ").map(t=>xo(xv,{id:t,name:t,label:t,defaultChecked:!0},t))}),xo(Iv,{position:"right",mt:"xl",children:xo(mv,{type:"submit",children:"Set scope"})})]})})}import{Alert as hv,Button as Cv,Center as yv,Group as vv,Stack as Qi,TextInput as Sv,Title as Rv}from"@mantine/core";import{normalizeErrorString as bv}from"@medplum/core";import{useState as Pv}from"react";import{jsx as Ge,jsxs as zi}from"react/jsx-runtime";function Wi(e){let o=v(),[t,r]=Pv();return Ge(W,{style:{maxWidth:400},onSubmit:a=>{r(void 0),o.post("auth/mfa/verify",{login:e.login,token:a.token}).then(e.handleAuthResponse).catch(n=>r(bv(n)))},children:zi(Qi,{children:[zi(yv,{sx:{flexDirection:"column"},children:[Ge(_e,{size:32}),Ge(Rv,{children:"Enter MFA code"})]}),t&&Ge(hv,{icon:Ge(to,{size:16}),title:"Error",color:"red",children:t}),Ge(Qi,{children:Ge(Sv,{name:"token",label:"MFA code",required:!0})}),Ge(vv,{position:"right",mt:"xl",children:Ge(Cv,{type:"submit",children:"Submit code"})})]})})}import{jsx as Io}from"react/jsx-runtime";function CN(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...s}=e,f=v(),[i,u]=Mn(),[d,c]=Mn(!1),[x,h]=Mn(),I=An(b=>{l?l(b):f.processCode(b).then(()=>{r&&r()}).catch(k=>Xi({color:"red",message:Ji(k)}))},[f,l,r]),R=An(b=>{c(!!b.mfaRequired),b.login&&u(b.login),b.memberships&&h(b.memberships),b.code&&(t?h(void 0):I(b.code))},[t,I]),D=An(b=>{I(b.code)},[I]);return Dv(()=>{o&&!i&&f.get("auth/login/"+o).then(R).catch(b=>Xi({color:"red",message:Ji(b)}))},[f,o,i,R]),Io(sr,{width:450,children:i?d?Io(Wi,{login:i,handleAuthResponse:R}):x?Io(Vi,{login:i,memberships:x,handleAuthResponse:R}):e.projectId==="new"?Io(Er,{login:i,handleAuthResponse:R}):e.chooseScopes?Io(Ui,{login:i,scope:e.scope,handleAuthResponse:D}):Io("div",{children:"Success"}):Io(Ni,{onForgotPassword:a,onRegister:n,handleAuthResponse:R,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children})})}export{qn as AddressDisplay,zn as AddressInput,Wn as AnnotationInput,MD as AppShell,Po as AsyncAutocomplete,hl as AttachmentArrayDisplay,yl as AttachmentArrayInput,Bo as AttachmentButton,ke as AttachmentDisplay,Ut as AttachmentInput,st as BackboneElementDisplay,pt as BackboneElementInput,Cf as CalendarInput,Kt as CheckboxFormSection,qt as CodeInput,Ao as CodeableConceptDisplay,Ol as CodeableConceptInput,bl as CodingDisplay,Zt as CodingInput,Pl as ContactDetailDisplay,Nl as ContactDetailInput,Wt as ContactPointDisplay,Yt as ContactPointInput,Xe as Container,be as DateTimeInput,KF as DefaultResourceTimeline,Sl as DescriptionList,Rl as DescriptionListEntry,La as DiagnosticReportDisplay,sr as Document,Up as ElementDefinitionInputSelector,xf as ElementDefinitionTypeInput,fw as EncounterTimeline,vo as ErrorBoundary,Qg as FhirPathTable,W as Form,pe as FormSection,dl as Header,Nt as HumanNameDisplay,Ul as HumanNameInput,Dl as IdentifierDisplay,Wl as IdentifierInput,Ca as Loading,_e as Logo,mE as MeasureReportDisplay,j as MedplumLink,Av as MedplumProvider,eE as MemoizedFhirPathTable,UO as MemoizedSearchControl,kl as MoneyDisplay,Xl as MoneyInput,gl as Navbar,Tx as ObservationTable,Uo as OperationOutcomeAlert,wo as Panel,DE as PatientTimeline,WE as PlanDefinitionBuilder,We as QuantityDisplay,he as QuantityInput,b0 as QuestionnaireBuilder,ui as QuestionnaireForm,vr as QuestionnaireItemType,Xt as RangeDisplay,ct as RangeInput,lo as ReferenceDisplay,Fo as ReferenceInput,i1 as ReferenceRangeEditor,MC as ReferenceRangeGroupEditor,I2 as RegisterForm,C1 as RequestGroupDisplay,Fl as ResourceArrayDisplay,ff as ResourceArrayInput,le as ResourceAvatar,Je as ResourceBadge,O1 as ResourceBlame,G1 as ResourceDiff,Z1 as ResourceForm,lL as ResourceHistoryTable,er as ResourceInput,Be as ResourceName,re as ResourcePropertyDisplay,Le as ResourcePropertyInput,Na as ResourceTable,Ke as ResourceTimeline,hL as Scheduler,Ya as SearchChangeEvent,so as SearchClickEvent,Mg as SearchControl,ss as SearchFieldEditor,xs as SearchFilterEditor,ja as SearchLoadEvent,PL as ServiceRequestTimeline,CN as SignInForm,rr as StatusBadge,wf as Timeline,$e as TimelineItem,mf as TimingInput,Qa as addDateFilterBetween,bw as addField,Lo as addFilter,Yf as addLastMonthFilter,za as addMissingFilter,es as addNextMonthFilter,jf as addThisMonthFilter,_f as addTodayFilter,Zf as addTomorrowFilter,os as addYearToDateFilter,Kf as addYesterdayFilter,ve as buildFieldNameString,zs as buildInitialResponse,cn as buildInitialResponseItem,Rw as clearFilters,cr as clearFiltersOnField,Vl as convertIsoToLocal,ql as convertLocalToIso,Lr as createScriptTag,$f as deleteFilter,Xs as formatReferenceString,ae as getErrorsForInput,Cs as getFieldDefinitions,_t as getIssuesForExpression,Us as getNewMultiSelectValues,Js as getNumberOfPages,vt as getOpString,Sr as getQuestionnaireItemReferenceTargetTypes,ki as getRecaptcha,ns as getSearchOperators,rs as getSortField,Di as initRecaptcha,qs as isChoiceQuestion,Gs as isQuestionEnabled,as as isSortDescending,ml as parseForm,Ln as reactContext,ls as renderValue,yt as setFilters,FI as setOffset,ts as setPage,Rr as setQuestionnaireItemReferenceTargetTypes,Wa as setSort,Lf as sortByDateAndPriority,Pw as toggleSort,v as useMedplum,Yo as useMedplumContext,Ue as useMedplumNavigate,Ft as useMedplumProfile,G as useResource,Ev as useSearch,Hn as useSearchOne,Vn as useSearchResources};
|
|
68
68
|
//# sourceMappingURL=index.mjs.map
|