@medplum/react 2.1.18 → 2.1.20

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 ac=Object.create;var ga=Object.defineProperty;var nc=Object.getOwnPropertyDescriptor;var lc=Object.getOwnPropertyNames;var fc=Object.getPrototypeOf,sc=Object.prototype.hasOwnProperty;var ic=(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 lc(o))!sc.call(e,a)&&a!==t&&ga(e,a,{get:()=>o[a],enumerable:!(r=nc(o,a))||r.enumerable});return e};var uc=(e,o,t)=>(t=e!=null?ac(fc(e)):{},_f(o||!e||!e.__esModule?ga(t,"default",{value:e,enumerable:!0}):t,e)),cc=e=>_f(ga({},"__esModule",{value:!0}),e);var Rp={};ic(Rp,{AddressDisplay:()=>zn,AddressInput:()=>Wn,AnnotationInput:()=>Xn,AppShell:()=>Xc,AsyncAutocomplete:()=>vt,AttachmentArrayDisplay:()=>Fl,AttachmentArrayInput:()=>Ol,AttachmentButton:()=>Rt,AttachmentDisplay:()=>lo,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:()=>oo,DefaultResourceTimeline:()=>Ed,DescriptionList:()=>Ll,DescriptionListEntry:()=>Nl,DiagnosticReportDisplay:()=>un,Document:()=>ea,ElementDefinitionInputSelector:()=>yi,ElementDefinitionTypeInput:()=>ef,EncounterTimeline:()=>Ld,ErrorBoundary:()=>yt,FhirPathTable:()=>tu,Form:()=>oe,FormSection:()=>He,Header:()=>Tl,HumanNameDisplay:()=>Br,HumanNameInput:()=>$l,IdentifierDisplay:()=>ql,IdentifierInput:()=>Kl,Loading:()=>ka,Logo:()=>Jo,MeasureReportDisplay:()=>um,MedplumLink:()=>Re,MedplumProvider:()=>dc,MemoizedFhirPathTable:()=>lm,MemoizedSearchControl:()=>em,MoneyDisplay:()=>Gl,MoneyInput:()=>_l,Navbar:()=>Ml,ObservationTable:()=>Mi,OperationOutcomeAlert:()=>Lt,Panel:()=>Ft,PatientTimeline:()=>cm,PlanDefinitionBuilder:()=>dm,QuantityDisplay:()=>wo,QuantityInput:()=>Ge,QuestionnaireBuilder:()=>Fm,QuestionnaireForm:()=>Uf,QuestionnaireItemType:()=>na,RangeDisplay:()=>Er,RangeInput:()=>tr,ReferenceDisplay:()=>Yo,ReferenceInput:()=>At,ReferenceRangeEditor:()=>Xm,ReferenceRangeGroupEditor:()=>Mu,RegisterForm:()=>Cp,RequestGroupDisplay:()=>jm,ResourceArrayDisplay:()=>Ul,ResourceArrayInput:()=>Yl,ResourceAvatar:()=>Fe,ResourceBadge:()=>Ho,ResourceBlame:()=>lp,ResourceDiff:()=>sp,ResourceForm:()=>up,ResourceHistoryTable:()=>cp,ResourceInput:()=>_r,ResourceName:()=>fo,ResourcePropertyDisplay:()=>De,ResourcePropertyInput:()=>Co,ResourceTable:()=>mn,ResourceTimeline:()=>Go,Scheduler:()=>xp,SearchChangeEvent:()=>vn,SearchClickEvent:()=>ut,SearchControl:()=>eu,SearchFieldEditor:()=>Pf,SearchFilterEditor:()=>Df,SearchLoadEvent:()=>Sn,ServiceRequestTimeline:()=>hp,SignInForm:()=>Sp,StatusBadge:()=>jr,Timeline:()=>nf,TimelineItem:()=>Vo,TimingInput:()=>jl,addDateFilterBetween:()=>xn,addField:()=>qd,addFilter:()=>Ot,addLastMonthFilter:()=>xf,addMissingFilter:()=>In,addNextMonthFilter:()=>gf,addThisMonthFilter:()=>If,addTodayFilter:()=>df,addTomorrowFilter:()=>mf,addYearToDateFilter:()=>Cf,addYesterdayFilter:()=>cf,buildFieldNameString:()=>ze,buildInitialResponse:()=>Of,buildInitialResponseItem:()=>Dn,clearFilters:()=>Vd,clearFiltersOnField:()=>ta,convertIsoToLocal:()=>Xl,convertLocalToIso:()=>Jl,createScriptTag:()=>pa,deleteFilter:()=>uf,formatReferenceString:()=>Ef,getErrorsForInput:()=>Te,getFieldDefinitions:()=>Tf,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:()=>kl,reactContext:()=>qn,renderValue:()=>bf,setFilters:()=>ur,setOffset:()=>Ki,setPage:()=>yf,setQuestionnaireItemReferenceTargetTypes:()=>fa,setSort:()=>gn,sortByDateAndPriority:()=>lf,toggleSort:()=>Gd,useMedplum:()=>P,useMedplumContext:()=>Gt,useMedplumNavigate:()=>ko,useMedplumProfile:()=>Sr,useResource:()=>K,useSearch:()=>pc,useSearchOne:()=>Gn,useSearchResources:()=>Un});module.exports=cc(Rp);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 ko(){return Gt().navigate}function Sr(){return Gt().profile}function dc(e){let o=e.medplum,t=e.navigate??mc,[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 mc(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 pc(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 no=require("@mantine/core"),va=require("react"),xo=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,xo.jsxs)(no.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,xo.jsx)(no.NativeSelect,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),(0,xo.jsx)(no.NativeSelect,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>l(c.currentTarget.value),data:["","postal","physical","both"]}),(0,xo.jsx)(no.TextInput,{placeholder:"Line 1",defaultValue:es(o,0),onChange:c=>s(c.currentTarget.value)}),(0,xo.jsx)(no.TextInput,{placeholder:"Line 2",defaultValue:es(o,1),onChange:c=>f(c.currentTarget.value)}),(0,xo.jsx)(no.TextInput,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),(0,xo.jsx)(no.TextInput,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),(0,xo.jsx)(no.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=uc(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 xc=Object.defineProperty,Ic=Object.defineProperties,gc=Object.getOwnPropertyDescriptors,Ra=Object.getOwnPropertySymbols,ss=Object.prototype.hasOwnProperty,is=Object.prototype.propertyIsEnumerable,ls=(e,o,t)=>o in e?xc(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},hc=(e,o)=>Ic(e,gc(o)),Cc=(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=Cc(l,["color","size","stroke","children"]);return(0,Rr.createElement)("svg",fs(hc(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:"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z",key:"svg-0"}],["path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2",key:"svg-1"}]]);var 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 Tr=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 kr=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 Ta=require("@mantine/core"),bl=require("react/jsx-runtime");function ka(){return(0,bl.jsx)(Ta.Center,{style:{width:"100%",height:"100vh"},children:(0,bl.jsx)(Ta.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 Re(e){let o=ko(),{to:t,suffix:r,label:a,onClick:n,children:l,...s}=e,f=yc(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 yc(e){if(e){if(typeof e=="string")return vc(e);if((0,Ma.isResource)(e))return Sc(e);if((0,Ma.isReference)(e))return Rc(e)}return"#"}function vc(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function Sc(e){return`/${e.resourceType}/${e.id}`}function Rc(e){return`/${e.reference}`}var Fa=require("react/jsx-runtime");function Fe(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)(Re,{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=bc(o),u=(0,fe.useRef)(null),[d,c]=(0,fe.useState)(),[x,S]=(0,fe.useState)(),[g,D]=(0,fe.useState)(),[B,k]=(0,fe.useState)(),[M,Z]=(0,fe.useState)(i.map(r)),[b,L]=(0,fe.useState)([]),de=(0,fe.useRef)();de.current=d;let ve=(0,fe.useRef)();ve.current=x;let Do=(0,fe.useRef)();Do.current=g;let xt=(0,fe.useRef)();xt.current=B;let Me=(0,fe.useRef)();Me.current=b;let h=(0,fe.useCallback)(()=>{S(void 0);let Se=u.current?.value.trim()||"";if(Se===de.current)return;c(Se);let ge=new AbortController;D(ge),a(Se,ge.signal).then(je=>{ge.signal.aborted||(L(je.map(r)),D(void 0),xt.current&&(je.length>0&&n(je.slice(0,1)),k(!1)))}).catch(je=>{ge.signal.aborted||je.message.includes("aborted")||(0,gs.showNotification)({color:"red",message:(0,hs.normalizeErrorString)(je)})})},[a,n,r]),U=(0,fe.useCallback)(()=>{Do.current&&(Do.current.abort(),D(void 0)),ve.current!==void 0&&window.clearTimeout(ve.current);let Se=window.setTimeout(()=>h(),100);S(Se)},[h]),po=(0,fe.useCallback)(Se=>{let ge=[],je=[];for(let Kf of Se){let Ia=Me.current?.find(rc=>rc.value===Kf),vr=Ia?.resource;!vr&&s!==!1&&l&&(vr=l(Kf),Ia=r(vr)),vr&&ge.push(vr),Ia&&je.push(Ia)}n(ge),Z(je)},[s,n,l,r]),C=(0,fe.useCallback)(Se=>{Se.key==="Enter"&&(!ve.current&&!Do.current?(N(Se),Me.current&&Me.current.length>0&&(L(Me.current.slice(0,1)),po([Me.current[0].value]))):k(!0))},[po]),X=(0,fe.useCallback)(Se=>{let ge=r(l(Se));return L([...Me.current,ge]),ge},[l,L,r]),To=(0,fe.useCallback)((Se,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:C,onSearchChange:U,data:[...M,...b],onFocus:h,onChange:po,onCreate:X,rightSectionWidth:40,rightSection:g?(0,Dl.jsx)(Oa.Loader,{size:16}):null,filter:To,creatable:!0,withinPortal:!0})}function bc(e){return e?Array.isArray(e)?e:[e]:[]}var Io=require("react/jsx-runtime"),Pc=(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 Dc(e){return e.id}function Tc(e){return{value:e.id,label:(0,Mo.getDisplayString)(e),resource:e}}function vs(e){let{classes:o}=Pc(),t=ko(),r=P(),a=(0,Ar.useCallback)(async(l,s)=>{let f=Bc(l),i={signal:s},u=await r.graphql(f,void 0,void 0,i);return Ac(u,l)},[r]),n=(0,Ar.useCallback)(l=>{l.length>0&&t(`/${(0,Mo.getReferenceString)(l[0])}`)},[t]);return(0,Io.jsx)(vt,{size:"sm",radius:"md",className:o.searchInput,icon:(0,Io.jsx)(hl,{size:16}),placeholder:"Search",itemComponent:kc,toKey:Dc,toOption:Tc,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var kc=(0,Ar.forwardRef)(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),(0,Io.jsx)("div",{ref:t,...o,children:(0,Io.jsxs)(St.Group,{noWrap:!0,children:[(0,Io.jsx)(Fe,{value:e}),(0,Io.jsxs)("div",{children:[(0,Io.jsx)(St.Text,{children:(0,Mo.getDisplayString)(e)}),(0,Io.jsx)(St.Text,{size:"xs",color:"dimmed",children:r})]})]})})});function Bc(e){let o=JSON.stringify(e);return(0,Mo.isUUID)(e)?`{
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:()=>Tl,HumanNameDisplay:()=>Br,HumanNameInput:()=>$l,IdentifierDisplay:()=>ql,IdentifierInput:()=>Kl,Loading:()=>ka,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:()=>Tf,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:()=>kl,reactContext:()=>qn,renderValue:()=>bf,setFilters:()=>ur,setOffset:()=>_i,setPage:()=>yf,setQuestionnaireItemReferenceTargetTypes:()=>fa,setSort:()=>gn,sortByDateAndPriority:()=>lf,toggleSort:()=>Qd,useMedplum:()=>P,useMedplumContext:()=>Gt,useMedplumNavigate:()=>ko,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 ko(){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:"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z",key:"svg-0"}],["path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2",key:"svg-1"}]]);var 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 Tr=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 kr=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 Ta=require("@mantine/core"),bl=require("react/jsx-runtime");function ka(){return(0,bl.jsx)(Ta.Center,{style:{width:"100%",height:"100vh"},children:(0,bl.jsx)(Ta.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=ko(),{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,k]=(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)),k(!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]))):k(!0))},[mo]),X=(0,fe.useCallback)(ve=>{let ge=r(l(ve));return L([...Ae.current,ge]),ge},[l,L,r]),To=(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:To,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 Tc(e){return e.id}function kc(e){return{value:e.id,label:(0,Mo.getDisplayString)(e),resource:e}}function vs(e){let{classes:o}=Dc(),t=ko(),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:Tc,toOption:kc,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)?`{
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 Ac(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),Fc(Mc(t),o).slice(0,5)}function Mc(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 Fc(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"),wc=(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 Tl(e){let o=Gt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:s}=wc(),[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)(Fe,{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)(Fe,{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 eo=require("@mantine/core"),Bl=require("@mantine/notifications"),Ea=require("@medplum/core");function kl(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Oc(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Ec(o,t);return o}function Oc(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Ec(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=kl(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}var go=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,go.jsx)(eo.Modal,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:(0,go.jsx)(oe,{onSubmit:r,children:(0,go.jsxs)(eo.Stack,{children:[(0,go.jsx)(Lc,{config:t}),(0,go.jsx)(eo.TextInput,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),(0,go.jsx)(eo.Group,{position:"right",children:(0,go.jsx)(eo.Button,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Lc(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return(0,go.jsx)(eo.NativeSelect,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}var La=require("react");var Ts=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 Nc(e){return typeof e.display=="string"?e.display:Al(e)}function Hc(e){return{value:Al(e),label:Nc(e),resource:e}}function Vc(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:Hc,loadOptions:l,onCreate:Vc,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}var ks=require("react/jsx-runtime");function Fr(e){let[o,t]=(0,Ts.useState)(e.defaultValue);function r(a){let n=a[0],l=Gc(n);t(l),e.onChange&&e.onChange(l)}return(0,ks.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:qc(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function qc(e){return e?{code:e}:void 0}function Gc(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=ko(),r=zc(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)(Uc,{to:i.href,active:i.href===r?.href,onClick:u=>l(u,i.href),children:[(0,pe.jsx)(Qc,{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 Uc(e){let{classes:o,cx:t}=As();return(0,pe.jsx)(Re,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function Qc(e){return e.icon?e.icon:(0,pe.jsx)(Ne.Space,{w:30})}function zc(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=Wc(e,o,l.href);s>a&&(a=s,r=l)}return r}function Wc(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 Xc(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)(ka,{}):(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)(Tl,{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)(ka,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}var Fs=require("@mantine/core"),ho=require("react/jsx-runtime");function lo(e){let{contentType:o,url:t,title:r}=e.value??{};return t?(0,ho.jsxs)("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&(0,ho.jsx)("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&(0,ho.jsx)("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:(0,ho.jsx)("source",{type:o,src:t})}),o==="application/pdf"&&(0,ho.jsx)("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:(0,ho.jsx)("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),(0,ho.jsx)("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:(0,ho.jsx)(Fs.Anchor,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Jc(r),children:r||"Download"})})]}):null}function Jc(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)(lo,{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)(lo,{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)(lo,{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"),$c=(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}=$c();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)(Re,{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)(De,{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 De(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.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)(lo,{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 qe(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]=qe(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)(De,{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 Te(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:Te(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 to=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=_c(a);t(n),e.onChange&&e.onChange(n)}return(0,Zs.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Kc(o),maxSelectedValues:1,onChange:r})}function Kc(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function _c(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&&Yc(n);t(l),e.onChange&&e.onChange(l)}return(0,js.jsx)(Xt,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Zc(o),maxSelectedValues:1,onChange:r})}function Zc(e){return{system:e.system,code:e.code,display:e.display}}function Yc(e){return{system:e.system,code:e.code,display:e.display}}var Ya=require("@mantine/core"),ja=require("react");var Tt=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)(Tt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,jt.jsx)(Tt.NativeSelect,{"data-testid":"system",defaultValue:o?.system,onChange:f=>n(f.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),(0,jt.jsx)(Tt.NativeSelect,{"data-testid":"use",defaultValue:o?.use,onChange:f=>l(f.currentTarget.value),data:["","home","work","temp","old","mobile"]}),(0,jt.jsx)(Tt.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 oo(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:jc(),defaultValue:Xl(e.defaultValue),autoFocus:e.autoFocus,error:Te(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(Jl(t))}}})}function jc(){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"),ed=["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:ed,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)(oo,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),(0,Wr.jsx)(oo,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}var kt=require("@mantine/core"),ui=require("react"),or=require("react/jsx-runtime");function Ge(e){let[o,t]=(0,ui.useState)(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return(0,or.jsxs)(kt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,or.jsx)(kt.NativeSelect,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),(0,or.jsx)(kt.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:od(a.currentTarget.value)})}}),(0,or.jsx)(kt.TextInput,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function od(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)(Ge,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),(0,Xr.jsx)(Ge,{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)(Ge,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),(0,Jr.jsx)(Ge,{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"),td={Observation:"code",User:"email:contains"},rd=["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 ad(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=ld(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:nd,defaultValue:n,placeholder:e.placeholder,maxSelectedValues:1,toKey:Kr.getReferenceString,toOption:ad,loadOptions:s,onChange:f,clearable:!0})}var nd=(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)(Fe,{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 ld(e){return td[e]??(rd.includes(e)?"name":"_id")}var rr=require("react/jsx-runtime");function At(e){let o=fd(e.targetTypes),t=sd(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 fd(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function sd(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 Ue=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,Ue.jsxs)(tt.Stack,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,l)=>(0,Ue.jsxs)(tt.Group,{noWrap:!0,children:[(0,Ue.jsx)("div",{style:{flexGrow:1},children:(0,Ue.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,Ue.jsx)("div",{children:(0,Ue.jsx)(tt.ActionIcon,{title:"Remove",size:"sm",onClick:s=>{N(s);let f=[...r.current];f.splice(l,1),a(f)},children:(0,Ue.jsx)(Ko,{})})})]},`${l}-${o.length}`)),(0,Ue.jsx)(tt.Group,{noWrap:!0,style:{justifyContent:"flex-end"},children:(0,Ue.jsx)("div",{children:(0,Ue.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,Ue.jsx)(Ut,{})})})})]})}var me=require("@mantine/core"),hi=require("@medplum/core"),Mt=require("react");var te=require("react/jsx-runtime"),id=["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)(ud,{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 ud(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)(oo,{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:id.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)(to.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,q.jsx)(to.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)(to.TextInput,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:Te(e.outcome,r)});case O.PropertyType.date:return(0,q.jsx)(to.TextInput,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:l=>{e.onChange&&e.onChange(l.currentTarget.value)},error:Te(e.outcome,r)});case O.PropertyType.dateTime:case O.PropertyType.instant:return(0,q.jsx)(oo,{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)(to.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)(to.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)(to.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)(Ge,{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:cd(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 cd(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]=qe(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"),dd=(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}=dd(),{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)(()=>md(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 md(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:pd(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 pd(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"),xd=(0,fn.createStyles)(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function No(e){let{children:o,...t}=e,{classes:r}=xd();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 Qe=require("react");var _=require("@mantine/core"),ro=require("@medplum/core");var sn=require("react");var nr=require("@mantine/core"),tf=require("react/jsx-runtime"),Id=(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}=Id();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 Ti=require("@mantine/core");var Pi=require("@mantine/core"),lr=require("@medplum/core");var Di=require("react");var af=require("react/jsx-runtime");function fo(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)(Re,{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)(Ti.Group,{spacing:"xs",children:[(0,Yr.jsx)(Fe,{size:24,radius:12,value:e.value,link:e.link}),(0,Yr.jsx)(fo,{value:e.value,link:e.link})]})}var ki=require("@mantine/core"),Bi=require("react/jsx-runtime"),gd={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)(ki.Badge,{color:gd[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)(hd,{value:t}),r&&!e.hideSpecimenInfo&&Cd(r),t.result&&(0,I.jsx)(Mi,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&(0,I.jsx)(rf,{value:n})]})}function hd({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,ro.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,ro.capitalize)(e.status)})]})]})}function Cd(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,ro.formatDateTime)(o.collection?.collectedDateTime)]}),(0,I.jsxs)(_.Group,{spacing:5,children:[(0,I.jsx)(_.Text,{fw:500,children:"Received:"})," ",(0,ro.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)(yd,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${(0,ro.isReference)(o)?o.reference:o.id}`))})}function yd(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=Rd(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)(Re,{to:r,children:(0,I.jsx)(bt,{value:r.code})})}),(0,I.jsx)("td",{children:(0,I.jsx)(vd,{value:r})}),(0,I.jsx)("td",{children:(0,I.jsx)(Sd,{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,ro.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 vd(e){let o=e.value;return(0,I.jsx)(I.Fragment,{children:(0,ro.formatObservationValue)(o)})}function Sd(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 Rd(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"),bd=(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%"}}})),Pd={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",Pd,e),{classes:s,cx:f}=bd({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"),cn=require("react");var Ce=require("react/jsx-runtime"),Dd=(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],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function Li(e){let{classes:o}=Dd(),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,yo.getDataType)(e.original.resourceType);return(0,Ce.jsxs)("table",{className:o.root,children:[(0,Ce.jsxs)("colgroup",{children:[(0,Ce.jsx)("col",{style:{width:"30%"}}),(0,Ce.jsx)("col",{style:{width:"35%"}}),(0,Ce.jsx)("col",{style:{width:"35%"}})]}),(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("th",{children:"Property"}),(0,Ce.jsx)("th",{children:"Before"}),(0,Ce.jsx)("th",{children:"After"})]})}),(0,Ce.jsx)("tbody",{children:Object.entries(n.elements).map(([l,s])=>{if(l==="id"||l==="meta")return null;let[f,i]=qe((0,yo.toTypedValue)(e.original),l),[u,d]=qe((0,yo.toTypedValue)(e.revised),l);return Oi(f)&&Oi(u)||(0,yo.stringify)(f)===(0,yo.stringify)(u)?null:(0,Ce.jsxs)("tr",{children:[(0,Ce.jsx)("td",{children:(0,yo.getPropertyDisplayName)(l)}),(0,Ce.jsx)("td",{className:o.removed,children:(0,Ce.jsx)(De,{property:s,propertyType:i,value:f,ignoreMissingValues:!0})}),(0,Ce.jsx)("td",{className:o.added,children:(0,Ce.jsx)(De,{property:s,propertyType:d,value:u,ignoreMissingValues:!0})})]},l)})})]})}function Oi(e){return!e||Array.isArray(e)&&e.length===0||typeof e=="object"&&Object.keys(e).length===0}var dn=require("react");var Ni=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,Ni.jsx)(Zt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}var so=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)(so.Group,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[(0,ce.jsx)(Fe,{value:l,link:!0,size:"md"}),(0,ce.jsxs)("div",{style:{flex:1},children:[(0,ce.jsx)(so.Text,{size:"sm",children:(0,ce.jsx)(fo,{color:"dark",weight:500,value:l,link:!0})}),(0,ce.jsxs)(so.Text,{size:"xs",children:[(0,ce.jsx)(Re,{color:"dimmed",to:e.resource,children:(0,pn.formatDateTime)(s)}),(0,ce.jsx)(so.Text,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),(0,ce.jsx)(Re,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&(0,ce.jsxs)(so.Menu,{position:"bottom-end",shadow:"md",width:200,children:[(0,ce.jsx)(so.Menu.Target,{children:(0,ce.jsx)(so.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=Hi(t,o),n=Hi(r,o);return a>n?1:a<n?-1:Vi(t,o)-Vi(r,o)})}function Hi(e,o){if(!qi(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Vi(e,o){if(!qi(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 qi(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}var R=require("react/jsx-runtime"),Td=(0,ne.createStyles)(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function Go(e){let o=P(),t=ko(),r=o.getProfile(),a=(0,Qe.useRef)(null),n=K(e.value),[l,s]=(0,Qe.useState)(),[f,i]=(0,Qe.useState)([]),u=e.loadTimelineResources,d=(0,Qe.useRef)(f);d.current=f;let c=(0,Qe.useCallback)(h=>{lf(h,n),h.reverse(),i(h)},[n]),x=(0,Qe.useCallback)(h=>{let U=[];for(let po of h){if(po.status!=="fulfilled")continue;let C=po.value;if(C.type==="history"&&s(C),C.entry)for(let X of C.entry)U.push(X.resource)}c(U)},[c]),S=(0,Qe.useCallback)(h=>c([...d.current,h]),[c]),g=(0,Qe.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,Qe.useEffect)(()=>g(),[g]);function D(h){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,h)).then(U=>S(U)).catch(console.log)}function B(h){!n||!e.createMedia||o.createResource(e.createMedia(n,r,h)).then(U=>S(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 k(h,U){return o.updateResource({...h,priority:U})}function M(h){k(h,"stat").then(g).catch(console.log)}function Z(h){k(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 ve(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:Od(h),autoClose:!1,withCloseButton:!1})}function Me(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)(Fe,{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:Me,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)(kd,{history:l,resource:h,onDetails:ve},U);switch(h.resourceType){case"AuditEvent":return(0,R.jsx)(Fd,{resource:h,onDetails:b},U);case"Communication":return(0,R.jsx)(Ad,{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)(wd,{resource:h,onDetails:b,onEdit:L,onDelete:de},U);case"Media":return(0,R.jsx)(Md,{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)(kr,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${(0,qo.getReferenceString)(e.resource)}`,children:"Delete"})]})]})}function kd(e){let o=Bd(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)(Li,{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 Bd(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 Ad(e){let{classes:o}=Td(),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 Md(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)(lo,{value:e.resource.content})})}function Fd(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 wd(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 Od(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 Gi=require("react/jsx-runtime");function Ed(e){return(0,Gi.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 Ui=require("react/jsx-runtime");function Ld(e){return(0,Ui.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"),ou=require("@medplum/core");var Xe=require("react");var Qi=require("@medplum/core");var Wi=require("react/jsx-runtime");function zi(e){let o;try{o=(0,Qi.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,Wi.jsx)(De,{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 Ji(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)(Xi,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&(0,at.jsx)(Xi,{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 Xi(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 T=require("@medplum/core");var ir=require("react/jsx-runtime"),Nd={string:[T.Operator.EQUALS,T.Operator.NOT,T.Operator.CONTAINS,T.Operator.EXACT],fulltext:[T.Operator.EQUALS,T.Operator.NOT,T.Operator.CONTAINS,T.Operator.EXACT],token:[T.Operator.EQUALS,T.Operator.NOT],reference:[T.Operator.EQUALS,T.Operator.NOT],numeric:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS],quantity:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS],date:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS,T.Operator.STARTS_AFTER,T.Operator.ENDS_BEFORE,T.Operator.APPROXIMATELY],datetime:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS,T.Operator.STARTS_AFTER,T.Operator.ENDS_BEFORE,T.Operator.APPROXIMATELY]},Hd={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 Vd(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 qd(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=$i(e,o,T.Operator.GREATER_THAN_OR_EQUALS,t),e=$i(e,o,T.Operator.LESS_THAN_OR_EQUALS,r),e}function $i(e,o,t,r){return Ot(e,o,t,r.toISOString())}function In(e,o,t=!0){return Ot(e,o,T.Operator.MISSING,t.toString())}function Ki(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function yf(e,o){let t=e.count??T.DEFAULT_SEARCH_COUNT,r=(o-1)*t;return Ki(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 Gd(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 Nd[e.type]}function cr(e){return Hd[e]??""}function ze(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(T.capitalize).join(" "))}function bf(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?(0,T.formatDateTime)(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?Ud(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?Qd(e,o.searchParams[0]):null}function Ud(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=qe({type:e.resourceType,value:e},t);return r?(0,ir.jsx)(De,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function Qd(e,o){let t=(0,T.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)(De,{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 zd(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:ze(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 zd(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(ze(n));if(o)for(let n of Object.keys(o)){let l=ze(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}var We=require("@mantine/core"),ra=require("@medplum/core"),zo=require("react");var io=require("@medplum/core");var Et=require("react/jsx-runtime");function hn(e){let{resourceType:o,filter:t}=e,r=io.globalSchema.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===io.Operator.EQUALS||t.operator===io.Operator.NOT_EQUALS))return(0,Et.jsx)(fo,{value:{reference:t.value}});let a=(0,io.getSearchParameterDetails)(o,r);if(t.code==="_lastUpdated"||a.type===io.SearchParameterType.DATETIME)return(0,Et.jsx)(Et.Fragment,{children:(0,io.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)(oo,{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)(Ge,{name:t,defaultValue:Wd(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 Wd(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)(We.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)(_i,{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)(Xd,{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)(_i,{resourceType:s,searchParams:f,okText:"Add",onOk:l})]})]})}),(0,E.jsx)(We.Group,{position:"right",mt:"xl",children:(0,E.jsx)(We.Button,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function Xd(e){let{filter:o}=e;return(0,E.jsxs)("tr",{children:[(0,E.jsx)("td",{children:ze(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)(We.Button,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),(0,E.jsx)(We.Button,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function _i(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)(We.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:ze(i)}))]})}),(0,E.jsx)("td",{children:f&&(0,E.jsx)(We.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)(We.Button,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&(0,E.jsx)(We.Button,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}var st=require("@mantine/core"),Zi=require("react");var Wo=require("react/jsx-runtime");function Yi(e){let[o,t]=(0,Zi.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"),be=require("@medplum/core");var m=require("react/jsx-runtime");function ji(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)(Jd,{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:ze(n.code)},n.code))})}function Jd(e){switch(e.searchParam.type){case"date":return(0,m.jsx)($d,{...e});case"number":case"quantity":return(0,m.jsx)(Kd,{...e});case"reference":return(0,m.jsx)(_d,{...e});case"string":case"token":case"uri":return(0,m.jsx)(Zd,{...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)(Tr,{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,be.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,be.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,be.Operator.ENDS_BEFORE),children:"Before..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Pa,{size:14}),onClick:()=>e.onPrompt(o,be.Operator.STARTS_AFTER),children:"After..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(jn,{size:14}),onClick:()=>e.onPrompt(o,be.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 Kd(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)(Tr,{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,be.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,be.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,be.Operator.GREATER_THAN),children:"Greater than..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Wt,{size:14}),onClick:()=>e.onPrompt(o,be.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,be.Operator.LESS_THAN),children:"Less than..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Wt,{size:14}),onClick:()=>e.onPrompt(o,be.Operator.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),(0,m.jsx)(yn,{...e})]})}function _d(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,be.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,be.Operator.NOT),children:"Does not equal..."}),(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 A to Z"}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Tr,{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,be.Operator.EQUALS),children:"Equals..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(Qt,{size:14}),onClick:()=>e.onPrompt(o,be.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,be.Operator.CONTAINS),children:"Contains..."}),(0,m.jsx)(A.Menu.Item,{icon:(0,m.jsx)(el,{size:14}),onClick:()=>e.onPrompt(o,be.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 Tf(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(Yd(o,r));return t}function Yd(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 y=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}},jd=(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 eu(e){let{classes:o}=jd(),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)(C=>{l(void 0),t.search(s.resourceType,(0,pr.formatSearchQuery)({...s,total:c,fields:void 0}),C).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]),S=(0,Ve.useCallback)(()=>{u({...d.current,searchResponse:void 0}),x({cache:"reload"})},[x]);(0,Ve.useEffect)(()=>{x()},[x]);function g(C,X){C.stopPropagation();let Se=C.target.checked,ge={...d.current.selected};Se?ge[X]=!0:delete ge[X],u({...d.current,selected:ge})}function D(C){C.stopPropagation();let To=C.target.checked,Se={},ge=d.current.searchResponse;To&&ge?.entry&&ge.entry.forEach(je=>{je.resource?.id&&(Se[je.resource.id]=!0)}),u({...d.current,selected:Se})}function B(){let C=d.current;if(!C.searchResponse?.entry||C.searchResponse.entry.length===0)return!1;for(let X of C.searchResponse.entry)if(X.resource?.id&&!C.selected[X.resource.id])return!1;return!0}function k(C){e.onChange&&e.onChange(new vn(C))}function M(C,X){if(Aa(C.target)||C.button===2)return;N(C);let To=C.button===1||C.ctrlKey||C.metaKey;!To&&e.onClick&&e.onClick(new ut(X,C)),To&&e.onAuxClick&&e.onAuxClick(new ut(X,C))}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,y.jsx)(H.Center,{style:{width:"100%",height:"100%"},children:(0,y.jsx)(H.Loader,{})});let b=e.checkboxesEnabled,L=Tf(s),de=s.resourceType,ve=i.searchResponse,xt=ve?.entry?.map(C=>C.resource),Me="subtle",h="gray",U=16,po=window.innerWidth<768;return(0,y.jsxs)("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&(0,y.jsxs)(H.Group,{position:"apart",mb:"xl",children:[(0,y.jsxs)(H.Group,{spacing:2,children:[(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(al,{size:U}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(ul,{size:U}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(il,{size:U}),onClick:e.onNew,children:"New..."}),!po&&Z()&&(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(vl,{size:U}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!po&&e.onDelete&&(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(kr,{size:U}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!po&&e.onBulk&&(0,y.jsx)(H.Button,{compact:!0,variant:Me,color:h,leftIcon:(0,y.jsx)(Yn,{size:U}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),(0,y.jsxs)(H.Group,{spacing:2,children:[ve&&(0,y.jsxs)(H.Text,{size:"xs",color:"dimmed",children:[am(s,ve.total),"-",nm(s,ve.total)," of"," ",`${c==="estimate"?"~":""}${ve.total?.toLocaleString()}`]}),(0,y.jsx)(H.ActionIcon,{title:"Refresh",onClick:S,children:(0,y.jsx)(gl,{size:"1.125rem"})})]})]}),(0,y.jsxs)(H.Table,{className:o.table,children:[(0,y.jsxs)("thead",{children:[(0,y.jsxs)("tr",{children:[b&&(0,y.jsx)("th",{children:(0,y.jsx)("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:B(),onChange:C=>D(C)})}),L.map(C=>(0,y.jsx)("th",{children:(0,y.jsxs)(H.Menu,{shadow:"md",width:240,position:"bottom-end",children:[(0,y.jsx)(H.Menu.Target,{children:(0,y.jsx)(H.UnstyledButton,{className:o.control,children:(0,y.jsxs)(H.Group,{position:"apart",noWrap:!0,children:[(0,y.jsx)(H.Text,{weight:500,size:"sm",children:ze(C.name)}),(0,y.jsx)(H.Center,{className:o.icon,children:(0,y.jsx)(Jn,{size:14,stroke:1.5})})]})})}),(0,y.jsx)(ji,{search:e.search,searchParams:C.searchParams,onPrompt:(X,To)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:X,filterDialogFilter:To})},onChange:X=>{k(X)}})]})},C.name))]}),!e.hideFilters&&(0,y.jsxs)("tr",{children:[b&&(0,y.jsx)("th",{}),L.map(C=>(0,y.jsx)("th",{children:C.searchParams&&(0,y.jsx)(om,{resourceType:de,searchParams:C.searchParams,filters:e.search.filters})},C.name))]})]}),(0,y.jsx)("tbody",{children:xt?.map(C=>C&&(0,y.jsxs)("tr",{className:o.tr,"data-testid":"search-control-row",onClick:X=>M(X,C),onAuxClick:X=>M(X,C),children:[b&&(0,y.jsx)("td",{children:(0,y.jsx)("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${C.id}`,checked:!!i.selected[C.id],onChange:X=>g(X,C.id)})}),L.map(X=>(0,y.jsx)("td",{children:bf(C,X)},X.name))]},C.id))})]}),xt?.length===0&&(0,y.jsx)(No,{children:(0,y.jsx)(H.Center,{style:{height:150},children:(0,y.jsx)(H.Text,{size:"xl",color:"dimmed",children:"No results"})})}),ve?.total!==void 0&&ve.total>0&&(0,y.jsx)(H.Center,{m:"md",p:"md",children:(0,y.jsx)(H.Pagination,{value:tm(s),total:rm(s,ve.total),onChange:C=>k(yf(s,C)),getControlProps:C=>{switch(C){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&(0,y.jsx)("div",{"data-testid":"search-error",children:(0,y.jsx)("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),(0,y.jsx)(Pf,{search:e.search,visible:d.current.fieldEditorVisible,onOk:C=>{k(C),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),(0,y.jsx)(Df,{search:e.search,visible:d.current.filterEditorVisible,onOk:C=>{k(C),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),(0,y.jsx)(Ji,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),(0,y.jsx)(Yi,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?ze(i.filterDialogSearchParam.code):"",resourceType:de,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:C=>{k(Ot(e.search,C.code,C.operator,C.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var em=(0,Ve.memo)(eu);function om(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?(0,y.jsx)("span",{children:"no filters"}):(0,y.jsx)(y.Fragment,{children:o.map(t=>(0,y.jsxs)("div",{children:[cr(t.operator),"\xA0",(0,y.jsx)(hn,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function tm(e){return Math.floor((e.offset??0)/(e.count??pr.DEFAULT_SEARCH_COUNT))+1}function rm(e,o){let t=e.count??pr.DEFAULT_SEARCH_COUNT;return Math.ceil(o/t)}function am(e,o){return Math.min(o,(e.offset??0)+1)}function nm(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??pr.DEFAULT_SEARCH_COUNT))}var xe=require("react/jsx-runtime");function tu(e){let o=P(),[t,r]=(0,Xe.useState)(!1),[a,n]=(0,Xe.useState)(),{query:l,fields:s}=e,[f,i]=(0,Xe.useState)(),[u,d]=(0,Xe.useState)({}),c=(0,Xe.useRef)();c.current=f;let x=(0,Xe.useRef)({});x.current=u,(0,Xe.useEffect)(()=>{n(void 0),o.graphql(l).then(i).catch(M=>n((0,ou.normalizeOperationOutcome)(M)))},[o,l]);function S(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(ve=>{ve.id&&(L[ve.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,Xe.useEffect)(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return(0,xe.jsx)(xr.Loader,{});let k=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:[k&&(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:[k&&(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=>S(Z,M.id)})}),s.map(Z=>(0,xe.jsx)("td",{children:(0,xe.jsx)(zi,{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 lm=(0,Xe.memo)(tu);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"),kf=require("@medplum/core");var J=require("react/jsx-runtime");function ru(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)(sm,{group:o}),!o.measureScore&&(0,J.jsx)(fm,{group:o})]})})}function au(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 fm(e){let{group:o}=e,t=o.population,r=t?.find(f=>(0,kf.formatCodeableConcept)(f.code)==="numerator"),a=t?.find(f=>(0,kf.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:nu(s)}],label:(0,J.jsx)(re.Flex,{justify:"center",children:(0,J.jsxs)(re.Text,{fw:700,fz:18,children:[n," / ",l]})})})}function sm(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:im(o),color:nu(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 im(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function nu(e){return e<=33?"red":e<=67?"yellow":"green"}var Ir=require("react/jsx-runtime");function um(e){let o=K(e.measureReport),[t]=Gn("Measure",{url:o?.measure});return o?(0,Ir.jsxs)(Rn.Box,{children:[t&&(0,Ir.jsx)(au,{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)(ru,{group:r},r.id??a))})]}):null}var lu=require("@mantine/core"),fu=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)(lu.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,fu.operationOutcomeIssueToString)(t)},t.details?.text))})}var aa=require("@medplum/core"),su=require("react");var iu=require("react/jsx-runtime");function cm(e){let o=(0,su.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,iu.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"),uu=require("@medplum/core");var ao=require("react");var V=require("react/jsx-runtime"),cu=(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 dm(e){let o=P(),t=K(e.value),[r,a]=(0,ao.useState)(!1),[n,l]=(0,ao.useState)(),[s,f]=(0,ao.useState)(),[i,u]=(0,ao.useState)();function d(){f(void 0)}function c(){l(void 0)}let x=(0,ao.useRef)();if(x.current=i,(0,ao.useEffect)(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),(0,ao.useEffect)(()=>(u(hm(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 S(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=>S("title",g.currentTarget.value)}),(0,V.jsx)(du,{actions:i.action||[],selectedKey:n,setSelectedKey:l,hoverKey:s,setHoverKey:f,onChange:g=>S("action",g)}),(0,V.jsx)(we.Button,{type:"submit",children:"Save"})]})})}function du(e){let{classes:o}=cu(),t=(0,ao.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)(mm,{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:pu()})},children:"Add action"})})]})}function mm(e){let{classes:o,cx:t}=cu(),{action:r}=e,a=gm(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)(xm,{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)(pm,{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 pm(e){let{action:o,actionType:t}=e,[r,a]=mu(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)(De,{property:Af,propertyType:a,value:r})})]})}function xm(e){let{action:o}=e,[t,r]=(0,ao.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)(du,{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)(Im,{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,uu.getReferenceString)(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function Im(e){let o=e.action,t="timing",[r,a]=mu(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 gm(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function mu(e){return qe({type:"PlanDefinitionAction",value:e},"timing")}var Bf=1;function pu(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 hm(e){return{...e,action:xu(e.action)}}function xu(e){if(e)return e.map(o=>({...o,id:pu(o.id),action:xu(o.action)}))}var G=require("@mantine/core"),Tn=require("@medplum/core");var So=require("react");var Ie=require("@mantine/core"),j=require("@medplum/core");var Pe=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=Iu(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=ym(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,Pe.formatCoding)(l.valueCoding)===r||l[o]===r),n=(0,Pe.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Iu(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Iu(t.item,o);if(r)return r}}}function Cm(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=(0,Pe.evalFhirPathTyped)(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function ym(e,o,t){let r=o||[],a=(0,Pe.getTypedPropertyValue)({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let s of r){let f=(0,Pe.getTypedPropertyValue)({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(Cm(f,a,i)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function la(e){let o=(0,Pe.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,Pe.deepClone)(e),r=(0,Pe.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,Pe.getReferenceString)(e),item:gu(e.item)}}function gu(e){return e?.map(Dn)??[]}function Dn(e){return{id:Sm(),linkId:e.linkId,text:e.text,item:gu(e.item),answer:e.initial?.map(Rm)??[]}}var vm=1;function Sm(){return"id-"+vm++}function Rm(e){return{...e}}function Ef(e){return e.value.display||e.value.reference||(0,Pe.stringify)(e.value)}function Lf(e){let o=e?.item?.[0];return o&&(0,Pe.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)(oo,{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)(Ge,{name:n,required:o.required,defaultValue:s?.value,onChange:f=>r({valueQuantity:f}),disableWheel:!0});case"choice":case"open-choice":return Bm(o)&&!o.answerValueSet?(0,Y.jsx)(bm,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)}):(0,Y.jsx)(Pm,{name:n,item:o,initial:l,response:t,onChangeAnswer:f=>r(f)});default:return null}}function bm(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return(0,Y.jsx)(yu,{});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(hu(i))}let s=Nf(a)??n;if(t.repeats){let{propertyName:f,data:i}=Am(e.item),u=Tm(a);return(0,Y.jsx)(Ie.MultiSelect,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[hu(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 Pm(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?(0,Y.jsx)(yu,{}):t.answerValueSet?(0,Y.jsx)(qr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):(0,Y.jsx)(Dm,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Dm(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],S=`${o}-option-${c}`,g=(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswerOption",value:x},"value");s&&(0,j.stringify)(g)===(0,j.stringify)(s)&&(i=S),f.push([S,g])}let u=Nf(n),d=km(f,u);return(0,Y.jsx)(Ie.Radio.Group,{name:o,value:d??i,onChange:c=>{let x=f.find(S=>S[0]===c);if(x){let S=x[1],g="value"+(0,j.capitalize)(S.type);a({[g]:S.value})}},children:f.map(([c,x])=>(0,Y.jsx)(Ie.Radio,{id:c,value:c,py:4,label:(0,Y.jsx)(De,{property:l,propertyType:x.type,value:x.value})},c))})}function yu(){return(0,Y.jsx)(Ie.TextInput,{disabled:!0,placeholder:"No Answers Defined"})}function vu(e){return(0,j.getTypedPropertyValue)({type:"QuestionnaireItemAnswer",value:e},"value")}function Nf(e,o=0){let t=e.answer;return vu(t?.[o]??{})}function Tm(e){let o=e.answer;return o?o.map(r=>vu(r)).map(r=>(0,j.formatCoding)(r?.value)||r?.value):[]}function km(e,o){return e.find(t=>(0,j.deepEquals)(t[1].value,o?.value))?.[0]}function hu(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 Bm(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Am(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:Cu(n,r),label:Cu(n,r)}));return{propertyName:r,data:a}}function Cu(e,o){return(0,j.formatCoding)(e.valueCoding)||e[o]?.toString()}var v=require("react/jsx-runtime"),Mm=(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 Fm(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)}return(0,So.useEffect)(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),(0,So.useEffect)(()=>(l(Lm(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]),!r||!n?null:(0,v.jsx)("div",{children:(0,v.jsxs)(oe,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[(0,v.jsx)(Su,{item:n,selectedKey:s,setSelectedKey:f,hoverKey:i,setHoverKey:u,onChange:l}),(0,v.jsx)(G.Button,{type:"submit",children:"Save"})]})})}function Su(e){let{classes:o,cx:t}=Mm(),r=e.item,a=e.item,n=(0,Tn.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 S(b){e.onChange({...e.item,item:[...e.item.item??[],b]})}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 k(b){e.onChange({...e.item,item:e.item.item?.map(L=>L===b?{...L,repeats:!L.repeats}:L)})}function M(b,L){let de=Vm(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,v.jsxs)("div",{"data-testid":a.linkId,className:Z,onClick:d,onMouseOver:c,children:[(0,v.jsx)("div",{className:o.questionBody,children:f?(0,v.jsxs)(v.Fragment,{children:[n&&(0,v.jsx)(G.TextInput,{size:"xl",defaultValue:r.title,onChange:b=>D("title",b.currentTarget.value)}),!n&&(0,v.jsx)(G.Textarea,{autosize:!0,minRows:2,defaultValue:a.text,onChange:b=>D("text",b.currentTarget.value)}),a.type==="reference"&&(0,v.jsx)(Em,{item:a,onChange:B}),Mf(a)&&(0,v.jsx)(wm,{item:a,onChange:b=>B(b)})]}):(0,v.jsxs)(v.Fragment,{children:[r.title&&(0,v.jsx)(G.Title,{children:r.title}),a.text&&(0,v.jsx)("div",{children:a.text}),!l&&(0,v.jsx)(sa,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((b,L)=>(0,v.jsx)("div",{children:(0,v.jsx)(Su,{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:k,onMoveUp:()=>M(L,-1),onMoveDown:()=>M(L,1)})},b.id)),!l&&(0,v.jsx)("div",{className:o.topActions,children:f?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(G.TextInput,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onChange:b=>D("linkId",b.currentTarget.value)}),!l&&(0,v.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,v.jsx)("div",{children:s})}),!n&&(0,v.jsx)(G.Box,{className:o.movementActions,children:(0,v.jsxs)(G.Box,{className:o.columnAlignment,children:[!e.isFirst&&(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:(0,v.jsx)(Kn,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:(0,v.jsx)($n,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),(0,v.jsxs)("div",{className:o.bottomActions,children:[l&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),S({id:Nt(),linkId:qf("q"),type:"string",text:"Question"})},children:"Add item"}),(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),S({id:Nt(),linkId:qf("g"),type:"group",text:"Group"})},children:"Add group"})]}),n&&(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),S(Hm())},children:"Add Page"}),f&&!n&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),(0,v.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function wm(e){let o=(0,Tn.getElementDefinition)("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return(0,v.jsxs)("div",{children:[e.item.answerValueSet!==void 0?(0,v.jsx)(G.TextInput,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):(0,v.jsx)(Om,{options:t,property:o,item:e.item,onChange:e.onChange}),(0,v.jsxs)(G.Box,{display:"flex",children:[(0,v.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:Nt()}]})},children:"Add choice"}),(0,v.jsx)(G.Space,{w:"lg"}),(0,v.jsx)(G.Anchor,{href:"#",onClick:r=>{N(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Om(e){return(0,v.jsx)("div",{children:e.options.map(o=>{let[t,r]=qe({type:"QuestionnaireItemAnswerOption",value:o},"value");return(0,v.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[(0,v.jsx)("div",{children:(0,v.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,v.jsx)("div",{children:(0,v.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 Em(e){let o=la(e.item)??[];return(0,v.jsxs)(v.Fragment,{children:[o.map((t,r)=>(0,v.jsxs)(G.Group,{children:[(0,v.jsx)(Jt,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(fa(e.item,o.map(n=>n===t?a:n)))}}),(0,v.jsx)(G.Anchor,{href:"#",onClick:a=>{N(a),e.onChange(fa(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),(0,v.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 Lm(e){return{...e,id:e.id||Nt(),item:Ru(e.item)}}function Ru(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:Ru(o.item),answerOption:Nm(o.answerOption)}))}function Nm(e){if(e)return e.map(o=>({...o,id:o.id||Nt()}))}function Hm(){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 Vm(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 Bu=require("@mantine/core"),Bn=require("@medplum/core");var Vt=require("react");var uo=require("@mantine/core");var bu=require("@mantine/core"),Pu=require("react");var Ht=require("react/jsx-runtime");function kn(e){let{item:o,response:t,onChange:r}=e,[a,n]=(0,Pu.useState)(qm(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)(bu.Anchor,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function qm(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"),Du=require("react");var Je=require("react/jsx-runtime");function Gf(e){let[o,t]=(0,Du.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,Je.jsxs)(Je.Fragment,{children:[o.map((n,l)=>(0,Je.jsx)(Tu,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,l)},n.id)),e.item.repeats&&(0,Je.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,Je.jsxs)("div",{children:[e.item.text&&(0,Je.jsx)(gr.Title,{order:3,mb:"md",children:e.item.text}),(0,Je.jsx)(gr.Stack,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?(0,Je.jsx)(Gf,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):(0,Je.jsx)(Tu,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):(0,Je.jsx)(kn,{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 ku(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)??[],S=c.type==="group"?(0,Oe.jsx)(Gf,{item:c,response:x,onChange:a,checkForQuestionEnabled:u},c.linkId):(0,Oe.jsx)(kn,{item:c,response:x?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return f?(0,Oe.jsx)(uo.Stepper.Step,{label:c.text,children:S},c.linkId):S});return(0,Oe.jsxs)(Oe.Fragment,{children:[f&&(0,Oe.jsx)(uo.Stepper,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!f&&(0,Oe.jsx)(uo.Stack,{children:d}),(0,Oe.jsx)(Gm,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:l,submitButtonText:i})]})}function Gm(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return(0,Oe.jsxs)(uo.Group,{position:"right",mt:"xl",spacing:"xs",children:[o&&(0,Oe.jsx)(uo.Button,{onClick:e.prevStep,children:"Back"}),t&&(0,Oe.jsx)(uo.Button,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&(0,Oe.jsx)(uo.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??[],k={resourceType:"QuestionnaireResponse",item:Au(D,Array.isArray(g)?g:[g])};s(k)}function d(g){return Ff(g,l?.item??[])}if(!r||!n)return null;let c=Lf(n),x=()=>i(g=>g+1),S=()=>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)(Bu.Title,{children:n.title}),(0,ia.jsx)(ku,{items:n.item??[],response:l,onChange:u,renderPages:c>1,activePage:f,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:x,prevStep:S})]})}function Um(e,o){let t=Au(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 Au(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(Um(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"),Qm=(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"}})),zm=["gender","age","gestationalAge","context","appliesTo","category"],Wm={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function Xm(e){e=Object.assign(Wm,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 S=$m(o,s);r(Km(S.qualifiedInterval||[],n))},[o]),(0,z.jsxs)(oe,{testid:"reference-range-editor",onSubmit:f,children:[(0,z.jsx)($.Stack,{children:t.map(S=>(0,z.jsx)(Mu,{unit:Zm(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:x,onRemoveGroup:u,intervalGroup:S},`group-${S.id}`))}),(0,z.jsx)($.ActionIcon,{title:"Add Group",size:"sm",onClick:S=>{N(S),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 S=t.flatMap(g=>g.intervals).filter(g=>!Ym(g));e.onSubmit({...o,qualifiedInterval:S})}function i(S){r(g=>[...g,S])}function u(S){r(g=>g.filter(D=>D.id!==S.id))}function d(S,g){r(D=>{D=[...D];let B=D.find(M=>M.id===S),k=B?.intervals.findIndex(M=>M.id===g.id);return k!==void 0&&B?.intervals[k]&&(B.intervals[k]=g),D})}function c(S,g){g.id===void 0&&(g.id=`id-${l}`,s(D=>D+1)),r(D=>{D=[...D];let B=D.findIndex(k=>k.id===S);if(B!==-1){let k={...D[B]};g={...g,...k.filters},k.intervals=[...k.intervals,g],D[B]=k}return D})}function x(S,g){r(D=>{D=[...D];let B=D.find(k=>k.id===S);return B&&(B.intervals=B.intervals.filter(k=>k.id!==g.id)),D})}}function Mu(e){let{intervalGroup:o,unit:t}=e,{classes:r}=Qm();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)(Jm,{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 Jm(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 Km(e,o){let t=1,r={};for(let a of e){let n=_m(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(zm.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function _m(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 Zm(e){return e&&((0,ua.getCodeBySystem)(e,"http://unitsofmeasure.org")||e.text)}function Ym(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 jm(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)(fo,{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 Lu=require("@mantine/core");var Fn=require("react");var Fu=require("@medplum/core");function Mn(e,o){let t=ep(e,o);return op(t,e,o)}function ep(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],S=s[c],g,D=0;i===-f||i!==f&&S.i<x.i?(D=x.i,g=x):(D=S.i+1,g=S),s[c]=void 0;let B=D-i,k={i:D,j:B,prev:tp(g),snake:!1};for(;D<t&&B<r&&e[D]===o[B];)D++,B++;if(D>k.i&&(k={i:D,j:B,prev:k,snake:!0}),s[u]=k,D>=t&&B>=r)return s[u]}s[l+f-1]=void 0}}function op(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 tp(e){return e&&!e.snake&&e.prev?e.prev:e}function wu(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:(0,Fu.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 rp(t,o),ap(t),t}function rp(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 ap(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 Ou(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Eu(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 Be=require("react/jsx-runtime"),np=(0,Lu.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 lp(e){let{classes:o}=np(),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,Be.jsx)("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=wu(r);return(0,Be.jsx)("div",{className:o.container,children:(0,Be.jsx)("table",{className:o.root,children:(0,Be.jsx)("tbody",{children:l.map((s,f)=>(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)(Ho,{value:s.meta.author,link:!0})}),(0,Be.jsx)("td",{className:o.dateTime,rowSpan:s.span,children:(0,Be.jsx)(Re,{to:Ou(n,s.meta.versionId),children:Eu(s.meta.lastUpdated)})})]}),(0,Be.jsx)("td",{className:o.lineNumber,children:f+1}),(0,Be.jsx)("td",{className:o.line,children:(0,Be.jsx)("pre",{className:o.pre,children:s.value})})]},"row-"+f))})})})}var Nu=require("@mantine/core"),Qf=require("@medplum/core");var co=require("react/jsx-runtime"),fp=(0,Nu.createStyles)(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function sp(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,co.jsx)("pre",{style:{color:"gray"},children:n.map((l,s)=>(0,co.jsx)(ip,{delta:l},"delta"+s))})}function ip(e){let{classes:o}=fp();return(0,co.jsxs)(co.Fragment,{children:["...",(0,co.jsx)("br",{}),e.delta.original.lines.length>0&&(0,co.jsx)("div",{className:o.removed,children:e.delta.original.lines.join(`
66
- `)}),e.delta.revised.lines.length>0&&(0,co.jsx)("div",{className:o.added,children:e.delta.revised.lines.join(`
67
- `)}),"...",(0,co.jsx)("br",{})]})}var bo=require("@mantine/core"),Hu=require("@medplum/core");var ca=require("react");var $e=require("react/jsx-runtime");function up(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,Hu.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)(bo.Stack,{mb:"xl",children:[(0,$e.jsx)(He,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:(0,$e.jsx)(bo.TextInput,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),(0,$e.jsx)(He,{title:"ID",htmlFor:"id",outcome:e.outcome,children:(0,$e.jsx)(bo.TextInput,{name:"id",defaultValue:n.id,disabled:!0})})]}),(0,$e.jsx)(ar,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:l}),(0,$e.jsxs)(bo.Group,{position:"right",mt:"xl",children:[(0,$e.jsx)(bo.Button,{type:"submit",children:"OK"}),e.onDelete&&(0,$e.jsx)(bo.Button,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}var Vu=require("@mantine/core"),wn=require("@medplum/core");var On=require("react");var ye=require("react/jsx-runtime");function cp(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,ye.jsxs)(Vu.Table,{withBorder:!0,withColumnBorders:!0,children:[(0,ye.jsx)("thead",{children:(0,ye.jsxs)("tr",{children:[(0,ye.jsx)("th",{children:"Author"}),(0,ye.jsx)("th",{children:"Date"}),(0,ye.jsx)("th",{children:"Version"})]})}),(0,ye.jsx)("tbody",{children:t.entry?.map((a,n)=>(0,ye.jsx)(dp,{entry:a},"entry-"+n))})]}):(0,ye.jsx)("div",{children:"Loading..."})}function dp(e){let{response:o,resource:t}=e.entry;return t?(0,ye.jsxs)("tr",{children:[(0,ye.jsx)("td",{children:(0,ye.jsx)(Ho,{value:t.meta?.author,link:!0})}),(0,ye.jsx)("td",{children:(0,wn.formatDateTime)(t.meta?.lastUpdated)}),(0,ye.jsx)("td",{children:(0,ye.jsx)(Re,{to:mp(t),children:t.meta?.versionId})})]}):(0,ye.jsx)("tr",{children:(0,ye.jsx)("td",{colSpan:3,children:(0,wn.normalizeErrorString)(o?.outcome)})})}function mp(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"),pp=(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 xp(e){let{classes:o}=pp(),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"+Ip(a)],["start","lt"+gp(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)(Fe,{value:x,size:"xl"}),x&&(0,se.jsx)(ct.Text,{size:"xl",weight:500,children:(0,se.jsx)(fo,{value:x})}),(0,se.jsx)("p",{children:"1 hour"}),l&&(0,se.jsx)("p",{children:l.toLocaleDateString()}),f&&(0,se.jsx)("p",{children:qu(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(S=>{let g=new Date(S.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(S),children:qu(g)})},S.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 Ip(e){return Gu(e.getTime())}function gp(e){return Gu(e.getTime()+31*24*60*60*1e3)}function Gu(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function qu(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}var ma=require("@medplum/core");var Uu=require("react/jsx-runtime");function hp(e){return(0,Uu.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 Ju=require("@medplum/core");var xa=require("react");var Ae=require("@mantine/core"),Qu=require("@medplum/core"),zu=require("react");var Ke=require("react/jsx-runtime");function Ln(e){let o=P(),[t,r]=(0,zu.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,Qu.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"),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 Wu=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,Wu.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 Xu(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:Te(a,"firstName")}),(0,le.jsx)(ee.TextInput,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:Te(a,"lastName")}),(0,le.jsx)(ee.TextInput,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:Te(a,"email")}),(0,le.jsx)(ee.PasswordInput,{name:"password",label:"Password",autoComplete:"off",required:!0,error:Te(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 Cp(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,Ju.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)(Xu,{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"),$u=require("@medplum/core");var mt=require("react");var ae=require("react/jsx-runtime");function Ku(e){let[o,t]=(0,mt.useState)();return o?(0,ae.jsx)(vp,{email:o,...e}):(0,ae.jsx)(yp,{setEmail:t,...e})}function yp(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}),S=new URL(c.authorizeUrl);return S.searchParams.set("state",x),window.location.assign(S.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 vp(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,$u.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:Te(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"),_u=require("@medplum/core"),Zu=require("react");var _e=require("react/jsx-runtime");function Yu(e){let o=P(),[t,r]=(0,Zu.useState)();return(0,_e.jsxs)(Ee.Stack,{children:[(0,_e.jsxs)(Ee.Center,{sx:{flexDirection:"column"},children:[(0,_e.jsx)(Jo,{size:32}),(0,_e.jsx)(Ee.Title,{order:3,children:"Choose profile"})]}),(0,_e.jsx)(Lt,{outcome:t}),e.memberships.map(a=>(0,_e.jsx)(Ee.UnstyledButton,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r((0,_u.normalizeOperationOutcome)(n)))},children:(0,_e.jsxs)(Ee.Group,{children:[(0,_e.jsx)(Ee.Avatar,{radius:"xl"}),(0,_e.jsxs)("div",{style:{flex:1},children:[(0,_e.jsx)(Ee.Text,{size:"sm",weight:500,children:a.profile?.display}),(0,_e.jsx)(Ee.Text,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}var Ze=require("@mantine/core");var mo=require("react/jsx-runtime");function ju(e){let o=P();return(0,mo.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,mo.jsxs)(Ze.Stack,{children:[(0,mo.jsxs)(Ze.Center,{sx:{flexDirection:"column"},children:[(0,mo.jsx)(Jo,{size:32}),(0,mo.jsx)(Ze.Title,{children:"Choose scope"})]}),(0,mo.jsx)(Ze.Stack,{children:(e.scope??"openid").split(" ").map(t=>(0,mo.jsx)(Ze.Checkbox,{id:t,name:t,label:t,defaultChecked:!0},t))}),(0,mo.jsx)(Ze.Group,{position:"right",mt:"xl",children:(0,mo.jsx)(Ze.Button,{type:"submit",children:"Set scope"})})]})})}var Le=require("@mantine/core"),ec=require("@medplum/core");var oc=require("react");var Ye=require("react/jsx-runtime");function tc(e){let o=P(),[t,r]=(0,oc.useState)();return(0,Ye.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,ec.normalizeErrorString)(n)))},children:(0,Ye.jsxs)(Le.Stack,{children:[(0,Ye.jsxs)(Le.Center,{sx:{flexDirection:"column"},children:[(0,Ye.jsx)(Jo,{size:32}),(0,Ye.jsx)(Le.Title,{children:"Enter MFA code"})]}),t&&(0,Ye.jsx)(Le.Alert,{icon:(0,Ye.jsx)(Ct,{size:16}),title:"Error",color:"red",children:t}),(0,Ye.jsx)(Le.Stack,{children:(0,Ye.jsx)(Le.TextInput,{name:"token",label:"MFA code",required:!0})}),(0,Ye.jsx)(Le.Group,{position:"right",mt:"xl",children:(0,Ye.jsx)(Le.Button,{type:"submit",children:"Submit code"})})]})})}var pt=require("react/jsx-runtime");function Sp(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,S]=(0,Po.useState)(),g=(0,Po.useCallback)(k=>{l?l(k):f.processCode(k).then(()=>{r&&r()}).catch(M=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(M)}))},[f,l,r]),D=(0,Po.useCallback)(k=>{c(!!k.mfaRequired),k.login&&u(k.login),k.memberships&&S(k.memberships),k.code&&(t?S(void 0):g(k.code))},[t,g]),B=(0,Po.useCallback)(k=>{g(k.code)},[g]);return(0,Po.useEffect)(()=>{o&&!i&&f.get("auth/login/"+o).then(D).catch(k=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(k)}))},[f,o,i,D]),(0,pt.jsx)(ea,{width:450,children:(()=>i?d?(0,pt.jsx)(tc,{login:i,handleAuthResponse:D}):x?(0,pt.jsx)(Yu,{login:i,memberships:x,handleAuthResponse:D}):e.projectId==="new"?(0,pt.jsx)(Ln,{login:i,handleAuthResponse:D}):e.chooseScopes?(0,pt.jsx)(ju,{login:i,scope:e.scope,handleAuthResponse:B}):(0,pt.jsx)("div",{children:"Success"}):(0,pt.jsx)(Ku,{onForgotPassword:a,onRegister:n,handleAuthResponse:D,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children}))()})}
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 Tl(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 kl(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=kl(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 Ts=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 ks=require("react/jsx-runtime");function Fr(e){let[o,t]=(0,Ts.useState)(e.defaultValue);function r(a){let n=a[0],l=Uc(n);t(l),e.onChange&&e.onChange(l)}return(0,ks.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=ko(),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)(ka,{}):(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)(Tl,{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)(ka,{}),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 Tt=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)(Tt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,jt.jsx)(Tt.NativeSelect,{"data-testid":"system",defaultValue:o?.system,onChange:f=>n(f.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),(0,jt.jsx)(Tt.NativeSelect,{"data-testid":"use",defaultValue:o?.use,onChange:f=>l(f.currentTarget.value),data:["","home","work","temp","old","mobile"]}),(0,jt.jsx)(Tt.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 kt=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)(kt.Group,{spacing:"xs",grow:!0,noWrap:!0,children:[(0,or.jsx)(kt.NativeSelect,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),(0,or.jsx)(kt.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)(kt.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 Ti=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)(Ti.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 ki=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)(ki.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"),Td=(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}=Td(),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=kd(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 kd(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=ko(),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 k(h,U){return o.updateResource({...h,priority:U})}function M(h){k(h,"stat").then(g).catch(console.log)}function Z(h){k(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)(kr,{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 T=require("@medplum/core");var ir=require("react/jsx-runtime"),Vd={string:[T.Operator.EQUALS,T.Operator.NOT,T.Operator.CONTAINS,T.Operator.EXACT],fulltext:[T.Operator.EQUALS,T.Operator.NOT,T.Operator.CONTAINS,T.Operator.EXACT],token:[T.Operator.EQUALS,T.Operator.NOT],reference:[T.Operator.EQUALS,T.Operator.NOT],numeric:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS],quantity:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS],date:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS,T.Operator.STARTS_AFTER,T.Operator.ENDS_BEFORE,T.Operator.APPROXIMATELY],datetime:[T.Operator.EQUALS,T.Operator.NOT_EQUALS,T.Operator.GREATER_THAN,T.Operator.LESS_THAN,T.Operator.GREATER_THAN_OR_EQUALS,T.Operator.LESS_THAN_OR_EQUALS,T.Operator.STARTS_AFTER,T.Operator.ENDS_BEFORE,T.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,T.Operator.GREATER_THAN_OR_EQUALS,t),e=Ki(e,o,T.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,T.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??T.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(T.capitalize).join(" "))}function bf(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?(0,T.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,T.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)(Tr,{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)(Tr,{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)(Tr,{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 Tf(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 To=y.target.checked,ve={},ge=d.current.searchResponse;To&&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 k(y){e.onChange&&e.onChange(new vn(y))}function M(y,X){if(Aa(y.target)||y.button===2)return;N(y);let To=y.button===1||y.ctrlKey||y.metaKey;!To&&e.onClick&&e.onClick(new ut(X,y)),To&&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=Tf(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)(kr,{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,To)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:X,filterDialogFilter:To})},onChange:X=>{k(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=>k(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=>{k(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=>{k(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=>{k(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 k=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:[k&&(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:[k&&(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"),kf=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,kf.formatCodeableConcept)(f.code)==="numerator"),a=t?.find(f=>(0,kf.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"),Tn=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)(Tm,{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 Tm(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)(km,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function km(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)}return(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]),!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:l}),(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,Tn.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){e.onChange({...e.item,item:[...e.item.item??[],b]})}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 k(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,onChange:b=>D("title",b.currentTarget.value)}),!n&&(0,S.jsx)(G.Textarea,{autosize:!0,minRows:2,defaultValue:a.text,onChange: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:k,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,onChange: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"})},children:"Add group"})]}),n&&(0,S.jsx)(G.Anchor,{href:"#",onClick:b=>{b.preventDefault(),C(qm())},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,Tn.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 kn(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"),Tu=require("react");var Xe=require("react/jsx-runtime");function Gf(e){let[o,t]=(0,Tu.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)(ku,{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 ku(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)(ku,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):(0,Xe.jsx)(kn,{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)(kn,{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??[],k={resourceType:"QuestionnaireResponse",item:Mu(D,Array.isArray(g)?g:[g])};s(k)}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),k=B?.intervals.findIndex(M=>M.id===g.id);return k!==void 0&&B?.intervals[k]&&(B.intervals[k]=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(k=>k.id===C);if(B!==-1){let k={...D[B]};g={...g,...k.filters},k.intervals=[...k.intervals,g],D[B]=k}return D})}function x(C,g){r(D=>{D=[...D];let B=D.find(k=>k.id===C);return B&&(B.intervals=B.intervals.filter(k=>k.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 Te=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,Te.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,Te.jsxs)(qt.Fragment,{children:[(0,Te.jsx)(Ro.Grid.Col,{span:1,p:"md",children:d?.status==="completed"?(0,Te.jsx)(tl,{}):(0,Te.jsx)(Cl,{color:"gray"})}),(0,Te.jsxs)(Ro.Grid.Col,{span:9,p:"xs",children:[(0,Te.jsx)(Ro.Text,{weight:500,children:i.title}),i.description&&(0,Te.jsx)("div",{children:i.description}),(0,Te.jsxs)("div",{children:["Last edited by\xA0",(0,Te.jsx)(lo,{value:d?.meta?.author}),"\xA0on\xA0",(0,An.formatDateTime)(d?.meta?.lastUpdated)]}),(0,Te.jsxs)("div",{children:["Status: ",(0,Te.jsx)(jr,{status:d?.status||"unknown"})]})]}),(0,Te.jsxs)(Ro.Grid.Col,{span:2,p:"md",children:[c&&!x&&(0,Te.jsx)(Ro.Button,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&x&&(0,Te.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,k={i:D,j:B,prev:ap(g),snake:!1};for(;D<t&&B<r&&e[D]===o[B];)D++,B++;if(D>k.i&&(k={i:D,j:B,prev:k,snake:!0}),s[u]=k,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 ke=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,ke.jsx)("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Ou(r);return(0,ke.jsx)("div",{className:o.container,children:(0,ke.jsx)("table",{className:o.root,children:(0,ke.jsx)("tbody",{children:l.map((s,f)=>(0,ke.jsxs)("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&(0,ke.jsxs)(ke.Fragment,{children:[(0,ke.jsx)("td",{className:o.author,rowSpan:s.span,children:(0,ke.jsx)(Ho,{value:s.meta.author,link:!0})}),(0,ke.jsx)("td",{className:o.dateTime,rowSpan:s.span,children:(0,ke.jsx)(Se,{to:Eu(n,s.meta.versionId),children:Lu(s.meta.lastUpdated)})})]}),(0,ke.jsx)("td",{className:o.lineNumber,children:f+1}),(0,ke.jsx)("td",{className:o.line,children:(0,ke.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)(k=>{l?l(k):f.processCode(k).then(()=>{r&&r()}).catch(M=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(M)}))},[f,l,r]),D=(0,Po.useCallback)(k=>{c(!!k.mfaRequired),k.login&&u(k.login),k.memberships&&C(k.memberships),k.code&&(t?C(void 0):g(k.code))},[t,g]),B=(0,Po.useCallback)(k=>{g(k.code)},[g]);return(0,Po.useEffect)(()=>{o&&!i&&f.get("auth/login/"+o).then(D).catch(k=>(0,Jf.showNotification)({color:"red",message:(0,$f.normalizeErrorString)(k)}))},[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}))()})}
68
68
  //# sourceMappingURL=index.cjs.map