@medplum/react 2.1.24 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var nc=Object.create;var ga=Object.defineProperty;var lc=Object.getOwnPropertyDescriptor;var fc=Object.getOwnPropertyNames;var sc=Object.getPrototypeOf,ic=Object.prototype.hasOwnProperty;var uc=(e,o)=>{for(var t in o)ga(e,t,{get:o[t],enumerable:!0})},_f=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of fc(o))!ic.call(e,a)&&a!==t&&ga(e,a,{get:()=>o[a],enumerable:!(r=lc(o,a))||r.enumerable});return e};var cc=(e,o,t)=>(t=e!=null?nc(sc(e)):{},_f(o||!e||!e.__esModule?ga(t,"default",{value:e,enumerable:!0}):t,e)),dc=e=>_f(ga({},"__esModule",{value:!0}),e);var Pp={};uc(Pp,{AddressDisplay:()=>zn,AddressInput:()=>Wn,AnnotationInput:()=>Xn,AppShell:()=>Jc,AsyncAutocomplete:()=>vt,AttachmentArrayDisplay:()=>Fl,AttachmentArrayInput:()=>Ol,AttachmentButton:()=>Rt,AttachmentDisplay:()=>no,AttachmentInput:()=>wr,BackboneElementDisplay:()=>Zt,BackboneElementInput:()=>ar,CalendarInput:()=>of,CheckboxFormSection:()=>Nr,CodeInput:()=>Fr,CodeableConceptDisplay:()=>bt,CodeableConceptInput:()=>Ql,CodingDisplay:()=>Hl,CodingInput:()=>qr,ContactDetailDisplay:()=>Vl,ContactDetailInput:()=>zl,ContactPointDisplay:()=>Or,ContactPointInput:()=>Gr,Container:()=>No,DateTimeInput:()=>eo,DefaultResourceTimeline:()=>Nd,DescriptionList:()=>Ll,DescriptionListEntry:()=>Nl,DiagnosticReportDisplay:()=>un,Document:()=>ea,ElementDefinitionInputSelector:()=>yi,ElementDefinitionTypeInput:()=>ef,EncounterTimeline:()=>Hd,ErrorBoundary:()=>yt,FhirPathTable:()=>ru,Form:()=>oe,FormSection:()=>He,Header:()=>kl,HumanNameDisplay:()=>Br,HumanNameInput:()=>$l,IdentifierDisplay:()=>ql,IdentifierInput:()=>Kl,Loading:()=>Ta,Logo:()=>Jo,MeasureReportDisplay:()=>dm,MedplumLink:()=>Se,MedplumProvider:()=>mc,MemoizedFhirPathTable:()=>sm,MemoizedSearchControl:()=>tm,MoneyDisplay:()=>Gl,MoneyInput:()=>_l,Navbar:()=>Ml,ObservationTable:()=>Mi,OperationOutcomeAlert:()=>Lt,Panel:()=>Ft,PatientTimeline:()=>mm,PlanDefinitionBuilder:()=>pm,QuantityDisplay:()=>wo,QuantityInput:()=>qe,QuestionnaireBuilder:()=>Om,QuestionnaireForm:()=>Uf,QuestionnaireItemType:()=>na,RangeDisplay:()=>Er,RangeInput:()=>tr,ReferenceDisplay:()=>Yo,ReferenceInput:()=>At,ReferenceRangeEditor:()=>$m,ReferenceRangeGroupEditor:()=>Fu,RegisterForm:()=>vp,RequestGroupDisplay:()=>op,ResourceArrayDisplay:()=>Ul,ResourceArrayInput:()=>Yl,ResourceAvatar:()=>Me,ResourceBadge:()=>Ho,ResourceBlame:()=>sp,ResourceDiff:()=>up,ResourceForm:()=>dp,ResourceHistoryTable:()=>mp,ResourceInput:()=>_r,ResourceName:()=>lo,ResourcePropertyDisplay:()=>Pe,ResourcePropertyInput:()=>Co,ResourceTable:()=>mn,ResourceTimeline:()=>Go,Scheduler:()=>gp,SearchChangeEvent:()=>vn,SearchClickEvent:()=>ut,SearchControl:()=>ou,SearchFieldEditor:()=>Pf,SearchFilterEditor:()=>Df,SearchLoadEvent:()=>Sn,ServiceRequestTimeline:()=>yp,SignInForm:()=>bp,StatusBadge:()=>jr,Timeline:()=>nf,TimelineItem:()=>Vo,TimingInput:()=>jl,addDateFilterBetween:()=>xn,addField:()=>Ud,addFilter:()=>Ot,addLastMonthFilter:()=>xf,addMissingFilter:()=>In,addNextMonthFilter:()=>gf,addThisMonthFilter:()=>If,addTodayFilter:()=>df,addTomorrowFilter:()=>mf,addYearToDateFilter:()=>Cf,addYesterdayFilter:()=>cf,buildFieldNameString:()=>Qe,buildInitialResponse:()=>Of,buildInitialResponseItem:()=>Dn,clearFilters:()=>Gd,clearFiltersOnField:()=>ta,convertIsoToLocal:()=>Xl,convertLocalToIso:()=>Jl,createScriptTag:()=>pa,deleteFilter:()=>uf,formatReferenceString:()=>Ef,getErrorsForInput:()=>De,getFieldDefinitions:()=>kf,getIssuesForExpression:()=>Hr,getNewMultiSelectValues:()=>wf,getNumberOfPages:()=>Lf,getOpString:()=>cr,getQuestionnaireItemReferenceTargetTypes:()=>la,getRecaptcha:()=>Wf,getSearchOperators:()=>Rf,getSortField:()=>vf,initRecaptcha:()=>zf,isChoiceQuestion:()=>Mf,isQuestionEnabled:()=>Ff,isSortDescending:()=>Sf,parseForm:()=>Tl,reactContext:()=>qn,renderValue:()=>bf,setFilters:()=>ur,setOffset:()=>_i,setPage:()=>yf,setQuestionnaireItemReferenceTargetTypes:()=>fa,setSort:()=>gn,sortByDateAndPriority:()=>lf,toggleSort:()=>Qd,useMedplum:()=>P,useMedplumContext:()=>Gt,useMedplumNavigate:()=>To,useMedplumProfile:()=>Sr,useResource:()=>K,useSearch:()=>xc,useSearchOne:()=>Gn,useSearchResources:()=>Un});module.exports=dc(Pp);var gt=require("react"),ha=require("react"),Yf=require("react/jsx-runtime"),Bo=require("@medplum/core"),ht=require("react"),Ca=require("@medplum/core"),It=require("react"),qn=(0,ha.createContext)(void 0);function Gt(){return(0,ha.useContext)(qn)}function P(){return Gt().medplum}function To(){return Gt().navigate}function Sr(){return Gt().profile}function mc(e){let o=e.medplum,t=e.navigate??pc,[r,a]=(0,gt.useState)({profile:o.getProfile(),loading:!o.isInitialized});(0,gt.useEffect)(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),(0,gt.useEffect)(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=(0,gt.useMemo)(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return(0,Yf.jsx)(qn.Provider,{value:n,children:e.children})}function pc(e){window.location.assign(e)}function K(e,o){let t=P(),[r,a]=(0,ht.useState)(Zf(t,e)),n=(0,ht.useCallback)(l=>{(0,Bo.deepEquals)(l,r)||a(l)},[r,a]);return(0,ht.useEffect)(()=>{n(Zf(t,e))},[t,e,n]),(0,ht.useEffect)(()=>{let l=!0;return(0,Bo.isReference)(e)&&t.readReference(e).then(s=>{l&&n(s)}).catch(s=>{l&&(n(void 0),o&&o((0,Bo.normalizeOperationOutcome)(s)))}),()=>l=!1},[t,r,e,n,o]),r}function Zf(e,o){if(o){if((0,Bo.isResource)(o))return o;if((0,Bo.isReference)(o))return e.getCachedReference(o)}}function xc(e,o){return Qn("search",e,o)}function Gn(e,o){return Qn("searchOne",e,o)}function Un(e,o){return Qn("searchResources",e,o)}function Qn(e,o,t){let r=P(),[a,n]=(0,It.useState)(),[l,s]=(0,It.useState)(!1),[f,i]=(0,It.useState)(),[u,d]=(0,It.useState)();return(0,It.useEffect)(()=>{let c=r.fhirSearchUrl(o,t).toString();c!==a&&(n(c),r[e](o,t).then(x=>{s(!1),i(x),d(Ca.allOk)}).catch(x=>{s(!1),i(void 0),d((0,Ca.normalizeOperationOutcome)(x))}))},[r,e,o,t,a,i]),[f,l,u]}var jf=require("@medplum/core"),ya=require("react/jsx-runtime");function zn(e){let o=e.value;return o?(0,ya.jsx)(ya.Fragment,{children:(0,jf.formatAddress)(o)}):null}var ao=require("@mantine/core"),va=require("react"),po=require("react/jsx-runtime");function es(e,o){return e.line&&e.line.length>o?e.line[o]:""}function os(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function Wn(e){let[o,t]=(0,va.useState)(e.defaultValue||{}),r=(0,va.useRef)();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(os(r.current||{},0,c))}function f(c){a(os(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(0,po.jsxs)(ao.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,po.jsx)(ao.NativeSelect,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),(0,po.jsx)(ao.NativeSelect,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>l(c.currentTarget.value),data:["","postal","physical","both"]}),(0,po.jsx)(ao.TextInput,{placeholder:"Line 1",defaultValue:es(o,0),onChange:c=>s(c.currentTarget.value)}),(0,po.jsx)(ao.TextInput,{placeholder:"Line 2",defaultValue:es(o,1),onChange:c=>f(c.currentTarget.value)}),(0,po.jsx)(ao.TextInput,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),(0,po.jsx)(ao.TextInput,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),(0,po.jsx)(ao.TextInput,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:c=>d(c.currentTarget.value)})]})}var ts=require("@mantine/core"),rs=require("@medplum/core");var Sa=require("react"),as=require("react/jsx-runtime");function Xn(e){let o=Sr(),[t,r]=(0,Sa.useState)(e.defaultValue||{}),a=(0,Sa.useRef)();a.current=t;function n(l){let s=l?{text:l,authorReference:o&&(0,rs.createReference)(o),time:new Date().toISOString()}:{};r(s),e.onChange&&e.onChange(s)}return(0,as.jsx)(ts.TextInput,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}var Ha=require("@mantine/core"),Ms=require("@mantine/notifications");var $t=require("react");var us=require("@mantine/core"),cs=require("@medplum/core");var Rr=require("react"),$o=cc(require("prop-types"));var ns={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 Ic=Object.defineProperty,gc=Object.defineProperties,hc=Object.getOwnPropertyDescriptors,Ra=Object.getOwnPropertySymbols,ss=Object.prototype.hasOwnProperty,is=Object.prototype.propertyIsEnumerable,ls=(e,o,t)=>o in e?Ic(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,fs=(e,o)=>{for(var t in o||(o={}))ss.call(o,t)&&ls(e,t,o[t]);if(Ra)for(var t of Ra(o))is.call(o,t)&&ls(e,t,o[t]);return e},Cc=(e,o)=>gc(e,hc(o)),yc=(e,o)=>{var t={};for(var r in e)ss.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ra)for(var r of Ra(e))o.indexOf(r)<0&&is.call(e,r)&&(t[r]=e[r]);return t},p=(e,o,t)=>{let r=(0,Rr.forwardRef)((a,n)=>{var l=a,{color:s="currentColor",size:f=24,stroke:i=2,children:u}=l,d=yc(l,["color","size","stroke","children"]);return(0,Rr.createElement)("svg",fs(Cc(fs({ref:n},ns),{width:f,height:f,stroke:s,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),d),[...t.map(([c,x])=>(0,Rr.createElement)(c,x)),...u||[]])});return r.propTypes={color:$o.default.string,size:$o.default.oneOfType([$o.default.string,$o.default.number]),stroke:$o.default.oneOfType([$o.default.string,$o.default.number])},r.displayName=`${o}`,r};var Jn=p("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 Ct=p("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 $n=p("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 Kn=p("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 _n=p("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 Zn=p("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 Yn=p("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 jn=p("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 el=p("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 ol=p("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 Ao=p("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 br=p("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var tl=p("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 rl=p("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Ko=p("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 Ut=p("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 Pr=p("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 al=p("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 nl=p("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 ll=p("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 fl=p("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 sl=p("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 Qt=p("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 zt=p("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var ba=p("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 il=p("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 ul=p("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 cl=p("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 dl=p("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 Pa=p("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Da=p("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var ml=p("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 pl=p("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 xl=p("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 Il=p("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var gl=p("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 hl=p("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 Wt=p("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 Dr=p("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 kr=p("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 Cl=p("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 yl=p("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 vl=p("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 Tr=p("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 Sl=p("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);var ds=require("react"),Rl=require("react/jsx-runtime"),yt=class extends ds.Component{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?(0,Rl.jsx)(us.Alert,{icon:(0,Rl.jsx)(Ct,{size:16}),title:"Something went wrong",color:"red",children:(0,cs.normalizeErrorString)(this.state.error)}):this.props.children}};var ka=require("@mantine/core"),bl=require("react/jsx-runtime");function Ta(){return(0,bl.jsx)(ka.Center,{style:{width:"100%",height:"100vh"},children:(0,bl.jsx)(ka.Loader,{})})}var W=require("@mantine/core"),Mr=require("@medplum/core");var Ss=require("react");var ms=require("@medplum/core"),Ba=require("react/jsx-runtime");function Br(e){let o=e.value;return o?(0,Ba.jsx)(Ba.Fragment,{children:(0,ms.formatHumanName)(o,e.options)}):null}var Pl=require("@mantine/core"),wa=require("@medplum/core");var xs=require("@mantine/core"),Ma=require("@medplum/core");function N(e){e.preventDefault(),e.stopPropagation()}function Aa(e){if(ps(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&ps(o[0]))return!0}return!1}function ps(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}var Is=require("react/jsx-runtime");function Se(e){let o=To(),{to:t,suffix:r,label:a,onClick:n,children:l,...s}=e,f=vc(t);return r&&(f+="/"+r),(0,Is.jsx)(xs.Anchor,{href:f,"aria-label":a,onClick:i=>{N(i),n?n(i):t&&o(f)},...s,children:l})}function vc(e){if(e){if(typeof e=="string")return Sc(e);if((0,Ma.isResource)(e))return Rc(e);if((0,Ma.isReference)(e))return bc(e)}return"#"}function Sc(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function Rc(e){return`/${e.resourceType}/${e.id}`}function bc(e){return`/${e.reference}`}var Fa=require("react/jsx-runtime");function Me(e){let o=K(e.value),t=o?(0,wa.getDisplayString)(o):e.alt??"",r=(o&&(0,wa.getImageSrc)(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?(0,Fa.jsx)(Se,{to:o,children:(0,Fa.jsx)(Pl.Avatar,{src:r,alt:t,radius:a,...n})}):(0,Fa.jsx)(Pl.Avatar,{src:r,alt:t,radius:a,...n})}var St=require("@mantine/core"),Mo=require("@medplum/core");var Ar=require("react");var Oa=require("@mantine/core"),gs=require("@mantine/notifications"),hs=require("@medplum/core"),fe=require("react");var Dl=require("react/jsx-runtime");function vt(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:s,...f}=e,i=Pc(o),u=(0,fe.useRef)(null),[d,c]=(0,fe.useState)(),[x,C]=(0,fe.useState)(),[g,D]=(0,fe.useState)(),[B,T]=(0,fe.useState)(),[M,Z]=(0,fe.useState)(i.map(r)),[b,L]=(0,fe.useState)([]),de=(0,fe.useRef)();de.current=d;let ye=(0,fe.useRef)();ye.current=x;let Do=(0,fe.useRef)();Do.current=g;let xt=(0,fe.useRef)();xt.current=B;let Ae=(0,fe.useRef)();Ae.current=b;let h=(0,fe.useCallback)(()=>{C(void 0);let ve=u.current?.value.trim()||"";if(ve===de.current)return;c(ve);let ge=new AbortController;D(ge),a(ve,ge.signal).then(Ye=>{ge.signal.aborted||(L(Ye.map(r)),D(void 0),xt.current&&(Ye.length>0&&n(Ye.slice(0,1)),T(!1)))}).catch(Ye=>{ge.signal.aborted||Ye.message.includes("aborted")||(0,gs.showNotification)({color:"red",message:(0,hs.normalizeErrorString)(Ye)})})},[a,n,r]),U=(0,fe.useCallback)(()=>{Do.current&&(Do.current.abort(),D(void 0)),ye.current!==void 0&&window.clearTimeout(ye.current);let ve=window.setTimeout(()=>h(),100);C(ve)},[h]),mo=(0,fe.useCallback)(ve=>{let ge=[],Ye=[];for(let Kf of ve){let Ia=Ae.current?.find(ac=>ac.value===Kf),vr=Ia?.resource;!vr&&s!==!1&&l&&(vr=l(Kf),Ia=r(vr)),vr&&ge.push(vr),Ia&&Ye.push(Ia)}n(ge),Z(Ye)},[s,n,l,r]),y=(0,fe.useCallback)(ve=>{ve.key==="Enter"&&(!ye.current&&!Do.current?(N(ve),Ae.current&&Ae.current.length>0&&(L(Ae.current.slice(0,1)),mo([Ae.current[0].value]))):T(!0))},[mo]),X=(0,fe.useCallback)(ve=>{let ge=r(l(ve));return L([...Ae.current,ge]),ge},[l,L,r]),ko=(0,fe.useCallback)((ve,ge)=>!ge,[]);return(0,fe.useEffect)(()=>()=>{Do.current&&Do.current.abort()},[]),(0,Dl.jsx)(Oa.MultiSelect,{...f,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:y,onSearchChange:U,data:[...M,...b],onFocus:h,onChange:mo,onCreate:X,rightSectionWidth:40,rightSection:g?(0,Dl.jsx)(Oa.Loader,{size:16}):null,filter:ko,creatable:!0,withinPortal:!0})}function Pc(e){return e?Array.isArray(e)?e:[e]:[]}var xo=require("react/jsx-runtime"),Dc=(0,St.createStyles)(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function kc(e){return e.id}function Tc(e){return{value:e.id,label:(0,Mo.getDisplayString)(e),resource:e}}function vs(e){let{classes:o}=Dc(),t=To(),r=P(),a=(0,Ar.useCallback)(async(l,s)=>{let f=Ac(l),i={signal:s},u=await r.graphql(f,void 0,void 0,i);return Mc(u,l)},[r]),n=(0,Ar.useCallback)(l=>{l.length>0&&t(`/${(0,Mo.getReferenceString)(l[0])}`)},[t]);return(0,xo.jsx)(vt,{size:"sm",radius:"md",className:o.searchInput,icon:(0,xo.jsx)(hl,{size:16}),placeholder:"Search",itemComponent:Bc,toKey:kc,toOption:Tc,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var Bc=(0,Ar.forwardRef)(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),(0,xo.jsx)("div",{ref:t,...o,children:(0,xo.jsxs)(St.Group,{noWrap:!0,children:[(0,xo.jsx)(Me,{value:e}),(0,xo.jsxs)("div",{children:[(0,xo.jsx)(St.Text,{children:(0,Mo.getDisplayString)(e)}),(0,xo.jsx)(St.Text,{size:"xs",color:"dimmed",children:r})]})]})})});function Ac(e){let o=JSON.stringify(e);return(0,Mo.isUUID)(e)?`{
1
+ "use strict";var Xc=Object.create;var Pa=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var $c=Object.getOwnPropertyNames;var _c=Object.getPrototypeOf,Kc=Object.prototype.hasOwnProperty;var Br=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports),Zc=(e,o)=>{for(var t in o)Pa(e,t,{get:o[t],enumerable:!0})},vs=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of $c(o))!Kc.call(e,a)&&a!==t&&Pa(e,a,{get:()=>o[a],enumerable:!(r=Jc(o,a))||r.enumerable});return e};var ys=(e,o,t)=>(t=e!=null?Xc(_c(e)):{},vs(o||!e||!e.__esModule?Pa(t,"default",{value:e,enumerable:!0}):t,e)),Yc=e=>vs(Pa({},"__esModule",{value:!0}),e);var gl=Br(vn=>{"use strict";Object.defineProperty(vn,"__esModule",{value:!0});vn.Pointer=void 0;function mm(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function pm(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var xm=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(mm);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(pm).join("/")},e.prototype.evaluate=function(o){for(var t=null,r="",a=o,n=1,f=this.tokens.length;n<f;n++)t=a,r=this.tokens[n],!(r=="__proto__"||r=="constructor"||r=="prototype")&&(a=(t||{})[r]);return{parent:t,key:r,value:a}},e.prototype.get=function(o){return this.evaluate(o).value},e.prototype.set=function(o,t){var r=this.evaluate(o);r.parent&&(r.parent[r.key]=t)},e.prototype.push=function(o){this.tokens.push(o)},e.prototype.add=function(o){var t=this.tokens.concat(String(o));return new e(t)},e}();vn.Pointer=xm});var vl=Br(Qo=>{"use strict";Object.defineProperty(Qo,"__esModule",{value:!0});Qo.clone=Qo.objectType=Qo.hasOwnProperty=void 0;Qo.hasOwnProperty=Object.prototype.hasOwnProperty;function Im(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Qo.objectType=Im;function gm(e){return e!=null&&typeof e=="object"}function hl(e){if(!gm(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=hl(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var f in e)Qo.hasOwnProperty.call(e,f)&&(n[f]=hl(e[f]));return n}Qo.clone=hl});var Sl=Br(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.diffAny=qe.diffObjects=qe.diffArrays=qe.intersection=qe.subtract=qe.isDestructive=void 0;var sa=vl();function hm(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}qe.isDestructive=hm;function Cl(e,o){var t={};for(var r in e)sa.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)sa.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}qe.subtract=Cl;function au(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)sa.hasOwnProperty.call(a,n)&&a[n]!==void 0&&(t[n]=(t[n]||0)+1)}for(var n in t)t[n]<o&&delete t[n];return Object.keys(t)}qe.intersection=au;function vm(e){return e.op==="add"}function ym(e){return e.op==="remove"}function yl(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function nu(e,o,t,r){r===void 0&&(r=yn);var a={"0,0":{operations:[],cost:0}};function n(u,d){var c="".concat(u,",").concat(d),m=a[c];if(m===void 0){if(u>0&&d>0&&!r(e[u-1],o[d-1],t.add(String(u-1))).length)m=n(u-1,d-1);else{var h=[];if(u>0){var g=n(u-1,d),y={op:"remove",index:u-1};h.push(yl(g,y))}if(d>0){var k=n(u,d-1),T={op:"add",index:u-1,value:o[d-1]};h.push(yl(k,T))}if(u>0&&d>0){var A=n(u-1,d-1),_={op:"replace",index:u-1,original:e[u-1],value:o[d-1]};h.push(yl(A,_))}var C=h.sort(function(E,se){return E.cost-se.cost})[0];m=C}a[c]=m}return m}var f=isNaN(e.length)||e.length<=0?0:e.length,s=isNaN(o.length)||o.length<=0?0:o.length,l=n(f,s).operations,i=l.reduce(function(u,d){var c=u[0],m=u[1];if(vm(d)){var h=d.index+1+m,g=h<f+m?String(h):"-",y={op:d.op,path:t.add(g).toString(),value:d.value};return[c.concat(y),m+1]}else if(ym(d)){var y={op:d.op,path:t.add(String(d.index+m)).toString()};return[c.concat(y),m-1]}else{var k=t.add(String(d.index+m)),T=r(d.original,d.value,k);return[c.concat.apply(c,T),m]}},[[],0])[0];return i}qe.diffArrays=nu;function fu(e,o,t,r){r===void 0&&(r=yn);var a=[];return Cl(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),Cl(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),au([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}qe.diffObjects=fu;function yn(e,o,t,r){if(r===void 0&&(r=yn),e===o)return[];var a=(0,sa.objectType)(e),n=(0,sa.objectType)(o);return a=="array"&&n=="array"?nu(e,o,t,r):a=="object"&&n=="object"?fu(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}qe.diffAny=yn});var Iu=Br(le=>{"use strict";var Rl=le&&le.__extends||function(){var e=function(o,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,a){r.__proto__=a}||function(r,a){for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(r[n]=a[n])},e(o,t)};return function(o,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(o,t);function r(){this.constructor=o}o.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}();Object.defineProperty(le,"__esModule",{value:!0});le.apply=le.InvalidOperationError=le.test=le.copy=le.move=le.replace=le.remove=le.add=le.TestError=le.MissingError=void 0;var zo=gl(),bl=vl(),Cm=Sl(),So=function(e){Rl(o,e);function o(t){var r=e.call(this,"Value required at path: ".concat(t))||this;return r.path=t,r.name="MissingError",r}return o}(Error);le.MissingError=So;var lu=function(e){Rl(o,e);function o(t,r){var a=e.call(this,"Test failed: ".concat(t," != ").concat(r))||this;return a.actual=t,a.expected=r,a.name="TestError",a}return o}(Error);le.TestError=lu;function Pl(e,o,t){if(Array.isArray(e))if(o=="-")e.push(t);else{var r=parseInt(o,10);e.splice(r,0,t)}else e[o]=t}function su(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function iu(e,o){var t=zo.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new So(o.path):(Pl(t.parent,t.key,(0,bl.clone)(o.value)),null)}le.add=iu;function uu(e,o){var t=zo.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new So(o.path):(su(t.parent,t.key),null)}le.remove=uu;function cu(e,o){var t=zo.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new So(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new So(o.path)}else if(t.value===void 0)return new So(o.path);return t.parent[t.key]=(0,bl.clone)(o.value),null}le.replace=cu;function du(e,o){var t=zo.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new So(o.from);var r=zo.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new So(o.path):(su(t.parent,t.key),Pl(r.parent,r.key,t.value),null)}le.move=du;function mu(e,o){var t=zo.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new So(o.from);var r=zo.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new So(o.path):(Pl(r.parent,r.key,(0,bl.clone)(t.value)),null)}le.copy=mu;function pu(e,o){var t=zo.Pointer.fromJSON(o.path).evaluate(e);return(0,Cm.diffAny)(t.value,o.value,new zo.Pointer).length?new lu(t.value,o.value):null}le.test=pu;var xu=function(e){Rl(o,e);function o(t){var r=e.call(this,"Invalid operation: ".concat(t.op))||this;return r.operation=t,r.name="InvalidOperationError",r}return o}(Error);le.InvalidOperationError=xu;function Sm(e,o){switch(o.op){case"add":return iu(e,o);case"remove":return uu(e,o);case"replace":return cu(e,o);case"move":return du(e,o);case"copy":return mu(e,o);case"test":return pu(e,o)}return new xu(o)}le.apply=Sm});var hu=Br(Ro=>{"use strict";Object.defineProperty(Ro,"__esModule",{value:!0});Ro.createTests=Ro.createPatch=Ro.applyPatch=Ro.Pointer=void 0;var Dl=gl();Object.defineProperty(Ro,"Pointer",{enumerable:!0,get:function(){return Dl.Pointer}});var Rm=Iu(),Tl=Sl();function bm(e,o){return o.map(function(t){return(0,Rm.apply)(e,t)})}Ro.applyPatch=bm;function Pm(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,Tl.diffAny)(t,r,a,o)}return o}function Dm(e,o,t){var r=new Dl.Pointer;return(t?Pm(t):Tl.diffAny)(e,o,r)}Ro.createPatch=Dm;function gu(e,o){var t=Dl.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function Tm(e,o){var t=new Array;return o.filter(Tl.isDestructive).forEach(function(r){var a=gu(e,r.path);if(a&&t.push(a),"from"in r){var n=gu(e,r.from);n&&t.push(n)}}),t}Ro.createTests=Tm});var Dx={};Zc(Dx,{AddressDisplay:()=>of,AddressInput:()=>tf,AnnotationInput:()=>rf,AppShell:()=>wd,AsyncAutocomplete:()=>Tt,AttachmentArrayDisplay:()=>zf,AttachmentArrayInput:()=>Xf,AttachmentButton:()=>Bt,AttachmentDisplay:()=>lo,AttachmentInput:()=>Gr,BackboneElementDisplay:()=>rr,BackboneElementInput:()=>ur,CalendarInput:()=>ml,CheckboxFormSection:()=>Wr,CodeInput:()=>qr,CodeableConceptDisplay:()=>At,CodeableConceptInput:()=>ol,CodingDisplay:()=>Kf,CodingInput:()=>$r,ContactDetailDisplay:()=>Zf,ContactDetailInput:()=>tl,ContactPointDisplay:()=>Ur,ContactPointInput:()=>_r,Container:()=>Go,DateTimeInput:()=>to,DefaultResourceTimeline:()=>Hm,DescriptionList:()=>$f,DescriptionListEntry:()=>_f,DiagnosticReportDisplay:()=>hn,Document:()=>ia,ElementDefinitionInputSelector:()=>zi,ElementDefinitionTypeInput:()=>dl,EncounterTimeline:()=>Vm,ErrorBoundary:()=>Dt,FhirPathTable:()=>Uu,Form:()=>oe,FormSection:()=>Ve,Header:()=>Vf,HumanNameDisplay:()=>Nr,HumanNameInput:()=>fl,IdentifierDisplay:()=>Yf,IdentifierInput:()=>ll,Loading:()=>La,Logo:()=>jo,MeasureReportDisplay:()=>mp,MedplumLink:()=>be,MedplumProvider:()=>jc,MemoizedFhirPathTable:()=>ip,MemoizedSearchControl:()=>rp,MoneyDisplay:()=>jf,MoneyInput:()=>sl,Navbar:()=>Qf,ObservationTable:()=>ou,OperationOutcomeAlert:()=>Ut,Panel:()=>Ht,PatientTimeline:()=>pp,PlanDefinitionBuilder:()=>xp,QuantityDisplay:()=>No,QuantityInput:()=>Ue,QuestionnaireBuilder:()=>Ep,QuestionnaireForm:()=>cs,QuestionnaireItemType:()=>pa,RangeDisplay:()=>Qr,RangeInput:()=>sr,ReferenceDisplay:()=>at,ReferenceInput:()=>Lt,ReferenceRangeEditor:()=>_p,ReferenceRangeGroupEditor:()=>vc,RegisterForm:()=>Sx,RequestGroupDisplay:()=>tx,ResourceArrayDisplay:()=>el,ResourceArrayInput:()=>ul,ResourceAvatar:()=>Fe,ResourceBadge:()=>Uo,ResourceBlame:()=>ix,ResourceDiff:()=>cx,ResourceForm:()=>mx,ResourceHistoryTable:()=>px,ResourceInput:()=>aa,ResourceName:()=>so,ResourcePropertyDisplay:()=>De,ResourcePropertyInput:()=>Co,ResourceTable:()=>Rn,ResourceTimeline:()=>Jo,Scheduler:()=>hx,SearchChangeEvent:()=>Mn,SearchClickEvent:()=>It,SearchControl:()=>qu,SearchFieldEditor:()=>Jl,SearchFilterEditor:()=>$l,SearchLoadEvent:()=>Fn,ServiceRequestTimeline:()=>Cx,SignInForm:()=>Px,StatusBadge:()=>la,Timeline:()=>kl,TimelineItem:()=>Wo,TimingInput:()=>cl,addDateFilterBetween:()=>Pn,addField:()=>Qm,addFilter:()=>qt,addLastMonthFilter:()=>Nl,addMissingFilter:()=>Dn,addNextMonthFilter:()=>Vl,addThisMonthFilter:()=>Hl,addTodayFilter:()=>Ol,addTomorrowFilter:()=>El,addYearToDateFilter:()=>Gl,addYesterdayFilter:()=>wl,buildFieldNameString:()=>We,buildInitialResponse:()=>rs,buildInitialResponseItem:()=>Ln,clearFilters:()=>Um,clearFiltersOnField:()=>ca,convertIsoToLocal:()=>al,convertLocalToIso:()=>nl,createScriptTag:()=>Sa,deleteFilter:()=>Fl,formatReferenceString:()=>as,getErrorsForInput:()=>Te,getFieldDefinitions:()=>_l,getIssuesForExpression:()=>Xr,getNewMultiSelectValues:()=>os,getNumberOfPages:()=>ns,getOpString:()=>gr,getQuestionnaireItemReferenceFilter:()=>ts,getQuestionnaireItemReferenceTargetTypes:()=>xa,getRecaptcha:()=>ps,getSearchOperators:()=>Wl,getSortField:()=>Ql,initRecaptcha:()=>ms,isChoiceQuestion:()=>jl,isQuestionEnabled:()=>es,isSortDescending:()=>zl,parseForm:()=>qf,reactContext:()=>Zn,renderValue:()=>Xl,setFilters:()=>Ir,setOffset:()=>Eu,setPage:()=>Ul,setQuestionnaireItemReferenceTargetTypes:()=>Ia,setSort:()=>Tn,sortByDateAndPriority:()=>Bl,toggleSort:()=>zm,useMedplum:()=>D,useMedplumContext:()=>Jt,useMedplumNavigate:()=>Fo,useMedplumProfile:()=>Ar,useResource:()=>K,useSearch:()=>od,useSearchOne:()=>Yn,useSearchResources:()=>jn});module.exports=Yc(Dx);var Rt=require("react"),Da=require("react"),Ss=require("react/jsx-runtime"),wo=require("@medplum/core"),bt=require("react"),Ta=require("@medplum/core"),St=require("react"),Zn=(0,Da.createContext)(void 0);function Jt(){return(0,Da.useContext)(Zn)}function D(){return Jt().medplum}function Fo(){return Jt().navigate}function Ar(){return Jt().profile}function jc(e){let o=e.medplum,t=e.navigate??ed,[r,a]=(0,Rt.useState)({profile:o.getProfile(),loading:!o.isInitialized});(0,Rt.useEffect)(()=>{o&&(o.isInitialized||(a(f=>({...f,loading:!0})),o.getInitPromise().then(()=>a(f=>({...f,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),(0,Rt.useEffect)(()=>{function f(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",f),()=>o.removeEventListener("change",f)},[o,r]);let n=(0,Rt.useMemo)(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return(0,Ss.jsx)(Zn.Provider,{value:n,children:e.children})}function ed(e){window.location.assign(e)}function K(e,o){let t=D(),[r,a]=(0,bt.useState)(Cs(t,e)),n=(0,bt.useCallback)(f=>{(0,wo.deepEquals)(f,r)||a(f)},[r,a]);return(0,bt.useEffect)(()=>{n(Cs(t,e))},[t,e,n]),(0,bt.useEffect)(()=>{let f=!0;return(0,wo.isReference)(e)&&t.readReference(e).then(s=>{f&&n(s)}).catch(s=>{f&&(n(void 0),o&&o((0,wo.normalizeOperationOutcome)(s)))}),()=>f=!1},[t,r,e,n,o]),r}function Cs(e,o){if(o){if((0,wo.isResource)(o))return o;if((0,wo.isReference)(o))return e.getCachedReference(o)}}function od(e,o){return ef("search",e,o)}function Yn(e,o){return ef("searchOne",e,o)}function jn(e,o){return ef("searchResources",e,o)}function ef(e,o,t){let r=D(),[a,n]=(0,St.useState)(),[f,s]=(0,St.useState)(!1),[l,i]=(0,St.useState)(),[u,d]=(0,St.useState)();return(0,St.useEffect)(()=>{let c=r.fhirSearchUrl(o,t).toString();c!==a&&(n(c),r[e](o,t).then(m=>{s(!1),i(m),d(Ta.allOk)}).catch(m=>{s(!1),i(void 0),d((0,Ta.normalizeOperationOutcome)(m))}))},[r,e,o,t,a,i]),[l,f,u]}var Rs=require("@medplum/core"),ka=require("react/jsx-runtime");function of(e){let o=e.value;return o?(0,ka.jsx)(ka.Fragment,{children:(0,Rs.formatAddress)(o)}):null}var fo=require("@mantine/core"),Ba=require("react"),Io=require("react/jsx-runtime");function bs(e,o){return e.line&&e.line.length>o?e.line[o]:""}function Ps(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function tf(e){let[o,t]=(0,Ba.useState)(e.defaultValue||{}),r=(0,Ba.useRef)();r.current=o;function a(c){t(c),e.onChange&&e.onChange(c)}function n(c){a({...r.current,use:c})}function f(c){a({...r.current,type:c})}function s(c){a(Ps(r.current||{},0,c))}function l(c){a(Ps(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(0,Io.jsxs)(fo.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Io.jsx)(fo.NativeSelect,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),(0,Io.jsx)(fo.NativeSelect,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>f(c.currentTarget.value),data:["","postal","physical","both"]}),(0,Io.jsx)(fo.TextInput,{placeholder:"Line 1",defaultValue:bs(o,0),onChange:c=>s(c.currentTarget.value)}),(0,Io.jsx)(fo.TextInput,{placeholder:"Line 2",defaultValue:bs(o,1),onChange:c=>l(c.currentTarget.value)}),(0,Io.jsx)(fo.TextInput,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),(0,Io.jsx)(fo.TextInput,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),(0,Io.jsx)(fo.TextInput,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:c=>d(c.currentTarget.value)})]})}var Ds=require("@mantine/core"),Ts=require("@medplum/core");var Aa=require("react"),ks=require("react/jsx-runtime");function rf(e){let o=Ar(),[t,r]=(0,Aa.useState)(e.defaultValue||{}),a=(0,Aa.useRef)();a.current=t;function n(f){let s=f?{text:f,authorReference:o&&(0,Ts.createReference)(o),time:new Date().toISOString()}:{};r(s),e.onChange&&e.onChange(s)}return(0,ks.jsx)(Ds.TextInput,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:f=>n(f.currentTarget.value)})}var Xa=require("@mantine/core"),oi=require("@mantine/notifications");var er=require("react");var Os=require("@mantine/core"),Es=require("@medplum/core");var Mr=require("react"),et=ys(require("prop-types"));var Bs={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 td=Object.defineProperty,rd=Object.defineProperties,ad=Object.getOwnPropertyDescriptors,Ma=Object.getOwnPropertySymbols,Fs=Object.prototype.hasOwnProperty,ws=Object.prototype.propertyIsEnumerable,As=(e,o,t)=>o in e?td(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Ms=(e,o)=>{for(var t in o||(o={}))Fs.call(o,t)&&As(e,t,o[t]);if(Ma)for(var t of Ma(o))ws.call(o,t)&&As(e,t,o[t]);return e},nd=(e,o)=>rd(e,ad(o)),fd=(e,o)=>{var t={};for(var r in e)Fs.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ma)for(var r of Ma(e))o.indexOf(r)<0&&ws.call(e,r)&&(t[r]=e[r]);return t},x=(e,o,t)=>{let r=(0,Mr.forwardRef)((a,n)=>{var f=a,{color:s="currentColor",size:l=24,stroke:i=2,children:u}=f,d=fd(f,["color","size","stroke","children"]);return(0,Mr.createElement)("svg",Ms(nd(Ms({ref:n},Bs),{width:l,height:l,stroke:s,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),d),[...t.map(([c,m])=>(0,Mr.createElement)(c,m)),...u||[]])});return r.propTypes={color:et.default.string,size:et.default.oneOfType([et.default.string,et.default.number]),stroke:et.default.oneOfType([et.default.string,et.default.number])},r.displayName=`${o}`,r};var af=x("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 Pt=x("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 nf=x("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 ff=x("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 lf=x("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 sf=x("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 uf=x("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 cf=x("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 df=x("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 mf=x("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 Oo=x("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 Fr=x("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var pf=x("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 xf=x("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var ot=x("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 $t=x("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 wr=x("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 If=x("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 gf=x("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 hf=x("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 vf=x("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 yf=x("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 _t=x("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 Kt=x("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Fa=x("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 Cf=x("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 Sf=x("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 Rf=x("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 bf=x("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 wa=x("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Oa=x("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var Pf=x("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 Df=x("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 Tf=x("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 kf=x("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var Bf=x("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 Af=x("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 Zt=x("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 Or=x("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 Er=x("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 Mf=x("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 Ff=x("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 wf=x("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 Lr=x("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 Of=x("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);var Ls=require("react"),Ef=require("react/jsx-runtime"),Dt=class extends Ls.Component{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?(0,Ef.jsx)(Os.Alert,{icon:(0,Ef.jsx)(Pt,{size:16}),title:"Something went wrong",color:"red",children:(0,Es.normalizeErrorString)(this.state.error)}):this.props.children}};var Ea=require("@mantine/core"),Lf=require("react/jsx-runtime");function La(){return(0,Lf.jsx)(Ea.Center,{style:{width:"100%",height:"100vh"},children:(0,Lf.jsx)(Ea.Loader,{})})}var W=require("@mantine/core"),Vr=require("@medplum/core");var Xs=require("react");var Ns=require("@medplum/core"),Na=require("react/jsx-runtime");function Nr(e){let o=e.value;return o?(0,Na.jsx)(Na.Fragment,{children:(0,Ns.formatHumanName)(o,e.options)}):null}var Nf=require("@mantine/core"),Ga=require("@medplum/core");var Vs=require("@mantine/core"),Va=require("@medplum/core");function N(e){e.preventDefault(),e.stopPropagation()}function Ha(e){if(Hs(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&Hs(o[0]))return!0}return!1}function Hs(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}var qs=require("react/jsx-runtime");function be(e){let o=Fo(),{to:t,suffix:r,label:a,onClick:n,children:f,...s}=e,l=ld(t);return r&&(l+="/"+r),(0,qs.jsx)(Vs.Anchor,{href:l,"aria-label":a,onClick:i=>{N(i),n?n(i):t&&o(l)},...s,children:f})}function ld(e){if(e){if(typeof e=="string")return sd(e);if((0,Va.isResource)(e))return id(e);if((0,Va.isReference)(e))return ud(e)}return"#"}function sd(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function id(e){return`/${e.resourceType}/${e.id}`}function ud(e){return`/${e.reference}`}var qa=require("react/jsx-runtime");function Fe(e){let o=K(e.value),t=o?(0,Ga.getDisplayString)(o):e.alt??"",r=(o&&(0,Ga.getImageSrc)(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?(0,qa.jsx)(be,{to:o,children:(0,qa.jsx)(Nf.Avatar,{src:r,alt:t,radius:a,...n})}):(0,qa.jsx)(Nf.Avatar,{src:r,alt:t,radius:a,...n})}var kt=require("@mantine/core"),Eo=require("@medplum/core");var Hr=require("react");var Ua=require("@mantine/core"),Gs=require("@mantine/notifications"),Us=require("@medplum/core"),ie=require("react");var Hf=require("react/jsx-runtime");function Tt(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:f,creatable:s,...l}=e,i=cd(o),u=(0,ie.useRef)(null),[d,c]=(0,ie.useState)(),[m,h]=(0,ie.useState)(),[g,y]=(0,ie.useState)(),[k,T]=(0,ie.useState)(),[A,_]=(0,ie.useState)(i.map(r)),[C,E]=(0,ie.useState)([]),se=(0,ie.useRef)();se.current=d;let Se=(0,ie.useRef)();Se.current=m;let Ao=(0,ie.useRef)();Ao.current=g;let Ct=(0,ie.useRef)();Ct.current=k;let Me=(0,ie.useRef)();Me.current=C;let v=(0,ie.useCallback)(()=>{h(void 0);let Re=u.current?.value.trim()||"";if(Re===se.current)return;c(Re);let ve=new AbortController;y(ve),a(Re,ve.signal).then(eo=>{ve.signal.aborted||(E(eo.map(r)),y(void 0),Ct.current&&(eo.length>0&&n(eo.slice(0,1)),T(!1)))}).catch(eo=>{ve.signal.aborted||eo.message.includes("aborted")||(0,Gs.showNotification)({color:"red",message:(0,Us.normalizeErrorString)(eo)})})},[a,n,r]),U=(0,ie.useCallback)(()=>{Ao.current&&(Ao.current.abort(),y(void 0)),Se.current!==void 0&&window.clearTimeout(Se.current);let Re=window.setTimeout(()=>v(),100);h(Re)},[v]),xo=(0,ie.useCallback)(Re=>{let ve=[],eo=[];for(let hs of Re){let ba=Me.current?.find(Wc=>Wc.value===hs),kr=ba?.resource;!kr&&s!==!1&&f&&(kr=f(hs),ba=r(kr)),kr&&ve.push(kr),ba&&eo.push(ba)}n(ve),_(eo)},[s,n,f,r]),S=(0,ie.useCallback)(Re=>{Re.key==="Enter"&&(!Se.current&&!Ao.current?(N(Re),Me.current&&Me.current.length>0&&(E(Me.current.slice(0,1)),xo([Me.current[0].value]))):T(!0))},[xo]),X=(0,ie.useCallback)(Re=>{let ve=r(f(Re));return E([...Me.current,ve]),ve},[f,E,r]),Mo=(0,ie.useCallback)((Re,ve)=>!ve,[]);return(0,ie.useEffect)(()=>()=>{Ao.current&&Ao.current.abort()},[]),(0,Hf.jsx)(Ua.MultiSelect,{...l,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:S,onSearchChange:U,data:[...A,...C],onFocus:v,onChange:xo,onCreate:X,rightSectionWidth:40,rightSection:g?(0,Hf.jsx)(Ua.Loader,{size:16}):null,filter:Mo,creatable:!0,withinPortal:!0})}function cd(e){return e?Array.isArray(e)?e:[e]:[]}var go=require("react/jsx-runtime"),dd=(0,kt.createStyles)(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function md(e){return e.id}function pd(e){return{value:e.id,label:(0,Eo.getDisplayString)(e),resource:e}}function Ws(e){let{classes:o}=dd(),t=Fo(),r=D(),a=(0,Hr.useCallback)(async(f,s)=>{let l=Id(f),i={signal:s},u=await r.graphql(l,void 0,void 0,i);return gd(u,f)},[r]),n=(0,Hr.useCallback)(f=>{f.length>0&&t(`/${(0,Eo.getReferenceString)(f[0])}`)},[t]);return(0,go.jsx)(Tt,{size:"sm",radius:"md",className:o.searchInput,icon:(0,go.jsx)(Af,{size:16}),placeholder:"Search",itemComponent:xd,toKey:md,toOption:pd,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var xd=(0,Hr.forwardRef)(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),(0,go.jsx)("div",{ref:t,...o,children:(0,go.jsxs)(kt.Group,{noWrap:!0,children:[(0,go.jsx)(Fe,{value:e}),(0,go.jsxs)("div",{children:[(0,go.jsx)(kt.Text,{children:(0,Eo.getDisplayString)(e)}),(0,go.jsx)(kt.Text,{size:"xs",color:"dimmed",children:r})]})]})})});function Id(e){let o=JSON.stringify(e);return(0,Eo.isUUID)(e)?`{
2
2
  Patients1: PatientList(_id: ${o}, _count: 1) {
3
3
  resourceType
4
4
  id
@@ -61,8 +61,8 @@
61
61
  display
62
62
  }
63
63
  }
64
- }`.replace(/\s+/g," ")}function Mc(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),wc(Fc(t),o).slice(0,5)}function Fc(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 wc(e,o){return e.sort((t,r)=>Cs(r,o)-Cs(t,o))}function Cs(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,ys(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,ys((0,Mo.formatHumanName)(r),o));return t}function ys(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}var Q=require("react/jsx-runtime"),Oc=(0,W.createStyles)(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 kl(e){let o=Gt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:s}=Oc(),[f,i]=(0,Ss.useState)(!1);return(0,Q.jsx)(W.Header,{height:60,p:8,style:{zIndex:101},children:(0,Q.jsxs)(W.Group,{position:"apart",children:[(0,Q.jsxs)(W.Group,{spacing:"xs",children:[(0,Q.jsx)(W.UnstyledButton,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&(0,Q.jsx)(vs,{pathname:e.pathname,searchParams:e.searchParams})]}),(0,Q.jsxs)(W.Menu,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:f,onClose:()=>i(!1),children:[(0,Q.jsx)(W.Menu.Target,{children:(0,Q.jsx)(W.UnstyledButton,{className:s(l.user,{[l.userActive]:f}),onClick:()=>i(u=>!u),children:(0,Q.jsxs)(W.Group,{spacing:7,children:[(0,Q.jsx)(Me,{value:r,radius:"xl",size:24}),(0,Q.jsx)(W.Text,{size:"sm",className:l.userName,children:(0,Mr.formatHumanName)(r?.name?.[0])}),(0,Q.jsx)(rl,{size:12,stroke:1.5})]})})}),(0,Q.jsxs)(W.Menu.Dropdown,{children:[(0,Q.jsxs)(W.Stack,{align:"center",p:"xl",children:[(0,Q.jsx)(Me,{size:"xl",radius:100,value:o.profile}),(0,Q.jsx)(Br,{value:o.profile?.name?.[0]}),(0,Q.jsx)(W.Text,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&(0,Q.jsx)(W.Menu.Divider,{}),n.map(u=>u.profile.reference!==(0,Mr.getReferenceString)(o.profile)&&(0,Q.jsx)(W.Menu.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:(0,Q.jsxs)(W.Group,{children:[(0,Q.jsx)(W.Avatar,{radius:"xl"}),(0,Q.jsxs)("div",{style:{flex:1},children:[(0,Q.jsx)(W.Text,{size:"sm",weight:500,children:u.profile.display}),(0,Q.jsx)(W.Text,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),(0,Q.jsx)(W.Menu.Divider,{}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(yl,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(Wt,{size:14,stroke:1.5}),onClick:()=>a(`/${(0,Mr.getReferenceString)(r)}`),children:"Account settings"}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(dl,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),(0,Q.jsx)(W.Text,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}var Ne=require("@mantine/core");var Na=require("react");var je=require("@mantine/core"),Bl=require("@mantine/notifications"),Ea=require("@medplum/core");function Tl(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Ec(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Lc(o,t);return o}function Ec(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Lc(e,o){e[o.name]=o.value}var Rs=require("react/jsx-runtime");function oe(e){return(0,Rs.jsx)("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=Tl(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}var Io=require("react/jsx-runtime");function bs(e){let o=P(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,s=`${e.pathname}?${e.searchParams.toString()}`,f=(0,Ea.deepClone)(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"}),(0,Bl.showNotification)({color:"green",message:"Success"}),e.onOk()}).catch(u=>{(0,Bl.showNotification)({color:"red",message:(0,Ea.normalizeErrorString)(u)})})}return(0,Io.jsx)(je.Modal,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:(0,Io.jsx)(oe,{onSubmit:r,children:(0,Io.jsxs)(je.Stack,{children:[(0,Io.jsx)(Nc,{config:t}),(0,Io.jsx)(je.TextInput,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),(0,Io.jsx)(je.Group,{position:"right",children:(0,Io.jsx)(je.Button,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Nc(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return(0,Io.jsx)(je.NativeSelect,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}var La=require("react");var ks=require("react");var Ps=require("react");var Ds=require("react/jsx-runtime");function Al(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Hc(e){return typeof e.display=="string"?e.display:Al(e)}function Vc(e){return{value:Al(e),label:Hc(e),resource:e}}function qc(e){return{code:e,display:e}}function Xt(e){let o=P(),{binding:t,creatable:r,clearable:a,...n}=e,l=(0,Ps.useCallback)(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(0,Ds.jsx)(vt,{...n,creatable:r??!0,clearable:a??!0,toKey:Al,toOption:Vc,loadOptions:l,onCreate:qc,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}var Ts=require("react/jsx-runtime");function Fr(e){let[o,t]=(0,ks.useState)(e.defaultValue);function r(a){let n=a[0],l=Uc(n);t(l),e.onChange&&e.onChange(l)}return(0,Ts.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Gc(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Gc(e){return e?{code:e}:void 0}function Uc(e){return e?.code}var Bs=require("react/jsx-runtime");function Jt(e){let[o,t]=(0,La.useState)(e.defaultValue),r=e.onChange,a=(0,La.useCallback)(n=>{t(n),r&&r(n)},[r]);return(0,Bs.jsx)(Fr,{"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})}var pe=require("react/jsx-runtime"),As=(0,Ne.createStyles)(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 Ml(e){let{classes:o}=As(),t=To(),r=Wc(e.pathname,e.searchParams,e.menus),[a,n]=(0,Na.useState)(!1);function l(f,i){f.stopPropagation(),f.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function s(f){f&&t(`/${f}`)}return(0,pe.jsxs)(pe.Fragment,{children:[(0,pe.jsx)(Ne.Navbar,{width:{sm:250},p:"xs",children:(0,pe.jsxs)(Ne.ScrollArea,{children:[!e.resourceTypeSearchDisabled&&(0,pe.jsx)(Ne.Navbar.Section,{mb:"sm",children:(0,pe.jsx)(Jt,{name:"resourceType",placeholder:"Resource Type",onChange:f=>s(f)},window.location.pathname)}),(0,pe.jsxs)(Ne.Navbar.Section,{grow:!0,children:[e.menus?.map(f=>(0,pe.jsxs)(Na.Fragment,{children:[(0,pe.jsx)(Ne.Text,{className:o.menuTitle,children:f.title}),f.links?.map(i=>(0,pe.jsxs)(Qc,{to:i.href,active:i.href===r?.href,onClick:u=>l(u,i.href),children:[(0,pe.jsx)(zc,{to:i.href,icon:i.icon}),(0,pe.jsx)("span",{children:i.label})]},i.href))]},`menu-${f.title}`)),e.displayAddBookmark&&(0,pe.jsx)(Ne.Button,{variant:"subtle",size:"xs",mt:"xl",leftIcon:(0,pe.jsx)(Il,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&(0,pe.jsx)(bs,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function Qc(e){let{classes:o,cx:t}=As();return(0,pe.jsx)(Se,{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:(0,pe.jsx)(Ne.Space,{w:30})}function Wc(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=Xc(e,o,l.href);s>a&&(a=s,r=l)}return r}function Xc(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}var _o=require("react/jsx-runtime");function Jc(e){let o=(0,Ha.useMantineTheme)(),[t,r]=(0,$t.useState)(localStorage.navbarOpen==="true"),a=P(),n=Sr();(0,$t.useEffect)(()=>{function i(){(0,Ms.showNotification)({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()?(0,_o.jsx)(Ta,{}):(0,_o.jsx)(Ha.AppShell,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&(0,_o.jsx)(kl,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:f}),navbar:n&&t?(0,_o.jsx)(Ml,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:s,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:(0,_o.jsx)(yt,{children:(0,_o.jsx)($t.Suspense,{fallback:(0,_o.jsx)(Ta,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}var Fs=require("@mantine/core"),go=require("react/jsx-runtime");function no(e){let{contentType:o,url:t,title:r}=e.value??{};return t?(0,go.jsxs)("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&(0,go.jsx)("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&(0,go.jsx)("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:(0,go.jsx)("source",{type:o,src:t})}),o==="application/pdf"&&(0,go.jsx)("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:(0,go.jsx)("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),(0,go.jsx)("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:(0,go.jsx)(Fs.Anchor,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:$c(r),children:r||"Download"})})]}):null}function $c(e){return e?.includes(".")?e:void 0}var Va=require("react/jsx-runtime");function Fl(e){return(0,Va.jsx)("div",{children:e.values?.map((o,t)=>(0,Va.jsx)("div",{children:(0,Va.jsx)(no,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}var wl=require("@mantine/core");var qa=require("react");var ws=require("react");var Os=require("@medplum/core"),Kt=require("react/jsx-runtime");function Rt(e){let o=P(),t=(0,ws.useRef)(null);function r(l){N(l),t.current?.click()}function a(l){N(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((0,Os.normalizeOperationOutcome)(u))})}return(0,Kt.jsxs)(Kt.Fragment,{children:[(0,Kt.jsx)("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}var he=require("react/jsx-runtime");function Ol(e){let[o,t]=(0,qa.useState)(e.defaultValue??[]),r=(0,qa.useRef)();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return(0,he.jsxs)("table",{style:{width:"100%"},children:[(0,he.jsxs)("colgroup",{children:[(0,he.jsx)("col",{width:"97%"}),(0,he.jsx)("col",{width:"3%"})]}),(0,he.jsxs)("tbody",{children:[o.map((n,l)=>(0,he.jsxs)("tr",{children:[(0,he.jsx)("td",{children:(0,he.jsx)(no,{value:n,maxWidth:200})}),(0,he.jsx)("td",{children:(0,he.jsx)(wl.ActionIcon,{title:"Remove",size:"sm",onClick:s=>{N(s);let f=o.slice();f.splice(l,1),a(f)},children:(0,he.jsx)(Ko,{})})})]},`${l}-${o.length}`)),(0,he.jsxs)("tr",{children:[(0,he.jsx)("td",{}),(0,he.jsx)("td",{children:(0,he.jsx)(Rt,{onUpload:n=>{a([...r.current,n])},children:n=>(0,he.jsx)(wl.ActionIcon,{...n,title:"Add",size:"sm",color:"green",children:(0,he.jsx)(Pr,{size:16})})})})]})]})]})}var El=require("@mantine/core"),Es=require("react");var Fo=require("react/jsx-runtime");function wr(e){let[o,t]=(0,Es.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?(0,Fo.jsxs)(Fo.Fragment,{children:[(0,Fo.jsx)(no,{value:o,maxWidth:200}),(0,Fo.jsx)(El.Button,{onClick:a=>{N(a),r(void 0)},children:"Remove"})]}):(0,Fo.jsx)(Rt,{onUpload:r,children:a=>(0,Fo.jsx)(El.Button,{...a,children:"Upload..."})})}var Ka=require("@medplum/core");var Ga=["meta","implicitRules","contained","extension","modifierExtension"],Ua=["language","text"];var Ls=require("@mantine/core"),Zo=require("react/jsx-runtime"),Kc=(0,Ls.createStyles)(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 Ll(e){let{children:o,compact:t}=e,{classes:r,cx:a}=Kc();return(0,Zo.jsx)("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function Nl(e){return(0,Zo.jsxs)(Zo.Fragment,{children:[(0,Zo.jsx)("dt",{children:e.term}),(0,Zo.jsx)("dd",{children:e.children})]})}var et=require("@mantine/core"),F=require("@medplum/core");var Ns=require("@medplum/core"),Qa=require("react/jsx-runtime");function bt(e){return(0,Qa.jsx)(Qa.Fragment,{children:(0,Ns.formatCodeableConcept)(e.value)})}var Hs=require("@medplum/core"),za=require("react/jsx-runtime");function Hl(e){return(0,za.jsx)(za.Fragment,{children:(0,Hs.formatCoding)(e.value)})}var Wa=require("react/jsx-runtime");function Or(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("]")),(0,Wa.jsx)(Wa.Fragment,{children:t.join("").trim()})}var _t=require("react/jsx-runtime");function Vl(e){let o=e.value;return o?(0,_t.jsxs)(_t.Fragment,{children:[o.name,o.name&&": ",o.telecom?.map(t=>(0,_t.jsx)(Or,{value:t},`telecom-${o.name}-${t.value}`))]}):null}var Vs=require("react/jsx-runtime");function ql(e){return(0,Vs.jsxs)("div",{children:[e.value?.system,": ",e.value?.value]})}var qs=require("@medplum/core"),Xa=require("react/jsx-runtime");function Gl(e){return(0,Xa.jsx)(Xa.Fragment,{children:(0,qs.formatMoney)(e.value)})}var Gs=require("@medplum/core"),Ja=require("react/jsx-runtime");function wo(e){return(0,Ja.jsx)(Ja.Fragment,{children:(0,Gs.formatQuantity)(e.value)})}var Us=require("@medplum/core"),$a=require("react/jsx-runtime");function Er(e){return(0,$a.jsx)($a.Fragment,{children:(0,Us.formatRange)(e.value)})}var Pt=require("react/jsx-runtime");function Qs(e){let o=e.value;return o?(0,Pt.jsxs)(Pt.Fragment,{children:[(0,Pt.jsx)(wo,{value:o.numerator}),"\xA0/\xA0",(0,Pt.jsx)(wo,{value:o.denominator})]}):null}var zs=require("@medplum/core");var Lr=require("react/jsx-runtime");function Yo(e){if(!e.value)return null;let o=e.value.display||e.value.reference||(0,zs.stringify)(e.value);return e.link!==!1&&e.value.reference?(0,Lr.jsx)(Se,{to:e.value,children:o}):(0,Lr.jsx)(Lr.Fragment,{children:o})}var jo=require("react/jsx-runtime");function Ul(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?(0,jo.jsx)(jo.Fragment,{children:t.map((a,n)=>(0,jo.jsx)("div",{children:(0,jo.jsx)(Pe,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):(0,jo.jsx)(jo.Fragment,{})}var w=require("react/jsx-runtime");function Pe(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return(0,w.jsxs)(et.Box,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!(0,F.isEmpty)(r)&&(0,w.jsx)(et.CopyButton,{value:r,timeout:2e3,children:({copied:n,copy:l})=>(0,w.jsx)(et.Tooltip,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:(0,w.jsx)(et.ActionIcon,{color:n?"teal":"gray",onClick:l,children:n?(0,w.jsx)(br,{size:"1rem"}):(0,w.jsx)(nl,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===F.PropertyType.Attachment?(0,w.jsx)(Fl,{values:r,maxWidth:e.maxWidth}):(0,w.jsx)(Ul,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case F.PropertyType.boolean:return(0,w.jsx)(w.Fragment,{children:r===void 0?"":(!!r).toString()});case F.PropertyType.SystemString:case F.PropertyType.string:return(0,w.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:r});case F.PropertyType.code:case F.PropertyType.date:case F.PropertyType.decimal:case F.PropertyType.id:case F.PropertyType.integer:case F.PropertyType.positiveInt:case F.PropertyType.unsignedInt:case F.PropertyType.uri:case F.PropertyType.url:return(0,w.jsx)(w.Fragment,{children:r});case F.PropertyType.canonical:return(0,w.jsx)(Yo,{value:{reference:r},link:e.link});case F.PropertyType.dateTime:case F.PropertyType.instant:return(0,w.jsx)(w.Fragment,{children:(0,F.formatDateTime)(r)});case F.PropertyType.markdown:return(0,w.jsx)("pre",{children:r});case F.PropertyType.Address:return(0,w.jsx)(zn,{value:r});case F.PropertyType.Annotation:return(0,w.jsx)(w.Fragment,{children:r?.text});case F.PropertyType.Attachment:return(0,w.jsx)(no,{value:r,maxWidth:e.maxWidth});case F.PropertyType.CodeableConcept:return(0,w.jsx)(bt,{value:r});case F.PropertyType.Coding:return(0,w.jsx)(Hl,{value:r});case F.PropertyType.ContactDetail:return(0,w.jsx)(Vl,{value:r});case F.PropertyType.ContactPoint:return(0,w.jsx)(Or,{value:r});case F.PropertyType.HumanName:return(0,w.jsx)(Br,{value:r});case F.PropertyType.Identifier:return(0,w.jsx)(ql,{value:r});case F.PropertyType.Money:return(0,w.jsx)(Gl,{value:r});case F.PropertyType.Period:return(0,w.jsx)(w.Fragment,{children:(0,F.formatPeriod)(r)});case F.PropertyType.Quantity:case F.PropertyType.Duration:return(0,w.jsx)(wo,{value:r});case F.PropertyType.Range:return(0,w.jsx)(Er,{value:r});case F.PropertyType.Ratio:return(0,w.jsx)(Qs,{value:r});case F.PropertyType.Reference:return(0,w.jsx)(Yo,{value:r,link:e.link});case F.PropertyType.Timing:return(0,w.jsx)(w.Fragment,{children:(0,F.formatTiming)(r)});case F.PropertyType.Dosage:case F.PropertyType.UsageContext:return(0,w.jsx)(Zt,{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(0,w.jsx)(Zt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}var Ws=require("@medplum/core");function ho(e,o){let t=(0,Ws.getTypedPropertyValue)(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}var Dt=require("react/jsx-runtime");function Zt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=(0,Ka.tryGetDataType)(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?(0,Dt.jsx)("div",{children:t.name}):(0,Dt.jsx)(Ll,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,s]=n;if(Ga.includes(l)||Ua.includes(l)&&s.path.split(".").length===2)return null;let[f,i]=ho(o,l);return e.ignoreMissingValues&&(!f||Array.isArray(f)&&f.length===0)?null:(0,Dt.jsx)(Nl,{term:(0,Ka.getPropertyDisplayName)(l),children:(0,Dt.jsx)(Pe,{property:s,propertyType:i,value:f,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):(0,Dt.jsxs)("div",{children:[r,"\xA0not implemented"]})}var vi=require("@mantine/core"),Zr=require("@medplum/core"),Si=require("react");var _a=require("@mantine/core"),Yt=require("react/jsx-runtime");function Nr(e){return(0,Yt.jsxs)(_a.Group,{noWrap:!0,children:[(0,Yt.jsx)("div",{children:e.children}),(0,Yt.jsx)("div",{children:(0,Yt.jsx)(_a.Input.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}var Js=require("@mantine/core");function De(e,o){return e?.issue?.filter(t=>Xs(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
65
- `)}function Hr(e,o){return e?.issue?.filter(t=>Xs(t.expression?.[0],o))}function Xs(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}var $s=require("react/jsx-runtime");function He(e){return(0,$s.jsx)(Js.Input.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,error:De(e.outcome,e.htmlFor),children:e.children})}var Ks=require("@medplum/core");function Vr(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let s=o.replace("[x]",(0,Ks.capitalize)(l.code));s in e&&delete e[s]}return e[t]=a,e}var oo=require("@mantine/core"),O=require("@medplum/core"),Ci=require("react");var _s=require("react");var Zs=require("react/jsx-runtime");function Ql(e){let[o,t]=(0,_s.useState)(e.defaultValue);function r(a){let n=Zc(a);t(n),e.onChange&&e.onChange(n)}return(0,Zs.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&_c(o),maxSelectedValues:1,onChange:r})}function _c(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Zc(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}var Ys=require("react");var js=require("react/jsx-runtime");function qr(e){let[o,t]=(0,Ys.useState)(e.defaultValue);function r(a){let n=a[0],l=n&&jc(n);t(l),e.onChange&&e.onChange(l)}return(0,js.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Yc(o),maxSelectedValues:1,onChange:r})}function Yc(e){return{system:e.system,code:e.code,display:e.display}}function jc(e){return{system:e.system,code:e.code,display:e.display}}var Ya=require("@mantine/core"),ja=require("react");var kt=require("@mantine/core"),Za=require("react"),jt=require("react/jsx-runtime");function Gr(e){let[o,t]=(0,Za.useState)(e.defaultValue),r=(0,Za.useRef)();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(0,jt.jsxs)(kt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,jt.jsx)(kt.NativeSelect,{"data-testid":"system",defaultValue:o?.system,onChange:f=>n(f.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),(0,jt.jsx)(kt.NativeSelect,{"data-testid":"use",defaultValue:o?.use,onChange:f=>l(f.currentTarget.value),data:["","home","work","temp","old","mobile"]}),(0,jt.jsx)(kt.TextInput,{placeholder:"Value",defaultValue:o?.value,onChange:f=>s(f.currentTarget.value)})]})}var Ur=require("react/jsx-runtime");function zl(e){let[o,t]=(0,ja.useState)(e.defaultValue),r=(0,ja.useRef)();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(0,Ur.jsxs)(Ya.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Ur.jsx)(Ya.TextInput,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:s=>n(s.currentTarget.value)}),(0,Ur.jsx)(Gr,{name:e.name+"-telecom",defaultValue:o?.telecom?.[0],onChange:l})]})}var ei=require("@mantine/core");var Wl=require("@medplum/core");function Xl(e){if(!e)return"";let o=new Date(e);return(0,Wl.isValidDate)(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function Jl(e){if(!e)return"";let o=new Date(e);return(0,Wl.isValidDate)(o)?o.toISOString():""}var oi=require("react/jsx-runtime");function eo(e){return(0,oi.jsx)(ei.TextInput,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:ed(),defaultValue:Xl(e.defaultValue),autoFocus:e.autoFocus,error:De(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(Jl(t))}}})}function ed(){return"datetime-local"}var ti=require("@mantine/core"),ri=require("@medplum/core"),ni=require("react/jsx-runtime");function ai(e){return(0,ni.jsx)(ti.JsonInput,{id:e.name,name:e.name,"data-testid":"extension-input",defaultValue:(0,ri.stringify)(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}var Oo=require("@mantine/core"),en=require("react"),ot=require("react/jsx-runtime");function $l(e){let[o,t]=(0,en.useState)(e.defaultValue),r=(0,en.useRef)();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(0,ot.jsxs)(Oo.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,ot.jsx)(Oo.NativeSelect,{defaultValue:o?.use,name:e.name+"-use","data-testid":"use",onChange:u=>n(u.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"]}),(0,ot.jsx)(Oo.TextInput,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:o?.prefix?.join(" "),onChange:u=>l(u.currentTarget.value)}),(0,ot.jsx)(Oo.TextInput,{placeholder:"Given",name:e.name+"-given",defaultValue:o?.given?.join(" "),onChange:u=>s(u.currentTarget.value)}),(0,ot.jsx)(Oo.TextInput,{name:e.name+"-family",placeholder:"Family",defaultValue:o?.family,onChange:u=>f(u.currentTarget.value)}),(0,ot.jsx)(Oo.TextInput,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:o?.suffix?.join(" "),onChange:u=>i(u.currentTarget.value)})]})}var Qr=require("@mantine/core"),li=require("react"),zr=require("react/jsx-runtime");function Kl(e){let[o,t]=(0,li.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,zr.jsxs)(Qr.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,zr.jsx)(Qr.TextInput,{placeholder:"System",defaultValue:o?.system,onChange:a=>r({...o,system:a.currentTarget.value})}),(0,zr.jsx)(Qr.TextInput,{placeholder:"Value",defaultValue:o?.value,onChange:a=>r({...o,value:a.currentTarget.value})})]})}var tn=require("@mantine/core");var er=require("react"),on=require("react/jsx-runtime"),od=["USD","EUR","CAD","GBP","AUD"];function _l(e){let{onChange:o}=e,[t,r]=(0,er.useState)(e.defaultValue),a=(0,er.useCallback)(f=>{r(f),o&&o(f)},[o]),n=(0,er.useCallback)(f=>{a({...t,currency:f.currentTarget.value})},[t,a]),l=(0,er.useCallback)(f=>{a({...t,value:f.currentTarget.valueAsNumber})},[t,a]),s=(0,on.jsx)(tn.NativeSelect,{defaultValue:t?.currency,data:od,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return(0,on.jsx)(tn.TextInput,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:(0,on.jsx)(ll,{size:14}),rightSection:s,rightSectionWidth:92,onChange:l})}var fi=require("@mantine/core"),si=require("react");var Wr=require("react/jsx-runtime");function ii(e){let[o,t]=(0,si.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,Wr.jsxs)(fi.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Wr.jsx)(eo,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),(0,Wr.jsx)(eo,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}var Tt=require("@mantine/core"),ui=require("react"),or=require("react/jsx-runtime");function qe(e){let[o,t]=(0,ui.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,or.jsxs)(Tt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,or.jsx)(Tt.NativeSelect,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),(0,or.jsx)(Tt.TextInput,{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:td(a.currentTarget.value)})}}),(0,or.jsx)(Tt.TextInput,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function td(e){if(e)return parseFloat(e)}var ci=require("@mantine/core"),di=require("react");var Xr=require("react/jsx-runtime");function tr(e){let[o,t]=(0,di.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,Xr.jsxs)(ci.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Xr.jsx)(qe,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),(0,Xr.jsx)(qe,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}var mi=require("@mantine/core"),pi=require("react");var Jr=require("react/jsx-runtime");function xi(e){let[o,t]=(0,pi.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,Jr.jsxs)(mi.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Jr.jsx)(qe,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),(0,Jr.jsx)(qe,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}var rn=require("@mantine/core"),Ii=require("@medplum/core"),Zl=require("react");var $r=require("@mantine/core"),Kr=require("@medplum/core");var Bt=require("react");var Eo=require("react/jsx-runtime"),rd={Observation:"code",User:"email:contains"},ad=["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 nd(e){return{value:(0,Kr.getReferenceString)(e),label:(0,Kr.getDisplayString)(e),resource:e}}function _r(e){let o=P(),t=e.resourceType,[r,a]=(0,Bt.useState)(),n=K(e.defaultValue,a),l=e.onChange,s=(0,Bt.useCallback)(async(i,u)=>{let d=fd(t),c=new URLSearchParams({[d]:i,_count:"10"});return await o.searchResources(t,c,{signal:u})},[o,t]),f=(0,Bt.useCallback)(i=>{l&&l(i[0])},[l]);return e.defaultValue&&!r&&!n?null:(0,Eo.jsx)(vt,{name:e.name,required:e.required,itemComponent:ld,defaultValue:n,placeholder:e.placeholder,maxSelectedValues:1,toKey:Kr.getReferenceString,toOption:nd,loadOptions:s,onChange:f,clearable:!0})}var ld=(0,Bt.forwardRef)(({label:e,resource:o,...t},r)=>(0,Eo.jsx)("div",{ref:r,...t,children:(0,Eo.jsxs)($r.Group,{noWrap:!0,children:[(0,Eo.jsx)(Me,{value:o}),(0,Eo.jsxs)("div",{children:[(0,Eo.jsx)($r.Text,{children:e}),(0,Eo.jsx)($r.Text,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function fd(e){return rd[e]??(ad.includes(e)?"name":"_id")}var rr=require("react/jsx-runtime");function At(e){let o=sd(e.targetTypes),t=id(e.defaultValue,o),[r,a]=(0,Zl.useState)(e.defaultValue),[n,l]=(0,Zl.useState)(t);function s(f){a(f),e.onChange&&e.onChange(f)}return(0,rr.jsxs)(rn.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&(0,rr.jsx)(rn.NativeSelect,{"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&&(0,rr.jsx)(Jt,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:l,name:e.name+"-resourceType",placeholder:"Resource Type"}),(0,rr.jsx)(_r,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,onChange:f=>{s(f?(0,Ii.createReference)(f):void 0)}})]})}function sd(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function id(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}var tt=require("@mantine/core");var an=require("react");var Ge=require("react/jsx-runtime");function Yl(e){let[o,t]=(0,an.useState)(e.defaultValue&&Array.isArray(e.defaultValue)?e.defaultValue:[]),r=(0,an.useRef)();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return(0,Ge.jsxs)(tt.Stack,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,l)=>(0,Ge.jsxs)(tt.Group,{noWrap:!0,children:[(0,Ge.jsx)("div",{style:{flexGrow:1},children:(0,Ge.jsx)(Co,{arrayElement:!0,property:e.property,name:e.name+"."+l,defaultValue:n,onChange:s=>{let f=[...r.current];f[l]=s,a(f)}})}),(0,Ge.jsx)("div",{children:(0,Ge.jsx)(tt.ActionIcon,{title:"Remove",size:"sm",onClick:s=>{N(s);let f=[...r.current];f.splice(l,1),a(f)},children:(0,Ge.jsx)(Ko,{})})})]},`${l}-${o.length}`)),(0,Ge.jsx)(tt.Group,{noWrap:!0,style:{justifyContent:"flex-end"},children:(0,Ge.jsx)("div",{children:(0,Ge.jsx)(tt.ActionIcon,{title:"Add",size:"sm",color:"green",onClick:n=>{N(n);let l=[...r.current];l.push(void 0),a(l)},children:(0,Ge.jsx)(Ut,{})})})})]})}var me=require("@mantine/core"),hi=require("@medplum/core"),Mt=require("react");var te=require("react/jsx-runtime"),ud=["sun","mon","tue","wed","thu","fri","sat"];function jl(e){let[o,t]=(0,Mt.useState)(e.defaultValue),[r,a]=(0,Mt.useState)(!1),n=(0,Mt.useRef)();return n.current=o,(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)(me.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,te.jsx)("span",{children:(0,hi.formatTiming)(n.current)||"No repeat"}),(0,te.jsx)(me.Button,{onClick:()=>a(!0),children:"Edit"})]}),(0,te.jsx)(cd,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var gi={repeat:{period:1,periodUnit:"d"}};function cd(e){let[o,t]=(0,Mt.useState)(e.defaultValue||gi),r=(0,Mt.useRef)();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(0,te.jsx)(me.Modal,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:(0,te.jsxs)(me.Stack,{children:[(0,te.jsx)(He,{title:"Starts on",htmlFor:"timing-dialog-start",children:(0,te.jsx)(eo,{name:"timing-dialog-start",onChange:i=>a(i)})}),(0,te.jsx)(me.Switch,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?gi.repeat:void 0)}),o.repeat&&(0,te.jsxs)(te.Fragment,{children:[(0,te.jsx)(He,{title:"Repeat every",htmlFor:"timing-dialog-period",children:(0,te.jsxs)(me.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,te.jsx)(me.TextInput,{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)}),(0,te.jsx)(me.NativeSelect,{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"&&(0,te.jsx)(He,{title:"Repeat on",children:(0,te.jsx)(me.Chip.Group,{multiple:!0,onChange:f,children:(0,te.jsx)(me.Group,{position:"apart",mt:"md",spacing:"xs",children:ud.map(i=>(0,te.jsx)(me.Chip,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),(0,te.jsx)(me.Group,{position:"right",children:(0,te.jsx)(me.Button,{onClick:()=>e.onOk(o),children:"OK"})})]})})}var q=require("react/jsx-runtime");function Co(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===O.PropertyType.Attachment?(0,q.jsx)(Ol,{name:r,defaultValue:a,onChange:e.onChange}):(0,q.jsx)(Yl,{property:o,name:r,defaultValue:a,onChange:e.onChange});let n=o.type;return n.length>1?(0,q.jsx)(yi,{elementDefinitionTypes:n,...e}):(0,q.jsx)(ef,{elementDefinitionType:n[0],...e})}function yi(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=(0,Ci.useState)(t);return(0,q.jsxs)(oo.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,q.jsx)(oo.NativeSelect,{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}))}),(0,q.jsx)(ef,{...e,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",(0,O.capitalize)(r.code)))}})]})}function ef(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 O.PropertyType.SystemString:case O.PropertyType.canonical:case O.PropertyType.string:case O.PropertyType.time:case O.PropertyType.uri:case O.PropertyType.url:return(0,q.jsx)(oo.TextInput,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:De(e.outcome,r)});case O.PropertyType.date:return(0,q.jsx)(oo.TextInput,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:De(e.outcome,r)});case O.PropertyType.dateTime:case O.PropertyType.instant:return(0,q.jsx)(eo,{name:r,defaultValue:a,onChange:e.onChange,outcome:e.outcome});case O.PropertyType.decimal:case O.PropertyType.integer:case O.PropertyType.positiveInt:case O.PropertyType.unsignedInt:return(0,q.jsx)(oo.TextInput,{type:"number",step:t===O.PropertyType.decimal?"any":"1",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.valueAsNumber)}});case O.PropertyType.code:return(0,q.jsx)(Fr,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.boolean:return(0,q.jsx)(oo.Checkbox,{id:r,name:r,"data-testid":r,defaultChecked:!!a,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.checked)}});case O.PropertyType.markdown:return(0,q.jsx)(oo.Textarea,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)}});case O.PropertyType.Address:return(0,q.jsx)(Wn,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Annotation:return(0,q.jsx)(Xn,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Attachment:return(0,q.jsx)(wr,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.CodeableConcept:return(0,q.jsx)(Ql,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Coding:return(0,q.jsx)(qr,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.ContactDetail:return(0,q.jsx)(zl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.ContactPoint:return(0,q.jsx)(Gr,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Extension:return(0,q.jsx)(ai,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.HumanName:return(0,q.jsx)($l,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Identifier:return(0,q.jsx)(Kl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Money:return(0,q.jsx)(_l,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Period:return(0,q.jsx)(ii,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Duration:case O.PropertyType.Quantity:return(0,q.jsx)(qe,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Range:return(0,q.jsx)(tr,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Ratio:return(0,q.jsx)(xi,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Reference:return(0,q.jsx)(At,{name:r,defaultValue:a,targetTypes:dd(o),onChange:e.onChange});case O.PropertyType.Timing:return(0,q.jsx)(jl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Dosage:case O.PropertyType.UsageContext:return(0,q.jsx)(ar,{typeName:t,defaultValue:a,onChange:e.onChange,outcome:e.outcome});default:return(0,q.jsx)(ar,{typeName:o.type[0].code,defaultValue:a,onChange:e.onChange,outcome:e.outcome})}}function dd(e){return e?.type?.[0]?.targetProfile?.map(o=>o.split("/").pop())}var rt=require("react/jsx-runtime");function ar(e){let[o,t]=(0,Si.useState)(e.defaultValue??{});function r(s){t(s),e.onChange&&e.onChange(s)}let a=e.typeName,n=(0,Zr.tryGetDataType)(a);if(!n)return(0,rt.jsxs)("div",{children:[a,"\xA0not implemented"]});let l={type:a,value:o};return(0,rt.jsx)(vi.Stack,{children:Object.entries(n.elements).map(([s,f])=>{if(s==="id"||Ga.includes(s)||Ua.includes(s)&&f.path.split(".").length===2||!f.type)return null;let[i,u]=ho(l,s),d=f.min!==void 0&&f.min>0;return f.type.length===1&&f.type[0].code==="boolean"?(0,rt.jsx)(Nr,{title:(0,Zr.getPropertyDisplayName)(s),description:f.description,htmlFor:s,children:(0,rt.jsx)(Co,{property:f,name:s,defaultValue:i,defaultPropertyType:u,outcome:e.outcome,onChange:(c,x)=>{r(Vr(o,s,x??s,f,c))}})},s):(0,rt.jsx)(He,{title:(0,Zr.getPropertyDisplayName)(s),description:f.description,withAsterisk:d,htmlFor:s,outcome:e.outcome,children:(0,rt.jsx)(Co,{property:f,name:s,defaultValue:i,defaultPropertyType:u,onChange:(c,x)=>{r(Vr(o,s,x??s,f,c))}})},s)})})}var Lo=require("@mantine/core"),ln=require("react");function Ri(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function nn(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}var ue=require("react/jsx-runtime"),md=(0,Lo.createStyles)(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 of(e){let{classes:o}=md(),{onChangeMonth:t,onClick:r}=e,[a,n]=(0,ln.useState)(nn);function l(f){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+f),t(u),u})}let s=(0,ln.useMemo)(()=>pd(a,e.slots),[a,e.slots]);return(0,ue.jsxs)("div",{children:[(0,ue.jsxs)(Lo.Group,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[(0,ue.jsx)("p",{style:{flex:1},children:Ri(a)}),(0,ue.jsxs)(Lo.Group,{position:"right",spacing:"xs",children:[(0,ue.jsx)(Lo.Button,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),(0,ue.jsx)(Lo.Button,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),(0,ue.jsxs)("table",{className:o.table,children:[(0,ue.jsx)("thead",{children:(0,ue.jsxs)("tr",{children:[(0,ue.jsx)("th",{children:"SUN"}),(0,ue.jsx)("th",{children:"MON"}),(0,ue.jsx)("th",{children:"TUE"}),(0,ue.jsx)("th",{children:"WED"}),(0,ue.jsx)("th",{children:"THU"}),(0,ue.jsx)("th",{children:"FRI"}),(0,ue.jsx)("th",{children:"SAT"})]})}),(0,ue.jsx)("tbody",{children:s.map((f,i)=>(0,ue.jsx)("tr",{children:f.map((u,d)=>(0,ue.jsx)("td",{children:u&&(0,ue.jsx)(Lo.Button,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+d))},"week-"+i))})]})]})}function pd(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:xd(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 xd(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}var fn=require("@mantine/core"),bi=require("react/jsx-runtime"),Id=(0,fn.createStyles)(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function No(e){let{children:o,...t}=e,{classes:r}=Id();return(0,bi.jsx)(fn.Container,{className:r.root,...t,children:o})}var ne=require("@mantine/core"),wt=require("@mantine/notifications"),qo=require("@medplum/core");var Ue=require("react");var _=require("@mantine/core"),to=require("@medplum/core");var sn=require("react");var nr=require("@mantine/core"),tf=require("react/jsx-runtime"),gd=(0,nr.createStyles)(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function rf({value:e}){let{classes:o}=gd();return e?(0,tf.jsx)(nr.Stack,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&(0,tf.jsx)(nr.Blockquote,{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}var ki=require("@mantine/core");var Pi=require("@mantine/core"),lr=require("@medplum/core");var Di=require("react");var af=require("react/jsx-runtime");function lo(e){let{value:o,link:t,...r}=e,[a,n]=(0,Di.useState)(),l=K(o,n),s;if(a&&!(0,lr.isOk)(a))s=`[${(0,lr.normalizeErrorString)(a)}]`;else if(l)s=(0,lr.getDisplayString)(l);else return null;return t?(0,af.jsx)(Se,{to:o,...r,children:s}):(0,af.jsx)(Pi.Text,{component:"span",...r,children:s})}var Yr=require("react/jsx-runtime");function Ho(e){return(0,Yr.jsxs)(ki.Group,{spacing:"xs",children:[(0,Yr.jsx)(Me,{size:24,radius:12,value:e.value,link:e.link}),(0,Yr.jsx)(lo,{value:e.value,link:e.link})]})}var Ti=require("@mantine/core"),Bi=require("react/jsx-runtime"),hd={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 jr(e){return(0,Bi.jsx)(Ti.Badge,{color:hd[e.status],children:e.status})}var I=require("react/jsx-runtime"),Ai=(0,_.createStyles)(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}}));un.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function un(e){let o=P(),t=K(e.value),[r,a]=(0,sn.useState)();if((0,sn.useEffect)(()=>{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(0,I.jsxs)(_.Stack,{children:[(0,I.jsx)(_.Title,{children:"Diagnostic Report"}),(0,I.jsx)(Cd,{value:t}),r&&!e.hideSpecimenInfo&&yd(r),t.result&&(0,I.jsx)(Mi,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&(0,I.jsx)(rf,{value:n})]})}function Cd({value:e}){return(0,I.jsxs)(_.Group,{mt:"md",spacing:30,children:[e.subject&&(0,I.jsxs)("div",{children:[(0,I.jsx)(_.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),(0,I.jsx)(_.Text,{children:(0,I.jsx)(Ho,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>(0,I.jsxs)("div",{children:[(0,I.jsx)(_.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),(0,I.jsx)(_.Text,{children:(0,I.jsx)(Ho,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>(0,I.jsxs)("div",{children:[(0,I.jsx)(_.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),(0,I.jsx)(_.Text,{children:(0,I.jsx)(Ho,{value:o,link:!0})})]},o.reference)),e.issued&&(0,I.jsxs)("div",{children:[(0,I.jsx)(_.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),(0,I.jsx)(_.Text,{children:(0,to.formatDateTime)(e.issued)})]}),e.status&&(0,I.jsxs)("div",{children:[(0,I.jsx)(_.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),(0,I.jsx)(_.Text,{children:(0,to.capitalize)(e.status)})]})]})}function yd(e){return(0,I.jsxs)(_.Stack,{spacing:"xs",children:[(0,I.jsx)(_.Title,{order:2,size:"h6",children:"Specimens"}),(0,I.jsx)(_.List,{type:"ordered",children:e?.map(o=>(0,I.jsx)(_.List.Item,{ml:"sm",children:(0,I.jsxs)(_.Group,{spacing:20,children:[(0,I.jsxs)(_.Group,{spacing:5,children:[(0,I.jsx)(_.Text,{fw:500,children:"Collected:"})," ",(0,to.formatDateTime)(o.collection?.collectedDateTime)]}),(0,I.jsxs)(_.Group,{spacing:5,children:[(0,I.jsx)(_.Text,{fw:500,children:"Received:"})," ",(0,to.formatDateTime)(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Mi(e){let{classes:o}=Ai();return(0,I.jsxs)("table",{className:o.table,children:[(0,I.jsx)("thead",{children:(0,I.jsxs)("tr",{children:[(0,I.jsx)("th",{children:"Test"}),(0,I.jsx)("th",{children:"Value"}),(0,I.jsx)("th",{children:"Reference Range"}),(0,I.jsx)("th",{children:"Interpretation"}),(0,I.jsx)("th",{children:"Category"}),(0,I.jsx)("th",{children:"Performer"}),(0,I.jsx)("th",{children:"Status"})]})}),(0,I.jsx)("tbody",{children:(0,I.jsx)(Fi,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function Fi(e){return(0,I.jsx)(I.Fragment,{children:e.value?.map(o=>(0,I.jsx)(vd,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${(0,to.isReference)(o)?o.reference:o.id}`))})}function vd(e){let{classes:o,cx:t}=Ai(),r=K(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=bd(r);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("tr",{className:t({[o.criticalRow]:n}),children:[(0,I.jsx)("td",{rowSpan:a?2:1,children:(0,I.jsx)(Se,{to:r,children:(0,I.jsx)(bt,{value:r.code})})}),(0,I.jsx)("td",{children:(0,I.jsx)(Sd,{value:r})}),(0,I.jsx)("td",{children:(0,I.jsx)(Rd,{value:r.referenceRange})}),(0,I.jsx)("td",{children:r.interpretation&&r.interpretation.length>0&&(0,I.jsx)(bt,{value:r.interpretation[0]})}),(0,I.jsx)("td",{children:r.category&&r.category.length>0&&(0,I.jsx)(I.Fragment,{children:r.category.map(l=>(0,I.jsx)("div",{children:(0,I.jsx)(bt,{value:l})},`category-${(0,to.formatCodeableConcept)(l)}`))})}),(0,I.jsx)("td",{children:r.performer?.map(l=>(0,I.jsx)(Yo,{value:l},l.reference))}),(0,I.jsx)("td",{children:r.status&&(0,I.jsx)(jr,{status:r.status})})]}),r.hasMember&&(0,I.jsx)(Fi,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&(0,I.jsx)("tr",{children:(0,I.jsx)("td",{colSpan:6,children:(0,I.jsx)(rf,{value:r.note})})})]})}function Sd(e){let o=e.value;return(0,I.jsx)(I.Fragment,{children:(0,to.formatObservationValue)(o)})}function Rd(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?(0,I.jsx)(I.Fragment,{children:o.text}):(0,I.jsx)(Er,{value:o}):null}function bd(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}var fr=require("@mantine/core"),wi=require("react/jsx-runtime"),Pd=(0,fr.createStyles)((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%"}}})),Dd={shadow:"xs",radius:"md",withBorder:!0};function Ft(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=(0,fr.useComponentDefaultProps)("Panel",Dd,e),{classes:s,cx:f}=Pd({width:r,fill:a},{name:"Panel",unstyled:n});return(0,wi.jsx)(fr.Paper,{className:f(s.paper,o),...l,children:t})}var Ei=require("@mantine/core"),yo=require("@medplum/core");var cn=require("react"),Li=require("rfc6902");var Fe=require("react/jsx-runtime"),kd=(0,Ei.createStyles)(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 Ni(e){let{classes:o}=kd(),t=P(),[r,a]=(0,cn.useState)(!1);if((0,cn.useEffect)(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,Li.createPatch)(e.original,e.revised),l=[(0,yo.toTypedValue)(e.original)],s=[(0,yo.toTypedValue)(e.revised)];return(0,Fe.jsxs)("table",{className:o.root,children:[(0,Fe.jsx)("thead",{children:(0,Fe.jsxs)("tr",{children:[(0,Fe.jsx)("th",{}),(0,Fe.jsx)("th",{children:"Before"}),(0,Fe.jsx)("th",{children:"After"})]})}),(0,Fe.jsx)("tbody",{children:n.map(f=>{if(f.path.startsWith("/meta"))return null;let i=f.path,u=Td(i),c=(0,yo.getSearchParameterDetails)(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],x=!!c?.isArray,C=f.op==="add"?void 0:(0,yo.evalFhirPathTyped)(u,l)?.[0],g=f.op==="remove"?void 0:(0,yo.evalFhirPathTyped)(u,s)?.[0];return(0,Fe.jsxs)("tr",{children:[(0,Fe.jsxs)("td",{children:[(0,yo.capitalize)(f.op)," ",u]}),(0,Fe.jsx)("td",{className:o.removed,children:C&&(0,Fe.jsx)(Pe,{property:c,propertyType:C.type,value:Oi(C.value,x),ignoreMissingValues:!0})}),(0,Fe.jsx)("td",{className:o.added,children:g&&(0,Fe.jsx)(Pe,{property:c,propertyType:g.type,value:Oi(g.value,x),ignoreMissingValues:!0})})]},`op-${f.op}-${f.path}`)})})]})}function Td(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 Oi(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}var dn=require("react");var Hi=require("react/jsx-runtime");function mn(e){let o=P(),t=K(e.value),[r,a]=(0,dn.useState)(!1);return(0,dn.useEffect)(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:(0,Hi.jsx)(Zt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}var fo=require("@mantine/core"),pn=require("@medplum/core");var ce=require("react/jsx-runtime");function nf(e){return(0,ce.jsx)(No,{children:e.children})}function Vo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,s=e.dateTime??o.meta?.lastUpdated;return(0,ce.jsxs)(Ft,{"data-testid":"timeline-item",fill:!0,...n,children:[(0,ce.jsxs)(fo.Group,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[(0,ce.jsx)(Me,{value:l,link:!0,size:"md"}),(0,ce.jsxs)("div",{style:{flex:1},children:[(0,ce.jsx)(fo.Text,{size:"sm",children:(0,ce.jsx)(lo,{color:"dark",weight:500,value:l,link:!0})}),(0,ce.jsxs)(fo.Text,{size:"xs",children:[(0,ce.jsx)(Se,{color:"dimmed",to:e.resource,children:(0,pn.formatDateTime)(s)}),(0,ce.jsx)(fo.Text,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),(0,ce.jsx)(Se,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&(0,ce.jsxs)(fo.Menu,{position:"bottom-end",shadow:"md",width:200,children:[(0,ce.jsx)(fo.Menu.Target,{children:(0,ce.jsx)(fo.ActionIcon,{radius:"xl","aria-label":`Actions for ${(0,pn.getReferenceString)(e.resource)}`,children:(0,ce.jsx)(fl,{})})}),a]})]}),(0,ce.jsxs)(yt,{children:[r&&(0,ce.jsx)("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&(0,ce.jsx)(ce.Fragment,{children:e.children})]})]})}function lf(e,o){e.sort((t,r)=>{let a=Vi(t,o),n=Vi(r,o);return a>n?1:a<n?-1:qi(t,o)-qi(r,o)})}function Vi(e,o){if(!Gi(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function qi(e,o){if(!Gi(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 Gi(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}var R=require("react/jsx-runtime"),Bd=(0,ne.createStyles)(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function Go(e){let o=P(),t=To(),r=o.getProfile(),a=(0,Ue.useRef)(null),n=K(e.value),[l,s]=(0,Ue.useState)(),[f,i]=(0,Ue.useState)([]),u=e.loadTimelineResources,d=(0,Ue.useRef)(f);d.current=f;let c=(0,Ue.useCallback)(h=>{lf(h,n),h.reverse(),i(h)},[n]),x=(0,Ue.useCallback)(h=>{let U=[];for(let mo of h){if(mo.status!=="fulfilled")continue;let y=mo.value;if(y.type==="history"&&s(y),y.entry)for(let X of y.entry)U.push(X.resource)}c(U)},[c]),C=(0,Ue.useCallback)(h=>c([...d.current,h]),[c]),g=(0,Ue.useCallback)(()=>{let h,U;"resourceType"in e.value?(h=e.value.resourceType,U=e.value.id):[h,U]=e.value.reference?.split("/"),u(o,h,U).then(x).catch(console.log)},[o,e.value,u,x]);(0,Ue.useEffect)(()=>g(),[g]);function D(h){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,h)).then(U=>C(U)).catch(console.log)}function B(h){!n||!e.createMedia||o.createResource(e.createMedia(n,r,h)).then(U=>C(U)).then(()=>(0,wt.updateNotification)({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:(0,R.jsx)(br,{size:16}),autoClose:2e3})).catch(U=>(0,wt.updateNotification)({id:"upload-notification",color:"red",title:"Upload error",message:(0,qo.normalizeErrorString)(U),icon:(0,R.jsx)(ba,{size:16}),autoClose:2e3}))}function T(h,U){return o.updateResource({...h,priority:U})}function M(h){T(h,"stat").then(g).catch(console.log)}function Z(h){T(h,"routine").then(g).catch(console.log)}function b(h){t(`/${h.resourceType}/${h.id}`)}function L(h){t(`/${h.resourceType}/${h.id}/edit`)}function de(h){t(`/${h.resourceType}/${h.id}/delete`)}function ye(h){t(`/${h.resourceType}/${h.id}/_history/${h.meta?.versionId}`)}function Do(){(0,wt.showNotification)({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function xt(h){(0,wt.updateNotification)({id:"upload-notification",loading:!0,title:"Uploading...",message:Ld(h),autoClose:!1,withCloseButton:!1})}function Ae(h){(0,wt.updateNotification)({id:"upload-notification",color:"red",title:"Upload error",message:(0,qo.normalizeErrorString)(h),icon:(0,R.jsx)(ba,{size:16}),autoClose:2e3})}return n?(0,R.jsxs)(nf,{children:[e.createCommunication&&(0,R.jsx)(Ft,{children:(0,R.jsx)(oe,{testid:"timeline-form",onSubmit:h=>{D(h.text);let U=a.current;U&&(U.value="",U.focus())},children:(0,R.jsxs)(ne.Group,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[(0,R.jsx)(Me,{value:r}),(0,R.jsx)(ne.TextInput,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),(0,R.jsx)(ne.ActionIcon,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:(0,R.jsx)(ml,{size:16})}),(0,R.jsx)(Rt,{onUpload:B,onUploadStart:Do,onUploadProgress:xt,onUploadError:Ae,children:h=>(0,R.jsx)(ne.ActionIcon,{...h,radius:"xl",color:"blue",variant:"filled",children:(0,R.jsx)(Pr,{size:16})})})]})})}),f.map(h=>{if(!h)return null;let U=`${h.resourceType}/${h.id}/${h.meta?.versionId}`;if(h.resourceType===n.resourceType&&h.id===n.id)return(0,R.jsx)(Ad,{history:l,resource:h,onDetails:ye},U);switch(h.resourceType){case"AuditEvent":return(0,R.jsx)(Od,{resource:h,onDetails:b},U);case"Communication":return(0,R.jsx)(Fd,{resource:h,onPin:h.priority!=="stat"?M:void 0,onUnpin:h.priority==="stat"?Z:void 0,onDetails:b,onEdit:L,onDelete:de},U);case"DiagnosticReport":return(0,R.jsx)(Ed,{resource:h,onDetails:b,onEdit:L,onDelete:de},U);case"Media":return(0,R.jsx)(wd,{resource:h,onDetails:b,onEdit:L,onDelete:de},U);default:return(0,R.jsx)(Vo,{resource:h,padding:!0,children:(0,R.jsx)(mn,{value:h,ignoreMissingValues:!0})},U)}})]}):(0,R.jsx)(ne.Center,{style:{width:"100%",height:"100%"},children:(0,R.jsx)(ne.Loader,{})})}function sr(e){return(0,R.jsxs)(ne.Menu.Dropdown,{children:[(0,R.jsx)(ne.Menu.Label,{children:"Resource"}),e.onPin&&(0,R.jsx)(ne.Menu.Item,{icon:(0,R.jsx)(pl,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${(0,qo.getReferenceString)(e.resource)}`,children:"Pin"}),e.onUnpin&&(0,R.jsx)(ne.Menu.Item,{icon:(0,R.jsx)(xl,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${(0,qo.getReferenceString)(e.resource)}`,children:"Unpin"}),e.onDetails&&(0,R.jsx)(ne.Menu.Item,{icon:(0,R.jsx)(cl,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${(0,qo.getReferenceString)(e.resource)}`,children:"Details"}),e.onEdit&&(0,R.jsx)(ne.Menu.Item,{icon:(0,R.jsx)(sl,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${(0,qo.getReferenceString)(e.resource)}`,children:"Edit"}),e.onDelete&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ne.Menu.Divider,{}),(0,R.jsx)(ne.Menu.Label,{children:"Danger zone"}),(0,R.jsx)(ne.Menu.Item,{color:"red",icon:(0,R.jsx)(Tr,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${(0,qo.getReferenceString)(e.resource)}`,children:"Delete"})]})]})}function Ad(e){let o=Md(e.history,e.resource);return o?(0,R.jsx)(Vo,{resource:e.resource,padding:!0,popupMenuItems:(0,R.jsx)(sr,{...e}),children:(0,R.jsx)(Ni,{original:o,revised:e.resource})}):(0,R.jsxs)(Vo,{resource:e.resource,padding:!0,popupMenuItems:(0,R.jsx)(sr,{...e}),children:[(0,R.jsx)("h3",{children:"Created"}),(0,R.jsx)(mn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function Md(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 Fd(e){let{classes:o}=Bd(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return(0,R.jsx)(Vo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:(0,R.jsx)(sr,{...e}),children:(0,R.jsx)("p",{children:e.resource.payload?.[0]?.contentString})})}function wd(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return(0,R.jsx)(Vo,{resource:e.resource,padding:!!t,popupMenuItems:(0,R.jsx)(sr,{...e}),children:(0,R.jsx)(no,{value:e.resource.content})})}function Od(e){return(0,R.jsx)(Vo,{resource:e.resource,padding:!0,popupMenuItems:(0,R.jsx)(sr,{...e}),children:(0,R.jsx)(ne.ScrollArea,{children:(0,R.jsx)("pre",{children:e.resource.outcomeDesc})})})}function Ed(e){return(0,R.jsx)(Vo,{resource:e.resource,padding:!0,popupMenuItems:(0,R.jsx)(sr,{...e}),children:(0,R.jsx)(un,{value:e.resource})})}function Ld(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${ff(e.loaded)} / ${ff(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${ff(e.loaded)}`}function ff(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"}var Ui=require("react/jsx-runtime");function Nd(e){return(0,Ui.jsx)(Go,{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})])}})}var sf=require("react/jsx-runtime");function ea(e){let{children:o,...t}=e;return(0,sf.jsx)(No,{children:(0,sf.jsx)(Ft,{...t,children:o})})}var oa=require("@medplum/core");var Qi=require("react/jsx-runtime");function Hd(e){return(0,Qi.jsx)(Go,{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:(0,oa.createReference)(o),subject:o.subject,sender:(0,oa.createReference)(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:(0,oa.createReference)(o),subject:o.subject,operator:(0,oa.createReference)(t),issued:new Date().toISOString(),content:r})})}var xr=require("@mantine/core"),tu=require("@medplum/core");var We=require("react");var zi=require("@medplum/core");var Xi=require("react/jsx-runtime");function Wi(e){let o;try{o=(0,zi.evalFhirPath)(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(0,Xi.jsx)(Pe,{value:o[0]||"",propertyType:e.propertyType})}var H=require("@mantine/core"),pr=require("@medplum/core");var Ve=require("react");var nt=require("@mantine/core"),at=require("react/jsx-runtime");function $i(e){return(0,at.jsxs)(nt.Modal,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[(0,at.jsxs)(nt.Box,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&(0,at.jsx)(Ji,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,at.jsx)(Ji,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),(0,at.jsx)(nt.Text,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function Ji(e){return(0,at.jsx)(nt.Button,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var vo=require("@mantine/core"),dr=require("@medplum/core"),Uo=require("react");var k=require("@medplum/core");var ir=require("react/jsx-runtime"),Vd={string:[k.Operator.EQUALS,k.Operator.NOT,k.Operator.CONTAINS,k.Operator.EXACT],fulltext:[k.Operator.EQUALS,k.Operator.NOT,k.Operator.CONTAINS,k.Operator.EXACT],token:[k.Operator.EQUALS,k.Operator.NOT],reference:[k.Operator.EQUALS,k.Operator.NOT],numeric:[k.Operator.EQUALS,k.Operator.NOT_EQUALS,k.Operator.GREATER_THAN,k.Operator.LESS_THAN,k.Operator.GREATER_THAN_OR_EQUALS,k.Operator.LESS_THAN_OR_EQUALS],quantity:[k.Operator.EQUALS,k.Operator.NOT_EQUALS,k.Operator.GREATER_THAN,k.Operator.LESS_THAN,k.Operator.GREATER_THAN_OR_EQUALS,k.Operator.LESS_THAN_OR_EQUALS],date:[k.Operator.EQUALS,k.Operator.NOT_EQUALS,k.Operator.GREATER_THAN,k.Operator.LESS_THAN,k.Operator.GREATER_THAN_OR_EQUALS,k.Operator.LESS_THAN_OR_EQUALS,k.Operator.STARTS_AFTER,k.Operator.ENDS_BEFORE,k.Operator.APPROXIMATELY],datetime:[k.Operator.EQUALS,k.Operator.NOT_EQUALS,k.Operator.GREATER_THAN,k.Operator.LESS_THAN,k.Operator.GREATER_THAN_OR_EQUALS,k.Operator.LESS_THAN_OR_EQUALS,k.Operator.STARTS_AFTER,k.Operator.ENDS_BEFORE,k.Operator.APPROXIMATELY]},qd={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 ur(e,o){return{...e,filters:o,offset:0,name:void 0}}function Gd(e){return ur(e,[])}function ta(e,o){return ur(e,(e.filters??[]).filter(t=>t.code!==o))}function Ot(e,o,t,r,a){a&&(e=ta(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),ur(e,n)}function Ud(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 uf(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function cf(e,o){return pf(e,o,-1)}function df(e,o){return pf(e,o,0)}function mf(e,o){return pf(e,o,1)}function pf(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),xn(e,o,r,a)}function xf(e,o){return hf(e,o,-1)}function If(e,o){return hf(e,o,0)}function gf(e,o){return hf(e,o,1)}function hf(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),xn(e,o,r,a)}function Cf(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),xn(e,o,t,new Date)}function xn(e,o,t,r){return e=ta(e,o),e=Ki(e,o,k.Operator.GREATER_THAN_OR_EQUALS,t),e=Ki(e,o,k.Operator.LESS_THAN_OR_EQUALS,r),e}function Ki(e,o,t,r){return Ot(e,o,t,r.toISOString())}function In(e,o,t=!0){return Ot(e,o,k.Operator.MISSING,t.toString())}function _i(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function yf(e,o){let t=e.count??k.DEFAULT_SEARCH_COUNT,r=(o-1)*t;return _i(e,r)}function gn(e,o,t){return o===vf(e)&&t!==void 0&&t===Sf(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function Qd(e,o){let t=!1;return vf(e)===o&&(t=!Sf(e)),gn(e,o,t)}function vf(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function Sf(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function Rf(e){return Vd[e.type]}function cr(e){return qd[e]??""}function Qe(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(k.capitalize).join(" "))}function bf(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?(0,k.formatDateTime)(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?zd(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?Wd(e,o.searchParams[0]):null}function zd(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=ho({type:e.resourceType,value:e},t);return r?(0,ir.jsx)(Pe,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function Wd(e,o){let t=(0,k.evalFhirPathTyped)(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:(0,ir.jsx)(ir.Fragment,{children:t.map((r,a)=>(0,ir.jsx)(Pe,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}var lt=require("react/jsx-runtime");function Pf(e){let o=(0,Uo.useRef)(!1),[t,r]=(0,Uo.useState)({search:JSON.parse((0,dr.stringify)(e.search))}),[a,n]=(0,Uo.useState)(!1);(0,Uo.useEffect)(()=>{r({search:e.search})},[e.search]);let l=(0,Uo.useMemo)(()=>{if(!e.visible)return[];let f=e.search.resourceType,i=(0,dr.getDataType)(f),u=(0,dr.getSearchParameters)(f);return Xd(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:Qe(d)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function s(f){r({search:{...t.search,fields:f}})}return(0,lt.jsx)(vo.Modal,{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:(0,lt.jsx)("div",{"data-testid":"overlay-child"})},children:(0,lt.jsxs)(vo.Stack,{children:[(0,lt.jsx)(vo.MultiSelect,{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}),(0,lt.jsx)(vo.Group,{position:"right",children:(0,lt.jsx)(vo.Button,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function Xd(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(Qe(n));if(o)for(let n of Object.keys(o)){let l=Qe(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}var ze=require("@mantine/core"),ra=require("@medplum/core"),zo=require("react");var so=require("@medplum/core");var Et=require("react/jsx-runtime");function hn(e){let{resourceType:o,filter:t}=e,r=so.globalSchema.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===so.Operator.EQUALS||t.operator===so.Operator.NOT_EQUALS))return(0,Et.jsx)(lo,{value:{reference:t.value}});let a=(0,so.getSearchParameterDetails)(o,r);if(t.code==="_lastUpdated"||a.type===so.SearchParameterType.DATETIME)return(0,Et.jsx)(Et.Fragment,{children:(0,so.formatDateTime)(t.value)})}return(0,Et.jsx)(Et.Fragment,{children:t.value})}var mr=require("@mantine/core"),Qo=require("@medplum/core");var ft=require("react/jsx-runtime");function Cn(e){let o=(0,Qo.getSearchParameterDetails)(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case Qo.SearchParameterType.REFERENCE:return(0,ft.jsx)(At,{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 Qo.SearchParameterType.BOOLEAN:return(0,ft.jsx)(mr.Checkbox,{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 Qo.SearchParameterType.DATE:return(0,ft.jsx)(mr.TextInput,{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 Qo.SearchParameterType.DATETIME:return(0,ft.jsx)(eo,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case Qo.SearchParameterType.NUMBER:return(0,ft.jsx)(mr.TextInput,{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 Qo.SearchParameterType.QUANTITY:return(0,ft.jsx)(qe,{name:t,defaultValue:Jd(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return(0,ft.jsx)(mr.TextInput,{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 Jd(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}var E=require("react/jsx-runtime");function Df(e){let[o,t]=(0,zo.useState)(JSON.parse((0,ra.stringify)(e.search))),[r,a]=(0,zo.useState)(-1),n=(0,zo.useRef)(o);n.current=o,(0,zo.useEffect)(()=>{t(JSON.parse((0,ra.stringify)(e.search)))},[e.search]);function l(u){t(Ot(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let s=e.search.resourceType,f=(0,ra.getSearchParameters)(s)??{},i=o.filters||[];return(0,E.jsxs)(ze.Modal,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[(0,E.jsx)("div",{children:(0,E.jsxs)("table",{children:[(0,E.jsxs)("colgroup",{children:[(0,E.jsx)("col",{style:{width:200}}),(0,E.jsx)("col",{style:{width:200}}),(0,E.jsx)("col",{style:{width:380}}),(0,E.jsx)("col",{style:{width:120}})]}),(0,E.jsx)("thead",{children:(0,E.jsxs)("tr",{children:[(0,E.jsx)("th",{children:"Field"}),(0,E.jsx)("th",{children:"Operation"}),(0,E.jsx)("th",{children:"Value"}),(0,E.jsx)("th",{children:"Actions"})]})}),(0,E.jsxs)("tbody",{children:[i.map((u,d)=>d===r?(0,E.jsx)(Zi,{resourceType:s,searchParams:f,defaultValue:u,okText:"Save",onOk:c=>{let x=[...i];x[d]=c,t(ur(n.current,x)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):(0,E.jsx)($d,{resourceType:s,searchParams:f,filter:u,onEdit:()=>a(d),onDelete:()=>t(uf(n.current,d))},`filter-${u.code}-${u.operator}-${u.value}-display`)),(0,E.jsx)(Zi,{resourceType:s,searchParams:f,okText:"Add",onOk:l})]})]})}),(0,E.jsx)(ze.Group,{position:"right",mt:"xl",children:(0,E.jsx)(ze.Button,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function $d(e){let{filter:o}=e;return(0,E.jsxs)("tr",{children:[(0,E.jsx)("td",{children:Qe(o.code)}),(0,E.jsx)("td",{children:cr(o.operator)}),(0,E.jsx)("td",{children:(0,E.jsx)(hn,{resourceType:e.resourceType,filter:o})}),(0,E.jsxs)("td",{children:[(0,E.jsx)(ze.Button,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),(0,E.jsx)(ze.Button,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function Zi(e){let[o,t]=(0,zo.useState)(e.defaultValue??{}),r=(0,zo.useRef)(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&&Rf(s);return(0,E.jsxs)("tr",{children:[(0,E.jsx)("td",{children:(0,E.jsx)(ze.NativeSelect,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:Qe(i)}))]})}),(0,E.jsx)("td",{children:f&&(0,E.jsx)(ze.NativeSelect,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...f.map(i=>({value:i,label:cr(i)}))]})}),(0,E.jsx)("td",{children:s&&o.operator&&(0,E.jsx)(Cn,{resourceType:e.resourceType,searchParam:s,defaultValue:o.value,onChange:l})}),(0,E.jsxs)("td",{children:[o.code&&o.operator&&(0,E.jsx)(ze.Button,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&(0,E.jsx)(ze.Button,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}var st=require("@mantine/core"),Yi=require("react");var Wo=require("react/jsx-runtime");function ji(e){let[o,t]=(0,Yi.useState)(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return(0,Wo.jsx)(st.Modal,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:(0,Wo.jsx)(oe,{onSubmit:r,children:(0,Wo.jsxs)(st.Grid,{children:[(0,Wo.jsx)(st.Grid.Col,{span:10,children:(0,Wo.jsx)(Cn,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),(0,Wo.jsx)(st.Grid.Col,{span:2,children:(0,Wo.jsx)(st.Button,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}var A=require("@mantine/core"),Re=require("@medplum/core");var m=require("react/jsx-runtime");function eu(e){if(!e.searchParams)return null;function o(n,l){a(gn(e.search,n.code,l))}function t(n){a(ta(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?(0,m.jsx)(Kd,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):(0,m.jsx)(A.Menu.Dropdown,{children:e.searchParams.map(n=>(0,m.jsx)(A.Menu.Item,{children:Qe(n.code)},n.code))})}function Kd(e){switch(e.searchParam.type){case"date":return(0,m.jsx)(_d,{...e});case"number":case"quantity":return(0,m.jsx)(Zd,{...e});case"reference":return(0,m.jsx)(Yd,{...e});case"string":case"token":case"uri":return(0,m.jsx)(jd,{...e});default:return(0,m.jsxs)(m.Fragment,{children:["Unknown search param type: ",e.searchParam.type]})}}function _d(e){let{searchParam:o}=e,t=o.code;return(0,m.jsxs)(A.Menu.Dropdown,{children:[(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Dr,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(kr,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(zt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.NOT_EQUALS),children:"Does not equal..."}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Da,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.ENDS_BEFORE),children:"Before..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Pa,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.STARTS_AFTER),children:"After..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(jn,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Between..."}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(mf(e.search,t)),children:"Tomorrow"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(df(e.search,t)),children:"Today"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(cf(e.search,t)),children:"Yesterday"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(gf(e.search,t)),children:"Next Month"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(If(e.search,t)),children:"This Month"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(xf(e.search,t)),children:"Last Month"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Ao,{size:14}),onClick:()=>e.onChange(Cf(e.search,t)),children:"Year to date"}),(0,m.jsx)(yn,{...e})]})}function Zd(e){let{searchParam:o}=e;return(0,m.jsxs)(A.Menu.Dropdown,{children:[(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Dr,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(kr,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(zt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.NOT_EQUALS),children:"Does not equal..."}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Pa,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.GREATER_THAN),children:"Greater than..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Wt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Da,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.LESS_THAN),children:"Less than..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Wt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),(0,m.jsx)(yn,{...e})]})}function Yd(e){let{searchParam:o}=e;return(0,m.jsxs)(A.Menu.Dropdown,{children:[(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(zt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.NOT),children:"Does not equal..."}),(0,m.jsx)(yn,{...e})]})}function jd(e){let{searchParam:o}=e;return(0,m.jsxs)(A.Menu.Dropdown,{children:[(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Dr,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(kr,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(zt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.NOT),children:"Does not equal..."}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(ol,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.CONTAINS),children:"Contains..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(el,{size:14}),onClick:()=>e.onPrompt(o,Re.Operator.EQUALS),children:"Does not contain..."}),(0,m.jsx)(yn,{...e})]})}function yn(e){let{searchParam:o}=e,t=o.code;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Zn,{size:14}),onClick:()=>e.onChange(In(e.search,t)),children:"Missing"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(_n,{size:14}),onClick:()=>e.onChange(In(e.search,t,!1)),children:"Not missing"}),(0,m.jsx)(A.Menu.Divider,{}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Sl,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}var it=require("@medplum/core");function kf(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(em(o,r));return t}function em(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=(0,it.getElementDefinition)(e,o),r=(0,it.getSearchParameter)(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=(0,it.getSearchParameters)(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=(0,it.getSearchParameterDetails)(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}var v=require("react/jsx-runtime"),vn=class extends Event{constructor(t){super("change");this.definition=t}},Sn=class extends Event{constructor(t){super("load");this.response=t}},ut=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},om=(0,H.createStyles)(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 ou(e){let{classes:o}=om(),t=P(),[r,a]=(0,Ve.useState)(!1),[n,l]=(0,Ve.useState)(),{search:s,onLoad:f}=e,[i,u]=(0,Ve.useState)({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),d=(0,Ve.useRef)(i);d.current=i;let c=s.total??"accurate",x=(0,Ve.useCallback)(y=>{l(void 0),t.search(s.resourceType,(0,pr.formatSearchQuery)({...s,total:c,fields:void 0}),y).then(X=>{u({...d.current,searchResponse:X}),f&&f(new Sn(X))}).catch(X=>{u({...d.current,searchResponse:void 0}),l(X)})},[t,s,c,f]),C=(0,Ve.useCallback)(()=>{u({...d.current,searchResponse:void 0}),x({cache:"reload"})},[x]);(0,Ve.useEffect)(()=>{x()},[x]);function g(y,X){y.stopPropagation();let ve=y.target.checked,ge={...d.current.selected};ve?ge[X]=!0:delete ge[X],u({...d.current,selected:ge})}function D(y){y.stopPropagation();let ko=y.target.checked,ve={},ge=d.current.searchResponse;ko&&ge?.entry&&ge.entry.forEach(Ye=>{Ye.resource?.id&&(ve[Ye.resource.id]=!0)}),u({...d.current,selected:ve})}function B(){let y=d.current;if(!y.searchResponse?.entry||y.searchResponse.entry.length===0)return!1;for(let X of y.searchResponse.entry)if(X.resource?.id&&!y.selected[X.resource.id])return!1;return!0}function T(y){e.onChange&&e.onChange(new vn(y))}function M(y,X){if(Aa(y.target)||y.button===2)return;N(y);let ko=y.button===1||y.ctrlKey||y.metaKey;!ko&&e.onClick&&e.onClick(new ut(X,y)),ko&&e.onAuxClick&&e.onAuxClick(new ut(X,y))}function Z(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if((0,Ve.useEffect)(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return(0,v.jsx)(H.Center,{style:{width:"100%",height:"100%"},children:(0,v.jsx)(H.Loader,{})});let b=e.checkboxesEnabled,L=kf(s),de=s.resourceType,ye=i.searchResponse,xt=ye?.entry?.map(y=>y.resource),Ae="subtle",h="gray",U=16,mo=window.innerWidth<768;return(0,v.jsxs)("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&(0,v.jsxs)(H.Group,{position:"apart",mb:"xl",children:[(0,v.jsxs)(H.Group,{spacing:2,children:[(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(al,{size:U}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(ul,{size:U}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(il,{size:U}),onClick:e.onNew,children:"New..."}),!mo&&Z()&&(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(vl,{size:U}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!mo&&e.onDelete&&(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(Tr,{size:U}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!mo&&e.onBulk&&(0,v.jsx)(H.Button,{compact:!0,variant:Ae,color:h,leftIcon:(0,v.jsx)(Yn,{size:U}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),(0,v.jsxs)(H.Group,{spacing:2,children:[ye&&(0,v.jsxs)(H.Text,{size:"xs",color:"dimmed",children:[lm(s,ye.total),"-",fm(s,ye.total)," of"," ",`${c==="estimate"?"~":""}${ye.total?.toLocaleString()}`]}),(0,v.jsx)(H.ActionIcon,{title:"Refresh",onClick:C,children:(0,v.jsx)(gl,{size:"1.125rem"})})]})]}),(0,v.jsxs)(H.Table,{className:o.table,children:[(0,v.jsxs)("thead",{children:[(0,v.jsxs)("tr",{children:[b&&(0,v.jsx)("th",{children:(0,v.jsx)("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:B(),onChange:y=>D(y)})}),L.map(y=>(0,v.jsx)("th",{children:(0,v.jsxs)(H.Menu,{shadow:"md",width:240,position:"bottom-end",children:[(0,v.jsx)(H.Menu.Target,{children:(0,v.jsx)(H.UnstyledButton,{className:o.control,children:(0,v.jsxs)(H.Group,{position:"apart",noWrap:!0,children:[(0,v.jsx)(H.Text,{weight:500,size:"sm",children:Qe(y.name)}),(0,v.jsx)(H.Center,{className:o.icon,children:(0,v.jsx)(Jn,{size:14,stroke:1.5})})]})})}),(0,v.jsx)(eu,{search:e.search,searchParams:y.searchParams,onPrompt:(X,ko)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:X,filterDialogFilter:ko})},onChange:X=>{T(X)}})]})},y.name))]}),!e.hideFilters&&(0,v.jsxs)("tr",{children:[b&&(0,v.jsx)("th",{}),L.map(y=>(0,v.jsx)("th",{children:y.searchParams&&(0,v.jsx)(rm,{resourceType:de,searchParams:y.searchParams,filters:e.search.filters})},y.name))]})]}),(0,v.jsx)("tbody",{children:xt?.map(y=>y&&(0,v.jsxs)("tr",{className:o.tr,"data-testid":"search-control-row",onClick:X=>M(X,y),onAuxClick:X=>M(X,y),children:[b&&(0,v.jsx)("td",{children:(0,v.jsx)("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${y.id}`,checked:!!i.selected[y.id],onChange:X=>g(X,y.id)})}),L.map(X=>(0,v.jsx)("td",{children:bf(y,X)},X.name))]},y.id))})]}),xt?.length===0&&(0,v.jsx)(No,{children:(0,v.jsx)(H.Center,{style:{height:150},children:(0,v.jsx)(H.Text,{size:"xl",color:"dimmed",children:"No results"})})}),ye?.total!==void 0&&ye.total>0&&(0,v.jsx)(H.Center,{m:"md",p:"md",children:(0,v.jsx)(H.Pagination,{value:am(s),total:nm(s,ye.total),onChange:y=>T(yf(s,y)),getControlProps:y=>{switch(y){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&(0,v.jsx)("div",{"data-testid":"search-error",children:(0,v.jsx)("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),(0,v.jsx)(Pf,{search:e.search,visible:d.current.fieldEditorVisible,onOk:y=>{T(y),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),(0,v.jsx)(Df,{search:e.search,visible:d.current.filterEditorVisible,onOk:y=>{T(y),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),(0,v.jsx)($i,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),(0,v.jsx)(ji,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?Qe(i.filterDialogSearchParam.code):"",resourceType:de,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:y=>{T(Ot(e.search,y.code,y.operator,y.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var tm=(0,Ve.memo)(ou);function rm(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?(0,v.jsx)("span",{children:"no filters"}):(0,v.jsx)(v.Fragment,{children:o.map(t=>(0,v.jsxs)("div",{children:[cr(t.operator),"\xA0",(0,v.jsx)(hn,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function am(e){return Math.floor((e.offset??0)/(e.count??pr.DEFAULT_SEARCH_COUNT))+1}function nm(e,o){let t=e.count??pr.DEFAULT_SEARCH_COUNT;return Math.ceil(o/t)}function lm(e,o){return Math.min(o,(e.offset??0)+1)}function fm(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??pr.DEFAULT_SEARCH_COUNT))}var xe=require("react/jsx-runtime");function ru(e){let o=P(),[t,r]=(0,We.useState)(!1),[a,n]=(0,We.useState)(),{query:l,fields:s}=e,[f,i]=(0,We.useState)(),[u,d]=(0,We.useState)({}),c=(0,We.useRef)();c.current=f;let x=(0,We.useRef)({});x.current=u,(0,We.useEffect)(()=>{n(void 0),o.graphql(l).then(i).catch(M=>n((0,tu.normalizeOperationOutcome)(M)))},[o,l]);function C(M,Z){M.stopPropagation();let L=M.target.checked,de={...x.current};L?de[Z]=!0:delete de[Z],d(de)}function g(M){M.stopPropagation();let b=M.target.checked,L={},de=c.current?.data.ResourceList;b&&de&&de.forEach(ye=>{ye.id&&(L[ye.id]=!0)}),d(L)}function D(){let M=c.current?.data.ResourceList;if(!M||M.length===0)return!1;for(let Z of M)if(Z.id&&!x.current[Z.id])return!1;return!0}function B(M,Z){Aa(M.target)||(N(M),M.button!==1&&e.onClick&&e.onClick(new ut(Z,M)),M.button===1&&e.onAuxClick&&e.onAuxClick(new ut(Z,M)))}if((0,We.useEffect)(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return(0,xe.jsx)(xr.Loader,{});let T=e.checkboxesEnabled;return(0,xe.jsxs)("div",{onContextMenu:M=>N(M),"data-testid":"search-control",children:[(0,xe.jsxs)(xr.Table,{children:[(0,xe.jsx)("thead",{children:(0,xe.jsxs)("tr",{children:[T&&(0,xe.jsx)("th",{children:(0,xe.jsx)("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:D(),onChange:M=>g(M)})}),s.map(M=>(0,xe.jsx)("th",{children:M.name},M.name))]})}),(0,xe.jsx)("tbody",{children:f?.data.ResourceList.map(M=>M&&(0,xe.jsxs)("tr",{"data-testid":"search-control-row",onClick:Z=>B(Z,M),onAuxClick:Z=>B(Z,M),children:[T&&(0,xe.jsx)("td",{children:(0,xe.jsx)("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${M.id}`,checked:!!u[M.id],onChange:Z=>C(Z,M.id)})}),s.map(Z=>(0,xe.jsx)("td",{children:(0,xe.jsx)(Wi,{propertyType:Z.propertyType,path:Z.fhirPath,resource:M})},Z.name))]},M.id))})]}),f?.data.ResourceList.length===0&&(0,xe.jsx)("div",{"data-testid":"empty-search",children:"No results"}),a&&(0,xe.jsx)("div",{"data-testid":"search-error",children:(0,xe.jsx)("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&(0,xe.jsx)(xr.Button,{onClick:()=>e.onBulk(Object.keys(x.current)),children:"Bulk..."})]})}var sm=(0,We.memo)(ru);var Xo=require("react/jsx-runtime");function Jo(e){return(0,Xo.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[(0,Xo.jsx)("title",{children:"Medplum Logo"}),(0,Xo.jsx)("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),(0,Xo.jsx)("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"}),(0,Xo.jsx)("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"}),(0,Xo.jsx)("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),(0,Xo.jsx)("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}var Rn=require("@mantine/core");var re=require("@mantine/core"),Tf=require("@medplum/core");var J=require("react/jsx-runtime");function au(e){let{group:o}=e;return(0,J.jsx)(re.Paper,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:(0,J.jsxs)(re.Group,{children:[o.measureScore&&(0,J.jsx)(um,{group:o}),!o.measureScore&&(0,J.jsx)(im,{group:o})]})})}function nu(e){let{measure:o}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(re.Text,{fz:"md",fw:500,mb:8,children:o.title}),(0,J.jsx)(re.Text,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function im(e){let{group:o}=e,t=o.population,r=t?.find(f=>(0,Tf.formatCodeableConcept)(f.code)==="numerator"),a=t?.find(f=>(0,Tf.formatCodeableConcept)(f.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return(0,J.jsxs)(re.Box,{children:[(0,J.jsx)(re.Title,{order:3,children:"Not Applicable"}),(0,J.jsx)(re.Text,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return(0,J.jsxs)(re.Box,{children:[(0,J.jsx)(re.Title,{order:3,children:"Insufficient Data"}),(0,J.jsx)(re.Text,{children:`Numerator: ${n}`}),(0,J.jsx)(re.Text,{children:`Denominator: ${l}`})]});let s=n/l*100;return(0,J.jsx)(re.RingProgress,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:lu(s)}],label:(0,J.jsx)(re.Flex,{justify:"center",children:(0,J.jsxs)(re.Text,{fw:700,fz:18,children:[n," / ",l]})})})}function um(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return(0,J.jsx)(J.Fragment,{children:t==="%"?(0,J.jsx)(re.RingProgress,{size:120,thickness:12,roundCaps:!0,sections:[{value:cm(o),color:lu(o?.measureScore?.value??0)}],label:(0,J.jsx)(re.Flex,{justify:"center",children:(0,J.jsx)(re.Text,{fw:700,fz:18,children:(0,J.jsx)(wo,{value:o.measureScore})})})}):(0,J.jsx)(re.Flex,{h:120,align:"center",children:(0,J.jsx)(re.Title,{order:3,children:(0,J.jsx)(wo,{value:o.measureScore})})})})}function cm(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function lu(e){return e<=33?"red":e<=67?"yellow":"green"}var Ir=require("react/jsx-runtime");function dm(e){let o=K(e.measureReport),[t]=Gn("Measure",{url:o?.measure});return o?(0,Ir.jsxs)(Rn.Box,{children:[t&&(0,Ir.jsx)(nu,{measure:t}),(0,Ir.jsx)(Rn.SimpleGrid,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>(0,Ir.jsx)(au,{group:r},r.id??a))})]}):null}var fu=require("@mantine/core"),su=require("@medplum/core");var bn=require("react/jsx-runtime");function Lt(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:(0,bn.jsx)(fu.Alert,{icon:(0,bn.jsx)(Ct,{size:16}),color:"red",children:o.map(t=>(0,bn.jsx)("div",{"data-testid":"text-field-error",children:(0,su.operationOutcomeIssueToString)(t)},t.details?.text))})}var aa=require("@medplum/core"),iu=require("react");var uu=require("react/jsx-runtime");function mm(e){let o=(0,iu.useCallback)((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(0,uu.jsx)(Go,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:(0,aa.createReference)(t),sender:(0,aa.createReference)(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:(0,aa.createReference)(t),operator:(0,aa.createReference)(r),issued:new Date().toISOString(),content:a})})}var we=require("@mantine/core"),cu=require("@medplum/core");var ro=require("react");var V=require("react/jsx-runtime"),du=(0,we.createStyles)(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 pm(e){let o=P(),t=K(e.value),[r,a]=(0,ro.useState)(!1),[n,l]=(0,ro.useState)(),[s,f]=(0,ro.useState)(),[i,u]=(0,ro.useState)();function d(){f(void 0)}function c(){l(void 0)}let x=(0,ro.useRef)();if(x.current=i,(0,ro.useEffect)(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),(0,ro.useEffect)(()=>(u(ym(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(g,D){u({...x.current,[g]:D})}return(0,V.jsx)("div",{children:(0,V.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[(0,V.jsx)(we.TextInput,{label:"Plan Title",defaultValue:i.title,onChange:g=>C("title",g.currentTarget.value)}),(0,V.jsx)(mu,{actions:i.action||[],selectedKey:n,setSelectedKey:l,hoverKey:s,setHoverKey:f,onChange:g=>C("action",g)}),(0,V.jsx)(we.Button,{type:"submit",children:"Save"})]})})}function mu(e){let{classes:o}=du(),t=(0,ro.useRef)();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(0,V.jsxs)("div",{className:o.section,children:[e.actions.map(l=>(0,V.jsx)("div",{children:(0,V.jsx)(xm,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),(0,V.jsx)("div",{className:o.bottomActions,children:(0,V.jsx)(we.Anchor,{href:"#",onClick:l=>{N(l),a({id:xu()})},children:"Add action"})})]})}function xm(e){let{classes:o,cx:t}=du(),{action:r}=e,a=Cm(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){N(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return(0,V.jsxs)("div",{"data-testid":r.id,className:i,onClick:s,onMouseOver:f,children:[n?(0,V.jsx)(gm,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):(0,V.jsx)(Im,{action:r,actionType:a}),(0,V.jsx)("div",{className:o.bottomActions,children:(0,V.jsx)(we.Anchor,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Af={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function Im(e){let{action:o,actionType:t}=e,[r,a]=pu(o);return(0,V.jsxs)("div",{children:[(0,V.jsxs)("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&(0,V.jsx)("div",{children:(0,V.jsx)(Yo,{value:{reference:o.definitionCanonical}})}),r&&(0,V.jsx)("div",{children:(0,V.jsx)(Pe,{property:Af,propertyType:a,value:r})})]})}function gm(e){let{action:o}=e,[t,r]=(0,ro.useState)(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return(0,V.jsxs)(we.Stack,{spacing:"xl",children:[(0,V.jsx)(we.TextInput,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),(0,V.jsx)(we.TextInput,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),(0,V.jsx)(we.NativeSelect,{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&&(0,V.jsx)(mu,{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(0,V.jsx)(Pn,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return(0,V.jsx)(Pn,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return(0,V.jsx)(Pn,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return(0,V.jsx)(Pn,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),(0,V.jsx)(He,{title:"Timing",description:"When the action should take place.",children:(0,V.jsx)(hm,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function Pn(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return(0,V.jsx)(_r,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:(0,cu.getReferenceString)(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function hm(e){let o=e.action,t="timing",[r,a]=pu(o);return(0,V.jsx)(Co,{property:Af,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(Vr(o,t,l??t,Af,n))}})}function Cm(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function pu(e){return ho({type:"PlanDefinitionAction",value:e},"timing")}var Bf=1;function xu(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Bf=Math.max(Bf,o+1))}return e}return"id-"+Bf++}function ym(e){return{...e,action:Iu(e.action)}}function Iu(e){if(e)return e.map(o=>({...o,id:xu(o.id),action:Iu(o.action)}))}var G=require("@mantine/core"),kn=require("@medplum/core");var So=require("react");var Ie=require("@mantine/core"),j=require("@medplum/core");var be=require("@medplum/core"),na=(B=>(B.group="group",B.display="display",B.question="question",B.boolean="boolean",B.decimal="decimal",B.integer="integer",B.date="date",B.dateTime="dateTime",B.time="time",B.string="string",B.text="text",B.url="url",B.choice="choice",B.openChoice="open-choice",B.attachment="attachment",B.reference="reference",B.quantity="quantity",B))(na||{});function Mf(e){return e.type==="choice"||e.type==="open-choice"}function Ff(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=gu(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=Sm(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function wf(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>(0,be.formatCoding)(l.valueCoding)===r||l[o]===r),n=(0,be.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function gu(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=gu(t.item,o);if(r)return r}}}function vm(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=(0,be.evalFhirPathTyped)(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function Sm(e,o,t){let r=o||[],a=(0,be.getTypedPropertyValue)({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let s of r){let f=(0,be.getTypedPropertyValue)({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(vm(f,a,i)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function la(e){let o=(0,be.getExtension)(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 fa(e,o){let t=(0,be.deepClone)(e),r=(0,be.getExtension)(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 Of(e){return{resourceType:"QuestionnaireResponse",questionnaire:(0,be.getReferenceString)(e),item:hu(e.item)}}function hu(e){return e?.map(Dn)??[]}function Dn(e){return{id:bm(),linkId:e.linkId,text:e.text,item:hu(e.item),answer:e.initial?.map(Pm)??[]}}var Rm=1;function bm(){return"id-"+Rm++}function Pm(e){return{...e}}function Ef(e){return e.value.display||e.value.reference||(0,be.stringify)(e.value)}function Lf(e){let o=e?.item?.[0];return o&&(0,be.getExtension)(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}var Y=require("react/jsx-runtime");function sa(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=Nf(t,e.index)??(0,j.getTypedPropertyValue)({type:"QuestionnaireItemInitial",value:l},"value");switch(a){case"display":return(0,Y.jsx)("p",{children:e.item.text},e.item.linkId);case"boolean":return(0,Y.jsx)(Nr,{title:e.item.text,htmlFor:e.item.linkId,children:(0,Y.jsx)(Ie.Checkbox,{id:e.item.linkId,name:e.item.linkId,defaultChecked:s?.value,onChange:f=>r({valueBoolean:f.currentTarget.checked})})},e.item.linkId);case"decimal":return(0,Y.jsx)(Ie.TextInput,{type:"number",step:"any",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDecimal:f.currentTarget.valueAsNumber})});case"integer":return(0,Y.jsx)(Ie.TextInput,{type:"number",step:1,id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueInteger:f.currentTarget.valueAsNumber})});case"date":return(0,Y.jsx)(Ie.TextInput,{type:"date",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDate:f.currentTarget.value})});case"dateTime":return(0,Y.jsx)(eo,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueDateTime:f})});case"time":return(0,Y.jsx)(Ie.TextInput,{type:"time",id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueTime:f.currentTarget.value})});case"string":case"url":return(0,Y.jsx)(Ie.TextInput,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"text":return(0,Y.jsx)(Ie.Textarea,{id:n,name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueString:f.currentTarget.value})});case"attachment":return(0,Y.jsx)(Ie.Group,{py:4,children:(0,Y.jsx)(wr,{name:n,defaultValue:s?.value,onChange:f=>r({valueAttachment:f})})});case"reference":return(0,Y.jsx)(At,{name:n,required:o.required,targetTypes:la(o),defaultValue:s?.value,onChange:f=>r({valueReference:f})});case"quantity":return(0,Y.jsx)(qe,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueQuantity:f}),disableWheel:!0});case"choice":case"open-choice":return Mm(o)&&!o.answerValueSet?(0,Y.jsx)(Dm,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)}):(0,Y.jsx)(km,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)});default:return null}}function Dm(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return(0,Y.jsx)(vu,{});let n=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let f of t.answerOption){let i=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:f},"value");l.push(Cu(i))}let s=Nf(a)??n;if(t.repeats){let{propertyName:f,data:i}=Fm(e.item),u=Bm(a);return(0,Y.jsx)(Ie.MultiSelect,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[Cu(n)],onChange:d=>{let c=wf(d,f,t);e.onChangeAnswer(c)}})}return(0,Y.jsx)(Ie.NativeSelect,{id:o,name:o,onChange:f=>{let i=f.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],d=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:u},"value"),c="value"+(0,j.capitalize)(d.type);e.onChangeAnswer({[c]:d.value})},defaultValue:(0,j.formatCoding)(s?.value)||s?.value,data:l})}function km(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?(0,Y.jsx)(vu,{}):t.answerValueSet?(0,Y.jsx)(qr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):(0,Y.jsx)(Tm,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Tm(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=(0,j.getElementDefinition)("QuestionnaireItemAnswerOption","value[x]"),s=(0,j.getTypedPropertyValue)({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}`,g=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:x},"value");s&&(0,j.stringify)(g)===(0,j.stringify)(s)&&(i=C),f.push([C,g])}let u=Nf(n),d=Am(f,u);return(0,Y.jsx)(Ie.Radio.Group,{name:o,value:d??i,onChange:c=>{let x=f.find(C=>C[0]===c);if(x){let C=x[1],g="value"+(0,j.capitalize)(C.type);a({[g]:C.value})}},children:f.map(([c,x])=>(0,Y.jsx)(Ie.Radio,{id:c,value:c,py:4,label:(0,Y.jsx)(Pe,{property:l,propertyType:x.type,value:x.value})},c))})}function vu(){return(0,Y.jsx)(Ie.TextInput,{disabled:!0,placeholder:"No Answers Defined"})}function Su(e){return(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswer",value:e},"value")}function Nf(e,o=0){let t=e.answer;return Su(t?.[o]??{})}function Bm(e){let o=e.answer;return o?o.map(r=>Su(r)).map(r=>(0,j.formatCoding)(r?.value)||r?.value):[]}function Am(e,o){return e.find(t=>(0,j.deepEquals)(t[1].value,o?.value))?.[0]}function Cu(e){if(e)return e.type==="CodeableConcept"?(0,j.formatCodeableConcept)(e.value):e.type==="Coding"?(0,j.formatCoding)(e.value):e.type==="Reference"?Ef(e):e.value.toString()}function Mm(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Fm(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+(0,j.capitalize)(t.type),a=(e.answerOption??[]).map(n=>({value:yu(n,r),label:yu(n,r)}));return{propertyName:r,data:a}}function yu(e,o){return(0,j.formatCoding)(e.valueCoding)||e[o]?.toString()}var S=require("react/jsx-runtime"),wm=(0,G.createStyles)(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 Om(e){let o=P(),t=K(e.questionnaire),[r,a]=(0,So.useState)(!1),[n,l]=(0,So.useState)(),[s,f]=(0,So.useState)(),[i,u]=(0,So.useState)();function d(){u(void 0)}function c(){f(void 0)}(0,So.useEffect)(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),(0,So.useEffect)(()=>(l(Hm(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]);let x=(C,g)=>{l(C),e.autoSave&&!g&&e.onSubmit&&e.onSubmit(C)};return!r||!n?null:(0,S.jsx)("div",{children:(0,S.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[(0,S.jsx)(Ru,{item:n,selectedKey:s,setSelectedKey:f,hoverKey:i,setHoverKey:u,onChange:x}),(0,S.jsx)(G.Button,{type:"submit",children:"Save"})]})})}function Ru(e){let{classes:o,cx:t}=wm(),r=e.item,a=e.item,n=(0,kn.isResource)(e.item),l=n||a.type==="group",s=a.linkId??"[untitled]",f=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=(0,So.useRef)();u.current=e.item;function d(b){N(b),e.setSelectedKey(e.item.id)}function c(b){N(b),e.setHoverKey(e.item.id)}function x(b){let L=u.current;e.onChange({...L,item:L.item?.map(de=>de.id===b.id?b:de)})}function C(b,L){e.onChange({...e.item,item:[...e.item.item??[],b]},L)}function g(b){e.onChange({...e.item,item:e.item.item?.filter(L=>L!==b)})}function D(b,L){e.onChange({...u.current,[b]:L})}function B(b){e.onChange({...e.item,...b})}function T(b){e.onChange({...e.item,item:e.item.item?.map(L=>L===b?{...L,repeats:!L.repeats}:L)})}function M(b,L){let de=Gm(e.item.item,b,L);e.onChange({...e.item,item:de})}let Z=t(o.section,{[o.editing]:f,[o.hovering]:i&&!f});return(0,S.jsxs)("div",{"data-testid":a.linkId,className:Z,onClick:d,onMouseOver:c,children:[(0,S.jsx)("div",{className:o.questionBody,children:f?(0,S.jsxs)(S.Fragment,{children:[n&&(0,S.jsx)(G.TextInput,{size:"xl",defaultValue:r.title,onBlur:b=>D("title",b.currentTarget.value)}),!n&&(0,S.jsx)(G.Textarea,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:b=>D("text",b.currentTarget.value)}),a.type==="reference"&&(0,S.jsx)(Nm,{item:a,onChange:B}),Mf(a)&&(0,S.jsx)(Em,{item:a,onChange:b=>B(b)})]}):(0,S.jsxs)(S.Fragment,{children:[r.title&&(0,S.jsx)(G.Title,{children:r.title}),a.text&&(0,S.jsx)("div",{children:a.text}),!l&&(0,S.jsx)(sa,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((b,L)=>(0,S.jsx)("div",{children:(0,S.jsx)(Ru,{item:b,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:L===0,isLast:L===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:x,onRemove:()=>g(b),onRepeatable:T,onMoveUp:()=>M(L,-1),onMoveDown:()=>M(L,1)})},b.id)),!l&&(0,S.jsx)("div",{className:o.topActions,children:f?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(G.TextInput,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:b=>D("linkId",b.currentTarget.value)}),!l&&(0,S.jsx)(G.NativeSelect,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:b=>D("type",b.currentTarget.value),data:[{value:"display",label:"Display"},{value:"boolean",label:"Boolean"},{value:"decimal",label:"Decimal"},{value:"integer",label:"Integer"},{value:"date",label:"Date"},{value:"dateTime",label:"Date/Time"},{value:"time",label:"Time"},{value:"string",label:"String"},{value:"text",label:"Text"},{value:"url",label:"URL"},{value:"choice",label:"Choice"},{value:"open-choice",label:"Open Choice"},{value:"attachment",label:"Attachment"},{value:"reference",label:"Reference"},{value:"quantity",label:"Quantity"}]})]}):(0,S.jsx)("div",{children:s})}),!n&&(0,S.jsx)(G.Box,{className:o.movementActions,children:(0,S.jsxs)(G.Box,{className:o.columnAlignment,children:[!e.isFirst&&(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,S.jsx)(Kn,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,S.jsx)($n,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),(0,S.jsxs)("div",{className:o.bottomActions,children:[l&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),C({id:Nt(),linkId:qf("q"),type:"string",text:"Question"})},children:"Add item"}),(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),C({id:Nt(),linkId:qf("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),C(qm(),!0)},children:"Add Page"}),f&&!n&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function Em(e){let o=(0,kn.getElementDefinition)("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return(0,S.jsxs)("div",{children:[e.item.answerValueSet!==void 0?(0,S.jsx)(G.TextInput,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):(0,S.jsx)(Lm,{options:t,property:o,item:e.item,onChange:e.onChange}),(0,S.jsxs)(G.Box,{display:"flex",children:[(0,S.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:Nt()}]})},children:"Add choice"}),(0,S.jsx)(G.Space,{w:"lg"}),(0,S.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Lm(e){return(0,S.jsx)("div",{children:e.options.map(o=>{let[t,r]=ho({type:"QuestionnaireItemAnswerOption",value:o},"value");return(0,S.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[(0,S.jsx)("div",{children:(0,S.jsx)(Co,{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)}),(0,S.jsx)("div",{children:(0,S.jsx)(G.Anchor,{href:"#",onClick:a=>{N(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Nm(e){let o=la(e.item)??[];return(0,S.jsxs)(S.Fragment,{children:[o.map((t,r)=>(0,S.jsxs)(G.Group,{children:[(0,S.jsx)(Jt,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(fa(e.item,o.map(n=>n===t?a:n)))}}),(0,S.jsx)(G.Anchor,{href:"#",onClick:a=>{N(a),e.onChange(fa(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),(0,S.jsx)(G.Anchor,{href:"#",onClick:t=>{N(t),e.onChange(fa(e.item,[...o,""]))},children:"Add Resource Type"})]})}var Hf=1,Vf=1;function qf(e){return e+Hf++}function Nt(){return"id-"+Vf++}function Hm(e){return{...e,id:e.id||Nt(),item:bu(e.item)}}function bu(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Vf=Math.max(Vf,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(Hf=Math.max(Hf,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||Nt(),item:bu(o.item),answerOption:Vm(o.answerOption)}))}function Vm(e){if(e)return e.map(o=>({...o,id:o.id||Nt()}))}function qm(){return{id:Nt(),linkId:qf("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 Gm(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}var Au=require("@mantine/core"),Bn=require("@medplum/core");var Vt=require("react");var io=require("@mantine/core");var Pu=require("@mantine/core"),Du=require("react");var Ht=require("react/jsx-runtime");function Tn(e){let{item:o,response:t,onChange:r}=e,[a,n]=(0,Du.useState)(Um(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return(0,Ht.jsx)("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?(0,Ht.jsx)(sa,{item:o,response:t,onChange:s=>r([s]),index:0},o.linkId):(0,Ht.jsxs)(He,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((s,f)=>(0,Ht.jsx)(sa,{item:o,response:t,onChange:i=>r([i]),index:f},`${o.linkId}-${f}`)),l&&(0,Ht.jsx)(Pu.Anchor,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function Um(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}var gr=require("@mantine/core"),ku=require("react");var Xe=require("react/jsx-runtime");function Gf(e){let[o,t]=(0,ku.useState)(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=Dn(e.item);t([...o,n])}return(0,Xe.jsxs)(Xe.Fragment,{children:[o.map((n,l)=>(0,Xe.jsx)(Tu,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,l)},n.id)),e.item.repeats&&(0,Xe.jsx)(gr.Anchor,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function Tu(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)?(0,Xe.jsxs)("div",{children:[e.item.text&&(0,Xe.jsx)(gr.Title,{order:3,mb:"md",children:e.item.text}),(0,Xe.jsx)(gr.Stack,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?(0,Xe.jsx)(Gf,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):(0,Xe.jsx)(Tu,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):(0,Xe.jsx)(Tn,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}var Oe=require("react/jsx-runtime");function Bu(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(g=>g.linkId===c.linkId)??[],C=c.type==="group"?(0,Oe.jsx)(Gf,{item:c,response:x,onChange:a,checkForQuestionEnabled:u},c.linkId):(0,Oe.jsx)(Tn,{item:c,response:x?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return f?(0,Oe.jsx)(io.Stepper.Step,{label:c.text,children:C},c.linkId):C});return(0,Oe.jsxs)(Oe.Fragment,{children:[f&&(0,Oe.jsx)(io.Stepper,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!f&&(0,Oe.jsx)(io.Stack,{children:d}),(0,Oe.jsx)(Qm,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:l,submitButtonText:i})]})}function Qm(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return(0,Oe.jsxs)(io.Group,{position:"right",mt:"xl",spacing:"xs",children:[o&&(0,Oe.jsx)(io.Button,{onClick:e.prevStep,children:"Back"}),t&&(0,Oe.jsx)(io.Button,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&(0,Oe.jsx)(io.Button,{type:"submit",children:e.submitButtonText??"Submit"})]})}var ia=require("react/jsx-runtime");function Uf(e){let o=P(),t=o.getProfile(),[r,a]=(0,Vt.useState)(!1),n=K(e.questionnaire),[l,s]=(0,Vt.useState)(),[f,i]=(0,Vt.useState)(0);(0,Vt.useEffect)(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),(0,Vt.useEffect)(()=>{s(n?Of(n):void 0)},[n]);function u(g){let D=l?.item??[],T={resourceType:"QuestionnaireResponse",item:Mu(D,Array.isArray(g)?g:[g])};s(T)}function d(g){return Ff(g,l?.item??[])}if(!r||!n)return null;let c=Lf(n),x=()=>i(g=>g+1),C=()=>i(g=>g-1);return(0,ia.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:(0,Bn.getReferenceString)(n),subject:e.subject,source:(0,Bn.createReference)(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&(0,ia.jsx)(Au.Title,{children:n.title}),(0,ia.jsx)(Bu,{items:n.item??[],response:l,onChange:u,renderPages:c>1,activePage:f,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:x,prevStep:C})]})}function zm(e,o){let t=Mu(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 Mu(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(zm(a,l)),r.add(l.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}var $=require("@mantine/core"),ua=require("@medplum/core");var hr=require("react");var z=require("react/jsx-runtime"),Wm=(0,$.createStyles)(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"}})),Xm=["gender","age","gestationalAge","context","appliesTo","category"],Jm={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function $m(e){e=Object.assign(Jm,e);let o=e.definition,[t,r]=(0,hr.useState)([]),[a,n]=(0,hr.useState)(1),[l,s]=(0,hr.useState)(1);return(0,hr.useEffect)(()=>{let C=_m(o,s);r(Zm(C.qualifiedInterval||[],n))},[o]),(0,z.jsxs)(oe,{testid:"reference-range-editor",onSubmit:f,children:[(0,z.jsx)($.Stack,{children:t.map(C=>(0,z.jsx)(Fu,{unit:jm(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:x,onRemoveGroup:u,intervalGroup:C},`group-${C.id}`))}),(0,z.jsx)($.ActionIcon,{title:"Add Group",size:"sm",onClick:C=>{N(C),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(g=>g+1)},children:(0,z.jsx)(Ut,{})}),(0,z.jsx)($.Group,{position:"right",children:(0,z.jsx)($.Button,{type:"submit",children:"Save"})})]});function f(){let C=t.flatMap(g=>g.intervals).filter(g=>!ep(g));e.onSubmit({...o,qualifiedInterval:C})}function i(C){r(g=>[...g,C])}function u(C){r(g=>g.filter(D=>D.id!==C.id))}function d(C,g){r(D=>{D=[...D];let B=D.find(M=>M.id===C),T=B?.intervals.findIndex(M=>M.id===g.id);return T!==void 0&&B?.intervals[T]&&(B.intervals[T]=g),D})}function c(C,g){g.id===void 0&&(g.id=`id-${l}`,s(D=>D+1)),r(D=>{D=[...D];let B=D.findIndex(T=>T.id===C);if(B!==-1){let T={...D[B]};g={...g,...T.filters},T.intervals=[...T.intervals,g],D[B]=T}return D})}function x(C,g){r(D=>{D=[...D];let B=D.find(T=>T.id===C);return B&&(B.intervals=B.intervals.filter(T=>T.id!==g.id)),D})}}function Fu(e){let{intervalGroup:o,unit:t}=e,{classes:r}=Wm();return(0,z.jsx)(No,{"data-testid":o.id,className:r.section,children:(0,z.jsxs)($.Stack,{spacing:"lg",children:[(0,z.jsx)($.Group,{position:"right",children:(0,z.jsx)($.ActionIcon,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{N(a),e.onRemoveGroup(o)},children:(0,z.jsx)(Ko,{})},`remove-group-button-${o.id}`)}),(0,z.jsx)(Km,{intervalGroup:o,onChange:e.onChange}),(0,z.jsx)($.Divider,{}),o.intervals.map(a=>(0,z.jsxs)($.Stack,{spacing:"xs",children:[(0,z.jsxs)($.Group,{children:[(0,z.jsx)($.TextInput,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{N(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),(0,z.jsx)($.ActionIcon,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{N(n),e.onRemove(o.id,a)},children:(0,z.jsx)(Ko,{})},`remove-interval-${a.id}`)]}),(0,z.jsx)(tr,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),(0,z.jsx)($.ActionIcon,{title:"Add Interval",size:"sm",onClick:a=>{N(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:(0,z.jsx)(Ut,{})})]})})}function Km(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(0,z.jsxs)($.Stack,{style:{maxWidth:"50%"},children:[(0,z.jsx)($.Group,{children:(0,z.jsx)($.NativeSelect,{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})}}})}),(0,z.jsxs)($.Group,{spacing:"xs",children:[(0,z.jsx)($.Text,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),(0,z.jsx)("div",{id:`div-age-${o.id}`,children:(0,z.jsx)(tr,{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}`)})]}),(0,z.jsx)($.NativeSelect,{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"}]}})}}}),(0,z.jsx)($.NativeSelect,{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 _m(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 Zm(e,o){let t=1,r={};for(let a of e){let n=Ym(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(Xm.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function Ym(e){return[`gender=${e.gender}`,`age=${(0,ua.formatRange)(e.age)}`,`gestationalAge=${(0,ua.formatRange)(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function jm(e){return e&&((0,ua.getCodeBySystem)(e,"http://unitsofmeasure.org")||e.text)}function ep(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}var Ro=require("@mantine/core"),An=require("@medplum/core");var qt=require("react");var ke=require("react/jsx-runtime");function op(e){let o=P(),t=K(e.value),[r,a]=(0,qt.useState)(!1),[n,l]=(0,qt.useState)();if((0,qt.useEffect)(()=>{t&&!r&&(o.executeBatch(s(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return(0,ke.jsx)(Ro.Grid,{children:t.action?.map((i,u)=>{let d=i.resource&&f(i.resource),c=d?.input?.[0]?.valueReference,x=d?.output?.[0]?.valueReference;return(0,ke.jsxs)(qt.Fragment,{children:[(0,ke.jsx)(Ro.Grid.Col,{span:1,p:"md",children:d?.status==="completed"?(0,ke.jsx)(tl,{}):(0,ke.jsx)(Cl,{color:"gray"})}),(0,ke.jsxs)(Ro.Grid.Col,{span:9,p:"xs",children:[(0,ke.jsx)(Ro.Text,{weight:500,children:i.title}),i.description&&(0,ke.jsx)("div",{children:i.description}),(0,ke.jsxs)("div",{children:["Last edited by\xA0",(0,ke.jsx)(lo,{value:d?.meta?.author}),"\xA0on\xA0",(0,An.formatDateTime)(d?.meta?.lastUpdated)]}),(0,ke.jsxs)("div",{children:["Status: ",(0,ke.jsx)(jr,{status:d?.status||"unknown"})]})]}),(0,ke.jsxs)(Ro.Grid.Col,{span:2,p:"md",children:[c&&!x&&(0,ke.jsx)(Ro.Button,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&x&&(0,ke.jsx)(Ro.Button,{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===(0,An.getReferenceString)(u.resource))return u.resource}}var Nu=require("@mantine/core");var Fn=require("react");var wu=require("@medplum/core");function Mn(e,o){let t=tp(e,o);return rp(t,e,o)}function tp(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],g,D=0;i===-f||i!==f&&C.i<x.i?(D=x.i,g=x):(D=C.i+1,g=C),s[c]=void 0;let B=D-i,T={i:D,j:B,prev:ap(g),snake:!1};for(;D<t&&B<r&&e[D]===o[B];)D++,B++;if(D>T.i&&(T={i:D,j:B,prev:T,snake:!0}),s[u]=T,D>=t&&B>=r)return s[u]}s[l+f-1]=void 0}}function rp(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 ap(e){return e&&!e.snake&&e.prev?e.prev:e}function Ou(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:(0,wu.stringify)(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 np(t,o),lp(t),t}function np(e,o){for(let t=1;t<o.length;t++){let r=Mn(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 lp(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 Eu(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Lu(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Cr(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Cr(r,"month");let a=Math.floor(o/86400);if(a>0)return Cr(a,"day");let n=Math.floor(o/3600);if(n>0)return Cr(n,"hour");let l=Math.floor(o/60);return l>0?Cr(l,"minute"):Cr(o,"second")}function Cr(e,o){return`${e} ${e===1?o:o+"s"} ago`}var Te=require("react/jsx-runtime"),fp=(0,Nu.createStyles)(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 sp(e){let{classes:o}=fp(),t=P(),[r,a]=(0,Fn.useState)(e.history);if((0,Fn.useEffect)(()=>{!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(0,Te.jsx)("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Ou(r);return(0,Te.jsx)("div",{className:o.container,children:(0,Te.jsx)("table",{className:o.root,children:(0,Te.jsx)("tbody",{children:l.map((s,f)=>(0,Te.jsxs)("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&(0,Te.jsxs)(Te.Fragment,{children:[(0,Te.jsx)("td",{className:o.author,rowSpan:s.span,children:(0,Te.jsx)(Ho,{value:s.meta.author,link:!0})}),(0,Te.jsx)("td",{className:o.dateTime,rowSpan:s.span,children:(0,Te.jsx)(Se,{to:Eu(n,s.meta.versionId),children:Lu(s.meta.lastUpdated)})})]}),(0,Te.jsx)("td",{className:o.lineNumber,children:f+1}),(0,Te.jsx)("td",{className:o.line,children:(0,Te.jsx)("pre",{className:o.pre,children:s.value})})]},"row-"+f))})})})}var Hu=require("@mantine/core"),Qf=require("@medplum/core");var uo=require("react/jsx-runtime"),ip=(0,Hu.createStyles)(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function up(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=(0,Qf.stringify)(o,!0).match(/[^\r\n]+/g),a=(0,Qf.stringify)(t,!0).match(/[^\r\n]+/g),n=Mn(r,a);return(0,uo.jsx)("pre",{style:{color:"gray"},children:n.map((l,s)=>(0,uo.jsx)(cp,{delta:l},"delta"+s))})}function cp(e){let{classes:o}=ip();return(0,uo.jsxs)(uo.Fragment,{children:["...",(0,uo.jsx)("br",{}),e.delta.original.lines.length>0&&(0,uo.jsx)("div",{className:o.removed,children:e.delta.original.lines.join(`
66
- `)}),e.delta.revised.lines.length>0&&(0,uo.jsx)("div",{className:o.added,children:e.delta.revised.lines.join(`
67
- `)}),"...",(0,uo.jsx)("br",{})]})}var bo=require("@mantine/core"),Vu=require("@medplum/core");var ca=require("react");var Je=require("react/jsx-runtime");function dp(e){let o=P(),t=K(e.defaultValue),[r,a]=(0,ca.useState)(!1),[n,l]=(0,ca.useState)();return(0,ca.useEffect)(()=>{t&&(l((0,Vu.deepClone)(t)),o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log))},[o,t]),!r||!n?(0,Je.jsx)("div",{children:"Loading..."}):(0,Je.jsxs)("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(n)},children:[(0,Je.jsxs)(bo.Stack,{mb:"xl",children:[(0,Je.jsx)(He,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:(0,Je.jsx)(bo.TextInput,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),(0,Je.jsx)(He,{title:"ID",htmlFor:"id",outcome:e.outcome,children:(0,Je.jsx)(bo.TextInput,{name:"id",defaultValue:n.id,disabled:!0})})]}),(0,Je.jsx)(ar,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:l}),(0,Je.jsxs)(bo.Group,{position:"right",mt:"xl",children:[(0,Je.jsx)(bo.Button,{type:"submit",children:"OK"}),e.onDelete&&(0,Je.jsx)(bo.Button,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}var qu=require("@mantine/core"),wn=require("@medplum/core");var On=require("react");var Ce=require("react/jsx-runtime");function mp(e){let o=P(),[t,r]=(0,On.useState)(e.history);return(0,On.useEffect)(()=>{!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?(0,Ce.jsxs)(qu.Table,{withBorder:!0,withColumnBorders:!0,children:[(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("th",{children:"Author"}),(0,Ce.jsx)("th",{children:"Date"}),(0,Ce.jsx)("th",{children:"Version"})]})}),(0,Ce.jsx)("tbody",{children:t.entry?.map((a,n)=>(0,Ce.jsx)(pp,{entry:a},"entry-"+n))})]}):(0,Ce.jsx)("div",{children:"Loading..."})}function pp(e){let{response:o,resource:t}=e.entry;return t?(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("td",{children:(0,Ce.jsx)(Ho,{value:t.meta?.author,link:!0})}),(0,Ce.jsx)("td",{children:(0,wn.formatDateTime)(t.meta?.lastUpdated)}),(0,Ce.jsx)("td",{children:(0,Ce.jsx)(Se,{to:xp(t),children:t.meta?.versionId})})]}):(0,Ce.jsx)("tr",{children:(0,Ce.jsx)("td",{colSpan:3,children:(0,wn.normalizeErrorString)(o?.outcome)})})}function xp(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}var ct=require("@mantine/core"),En=require("@medplum/core");var da=require("react");var se=require("react/jsx-runtime"),Ip=(0,ct.createStyles)(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function gp(e){let{classes:o}=Ip(),t=K(e.schedule),r=K(e.questionnaire),[a,n]=(0,da.useState)(nn()),[l,s]=(0,da.useState)(),[f,i]=(0,da.useState)(),[u,d]=(0,da.useState)(),[c]=Un("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",(0,En.isReference)(e.schedule)?e.schedule.reference:(0,En.getReferenceString)(e.schedule)],["start","gt"+hp(a)],["start","lt"+Cp(a)]]));if(!t||!c||!r)return null;let x=t.actor?.[0];return(0,se.jsxs)("div",{className:o.container,"data-testid":"scheduler",children:[(0,se.jsxs)("div",{className:o.info,children:[x&&(0,se.jsx)(Me,{value:x,size:"xl"}),x&&(0,se.jsx)(ct.Text,{size:"xl",weight:500,children:(0,se.jsx)(lo,{value:x})}),(0,se.jsx)("p",{children:"1 hour"}),l&&(0,se.jsx)("p",{children:l.toLocaleDateString()}),f&&(0,se.jsx)("p",{children:Gu(new Date(f.start))})]}),(0,se.jsxs)("div",{className:o.selection,children:[!l&&(0,se.jsxs)("div",{children:[(0,se.jsx)("h3",{children:"Select date"}),(0,se.jsx)(of,{slots:c,onChangeMonth:n,onClick:s})]}),l&&!f&&(0,se.jsxs)("div",{children:[(0,se.jsx)("h3",{children:"Select time"}),(0,se.jsx)(ct.Stack,{children:c.map(C=>{let g=new Date(C.start);return g.getTime()>l.getTime()&&g.getTime()<l.getTime()+24*3600*1e3&&(0,se.jsx)("div",{children:(0,se.jsx)(ct.Button,{variant:"outline",style:{width:150},onClick:()=>i(C),children:Gu(g)})},C.id)})})]}),l&&f&&!u&&(0,se.jsx)(Uf,{questionnaire:r,submitButtonText:"Next",onSubmit:d}),l&&f&&u&&(0,se.jsxs)("div",{children:[(0,se.jsx)("h3",{children:"You're all set!"}),(0,se.jsx)("p",{children:"Check your email for a calendar invite."})]})]})]})}function hp(e){return Uu(e.getTime())}function Cp(e){return Uu(e.getTime()+31*24*60*60*1e3)}function Uu(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Gu(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}var ma=require("@medplum/core");var Qu=require("react/jsx-runtime");function yp(e){return(0,Qu.jsx)(Go,{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:[(0,ma.createReference)(o)],subject:o.subject,sender:(0,ma.createReference)(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[(0,ma.createReference)(o)],subject:o.subject,operator:(0,ma.createReference)(t),issued:new Date().toISOString(),content:r})})}var $u=require("@medplum/core");var xa=require("react");var Be=require("@mantine/core"),zu=require("@medplum/core"),Wu=require("react");var $e=require("react/jsx-runtime");function Ln(e){let o=P(),[t,r]=(0,Wu.useState)();return(0,$e.jsxs)(oe,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r((0,zu.normalizeOperationOutcome)(n))}},children:[(0,$e.jsxs)(Be.Center,{sx:{flexDirection:"column"},children:[(0,$e.jsx)(Jo,{size:32}),(0,$e.jsx)(Be.Title,{children:"Create project"})]}),(0,$e.jsxs)(Be.Stack,{spacing:"xl",children:[(0,$e.jsx)(Be.TextInput,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:De(t,"firstName")}),(0,$e.jsxs)(Be.Text,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",(0,$e.jsx)(Be.Anchor,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,$e.jsx)(Be.Anchor,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),(0,$e.jsx)(Be.Group,{position:"right",mt:"xl",noWrap:!0,children:(0,$e.jsx)(Be.Button,{type:"submit",children:"Create project"})})]})}var ee=require("@mantine/core"),Xf=require("@medplum/core");var Vn=require("react");var dt=require("react");function pa(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)}var Xu=require("react/jsx-runtime");function Nn(e){let o=P(),{googleClientId:t,handleGoogleCredential:r}=e,a=(0,dt.useRef)(null),[n,l]=(0,dt.useState)(typeof google<"u"),[s,f]=(0,dt.useState)(!1),[i,u]=(0,dt.useState)(!1);return(0,dt.useEffect)(()=>{if(typeof google>"u"){pa("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?(0,Xu.jsx)("div",{ref:a}):null}function Hn(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 zf(e){typeof grecaptcha>"u"&&pa("https://www.google.com/recaptcha/api.js?render="+e)}function Wf(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}var le=require("react/jsx-runtime");function Ju(e){let o=Hn(e.googleClientId),t=e.recaptchaSiteKey,r=P(),[a,n]=(0,Vn.useState)(),l=Hr(a,void 0);return(0,Vn.useEffect)(()=>{t&&zf(t)},[t]),(0,le.jsxs)(oe,{style:{maxWidth:400},onSubmit:async s=>{try{let f="";t&&(f=await Wf(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((0,Xf.normalizeOperationOutcome)(f))}},children:[(0,le.jsx)(ee.Center,{sx:{flexDirection:"column"},children:e.children}),(0,le.jsx)(Lt,{issues:l}),o&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ee.Group,{position:"center",p:"xl",style:{height:70},children:(0,le.jsx)(Nn,{googleClientId:o,handleGoogleCredential:async s=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:s.clientId,googleCredential:s.credential,createUser:!0}))}catch(f){n((0,Xf.normalizeOperationOutcome)(f))}}})}),(0,le.jsx)(ee.Divider,{label:"or",labelPosition:"center",my:"lg"})]}),(0,le.jsxs)(ee.Stack,{spacing:"xl",children:[(0,le.jsx)(ee.TextInput,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:De(a,"firstName")}),(0,le.jsx)(ee.TextInput,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:De(a,"lastName")}),(0,le.jsx)(ee.TextInput,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:De(a,"email")}),(0,le.jsx)(ee.PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,error:De(a,"password")}),(0,le.jsxs)(ee.Text,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",(0,le.jsx)(ee.Anchor,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,le.jsx)(ee.Anchor,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),(0,le.jsxs)(ee.Text,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",(0,le.jsx)(ee.Anchor,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,le.jsx)(ee.Anchor,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),(0,le.jsxs)(ee.Group,{position:"apart",mt:"xl",noWrap:!0,children:[(0,le.jsx)(ee.Checkbox,{name:"remember",label:"Remember me",size:"xs"}),(0,le.jsx)(ee.Button,{type:"submit",children:"Create account"})]})]})}var yr=require("react/jsx-runtime");function vp(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,s=P(),[f,i]=(0,xa.useState)(),[u,d]=(0,xa.useState)();(0,xa.useEffect)(()=>{o==="patient"&&f&&s.startNewPatient({login:f,projectId:t}).then(x=>s.processCode(x.code)).then(()=>l()).catch(x=>d((0,$u.normalizeOperationOutcome)(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(0,yr.jsxs)(ea,{width:450,children:[u&&(0,yr.jsx)("pre",{children:JSON.stringify(u,null,2)}),!f&&(0,yr.jsx)(Ju,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:c,children:e.children}),f&&o==="project"&&(0,yr.jsx)(Ln,{login:f,handleAuthResponse:c})]})}var Jf=require("@mantine/notifications"),$f=require("@medplum/core");var Po=require("react");var ie=require("@mantine/core"),Ku=require("@medplum/core");var mt=require("react");var ae=require("react/jsx-runtime");function _u(e){let[o,t]=(0,mt.useState)();return o?(0,ae.jsx)(Rp,{email:o,...e}):(0,ae.jsx)(Sp,{setEmail:t,...e})}function Sp(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,s=P(),f=!e.disableGoogleAuth&&Hn(e.googleClientId),i=(0,mt.useCallback)(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=(0,mt.useCallback)(async c=>{let x=await s.post("auth/method",{email:c.email});await i(x)||o(c.email)},[s,i,o]),d=(0,mt.useCallback)(async c=>{let x=await s.startGoogleLogin({...l,googleCredential:c.credential});await i(x)||r(x)},[s,l,i,r]);return(0,ae.jsxs)(oe,{style:{maxWidth:400},onSubmit:u,children:[(0,ae.jsx)(ie.Center,{sx:{flexDirection:"column"},children:a}),f&&(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)(ie.Group,{position:"center",p:"xl",style:{height:70},children:(0,ae.jsx)(Nn,{googleClientId:f,handleGoogleCredential:d})}),!n&&(0,ae.jsx)(ie.Divider,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&(0,ae.jsx)(ie.TextInput,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),(0,ae.jsxs)(ie.Group,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[(0,ae.jsx)("div",{children:t&&(0,ae.jsx)(ie.Anchor,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&(0,ae.jsx)(ie.Button,{type:"submit",children:"Next"})]})]})}function Rp(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=P(),[l,s]=(0,mt.useState)(),f=Hr(l,void 0),i=(0,mt.useCallback)(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(d=>s((0,Ku.normalizeOperationOutcome)(d)))},[n,a,t]);return(0,ae.jsxs)(oe,{style:{maxWidth:400},onSubmit:i,children:[(0,ae.jsx)(ie.Center,{sx:{flexDirection:"column"},children:r}),(0,ae.jsx)(Lt,{issues:f}),(0,ae.jsx)(ie.Stack,{spacing:"xl",children:(0,ae.jsx)(ie.PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:De(l,"password")})}),(0,ae.jsxs)(ie.Group,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&(0,ae.jsx)(ie.Anchor,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),(0,ae.jsx)(ie.Checkbox,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),(0,ae.jsx)(ie.Button,{type:"submit",children:"Sign in"})]})]})}var Ee=require("@mantine/core"),Zu=require("@medplum/core"),Yu=require("react");var Ke=require("react/jsx-runtime");function ju(e){let o=P(),[t,r]=(0,Yu.useState)();return(0,Ke.jsxs)(Ee.Stack,{children:[(0,Ke.jsxs)(Ee.Center,{sx:{flexDirection:"column"},children:[(0,Ke.jsx)(Jo,{size:32}),(0,Ke.jsx)(Ee.Title,{order:3,children:"Choose profile"})]}),(0,Ke.jsx)(Lt,{outcome:t}),e.memberships.map(a=>(0,Ke.jsx)(Ee.UnstyledButton,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r((0,Zu.normalizeOperationOutcome)(n)))},children:(0,Ke.jsxs)(Ee.Group,{children:[(0,Ke.jsx)(Ee.Avatar,{radius:"xl"}),(0,Ke.jsxs)("div",{style:{flex:1},children:[(0,Ke.jsx)(Ee.Text,{size:"sm",weight:500,children:a.profile?.display}),(0,Ke.jsx)(Ee.Text,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}var _e=require("@mantine/core");var co=require("react/jsx-runtime");function ec(e){let o=P();return(0,co.jsx)(oe,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:(0,co.jsxs)(_e.Stack,{children:[(0,co.jsxs)(_e.Center,{sx:{flexDirection:"column"},children:[(0,co.jsx)(Jo,{size:32}),(0,co.jsx)(_e.Title,{children:"Choose scope"})]}),(0,co.jsx)(_e.Stack,{children:(e.scope??"openid").split(" ").map(t=>(0,co.jsx)(_e.Checkbox,{id:t,name:t,label:t,defaultChecked:!0},t))}),(0,co.jsx)(_e.Group,{position:"right",mt:"xl",children:(0,co.jsx)(_e.Button,{type:"submit",children:"Set scope"})})]})})}var Le=require("@mantine/core"),oc=require("@medplum/core");var tc=require("react");var Ze=require("react/jsx-runtime");function rc(e){let o=P(),[t,r]=(0,tc.useState)();return(0,Ze.jsx)(oe,{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((0,oc.normalizeErrorString)(n)))},children:(0,Ze.jsxs)(Le.Stack,{children:[(0,Ze.jsxs)(Le.Center,{sx:{flexDirection:"column"},children:[(0,Ze.jsx)(Jo,{size:32}),(0,Ze.jsx)(Le.Title,{children:"Enter MFA code"})]}),t&&(0,Ze.jsx)(Le.Alert,{icon:(0,Ze.jsx)(Ct,{size:16}),title:"Error",color:"red",children:t}),(0,Ze.jsx)(Le.Stack,{children:(0,Ze.jsx)(Le.TextInput,{name:"token",label:"MFA code",required:!0})}),(0,Ze.jsx)(Le.Group,{position:"right",mt:"xl",children:(0,Ze.jsx)(Le.Button,{type:"submit",children:"Submit code"})})]})})}var pt=require("react/jsx-runtime");function bp(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...s}=e,f=P(),[i,u]=(0,Po.useState)(),[d,c]=(0,Po.useState)(!1),[x,C]=(0,Po.useState)(),g=(0,Po.useCallback)(T=>{l?l(T):f.processCode(T).then(()=>{r&&r()}).catch(M=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(M)}))},[f,l,r]),D=(0,Po.useCallback)(T=>{c(!!T.mfaRequired),T.login&&u(T.login),T.memberships&&C(T.memberships),T.code&&(t?C(void 0):g(T.code))},[t,g]),B=(0,Po.useCallback)(T=>{g(T.code)},[g]);return(0,Po.useEffect)(()=>{o&&!i&&f.get("auth/login/"+o).then(D).catch(T=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(T)}))},[f,o,i,D]),(0,pt.jsx)(ea,{width:450,children:i?d?(0,pt.jsx)(rc,{login:i,handleAuthResponse:D}):x?(0,pt.jsx)(ju,{login:i,memberships:x,handleAuthResponse:D}):e.projectId==="new"?(0,pt.jsx)(Ln,{login:i,handleAuthResponse:D}):e.chooseScopes?(0,pt.jsx)(ec,{login:i,scope:e.scope,handleAuthResponse:B}):(0,pt.jsx)("div",{children:"Success"}):(0,pt.jsx)(_u,{onForgotPassword:a,onRegister:n,handleAuthResponse:D,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children})})}
64
+ }`.replace(/\s+/g," ")}function gd(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),vd(hd(t),o).slice(0,5)}function hd(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 vd(e,o){return e.sort((t,r)=>Qs(r,o)-Qs(t,o))}function Qs(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,zs(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,zs((0,Eo.formatHumanName)(r),o));return t}function zs(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}var Q=require("react/jsx-runtime"),yd=(0,W.createStyles)(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 Vf(e){let o=Jt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:f,cx:s}=yd(),[l,i]=(0,Xs.useState)(!1);return(0,Q.jsx)(W.Header,{height:60,p:8,style:{zIndex:101},children:(0,Q.jsxs)(W.Group,{position:"apart",children:[(0,Q.jsxs)(W.Group,{spacing:"xs",children:[(0,Q.jsx)(W.UnstyledButton,{className:f.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&(0,Q.jsx)(Ws,{pathname:e.pathname,searchParams:e.searchParams})]}),(0,Q.jsxs)(W.Menu,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:l,onClose:()=>i(!1),children:[(0,Q.jsx)(W.Menu.Target,{children:(0,Q.jsx)(W.UnstyledButton,{className:s(f.user,{[f.userActive]:l}),onClick:()=>i(u=>!u),children:(0,Q.jsxs)(W.Group,{spacing:7,children:[(0,Q.jsx)(Fe,{value:r,radius:"xl",size:24}),(0,Q.jsx)(W.Text,{size:"sm",className:f.userName,children:(0,Vr.formatHumanName)(r?.name?.[0])}),(0,Q.jsx)(xf,{size:12,stroke:1.5})]})})}),(0,Q.jsxs)(W.Menu.Dropdown,{children:[(0,Q.jsxs)(W.Stack,{align:"center",p:"xl",children:[(0,Q.jsx)(Fe,{size:"xl",radius:100,value:o.profile}),(0,Q.jsx)(Nr,{value:o.profile?.name?.[0]}),(0,Q.jsx)(W.Text,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&(0,Q.jsx)(W.Menu.Divider,{}),n.map(u=>u.profile.reference!==(0,Vr.getReferenceString)(o.profile)&&(0,Q.jsx)(W.Menu.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:(0,Q.jsxs)(W.Group,{children:[(0,Q.jsx)(W.Avatar,{radius:"xl"}),(0,Q.jsxs)("div",{style:{flex:1},children:[(0,Q.jsx)(W.Text,{size:"sm",weight:500,children:u.profile.display}),(0,Q.jsx)(W.Text,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),(0,Q.jsx)(W.Menu.Divider,{}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(Ff,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(Zt,{size:14,stroke:1.5}),onClick:()=>a(`/${(0,Vr.getReferenceString)(r)}`),children:"Account settings"}),(0,Q.jsx)(W.Menu.Item,{icon:(0,Q.jsx)(bf,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),(0,Q.jsx)(W.Text,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}var He=require("@mantine/core");var Wa=require("react");var oo=require("@mantine/core"),Gf=require("@mantine/notifications"),Qa=require("@medplum/core");function qf(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Cd(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Sd(o,t);return o}function Cd(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Sd(e,o){e[o.name]=o.value}var Js=require("react/jsx-runtime");function oe(e){return(0,Js.jsx)("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=qf(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}var ho=require("react/jsx-runtime");function $s(e){let o=D(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:f}=a,s=`${e.pathname}?${e.searchParams.toString()}`,l=(0,Qa.deepClone)(t);l.menu?.find(({title:u})=>u===n)?.link?.push({name:f,target:s}),o.updateResource(l).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),(0,Gf.showNotification)({color:"green",message:"Success"}),e.onOk()}).catch(u=>{(0,Gf.showNotification)({color:"red",message:(0,Qa.normalizeErrorString)(u)})})}return(0,ho.jsx)(oo.Modal,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:(0,ho.jsx)(oe,{onSubmit:r,children:(0,ho.jsxs)(oo.Stack,{children:[(0,ho.jsx)(Rd,{config:t}),(0,ho.jsx)(oo.TextInput,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),(0,ho.jsx)(oo.Group,{position:"right",children:(0,ho.jsx)(oo.Button,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Rd(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return(0,ho.jsx)(oo.NativeSelect,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}var za=require("react");var Zs=require("react");var _s=require("react");var Ks=require("react/jsx-runtime");function Uf(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function bd(e){return typeof e.display=="string"?e.display:Uf(e)}function Pd(e){return{value:Uf(e),label:bd(e),resource:e}}function Dd(e){return{code:e,display:e}}function Yt(e){let o=D(),{binding:t,creatable:r,clearable:a,...n}=e,f=(0,_s.useCallback)(async(s,l)=>{if(!t)return[];let u=(await o.searchValueSet(t,s,{signal:l})).expansion?.contains,d=[];for(let c of u)c.code&&!d.some(m=>m.code===c.code)&&d.push(c);return d},[o,t]);return(0,Ks.jsx)(Tt,{...n,creatable:r??!0,clearable:a??!0,toKey:Uf,toOption:Pd,loadOptions:f,onCreate:Dd,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}var Ys=require("react/jsx-runtime");function qr(e){let[o,t]=(0,Zs.useState)(e.defaultValue);function r(a){let n=a[0],f=kd(n);t(f),e.onChange&&e.onChange(f)}return(0,Ys.jsx)(Yt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Td(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Td(e){return e?{code:e}:void 0}function kd(e){return e?.code}var js=require("react/jsx-runtime");function jt(e){let[o,t]=(0,za.useState)(e.defaultValue),r=e.onChange,a=(0,za.useCallback)(n=>{t(n),r&&r(n)},[r]);return(0,js.jsx)(qr,{"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})}var Ie=require("react/jsx-runtime"),ei=(0,He.createStyles)(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 Qf(e){let{classes:o}=ei(),t=Fo(),r=Md(e.pathname,e.searchParams,e.menus),[a,n]=(0,Wa.useState)(!1);function f(l,i){l.stopPropagation(),l.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function s(l){l&&t(`/${l}`)}return(0,Ie.jsxs)(Ie.Fragment,{children:[(0,Ie.jsx)(He.Navbar,{width:{sm:250},p:"xs",children:(0,Ie.jsxs)(He.ScrollArea,{children:[!e.resourceTypeSearchDisabled&&(0,Ie.jsx)(He.Navbar.Section,{mb:"sm",children:(0,Ie.jsx)(jt,{name:"resourceType",placeholder:"Resource Type",onChange:l=>s(l)},window.location.pathname)}),(0,Ie.jsxs)(He.Navbar.Section,{grow:!0,children:[e.menus?.map(l=>(0,Ie.jsxs)(Wa.Fragment,{children:[(0,Ie.jsx)(He.Text,{className:o.menuTitle,children:l.title}),l.links?.map(i=>(0,Ie.jsxs)(Bd,{to:i.href,active:i.href===r?.href,onClick:u=>f(u,i.href),children:[(0,Ie.jsx)(Ad,{to:i.href,icon:i.icon}),(0,Ie.jsx)("span",{children:i.label})]},i.href))]},`menu-${l.title}`)),e.displayAddBookmark&&(0,Ie.jsx)(He.Button,{variant:"subtle",size:"xs",mt:"xl",leftIcon:(0,Ie.jsx)(kf,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&(0,Ie.jsx)($s,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function Bd(e){let{classes:o,cx:t}=ei();return(0,Ie.jsx)(be,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function Ad(e){return e.icon?e.icon:(0,Ie.jsx)(He.Space,{w:30})}function Md(e,o,t){if(!e||!o||!t)return;let r,a=0;for(let n of t)if(n.links)for(let f of n.links){let s=Fd(e,o,f.href);s>a&&(a=s,r=f)}return r}function Fd(e,o,t){let r=new URL(t,"https://example.com");if(e!==r.pathname)return 0;let a=["_count","_offset"];for(let[f,s]of r.searchParams.entries())if(!a.includes(f)&&o.get(f)!==s)return 0;let n=1;for(let[f,s]of o.entries())a.includes(f)||r.searchParams.get(f)===s&&n++;return n}var tt=require("react/jsx-runtime");function wd(e){let o=(0,Xa.useMantineTheme)(),[t,r]=(0,er.useState)(localStorage.navbarOpen==="true"),a=D(),n=Ar();(0,er.useEffect)(()=>{function i(){(0,oi.showNotification)({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",i),()=>a.removeEventListener("offline",i)},[a]);function f(i){localStorage.navbarOpen=i.toString(),r(i)}function s(){f(!1)}function l(){f(!t)}return a.isLoading()?(0,tt.jsx)(La,{}):(0,tt.jsx)(Xa.AppShell,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&(0,tt.jsx)(Vf,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:l}),navbar:n&&t?(0,tt.jsx)(Qf,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:s,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:(0,tt.jsx)(Dt,{children:(0,tt.jsx)(er.Suspense,{fallback:(0,tt.jsx)(La,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}var ti=require("@mantine/core"),vo=require("react/jsx-runtime");function lo(e){let{contentType:o,url:t,title:r}=e.value??{};return t?(0,vo.jsxs)("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&(0,vo.jsx)("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&(0,vo.jsx)("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:(0,vo.jsx)("source",{type:o,src:t})}),o==="application/pdf"&&(0,vo.jsx)("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:(0,vo.jsx)("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),(0,vo.jsx)("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:(0,vo.jsx)(ti.Anchor,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Od(r),children:r||"Download"})})]}):null}function Od(e){return e?.includes(".")?e:void 0}var Ja=require("react/jsx-runtime");function zf(e){return(0,Ja.jsx)("div",{children:e.values?.map((o,t)=>(0,Ja.jsx)("div",{children:(0,Ja.jsx)(lo,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}var Wf=require("@mantine/core");var $a=require("react");var ri=require("react");var ai=require("@medplum/core"),or=require("react/jsx-runtime");function Bt(e){let o=D(),t=(0,ri.useRef)(null);function r(f){N(f),t.current?.click()}function a(f){N(f);let s=f.target.files;s&&Array.from(s).forEach(n)}function n(f){if(!f||!f.name)return;e.onUploadStart&&e.onUploadStart();let l=f.name,i=f.type||"application/octet-stream";o.createBinary(f,l,i,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:l})}).catch(u=>{e.onUploadError&&e.onUploadError((0,ai.normalizeOperationOutcome)(u))})}return(0,or.jsxs)(or.Fragment,{children:[(0,or.jsx)("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:f=>a(f)}),e.children({onClick:r})]})}var ye=require("react/jsx-runtime");function Xf(e){let[o,t]=(0,$a.useState)(e.defaultValue??[]),r=(0,$a.useRef)();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return(0,ye.jsxs)("table",{style:{width:"100%"},children:[(0,ye.jsxs)("colgroup",{children:[(0,ye.jsx)("col",{width:"97%"}),(0,ye.jsx)("col",{width:"3%"})]}),(0,ye.jsxs)("tbody",{children:[o.map((n,f)=>(0,ye.jsxs)("tr",{children:[(0,ye.jsx)("td",{children:(0,ye.jsx)(lo,{value:n,maxWidth:200})}),(0,ye.jsx)("td",{children:(0,ye.jsx)(Wf.ActionIcon,{title:"Remove",size:"sm",onClick:s=>{N(s);let l=o.slice();l.splice(f,1),a(l)},children:(0,ye.jsx)(ot,{})})})]},`${f}-${o.length}`)),(0,ye.jsxs)("tr",{children:[(0,ye.jsx)("td",{}),(0,ye.jsx)("td",{children:(0,ye.jsx)(Bt,{onUpload:n=>{a([...r.current,n])},children:n=>(0,ye.jsx)(Wf.ActionIcon,{...n,title:"Add",size:"sm",color:"green",children:(0,ye.jsx)(wr,{size:16})})})})]})]})]})}var Jf=require("@mantine/core"),ni=require("react");var Lo=require("react/jsx-runtime");function Gr(e){let[o,t]=(0,ni.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?(0,Lo.jsxs)(Lo.Fragment,{children:[(0,Lo.jsx)(lo,{value:o,maxWidth:200}),(0,Lo.jsx)(Jf.Button,{onClick:a=>{N(a),r(void 0)},children:"Remove"})]}):(0,Lo.jsx)(Bt,{onUpload:r,children:a=>(0,Lo.jsx)(Jf.Button,{...a,children:"Upload..."})})}var rn=require("@medplum/core");var _a=["meta","implicitRules","contained","extension","modifierExtension"],Ka=["language","text"];var fi=require("@mantine/core"),rt=require("react/jsx-runtime"),Ed=(0,fi.createStyles)(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 $f(e){let{children:o,compact:t}=e,{classes:r,cx:a}=Ed();return(0,rt.jsx)("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function _f(e){return(0,rt.jsxs)(rt.Fragment,{children:[(0,rt.jsx)("dt",{children:e.term}),(0,rt.jsx)("dd",{children:e.children})]})}var ft=require("@mantine/core"),F=require("@medplum/core");var li=require("@medplum/core"),Za=require("react/jsx-runtime");function At(e){return(0,Za.jsx)(Za.Fragment,{children:(0,li.formatCodeableConcept)(e.value)})}var si=require("@medplum/core"),Ya=require("react/jsx-runtime");function Kf(e){return(0,Ya.jsx)(Ya.Fragment,{children:(0,si.formatCoding)(e.value)})}var ja=require("react/jsx-runtime");function Ur(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("]")),(0,ja.jsx)(ja.Fragment,{children:t.join("").trim()})}var tr=require("react/jsx-runtime");function Zf(e){let o=e.value;return o?(0,tr.jsxs)(tr.Fragment,{children:[o.name,o.name&&": ",o.telecom?.map(t=>(0,tr.jsx)(Ur,{value:t},`telecom-${o.name}-${t.value}`))]}):null}var ii=require("react/jsx-runtime");function Yf(e){return(0,ii.jsxs)("div",{children:[e.value?.system,": ",e.value?.value]})}var ui=require("@medplum/core"),en=require("react/jsx-runtime");function jf(e){return(0,en.jsx)(en.Fragment,{children:(0,ui.formatMoney)(e.value)})}var ci=require("@medplum/core"),on=require("react/jsx-runtime");function No(e){return(0,on.jsx)(on.Fragment,{children:(0,ci.formatQuantity)(e.value)})}var di=require("@medplum/core"),tn=require("react/jsx-runtime");function Qr(e){return(0,tn.jsx)(tn.Fragment,{children:(0,di.formatRange)(e.value)})}var Mt=require("react/jsx-runtime");function mi(e){let o=e.value;return o?(0,Mt.jsxs)(Mt.Fragment,{children:[(0,Mt.jsx)(No,{value:o.numerator}),"\xA0/\xA0",(0,Mt.jsx)(No,{value:o.denominator})]}):null}var pi=require("@medplum/core");var zr=require("react/jsx-runtime");function at(e){if(!e.value)return null;let o=e.value.display||e.value.reference||(0,pi.stringify)(e.value);return e.link!==!1&&e.value.reference?(0,zr.jsx)(be,{to:e.value,children:o}):(0,zr.jsx)(zr.Fragment,{children:o})}var nt=require("react/jsx-runtime");function el(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?(0,nt.jsx)(nt.Fragment,{children:t.map((a,n)=>(0,nt.jsx)("div",{children:(0,nt.jsx)(De,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):(0,nt.jsx)(nt.Fragment,{})}var w=require("react/jsx-runtime");function De(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return(0,w.jsxs)(ft.Box,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!(0,F.isEmpty)(r)&&(0,w.jsx)(ft.CopyButton,{value:r,timeout:2e3,children:({copied:n,copy:f})=>(0,w.jsx)(ft.Tooltip,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:(0,w.jsx)(ft.ActionIcon,{color:n?"teal":"gray",onClick:f,children:n?(0,w.jsx)(Fr,{size:"1rem"}):(0,w.jsx)(gf,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===F.PropertyType.Attachment?(0,w.jsx)(zf,{values:r,maxWidth:e.maxWidth}):(0,w.jsx)(el,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case F.PropertyType.boolean:return(0,w.jsx)(w.Fragment,{children:r===void 0?"":(!!r).toString()});case F.PropertyType.SystemString:case F.PropertyType.string:return(0,w.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:r});case F.PropertyType.code:case F.PropertyType.date:case F.PropertyType.decimal:case F.PropertyType.id:case F.PropertyType.integer:case F.PropertyType.positiveInt:case F.PropertyType.unsignedInt:case F.PropertyType.uri:case F.PropertyType.url:return(0,w.jsx)(w.Fragment,{children:r});case F.PropertyType.canonical:return(0,w.jsx)(at,{value:{reference:r},link:e.link});case F.PropertyType.dateTime:case F.PropertyType.instant:return(0,w.jsx)(w.Fragment,{children:(0,F.formatDateTime)(r)});case F.PropertyType.markdown:return(0,w.jsx)("pre",{children:r});case F.PropertyType.Address:return(0,w.jsx)(of,{value:r});case F.PropertyType.Annotation:return(0,w.jsx)(w.Fragment,{children:r?.text});case F.PropertyType.Attachment:return(0,w.jsx)(lo,{value:r,maxWidth:e.maxWidth});case F.PropertyType.CodeableConcept:return(0,w.jsx)(At,{value:r});case F.PropertyType.Coding:return(0,w.jsx)(Kf,{value:r});case F.PropertyType.ContactDetail:return(0,w.jsx)(Zf,{value:r});case F.PropertyType.ContactPoint:return(0,w.jsx)(Ur,{value:r});case F.PropertyType.HumanName:return(0,w.jsx)(Nr,{value:r});case F.PropertyType.Identifier:return(0,w.jsx)(Yf,{value:r});case F.PropertyType.Money:return(0,w.jsx)(jf,{value:r});case F.PropertyType.Period:return(0,w.jsx)(w.Fragment,{children:(0,F.formatPeriod)(r)});case F.PropertyType.Quantity:case F.PropertyType.Duration:return(0,w.jsx)(No,{value:r});case F.PropertyType.Range:return(0,w.jsx)(Qr,{value:r});case F.PropertyType.Ratio:return(0,w.jsx)(mi,{value:r});case F.PropertyType.Reference:return(0,w.jsx)(at,{value:r,link:e.link});case F.PropertyType.Timing:return(0,w.jsx)(w.Fragment,{children:(0,F.formatTiming)(r)});case F.PropertyType.Dosage:case F.PropertyType.UsageContext:return(0,w.jsx)(rr,{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(0,w.jsx)(rr,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}var xi=require("@medplum/core");function yo(e,o){let t=(0,xi.getTypedPropertyValue)(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}var Ft=require("react/jsx-runtime");function rr(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=(0,rn.tryGetDataType)(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?(0,Ft.jsx)("div",{children:t.name}):(0,Ft.jsx)($f,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[f,s]=n;if(_a.includes(f)||Ka.includes(f)&&s.path.split(".").length===2)return null;let[l,i]=yo(o,f);return e.ignoreMissingValues&&(!l||Array.isArray(l)&&l.length===0)?null:(0,Ft.jsx)(_f,{term:(0,rn.getPropertyDisplayName)(f),children:(0,Ft.jsx)(De,{property:s,propertyType:i,value:l,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},f)})}):(0,Ft.jsxs)("div",{children:[r,"\xA0not implemented"]})}var Wi=require("@mantine/core"),na=require("@medplum/core"),Xi=require("react");var an=require("@mantine/core"),ar=require("react/jsx-runtime");function Wr(e){return(0,ar.jsxs)(an.Group,{noWrap:!0,children:[(0,ar.jsx)("div",{children:e.children}),(0,ar.jsx)("div",{children:(0,ar.jsx)(an.Input.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}var gi=require("@mantine/core");function Te(e,o){return e?.issue?.filter(t=>Ii(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
65
+ `)}function Xr(e,o){return e?.issue?.filter(t=>Ii(t.expression?.[0],o))}function Ii(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}var hi=require("react/jsx-runtime");function Ve(e){return(0,hi.jsx)(gi.Input.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,error:Te(e.outcome,e.htmlFor),children:e.children})}var vi=require("@medplum/core");function Jr(e,o,t,r,a){let n=r.type;if(n.length>1)for(let f of n){let s=o.replace("[x]",(0,vi.capitalize)(f.code));s in e&&delete e[s]}return e[t]=a,e}var ro=require("@mantine/core"),O=require("@medplum/core"),Qi=require("react");var yi=require("react");var Ci=require("react/jsx-runtime");function ol(e){let[o,t]=(0,yi.useState)(e.defaultValue);function r(a){let n=Nd(a);t(n),e.onChange&&e.onChange(n)}return(0,Ci.jsx)(Yt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Ld(o),maxSelectedValues:1,onChange:r})}function Ld(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Nd(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}var Si=require("react");var Ri=require("react/jsx-runtime");function $r(e){let[o,t]=(0,Si.useState)(e.defaultValue);function r(a){let n=a[0],f=n&&Vd(n);t(f),e.onChange&&e.onChange(f)}return(0,Ri.jsx)(Yt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Hd(o),maxSelectedValues:1,onChange:r})}function Hd(e){return{system:e.system,code:e.code,display:e.display}}function Vd(e){return{system:e.system,code:e.code,display:e.display}}var fn=require("@mantine/core"),ln=require("react");var wt=require("@mantine/core"),nn=require("react"),nr=require("react/jsx-runtime");function _r(e){let[o,t]=(0,nn.useState)(e.defaultValue),r=(0,nn.useRef)();r.current=o;function a(l){l&&Object.keys(l).length===0&&(l=void 0),t(l),e.onChange&&e.onChange(l)}function n(l){let i={...r.current,system:l};l||delete i.system,a(i)}function f(l){let i={...r.current,use:l};l||delete i.use,a(i)}function s(l){let i={...r.current,value:l};l||delete i.value,a(i)}return(0,nr.jsxs)(wt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,nr.jsx)(wt.NativeSelect,{"data-testid":"system",defaultValue:o?.system,onChange:l=>n(l.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),(0,nr.jsx)(wt.NativeSelect,{"data-testid":"use",defaultValue:o?.use,onChange:l=>f(l.currentTarget.value),data:["","home","work","temp","old","mobile"]}),(0,nr.jsx)(wt.TextInput,{placeholder:"Value",defaultValue:o?.value,onChange:l=>s(l.currentTarget.value)})]})}var Kr=require("react/jsx-runtime");function tl(e){let[o,t]=(0,ln.useState)(e.defaultValue),r=(0,ln.useRef)();r.current=o;function a(s){t(s),e.onChange&&e.onChange(s)}function n(s){let l={...r.current,name:s};s||delete l.name,a(l)}function f(s){let l={...r.current,telecom:s&&[s]};s||delete l.telecom,a(l)}return(0,Kr.jsxs)(fn.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Kr.jsx)(fn.TextInput,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:s=>n(s.currentTarget.value)}),(0,Kr.jsx)(_r,{name:e.name+"-telecom",defaultValue:o?.telecom?.[0],onChange:f})]})}var bi=require("@mantine/core");var rl=require("@medplum/core");function al(e){if(!e)return"";let o=new Date(e);return(0,rl.isValidDate)(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function nl(e){if(!e)return"";let o=new Date(e);return(0,rl.isValidDate)(o)?o.toISOString():""}var Pi=require("react/jsx-runtime");function to(e){return(0,Pi.jsx)(bi.TextInput,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:qd(),defaultValue:al(e.defaultValue),autoFocus:e.autoFocus,error:Te(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(nl(t))}}})}function qd(){return"datetime-local"}var Di=require("@mantine/core"),Ti=require("@medplum/core"),Bi=require("react/jsx-runtime");function ki(e){return(0,Bi.jsx)(Di.JsonInput,{id:e.name,name:e.name,"data-testid":"extension-input",defaultValue:(0,Ti.stringify)(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}var Ho=require("@mantine/core"),sn=require("react"),lt=require("react/jsx-runtime");function fl(e){let[o,t]=(0,sn.useState)(e.defaultValue),r=(0,sn.useRef)();r.current=o;function a(u){t(u),e.onChange&&e.onChange(u)}function n(u){a({...r.current,use:u||void 0})}function f(u){a({...r.current,prefix:u?u.split(" "):void 0})}function s(u){a({...r.current,given:u?u.split(" "):void 0})}function l(u){a({...r.current,family:u||void 0})}function i(u){a({...r.current,suffix:u?u.split(" "):void 0})}return(0,lt.jsxs)(Ho.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,lt.jsx)(Ho.NativeSelect,{defaultValue:o?.use,name:e.name+"-use","data-testid":"use",onChange:u=>n(u.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"]}),(0,lt.jsx)(Ho.TextInput,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:o?.prefix?.join(" "),onChange:u=>f(u.currentTarget.value)}),(0,lt.jsx)(Ho.TextInput,{placeholder:"Given",name:e.name+"-given",defaultValue:o?.given?.join(" "),onChange:u=>s(u.currentTarget.value)}),(0,lt.jsx)(Ho.TextInput,{name:e.name+"-family",placeholder:"Family",defaultValue:o?.family,onChange:u=>l(u.currentTarget.value)}),(0,lt.jsx)(Ho.TextInput,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:o?.suffix?.join(" "),onChange:u=>i(u.currentTarget.value)})]})}var Zr=require("@mantine/core"),Ai=require("react"),Yr=require("react/jsx-runtime");function ll(e){let[o,t]=(0,Ai.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,Yr.jsxs)(Zr.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,Yr.jsx)(Zr.TextInput,{placeholder:"System",defaultValue:o?.system,onChange:a=>r({...o,system:a.currentTarget.value})}),(0,Yr.jsx)(Zr.TextInput,{placeholder:"Value",defaultValue:o?.value,onChange:a=>r({...o,value:a.currentTarget.value})})]})}var cn=require("@mantine/core");var fr=require("react"),un=require("react/jsx-runtime"),Gd=["USD","EUR","CAD","GBP","AUD"];function sl(e){let{onChange:o}=e,[t,r]=(0,fr.useState)(e.defaultValue),a=(0,fr.useCallback)(l=>{r(l),o&&o(l)},[o]),n=(0,fr.useCallback)(l=>{a({...t,currency:l.currentTarget.value})},[t,a]),f=(0,fr.useCallback)(l=>{a({...t,value:l.currentTarget.valueAsNumber})},[t,a]),s=(0,un.jsx)(cn.NativeSelect,{defaultValue:t?.currency,data:Gd,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return(0,un.jsx)(cn.TextInput,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:(0,un.jsx)(hf,{size:14}),rightSection:s,rightSectionWidth:92,onChange:f})}var Mi=require("@mantine/core"),Fi=require("react");var jr=require("react/jsx-runtime");function wi(e){let[o,t]=(0,Fi.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,jr.jsxs)(Mi.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,jr.jsx)(to,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),(0,jr.jsx)(to,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}var Ot=require("@mantine/core"),Oi=require("react"),lr=require("react/jsx-runtime");function Ue(e){let[o,t]=(0,Oi.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,lr.jsxs)(Ot.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,lr.jsx)(Ot.NativeSelect,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),(0,lr.jsx)(Ot.TextInput,{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:Ud(a.currentTarget.value)})}}),(0,lr.jsx)(Ot.TextInput,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function Ud(e){if(e)return parseFloat(e)}var Ei=require("@mantine/core"),Li=require("react");var ea=require("react/jsx-runtime");function sr(e){let[o,t]=(0,Li.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,ea.jsxs)(Ei.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,ea.jsx)(Ue,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),(0,ea.jsx)(Ue,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}var Ni=require("@mantine/core"),Hi=require("react");var oa=require("react/jsx-runtime");function Vi(e){let[o,t]=(0,Hi.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,oa.jsxs)(Ni.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,oa.jsx)(Ue,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),(0,oa.jsx)(Ue,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}var dn=require("@mantine/core"),qi=require("@medplum/core"),il=require("react");var ta=require("@mantine/core"),ra=require("@medplum/core");var Et=require("react");var Vo=require("react/jsx-runtime"),Qd={Observation:"code",User:"email:contains"},zd=["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 Wd(e){return{value:(0,ra.getReferenceString)(e),label:(0,ra.getDisplayString)(e),resource:e}}function aa(e){let o=D(),{resourceType:t,searchCriteria:r}=e,[a,n]=(0,Et.useState)(),f=K(e.defaultValue,n),s=e.onChange,l=(0,Et.useCallback)(async(u,d)=>{let c=Jd(t),m=new URLSearchParams({[c]:u,_count:"10",...r});return await o.searchResources(t,m,{signal:d})},[o,t,r]),i=(0,Et.useCallback)(u=>{s&&s(u[0])},[s]);return e.defaultValue&&!a&&!f?null:(0,Vo.jsx)(Tt,{name:e.name,required:e.required,itemComponent:Xd,defaultValue:f,placeholder:e.placeholder,maxSelectedValues:1,toKey:ra.getReferenceString,toOption:Wd,loadOptions:l,onChange:i,clearable:!0})}var Xd=(0,Et.forwardRef)(({label:e,resource:o,...t},r)=>(0,Vo.jsx)("div",{ref:r,...t,children:(0,Vo.jsxs)(ta.Group,{noWrap:!0,children:[(0,Vo.jsx)(Fe,{value:o}),(0,Vo.jsxs)("div",{children:[(0,Vo.jsx)(ta.Text,{children:e}),(0,Vo.jsx)(ta.Text,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function Jd(e){return Qd[e]??(zd.includes(e)?"name":"_id")}var ir=require("react/jsx-runtime");function Lt(e){let o=$d(e.targetTypes),t=_d(e.defaultValue,o),[r,a]=(0,il.useState)(e.defaultValue),[n,f]=(0,il.useState)(t);function s(l){a(l),e.onChange&&e.onChange(l)}return(0,ir.jsxs)(dn.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&(0,ir.jsx)(dn.NativeSelect,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:n,autoFocus:e.autoFocus,onChange:l=>f(l.currentTarget.value),data:o}),!o&&(0,ir.jsx)(jt,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:f,name:e.name+"-resourceType",placeholder:"Resource Type"}),(0,ir.jsx)(aa,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:e.searchCriteria,onChange:l=>{s(l?(0,qi.createReference)(l):void 0)}})]})}function $d(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function _d(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}var st=require("@mantine/core");var mn=require("react");var Qe=require("react/jsx-runtime");function ul(e){let[o,t]=(0,mn.useState)(e.defaultValue&&Array.isArray(e.defaultValue)?e.defaultValue:[]),r=(0,mn.useRef)();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return(0,Qe.jsxs)(st.Stack,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,f)=>(0,Qe.jsxs)(st.Group,{noWrap:!0,children:[(0,Qe.jsx)("div",{style:{flexGrow:1},children:(0,Qe.jsx)(Co,{arrayElement:!0,property:e.property,name:e.name+"."+f,defaultValue:n,onChange:s=>{let l=[...r.current];l[f]=s,a(l)}})}),(0,Qe.jsx)("div",{children:(0,Qe.jsx)(st.ActionIcon,{title:"Remove",size:"sm",onClick:s=>{N(s);let l=[...r.current];l.splice(f,1),a(l)},children:(0,Qe.jsx)(ot,{})})})]},`${f}-${o.length}`)),(0,Qe.jsx)(st.Group,{noWrap:!0,style:{justifyContent:"flex-end"},children:(0,Qe.jsx)("div",{children:(0,Qe.jsx)(st.ActionIcon,{title:"Add",size:"sm",color:"green",onClick:n=>{N(n);let f=[...r.current];f.push(void 0),a(f)},children:(0,Qe.jsx)($t,{})})})})]})}var pe=require("@mantine/core"),Ui=require("@medplum/core"),Nt=require("react");var te=require("react/jsx-runtime"),Kd=["sun","mon","tue","wed","thu","fri","sat"];function cl(e){let[o,t]=(0,Nt.useState)(e.defaultValue),[r,a]=(0,Nt.useState)(!1),n=(0,Nt.useRef)();return n.current=o,(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)(pe.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,te.jsx)("span",{children:(0,Ui.formatTiming)(n.current)||"No repeat"}),(0,te.jsx)(pe.Button,{onClick:()=>a(!0),children:"Edit"})]}),(0,te.jsx)(Zd,{visible:r,defaultValue:n.current,onOk:f=>{e.onChange&&e.onChange(f),t(f),a(!1)},onCancel:()=>a(!1)})]})}var Gi={repeat:{period:1,periodUnit:"d"}};function Zd(e){let[o,t]=(0,Nt.useState)(e.defaultValue||Gi),r=(0,Nt.useRef)();r.current=o;function a(i){t({...r.current,event:[i]})}function n(i){t({...r.current,repeat:i})}function f(i){n({...r.current?.repeat,period:i})}function s(i){n({...r.current?.repeat,periodUnit:i})}function l(i){n({...r.current?.repeat,dayOfWeek:i})}return(0,te.jsx)(pe.Modal,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:(0,te.jsxs)(pe.Stack,{children:[(0,te.jsx)(Ve,{title:"Starts on",htmlFor:"timing-dialog-start",children:(0,te.jsx)(to,{name:"timing-dialog-start",onChange:i=>a(i)})}),(0,te.jsx)(pe.Switch,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?Gi.repeat:void 0)}),o.repeat&&(0,te.jsxs)(te.Fragment,{children:[(0,te.jsx)(Ve,{title:"Repeat every",htmlFor:"timing-dialog-period",children:(0,te.jsxs)(pe.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,te.jsx)(pe.TextInput,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:i=>f(parseInt(i.currentTarget.value,10)||1)}),(0,te.jsx)(pe.NativeSelect,{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"&&(0,te.jsx)(Ve,{title:"Repeat on",children:(0,te.jsx)(pe.Chip.Group,{multiple:!0,onChange:l,children:(0,te.jsx)(pe.Group,{position:"apart",mt:"md",spacing:"xs",children:Kd.map(i=>(0,te.jsx)(pe.Chip,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),(0,te.jsx)(pe.Group,{position:"right",children:(0,te.jsx)(pe.Button,{onClick:()=>e.onOk(o),children:"OK"})})]})})}var q=require("react/jsx-runtime");function Co(e){let o=e.property,t=e.defaultPropertyType&&e.defaultPropertyType!=="undefined"?e.defaultPropertyType:o.type[0].code,r=e.name,a=e.defaultValue;if(o.max>1&&!e.arrayElement)return t===O.PropertyType.Attachment?(0,q.jsx)(Xf,{name:r,defaultValue:a,onChange:e.onChange}):(0,q.jsx)(ul,{property:o,name:r,defaultValue:a,onChange:e.onChange});let n=o.type;return n.length>1?(0,q.jsx)(zi,{elementDefinitionTypes:n,...e}):(0,q.jsx)(dl,{elementDefinitionType:n[0],...e})}function zi(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=(0,Qi.useState)(t);return(0,q.jsxs)(ro.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,q.jsx)(ro.NativeSelect,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(f=>f.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),(0,q.jsx)(dl,{...e,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",(0,O.capitalize)(r.code)))}})]})}function dl(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 O.PropertyType.SystemString:case O.PropertyType.canonical:case O.PropertyType.string:case O.PropertyType.time:case O.PropertyType.uri:case O.PropertyType.url:return(0,q.jsx)(ro.TextInput,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)},error:Te(e.outcome,r)});case O.PropertyType.date:return(0,q.jsx)(ro.TextInput,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)},error:Te(e.outcome,r)});case O.PropertyType.dateTime:case O.PropertyType.instant:return(0,q.jsx)(to,{name:r,defaultValue:a,onChange:e.onChange,outcome:e.outcome});case O.PropertyType.decimal:case O.PropertyType.integer:case O.PropertyType.positiveInt:case O.PropertyType.unsignedInt:return(0,q.jsx)(ro.TextInput,{type:"number",step:t===O.PropertyType.decimal?"any":"1",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.valueAsNumber)}});case O.PropertyType.code:return(0,q.jsx)(qr,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.boolean:return(0,q.jsx)(ro.Checkbox,{id:r,name:r,"data-testid":r,defaultChecked:!!a,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.checked)}});case O.PropertyType.markdown:return(0,q.jsx)(ro.Textarea,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)}});case O.PropertyType.Address:return(0,q.jsx)(tf,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Annotation:return(0,q.jsx)(rf,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Attachment:return(0,q.jsx)(Gr,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.CodeableConcept:return(0,q.jsx)(ol,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Coding:return(0,q.jsx)($r,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.ContactDetail:return(0,q.jsx)(tl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.ContactPoint:return(0,q.jsx)(_r,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Extension:return(0,q.jsx)(ki,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.HumanName:return(0,q.jsx)(fl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Identifier:return(0,q.jsx)(ll,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Money:return(0,q.jsx)(sl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Period:return(0,q.jsx)(wi,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Duration:case O.PropertyType.Quantity:return(0,q.jsx)(Ue,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Range:return(0,q.jsx)(sr,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Ratio:return(0,q.jsx)(Vi,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Reference:return(0,q.jsx)(Lt,{name:r,defaultValue:a,targetTypes:Yd(o),onChange:e.onChange});case O.PropertyType.Timing:return(0,q.jsx)(cl,{name:r,defaultValue:a,onChange:e.onChange});case O.PropertyType.Dosage:case O.PropertyType.UsageContext:return(0,q.jsx)(ur,{typeName:t,defaultValue:a,onChange:e.onChange,outcome:e.outcome});default:return(0,q.jsx)(ur,{typeName:o.type[0].code,defaultValue:a,onChange:e.onChange,outcome:e.outcome})}}function Yd(e){return e?.type?.[0]?.targetProfile?.map(o=>o.split("/").pop())}var it=require("react/jsx-runtime");function ur(e){let[o,t]=(0,Xi.useState)(e.defaultValue??{});function r(s){t(s),e.onChange&&e.onChange(s)}let a=e.typeName,n=(0,na.tryGetDataType)(a);if(!n)return(0,it.jsxs)("div",{children:[a,"\xA0not implemented"]});let f={type:a,value:o};return(0,it.jsx)(Wi.Stack,{children:Object.entries(n.elements).map(([s,l])=>{if(s==="id"||_a.includes(s)||Ka.includes(s)&&l.path.split(".").length===2||!l.type)return null;let[i,u]=yo(f,s),d=l.min!==void 0&&l.min>0;return l.type.length===1&&l.type[0].code==="boolean"?(0,it.jsx)(Wr,{title:(0,na.getPropertyDisplayName)(s),description:l.description,htmlFor:s,children:(0,it.jsx)(Co,{property:l,name:s,defaultValue:i,defaultPropertyType:u,outcome:e.outcome,onChange:(c,m)=>{r(Jr(o,s,m??s,l,c))}})},s):(0,it.jsx)(Ve,{title:(0,na.getPropertyDisplayName)(s),description:l.description,withAsterisk:d,htmlFor:s,outcome:e.outcome,children:(0,it.jsx)(Co,{property:l,name:s,defaultValue:i,defaultPropertyType:u,onChange:(c,m)=>{r(Jr(o,s,m??s,l,c))}})},s)})})}var qo=require("@mantine/core"),xn=require("react");function Ji(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function pn(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}var de=require("react/jsx-runtime"),jd=(0,qo.createStyles)(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 ml(e){let{classes:o}=jd(),{onChangeMonth:t,onClick:r}=e,[a,n]=(0,xn.useState)(pn);function f(l){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+l),t(u),u})}let s=(0,xn.useMemo)(()=>em(a,e.slots),[a,e.slots]);return(0,de.jsxs)("div",{children:[(0,de.jsxs)(qo.Group,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[(0,de.jsx)("p",{style:{flex:1},children:Ji(a)}),(0,de.jsxs)(qo.Group,{position:"right",spacing:"xs",children:[(0,de.jsx)(qo.Button,{variant:"outline","aria-label":"Previous month",onClick:()=>f(-1),children:"<"}),(0,de.jsx)(qo.Button,{variant:"outline","aria-label":"Next month",onClick:()=>f(1),children:">"})]})]}),(0,de.jsxs)("table",{className:o.table,children:[(0,de.jsx)("thead",{children:(0,de.jsxs)("tr",{children:[(0,de.jsx)("th",{children:"SUN"}),(0,de.jsx)("th",{children:"MON"}),(0,de.jsx)("th",{children:"TUE"}),(0,de.jsx)("th",{children:"WED"}),(0,de.jsx)("th",{children:"THU"}),(0,de.jsx)("th",{children:"FRI"}),(0,de.jsx)("th",{children:"SAT"})]})}),(0,de.jsx)("tbody",{children:s.map((l,i)=>(0,de.jsx)("tr",{children:l.map((u,d)=>(0,de.jsx)("td",{children:u&&(0,de.jsx)(qo.Button,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+d))},"week-"+i))})]})]})}function em(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:om(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 om(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}var In=require("@mantine/core"),$i=require("react/jsx-runtime"),tm=(0,In.createStyles)(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Go(e){let{children:o,...t}=e,{classes:r}=tm();return(0,$i.jsx)(In.Container,{className:r.root,...t,children:o})}var ne=require("@mantine/core"),Vt=require("@mantine/notifications"),Xo=require("@medplum/core");var ze=require("react");var Z=require("@mantine/core"),ao=require("@medplum/core");var gn=require("react");var cr=require("@mantine/core"),pl=require("react/jsx-runtime"),rm=(0,cr.createStyles)(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function xl({value:e}){let{classes:o}=rm();return e?(0,pl.jsx)(cr.Stack,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&(0,pl.jsx)(cr.Blockquote,{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}var Zi=require("@mantine/core");var _i=require("@mantine/core"),dr=require("@medplum/core");var Ki=require("react");var Il=require("react/jsx-runtime");function so(e){let{value:o,link:t,...r}=e,[a,n]=(0,Ki.useState)(),f=K(o,n),s;if(a&&!(0,dr.isOk)(a))s=`[${(0,dr.normalizeErrorString)(a)}]`;else if(f)s=(0,dr.getDisplayString)(f);else return null;return t?(0,Il.jsx)(be,{to:o,...r,children:s}):(0,Il.jsx)(_i.Text,{component:"span",...r,children:s})}var fa=require("react/jsx-runtime");function Uo(e){return(0,fa.jsxs)(Zi.Group,{spacing:"xs",children:[(0,fa.jsx)(Fe,{size:24,radius:12,value:e.value,link:e.link}),(0,fa.jsx)(so,{value:e.value,link:e.link})]})}var Yi=require("@mantine/core"),ji=require("react/jsx-runtime"),am={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 la(e){return(0,ji.jsx)(Yi.Badge,{color:am[e.status],children:e.status})}var I=require("react/jsx-runtime"),eu=(0,Z.createStyles)(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}}));hn.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function hn(e){let o=D(),t=K(e.value),[r,a]=(0,gn.useState)();if((0,gn.useEffect)(()=>{t?.specimen&&Promise.allSettled(t.specimen.map(f=>o.readReference(f))).then(f=>f.filter(s=>s.status==="fulfilled").map(s=>s.value)).then(a).catch(console.error)},[o,t]),!t)return null;let n=r?.flatMap(f=>f.note||[])||[];if(t.presentedForm&&t.presentedForm.length>0){let f=t.presentedForm[0];f.contentType?.startsWith("text/plain")&&f.data&&n.push({text:window.atob(f.data)})}return(0,I.jsxs)(Z.Stack,{children:[(0,I.jsx)(Z.Title,{children:"Diagnostic Report"}),(0,I.jsx)(nm,{value:t}),r&&!e.hideSpecimenInfo&&fm(r),t.result&&(0,I.jsx)(ou,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&(0,I.jsx)(xl,{value:n})]})}function nm({value:e}){return(0,I.jsxs)(Z.Group,{mt:"md",spacing:30,children:[e.subject&&(0,I.jsxs)("div",{children:[(0,I.jsx)(Z.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),(0,I.jsx)(Z.Text,{children:(0,I.jsx)(Uo,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>(0,I.jsxs)("div",{children:[(0,I.jsx)(Z.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),(0,I.jsx)(Z.Text,{children:(0,I.jsx)(Uo,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>(0,I.jsxs)("div",{children:[(0,I.jsx)(Z.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),(0,I.jsx)(Z.Text,{children:(0,I.jsx)(Uo,{value:o,link:!0})})]},o.reference)),e.issued&&(0,I.jsxs)("div",{children:[(0,I.jsx)(Z.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),(0,I.jsx)(Z.Text,{children:(0,ao.formatDateTime)(e.issued)})]}),e.status&&(0,I.jsxs)("div",{children:[(0,I.jsx)(Z.Text,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),(0,I.jsx)(Z.Text,{children:(0,ao.capitalize)(e.status)})]})]})}function fm(e){return(0,I.jsxs)(Z.Stack,{spacing:"xs",children:[(0,I.jsx)(Z.Title,{order:2,size:"h6",children:"Specimens"}),(0,I.jsx)(Z.List,{type:"ordered",children:e?.map(o=>(0,I.jsx)(Z.List.Item,{ml:"sm",children:(0,I.jsxs)(Z.Group,{spacing:20,children:[(0,I.jsxs)(Z.Group,{spacing:5,children:[(0,I.jsx)(Z.Text,{fw:500,children:"Collected:"})," ",(0,ao.formatDateTime)(o.collection?.collectedDateTime)]}),(0,I.jsxs)(Z.Group,{spacing:5,children:[(0,I.jsx)(Z.Text,{fw:500,children:"Received:"})," ",(0,ao.formatDateTime)(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function ou(e){let{classes:o}=eu();return(0,I.jsxs)("table",{className:o.table,children:[(0,I.jsx)("thead",{children:(0,I.jsxs)("tr",{children:[(0,I.jsx)("th",{children:"Test"}),(0,I.jsx)("th",{children:"Value"}),(0,I.jsx)("th",{children:"Reference Range"}),(0,I.jsx)("th",{children:"Interpretation"}),(0,I.jsx)("th",{children:"Category"}),(0,I.jsx)("th",{children:"Performer"}),(0,I.jsx)("th",{children:"Status"})]})}),(0,I.jsx)("tbody",{children:(0,I.jsx)(tu,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function tu(e){return(0,I.jsx)(I.Fragment,{children:e.value?.map(o=>(0,I.jsx)(lm,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${(0,ao.isReference)(o)?o.reference:o.id}`))})}function lm(e){let{classes:o,cx:t}=eu(),r=K(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=um(r);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("tr",{className:t({[o.criticalRow]:n}),children:[(0,I.jsx)("td",{rowSpan:a?2:1,children:(0,I.jsx)(be,{to:r,children:(0,I.jsx)(At,{value:r.code})})}),(0,I.jsx)("td",{children:(0,I.jsx)(sm,{value:r})}),(0,I.jsx)("td",{children:(0,I.jsx)(im,{value:r.referenceRange})}),(0,I.jsx)("td",{children:r.interpretation&&r.interpretation.length>0&&(0,I.jsx)(At,{value:r.interpretation[0]})}),(0,I.jsx)("td",{children:r.category&&r.category.length>0&&(0,I.jsx)(I.Fragment,{children:r.category.map(f=>(0,I.jsx)("div",{children:(0,I.jsx)(At,{value:f})},`category-${(0,ao.formatCodeableConcept)(f)}`))})}),(0,I.jsx)("td",{children:r.performer?.map(f=>(0,I.jsx)(at,{value:f},f.reference))}),(0,I.jsx)("td",{children:r.status&&(0,I.jsx)(la,{status:r.status})})]}),r.hasMember&&(0,I.jsx)(tu,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&(0,I.jsx)("tr",{children:(0,I.jsx)("td",{colSpan:6,children:(0,I.jsx)(xl,{value:r.note})})})]})}function sm(e){let o=e.value;return(0,I.jsx)(I.Fragment,{children:(0,ao.formatObservationValue)(o)})}function im(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?(0,I.jsx)(I.Fragment,{children:o.text}):(0,I.jsx)(Qr,{value:o}):null}function um(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}var mr=require("@mantine/core"),ru=require("react/jsx-runtime"),cm=(0,mr.createStyles)((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%"}}})),dm={shadow:"xs",radius:"md",withBorder:!0};function Ht(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...f}=(0,mr.useComponentDefaultProps)("Panel",dm,e),{classes:s,cx:l}=cm({width:r,fill:a},{name:"Panel",unstyled:n});return(0,ru.jsx)(mr.Paper,{className:l(s.paper,o),...f,children:t})}var yu=require("@mantine/core"),bo=require("@medplum/core");var Cn=require("react"),Cu=ys(hu(),1);var we=require("react/jsx-runtime"),km=(0,yu.createStyles)(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 Su(e){let{classes:o}=km(),t=D(),[r,a]=(0,Cn.useState)(!1);if((0,Cn.useEffect)(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,Cu.createPatch)(e.original,e.revised),f=[(0,bo.toTypedValue)(e.original)],s=[(0,bo.toTypedValue)(e.revised)];return(0,we.jsxs)("table",{className:o.root,children:[(0,we.jsx)("thead",{children:(0,we.jsxs)("tr",{children:[(0,we.jsx)("th",{}),(0,we.jsx)("th",{children:"Before"}),(0,we.jsx)("th",{children:"After"})]})}),(0,we.jsx)("tbody",{children:n.map(l=>{if(l.path.startsWith("/meta"))return null;let i=l.path,u=Bm(i),c=(0,bo.getSearchParameterDetails)(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],m=!!c?.isArray,h=l.op==="add"?void 0:(0,bo.evalFhirPathTyped)(u,f)?.[0],g=l.op==="remove"?void 0:(0,bo.evalFhirPathTyped)(u,s)?.[0];return(0,we.jsxs)("tr",{children:[(0,we.jsxs)("td",{children:[(0,bo.capitalize)(l.op)," ",u]}),(0,we.jsx)("td",{className:o.removed,children:h&&(0,we.jsx)(De,{property:c,propertyType:h.type,value:vu(h.value,m),ignoreMissingValues:!0})}),(0,we.jsx)("td",{className:o.added,children:g&&(0,we.jsx)(De,{property:c,propertyType:g.type,value:vu(g.value,m),ignoreMissingValues:!0})})]},`op-${l.op}-${l.path}`)})})]})}function Bm(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 vu(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}var Sn=require("react");var Ru=require("react/jsx-runtime");function Rn(e){let o=D(),t=K(e.value),[r,a]=(0,Sn.useState)(!1);return(0,Sn.useEffect)(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:(0,Ru.jsx)(rr,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}var io=require("@mantine/core"),bn=require("@medplum/core");var me=require("react/jsx-runtime");function kl(e){return(0,me.jsx)(Go,{children:e.children})}function Wo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,f=t??o.meta?.author,s=e.dateTime??o.meta?.lastUpdated;return(0,me.jsxs)(Ht,{"data-testid":"timeline-item",fill:!0,...n,children:[(0,me.jsxs)(io.Group,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[(0,me.jsx)(Fe,{value:f,link:!0,size:"md"}),(0,me.jsxs)("div",{style:{flex:1},children:[(0,me.jsx)(io.Text,{size:"sm",children:(0,me.jsx)(so,{color:"dark",weight:500,value:f,link:!0})}),(0,me.jsxs)(io.Text,{size:"xs",children:[(0,me.jsx)(be,{color:"dimmed",to:e.resource,children:(0,bn.formatDateTime)(s)}),(0,me.jsx)(io.Text,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),(0,me.jsx)(be,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&(0,me.jsxs)(io.Menu,{position:"bottom-end",shadow:"md",width:200,children:[(0,me.jsx)(io.Menu.Target,{children:(0,me.jsx)(io.ActionIcon,{radius:"xl","aria-label":`Actions for ${(0,bn.getReferenceString)(e.resource)}`,children:(0,me.jsx)(vf,{})})}),a]})]}),(0,me.jsxs)(Dt,{children:[r&&(0,me.jsx)("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&(0,me.jsx)(me.Fragment,{children:e.children})]})]})}function Bl(e,o){e.sort((t,r)=>{let a=bu(t,o),n=bu(r,o);return a>n?1:a<n?-1:Pu(t,o)-Pu(r,o)})}function bu(e,o){if(!Du(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Pu(e,o){if(!Du(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 Du(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}var P=require("react/jsx-runtime"),Am=(0,ne.createStyles)(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function Jo(e){let o=D(),t=Fo(),r=o.getProfile(),a=(0,ze.useRef)(null),n=K(e.value),[f,s]=(0,ze.useState)(),[l,i]=(0,ze.useState)([]),u=e.loadTimelineResources,d=(0,ze.useRef)(l);d.current=l;let c=(0,ze.useCallback)(v=>{Bl(v,n),v.reverse(),i(v)},[n]),m=(0,ze.useCallback)(v=>{let U=[];for(let xo of v){if(xo.status!=="fulfilled")continue;let S=xo.value;if(S.type==="history"&&s(S),S.entry)for(let X of S.entry)U.push(X.resource)}c(U)},[c]),h=(0,ze.useCallback)(v=>c([...d.current,v]),[c]),g=(0,ze.useCallback)(()=>{let v,U;"resourceType"in e.value?(v=e.value.resourceType,U=e.value.id):[v,U]=e.value.reference?.split("/"),u(o,v,U).then(m).catch(console.log)},[o,e.value,u,m]);(0,ze.useEffect)(()=>g(),[g]);function y(v){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,v)).then(U=>h(U)).catch(console.log)}function k(v){!n||!e.createMedia||o.createResource(e.createMedia(n,r,v)).then(U=>h(U)).then(()=>(0,Vt.updateNotification)({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:(0,P.jsx)(Fr,{size:16}),autoClose:2e3})).catch(U=>(0,Vt.updateNotification)({id:"upload-notification",color:"red",title:"Upload error",message:(0,Xo.normalizeErrorString)(U),icon:(0,P.jsx)(Fa,{size:16}),autoClose:2e3}))}function T(v,U){return o.updateResource({...v,priority:U})}function A(v){T(v,"stat").then(g).catch(console.log)}function _(v){T(v,"routine").then(g).catch(console.log)}function C(v){t(`/${v.resourceType}/${v.id}`)}function E(v){t(`/${v.resourceType}/${v.id}/edit`)}function se(v){t(`/${v.resourceType}/${v.id}/delete`)}function Se(v){t(`/${v.resourceType}/${v.id}/_history/${v.meta?.versionId}`)}function Ao(){(0,Vt.showNotification)({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function Ct(v){(0,Vt.updateNotification)({id:"upload-notification",loading:!0,title:"Uploading...",message:Nm(v),autoClose:!1,withCloseButton:!1})}function Me(v){(0,Vt.updateNotification)({id:"upload-notification",color:"red",title:"Upload error",message:(0,Xo.normalizeErrorString)(v),icon:(0,P.jsx)(Fa,{size:16}),autoClose:2e3})}return n?(0,P.jsxs)(kl,{children:[e.createCommunication&&(0,P.jsx)(Ht,{children:(0,P.jsx)(oe,{testid:"timeline-form",onSubmit:v=>{y(v.text);let U=a.current;U&&(U.value="",U.focus())},children:(0,P.jsxs)(ne.Group,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[(0,P.jsx)(Fe,{value:r}),(0,P.jsx)(ne.TextInput,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),(0,P.jsx)(ne.ActionIcon,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:(0,P.jsx)(Pf,{size:16})}),(0,P.jsx)(Bt,{onUpload:k,onUploadStart:Ao,onUploadProgress:Ct,onUploadError:Me,children:v=>(0,P.jsx)(ne.ActionIcon,{...v,radius:"xl",color:"blue",variant:"filled",children:(0,P.jsx)(wr,{size:16})})})]})})}),l.map(v=>{if(!v)return null;let U=`${v.resourceType}/${v.id}/${v.meta?.versionId}`;if(v.resourceType===n.resourceType&&v.id===n.id)return(0,P.jsx)(Mm,{history:f,resource:v,onDetails:Se},U);switch(v.resourceType){case"AuditEvent":return(0,P.jsx)(Em,{resource:v,onDetails:C},U);case"Communication":return(0,P.jsx)(wm,{resource:v,onPin:v.priority!=="stat"?A:void 0,onUnpin:v.priority==="stat"?_:void 0,onDetails:C,onEdit:E,onDelete:se},U);case"DiagnosticReport":return(0,P.jsx)(Lm,{resource:v,onDetails:C,onEdit:E,onDelete:se},U);case"Media":return(0,P.jsx)(Om,{resource:v,onDetails:C,onEdit:E,onDelete:se},U);default:return(0,P.jsx)(Wo,{resource:v,padding:!0,children:(0,P.jsx)(Rn,{value:v,ignoreMissingValues:!0})},U)}})]}):(0,P.jsx)(ne.Center,{style:{width:"100%",height:"100%"},children:(0,P.jsx)(ne.Loader,{})})}function pr(e){return(0,P.jsxs)(ne.Menu.Dropdown,{children:[(0,P.jsx)(ne.Menu.Label,{children:"Resource"}),e.onPin&&(0,P.jsx)(ne.Menu.Item,{icon:(0,P.jsx)(Df,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${(0,Xo.getReferenceString)(e.resource)}`,children:"Pin"}),e.onUnpin&&(0,P.jsx)(ne.Menu.Item,{icon:(0,P.jsx)(Tf,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${(0,Xo.getReferenceString)(e.resource)}`,children:"Unpin"}),e.onDetails&&(0,P.jsx)(ne.Menu.Item,{icon:(0,P.jsx)(Rf,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${(0,Xo.getReferenceString)(e.resource)}`,children:"Details"}),e.onEdit&&(0,P.jsx)(ne.Menu.Item,{icon:(0,P.jsx)(yf,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${(0,Xo.getReferenceString)(e.resource)}`,children:"Edit"}),e.onDelete&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(ne.Menu.Divider,{}),(0,P.jsx)(ne.Menu.Label,{children:"Danger zone"}),(0,P.jsx)(ne.Menu.Item,{color:"red",icon:(0,P.jsx)(Lr,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${(0,Xo.getReferenceString)(e.resource)}`,children:"Delete"})]})]})}function Mm(e){let o=Fm(e.history,e.resource);return o?(0,P.jsx)(Wo,{resource:e.resource,padding:!0,popupMenuItems:(0,P.jsx)(pr,{...e}),children:(0,P.jsx)(Su,{original:o,revised:e.resource})}):(0,P.jsxs)(Wo,{resource:e.resource,padding:!0,popupMenuItems:(0,P.jsx)(pr,{...e}),children:[(0,P.jsx)("h3",{children:"Created"}),(0,P.jsx)(Rn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function Fm(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 wm(e){let{classes:o}=Am(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return(0,P.jsx)(Wo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:(0,P.jsx)(pr,{...e}),children:(0,P.jsx)("p",{children:e.resource.payload?.[0]?.contentString})})}function Om(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return(0,P.jsx)(Wo,{resource:e.resource,padding:!!t,popupMenuItems:(0,P.jsx)(pr,{...e}),children:(0,P.jsx)(lo,{value:e.resource.content})})}function Em(e){return(0,P.jsx)(Wo,{resource:e.resource,padding:!0,popupMenuItems:(0,P.jsx)(pr,{...e}),children:(0,P.jsx)(ne.ScrollArea,{children:(0,P.jsx)("pre",{children:e.resource.outcomeDesc})})})}function Lm(e){return(0,P.jsx)(Wo,{resource:e.resource,padding:!0,popupMenuItems:(0,P.jsx)(pr,{...e}),children:(0,P.jsx)(hn,{value:e.resource})})}function Nm(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Al(e.loaded)} / ${Al(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Al(e.loaded)}`}function Al(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"}var Tu=require("react/jsx-runtime");function Hm(e){return(0,Tu.jsx)(Jo,{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})])}})}var Ml=require("react/jsx-runtime");function ia(e){let{children:o,...t}=e;return(0,Ml.jsx)(Go,{children:(0,Ml.jsx)(Ht,{...t,children:o})})}var ua=require("@medplum/core");var ku=require("react/jsx-runtime");function Vm(e){return(0,ku.jsx)(Jo,{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:(0,ua.createReference)(o),subject:o.subject,sender:(0,ua.createReference)(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:(0,ua.createReference)(o),subject:o.subject,operator:(0,ua.createReference)(t),issued:new Date().toISOString(),content:r})})}var Cr=require("@mantine/core"),Gu=require("@medplum/core");var Je=require("react");var Bu=require("@medplum/core");var Mu=require("react/jsx-runtime");function Au(e){let o;try{o=(0,Bu.evalFhirPath)(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(0,Mu.jsx)(De,{value:o[0]||"",propertyType:e.propertyType})}var H=require("@mantine/core"),yr=require("@medplum/core");var Ge=require("react");var ct=require("@mantine/core"),ut=require("react/jsx-runtime");function wu(e){return(0,ut.jsxs)(ct.Modal,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[(0,ut.jsxs)(ct.Box,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&(0,ut.jsx)(Fu,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,ut.jsx)(Fu,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),(0,ut.jsx)(ct.Text,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function Fu(e){return(0,ut.jsx)(ct.Button,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}var Po=require("@mantine/core"),hr=require("@medplum/core"),$o=require("react");var B=require("@medplum/core");var xr=require("react/jsx-runtime"),qm={string:[B.Operator.EQUALS,B.Operator.NOT,B.Operator.CONTAINS,B.Operator.EXACT],fulltext:[B.Operator.EQUALS,B.Operator.NOT,B.Operator.CONTAINS,B.Operator.EXACT],token:[B.Operator.EQUALS,B.Operator.NOT],reference:[B.Operator.EQUALS,B.Operator.NOT],numeric:[B.Operator.EQUALS,B.Operator.NOT_EQUALS,B.Operator.GREATER_THAN,B.Operator.LESS_THAN,B.Operator.GREATER_THAN_OR_EQUALS,B.Operator.LESS_THAN_OR_EQUALS],quantity:[B.Operator.EQUALS,B.Operator.NOT_EQUALS,B.Operator.GREATER_THAN,B.Operator.LESS_THAN,B.Operator.GREATER_THAN_OR_EQUALS,B.Operator.LESS_THAN_OR_EQUALS],date:[B.Operator.EQUALS,B.Operator.NOT_EQUALS,B.Operator.GREATER_THAN,B.Operator.LESS_THAN,B.Operator.GREATER_THAN_OR_EQUALS,B.Operator.LESS_THAN_OR_EQUALS,B.Operator.STARTS_AFTER,B.Operator.ENDS_BEFORE,B.Operator.APPROXIMATELY],datetime:[B.Operator.EQUALS,B.Operator.NOT_EQUALS,B.Operator.GREATER_THAN,B.Operator.LESS_THAN,B.Operator.GREATER_THAN_OR_EQUALS,B.Operator.LESS_THAN_OR_EQUALS,B.Operator.STARTS_AFTER,B.Operator.ENDS_BEFORE,B.Operator.APPROXIMATELY]},Gm={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 Ir(e,o){return{...e,filters:o,offset:0,name:void 0}}function Um(e){return Ir(e,[])}function ca(e,o){return Ir(e,(e.filters??[]).filter(t=>t.code!==o))}function qt(e,o,t,r,a){a&&(e=ca(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Ir(e,n)}function Qm(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 Fl(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function wl(e,o){return Ll(e,o,-1)}function Ol(e,o){return Ll(e,o,0)}function El(e,o){return Ll(e,o,1)}function Ll(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),Pn(e,o,r,a)}function Nl(e,o){return ql(e,o,-1)}function Hl(e,o){return ql(e,o,0)}function Vl(e,o){return ql(e,o,1)}function ql(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),Pn(e,o,r,a)}function Gl(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Pn(e,o,t,new Date)}function Pn(e,o,t,r){return e=ca(e,o),e=Ou(e,o,B.Operator.GREATER_THAN_OR_EQUALS,t),e=Ou(e,o,B.Operator.LESS_THAN_OR_EQUALS,r),e}function Ou(e,o,t,r){return qt(e,o,t,r.toISOString())}function Dn(e,o,t=!0){return qt(e,o,B.Operator.MISSING,t.toString())}function Eu(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function Ul(e,o){let t=e.count??B.DEFAULT_SEARCH_COUNT,r=(o-1)*t;return Eu(e,r)}function Tn(e,o,t){return o===Ql(e)&&t!==void 0&&t===zl(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function zm(e,o){let t=!1;return Ql(e)===o&&(t=!zl(e)),Tn(e,o,t)}function Ql(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function zl(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function Wl(e){return qm[e.type]}function gr(e){return Gm[e]??""}function We(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(B.capitalize).join(" "))}function Xl(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?(0,B.formatDateTime)(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?Wm(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?Xm(e,o.searchParams[0]):null}function Wm(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=yo({type:e.resourceType,value:e},t);return r?(0,xr.jsx)(De,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function Xm(e,o){let t=(0,B.evalFhirPathTyped)(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:(0,xr.jsx)(xr.Fragment,{children:t.map((r,a)=>(0,xr.jsx)(De,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}var dt=require("react/jsx-runtime");function Jl(e){let o=(0,$o.useRef)(!1),[t,r]=(0,$o.useState)({search:JSON.parse((0,hr.stringify)(e.search))}),[a,n]=(0,$o.useState)(!1);(0,$o.useEffect)(()=>{r({search:e.search})},[e.search]);let f=(0,$o.useMemo)(()=>{if(!e.visible)return[];let l=e.search.resourceType,i=(0,hr.getDataType)(l),u=(0,hr.getSearchParameters)(l);return Jm(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:We(d)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function s(l){r({search:{...t.search,fields:l}})}return(0,dt.jsx)(Po.Modal,{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:(0,dt.jsx)("div",{"data-testid":"overlay-child"})},children:(0,dt.jsxs)(Po.Stack,{children:[(0,dt.jsx)(Po.MultiSelect,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:f,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}),(0,dt.jsx)(Po.Group,{position:"right",children:(0,dt.jsx)(Po.Button,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function Jm(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(We(n));if(o)for(let n of Object.keys(o)){let f=We(n);!r.has(n)&&!a.has(f)&&(t.push(n),r.add(n),a.add(f))}return t}var Xe=require("@mantine/core"),da=require("@medplum/core"),Ko=require("react");var uo=require("@medplum/core");var Gt=require("react/jsx-runtime");function kn(e){let{resourceType:o,filter:t}=e,r=uo.globalSchema.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===uo.Operator.EQUALS||t.operator===uo.Operator.NOT_EQUALS))return(0,Gt.jsx)(so,{value:{reference:t.value}});let a=(0,uo.getSearchParameterDetails)(o,r);if(t.code==="_lastUpdated"||a.type===uo.SearchParameterType.DATETIME)return(0,Gt.jsx)(Gt.Fragment,{children:(0,uo.formatDateTime)(t.value)})}return(0,Gt.jsx)(Gt.Fragment,{children:t.value})}var vr=require("@mantine/core"),_o=require("@medplum/core");var mt=require("react/jsx-runtime");function Bn(e){let o=(0,_o.getSearchParameterDetails)(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case _o.SearchParameterType.REFERENCE:return(0,mt.jsx)(Lt,{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 _o.SearchParameterType.BOOLEAN:return(0,mt.jsx)(vr.Checkbox,{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 _o.SearchParameterType.DATE:return(0,mt.jsx)(vr.TextInput,{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 _o.SearchParameterType.DATETIME:return(0,mt.jsx)(to,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case _o.SearchParameterType.NUMBER:return(0,mt.jsx)(vr.TextInput,{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 _o.SearchParameterType.QUANTITY:return(0,mt.jsx)(Ue,{name:t,defaultValue:$m(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return(0,mt.jsx)(vr.TextInput,{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 $m(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}var L=require("react/jsx-runtime");function $l(e){let[o,t]=(0,Ko.useState)(JSON.parse((0,da.stringify)(e.search))),[r,a]=(0,Ko.useState)(-1),n=(0,Ko.useRef)(o);n.current=o,(0,Ko.useEffect)(()=>{t(JSON.parse((0,da.stringify)(e.search)))},[e.search]);function f(u){t(qt(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let s=e.search.resourceType,l=(0,da.getSearchParameters)(s)??{},i=o.filters||[];return(0,L.jsxs)(Xe.Modal,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[(0,L.jsx)("div",{children:(0,L.jsxs)("table",{children:[(0,L.jsxs)("colgroup",{children:[(0,L.jsx)("col",{style:{width:200}}),(0,L.jsx)("col",{style:{width:200}}),(0,L.jsx)("col",{style:{width:380}}),(0,L.jsx)("col",{style:{width:120}})]}),(0,L.jsx)("thead",{children:(0,L.jsxs)("tr",{children:[(0,L.jsx)("th",{children:"Field"}),(0,L.jsx)("th",{children:"Operation"}),(0,L.jsx)("th",{children:"Value"}),(0,L.jsx)("th",{children:"Actions"})]})}),(0,L.jsxs)("tbody",{children:[i.map((u,d)=>d===r?(0,L.jsx)(Lu,{resourceType:s,searchParams:l,defaultValue:u,okText:"Save",onOk:c=>{let m=[...i];m[d]=c,t(Ir(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):(0,L.jsx)(_m,{resourceType:s,searchParams:l,filter:u,onEdit:()=>a(d),onDelete:()=>t(Fl(n.current,d))},`filter-${u.code}-${u.operator}-${u.value}-display`)),(0,L.jsx)(Lu,{resourceType:s,searchParams:l,okText:"Add",onOk:f})]})]})}),(0,L.jsx)(Xe.Group,{position:"right",mt:"xl",children:(0,L.jsx)(Xe.Button,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function _m(e){let{filter:o}=e;return(0,L.jsxs)("tr",{children:[(0,L.jsx)("td",{children:We(o.code)}),(0,L.jsx)("td",{children:gr(o.operator)}),(0,L.jsx)("td",{children:(0,L.jsx)(kn,{resourceType:e.resourceType,filter:o})}),(0,L.jsxs)("td",{children:[(0,L.jsx)(Xe.Button,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),(0,L.jsx)(Xe.Button,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function Lu(e){let[o,t]=(0,Ko.useState)(e.defaultValue??{}),r=(0,Ko.useRef)(o);r.current=o;function a(i){t({...r.current,code:i})}function n(i){t({...r.current,operator:i})}function f(i){t({...r.current,value:i})}let s=e.searchParams[o.code],l=s&&Wl(s);return(0,L.jsxs)("tr",{children:[(0,L.jsx)("td",{children:(0,L.jsx)(Xe.NativeSelect,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:We(i)}))]})}),(0,L.jsx)("td",{children:l&&(0,L.jsx)(Xe.NativeSelect,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...l.map(i=>({value:i,label:gr(i)}))]})}),(0,L.jsx)("td",{children:s&&o.operator&&(0,L.jsx)(Bn,{resourceType:e.resourceType,searchParam:s,defaultValue:o.value,onChange:f})}),(0,L.jsxs)("td",{children:[o.code&&o.operator&&(0,L.jsx)(Xe.Button,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&(0,L.jsx)(Xe.Button,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}var pt=require("@mantine/core"),Nu=require("react");var Zo=require("react/jsx-runtime");function Hu(e){let[o,t]=(0,Nu.useState)(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return(0,Zo.jsx)(pt.Modal,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:(0,Zo.jsx)(oe,{onSubmit:r,children:(0,Zo.jsxs)(pt.Grid,{children:[(0,Zo.jsx)(pt.Grid.Col,{span:10,children:(0,Zo.jsx)(Bn,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),(0,Zo.jsx)(pt.Grid.Col,{span:2,children:(0,Zo.jsx)(pt.Button,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}var M=require("@mantine/core"),Pe=require("@medplum/core");var p=require("react/jsx-runtime");function Vu(e){if(!e.searchParams)return null;function o(n,f){a(Tn(e.search,n.code,f))}function t(n){a(ca(e.search,n.code))}function r(n,f){e.onPrompt(n,{code:n.code,operator:f,value:""})}function a(n){e.onChange(n)}return e.searchParams.length===1?(0,p.jsx)(Km,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):(0,p.jsx)(M.Menu.Dropdown,{children:e.searchParams.map(n=>(0,p.jsx)(M.Menu.Item,{children:We(n.code)},n.code))})}function Km(e){switch(e.searchParam.type){case"date":return(0,p.jsx)(Zm,{...e});case"number":case"quantity":return(0,p.jsx)(Ym,{...e});case"reference":return(0,p.jsx)(jm,{...e});case"string":case"token":case"uri":return(0,p.jsx)(ep,{...e});default:return(0,p.jsxs)(p.Fragment,{children:["Unknown search param type: ",e.searchParam.type]})}}function Zm(e){let{searchParam:o}=e,t=o.code;return(0,p.jsxs)(M.Menu.Dropdown,{children:[(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Or,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Er,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Kt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Equals..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(_t,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.NOT_EQUALS),children:"Does not equal..."}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oa,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.ENDS_BEFORE),children:"Before..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(wa,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.STARTS_AFTER),children:"After..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(cf,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Between..."}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(El(e.search,t)),children:"Tomorrow"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(Ol(e.search,t)),children:"Today"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(wl(e.search,t)),children:"Yesterday"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(Vl(e.search,t)),children:"Next Month"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(Hl(e.search,t)),children:"This Month"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(Nl(e.search,t)),children:"Last Month"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oo,{size:14}),onClick:()=>e.onChange(Gl(e.search,t)),children:"Year to date"}),(0,p.jsx)(An,{...e})]})}function Ym(e){let{searchParam:o}=e;return(0,p.jsxs)(M.Menu.Dropdown,{children:[(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Or,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Er,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Kt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Equals..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(_t,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.NOT_EQUALS),children:"Does not equal..."}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(wa,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.GREATER_THAN),children:"Greater than..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Zt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Oa,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.LESS_THAN),children:"Less than..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Zt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),(0,p.jsx)(An,{...e})]})}function jm(e){let{searchParam:o}=e;return(0,p.jsxs)(M.Menu.Dropdown,{children:[(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Kt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Equals..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(_t,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.NOT),children:"Does not equal..."}),(0,p.jsx)(An,{...e})]})}function ep(e){let{searchParam:o}=e;return(0,p.jsxs)(M.Menu.Dropdown,{children:[(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Or,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Er,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Kt,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Equals..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(_t,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.NOT),children:"Does not equal..."}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(mf,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.CONTAINS),children:"Contains..."}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(df,{size:14}),onClick:()=>e.onPrompt(o,Pe.Operator.EQUALS),children:"Does not contain..."}),(0,p.jsx)(An,{...e})]})}function An(e){let{searchParam:o}=e,t=o.code;return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(sf,{size:14}),onClick:()=>e.onChange(Dn(e.search,t)),children:"Missing"}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(lf,{size:14}),onClick:()=>e.onChange(Dn(e.search,t,!1)),children:"Not missing"}),(0,p.jsx)(M.Menu.Divider,{}),(0,p.jsx)(M.Menu.Item,{icon:(0,p.jsx)(Of,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}var xt=require("@medplum/core");function _l(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(op(o,r));return t}function op(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=(0,xt.getElementDefinition)(e,o),r=(0,xt.getSearchParameter)(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=(0,xt.getSearchParameters)(e),n;if(a){let f=new RegExp(`${e}\\.${o.replaceAll("[x]","")}([^\\w-]|$)`);n=Object.values(a).filter(s=>!!s.expression&&f.test(s?.expression)),n.length===0&&(n=void 0)}return{name:o,elementDefinition:t,searchParams:n}}if(r){let a=(0,xt.getSearchParameterDetails)(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}var R=require("react/jsx-runtime"),Mn=class extends Event{constructor(t){super("change");this.definition=t}},Fn=class extends Event{constructor(t){super("load");this.response=t}},It=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},tp=(0,H.createStyles)(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 qu(e){let{classes:o}=tp(),t=D(),[r,a]=(0,Ge.useState)(!1),[n,f]=(0,Ge.useState)(),{search:s,onLoad:l}=e,[i,u]=(0,Ge.useState)({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),d=(0,Ge.useRef)(i);d.current=i;let c=s.total??"accurate",m=(0,Ge.useCallback)(S=>{f(void 0),t.search(s.resourceType,(0,yr.formatSearchQuery)({...s,total:c,fields:void 0}),S).then(X=>{u({...d.current,searchResponse:X}),l&&l(new Fn(X))}).catch(X=>{u({...d.current,searchResponse:void 0}),f(X)})},[t,s,c,l]),h=(0,Ge.useCallback)(()=>{u({...d.current,searchResponse:void 0}),m({cache:"reload"})},[m]);(0,Ge.useEffect)(()=>{m()},[m]);function g(S,X){S.stopPropagation();let Re=S.target.checked,ve={...d.current.selected};Re?ve[X]=!0:delete ve[X],u({...d.current,selected:ve})}function y(S){S.stopPropagation();let Mo=S.target.checked,Re={},ve=d.current.searchResponse;Mo&&ve?.entry&&ve.entry.forEach(eo=>{eo.resource?.id&&(Re[eo.resource.id]=!0)}),u({...d.current,selected:Re})}function k(){let S=d.current;if(!S.searchResponse?.entry||S.searchResponse.entry.length===0)return!1;for(let X of S.searchResponse.entry)if(X.resource?.id&&!S.selected[X.resource.id])return!1;return!0}function T(S){e.onChange&&e.onChange(new Mn(S))}function A(S,X){if(Ha(S.target)||S.button===2)return;N(S);let Mo=S.button===1||S.ctrlKey||S.metaKey;!Mo&&e.onClick&&e.onClick(new It(X,S)),Mo&&e.onAuxClick&&e.onAuxClick(new It(X,S))}function _(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if((0,Ge.useEffect)(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return(0,R.jsx)(H.Center,{style:{width:"100%",height:"100%"},children:(0,R.jsx)(H.Loader,{})});let C=e.checkboxesEnabled,E=_l(s),se=s.resourceType,Se=i.searchResponse,Ct=Se?.entry?.map(S=>S.resource),Me="subtle",v="gray",U=16,xo=window.innerWidth<768;return(0,R.jsxs)("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&(0,R.jsxs)(H.Group,{position:"apart",mb:"xl",children:[(0,R.jsxs)(H.Group,{spacing:2,children:[(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(If,{size:U}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(Sf,{size:U}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(Cf,{size:U}),onClick:e.onNew,children:"New..."}),!xo&&_()&&(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(wf,{size:U}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!xo&&e.onDelete&&(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(Lr,{size:U}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!xo&&e.onBulk&&(0,R.jsx)(H.Button,{compact:!0,variant:Me,color:v,leftIcon:(0,R.jsx)(uf,{size:U}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),(0,R.jsxs)(H.Group,{spacing:2,children:[Se&&(0,R.jsxs)(H.Text,{size:"xs",color:"dimmed",children:[lp(s,Se.total),"-",sp(s,Se.total)," of"," ",`${c==="estimate"?"~":""}${Se.total?.toLocaleString()}`]}),(0,R.jsx)(H.ActionIcon,{title:"Refresh",onClick:h,children:(0,R.jsx)(Bf,{size:"1.125rem"})})]})]}),(0,R.jsxs)(H.Table,{className:o.table,children:[(0,R.jsxs)("thead",{children:[(0,R.jsxs)("tr",{children:[C&&(0,R.jsx)("th",{children:(0,R.jsx)("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:k(),onChange:S=>y(S)})}),E.map(S=>(0,R.jsx)("th",{children:(0,R.jsxs)(H.Menu,{shadow:"md",width:240,position:"bottom-end",children:[(0,R.jsx)(H.Menu.Target,{children:(0,R.jsx)(H.UnstyledButton,{className:o.control,children:(0,R.jsxs)(H.Group,{position:"apart",noWrap:!0,children:[(0,R.jsx)(H.Text,{weight:500,size:"sm",children:We(S.name)}),(0,R.jsx)(H.Center,{className:o.icon,children:(0,R.jsx)(af,{size:14,stroke:1.5})})]})})}),(0,R.jsx)(Vu,{search:e.search,searchParams:S.searchParams,onPrompt:(X,Mo)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:X,filterDialogFilter:Mo})},onChange:X=>{T(X)}})]})},S.name))]}),!e.hideFilters&&(0,R.jsxs)("tr",{children:[C&&(0,R.jsx)("th",{}),E.map(S=>(0,R.jsx)("th",{children:S.searchParams&&(0,R.jsx)(ap,{resourceType:se,searchParams:S.searchParams,filters:e.search.filters})},S.name))]})]}),(0,R.jsx)("tbody",{children:Ct?.map(S=>S&&(0,R.jsxs)("tr",{className:o.tr,"data-testid":"search-control-row",onClick:X=>A(X,S),onAuxClick:X=>A(X,S),children:[C&&(0,R.jsx)("td",{children:(0,R.jsx)("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${S.id}`,checked:!!i.selected[S.id],onChange:X=>g(X,S.id)})}),E.map(X=>(0,R.jsx)("td",{children:Xl(S,X)},X.name))]},S.id))})]}),Ct?.length===0&&(0,R.jsx)(Go,{children:(0,R.jsx)(H.Center,{style:{height:150},children:(0,R.jsx)(H.Text,{size:"xl",color:"dimmed",children:"No results"})})}),Se?.total!==void 0&&Se.total>0&&(0,R.jsx)(H.Center,{m:"md",p:"md",children:(0,R.jsx)(H.Pagination,{value:np(s),total:fp(s,Se.total),onChange:S=>T(Ul(s,S)),getControlProps:S=>{switch(S){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&(0,R.jsx)("div",{"data-testid":"search-error",children:(0,R.jsx)("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),(0,R.jsx)(Jl,{search:e.search,visible:d.current.fieldEditorVisible,onOk:S=>{T(S),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),(0,R.jsx)($l,{search:e.search,visible:d.current.filterEditorVisible,onOk:S=>{T(S),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),(0,R.jsx)(wu,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),(0,R.jsx)(Hu,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?We(i.filterDialogSearchParam.code):"",resourceType:se,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:S=>{T(qt(e.search,S.code,S.operator,S.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var rp=(0,Ge.memo)(qu);function ap(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?(0,R.jsx)("span",{children:"no filters"}):(0,R.jsx)(R.Fragment,{children:o.map(t=>(0,R.jsxs)("div",{children:[gr(t.operator),"\xA0",(0,R.jsx)(kn,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function np(e){return Math.floor((e.offset??0)/(e.count??yr.DEFAULT_SEARCH_COUNT))+1}function fp(e,o){let t=e.count??yr.DEFAULT_SEARCH_COUNT;return Math.ceil(o/t)}function lp(e,o){return Math.min(o,(e.offset??0)+1)}function sp(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??yr.DEFAULT_SEARCH_COUNT))}var ge=require("react/jsx-runtime");function Uu(e){let o=D(),[t,r]=(0,Je.useState)(!1),[a,n]=(0,Je.useState)(),{query:f,fields:s}=e,[l,i]=(0,Je.useState)(),[u,d]=(0,Je.useState)({}),c=(0,Je.useRef)();c.current=l;let m=(0,Je.useRef)({});m.current=u,(0,Je.useEffect)(()=>{n(void 0),o.graphql(f).then(i).catch(A=>n((0,Gu.normalizeOperationOutcome)(A)))},[o,f]);function h(A,_){A.stopPropagation();let E=A.target.checked,se={...m.current};E?se[_]=!0:delete se[_],d(se)}function g(A){A.stopPropagation();let C=A.target.checked,E={},se=c.current?.data.ResourceList;C&&se&&se.forEach(Se=>{Se.id&&(E[Se.id]=!0)}),d(E)}function y(){let A=c.current?.data.ResourceList;if(!A||A.length===0)return!1;for(let _ of A)if(_.id&&!m.current[_.id])return!1;return!0}function k(A,_){Ha(A.target)||(N(A),A.button!==1&&e.onClick&&e.onClick(new It(_,A)),A.button===1&&e.onAuxClick&&e.onAuxClick(new It(_,A)))}if((0,Je.useEffect)(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return(0,ge.jsx)(Cr.Loader,{});let T=e.checkboxesEnabled;return(0,ge.jsxs)("div",{onContextMenu:A=>N(A),"data-testid":"search-control",children:[(0,ge.jsxs)(Cr.Table,{children:[(0,ge.jsx)("thead",{children:(0,ge.jsxs)("tr",{children:[T&&(0,ge.jsx)("th",{children:(0,ge.jsx)("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:y(),onChange:A=>g(A)})}),s.map(A=>(0,ge.jsx)("th",{children:A.name},A.name))]})}),(0,ge.jsx)("tbody",{children:l?.data.ResourceList.map(A=>A&&(0,ge.jsxs)("tr",{"data-testid":"search-control-row",onClick:_=>k(_,A),onAuxClick:_=>k(_,A),children:[T&&(0,ge.jsx)("td",{children:(0,ge.jsx)("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${A.id}`,checked:!!u[A.id],onChange:_=>h(_,A.id)})}),s.map(_=>(0,ge.jsx)("td",{children:(0,ge.jsx)(Au,{propertyType:_.propertyType,path:_.fhirPath,resource:A})},_.name))]},A.id))})]}),l?.data.ResourceList.length===0&&(0,ge.jsx)("div",{"data-testid":"empty-search",children:"No results"}),a&&(0,ge.jsx)("div",{"data-testid":"search-error",children:(0,ge.jsx)("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&(0,ge.jsx)(Cr.Button,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var ip=(0,Je.memo)(Uu);var Yo=require("react/jsx-runtime");function jo(e){return(0,Yo.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[(0,Yo.jsx)("title",{children:"Medplum Logo"}),(0,Yo.jsx)("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),(0,Yo.jsx)("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"}),(0,Yo.jsx)("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"}),(0,Yo.jsx)("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),(0,Yo.jsx)("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}var wn=require("@mantine/core");var re=require("@mantine/core"),Kl=require("@medplum/core");var J=require("react/jsx-runtime");function Qu(e){let{group:o}=e;return(0,J.jsx)(re.Paper,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:(0,J.jsxs)(re.Group,{children:[o.measureScore&&(0,J.jsx)(cp,{group:o}),!o.measureScore&&(0,J.jsx)(up,{group:o})]})})}function zu(e){let{measure:o}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(re.Text,{fz:"md",fw:500,mb:8,children:o.title}),(0,J.jsx)(re.Text,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function up(e){let{group:o}=e,t=o.population,r=t?.find(l=>(0,Kl.formatCodeableConcept)(l.code)==="numerator"),a=t?.find(l=>(0,Kl.formatCodeableConcept)(l.code)==="denominator"),n=r?.count,f=a?.count;if(f===0)return(0,J.jsxs)(re.Box,{children:[(0,J.jsx)(re.Title,{order:3,children:"Not Applicable"}),(0,J.jsx)(re.Text,{children:`Denominator: ${f}`})]});if(n===void 0||f===void 0)return(0,J.jsxs)(re.Box,{children:[(0,J.jsx)(re.Title,{order:3,children:"Insufficient Data"}),(0,J.jsx)(re.Text,{children:`Numerator: ${n}`}),(0,J.jsx)(re.Text,{children:`Denominator: ${f}`})]});let s=n/f*100;return(0,J.jsx)(re.RingProgress,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:Wu(s)}],label:(0,J.jsx)(re.Flex,{justify:"center",children:(0,J.jsxs)(re.Text,{fw:700,fz:18,children:[n," / ",f]})})})}function cp(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return(0,J.jsx)(J.Fragment,{children:t==="%"?(0,J.jsx)(re.RingProgress,{size:120,thickness:12,roundCaps:!0,sections:[{value:dp(o),color:Wu(o?.measureScore?.value??0)}],label:(0,J.jsx)(re.Flex,{justify:"center",children:(0,J.jsx)(re.Text,{fw:700,fz:18,children:(0,J.jsx)(No,{value:o.measureScore})})})}):(0,J.jsx)(re.Flex,{h:120,align:"center",children:(0,J.jsx)(re.Title,{order:3,children:(0,J.jsx)(No,{value:o.measureScore})})})})}function dp(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function Wu(e){return e<=33?"red":e<=67?"yellow":"green"}var Sr=require("react/jsx-runtime");function mp(e){let o=K(e.measureReport),[t]=Yn("Measure",{url:o?.measure});return o?(0,Sr.jsxs)(wn.Box,{children:[t&&(0,Sr.jsx)(zu,{measure:t}),(0,Sr.jsx)(wn.SimpleGrid,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>(0,Sr.jsx)(Qu,{group:r},r.id??a))})]}):null}var Xu=require("@mantine/core"),Ju=require("@medplum/core");var On=require("react/jsx-runtime");function Ut(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:(0,On.jsx)(Xu.Alert,{icon:(0,On.jsx)(Pt,{size:16}),color:"red",children:o.map(t=>(0,On.jsx)("div",{"data-testid":"text-field-error",children:(0,Ju.operationOutcomeIssueToString)(t)},t.details?.text))})}var ma=require("@medplum/core"),$u=require("react");var _u=require("react/jsx-runtime");function pp(e){let o=(0,$u.useCallback)((t,r,a)=>{let n=`${r}/${a}`,f=100;return Promise.allSettled([t.readHistory("Patient",a),t.search("Communication",{subject:n,_count:f}),t.search("Device",{patient:n,_count:f}),t.search("DeviceRequest",{patient:n,_count:f}),t.search("DiagnosticReport",{subject:n,_count:f}),t.search("Media",{subject:n,_count:f}),t.search("ServiceRequest",{subject:n,_count:f}),t.search("Task",{subject:n,_count:f})])},[]);return(0,_u.jsx)(Jo,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:(0,ma.createReference)(t),sender:(0,ma.createReference)(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:(0,ma.createReference)(t),operator:(0,ma.createReference)(r),issued:new Date().toISOString(),content:a})})}var Oe=require("@mantine/core"),Ku=require("@medplum/core");var no=require("react");var V=require("react/jsx-runtime"),Zu=(0,Oe.createStyles)(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 xp(e){let o=D(),t=K(e.value),[r,a]=(0,no.useState)(!1),[n,f]=(0,no.useState)(),[s,l]=(0,no.useState)(),[i,u]=(0,no.useState)();function d(){l(void 0)}function c(){f(void 0)}let m=(0,no.useRef)();if(m.current=i,(0,no.useEffect)(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),(0,no.useEffect)(()=>(u(Cp(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(g,y){u({...m.current,[g]:y})}return(0,V.jsx)("div",{children:(0,V.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[(0,V.jsx)(Oe.TextInput,{label:"Plan Title",defaultValue:i.title,onChange:g=>h("title",g.currentTarget.value)}),(0,V.jsx)(Yu,{actions:i.action||[],selectedKey:n,setSelectedKey:f,hoverKey:s,setHoverKey:l,onChange:g=>h("action",g)}),(0,V.jsx)(Oe.Button,{type:"submit",children:"Save"})]})})}function Yu(e){let{classes:o}=Zu(),t=(0,no.useRef)();t.current=e.actions;function r(f){e.onChange(t.current.map(s=>s.id===f.id?f:s))}function a(f){e.onChange([...t.current,f]),e.setSelectedKey(f.id)}function n(f){e.onChange(t.current.filter(s=>s!==f))}return(0,V.jsxs)("div",{className:o.section,children:[e.actions.map(f=>(0,V.jsx)("div",{children:(0,V.jsx)(Ip,{action:f,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(f)})},f.id)),(0,V.jsx)("div",{className:o.bottomActions,children:(0,V.jsx)(Oe.Anchor,{href:"#",onClick:f=>{N(f),a({id:ec()})},children:"Add action"})})]})}function Ip(e){let{classes:o,cx:t}=Zu(),{action:r}=e,a=yp(r),n=e.selectedKey===e.action.id,f=e.hoverKey===e.action.id;function s(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function l(u){N(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:f&&!n});return(0,V.jsxs)("div",{"data-testid":r.id,className:i,onClick:s,onMouseOver:l,onFocus:l,children:[n?(0,V.jsx)(hp,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):(0,V.jsx)(gp,{action:r,actionType:a}),(0,V.jsx)("div",{className:o.bottomActions,children:(0,V.jsx)(Oe.Anchor,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Yl={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function gp(e){let{action:o,actionType:t}=e,[r,a]=ju(o);return(0,V.jsxs)("div",{children:[(0,V.jsxs)("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&(0,V.jsx)("div",{children:(0,V.jsx)(at,{value:{reference:o.definitionCanonical}})}),r&&(0,V.jsx)("div",{children:(0,V.jsx)(De,{property:Yl,propertyType:a,value:r})})]})}function hp(e){let{action:o}=e,[t,r]=(0,no.useState)(e.actionType);function a(n,f){e.onChange({...o,[n]:f})}return(0,V.jsxs)(Oe.Stack,{spacing:"xl",children:[(0,V.jsx)(Oe.TextInput,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),(0,V.jsx)(Oe.TextInput,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),(0,V.jsx)(Oe.NativeSelect,{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&&(0,V.jsx)(Yu,{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(0,V.jsx)(En,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return(0,V.jsx)(En,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return(0,V.jsx)(En,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return(0,V.jsx)(En,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),(0,V.jsx)(Ve,{title:"Timing",description:"When the action should take place.",children:(0,V.jsx)(vp,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function En(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return(0,V.jsx)(aa,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:(0,Ku.getReferenceString)(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function vp(e){let o=e.action,t="timing",[r,a]=ju(o);return(0,V.jsx)(Co,{property:Yl,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,f)=>{e.onChange(Jr(o,t,f??t,Yl,n))}})}function yp(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function ju(e){return yo({type:"PlanDefinitionAction",value:e},"timing")}var Zl=1;function ec(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Zl=Math.max(Zl,o+1))}return e}return"id-"+Zl++}function Cp(e){return{...e,action:oc(e.action)}}function oc(e){if(e)return e.map(o=>({...o,id:ec(o.id),action:oc(o.action)}))}var G=require("@mantine/core"),Hn=require("@medplum/core");var Do=require("react");var he=require("@mantine/core"),j=require("@medplum/core"),lc=require("react");var xe=require("@medplum/core"),pa=(k=>(k.group="group",k.display="display",k.question="question",k.boolean="boolean",k.decimal="decimal",k.integer="integer",k.date="date",k.dateTime="dateTime",k.time="time",k.string="string",k.text="text",k.url="url",k.choice="choice",k.openChoice="open-choice",k.attachment="attachment",k.reference="reference",k.quantity="quantity",k))(pa||{});function jl(e){return e.type==="choice"||e.type==="open-choice"}function es(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=tc(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:f}=Rp(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!f)return!1}return t!=="any"}function os(e,o,t){return e.map(r=>{let a=t.answerOption?.find(f=>(0,xe.formatCoding)(f.valueCoding)===r||f[o]===r),n=(0,xe.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function tc(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=tc(t.item,o);if(r)return r}}}function Sp(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=(0,xe.evalFhirPathTyped)(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function Rp(e,o,t){let r=o||[],a=(0,xe.getTypedPropertyValue)({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,f=!0;for(let s of r){let l=(0,xe.getTypedPropertyValue)({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(Sp(l,a,i)?n=!0:f=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:f}}function xa(e){let o=(0,xe.getExtension)(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 Ia(e,o){let t=(0,xe.deepClone)(e),r=(0,xe.getExtension)(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 ts(e,o,t){let r=(0,xe.getExtension)(e,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceFilter");if(!r?.valueString)return;let a=r.valueString;o?.reference&&(a=a.replaceAll("$subj",o.reference)),t?.reference&&(a=a.replaceAll("$encounter",t.reference));let n={},f=a.split("&");for(let s of f){let[l,i]=(0,xe.splitN)(s,"=",2);n[l]=i}return n}function rs(e){return{resourceType:"QuestionnaireResponse",questionnaire:(0,xe.getReferenceString)(e),item:rc(e.item)}}function rc(e){return e?.map(Ln)??[]}function Ln(e){return{id:Pp(),linkId:e.linkId,text:e.text,item:rc(e.item),answer:e.initial?.map(Dp)??[]}}var bp=1;function Pp(){return"id-"+bp++}function Dp(e){return{...e}}function as(e){return e.value.display||e.value.reference||(0,xe.stringify)(e.value)}function ns(e){let o=e?.item?.[0];return o&&(0,xe.getExtension)(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}var ac=require("react"),Nn=(0,ac.createContext)({});var Y=require("react/jsx-runtime");function ga(e){let o=(0,lc.useContext)(Nn),t=e.item,r=e.response;function a(i){let u;Array.isArray(i)?u=i:e.index>=(e.response?.answer?.length??0)?u=(e.response?.answer??[]).concat([i]):u=(e.response?.answer??[]).map((c,m)=>m===e.index?i:c)??[],e.onChange({id:r?.id,linkId:r?.linkId,text:t.text,answer:u})}let n=t.type;if(!n)return null;let f=t.linkId;if(!f)return null;let s=t.initial&&t.initial.length>0?t.initial[0]:void 0,l=fs(r,e.index)??(0,j.getTypedPropertyValue)({type:"QuestionnaireItemInitial",value:s},"value");switch(n){case"display":return(0,Y.jsx)("p",{children:e.item.text},e.item.linkId);case"boolean":return(0,Y.jsx)(Wr,{title:e.item.text,htmlFor:e.item.linkId,children:(0,Y.jsx)(he.Checkbox,{id:e.item.linkId,name:e.item.linkId,defaultChecked:l?.value,onChange:i=>a({valueBoolean:i.currentTarget.checked})})},e.item.linkId);case"decimal":return(0,Y.jsx)(he.TextInput,{type:"number",step:"any",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDecimal:i.currentTarget.valueAsNumber})});case"integer":return(0,Y.jsx)(he.TextInput,{type:"number",step:1,id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueInteger:i.currentTarget.valueAsNumber})});case"date":return(0,Y.jsx)(he.TextInput,{type:"date",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDate:i.currentTarget.value})});case"dateTime":return(0,Y.jsx)(to,{name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDateTime:i})});case"time":return(0,Y.jsx)(he.TextInput,{type:"time",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueTime:i.currentTarget.value})});case"string":case"url":return(0,Y.jsx)(he.TextInput,{id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"text":return(0,Y.jsx)(he.Textarea,{id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"attachment":return(0,Y.jsx)(he.Group,{py:4,children:(0,Y.jsx)(Gr,{name:f,defaultValue:l?.value,onChange:i=>a({valueAttachment:i})})});case"reference":return(0,Y.jsx)(Lt,{name:f,required:t.required,targetTypes:xa(t),searchCriteria:ts(t,o.subject,o.encounter),defaultValue:l?.value,onChange:i=>a({valueReference:i})});case"quantity":return(0,Y.jsx)(Ue,{name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueQuantity:i}),disableWheel:!0});case"choice":case"open-choice":return Fp(t)&&!t.answerValueSet?(0,Y.jsx)(Tp,{name:f,item:t,initial:s,response:r,onChangeAnswer:i=>a(i)}):(0,Y.jsx)(kp,{name:f,item:t,initial:s,response:r,onChangeAnswer:i=>a(i)});default:return null}}function Tp(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return(0,Y.jsx)(sc,{});let n=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemInitial",value:r},"value"),f=[""];for(let l of t.answerOption){let i=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:l},"value");f.push(nc(i))}let s=fs(a)??n;if(t.repeats){let{propertyName:l,data:i}=wp(e.item),u=Ap(a);return(0,Y.jsx)(he.MultiSelect,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[nc(n)],onChange:d=>{let c=os(d,l,t);e.onChangeAnswer(c)}})}return(0,Y.jsx)(he.NativeSelect,{id:o,name:o,onChange:l=>{let i=l.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],d=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:u},"value"),c="value"+(0,j.capitalize)(d.type);e.onChangeAnswer({[c]:d.value})},defaultValue:(0,j.formatCoding)(s?.value)||s?.value,data:f})}function kp(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?(0,Y.jsx)(sc,{}):t.answerValueSet?(0,Y.jsx)($r,{name:o,binding:t.answerValueSet,onChange:f=>a({valueCoding:f})}):(0,Y.jsx)(Bp,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Bp(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,f=(0,j.getElementDefinition)("QuestionnaireItemAnswerOption","value[x]"),s=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemInitial",value:r},"value"),l=[],i;if(t.answerOption)for(let c=0;c<t.answerOption.length;c++){let m=t.answerOption[c],h=`${o}-option-${c}`,g=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:m},"value");s&&(0,j.stringify)(g)===(0,j.stringify)(s)&&(i=h),l.push([h,g])}let u=fs(n),d=Mp(l,u);return(0,Y.jsx)(he.Radio.Group,{name:o,value:d??i,onChange:c=>{let m=l.find(h=>h[0]===c);if(m){let h=m[1],g="value"+(0,j.capitalize)(h.type);a({[g]:h.value})}},children:l.map(([c,m])=>(0,Y.jsx)(he.Radio,{id:c,value:c,py:4,label:(0,Y.jsx)(De,{property:f,propertyType:m.type,value:m.value})},c))})}function sc(){return(0,Y.jsx)(he.TextInput,{disabled:!0,placeholder:"No Answers Defined"})}function ic(e){return(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswer",value:e},"value")}function fs(e,o=0){let t=e.answer;return ic(t?.[o]??{})}function Ap(e){let o=e.answer;return o?o.map(r=>ic(r)).map(r=>(0,j.formatCoding)(r?.value)||r?.value):[]}function Mp(e,o){return e.find(t=>(0,j.deepEquals)(t[1].value,o?.value))?.[0]}function nc(e){if(e)return e.type==="CodeableConcept"?(0,j.formatCodeableConcept)(e.value):e.type==="Coding"?(0,j.formatCoding)(e.value):e.type==="Reference"?as(e):e.value.toString()}function Fp(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function wp(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+(0,j.capitalize)(t.type),a=(e.answerOption??[]).map(n=>({value:fc(n,r),label:fc(n,r)}));return{propertyName:r,data:a}}function fc(e,o){return(0,j.formatCoding)(e.valueCoding)||e[o]?.toString()}var b=require("react/jsx-runtime"),Op=(0,G.createStyles)(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 Ep(e){let o=D(),t=K(e.questionnaire),[r,a]=(0,Do.useState)(!1),[n,f]=(0,Do.useState)(),[s,l]=(0,Do.useState)(),[i,u]=(0,Do.useState)();function d(){u(void 0)}function c(){l(void 0)}(0,Do.useEffect)(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),(0,Do.useEffect)(()=>(f(Vp(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]);let m=(h,g)=>{f(h),e.autoSave&&!g&&e.onSubmit&&e.onSubmit(h)};return!r||!n?null:(0,b.jsx)("div",{children:(0,b.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[(0,b.jsx)(uc,{item:n,selectedKey:s,setSelectedKey:l,hoverKey:i,setHoverKey:u,onChange:m}),(0,b.jsx)(G.Button,{type:"submit",children:"Save"})]})})}function uc(e){let{classes:o,cx:t}=Op(),r=e.item,a=e.item,n=(0,Hn.isResource)(e.item),f=n||a.type==="group",s=a.linkId??"[untitled]",l=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=(0,Do.useRef)();u.current=e.item;function d(C){N(C),e.setSelectedKey(e.item.id)}function c(C){N(C),e.setHoverKey(e.item.id)}function m(C){let E=u.current;e.onChange({...E,item:E.item?.map(se=>se.id===C.id?C:se)})}function h(C,E){e.onChange({...e.item,item:[...e.item.item??[],C]},E)}function g(C){e.onChange({...e.item,item:e.item.item?.filter(E=>E!==C)})}function y(C,E){e.onChange({...u.current,[C]:E})}function k(C){e.onChange({...e.item,...C})}function T(C){e.onChange({...e.item,item:e.item.item?.map(E=>E===C?{...E,repeats:!E.repeats}:E)})}function A(C,E){let se=Up(e.item.item,C,E);e.onChange({...e.item,item:se})}let _=t(o.section,{[o.editing]:l,[o.hovering]:i&&!l});return(0,b.jsxs)("div",{"data-testid":a.linkId,className:_,onClick:d,onMouseOver:c,onFocus:c,children:[(0,b.jsx)("div",{className:o.questionBody,children:l?(0,b.jsxs)(b.Fragment,{children:[n&&(0,b.jsx)(G.TextInput,{size:"xl",defaultValue:r.title,onBlur:C=>y("title",C.currentTarget.value)}),!n&&(0,b.jsx)(G.Textarea,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:C=>y("text",C.currentTarget.value)}),a.type==="reference"&&(0,b.jsx)(Hp,{item:a,onChange:k}),jl(a)&&(0,b.jsx)(Lp,{item:a,onChange:C=>k(C)})]}):(0,b.jsxs)(b.Fragment,{children:[r.title&&(0,b.jsx)(G.Title,{children:r.title}),a.text&&(0,b.jsx)("div",{children:a.text}),!f&&(0,b.jsx)(ga,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((C,E)=>(0,b.jsx)("div",{children:(0,b.jsx)(uc,{item:C,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:E===0,isLast:E===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>g(C),onRepeatable:T,onMoveUp:()=>A(E,-1),onMoveDown:()=>A(E,1)})},C.id)),!f&&(0,b.jsx)("div",{className:o.topActions,children:l?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(G.TextInput,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:C=>y("linkId",C.currentTarget.value)}),!f&&(0,b.jsx)(G.NativeSelect,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:C=>y("type",C.currentTarget.value),data:[{value:"display",label:"Display"},{value:"boolean",label:"Boolean"},{value:"decimal",label:"Decimal"},{value:"integer",label:"Integer"},{value:"date",label:"Date"},{value:"dateTime",label:"Date/Time"},{value:"time",label:"Time"},{value:"string",label:"String"},{value:"text",label:"Text"},{value:"url",label:"URL"},{value:"choice",label:"Choice"},{value:"open-choice",label:"Open Choice"},{value:"attachment",label:"Attachment"},{value:"reference",label:"Reference"},{value:"quantity",label:"Quantity"}]})]}):(0,b.jsx)("div",{children:s})}),!n&&(0,b.jsx)(G.Box,{className:o.movementActions,children:(0,b.jsxs)(G.Box,{className:o.columnAlignment,children:[!e.isFirst&&(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,b.jsx)(ff,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,b.jsx)(nf,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),(0,b.jsxs)("div",{className:o.bottomActions,children:[f&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),h({id:Qt(),linkId:is("q"),type:"string",text:"Question"})},children:"Add item"}),(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),h({id:Qt(),linkId:is("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),h(Gp(),!0)},children:"Add Page"}),l&&!n&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),(0,b.jsx)(G.Anchor,{href:"#",onClick:C=>{C.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function Lp(e){let o=(0,Hn.getElementDefinition)("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return(0,b.jsxs)("div",{children:[e.item.answerValueSet!==void 0?(0,b.jsx)(G.TextInput,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):(0,b.jsx)(Np,{options:t,property:o,item:e.item,onChange:e.onChange}),(0,b.jsxs)(G.Box,{display:"flex",children:[(0,b.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:Qt()}]})},children:"Add choice"}),(0,b.jsx)(G.Space,{w:"lg"}),(0,b.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Np(e){return(0,b.jsx)("div",{children:e.options.map(o=>{let[t,r]=yo({type:"QuestionnaireItemAnswerOption",value:o},"value");return(0,b.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[(0,b.jsx)("div",{children:(0,b.jsx)(Co,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let f=[...e.options],s=f.findIndex(l=>l.id===o.id);f[s]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:f})}},o.id)}),(0,b.jsx)("div",{children:(0,b.jsx)(G.Anchor,{href:"#",onClick:a=>{N(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Hp(e){let o=xa(e.item)??[];return(0,b.jsxs)(b.Fragment,{children:[o.map((t,r)=>(0,b.jsxs)(G.Group,{children:[(0,b.jsx)(jt,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(Ia(e.item,o.map(n=>n===t?a:n)))}}),(0,b.jsx)(G.Anchor,{href:"#",onClick:a=>{N(a),e.onChange(Ia(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),(0,b.jsx)(G.Anchor,{href:"#",onClick:t=>{N(t),e.onChange(Ia(e.item,[...o,""]))},children:"Add Resource Type"})]})}var ls=1,ss=1;function is(e){return e+ls++}function Qt(){return"id-"+ss++}function Vp(e){return{...e,id:e.id||Qt(),item:cc(e.item)}}function cc(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(ss=Math.max(ss,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(ls=Math.max(ls,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||Qt(),item:cc(o.item),answerOption:qp(o.answerOption)}))}function qp(e){if(e)return e.map(o=>({...o,id:o.id||Qt()}))}function Gp(){return{id:Qt(),linkId:is("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 Up(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}var gc=require("@mantine/core"),qn=require("@medplum/core");var Wt=require("react");var co=require("@mantine/core");var dc=require("@mantine/core"),mc=require("react");var zt=require("react/jsx-runtime");function Vn(e){let{item:o,response:t,onChange:r}=e,[a,n]=(0,mc.useState)(Qp(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return(0,zt.jsx)("p",{children:o.text},o.linkId);let f=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?(0,zt.jsx)(ga,{item:o,response:t,onChange:s=>r([s]),index:0},o.linkId):(0,zt.jsxs)(Ve,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((s,l)=>(0,zt.jsx)(ga,{item:o,response:t,onChange:i=>r([i]),index:l},`${o.linkId}-${l}`)),f&&(0,zt.jsx)(dc.Anchor,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function Qp(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}var Rr=require("@mantine/core"),pc=require("react");var $e=require("react/jsx-runtime");function us(e){let[o,t]=(0,pc.useState)(e.response);if(o.length===0)return null;function r(n,f){let s=o.map((l,i)=>i===f?n[0]:l);t(s),e.onChange(s)}function a(){let n=Ln(e.item);t([...o,n])}return(0,$e.jsxs)($e.Fragment,{children:[o.map((n,f)=>(0,$e.jsx)(xc,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,f)},n.id)),e.item.repeats&&(0,$e.jsx)(Rr.Anchor,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function xc(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)),l={...o,item:s};r([l])}return e.checkForQuestionEnabled(e.item)?(0,$e.jsxs)("div",{children:[e.item.text&&(0,$e.jsx)(Rr.Title,{order:3,mb:"md",children:e.item.text}),(0,$e.jsx)(Rr.Stack,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?(0,$e.jsx)(us,{item:n,response:o.item?.filter(f=>f.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):(0,$e.jsx)(xc,{item:n,checkForQuestionEnabled:t,response:o.item?.find(f=>f.linkId===n.linkId)??{},onChange:a},n.linkId):(0,$e.jsx)(Vn,{item:n,response:o.item?.find(f=>f.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}var Ee=require("react/jsx-runtime");function Ic(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:f,numberOfPages:s,renderPages:l,submitButtonText:i,checkForQuestionEnabled:u}=e,d=o.map(c=>{let m=t?.item?.filter(g=>g.linkId===c.linkId)??[],h=c.type==="group"?(0,Ee.jsx)(us,{item:c,response:m,onChange:a,checkForQuestionEnabled:u},c.linkId):(0,Ee.jsx)(Vn,{item:c,response:m?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return l?(0,Ee.jsx)(co.Stepper.Step,{label:c.text,children:h},c.linkId):h});return(0,Ee.jsxs)(Ee.Fragment,{children:[l&&(0,Ee.jsx)(co.Stepper,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!l&&(0,Ee.jsx)(co.Stack,{children:d}),(0,Ee.jsx)(zp,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:f,submitButtonText:i})]})}function zp(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return(0,Ee.jsxs)(co.Group,{position:"right",mt:"xl",spacing:"xs",children:[o&&(0,Ee.jsx)(co.Button,{onClick:e.prevStep,children:"Back"}),t&&(0,Ee.jsx)(co.Button,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&(0,Ee.jsx)(co.Button,{type:"submit",children:e.submitButtonText??"Submit"})]})}var br=require("react/jsx-runtime");function cs(e){let o=D(),t=o.getProfile(),[r,a]=(0,Wt.useState)(!1),n=K(e.questionnaire),[f,s]=(0,Wt.useState)(),[l,i]=(0,Wt.useState)(0);(0,Wt.useEffect)(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),(0,Wt.useEffect)(()=>{s(n?rs(n):void 0)},[n]);function u(g){let y=f?.item??[],T={resourceType:"QuestionnaireResponse",item:hc(y,Array.isArray(g)?g:[g])};s(T)}function d(g){return es(g,f?.item??[])}if(!r||!n)return null;let c=ns(n),m=()=>i(g=>g+1),h=()=>i(g=>g-1);return(0,br.jsx)(Nn.Provider,{value:{subject:e.subject,encounter:e.encounter},children:(0,br.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&f&&e.onSubmit({...f,questionnaire:(0,qn.getReferenceString)(n),subject:e.subject,source:(0,qn.createReference)(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&(0,br.jsx)(gc.Title,{children:n.title}),(0,br.jsx)(Ic,{items:n.item??[],response:f,onChange:u,renderPages:c>1,activePage:l,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:m,prevStep:h})]})})}function Wp(e,o){let t=hc(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 hc(e,o){let t=[],r=new Set;for(let a of e){let n=a.id,f=o.find(s=>s.id===n);f?(t.push(Wp(a,f)),r.add(f.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}var $=require("@mantine/core"),ha=require("@medplum/core");var Pr=require("react");var z=require("react/jsx-runtime"),Xp=(0,$.createStyles)(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"}})),Jp=["gender","age","gestationalAge","context","appliesTo","category"],$p={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function _p(e){e=Object.assign($p,e);let o=e.definition,[t,r]=(0,Pr.useState)([]),[a,n]=(0,Pr.useState)(1),[f,s]=(0,Pr.useState)(1);return(0,Pr.useEffect)(()=>{let h=Zp(o,s);r(Yp(h.qualifiedInterval||[],n))},[o]),(0,z.jsxs)(oe,{testid:"reference-range-editor",onSubmit:l,children:[(0,z.jsx)($.Stack,{children:t.map(h=>(0,z.jsx)(vc,{unit:ex(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:m,onRemoveGroup:u,intervalGroup:h},`group-${h.id}`))}),(0,z.jsx)($.ActionIcon,{title:"Add Group",size:"sm",onClick:h=>{N(h),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(g=>g+1)},children:(0,z.jsx)($t,{})}),(0,z.jsx)($.Group,{position:"right",children:(0,z.jsx)($.Button,{type:"submit",children:"Save"})})]});function l(){let h=t.flatMap(g=>g.intervals).filter(g=>!ox(g));e.onSubmit({...o,qualifiedInterval:h})}function i(h){r(g=>[...g,h])}function u(h){r(g=>g.filter(y=>y.id!==h.id))}function d(h,g){r(y=>{y=[...y];let k=y.find(A=>A.id===h),T=k?.intervals.findIndex(A=>A.id===g.id);return T!==void 0&&k?.intervals[T]&&(k.intervals[T]=g),y})}function c(h,g){g.id===void 0&&(g.id=`id-${f}`,s(y=>y+1)),r(y=>{y=[...y];let k=y.findIndex(T=>T.id===h);if(k!==-1){let T={...y[k]};g={...g,...T.filters},T.intervals=[...T.intervals,g],y[k]=T}return y})}function m(h,g){r(y=>{y=[...y];let k=y.find(T=>T.id===h);return k&&(k.intervals=k.intervals.filter(T=>T.id!==g.id)),y})}}function vc(e){let{intervalGroup:o,unit:t}=e,{classes:r}=Xp();return(0,z.jsx)(Go,{"data-testid":o.id,className:r.section,children:(0,z.jsxs)($.Stack,{spacing:"lg",children:[(0,z.jsx)($.Group,{position:"right",children:(0,z.jsx)($.ActionIcon,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{N(a),e.onRemoveGroup(o)},children:(0,z.jsx)(ot,{})},`remove-group-button-${o.id}`)}),(0,z.jsx)(Kp,{intervalGroup:o,onChange:e.onChange}),(0,z.jsx)($.Divider,{}),o.intervals.map(a=>(0,z.jsxs)($.Stack,{spacing:"xs",children:[(0,z.jsxs)($.Group,{children:[(0,z.jsx)($.TextInput,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{N(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),(0,z.jsx)($.ActionIcon,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{N(n),e.onRemove(o.id,a)},children:(0,z.jsx)(ot,{})},`remove-interval-${a.id}`)]}),(0,z.jsx)(sr,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),(0,z.jsx)($.ActionIcon,{title:"Add Interval",size:"sm",onClick:a=>{N(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:(0,z.jsx)($t,{})})]})})}function Kp(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(0,z.jsxs)($.Stack,{style:{maxWidth:"50%"},children:[(0,z.jsx)($.Group,{children:(0,z.jsx)($.NativeSelect,{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})}}})}),(0,z.jsxs)($.Group,{spacing:"xs",children:[(0,z.jsx)($.Text,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),(0,z.jsx)("div",{id:`div-age-${o.id}`,children:(0,z.jsx)(sr,{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}`)})]}),(0,z.jsx)($.NativeSelect,{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"}]}})}}}),(0,z.jsx)($.NativeSelect,{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 Zp(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 Yp(e,o){let t=1,r={};for(let a of e){let n=jp(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(Jp.map(f=>[f,a[f]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function jp(e){return[`gender=${e.gender}`,`age=${(0,ha.formatRange)(e.age)}`,`gestationalAge=${(0,ha.formatRange)(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function ex(e){return e&&((0,ha.getCodeBySystem)(e,"http://unitsofmeasure.org")||e.text)}function ox(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}var To=require("@mantine/core"),Gn=require("@medplum/core");var Xt=require("react");var ke=require("react/jsx-runtime");function tx(e){let o=D(),t=K(e.value),[r,a]=(0,Xt.useState)(!1),[n,f]=(0,Xt.useState)();if((0,Xt.useEffect)(()=>{t&&!r&&(o.executeBatch(s(t)).then(f).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return(0,ke.jsx)(To.Grid,{children:t.action?.map((i,u)=>{let d=i.resource&&l(i.resource),c=d?.input?.[0]?.valueReference,m=d?.output?.[0]?.valueReference;return(0,ke.jsxs)(Xt.Fragment,{children:[(0,ke.jsx)(To.Grid.Col,{span:1,p:"md",children:d?.status==="completed"?(0,ke.jsx)(pf,{}):(0,ke.jsx)(Mf,{color:"gray"})}),(0,ke.jsxs)(To.Grid.Col,{span:9,p:"xs",children:[(0,ke.jsx)(To.Text,{weight:500,children:i.title}),i.description&&(0,ke.jsx)("div",{children:i.description}),(0,ke.jsxs)("div",{children:["Last edited by\xA0",(0,ke.jsx)(so,{value:d?.meta?.author}),"\xA0on\xA0",(0,Gn.formatDateTime)(d?.meta?.lastUpdated)]}),(0,ke.jsxs)("div",{children:["Status: ",(0,ke.jsx)(la,{status:d?.status||"unknown"})]})]}),(0,ke.jsxs)(To.Grid.Col,{span:2,p:"md",children:[c&&!m&&(0,ke.jsx)(To.Button,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&m&&(0,ke.jsx)(To.Button,{onClick:()=>e.onEdit(d,c,m),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 l(i){for(let u of n?.entry)if(u.resource&&i.reference===(0,Gn.getReferenceString)(u.resource))return u.resource}}var bc=require("@mantine/core");var Qn=require("react");var yc=require("@medplum/core");function Un(e,o){let t=rx(e,o);return ax(t,e,o)}function rx(e,o){let t=e.length,r=o.length,a=t+r+1,n=1+2*a,f=n/2|0,s=new Array(n);s[f+1]={i:0,j:-1,prev:void 0,snake:!0};for(let l=0;l<a;l++){for(let i=-l;i<=l;i+=2){let u=f+i,d=u+1,c=u-1,m=s[d],h=s[c],g,y=0;i===-l||i!==l&&h.i<m.i?(y=m.i,g=m):(y=h.i+1,g=h),s[c]=void 0;let k=y-i,T={i:y,j:k,prev:nx(g),snake:!1};for(;y<t&&k<r&&e[y]===o[k];)y++,k++;if(y>T.i&&(T={i:y,j:k,prev:T,snake:!0}),s[u]=T,y>=t&&k>=r)return s[u]}s[f+l-1]=void 0}}function ax(e,o,t){let r=[],a=e;for(a.snake&&(a=a.prev);a?.prev&&a.prev.j>=0;){let n=a.i,f=a.j;a=a.prev;let s=a.i,l=a.j,i={position:s,lines:o.slice(s,n)},u={position:l,lines:t.slice(l,f)},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 nx(e){return e&&!e.snake&&e.prev?e.prev:e}function Cc(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:(0,yc.stringify)(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 fx(t,o),lx(t),t}function fx(e,o){for(let t=1;t<o.length;t++){let r=Un(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,f=a.original.lines,s=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,f.length),a.type==="insert"||a.type==="change")for(let l=0;l<a.revised.lines.length;l++)e.splice(n+l,0,{id:o[t].meta.versionId,meta:o[t].meta,value:s[l],span:1})}}}function lx(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 Sc(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Rc(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Dr(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Dr(r,"month");let a=Math.floor(o/86400);if(a>0)return Dr(a,"day");let n=Math.floor(o/3600);if(n>0)return Dr(n,"hour");let f=Math.floor(o/60);return f>0?Dr(f,"minute"):Dr(o,"second")}function Dr(e,o){return`${e} ${e===1?o:o+"s"} ago`}var Be=require("react/jsx-runtime"),sx=(0,bc.createStyles)(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 ix(e){let{classes:o}=sx(),t=D(),[r,a]=(0,Qn.useState)(e.history);if((0,Qn.useEffect)(()=>{!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(0,Be.jsx)("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let f=Cc(r);return(0,Be.jsx)("div",{className:o.container,children:(0,Be.jsx)("table",{className:o.root,children:(0,Be.jsx)("tbody",{children:f.map((s,l)=>(0,Be.jsxs)("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&(0,Be.jsxs)(Be.Fragment,{children:[(0,Be.jsx)("td",{className:o.author,rowSpan:s.span,children:(0,Be.jsx)(Uo,{value:s.meta.author,link:!0})}),(0,Be.jsx)("td",{className:o.dateTime,rowSpan:s.span,children:(0,Be.jsx)(be,{to:Sc(n,s.meta.versionId),children:Rc(s.meta.lastUpdated)})})]}),(0,Be.jsx)("td",{className:o.lineNumber,children:l+1}),(0,Be.jsx)("td",{className:o.line,children:(0,Be.jsx)("pre",{className:o.pre,children:s.value})})]},"row-"+l))})})})}var Pc=require("@mantine/core"),ds=require("@medplum/core");var mo=require("react/jsx-runtime"),ux=(0,Pc.createStyles)(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function cx(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=(0,ds.stringify)(o,!0).match(/[^\r\n]+/g),a=(0,ds.stringify)(t,!0).match(/[^\r\n]+/g),n=Un(r,a);return(0,mo.jsx)("pre",{style:{color:"gray"},children:n.map((f,s)=>(0,mo.jsx)(dx,{delta:f},"delta"+s))})}function dx(e){let{classes:o}=ux();return(0,mo.jsxs)(mo.Fragment,{children:["...",(0,mo.jsx)("br",{}),e.delta.original.lines.length>0&&(0,mo.jsx)("div",{className:o.removed,children:e.delta.original.lines.join(`
66
+ `)}),e.delta.revised.lines.length>0&&(0,mo.jsx)("div",{className:o.added,children:e.delta.revised.lines.join(`
67
+ `)}),"...",(0,mo.jsx)("br",{})]})}var ko=require("@mantine/core"),Dc=require("@medplum/core");var va=require("react");var _e=require("react/jsx-runtime");function mx(e){let o=D(),t=K(e.defaultValue),[r,a]=(0,va.useState)(!1),[n,f]=(0,va.useState)();return(0,va.useEffect)(()=>{t&&(f((0,Dc.deepClone)(t)),o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log))},[o,t]),!r||!n?(0,_e.jsx)("div",{children:"Loading..."}):(0,_e.jsxs)("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(n)},children:[(0,_e.jsxs)(ko.Stack,{mb:"xl",children:[(0,_e.jsx)(Ve,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:(0,_e.jsx)(ko.TextInput,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),(0,_e.jsx)(Ve,{title:"ID",htmlFor:"id",outcome:e.outcome,children:(0,_e.jsx)(ko.TextInput,{name:"id",defaultValue:n.id,disabled:!0})})]}),(0,_e.jsx)(ur,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:f}),(0,_e.jsxs)(ko.Group,{position:"right",mt:"xl",children:[(0,_e.jsx)(ko.Button,{type:"submit",children:"OK"}),e.onDelete&&(0,_e.jsx)(ko.Button,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}var Tc=require("@mantine/core"),zn=require("@medplum/core");var Wn=require("react");var Ce=require("react/jsx-runtime");function px(e){let o=D(),[t,r]=(0,Wn.useState)(e.history);return(0,Wn.useEffect)(()=>{!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?(0,Ce.jsxs)(Tc.Table,{withBorder:!0,withColumnBorders:!0,children:[(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("th",{children:"Author"}),(0,Ce.jsx)("th",{children:"Date"}),(0,Ce.jsx)("th",{children:"Version"})]})}),(0,Ce.jsx)("tbody",{children:t.entry?.map((a,n)=>(0,Ce.jsx)(xx,{entry:a},"entry-"+n))})]}):(0,Ce.jsx)("div",{children:"Loading..."})}function xx(e){let{response:o,resource:t}=e.entry;return t?(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("td",{children:(0,Ce.jsx)(Uo,{value:t.meta?.author,link:!0})}),(0,Ce.jsx)("td",{children:(0,zn.formatDateTime)(t.meta?.lastUpdated)}),(0,Ce.jsx)("td",{children:(0,Ce.jsx)(be,{to:Ix(t),children:t.meta?.versionId})})]}):(0,Ce.jsx)("tr",{children:(0,Ce.jsx)("td",{colSpan:3,children:(0,zn.normalizeErrorString)(o?.outcome)})})}function Ix(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}var gt=require("@mantine/core"),Xn=require("@medplum/core");var ya=require("react");var ue=require("react/jsx-runtime"),gx=(0,gt.createStyles)(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function hx(e){let{classes:o}=gx(),t=K(e.schedule),r=K(e.questionnaire),[a,n]=(0,ya.useState)(pn()),[f,s]=(0,ya.useState)(),[l,i]=(0,ya.useState)(),[u,d]=(0,ya.useState)(),[c]=jn("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",(0,Xn.isReference)(e.schedule)?e.schedule.reference:(0,Xn.getReferenceString)(e.schedule)],["start","gt"+vx(a)],["start","lt"+yx(a)]]));if(!t||!c||!r)return null;let m=t.actor?.[0];return(0,ue.jsxs)("div",{className:o.container,"data-testid":"scheduler",children:[(0,ue.jsxs)("div",{className:o.info,children:[m&&(0,ue.jsx)(Fe,{value:m,size:"xl"}),m&&(0,ue.jsx)(gt.Text,{size:"xl",weight:500,children:(0,ue.jsx)(so,{value:m})}),(0,ue.jsx)("p",{children:"1 hour"}),f&&(0,ue.jsx)("p",{children:f.toLocaleDateString()}),l&&(0,ue.jsx)("p",{children:kc(new Date(l.start))})]}),(0,ue.jsxs)("div",{className:o.selection,children:[!f&&(0,ue.jsxs)("div",{children:[(0,ue.jsx)("h3",{children:"Select date"}),(0,ue.jsx)(ml,{slots:c,onChangeMonth:n,onClick:s})]}),f&&!l&&(0,ue.jsxs)("div",{children:[(0,ue.jsx)("h3",{children:"Select time"}),(0,ue.jsx)(gt.Stack,{children:c.map(h=>{let g=new Date(h.start);return g.getTime()>f.getTime()&&g.getTime()<f.getTime()+24*3600*1e3&&(0,ue.jsx)("div",{children:(0,ue.jsx)(gt.Button,{variant:"outline",style:{width:150},onClick:()=>i(h),children:kc(g)})},h.id)})})]}),f&&l&&!u&&(0,ue.jsx)(cs,{questionnaire:r,submitButtonText:"Next",onSubmit:d}),f&&l&&u&&(0,ue.jsxs)("div",{children:[(0,ue.jsx)("h3",{children:"You're all set!"}),(0,ue.jsx)("p",{children:"Check your email for a calendar invite."})]})]})]})}function vx(e){return Bc(e.getTime())}function yx(e){return Bc(e.getTime()+31*24*60*60*1e3)}function Bc(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function kc(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}var Ca=require("@medplum/core");var Ac=require("react/jsx-runtime");function Cx(e){return(0,Ac.jsx)(Jo,{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:[(0,Ca.createReference)(o)],subject:o.subject,sender:(0,Ca.createReference)(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[(0,Ca.createReference)(o)],subject:o.subject,operator:(0,Ca.createReference)(t),issued:new Date().toISOString(),content:r})})}var Ec=require("@medplum/core");var Ra=require("react");var Ae=require("@mantine/core"),Mc=require("@medplum/core"),Fc=require("react");var Ke=require("react/jsx-runtime");function Jn(e){let o=D(),[t,r]=(0,Fc.useState)();return(0,Ke.jsxs)(oe,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r((0,Mc.normalizeOperationOutcome)(n))}},children:[(0,Ke.jsxs)(Ae.Center,{sx:{flexDirection:"column"},children:[(0,Ke.jsx)(jo,{size:32}),(0,Ke.jsx)(Ae.Title,{children:"Create project"})]}),(0,Ke.jsxs)(Ae.Stack,{spacing:"xl",children:[(0,Ke.jsx)(Ae.TextInput,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:Te(t,"firstName")}),(0,Ke.jsxs)(Ae.Text,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",(0,Ke.jsx)(Ae.Anchor,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,Ke.jsx)(Ae.Anchor,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),(0,Ke.jsx)(Ae.Group,{position:"right",mt:"xl",noWrap:!0,children:(0,Ke.jsx)(Ae.Button,{type:"submit",children:"Create project"})})]})}var ee=require("@mantine/core"),xs=require("@medplum/core");var Kn=require("react");var ht=require("react");function Sa(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)}var wc=require("react/jsx-runtime");function $n(e){let o=D(),{googleClientId:t,handleGoogleCredential:r}=e,a=(0,ht.useRef)(null),[n,f]=(0,ht.useState)(typeof google<"u"),[s,l]=(0,ht.useState)(!1),[i,u]=(0,ht.useState)(!1);return(0,ht.useEffect)(()=>{if(typeof google>"u"){Sa("https://accounts.google.com/gsi/client",()=>f(!0));return}s||(google.accounts.id.initialize({client_id:t,callback:r}),l(!0)),a.current&&!i&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,s,n,a,i,r]),t?(0,wc.jsx)("div",{ref:a}):null}function _n(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 ms(e){typeof grecaptcha>"u"&&Sa("https://www.google.com/recaptcha/api.js?render="+e)}function ps(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}var fe=require("react/jsx-runtime");function Oc(e){let o=_n(e.googleClientId),t=e.recaptchaSiteKey,r=D(),[a,n]=(0,Kn.useState)(),f=Xr(a,void 0);return(0,Kn.useEffect)(()=>{t&&ms(t)},[t]),(0,fe.jsxs)(oe,{style:{maxWidth:400},onSubmit:async s=>{try{let l="";t&&(l=await ps(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:l}))}catch(l){n((0,xs.normalizeOperationOutcome)(l))}},children:[(0,fe.jsx)(ee.Center,{sx:{flexDirection:"column"},children:e.children}),(0,fe.jsx)(Ut,{issues:f}),o&&(0,fe.jsxs)(fe.Fragment,{children:[(0,fe.jsx)(ee.Group,{position:"center",p:"xl",style:{height:70},children:(0,fe.jsx)($n,{googleClientId:o,handleGoogleCredential:async s=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:s.clientId,googleCredential:s.credential,createUser:!0}))}catch(l){n((0,xs.normalizeOperationOutcome)(l))}}})}),(0,fe.jsx)(ee.Divider,{label:"or",labelPosition:"center",my:"lg"})]}),(0,fe.jsxs)(ee.Stack,{spacing:"xl",children:[(0,fe.jsx)(ee.TextInput,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:Te(a,"firstName")}),(0,fe.jsx)(ee.TextInput,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:Te(a,"lastName")}),(0,fe.jsx)(ee.TextInput,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:Te(a,"email")}),(0,fe.jsx)(ee.PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,error:Te(a,"password")}),(0,fe.jsxs)(ee.Text,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",(0,fe.jsx)(ee.Anchor,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,fe.jsx)(ee.Anchor,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),(0,fe.jsxs)(ee.Text,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",(0,fe.jsx)(ee.Anchor,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",(0,fe.jsx)(ee.Anchor,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),(0,fe.jsxs)(ee.Group,{position:"apart",mt:"xl",noWrap:!0,children:[(0,fe.jsx)(ee.Checkbox,{name:"remember",label:"Remember me",size:"xs"}),(0,fe.jsx)(ee.Button,{type:"submit",children:"Create account"})]})]})}var Tr=require("react/jsx-runtime");function Sx(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:f}=e,s=D(),[l,i]=(0,Ra.useState)(),[u,d]=(0,Ra.useState)();(0,Ra.useEffect)(()=>{o==="patient"&&l&&s.startNewPatient({login:l,projectId:t}).then(m=>s.processCode(m.code)).then(()=>f()).catch(m=>d((0,Ec.normalizeOperationOutcome)(m)))},[s,o,t,l,f]);function c(m){m.code?s.processCode(m.code).then(()=>f()).catch(console.log):m.login&&i(m.login)}return(0,Tr.jsxs)(ia,{width:450,children:[u&&(0,Tr.jsx)("pre",{children:JSON.stringify(u,null,2)}),!l&&(0,Tr.jsx)(Oc,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:c,children:e.children}),l&&o==="project"&&(0,Tr.jsx)(Jn,{login:l,handleAuthResponse:c})]})}var Is=require("@mantine/notifications"),gs=require("@medplum/core");var Bo=require("react");var ce=require("@mantine/core"),Lc=require("@medplum/core");var vt=require("react");var ae=require("react/jsx-runtime");function Nc(e){let[o,t]=(0,vt.useState)();return o?(0,ae.jsx)(bx,{email:o,...e}):(0,ae.jsx)(Rx,{setEmail:t,...e})}function Rx(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...f}=e,s=D(),l=!e.disableGoogleAuth&&_n(e.googleClientId),i=(0,vt.useCallback)(async c=>{if(!c.authorizeUrl)return!1;let m=JSON.stringify({...await s.ensureCodeChallenge(f),domain:c.domain}),h=new URL(c.authorizeUrl);return h.searchParams.set("state",m),window.location.assign(h.toString()),!0},[s,f]),u=(0,vt.useCallback)(async c=>{let m=await s.post("auth/method",{email:c.email});await i(m)||o(c.email)},[s,i,o]),d=(0,vt.useCallback)(async c=>{let m=await s.startGoogleLogin({...f,googleCredential:c.credential});await i(m)||r(m)},[s,f,i,r]);return(0,ae.jsxs)(oe,{style:{maxWidth:400},onSubmit:u,children:[(0,ae.jsx)(ce.Center,{sx:{flexDirection:"column"},children:a}),l&&(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)(ce.Group,{position:"center",p:"xl",style:{height:70},children:(0,ae.jsx)($n,{googleClientId:l,handleGoogleCredential:d})}),!n&&(0,ae.jsx)(ce.Divider,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&(0,ae.jsx)(ce.TextInput,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),(0,ae.jsxs)(ce.Group,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[(0,ae.jsx)("div",{children:t&&(0,ae.jsx)(ce.Anchor,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&(0,ae.jsx)(ce.Button,{type:"submit",children:"Next"})]})]})}function bx(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=D(),[f,s]=(0,vt.useState)(),l=Xr(f,void 0),i=(0,vt.useCallback)(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(d=>s((0,Lc.normalizeOperationOutcome)(d)))},[n,a,t]);return(0,ae.jsxs)(oe,{style:{maxWidth:400},onSubmit:i,children:[(0,ae.jsx)(ce.Center,{sx:{flexDirection:"column"},children:r}),(0,ae.jsx)(Ut,{issues:l}),(0,ae.jsx)(ce.Stack,{spacing:"xl",children:(0,ae.jsx)(ce.PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:Te(f,"password")})}),(0,ae.jsxs)(ce.Group,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&(0,ae.jsx)(ce.Anchor,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),(0,ae.jsx)(ce.Checkbox,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),(0,ae.jsx)(ce.Button,{type:"submit",children:"Sign in"})]})]})}var Le=require("@mantine/core"),Hc=require("@medplum/core"),Vc=require("react");var Ze=require("react/jsx-runtime");function qc(e){let o=D(),[t,r]=(0,Vc.useState)();return(0,Ze.jsxs)(Le.Stack,{children:[(0,Ze.jsxs)(Le.Center,{sx:{flexDirection:"column"},children:[(0,Ze.jsx)(jo,{size:32}),(0,Ze.jsx)(Le.Title,{order:3,children:"Choose profile"})]}),(0,Ze.jsx)(Ut,{outcome:t}),e.memberships.map(a=>(0,Ze.jsx)(Le.UnstyledButton,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r((0,Hc.normalizeOperationOutcome)(n)))},children:(0,Ze.jsxs)(Le.Group,{children:[(0,Ze.jsx)(Le.Avatar,{radius:"xl"}),(0,Ze.jsxs)("div",{style:{flex:1},children:[(0,Ze.jsx)(Le.Text,{size:"sm",weight:500,children:a.profile?.display}),(0,Ze.jsx)(Le.Text,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}var Ye=require("@mantine/core");var po=require("react/jsx-runtime");function Gc(e){let o=D();return(0,po.jsx)(oe,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:(0,po.jsxs)(Ye.Stack,{children:[(0,po.jsxs)(Ye.Center,{sx:{flexDirection:"column"},children:[(0,po.jsx)(jo,{size:32}),(0,po.jsx)(Ye.Title,{children:"Choose scope"})]}),(0,po.jsx)(Ye.Stack,{children:(e.scope??"openid").split(" ").map(t=>(0,po.jsx)(Ye.Checkbox,{id:t,name:t,label:t,defaultChecked:!0},t))}),(0,po.jsx)(Ye.Group,{position:"right",mt:"xl",children:(0,po.jsx)(Ye.Button,{type:"submit",children:"Set scope"})})]})})}var Ne=require("@mantine/core"),Uc=require("@medplum/core");var Qc=require("react");var je=require("react/jsx-runtime");function zc(e){let o=D(),[t,r]=(0,Qc.useState)();return(0,je.jsx)(oe,{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((0,Uc.normalizeErrorString)(n)))},children:(0,je.jsxs)(Ne.Stack,{children:[(0,je.jsxs)(Ne.Center,{sx:{flexDirection:"column"},children:[(0,je.jsx)(jo,{size:32}),(0,je.jsx)(Ne.Title,{children:"Enter MFA code"})]}),t&&(0,je.jsx)(Ne.Alert,{icon:(0,je.jsx)(Pt,{size:16}),title:"Error",color:"red",children:t}),(0,je.jsx)(Ne.Stack,{children:(0,je.jsx)(Ne.TextInput,{name:"token",label:"MFA code",required:!0})}),(0,je.jsx)(Ne.Group,{position:"right",mt:"xl",children:(0,je.jsx)(Ne.Button,{type:"submit",children:"Submit code"})})]})})}var yt=require("react/jsx-runtime");function Px(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:f,...s}=e,l=D(),[i,u]=(0,Bo.useState)(),[d,c]=(0,Bo.useState)(!1),[m,h]=(0,Bo.useState)(),g=(0,Bo.useCallback)(T=>{f?f(T):l.processCode(T).then(()=>{r&&r()}).catch(A=>(0,Is.showNotification)({color:"red",message:(0,gs.normalizeErrorString)(A)}))},[l,f,r]),y=(0,Bo.useCallback)(T=>{c(!!T.mfaRequired),T.login&&u(T.login),T.memberships&&h(T.memberships),T.code&&(t?h(void 0):g(T.code))},[t,g]),k=(0,Bo.useCallback)(T=>{g(T.code)},[g]);return(0,Bo.useEffect)(()=>{o&&!i&&l.get("auth/login/"+o).then(y).catch(T=>(0,Is.showNotification)({color:"red",message:(0,gs.normalizeErrorString)(T)}))},[l,o,i,y]),(0,yt.jsx)(ia,{width:450,children:i?d?(0,yt.jsx)(zc,{login:i,handleAuthResponse:y}):m?(0,yt.jsx)(qc,{login:i,memberships:m,handleAuthResponse:y}):e.projectId==="new"?(0,yt.jsx)(Jn,{login:i,handleAuthResponse:y}):e.chooseScopes?(0,yt.jsx)(Gc,{login:i,scope:e.scope,handleAuthResponse:k}):(0,yt.jsx)("div",{children:"Success"}):(0,yt.jsx)(Nc,{onForgotPassword:a,onRegister:n,handleAuthResponse:y,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children})})}
68
68
  //# sourceMappingURL=index.cjs.map