@medplum/react 2.2.3 → 2.2.4

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
- var Eu=Object.create;var tf=Object.defineProperty;var Lu=Object.getOwnPropertyDescriptor;var Nu=Object.getOwnPropertyNames;var Hu=Object.getPrototypeOf,Vu=Object.prototype.hasOwnProperty;var at=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var qu=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of Nu(o))!Vu.call(e,a)&&a!==t&&tf(e,a,{get:()=>o[a],enumerable:!(r=Lu(o,a))||r.enumerable});return e};var Gu=(e,o,t)=>(t=e!=null?Eu(Hu(e)):{},qu(o||!e||!e.__esModule?tf(t,"default",{value:e,enumerable:!0}):t,e));var _a=at(mr=>{"use strict";Object.defineProperty(mr,"__esModule",{value:!0});mr.Pointer=void 0;function FI(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function wI(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var OI=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(FI);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(wI).join("/")},e.prototype.evaluate=function(o){for(var t=null,r="",a=o,n=1,f=this.tokens.length;n<f;n++)t=a,r=this.tokens[n],!(r=="__proto__"||r=="constructor"||r=="prototype")&&(a=(t||{})[r]);return{parent:t,key:r,value:a}},e.prototype.get=function(o){return this.evaluate(o).value},e.prototype.set=function(o,t){var r=this.evaluate(o);r.parent&&(r.parent[r.key]=t)},e.prototype.push=function(o){this.tokens.push(o)},e.prototype.add=function(o){var t=this.tokens.concat(String(o));return new e(t)},e}();mr.Pointer=OI});var Za=at(Ge=>{"use strict";Object.defineProperty(Ge,"__esModule",{value:!0});Ge.clone=Ge.objectType=Ge.hasOwnProperty=void 0;Ge.hasOwnProperty=Object.prototype.hasOwnProperty;function EI(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ge.objectType=EI;function LI(e){return e!=null&&typeof e=="object"}function Ka(e){if(!LI(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=Ka(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var f in e)Ge.hasOwnProperty.call(e,f)&&(n[f]=Ka(e[f]));return n}Ge.clone=Ka});var en=at(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});de.diffAny=de.diffObjects=de.diffArrays=de.intersection=de.subtract=de.isDestructive=void 0;var Pt=Za();function NI(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}de.isDestructive=NI;function ja(e,o){var t={};for(var r in e)Pt.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Pt.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}de.subtract=ja;function Yl(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Pt.hasOwnProperty.call(a,n)&&a[n]!==void 0&&(t[n]=(t[n]||0)+1)}for(var n in t)t[n]<o&&delete t[n];return Object.keys(t)}de.intersection=Yl;function HI(e){return e.op==="add"}function VI(e){return e.op==="remove"}function Ya(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function jl(e,o,t,r){r===void 0&&(r=pr);var a={"0,0":{operations:[],cost:0}};function n(u,d){var c="".concat(u,",").concat(d),m=a[c];if(m===void 0){if(u>0&&d>0&&!r(e[u-1],o[d-1],t.add(String(u-1))).length)m=n(u-1,d-1);else{var g=[];if(u>0){var I=n(u-1,d),v={op:"remove",index:u-1};g.push(Ya(I,v))}if(d>0){var P=n(u,d-1),b={op:"add",index:u-1,value:o[d-1]};g.push(Ya(P,b))}if(u>0&&d>0){var T=n(u-1,d-1),q={op:"replace",index:u-1,original:e[u-1],value:o[d-1]};g.push(Ya(T,q))}var y=g.sort(function(M,_){return M.cost-_.cost})[0];m=y}a[c]=m}return m}var f=isNaN(e.length)||e.length<=0?0:e.length,s=isNaN(o.length)||o.length<=0?0:o.length,l=n(f,s).operations,i=l.reduce(function(u,d){var c=u[0],m=u[1];if(HI(d)){var g=d.index+1+m,I=g<f+m?String(g):"-",v={op:d.op,path:t.add(I).toString(),value:d.value};return[c.concat(v),m+1]}else if(VI(d)){var v={op:d.op,path:t.add(String(d.index+m)).toString()};return[c.concat(v),m-1]}else{var P=t.add(String(d.index+m)),b=r(d.original,d.value,P);return[c.concat.apply(c,b),m]}},[[],0])[0];return i}de.diffArrays=jl;function es(e,o,t,r){r===void 0&&(r=pr);var a=[];return ja(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),ja(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),Yl([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}de.diffObjects=es;function pr(e,o,t,r){if(r===void 0&&(r=pr),e===o)return[];var a=(0,Pt.objectType)(e),n=(0,Pt.objectType)(o);return a=="array"&&n=="array"?jl(e,o,t,r):a=="object"&&n=="object"?es(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}de.diffAny=pr});var us=at($=>{"use strict";var on=$&&$.__extends||function(){var e=function(o,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,a){r.__proto__=a}||function(r,a){for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(r[n]=a[n])},e(o,t)};return function(o,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(o,t);function r(){this.constructor=o}o.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}();Object.defineProperty($,"__esModule",{value:!0});$.apply=$.InvalidOperationError=$.test=$.copy=$.move=$.replace=$.remove=$.add=$.TestError=$.MissingError=void 0;var Ue=_a(),tn=Za(),qI=en(),Fe=function(e){on(o,e);function o(t){var r=e.call(this,"Value required at path: ".concat(t))||this;return r.path=t,r.name="MissingError",r}return o}(Error);$.MissingError=Fe;var os=function(e){on(o,e);function o(t,r){var a=e.call(this,"Test failed: ".concat(t," != ").concat(r))||this;return a.actual=t,a.expected=r,a.name="TestError",a}return o}(Error);$.TestError=os;function rn(e,o,t){if(Array.isArray(e))if(o=="-")e.push(t);else{var r=parseInt(o,10);e.splice(r,0,t)}else e[o]=t}function ts(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function rs(e,o){var t=Ue.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new Fe(o.path):(rn(t.parent,t.key,(0,tn.clone)(o.value)),null)}$.add=rs;function as(e,o){var t=Ue.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new Fe(o.path):(ts(t.parent,t.key),null)}$.remove=as;function ns(e,o){var t=Ue.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new Fe(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new Fe(o.path)}else if(t.value===void 0)return new Fe(o.path);return t.parent[t.key]=(0,tn.clone)(o.value),null}$.replace=ns;function fs(e,o){var t=Ue.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Fe(o.from);var r=Ue.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Fe(o.path):(ts(t.parent,t.key),rn(r.parent,r.key,t.value),null)}$.move=fs;function ls(e,o){var t=Ue.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Fe(o.from);var r=Ue.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Fe(o.path):(rn(r.parent,r.key,(0,tn.clone)(t.value)),null)}$.copy=ls;function ss(e,o){var t=Ue.Pointer.fromJSON(o.path).evaluate(e);return(0,qI.diffAny)(t.value,o.value,new Ue.Pointer).length?new os(t.value,o.value):null}$.test=ss;var is=function(e){on(o,e);function o(t){var r=e.call(this,"Invalid operation: ".concat(t.op))||this;return r.operation=t,r.name="InvalidOperationError",r}return o}(Error);$.InvalidOperationError=is;function GI(e,o){switch(o.op){case"add":return rs(e,o);case"remove":return as(e,o);case"replace":return ns(e,o);case"move":return fs(e,o);case"copy":return ls(e,o);case"test":return ss(e,o)}return new is(o)}$.apply=GI});var ds=at(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.createTests=we.createPatch=we.applyPatch=we.Pointer=void 0;var an=_a();Object.defineProperty(we,"Pointer",{enumerable:!0,get:function(){return an.Pointer}});var UI=us(),nn=en();function QI(e,o){return o.map(function(t){return(0,UI.apply)(e,t)})}we.applyPatch=QI;function zI(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,nn.diffAny)(t,r,a,o)}return o}function WI(e,o,t){var r=new an.Pointer;return(t?zI(t):nn.diffAny)(e,o,r)}we.createPatch=WI;function cs(e,o){var t=an.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function XI(e,o){var t=new Array;return o.filter(nn.isDestructive).forEach(function(r){var a=cs(e,r.path);if(a&&t.push(a),"from"in r){var n=cs(e,r.from);n&&t.push(n)}}),t}we.createTests=XI});import{useEffect as rf,useMemo as Uu,useState as Qu}from"react";import{createContext as zu,useContext as Wu}from"react";import{jsx as Xu}from"react/jsx-runtime";import{deepEquals as $u,isReference as lf,isResource as _u,normalizeOperationOutcome as Ku}from"@medplum/core";import{useCallback as Zu,useEffect as af,useState as Yu}from"react";import{allOk as ju,normalizeOperationOutcome as ec}from"@medplum/core";import{useEffect as oc,useState as Vt}from"react";var ff=zu(void 0);function nt(){return Wu(ff)}function S(){return nt().medplum}function $e(){return nt().navigate}function qt(){return nt().profile}function GS(e){let o=e.medplum,t=e.navigate??Ju,[r,a]=Qu({profile:o.getProfile(),loading:!o.isInitialized});rf(()=>{o&&(o.isInitialized||(a(f=>({...f,loading:!0})),o.getInitPromise().then(()=>a(f=>({...f,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),rf(()=>{function f(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",f),()=>o.removeEventListener("change",f)},[o,r]);let n=Uu(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return Xu(ff.Provider,{value:n,children:e.children})}function Ju(e){window.location.assign(e)}function U(e,o){let t=S(),[r,a]=Yu(nf(t,e)),n=Zu(f=>{$u(f,r)||a(f)},[r,a]);return af(()=>{n(nf(t,e))},[t,e,n]),af(()=>{let f=!0;return lf(e)&&t.readReference(e).then(s=>{f&&n(s)}).catch(s=>{f&&(n(void 0),o&&o(Ku(s)))}),()=>f=!1},[t,r,e,n,o]),r}function nf(e,o){if(o){if(_u(o))return o;if(lf(o))return e.getCachedReference(o)}}function XS(e,o){return ea("search",e,o)}function sf(e,o){return ea("searchOne",e,o)}function uf(e,o){return ea("searchResources",e,o)}function ea(e,o,t){let r=S(),[a,n]=Vt(),[f,s]=Vt(!1),[l,i]=Vt(),[u,d]=Vt();return oc(()=>{let c=r.fhirSearchUrl(o,t).toString();c!==a&&(n(c),r[e](o,t).then(m=>{s(!1),i(m),d(ju)}).catch(m=>{s(!1),i(void 0),d(ec(m))}))},[r,e,o,t,a,i]),[l,f,u]}import{formatAddress as tc}from"@medplum/core";import{Fragment as rc,jsx as ac}from"react/jsx-runtime";function cf(e){let o=e.value;return o?ac(rc,{children:tc(o)}):null}import{Group as nc,NativeSelect as df,TextInput as ft}from"@mantine/core";import{useRef as fc,useState as lc}from"react";import{jsx as fo,jsxs as sc}from"react/jsx-runtime";function mf(e,o){return e.line&&e.line.length>o?e.line[o]:""}function pf(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function xf(e){let[o,t]=lc(e.defaultValue||{}),r=fc();r.current=o;function a(c){t(c),e.onChange&&e.onChange(c)}function n(c){a({...r.current,use:c})}function f(c){a({...r.current,type:c})}function s(c){a(pf(r.current||{},0,c))}function l(c){a(pf(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 sc(nc,{spacing:"xs",grow:!0,noWrap:!0,children:[fo(df,{"data-testid":"address-use",defaultValue:o.use,onChange:c=>n(c.currentTarget.value),data:["","home","work","temp","old","billing"]}),fo(df,{"data-testid":"address-type",defaultValue:o.type,onChange:c=>f(c.currentTarget.value),data:["","postal","physical","both"]}),fo(ft,{placeholder:"Line 1",defaultValue:mf(o,0),onChange:c=>s(c.currentTarget.value)}),fo(ft,{placeholder:"Line 2",defaultValue:mf(o,1),onChange:c=>l(c.currentTarget.value)}),fo(ft,{placeholder:"City",defaultValue:o.city,onChange:c=>i(c.currentTarget.value)}),fo(ft,{placeholder:"State",defaultValue:o.state,onChange:c=>u(c.currentTarget.value)}),fo(ft,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:c=>d(c.currentTarget.value)})]})}import{TextInput as ic}from"@mantine/core";import{createReference as uc}from"@medplum/core";import{useRef as cc,useState as dc}from"react";import{jsx as mc}from"react/jsx-runtime";function If(e){let o=qt(),[t,r]=dc(e.defaultValue||{}),a=cc();a.current=t;function n(f){let s=f?{text:f,authorReference:o&&uc(o),time:new Date().toISOString()}:{};r(s),e.onChange&&e.onChange(s)}return mc(ic,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:f=>n(f.currentTarget.value)})}import{AppShell as $d,useMantineTheme as _d}from"@mantine/core";import{showNotification as Kd}from"@mantine/notifications";import{Suspense as Zd,useEffect as Yd,useState as jd}from"react";import{Alert as yc}from"@mantine/core";import{normalizeErrorString as Cc}from"@medplum/core";import{forwardRef as pc,createElement as hf}from"react";import lo from"prop-types";var gf={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,Gt=Object.getOwnPropertySymbols,Cf=Object.prototype.hasOwnProperty,Sf=Object.prototype.propertyIsEnumerable,vf=(e,o,t)=>o in e?xc(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,yf=(e,o)=>{for(var t in o||(o={}))Cf.call(o,t)&&vf(e,t,o[t]);if(Gt)for(var t of Gt(o))Sf.call(o,t)&&vf(e,t,o[t]);return e},hc=(e,o)=>Ic(e,gc(o)),vc=(e,o)=>{var t={};for(var r in e)Cf.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Gt)for(var r of Gt(e))o.indexOf(r)<0&&Sf.call(e,r)&&(t[r]=e[r]);return t},p=(e,o,t)=>{let r=pc((a,n)=>{var f=a,{color:s="currentColor",size:l=24,stroke:i=2,children:u}=f,d=vc(f,["color","size","stroke","children"]);return hf("svg",yf(hc(yf({ref:n},gf),{width:l,height:l,stroke:s,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),d),[...t.map(([c,m])=>hf(c,m)),...u||[]])});return r.propTypes={color:lo.string,size:lo.oneOfType([lo.string,lo.number]),stroke:lo.oneOfType([lo.string,lo.number])},r.displayName=`${o}`,r};var oa=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 so=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 ta=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 ra=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 aa=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 na=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 fa=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 la=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 sa=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 ia=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 Ne=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 lt=p("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var ua=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 ca=p("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var _e=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 Ro=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 st=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 da=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 ma=p("copy","IconCopy",[["path",{d:"M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z",key:"svg-0"}],["path",{d:"M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1",key:"svg-1"}]]);var pa=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 xa=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 Ia=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 bo=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 Po=p("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Ut=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 ga=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 ha=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 va=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 ya=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 Qt=p("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var zt=p("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var Ca=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 Sa=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 Ra=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 ba=p("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var Pa=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 Da=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 Do=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 it=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 ut=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 Ta=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 ka=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 Ba=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 ct=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 Aa=p("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Sc}from"react";import{jsx as Rf}from"react/jsx-runtime";var To=class extends Sc{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?Rf(yc,{icon:Rf(so,{size:16}),title:"Something went wrong",color:"red",children:Cc(this.state.error)}):this.props.children}};import{Center as Rc,Loader as bc}from"@mantine/core";import{jsx as bf}from"react/jsx-runtime";function Ma(){return bf(Rc,{style:{width:"100%",height:"100vh"},children:bf(bc,{})})}import{Avatar as ad,createStyles as nd,Group as Jt,Header as fd,Menu as He,Stack as ld,Text as dt,UnstyledButton as Ef}from"@mantine/core";import{formatHumanName as sd,getReferenceString as Lf}from"@medplum/core";import{useState as id}from"react";import{formatHumanName as Pc}from"@medplum/core";import{Fragment as Dc,jsx as Tc}from"react/jsx-runtime";function Wt(e){let o=e.value;return o?Tc(Dc,{children:Pc(o,e.options)}):null}import{Avatar as Df}from"@mantine/core";import{getDisplayString as Lc,getImageSrc as Nc}from"@medplum/core";import{Anchor as kc}from"@mantine/core";import{isReference as Bc,isResource as Ac}from"@medplum/core";function O(e){e.preventDefault(),e.stopPropagation()}function Xt(e){if(Pf(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&Pf(o[0]))return!0}return!1}function Pf(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as Ec}from"react/jsx-runtime";function ee(e){let o=$e(),{to:t,suffix:r,label:a,onClick:n,children:f,...s}=e,l=Mc(t);return r&&(l+="/"+r),Ec(kc,{href:l,"aria-label":a,onClick:i=>{O(i),n?n(i):t&&o(l)},...s,children:f})}function Mc(e){if(e){if(typeof e=="string")return Fc(e);if(Ac(e))return wc(e);if(Bc(e))return Oc(e)}return"#"}function Fc(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function wc(e){return`/${e.resourceType}/${e.id}`}function Oc(e){return`/${e.reference}`}import{jsx as Fa}from"react/jsx-runtime";function le(e){let o=U(e.value),t=o?Lc(o):e.alt??"",r=(o&&Nc(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?Fa(ee,{to:o,children:Fa(Df,{src:r,alt:t,radius:a,...n})}):Fa(Df,{src:r,alt:t,radius:a,...n})}import{createStyles as zc,Group as Wc,Text as kf}from"@mantine/core";import{formatHumanName as Xc,getDisplayString as wf,getReferenceString as Jc,isUUID as $c}from"@medplum/core";import{forwardRef as _c,useCallback as Bf}from"react";import{Loader as Hc,MultiSelect as Vc}from"@mantine/core";import{showNotification as qc}from"@mantine/notifications";import{normalizeErrorString as Gc}from"@medplum/core";import{useCallback as ko,useEffect as Uc,useRef as Bo,useState as Ao}from"react";import{jsx as Tf}from"react/jsx-runtime";function Mo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:f,creatable:s,...l}=e,i=Qc(o),u=Bo(null),[d,c]=Ao(),[m,g]=Ao(),[I,v]=Ao(),[P,b]=Ao(),[T,q]=Ao(i.map(r)),[y,M]=Ao([]),_=Bo();_.current=d;let Y=Bo();Y.current=m;let Ee=Bo();Ee.current=I;let no=Bo();no.current=P;let re=Bo();re.current=y;let h=ko(()=>{g(void 0);let j=u.current?.value.trim()||"";if(j===_.current)return;c(j);let Z=new AbortController;v(Z),a(j,Z.signal).then(he=>{Z.signal.aborted||(M(he.map(r)),v(void 0),no.current&&(he.length>0&&n(he.slice(0,1)),b(!1)))}).catch(he=>{Z.signal.aborted||he.message.includes("aborted")||qc({color:"red",message:Gc(he)})})},[a,n,r]),L=ko(()=>{Ee.current&&(Ee.current.abort(),v(void 0)),Y.current!==void 0&&window.clearTimeout(Y.current);let j=window.setTimeout(()=>h(),100);g(j)},[h]),ke=ko(j=>{let Z=[],he=[];for(let of of j){let Ht=re.current?.find(Ou=>Ou.value===of),rt=Ht?.resource;!rt&&s!==!1&&f&&(rt=f(of),Ht=r(rt)),rt&&Z.push(rt),Ht&&he.push(Ht)}n(Z),q(he)},[s,n,f,r]),C=ko(j=>{j.key==="Enter"&&(!Y.current&&!Ee.current?(O(j),re.current&&re.current.length>0&&(M(re.current.slice(0,1)),ke([re.current[0].value]))):b(!0))},[ke]),H=ko(j=>{let Z=r(f(j));return M([...re.current,Z]),Z},[f,M,r]),Le=ko((j,Z)=>!Z,[]);return Uc(()=>()=>{Ee.current&&Ee.current.abort()},[]),Tf(Vc,{...l,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:C,onSearchChange:L,data:[...T,...y],onFocus:h,onChange:ke,onCreate:H,rightSectionWidth:40,rightSection:I?Tf(Hc,{size:16}):null,filter:Le,creatable:!0,withinPortal:!0})}function Qc(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Fo,jsxs as Ff}from"react/jsx-runtime";var Kc=zc(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function Zc(e){return e.id}function Yc(e){return{value:e.id,label:wf(e),resource:e}}function Of(e){let{classes:o}=Kc(),t=$e(),r=S(),a=Bf(async(f,s)=>{let l=ed(f),i={signal:s},u=await r.graphql(l,void 0,void 0,i);return od(u,f)},[r]),n=Bf(f=>{f.length>0&&t(`/${Jc(f[0])}`)},[t]);return Fo(Mo,{size:"sm",radius:"md",className:o.searchInput,icon:Fo(Da,{size:16}),placeholder:"Search",itemComponent:jc,toKey:Zc,toOption:Yc,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var jc=_c(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Fo("div",{ref:t,...o,children:Ff(Wc,{noWrap:!0,children:[Fo(le,{value:e}),Ff("div",{children:[Fo(kf,{children:wf(e)}),Fo(kf,{size:"xs",color:"dimmed",children:r})]})]})})});function ed(e){let o=JSON.stringify(e);return $c(e)?`{
1
+ var nc=Object.create;var il=Object.defineProperty;var lc=Object.getOwnPropertyDescriptor;var fc=Object.getOwnPropertyNames;var sc=Object.getPrototypeOf,ic=Object.prototype.hasOwnProperty;var ft=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var uc=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of fc(o))!ic.call(e,a)&&a!==t&&il(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)):{},uc(o||!e||!e.__esModule?il(t,"default",{value:e,enumerable:!0}):t,e));var tn=ft(hr=>{"use strict";Object.defineProperty(hr,"__esModule",{value:!0});hr.Pointer=void 0;function Sg(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Cg(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var bg=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(Sg);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(Cg).join("/")},e.prototype.evaluate=function(o){for(var t=null,r="",a=o,n=1,l=this.tokens.length;n<l;n++)t=a,r=this.tokens[n],!(r=="__proto__"||r=="constructor"||r=="prototype")&&(a=(t||{})[r]);return{parent:t,key:r,value:a}},e.prototype.get=function(o){return this.evaluate(o).value},e.prototype.set=function(o,t){var r=this.evaluate(o);r.parent&&(r.parent[r.key]=t)},e.prototype.push=function(o){this.tokens.push(o)},e.prototype.add=function(o){var t=this.tokens.concat(String(o));return new e(t)},e}();hr.Pointer=bg});var an=ft(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.clone=Ue.objectType=Ue.hasOwnProperty=void 0;Ue.hasOwnProperty=Object.prototype.hasOwnProperty;function Rg(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ue.objectType=Rg;function Pg(e){return e!=null&&typeof e=="object"}function rn(e){if(!Pg(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=rn(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var l in e)Ue.hasOwnProperty.call(e,l)&&(n[l]=rn(e[l]));return n}Ue.clone=rn});var fn=ft(me=>{"use strict";Object.defineProperty(me,"__esModule",{value:!0});me.diffAny=me.diffObjects=me.diffArrays=me.intersection=me.subtract=me.isDestructive=void 0;var Tt=an();function Tg(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}me.isDestructive=Tg;function ln(e,o){var t={};for(var r in e)Tt.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Tt.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}me.subtract=ln;function Cs(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Tt.hasOwnProperty.call(a,n)&&a[n]!==void 0&&(t[n]=(t[n]||0)+1)}for(var n in t)t[n]<o&&delete t[n];return Object.keys(t)}me.intersection=Cs;function Dg(e){return e.op==="add"}function kg(e){return e.op==="remove"}function nn(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function bs(e,o,t,r){r===void 0&&(r=yr);var a={"0,0":{operations:[],cost:0}};function n(u,c){var d="".concat(u,",").concat(c),m=a[d];if(m===void 0){if(u>0&&c>0&&!r(e[u-1],o[c-1],t.add(String(u-1))).length)m=n(u-1,c-1);else{var x=[];if(u>0){var p=n(u-1,c),h={op:"remove",index:u-1};x.push(nn(p,h))}if(c>0){var S=n(u,c-1),y={op:"add",index:u-1,value:o[c-1]};x.push(nn(S,y))}if(u>0&&c>0){var b=n(u-1,c-1),E={op:"replace",index:u-1,original:e[u-1],value:o[c-1]};x.push(nn(b,E))}var C=x.sort(function(M,K){return M.cost-K.cost})[0];m=C}a[d]=m}return m}var l=isNaN(e.length)||e.length<=0?0:e.length,f=isNaN(o.length)||o.length<=0?0:o.length,s=n(l,f).operations,i=s.reduce(function(u,c){var d=u[0],m=u[1];if(Dg(c)){var x=c.index+1+m,p=x<l+m?String(x):"-",h={op:c.op,path:t.add(p).toString(),value:c.value};return[d.concat(h),m+1]}else if(kg(c)){var h={op:c.op,path:t.add(String(c.index+m)).toString()};return[d.concat(h),m-1]}else{var S=t.add(String(c.index+m)),y=r(c.original,c.value,S);return[d.concat.apply(d,y),m]}},[[],0])[0];return i}me.diffArrays=bs;function Rs(e,o,t,r){r===void 0&&(r=yr);var a=[];return ln(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),ln(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),Cs([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}me.diffObjects=Rs;function yr(e,o,t,r){if(r===void 0&&(r=yr),e===o)return[];var a=(0,Tt.objectType)(e),n=(0,Tt.objectType)(o);return a=="array"&&n=="array"?bs(e,o,t,r):a=="object"&&n=="object"?Rs(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}me.diffAny=yr});var Os=ft(_=>{"use strict";var sn=_&&_.__extends||function(){var e=function(o,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,a){r.__proto__=a}||function(r,a){for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(r[n]=a[n])},e(o,t)};return function(o,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(o,t);function r(){this.constructor=o}o.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}();Object.defineProperty(_,"__esModule",{value:!0});_.apply=_.InvalidOperationError=_.test=_.copy=_.move=_.replace=_.remove=_.add=_.TestError=_.MissingError=void 0;var Qe=tn(),un=an(),Bg=fn(),Ee=function(e){sn(o,e);function o(t){var r=e.call(this,"Value required at path: ".concat(t))||this;return r.path=t,r.name="MissingError",r}return o}(Error);_.MissingError=Ee;var Ps=function(e){sn(o,e);function o(t,r){var a=e.call(this,"Test failed: ".concat(t," != ").concat(r))||this;return a.actual=t,a.expected=r,a.name="TestError",a}return o}(Error);_.TestError=Ps;function cn(e,o,t){if(Array.isArray(e))if(o=="-")e.push(t);else{var r=parseInt(o,10);e.splice(r,0,t)}else e[o]=t}function Ts(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function Ds(e,o){var t=Qe.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new Ee(o.path):(cn(t.parent,t.key,(0,un.clone)(o.value)),null)}_.add=Ds;function ks(e,o){var t=Qe.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new Ee(o.path):(Ts(t.parent,t.key),null)}_.remove=ks;function Bs(e,o){var t=Qe.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new Ee(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new Ee(o.path)}else if(t.value===void 0)return new Ee(o.path);return t.parent[t.key]=(0,un.clone)(o.value),null}_.replace=Bs;function As(e,o){var t=Qe.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Ee(o.from);var r=Qe.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Ee(o.path):(Ts(t.parent,t.key),cn(r.parent,r.key,t.value),null)}_.move=As;function Ms(e,o){var t=Qe.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Ee(o.from);var r=Qe.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Ee(o.path):(cn(r.parent,r.key,(0,un.clone)(t.value)),null)}_.copy=Ms;function Fs(e,o){var t=Qe.Pointer.fromJSON(o.path).evaluate(e);return(0,Bg.diffAny)(t.value,o.value,new Qe.Pointer).length?new Ps(t.value,o.value):null}_.test=Fs;var ws=function(e){sn(o,e);function o(t){var r=e.call(this,"Invalid operation: ".concat(t.op))||this;return r.operation=t,r.name="InvalidOperationError",r}return o}(Error);_.InvalidOperationError=ws;function Ag(e,o){switch(o.op){case"add":return Ds(e,o);case"remove":return ks(e,o);case"replace":return Bs(e,o);case"move":return As(e,o);case"copy":return Ms(e,o);case"test":return Fs(e,o)}return new ws(o)}_.apply=Ag});var Ls=ft(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.createTests=Le.createPatch=Le.applyPatch=Le.Pointer=void 0;var dn=tn();Object.defineProperty(Le,"Pointer",{enumerable:!0,get:function(){return dn.Pointer}});var Mg=Os(),mn=fn();function Fg(e,o){return o.map(function(t){return(0,Mg.apply)(e,t)})}Le.applyPatch=Fg;function wg(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,mn.diffAny)(t,r,a,o)}return o}function Og(e,o,t){var r=new dn.Pointer;return(t?wg(t):mn.diffAny)(e,o,r)}Le.createPatch=Og;function Es(e,o){var t=dn.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function Eg(e,o){var t=new Array;return o.filter(mn.isDestructive).forEach(function(r){var a=Es(e,r.path);if(a&&t.push(a),"from"in r){var n=Es(e,r.from);n&&t.push(n)}}),t}Le.createTests=Eg});import{useEffect as ul,useMemo as dc,useState as mc}from"react";import{createContext as pc,useContext as xc}from"react";import{jsx as Ic}from"react/jsx-runtime";import{deepEquals as hc,isReference as pl,isResource as yc,normalizeOperationOutcome as vc}from"@medplum/core";import{useCallback as Sc,useEffect as cl,useState as Cc}from"react";import{allOk as bc,normalizeOperationOutcome as Rc}from"@medplum/core";import{useEffect as Pc,useState as qt}from"react";var ml=pc(void 0);function st(){return xc(ml)}function P(){return st().medplum}function _e(){return st().navigate}function Gt(){return st().profile}function Mb(e){let o=e.medplum,t=e.navigate??gc,[r,a]=mc({profile:o.getProfile(),loading:!o.isInitialized});ul(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),ul(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=dc(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return Ic(ml.Provider,{value:n,children:e.children})}function gc(e){window.location.assign(e)}function Q(e,o){let t=P(),[r,a]=Cc(dl(t,e)),n=Sc(l=>{hc(l,r)||a(l)},[r,a]);return cl(()=>{n(dl(t,e))},[t,e,n]),cl(()=>{let l=!0;return pl(e)&&t.readReference(e).then(f=>{l&&n(f)}).catch(f=>{l&&(n(void 0),o&&o(vc(f)))}),()=>l=!1},[t,r,e,n,o]),r}function dl(e,o){if(o){if(yc(o))return o;if(pl(o))return e.getCachedReference(o)}}function Lb(e,o){return na("search",e,o)}function xl(e,o){return na("searchOne",e,o)}function Il(e,o){return na("searchResources",e,o)}function na(e,o,t){let r=P(),[a,n]=qt(),[l,f]=qt(!1),[s,i]=qt(),[u,c]=qt();return Pc(()=>{let d=r.fhirSearchUrl(o,t).toString();d!==a&&(n(d),r[e](o,t).then(m=>{f(!1),i(m),c(bc)}).catch(m=>{f(!1),i(void 0),c(Rc(m))}))},[r,e,o,t,a,i]),[s,l,u]}import{formatAddress as Tc}from"@medplum/core";import{Fragment as Dc,jsx as kc}from"react/jsx-runtime";function gl(e){let o=e.value;return o?kc(Dc,{children:Tc(o)}):null}import{Group as Bc,NativeSelect as hl,TextInput as it}from"@mantine/core";import{useRef as Ac,useState as Mc}from"react";import{jsx as io,jsxs as Fc}from"react/jsx-runtime";function yl(e,o){return e.line&&e.line.length>o?e.line[o]:""}function vl(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function Sl(e){let[o,t]=Mc(e.defaultValue||{}),r=Ac();r.current=o;function a(d){t(d),e.onChange&&e.onChange(d)}function n(d){a({...r.current,use:d})}function l(d){a({...r.current,type:d})}function f(d){a(vl(r.current||{},0,d))}function s(d){a(vl(r.current||{},1,d))}function i(d){a({...r.current,city:d})}function u(d){a({...r.current,state:d})}function c(d){a({...r.current,postalCode:d})}return Fc(Bc,{spacing:"xs",grow:!0,noWrap:!0,children:[io(hl,{"data-testid":"address-use",defaultValue:o.use,onChange:d=>n(d.currentTarget.value),data:["","home","work","temp","old","billing"]}),io(hl,{"data-testid":"address-type",defaultValue:o.type,onChange:d=>l(d.currentTarget.value),data:["","postal","physical","both"]}),io(it,{placeholder:"Line 1",defaultValue:yl(o,0),onChange:d=>f(d.currentTarget.value)}),io(it,{placeholder:"Line 2",defaultValue:yl(o,1),onChange:d=>s(d.currentTarget.value)}),io(it,{placeholder:"City",defaultValue:o.city,onChange:d=>i(d.currentTarget.value)}),io(it,{placeholder:"State",defaultValue:o.state,onChange:d=>u(d.currentTarget.value)}),io(it,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:d=>c(d.currentTarget.value)})]})}import{TextInput as wc}from"@mantine/core";import{createReference as Oc}from"@medplum/core";import{useRef as Ec,useState as Lc}from"react";import{jsx as Nc}from"react/jsx-runtime";function Cl(e){let o=Gt(),[t,r]=Lc(e.defaultValue||{}),a=Ec();a.current=t;function n(l){let f=l?{text:l,authorReference:o&&Oc(o),time:new Date().toISOString()}:{};r(f),e.onChange&&e.onChange(f)}return Nc(wc,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as hm,useMantineTheme as ym}from"@mantine/core";import{showNotification as vm}from"@mantine/notifications";import{Suspense as Sm,useEffect as Cm,useState as bm}from"react";import{Alert as zc}from"@mantine/core";import{normalizeErrorString as Wc}from"@medplum/core";import{forwardRef as Vc,createElement as Rl}from"react";import uo from"prop-types";var bl={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 Hc=Object.defineProperty,qc=Object.defineProperties,Gc=Object.getOwnPropertyDescriptors,Ut=Object.getOwnPropertySymbols,Dl=Object.prototype.hasOwnProperty,kl=Object.prototype.propertyIsEnumerable,Pl=(e,o,t)=>o in e?Hc(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Tl=(e,o)=>{for(var t in o||(o={}))Dl.call(o,t)&&Pl(e,t,o[t]);if(Ut)for(var t of Ut(o))kl.call(o,t)&&Pl(e,t,o[t]);return e},Uc=(e,o)=>qc(e,Gc(o)),Qc=(e,o)=>{var t={};for(var r in e)Dl.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ut)for(var r of Ut(e))o.indexOf(r)<0&&kl.call(e,r)&&(t[r]=e[r]);return t},I=(e,o,t)=>{let r=Vc((a,n)=>{var l=a,{color:f="currentColor",size:s=24,stroke:i=2,children:u}=l,c=Qc(l,["color","size","stroke","children"]);return Rl("svg",Tl(Uc(Tl({ref:n},bl),{width:s,height:s,stroke:f,strokeWidth:i,className:`tabler-icon tabler-icon-${e}`}),c),[...t.map(([d,m])=>Rl(d,m)),...u||[]])});return r.propTypes={color:uo.string,size:uo.oneOfType([uo.string,uo.number]),stroke:uo.oneOfType([uo.string,uo.number])},r.displayName=`${o}`,r};var la=I("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 co=I("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 fa=I("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 sa=I("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 ia=I("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 ua=I("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 ca=I("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 da=I("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 ma=I("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 pa=I("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 qe=I("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 ut=I("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var xa=I("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 Ia=I("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Fe=I("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 Ke=I("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 ct=I("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 ga=I("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 ha=I("copy","IconCopy",[["path",{d:"M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z",key:"svg-0"}],["path",{d:"M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1",key:"svg-1"}]]);var ya=I("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 va=I("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 Sa=I("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 To=I("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 Do=I("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Qt=I("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 Ca=I("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 ba=I("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 Ra=I("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 Pa=I("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 zt=I("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Wt=I("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var Ta=I("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 Da=I("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 ka=I("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 Ba=I("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var Aa=I("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 Ma=I("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 ko=I("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 dt=I("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 mt=I("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 Fa=I("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 wa=I("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 Oa=I("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 pt=I("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 Ea=I("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Xc}from"react";import{jsx as Bl}from"react/jsx-runtime";var Bo=class extends Xc{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?Bl(zc,{icon:Bl(co,{size:16}),title:"Something went wrong",color:"red",children:Wc(this.state.error)}):this.props.children}};import{Center as Jc,Loader as $c}from"@mantine/core";import{jsx as Al}from"react/jsx-runtime";function La(){return Al(Jc,{style:{width:"100%",height:"100vh"},children:Al($c,{})})}import{Avatar as kd,createStyles as Bd,Group as $t,Header as Ad,Menu as Ge,Stack as Md,Text as xt,UnstyledButton as Gl}from"@mantine/core";import{formatHumanName as Fd,getReferenceString as Ul}from"@medplum/core";import{useState as wd}from"react";import{formatHumanName as _c}from"@medplum/core";import{Fragment as Kc,jsx as Zc}from"react/jsx-runtime";function Xt(e){let o=e.value;return o?Zc(Kc,{children:_c(o,e.options)}):null}import{Avatar as Fl}from"@mantine/core";import{getDisplayString as ld,getImageSrc as fd}from"@medplum/core";import{Anchor as Yc}from"@mantine/core";import{isReference as jc,isResource as ed}from"@medplum/core";function w(e){e.preventDefault(),e.stopPropagation()}function Jt(e){if(Ml(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&Ml(o[0]))return!0}return!1}function Ml(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as nd}from"react/jsx-runtime";function oe(e){let o=_e(),{to:t,suffix:r,label:a,onClick:n,children:l,...f}=e,s=od(t);return r&&(s+="/"+r),nd(Yc,{href:s,"aria-label":a,onClick:i=>{w(i),n?n(i):t&&o(s)},...f,children:l})}function od(e){if(e){if(typeof e=="string")return td(e);if(ed(e))return rd(e);if(jc(e))return ad(e)}return"#"}function td(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function rd(e){return`/${e.resourceType}/${e.id}`}function ad(e){return`/${e.reference}`}import{jsx as Na}from"react/jsx-runtime";function fe(e){let o=Q(e.value),t=o?ld(o):e.alt??"",r=(o&&fd(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?Na(oe,{to:o,children:Na(Fl,{src:r,alt:t,radius:a,...n})}):Na(Fl,{src:r,alt:t,radius:a,...n})}import{createStyles as pd,Group as xd,Text as Ol}from"@mantine/core";import{formatHumanName as Id,getDisplayString as Hl,getReferenceString as gd,isUUID as hd}from"@medplum/core";import{forwardRef as yd,useCallback as El}from"react";import{Loader as sd,MultiSelect as id}from"@mantine/core";import{showNotification as ud}from"@mantine/notifications";import{normalizeErrorString as cd}from"@medplum/core";import{useCallback as Ao,useEffect as dd,useRef as Mo,useState as Fo}from"react";import{jsx as wl}from"react/jsx-runtime";function wo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:f,...s}=e,i=md(o),u=Mo(null),[c,d]=Fo(),[m,x]=Fo(),[p,h]=Fo(),[S,y]=Fo(),[b,E]=Fo(i.map(r)),[C,M]=Fo([]),K=Mo();K.current=c;let j=Mo();j.current=m;let Ve=Mo();Ve.current=p;let so=Mo();so.current=S;let ae=Mo();ae.current=C;let v=Ao(()=>{x(void 0);let ee=u.current?.value.trim()||"";if(ee===K.current)return;d(ee);let Y=new AbortController;h(Y),a(ee,Y.signal).then(he=>{Y.signal.aborted||(M(he.map(r)),h(void 0),so.current&&(he.length>0&&n(he.slice(0,1)),y(!1)))}).catch(he=>{Y.signal.aborted||he.message.includes("aborted")||ud({color:"red",message:cd(he)})})},[a,n,r]),N=Ao(()=>{Ve.current&&(Ve.current.abort(),h(void 0)),j.current!==void 0&&window.clearTimeout(j.current);let ee=window.setTimeout(()=>v(),100);x(ee)},[v]),Me=Ao(ee=>{let Y=[],he=[];for(let sl of ee){let Ht=ae.current?.find(ac=>ac.value===sl),lt=Ht?.resource;!lt&&f!==!1&&l&&(lt=l(sl),Ht=r(lt)),lt&&Y.push(lt),Ht&&he.push(Ht)}n(Y),E(he)},[f,n,l,r]),R=Ao(ee=>{ee.key==="Enter"&&(!j.current&&!Ve.current?(w(ee),ae.current&&ae.current.length>0&&(M(ae.current.slice(0,1)),Me([ae.current[0].value]))):y(!0))},[Me]),H=Ao(ee=>{let Y=r(l(ee));return M([...ae.current,Y]),Y},[l,M,r]),He=Ao((ee,Y)=>!Y,[]);return dd(()=>()=>{Ve.current&&Ve.current.abort()},[]),wl(id,{...s,ref:u,defaultValue:i.map(t),searchable:!0,onKeyDown:R,onSearchChange:N,data:[...b,...C],onFocus:v,onChange:Me,onCreate:H,rightSectionWidth:40,rightSection:p?wl(sd,{size:16}):null,filter:He,creatable:!0,withinPortal:!0})}function md(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Oo,jsxs as Vl}from"react/jsx-runtime";var vd=pd(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function Sd(e){return e.id}function Cd(e){return{value:e.id,label:Hl(e),resource:e}}function ql(e){let{classes:o}=vd(),t=_e(),r=P(),a=El(async(l,f)=>{let s=Rd(l),i={signal:f},u=await r.graphql(s,void 0,void 0,i);return Pd(u,l)},[r]),n=El(l=>{l.length>0&&t(`/${gd(l[0])}`)},[t]);return Oo(wo,{size:"sm",radius:"md",className:o.searchInput,icon:Oo(Ma,{size:16}),placeholder:"Search",itemComponent:bd,toKey:Sd,toOption:Cd,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var bd=yd(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Oo("div",{ref:t,...o,children:Vl(xd,{noWrap:!0,children:[Oo(fe,{value:e}),Vl("div",{children:[Oo(Ol,{children:Hl(e)}),Oo(Ol,{size:"xs",color:"dimmed",children:r})]})]})})});function Rd(e){let o=JSON.stringify(e);return hd(e)?`{
2
2
  Patients1: PatientList(_id: ${o}, _count: 1) {
3
3
  resourceType
4
4
  id
@@ -61,8 +61,8 @@ var Eu=Object.create;var tf=Object.defineProperty;var Lu=Object.getOwnPropertyDe
61
61
  display
62
62
  }
63
63
  }
64
- }`.replace(/\s+/g," ")}function od(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),rd(td(t),o).slice(0,5)}function td(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 rd(e,o){return e.sort((t,r)=>Af(r,o)-Af(t,o))}function Af(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,Mf(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,Mf(Xc(r),o));return t}function Mf(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as J,jsxs as Ke}from"react/jsx-runtime";var ud=nd(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 Nf(e){let o=nt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:f,cx:s}=ud(),[l,i]=id(!1);return J(fd,{height:60,p:8,style:{zIndex:101},children:Ke(Jt,{position:"apart",children:[Ke(Jt,{spacing:"xs",children:[J(Ef,{className:f.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&J(Of,{pathname:e.pathname,searchParams:e.searchParams})]}),Ke(He,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:l,onClose:()=>i(!1),children:[J(He.Target,{children:J(Ef,{className:s(f.user,{[f.userActive]:l}),onClick:()=>i(u=>!u),children:Ke(Jt,{spacing:7,children:[J(le,{value:r,radius:"xl",size:24}),J(dt,{size:"sm",className:f.userName,children:sd(r?.name?.[0])}),J(ca,{size:12,stroke:1.5})]})})}),Ke(He.Dropdown,{children:[Ke(ld,{align:"center",p:"xl",children:[J(le,{size:"xl",radius:100,value:o.profile}),J(Wt,{value:o.profile?.name?.[0]}),J(dt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&J(He.Divider,{}),n.map(u=>u.profile.reference!==Lf(o.profile)&&J(He.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:Ke(Jt,{children:[J(ad,{radius:"xl"}),Ke("div",{style:{flex:1},children:[J(dt,{size:"sm",weight:500,children:u.profile.display}),J(dt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),J(He.Divider,{}),J(He.Item,{icon:J(ka,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),J(He.Item,{icon:J(Do,{size:14,stroke:1.5}),onClick:()=>a(`/${Lf(r)}`),children:"Account settings"}),J(He.Item,{icon:J(ya,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),J(dt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as Ld,createStyles as Nd,Navbar as Oa,ScrollArea as Hd,Space as Vd,Text as qd}from"@mantine/core";import{Fragment as Gd,useState as Ud}from"react";import{Button as pd,Group as xd,Modal as Id,NativeSelect as gd,Stack as hd,TextInput as vd}from"@mantine/core";import{showNotification as Vf}from"@mantine/notifications";import{deepClone as yd,normalizeErrorString as Cd}from"@medplum/core";function Hf(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?cd(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&dd(o,t);return o}function cd(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function dd(e,o){e[o.name]=o.value}import{jsx as md}from"react/jsx-runtime";function W(e){return md("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=Hf(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as io,jsxs as Rd}from"react/jsx-runtime";function qf(e){let o=S(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:f}=a,s=`${e.pathname}?${e.searchParams.toString()}`,l=yd(t);l.menu?.find(({title:u})=>u===n)?.link?.push({name:f,target:s}),o.updateResource(l).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),Vf({color:"green",message:"Success"}),e.onOk()}).catch(u=>{Vf({color:"red",message:Cd(u)})})}return io(Id,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:io(W,{onSubmit:r,children:Rd(hd,{children:[io(Sd,{config:t}),io(vd,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),io(xd,{position:"right",children:io(pd,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Sd(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return io(gd,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as wd,useState as Od}from"react";import{useState as Bd}from"react";import{useCallback as bd}from"react";import{jsx as kd}from"react/jsx-runtime";function wa(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Pd(e){return typeof e.display=="string"?e.display:wa(e)}function Dd(e){return{value:wa(e),label:Pd(e),resource:e}}function Td(e){return{code:e,display:e}}function wo(e){let o=S(),{binding:t,creatable:r,clearable:a,...n}=e,f=bd(async(s,l)=>{if(!t)return[];let u=(await o.searchValueSet(t,s,{signal:l})).expansion?.contains,d=[];for(let c of u)c.code&&!d.some(m=>m.code===c.code)&&d.push(c);return d},[o,t]);return kd(Mo,{...n,creatable:r??!0,clearable:a??!0,toKey:wa,toOption:Dd,loadOptions:f,onCreate:Td,getCreateLabel:r===!1?void 0:s=>`+ Create ${s}`})}import{jsx as Fd}from"react/jsx-runtime";function $t(e){let[o,t]=Bd(e.defaultValue);function r(a){let n=a[0],f=Md(n);t(f),e.onChange&&e.onChange(f)}return Fd(wo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Ad(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Ad(e){return e?{code:e}:void 0}function Md(e){return e?.code}import{jsx as Ed}from"react/jsx-runtime";function Oo(e){let[o,t]=Od(e.defaultValue),r=e.onChange,a=wd(n=>{t(n),r&&r(n)},[r]);return Ed($t,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as Jd,jsx as Pe,jsxs as mt}from"react/jsx-runtime";var Gf=Nd(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 Uf(e){let{classes:o}=Gf(),t=$e(),r=Wd(e.pathname,e.searchParams,e.menus),[a,n]=Ud(!1);function f(l,i){l.stopPropagation(),l.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function s(l){l&&t(`/${l}`)}return mt(Jd,{children:[Pe(Oa,{width:{sm:250},p:"xs",children:mt(Hd,{children:[!e.resourceTypeSearchDisabled&&Pe(Oa.Section,{mb:"sm",children:Pe(Oo,{name:"resourceType",placeholder:"Resource Type",onChange:l=>s(l)},window.location.pathname)}),mt(Oa.Section,{grow:!0,children:[e.menus?.map(l=>mt(Gd,{children:[Pe(qd,{className:o.menuTitle,children:l.title}),l.links?.map(i=>mt(Qd,{to:i.href,active:i.href===r?.href,onClick:u=>f(u,i.href),children:[Pe(zd,{to:i.href,icon:i.icon}),Pe("span",{children:i.label})]},i.href))]},`menu-${l.title}`)),e.displayAddBookmark&&Pe(Ld,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Pe(ba,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Pe(qf,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function Qd(e){let{classes:o,cx:t}=Gf();return Pe(ee,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function zd(e){return e.icon?e.icon:Pe(Vd,{w:30})}function Wd(e,o,t){if(!e||!o||!t)return;let r,a=0;for(let n of t)if(n.links)for(let f of n.links){let s=Xd(e,o,f.href);s>a&&(a=s,r=f)}return r}function Xd(e,o,t){let r=new URL(t,"https://example.com");if(e!==r.pathname)return 0;let a=["_count","_offset"];for(let[f,s]of r.searchParams.entries())if(!a.includes(f)&&o.get(f)!==s)return 0;let n=1;for(let[f,s]of o.entries())a.includes(f)||r.searchParams.get(f)===s&&n++;return n}import{jsx as uo}from"react/jsx-runtime";function UT(e){let o=_d(),[t,r]=jd(localStorage.navbarOpen==="true"),a=S(),n=qt();Yd(()=>{function i(){Kd({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",i),()=>a.removeEventListener("offline",i)},[a]);function f(i){localStorage.navbarOpen=i.toString(),r(i)}function s(){f(!1)}function l(){f(!t)}return a.isLoading()?uo(Ma,{}):uo($d,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&uo(Nf,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:l}),navbar:n&&t?uo(Uf,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:s,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:uo(To,{children:uo(Zd,{fallback:uo(Ma,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as em}from"@mantine/core";import{jsx as co,jsxs as tm}from"react/jsx-runtime";function Be(e){let{contentType:o,url:t,title:r}=e.value??{};return t?tm("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&co("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&co("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:co("source",{type:o,src:t})}),o==="application/pdf"&&co("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:co("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),co("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:co(em,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:om(r),children:r||"Download"})})]}):null}function om(e){return e?.includes(".")?e:void 0}import{jsx as Ea}from"react/jsx-runtime";function Qf(e){return Ea("div",{children:e.values?.map((o,t)=>Ea("div",{children:Ea(Be,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as zf}from"@mantine/core";import{useRef as sm,useState as im}from"react";import{useRef as rm}from"react";import{normalizeOperationOutcome as am}from"@medplum/core";import{Fragment as fm,jsx as nm,jsxs as lm}from"react/jsx-runtime";function Eo(e){let o=S(),t=rm(null);function r(f){O(f),t.current?.click()}function a(f){O(f);let s=f.target.files;s&&Array.from(s).forEach(n)}function n(f){if(!f||!f.name)return;e.onUploadStart&&e.onUploadStart();let l=f.name,i=f.type||"application/octet-stream";o.createBinary(f,l,i,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:l})}).catch(u=>{e.onUploadError&&e.onUploadError(am(u))})}return lm(fm,{children:[nm("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:f=>a(f)}),e.children({onClick:r})]})}import{jsx as ve,jsxs as pt}from"react/jsx-runtime";function Wf(e){let[o,t]=im(e.defaultValue??[]),r=sm();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return pt("table",{style:{width:"100%"},children:[pt("colgroup",{children:[ve("col",{width:"97%"}),ve("col",{width:"3%"})]}),pt("tbody",{children:[o.map((n,f)=>pt("tr",{children:[ve("td",{children:ve(Be,{value:n,maxWidth:200})}),ve("td",{children:ve(zf,{title:"Remove",size:"sm",onClick:s=>{O(s);let l=o.slice();l.splice(f,1),a(l)},children:ve(_e,{})})})]},`${f}-${o.length}`)),pt("tr",{children:[ve("td",{}),ve("td",{children:ve(Eo,{onUpload:n=>{a([...r.current,n])},children:n=>ve(zf,{...n,title:"Add",size:"sm",color:"green",children:ve(st,{size:16})})})})]})]})]})}import{Button as Xf}from"@mantine/core";import{useState as um}from"react";import{Fragment as cm,jsx as _t,jsxs as dm}from"react/jsx-runtime";function Kt(e){let[o,t]=um(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?dm(cm,{children:[_t(Be,{value:o,maxWidth:200}),_t(Xf,{onClick:a=>{O(a),r(void 0)},children:"Remove"})]}):_t(Eo,{onUpload:r,children:a=>_t(Xf,{...a,children:"Upload..."})})}import{getPropertyDisplayName as Ym,tryGetDataType as jm}from"@medplum/core";var Zt=["meta","implicitRules","contained","extension","modifierExtension"],Yt=["language","text"];import{createStyles as mm}from"@mantine/core";import{Fragment as xm,jsx as La,jsxs as Im}from"react/jsx-runtime";var pm=mm(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 Jf(e){let{children:o,compact:t}=e,{classes:r,cx:a}=pm();return La("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function $f(e){return Im(xm,{children:[La("dt",{children:e.term}),La("dd",{children:e.children})]})}import{ActionIcon as Um,Box as Qm,CopyButton as zm,Tooltip as Wm}from"@mantine/core";import{PropertyType as E,formatDateTime as Xm,formatPeriod as Jm,formatTiming as $m,isEmpty as _m}from"@medplum/core";import{formatCodeableConcept as gm}from"@medplum/core";import{Fragment as hm,jsx as vm}from"react/jsx-runtime";function Lo(e){return vm(hm,{children:gm(e.value)})}import{formatCoding as ym}from"@medplum/core";import{Fragment as Cm,jsx as Sm}from"react/jsx-runtime";function _f(e){return Sm(Cm,{children:ym(e.value)})}import{Fragment as Rm,jsx as bm}from"react/jsx-runtime";function jt(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("]")),bm(Rm,{children:t.join("").trim()})}import{Fragment as Dm,jsx as Pm,jsxs as Tm}from"react/jsx-runtime";function Kf(e){let o=e.value;return o?Tm(Dm,{children:[o.name,o.name&&": ",o.telecom?.map(t=>Pm(jt,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as km}from"react/jsx-runtime";function Zf(e){return km("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as Bm}from"@medplum/core";import{Fragment as Am,jsx as Mm}from"react/jsx-runtime";function Yf(e){return Mm(Am,{children:Bm(e.value)})}import{formatQuantity as Fm}from"@medplum/core";import{Fragment as wm,jsx as Om}from"react/jsx-runtime";function Ze(e){return Om(wm,{children:Fm(e.value)})}import{formatRange as Em}from"@medplum/core";import{Fragment as Lm,jsx as Nm}from"react/jsx-runtime";function er(e){return Nm(Lm,{children:Em(e.value)})}import{Fragment as Hm,jsx as jf,jsxs as Vm}from"react/jsx-runtime";function el(e){let o=e.value;return o?Vm(Hm,{children:[jf(Ze,{value:o.numerator}),"\xA0/\xA0",jf(Ze,{value:o.denominator})]}):null}import{stringify as qm}from"@medplum/core";import{Fragment as Gm,jsx as ol}from"react/jsx-runtime";function mo(e){if(!e.value)return null;let o=e.value.display||e.value.reference||qm(e.value);return e.link!==!1&&e.value.reference?ol(ee,{to:e.value,children:o}):ol(Gm,{children:o})}import{Fragment as tl,jsx as or}from"react/jsx-runtime";function rl(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?or(tl,{children:t.map((a,n)=>or("div",{children:or(ae,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):or(tl,{})}import{Fragment as No,jsx as V,jsxs as Km}from"react/jsx-runtime";function ae(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return Km(Qm,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!_m(r)&&V(zm,{value:r,timeout:2e3,children:({copied:n,copy:f})=>V(Wm,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:V(Um,{color:n?"teal":"gray",onClick:f,children:n?V(lt,{size:"1rem"}):V(ma,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===E.Attachment?V(Qf,{values:r,maxWidth:e.maxWidth}):V(rl,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case E.boolean:return V(No,{children:r===void 0?"":(!!r).toString()});case E.SystemString:case E.string:return V("div",{style:{whiteSpace:"pre-wrap"},children:r});case E.code:case E.date:case E.decimal:case E.id:case E.integer:case E.positiveInt:case E.unsignedInt:case E.uri:case E.url:return V(No,{children:r});case E.canonical:return V(mo,{value:{reference:r},link:e.link});case E.dateTime:case E.instant:return V(No,{children:Xm(r)});case E.markdown:return V("pre",{children:r});case E.Address:return V(cf,{value:r});case E.Annotation:return V(No,{children:r?.text});case E.Attachment:return V(Be,{value:r,maxWidth:e.maxWidth});case E.CodeableConcept:return V(Lo,{value:r});case E.Coding:return V(_f,{value:r});case E.ContactDetail:return V(Kf,{value:r});case E.ContactPoint:return V(jt,{value:r});case E.HumanName:return V(Wt,{value:r});case E.Identifier:return V(Zf,{value:r});case E.Money:return V(Yf,{value:r});case E.Period:return V(No,{children:Jm(r)});case E.Quantity:case E.Duration:return V(Ze,{value:r});case E.Range:return V(er,{value:r});case E.Ratio:return V(el,{value:r});case E.Reference:return V(mo,{value:r,link:e.link});case E.Timing:return V(No,{children:$m(r)});case E.Dosage:case E.UsageContext:return V(xt,{value:{type:t,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});default:if(!o)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);return V(xt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as Zm}from"@medplum/core";function Ae(e,o){let t=Zm(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}import{jsx as tr,jsxs as ep}from"react/jsx-runtime";function xt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=jm(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?tr("div",{children:t.name}):tr(Jf,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[f,s]=n;if(Zt.includes(f)||Yt.includes(f)&&s.path.split(".").length===2)return null;let[l,i]=Ae(o,f);return e.ignoreMissingValues&&(!l||Array.isArray(l)&&l.length===0)?null:tr($f,{term:Ym(f),children:tr(ae,{property:s,propertyType:i,value:l,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},f)})}):ep("div",{children:[r,"\xA0not implemented"]})}import{Stack as Hx}from"@mantine/core";import{getPropertyDisplayName as ql,tryGetDataType as Vx}from"@medplum/core";import{useState as qx}from"react";import{Group as op,Input as tp}from"@mantine/core";import{jsx as Na,jsxs as rp}from"react/jsx-runtime";function rr(e){return rp(op,{noWrap:!0,children:[Na("div",{children:e.children}),Na("div",{children:Na(tp.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as ap}from"@mantine/core";function ne(e,o){return e?.issue?.filter(t=>al(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
65
- `)}function ar(e,o){return e?.issue?.filter(t=>al(t.expression?.[0],o))}function al(e,o){if(e===o)return!0;if(!e||!o)return!1;let t=e.indexOf(".");if(t>=0&&e.substring(t+1)===o)return!0;let r=o.indexOf(".");return r>=0&&o.substring(r+1)===e}import{jsx as np}from"react/jsx-runtime";function Ie(e){return np(ap.Wrapper,{id:e.htmlFor,label:e.title,description:e.description,withAsterisk:e.withAsterisk,error:ne(e.outcome,e.htmlFor),children:e.children})}import{capitalize as fp}from"@medplum/core";function It(e,o,t,r,a){let n=r.type;if(n.length>1)for(let f of n){let s=o.replace("[x]",fp(f.code));s in e&&delete e[s]}return e[t]=a,e}import{Checkbox as Bx,Group as Ax,NativeSelect as Mx,Textarea as Fx,TextInput as za}from"@mantine/core";import{capitalize as wx,PropertyType as w}from"@medplum/core";import{useState as Ox}from"react";import{useState as lp}from"react";import{jsx as up}from"react/jsx-runtime";function nl(e){let[o,t]=lp(e.defaultValue);function r(a){let n=ip(a);t(n),e.onChange&&e.onChange(n)}return up(wo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&sp(o),maxSelectedValues:1,onChange:r})}function sp(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function ip(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as cp}from"react";import{jsx as pp}from"react/jsx-runtime";function nr(e){let[o,t]=cp(e.defaultValue);function r(a){let n=a[0],f=n&&mp(n);t(f),e.onChange&&e.onChange(f)}return pp(wo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&dp(o),maxSelectedValues:1,onChange:r})}function dp(e){return{system:e.system,code:e.code,display:e.display}}function mp(e){return{system:e.system,code:e.code,display:e.display}}import{Group as yp,TextInput as Cp}from"@mantine/core";import{useRef as Sp,useState as Rp}from"react";import{Group as xp,NativeSelect as fl,TextInput as Ip}from"@mantine/core";import{useRef as gp,useState as hp}from"react";import{jsx as Ha,jsxs as vp}from"react/jsx-runtime";function fr(e){let[o,t]=hp(e.defaultValue),r=gp();r.current=o;function a(l){l&&Object.keys(l).length===0&&(l=void 0),t(l),e.onChange&&e.onChange(l)}function n(l){let i={...r.current,system:l};l||delete i.system,a(i)}function f(l){let i={...r.current,use:l};l||delete i.use,a(i)}function s(l){let i={...r.current,value:l};l||delete i.value,a(i)}return vp(xp,{spacing:"xs",grow:!0,noWrap:!0,children:[Ha(fl,{"data-testid":"system",defaultValue:o?.system,onChange:l=>n(l.currentTarget.value),data:["","email","phone","fax","pager","sms","other"]}),Ha(fl,{"data-testid":"use",defaultValue:o?.use,onChange:l=>f(l.currentTarget.value),data:["","home","work","temp","old","mobile"]}),Ha(Ip,{placeholder:"Value",defaultValue:o?.value,onChange:l=>s(l.currentTarget.value)})]})}import{jsx as ll,jsxs as bp}from"react/jsx-runtime";function sl(e){let[o,t]=Rp(e.defaultValue),r=Sp();r.current=o;function a(s){t(s),e.onChange&&e.onChange(s)}function n(s){let l={...r.current,name:s};s||delete l.name,a(l)}function f(s){let l={...r.current,telecom:s&&[s]};s||delete l.telecom,a(l)}return bp(yp,{spacing:"xs",grow:!0,noWrap:!0,children:[ll(Cp,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:s=>n(s.currentTarget.value)}),ll(fr,{name:e.name+"-telecom",defaultValue:o?.telecom?.[0],onChange:f})]})}import{TextInput as Pp}from"@mantine/core";import{isValidDate as il}from"@medplum/core";function ul(e){if(!e)return"";let o=new Date(e);return il(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function cl(e){if(!e)return"";let o=new Date(e);return il(o)?o.toISOString():""}import{jsx as Tp}from"react/jsx-runtime";function De(e){return Tp(Pp,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:Dp(),defaultValue:ul(e.defaultValue),autoFocus:e.autoFocus,error:ne(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(cl(t))}}})}function Dp(){return"datetime-local"}import{JsonInput as kp}from"@mantine/core";import{stringify as Bp}from"@medplum/core";import{jsx as Ap}from"react/jsx-runtime";function dl(e){return Ap(kp,{id:e.name,name:e.name,"data-testid":"extension-input",defaultValue:Bp(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as Mp,NativeSelect as Fp,TextInput as lr}from"@mantine/core";import{useRef as wp,useState as Op}from"react";import{jsx as gt,jsxs as Ep}from"react/jsx-runtime";function ml(e){let[o,t]=Op(e.defaultValue),r=wp();r.current=o;function a(u){t(u),e.onChange&&e.onChange(u)}function n(u){a({...r.current,use:u||void 0})}function f(u){a({...r.current,prefix:u?u.split(" "):void 0})}function s(u){a({...r.current,given:u?u.split(" "):void 0})}function l(u){a({...r.current,family:u||void 0})}function i(u){a({...r.current,suffix:u?u.split(" "):void 0})}return Ep(Mp,{spacing:"xs",grow:!0,noWrap:!0,children:[gt(Fp,{defaultValue:o?.use,name:e.name+"-use","data-testid":"use",onChange:u=>n(u.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"]}),gt(lr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:o?.prefix?.join(" "),onChange:u=>f(u.currentTarget.value)}),gt(lr,{placeholder:"Given",name:e.name+"-given",defaultValue:o?.given?.join(" "),onChange:u=>s(u.currentTarget.value)}),gt(lr,{name:e.name+"-family",placeholder:"Family",defaultValue:o?.family,onChange:u=>l(u.currentTarget.value)}),gt(lr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:o?.suffix?.join(" "),onChange:u=>i(u.currentTarget.value)})]})}import{Group as Lp,TextInput as pl}from"@mantine/core";import{useState as Np}from"react";import{jsx as xl,jsxs as Hp}from"react/jsx-runtime";function Il(e){let[o,t]=Np(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Hp(Lp,{spacing:"xs",grow:!0,noWrap:!0,children:[xl(pl,{placeholder:"System",defaultValue:o?.system,onChange:a=>r({...o,system:a.currentTarget.value})}),xl(pl,{placeholder:"Value",defaultValue:o?.value,onChange:a=>r({...o,value:a.currentTarget.value})})]})}import{NativeSelect as Vp,TextInput as qp}from"@mantine/core";import{useCallback as Va,useState as Gp}from"react";import{jsx as qa}from"react/jsx-runtime";var Up=["USD","EUR","CAD","GBP","AUD"];function gl(e){let{onChange:o}=e,[t,r]=Gp(e.defaultValue),a=Va(l=>{r(l),o&&o(l)},[o]),n=Va(l=>{a({...t,currency:l.currentTarget.value})},[t,a]),f=Va(l=>{a({...t,value:l.currentTarget.valueAsNumber})},[t,a]),s=qa(Vp,{defaultValue:t?.currency,data:Up,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return qa(qp,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:qa(pa,{size:14}),rightSection:s,rightSectionWidth:92,onChange:f})}import{Group as Qp}from"@mantine/core";import{useState as zp}from"react";import{jsx as hl,jsxs as Wp}from"react/jsx-runtime";function vl(e){let[o,t]=zp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Wp(Qp,{spacing:"xs",grow:!0,noWrap:!0,children:[hl(De,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),hl(De,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as Xp,NativeSelect as Jp,TextInput as yl}from"@mantine/core";import{useState as $p}from"react";import{jsx as Ga,jsxs as Kp}from"react/jsx-runtime";function ye(e){let[o,t]=$p(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Kp(Xp,{spacing:"xs",grow:!0,noWrap:!0,children:[Ga(Jp,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),Ga(yl,{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:_p(a.currentTarget.value)})}}),Ga(yl,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function _p(e){if(e)return parseFloat(e)}import{Group as Zp}from"@mantine/core";import{useState as Yp}from"react";import{jsx as Cl,jsxs as jp}from"react/jsx-runtime";function ht(e){let[o,t]=Yp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return jp(Zp,{spacing:"xs",grow:!0,noWrap:!0,children:[Cl(ye,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),Cl(ye,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as ex}from"@mantine/core";import{useState as ox}from"react";import{jsx as Sl,jsxs as tx}from"react/jsx-runtime";function Rl(e){let[o,t]=ox(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return tx(ex,{spacing:"xs",grow:!0,noWrap:!0,children:[Sl(ye,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Sl(ye,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as dx,NativeSelect as mx}from"@mantine/core";import{createReference as px}from"@medplum/core";import{useState as kl}from"react";import{Group as rx,Text as bl}from"@mantine/core";import{getDisplayString as ax,getReferenceString as Tl}from"@medplum/core";import{forwardRef as nx,useCallback as Pl,useState as fx}from"react";import{jsx as vt,jsxs as Dl}from"react/jsx-runtime";var lx={Observation:"code",User:"email:contains"},sx=["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 ix(e){return{value:Tl(e),label:ax(e),resource:e}}function sr(e){let o=S(),{resourceType:t,searchCriteria:r}=e,[a,n]=fx(),f=U(e.defaultValue,n),s=e.onChange,l=Pl(async(u,d)=>{let c=cx(t),m=new URLSearchParams({[c]:u,_count:"10",...r});return await o.searchResources(t,m,{signal:d})},[o,t,r]),i=Pl(u=>{s&&s(u[0])},[s]);return e.defaultValue&&!a&&!f?null:vt(Mo,{name:e.name,required:e.required,itemComponent:ux,defaultValue:f,placeholder:e.placeholder,maxSelectedValues:1,toKey:Tl,toOption:ix,loadOptions:l,onChange:i,clearable:!0})}var ux=nx(({label:e,resource:o,...t},r)=>vt("div",{ref:r,...t,children:Dl(rx,{noWrap:!0,children:[vt(le,{value:o}),Dl("div",{children:[vt(bl,{children:e}),vt(bl,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function cx(e){return lx[e]??(sx.includes(e)?"name":"_id")}import{jsx as Ua,jsxs as gx}from"react/jsx-runtime";function Ho(e){let o=xx(e.targetTypes),t=Ix(e.defaultValue,o),[r,a]=kl(e.defaultValue),[n,f]=kl(t);function s(l){a(l),e.onChange&&e.onChange(l)}return gx(dx,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&Ua(mx,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:n,autoFocus:e.autoFocus,onChange:l=>f(l.currentTarget.value),data:o}),!o&&Ua(Oo,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:f,name:e.name+"-resourceType",placeholder:"Resource Type"}),Ua(sr,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:e.searchCriteria,onChange:l=>{s(l?px(l):void 0)}})]})}function xx(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function Ix(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}import{ActionIcon as Bl,Group as Al,Stack as hx}from"@mantine/core";import{useRef as vx,useState as yx}from"react";import{jsx as Ve,jsxs as Ml}from"react/jsx-runtime";function Fl(e){let[o,t]=yx(e.defaultValue&&Array.isArray(e.defaultValue)?e.defaultValue:[]),r=vx();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return Ml(hx,{style:{marginTop:"1rem",marginLeft:"1rem"},children:[o.map((n,f)=>Ml(Al,{noWrap:!0,children:[Ve("div",{style:{flexGrow:1},children:Ve(qe,{arrayElement:!0,property:e.property,name:e.name+"."+f,defaultValue:n,onChange:s=>{let l=[...r.current];l[f]=s,a(l)}})}),Ve("div",{children:Ve(Bl,{title:"Remove",size:"sm",onClick:s=>{O(s);let l=[...r.current];l.splice(f,1),a(l)},children:Ve(_e,{})})})]},`${f}-${o.length}`)),Ve(Al,{noWrap:!0,style:{justifyContent:"flex-end"},children:Ve("div",{children:Ve(Bl,{title:"Add",size:"sm",color:"green",onClick:n=>{O(n);let f=[...r.current];f.push(void 0),a(f)},children:Ve(Ro,{})})})})]})}import{Button as El,Chip as wl,Group as ir,Modal as Cx,NativeSelect as Sx,Stack as Rx,Switch as bx,TextInput as Px}from"@mantine/core";import{formatTiming as Dx}from"@medplum/core";import{useRef as Ll,useState as Qa}from"react";import{Fragment as Hl,jsx as fe,jsxs as yt}from"react/jsx-runtime";var Tx=["sun","mon","tue","wed","thu","fri","sat"];function Nl(e){let[o,t]=Qa(e.defaultValue),[r,a]=Qa(!1),n=Ll();return n.current=o,yt(Hl,{children:[yt(ir,{spacing:"xs",grow:!0,noWrap:!0,children:[fe("span",{children:Dx(n.current)||"No repeat"}),fe(El,{onClick:()=>a(!0),children:"Edit"})]}),fe(kx,{visible:r,defaultValue:n.current,onOk:f=>{e.onChange&&e.onChange(f),t(f),a(!1)},onCancel:()=>a(!1)})]})}var Ol={repeat:{period:1,periodUnit:"d"}};function kx(e){let[o,t]=Qa(e.defaultValue||Ol),r=Ll();r.current=o;function a(i){t({...r.current,event:[i]})}function n(i){t({...r.current,repeat:i})}function f(i){n({...r.current?.repeat,period:i})}function s(i){n({...r.current?.repeat,periodUnit:i})}function l(i){n({...r.current?.repeat,dayOfWeek:i})}return fe(Cx,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:yt(Rx,{children:[fe(Ie,{title:"Starts on",htmlFor:"timing-dialog-start",children:fe(De,{name:"timing-dialog-start",onChange:i=>a(i)})}),fe(bx,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?Ol.repeat:void 0)}),o.repeat&&yt(Hl,{children:[fe(Ie,{title:"Repeat every",htmlFor:"timing-dialog-period",children:yt(ir,{spacing:"xs",grow:!0,noWrap:!0,children:[fe(Px,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:i=>f(parseInt(i.currentTarget.value,10)||1)}),fe(Sx,{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"&&fe(Ie,{title:"Repeat on",children:fe(wl.Group,{multiple:!0,onChange:l,children:fe(ir,{position:"apart",mt:"md",spacing:"xs",children:Tx.map(i=>fe(wl,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),fe(ir,{position:"right",children:fe(El,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as N,jsxs as Nx}from"react/jsx-runtime";function qe(e){let o=e.property,t=e.defaultPropertyType&&e.defaultPropertyType!=="undefined"?e.defaultPropertyType:o.type[0].code,r=e.name,a=e.defaultValue;if(o.max>1&&!e.arrayElement)return t===w.Attachment?N(Wf,{name:r,defaultValue:a,onChange:e.onChange}):N(Fl,{property:o,name:r,defaultValue:a,onChange:e.onChange});let n=o.type;return n.length>1?N(Ex,{elementDefinitionTypes:n,...e}):N(Vl,{elementDefinitionType:n[0],...e})}function Ex(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=Ox(t);return Nx(Ax,{spacing:"xs",grow:!0,noWrap:!0,children:[N(Mx,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(f=>f.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),N(Vl,{...e,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",wx(r.code)))}})]})}function Vl(e){let o=e.property,t=e.elementDefinitionType.code,r=e.name,a=e.defaultValue,n=o.min!==void 0&&o.min>0;switch(t){case w.SystemString:case w.canonical:case w.string:case w.time:case w.uri:case w.url:return N(za,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)},error:ne(e.outcome,r)});case w.date:return N(za,{type:"date",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)},error:ne(e.outcome,r)});case w.dateTime:case w.instant:return N(De,{name:r,defaultValue:a,onChange:e.onChange,outcome:e.outcome});case w.decimal:case w.integer:case w.positiveInt:case w.unsignedInt:return N(za,{type:"number",step:t===w.decimal?"any":"1",id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.valueAsNumber)}});case w.code:return N($t,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.boolean:return N(Bx,{id:r,name:r,"data-testid":r,defaultChecked:!!a,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.checked)}});case w.markdown:return N(Fx,{id:r,name:r,"data-testid":r,defaultValue:a,required:n,onChange:f=>{e.onChange&&e.onChange(f.currentTarget.value)}});case w.Address:return N(xf,{name:r,defaultValue:a,onChange:e.onChange});case w.Annotation:return N(If,{name:r,defaultValue:a,onChange:e.onChange});case w.Attachment:return N(Kt,{name:r,defaultValue:a,onChange:e.onChange});case w.CodeableConcept:return N(nl,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.Coding:return N(nr,{binding:o.binding?.valueSet,name:r,defaultValue:a,onChange:e.onChange});case w.ContactDetail:return N(sl,{name:r,defaultValue:a,onChange:e.onChange});case w.ContactPoint:return N(fr,{name:r,defaultValue:a,onChange:e.onChange});case w.Extension:return N(dl,{name:r,defaultValue:a,onChange:e.onChange});case w.HumanName:return N(ml,{name:r,defaultValue:a,onChange:e.onChange});case w.Identifier:return N(Il,{name:r,defaultValue:a,onChange:e.onChange});case w.Money:return N(gl,{name:r,defaultValue:a,onChange:e.onChange});case w.Period:return N(vl,{name:r,defaultValue:a,onChange:e.onChange});case w.Duration:case w.Quantity:return N(ye,{name:r,defaultValue:a,onChange:e.onChange});case w.Range:return N(ht,{name:r,defaultValue:a,onChange:e.onChange});case w.Ratio:return N(Rl,{name:r,defaultValue:a,onChange:e.onChange});case w.Reference:return N(Ho,{name:r,defaultValue:a,targetTypes:Lx(o),onChange:e.onChange});case w.Timing:return N(Nl,{name:r,defaultValue:a,onChange:e.onChange});case w.Dosage:case w.UsageContext:return N(Ct,{typeName:t,defaultValue:a,onChange:e.onChange,outcome:e.outcome});default:return N(Ct,{typeName:o.type[0].code,defaultValue:a,onChange:e.onChange,outcome:e.outcome})}}function Lx(e){return e?.type?.[0]?.targetProfile?.map(o=>o.split("/").pop())}import{jsx as St,jsxs as Gx}from"react/jsx-runtime";function Ct(e){let[o,t]=qx(e.defaultValue??{});function r(s){t(s),e.onChange&&e.onChange(s)}let a=e.typeName,n=Vx(a);if(!n)return Gx("div",{children:[a,"\xA0not implemented"]});let f={type:a,value:o};return St(Hx,{children:Object.entries(n.elements).map(([s,l])=>{if(s==="id"||Zt.includes(s)||Yt.includes(s)&&l.path.split(".").length===2||!l.type)return null;let[i,u]=Ae(f,s),d=l.min!==void 0&&l.min>0;return l.type.length===1&&l.type[0].code==="boolean"?St(rr,{title:ql(s),description:l.description,htmlFor:s,children:St(qe,{property:l,name:s,defaultValue:i,defaultPropertyType:u,outcome:e.outcome,onChange:(c,m)=>{r(It(o,s,m??s,l,c))}})},s):St(Ie,{title:ql(s),description:l.description,withAsterisk:d,htmlFor:s,outcome:e.outcome,children:St(qe,{property:l,name:s,defaultValue:i,defaultPropertyType:u,onChange:(c,m)=>{r(It(o,s,m??s,l,c))}})},s)})})}import{Button as Wa,createStyles as Ux,Group as Ul}from"@mantine/core";import{useMemo as Qx,useState as zx}from"react";function Gl(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function ur(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as se,jsxs as Rt}from"react/jsx-runtime";var Wx=Ux(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 Ql(e){let{classes:o}=Wx(),{onChangeMonth:t,onClick:r}=e,[a,n]=zx(ur);function f(l){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+l),t(u),u})}let s=Qx(()=>Xx(a,e.slots),[a,e.slots]);return Rt("div",{children:[Rt(Ul,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[se("p",{style:{flex:1},children:Gl(a)}),Rt(Ul,{position:"right",spacing:"xs",children:[se(Wa,{variant:"outline","aria-label":"Previous month",onClick:()=>f(-1),children:"<"}),se(Wa,{variant:"outline","aria-label":"Next month",onClick:()=>f(1),children:">"})]})]}),Rt("table",{className:o.table,children:[se("thead",{children:Rt("tr",{children:[se("th",{children:"SUN"}),se("th",{children:"MON"}),se("th",{children:"TUE"}),se("th",{children:"WED"}),se("th",{children:"THU"}),se("th",{children:"FRI"}),se("th",{children:"SAT"})]})}),se("tbody",{children:s.map((l,i)=>se("tr",{children:l.map((u,d)=>se("td",{children:u&&se(Wa,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+d))},"week-"+i))})]})]})}function Xx(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:Jx(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 Jx(e,o){for(let t of o){let r=new Date(t.start);if(r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate())return!0}return!1}import{Container as $x,createStyles as _x}from"@mantine/core";import{jsx as Zx}from"react/jsx-runtime";var Kx=_x(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Ye(e){let{children:o,...t}=e,{classes:r}=Kx();return Zx($x,{className:r.root,...t,children:o})}import{ActionIcon as bs,Center as sg,createStyles as ig,Group as ug,Loader as cg,Menu as ze,ScrollArea as dg,TextInput as mg}from"@mantine/core";import{showNotification as pg,updateNotification as Ir}from"@mantine/notifications";import{getReferenceString as Dt,normalizeErrorString as Ps}from"@medplum/core";import{useCallback as gr,useEffect as xg,useRef as Ds,useState as Ts}from"react";import{createStyles as dI,Group as dr,List as Jl,Stack as $l,Text as Ce,Title as _l}from"@mantine/core";import{capitalize as mI,formatCodeableConcept as pI,formatDateTime as Ja,formatObservationValue as xI,isReference as II}from"@medplum/core";import{useEffect as gI,useState as hI}from"react";import{Blockquote as Yx,createStyles as jx,Stack as eI}from"@mantine/core";import{jsx as zl}from"react/jsx-runtime";var oI=jx(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function Xa({value:e}){let{classes:o}=oI();return e?zl(eI,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&zl(Yx,{classNames:{cite:o.noteCite,body:o.noteBody,root:o.noteRoot},cite:t.authorReference?.display||t.authorString,icon:null,children:t.text},`note-${t.text}`))}):null}import{Group as lI}from"@mantine/core";import{Text as tI}from"@mantine/core";import{getDisplayString as rI,isOk as aI,normalizeErrorString as nI}from"@medplum/core";import{useState as fI}from"react";import{jsx as Wl}from"react/jsx-runtime";function Me(e){let{value:o,link:t,...r}=e,[a,n]=fI(),f=U(o,n),s;if(a&&!aI(a))s=`[${nI(a)}]`;else if(f)s=rI(f);else return null;return t?Wl(ee,{to:o,...r,children:s}):Wl(tI,{component:"span",...r,children:s})}import{jsx as Xl,jsxs as sI}from"react/jsx-runtime";function je(e){return sI(lI,{spacing:"xs",children:[Xl(le,{size:24,radius:12,value:e.value,link:e.link}),Xl(Me,{value:e.value,link:e.link})]})}import{Badge as iI}from"@mantine/core";import{jsx as cI}from"react/jsx-runtime";var uI={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 cr(e){return cI(iI,{color:uI[e.status],children:e.status})}import{Fragment as bt,jsx as R,jsxs as ie}from"react/jsx-runtime";var Kl=dI(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}}));$a.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function $a(e){let o=S(),t=U(e.value),[r,a]=hI();if(gI(()=>{t?.specimen&&Promise.allSettled(t.specimen.map(f=>o.readReference(f))).then(f=>f.filter(s=>s.status==="fulfilled").map(s=>s.value)).then(a).catch(console.error)},[o,t]),!t)return null;let n=r?.flatMap(f=>f.note||[])||[];if(t.presentedForm&&t.presentedForm.length>0){let f=t.presentedForm[0];f.contentType?.startsWith("text/plain")&&f.data&&n.push({text:window.atob(f.data)})}return ie($l,{children:[R(_l,{children:"Diagnostic Report"}),R(vI,{value:t}),r&&!e.hideSpecimenInfo&&yI(r),t.result&&R(CI,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&R(Xa,{value:n})]})}function vI({value:e}){return ie(dr,{mt:"md",spacing:30,children:[e.subject&&ie("div",{children:[R(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),R(Ce,{children:R(je,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>ie("div",{children:[R(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),R(Ce,{children:R(je,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>ie("div",{children:[R(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),R(Ce,{children:R(je,{value:o,link:!0})})]},o.reference)),e.issued&&ie("div",{children:[R(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),R(Ce,{children:Ja(e.issued)})]}),e.status&&ie("div",{children:[R(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),R(Ce,{children:mI(e.status)})]})]})}function yI(e){return ie($l,{spacing:"xs",children:[R(_l,{order:2,size:"h6",children:"Specimens"}),R(Jl,{type:"ordered",children:e?.map(o=>R(Jl.Item,{ml:"sm",children:ie(dr,{spacing:20,children:[ie(dr,{spacing:5,children:[R(Ce,{fw:500,children:"Collected:"})," ",Ja(o.collection?.collectedDateTime)]}),ie(dr,{spacing:5,children:[R(Ce,{fw:500,children:"Received:"})," ",Ja(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function CI(e){let{classes:o}=Kl();return ie("table",{className:o.table,children:[R("thead",{children:ie("tr",{children:[R("th",{children:"Test"}),R("th",{children:"Value"}),R("th",{children:"Reference Range"}),R("th",{children:"Interpretation"}),R("th",{children:"Category"}),R("th",{children:"Performer"}),R("th",{children:"Status"})]})}),R("tbody",{children:R(Zl,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function Zl(e){return R(bt,{children:e.value?.map(o=>R(SI,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${II(o)?o.reference:o.id}`))})}function SI(e){let{classes:o,cx:t}=Kl(),r=U(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=PI(r);return ie(bt,{children:[ie("tr",{className:t({[o.criticalRow]:n}),children:[R("td",{rowSpan:a?2:1,children:R(ee,{to:r,children:R(Lo,{value:r.code})})}),R("td",{children:R(RI,{value:r})}),R("td",{children:R(bI,{value:r.referenceRange})}),R("td",{children:r.interpretation&&r.interpretation.length>0&&R(Lo,{value:r.interpretation[0]})}),R("td",{children:r.category&&r.category.length>0&&R(bt,{children:r.category.map(f=>R("div",{children:R(Lo,{value:f})},`category-${pI(f)}`))})}),R("td",{children:r.performer?.map(f=>R(mo,{value:f},f.reference))}),R("td",{children:r.status&&R(cr,{status:r.status})})]}),r.hasMember&&R(Zl,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&R("tr",{children:R("td",{colSpan:6,children:R(Xa,{value:r.note})})})]})}function RI(e){let o=e.value;return R(bt,{children:xI(o)})}function bI(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?R(bt,{children:o.text}):R(er,{value:o}):null}function PI(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as DI,Paper as TI,useComponentDefaultProps as kI}from"@mantine/core";import{jsx as MI}from"react/jsx-runtime";var BI=DI((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%"}}})),AI={shadow:"xs",radius:"md",withBorder:!0};function Vo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...f}=kI("Panel",AI,e),{classes:s,cx:l}=BI({width:r,fill:a},{name:"Panel",unstyled:n});return MI(TI,{className:l(s.paper,o),...f,children:t})}import{createStyles as JI}from"@mantine/core";import{capitalize as $I,evalFhirPathTyped as ms,getSearchParameterDetails as _I,toTypedValue as ps}from"@medplum/core";var Is=Gu(ds(),1);import{useEffect as KI,useState as ZI}from"react";import{jsx as Qe,jsxs as xr}from"react/jsx-runtime";var YI=JI(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 gs(e){let{classes:o}=YI(),t=S(),[r,a]=ZI(!1);if(KI(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,Is.createPatch)(e.original,e.revised),f=[ps(e.original)],s=[ps(e.revised)];return xr("table",{className:o.root,children:[Qe("thead",{children:xr("tr",{children:[Qe("th",{}),Qe("th",{children:"Before"}),Qe("th",{children:"After"})]})}),Qe("tbody",{children:n.map(l=>{if(l.path.startsWith("/meta"))return null;let i=l.path,u=jI(i),c=_I(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],m=!!c?.isArray,g=l.op==="add"?void 0:ms(u,f)?.[0],I=l.op==="remove"?void 0:ms(u,s)?.[0];return xr("tr",{children:[xr("td",{children:[$I(l.op)," ",u]}),Qe("td",{className:o.removed,children:g&&Qe(ae,{property:c,propertyType:g.type,value:xs(g.value,m),ignoreMissingValues:!0})}),Qe("td",{className:o.added,children:I&&Qe(ae,{property:c,propertyType:I.type,value:xs(I.value,m),ignoreMissingValues:!0})})]},`op-${l.op}-${l.path}`)})})]})}function jI(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 xs(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as eg,useState as og}from"react";import{jsx as tg}from"react/jsx-runtime";function fn(e){let o=S(),t=U(e.value),[r,a]=og(!1);return eg(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:tg(xt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as rg,Group as ag,Menu as hs,Text as ln}from"@mantine/core";import{formatDateTime as ng,getReferenceString as fg}from"@medplum/core";import{Fragment as lg,jsx as Se,jsxs as qo}from"react/jsx-runtime";function vs(e){return Se(Ye,{children:e.children})}function eo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,f=t??o.meta?.author,s=e.dateTime??o.meta?.lastUpdated;return qo(Vo,{"data-testid":"timeline-item",fill:!0,...n,children:[qo(ag,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Se(le,{value:f,link:!0,size:"md"}),qo("div",{style:{flex:1},children:[Se(ln,{size:"sm",children:Se(Me,{color:"dark",weight:500,value:f,link:!0})}),qo(ln,{size:"xs",children:[Se(ee,{color:"dimmed",to:e.resource,children:ng(s)}),Se(ln,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Se(ee,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&qo(hs,{position:"bottom-end",shadow:"md",width:200,children:[Se(hs.Target,{children:Se(rg,{radius:"xl","aria-label":`Actions for ${fg(e.resource)}`,children:Se(xa,{})})}),a]})]}),qo(To,{children:[r&&Se("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Se(lg,{children:e.children})]})]})}function Ss(e,o){e.sort((t,r)=>{let a=ys(t,o),n=ys(r,o);return a>n?1:a<n?-1:Cs(t,o)-Cs(r,o)})}function ys(e,o){if(!Rs(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Cs(e,o){if(!Rs(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 Rs(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as bg,jsx as D,jsxs as Tt}from"react/jsx-runtime";var Ig=ig(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function oo(e){let o=S(),t=$e(),r=o.getProfile(),a=Ds(null),n=U(e.value),[f,s]=Ts(),[l,i]=Ts([]),u=e.loadTimelineResources,d=Ds(l);d.current=l;let c=gr(h=>{Ss(h,n),h.reverse(),i(h)},[n]),m=gr(h=>{let L=[];for(let ke of h){if(ke.status!=="fulfilled")continue;let C=ke.value;if(C.type==="history"&&s(C),C.entry)for(let H of C.entry)L.push(H.resource)}c(L)},[c]),g=gr(h=>c([...d.current,h]),[c]),I=gr(()=>{let h,L;"resourceType"in e.value?(h=e.value.resourceType,L=e.value.id):[h,L]=e.value.reference?.split("/"),u(o,h,L).then(m).catch(console.log)},[o,e.value,u,m]);xg(()=>I(),[I]);function v(h){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,h)).then(L=>g(L)).catch(console.log)}function P(h){!n||!e.createMedia||o.createResource(e.createMedia(n,r,h)).then(L=>g(L)).then(()=>Ir({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:D(lt,{size:16}),autoClose:2e3})).catch(L=>Ir({id:"upload-notification",color:"red",title:"Upload error",message:Ps(L),icon:D(Ut,{size:16}),autoClose:2e3}))}function b(h,L){return o.updateResource({...h,priority:L})}function T(h){b(h,"stat").then(I).catch(console.log)}function q(h){b(h,"routine").then(I).catch(console.log)}function y(h){t(`/${h.resourceType}/${h.id}`)}function M(h){t(`/${h.resourceType}/${h.id}/edit`)}function _(h){t(`/${h.resourceType}/${h.id}/delete`)}function Y(h){t(`/${h.resourceType}/${h.id}/_history/${h.meta?.versionId}`)}function Ee(){pg({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function no(h){Ir({id:"upload-notification",loading:!0,title:"Uploading...",message:Rg(h),autoClose:!1,withCloseButton:!1})}function re(h){Ir({id:"upload-notification",color:"red",title:"Upload error",message:Ps(h),icon:D(Ut,{size:16}),autoClose:2e3})}return n?Tt(vs,{children:[e.createCommunication&&D(Vo,{children:D(W,{testid:"timeline-form",onSubmit:h=>{v(h.text);let L=a.current;L&&(L.value="",L.focus())},children:Tt(ug,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[D(le,{value:r}),D(mg,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),D(bs,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:D(Ca,{size:16})}),D(Eo,{onUpload:P,onUploadStart:Ee,onUploadProgress:no,onUploadError:re,children:h=>D(bs,{...h,radius:"xl",color:"blue",variant:"filled",children:D(st,{size:16})})})]})})}),l.map(h=>{if(!h)return null;let L=`${h.resourceType}/${h.id}/${h.meta?.versionId}`;if(h.resourceType===n.resourceType&&h.id===n.id)return D(gg,{history:f,resource:h,onDetails:Y},L);switch(h.resourceType){case"AuditEvent":return D(Cg,{resource:h,onDetails:y},L);case"Communication":return D(vg,{resource:h,onPin:h.priority!=="stat"?T:void 0,onUnpin:h.priority==="stat"?q:void 0,onDetails:y,onEdit:M,onDelete:_},L);case"DiagnosticReport":return D(Sg,{resource:h,onDetails:y,onEdit:M,onDelete:_},L);case"Media":return D(yg,{resource:h,onDetails:y,onEdit:M,onDelete:_},L);default:return D(eo,{resource:h,padding:!0,children:D(fn,{value:h,ignoreMissingValues:!0})},L)}})]}):D(sg,{style:{width:"100%",height:"100%"},children:D(cg,{})})}function Go(e){return Tt(ze.Dropdown,{children:[D(ze.Label,{children:"Resource"}),e.onPin&&D(ze.Item,{icon:D(Sa,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Dt(e.resource)}`,children:"Pin"}),e.onUnpin&&D(ze.Item,{icon:D(Ra,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Dt(e.resource)}`,children:"Unpin"}),e.onDetails&&D(ze.Item,{icon:D(va,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Dt(e.resource)}`,children:"Details"}),e.onEdit&&D(ze.Item,{icon:D(Ia,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Dt(e.resource)}`,children:"Edit"}),e.onDelete&&Tt(bg,{children:[D(ze.Divider,{}),D(ze.Label,{children:"Danger zone"}),D(ze.Item,{color:"red",icon:D(ct,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Dt(e.resource)}`,children:"Delete"})]})]})}function gg(e){let o=hg(e.history,e.resource);return o?D(eo,{resource:e.resource,padding:!0,popupMenuItems:D(Go,{...e}),children:D(gs,{original:o,revised:e.resource})}):Tt(eo,{resource:e.resource,padding:!0,popupMenuItems:D(Go,{...e}),children:[D("h3",{children:"Created"}),D(fn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function hg(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 vg(e){let{classes:o}=Ig(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return D(eo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:D(Go,{...e}),children:D("p",{children:e.resource.payload?.[0]?.contentString})})}function yg(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return D(eo,{resource:e.resource,padding:!!t,popupMenuItems:D(Go,{...e}),children:D(Be,{value:e.resource.content})})}function Cg(e){return D(eo,{resource:e.resource,padding:!0,popupMenuItems:D(Go,{...e}),children:D(dg,{children:D("pre",{children:e.resource.outcomeDesc})})})}function Sg(e){return D(eo,{resource:e.resource,padding:!0,popupMenuItems:D(Go,{...e}),children:D($a,{value:e.resource})})}function Rg(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${sn(e.loaded)} / ${sn(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${sn(e.loaded)}`}function sn(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as Pg}from"react/jsx-runtime";function uO(e){return Pg(oo,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as ks}from"react/jsx-runtime";function hr(e){let{children:o,...t}=e;return ks(Ye,{children:ks(Vo,{...t,children:o})})}import{createReference as vr}from"@medplum/core";import{jsx as Dg}from"react/jsx-runtime";function SO(e){return Dg(oo,{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:vr(o),subject:o.subject,sender:vr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:vr(o),subject:o.subject,operator:vr(t),issued:new Date().toISOString(),content:r})})}import{Button as Wh,Loader as Xh,Table as Jh}from"@mantine/core";import{normalizeOperationOutcome as $h}from"@medplum/core";import{memo as _h,useEffect as ii,useRef as ui,useState as Tr}from"react";import{evalFhirPath as Tg}from"@medplum/core";import{jsx as kg}from"react/jsx-runtime";function Bs(e){let o;try{o=Tg(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 kg(ae,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as kh,Button as Xo,Center as Pr,createStyles as Bh,Group as Dr,Loader as Ah,Menu as fi,Pagination as Mh,Table as Fh,Text as yn,UnstyledButton as wh}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as bn,formatSearchQuery as Oh}from"@medplum/core";import{memo as Eh,useCallback as li,useEffect as si,useRef as Lh,useState as Cn}from"react";import{Box as Bg,Button as Ag,Modal as Mg,Text as Fg}from"@mantine/core";import{jsx as yr,jsxs as Ms}from"react/jsx-runtime";function Fs(e){return Ms(Mg,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Ms(Bg,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&yr(As,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&yr(As,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),yr(Fg,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function As(e){return yr(Ag,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as Qg,Group as zg,Modal as Wg,MultiSelect as Xg,Stack as Jg}from"@mantine/core";import{getDataType as $g,getSearchParameters as _g,stringify as Kg}from"@medplum/core";import{useEffect as Zg,useMemo as Yg,useRef as jg,useState as Js}from"react";import{capitalize as wg,DEFAULT_SEARCH_COUNT as Og,evalFhirPathTyped as Eg,formatDateTime as Lg,Operator as A}from"@medplum/core";import{Fragment as Ug,jsx as un}from"react/jsx-runtime";var Ng={string:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],fulltext:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],token:[A.EQUALS,A.NOT],reference:[A.EQUALS,A.NOT],numeric:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],quantity:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],date:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY],datetime:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY]},Hg={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 kt(e,o){return{...e,filters:o,offset:0,name:void 0}}function HO(e){return kt(e,[])}function Cr(e,o){return kt(e,(e.filters??[]).filter(t=>t.code!==o))}function Uo(e,o,t,r,a){a&&(e=Cr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),kt(e,n)}function VO(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 Os(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function Es(e,o){return cn(e,o,-1)}function Ls(e,o){return cn(e,o,0)}function Ns(e,o){return cn(e,o,1)}function cn(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),mn(e,o,r,a)}function Hs(e,o){return dn(e,o,-1)}function Vs(e,o){return dn(e,o,0)}function qs(e,o){return dn(e,o,1)}function dn(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),mn(e,o,r,a)}function Gs(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),mn(e,o,t,new Date)}function mn(e,o,t,r){return e=Cr(e,o),e=ws(e,o,A.GREATER_THAN_OR_EQUALS,t),e=ws(e,o,A.LESS_THAN_OR_EQUALS,r),e}function ws(e,o,t,r){return Uo(e,o,t,r.toISOString())}function pn(e,o,t=!0){return Uo(e,o,A.MISSING,t.toString())}function Vg(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function Us(e,o){let t=e.count??Og,r=(o-1)*t;return Vg(e,r)}function xn(e,o,t){return o===Qs(e)&&t!==void 0&&t===zs(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function qO(e,o){let t=!1;return Qs(e)===o&&(t=!zs(e)),xn(e,o,t)}function Qs(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function zs(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function Ws(e){return Ng[e.type]}function Bt(e){return Hg[e]??""}function Re(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(wg).join(" "))}function Xs(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?Lg(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?qg(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?Gg(e,o.searchParams[0]):null}function qg(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=Ae({type:e.resourceType,value:e},t);return r?un(ae,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function Gg(e,o){let t=Eg(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:un(Ug,{children:t.map((r,a)=>un(ae,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as At,jsxs as oh}from"react/jsx-runtime";function $s(e){let o=jg(!1),[t,r]=Js({search:JSON.parse(Kg(e.search))}),[a,n]=Js(!1);Zg(()=>{r({search:e.search})},[e.search]);let f=Yg(()=>{if(!e.visible)return[];let l=e.search.resourceType,i=$g(l),u=_g(l);return eh(i,u).sort((d,c)=>d.localeCompare(c)).map(d=>({value:d,label:Re(d)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function s(l){r({search:{...t.search,fields:l}})}return At(Wg,{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:At("div",{"data-testid":"overlay-child"})},children:oh(Jg,{children:[At(Xg,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:f,value:t.search.fields??[],onChange:s,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),At(zg,{position:"right",children:At(Qg,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function eh(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(Re(n));if(o)for(let n of Object.keys(o)){let f=Re(n);!r.has(n)&&!a.has(f)&&(t.push(n),r.add(n),a.add(f))}return t}import{Button as Mt,Group as ih,Modal as uh,NativeSelect as Zs}from"@mantine/core";import{getSearchParameters as ch,stringify as Ys}from"@medplum/core";import{useEffect as dh,useRef as ei,useState as hn}from"react";import{formatDateTime as th,getSearchParameterDetails as rh,globalSchema as ah,Operator as _s,SearchParameterType as nh}from"@medplum/core";import{Fragment as Ks,jsx as In}from"react/jsx-runtime";function Sr(e){let{resourceType:o,filter:t}=e,r=ah.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===_s.EQUALS||t.operator===_s.NOT_EQUALS))return In(Me,{value:{reference:t.value}});let a=rh(o,r);if(t.code==="_lastUpdated"||a.type===nh.DATETIME)return In(Ks,{children:th(t.value)})}return In(Ks,{children:t.value})}import{Checkbox as fh,TextInput as gn}from"@mantine/core";import{getSearchParameterDetails as lh,SearchParameterType as Qo}from"@medplum/core";import{jsx as po}from"react/jsx-runtime";function Rr(e){let o=lh(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case Qo.REFERENCE:return po(Ho,{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.BOOLEAN:return po(fh,{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.DATE:return po(gn,{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.DATETIME:return po(De,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case Qo.NUMBER:return po(gn,{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.QUANTITY:return po(ye,{name:t,defaultValue:sh(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return po(gn,{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 sh(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as G,jsxs as We}from"react/jsx-runtime";function oi(e){let[o,t]=hn(JSON.parse(Ys(e.search))),[r,a]=hn(-1),n=ei(o);n.current=o,dh(()=>{t(JSON.parse(Ys(e.search)))},[e.search]);function f(u){t(Uo(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let s=e.search.resourceType,l=ch(s)??{},i=o.filters||[];return We(uh,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[G("div",{children:We("table",{children:[We("colgroup",{children:[G("col",{style:{width:200}}),G("col",{style:{width:200}}),G("col",{style:{width:380}}),G("col",{style:{width:120}})]}),G("thead",{children:We("tr",{children:[G("th",{children:"Field"}),G("th",{children:"Operation"}),G("th",{children:"Value"}),G("th",{children:"Actions"})]})}),We("tbody",{children:[i.map((u,d)=>d===r?G(js,{resourceType:s,searchParams:l,defaultValue:u,okText:"Save",onOk:c=>{let m=[...i];m[d]=c,t(kt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):G(mh,{resourceType:s,searchParams:l,filter:u,onEdit:()=>a(d),onDelete:()=>t(Os(n.current,d))},`filter-${u.code}-${u.operator}-${u.value}-display`)),G(js,{resourceType:s,searchParams:l,okText:"Add",onOk:f})]})]})}),G(ih,{position:"right",mt:"xl",children:G(Mt,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function mh(e){let{filter:o}=e;return We("tr",{children:[G("td",{children:Re(o.code)}),G("td",{children:Bt(o.operator)}),G("td",{children:G(Sr,{resourceType:e.resourceType,filter:o})}),We("td",{children:[G(Mt,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),G(Mt,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function js(e){let[o,t]=hn(e.defaultValue??{}),r=ei(o);r.current=o;function a(i){t({...r.current,code:i})}function n(i){t({...r.current,operator:i})}function f(i){t({...r.current,value:i})}let s=e.searchParams[o.code],l=s&&Ws(s);return We("tr",{children:[G("td",{children:G(Zs,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:Re(i)}))]})}),G("td",{children:l&&G(Zs,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...l.map(i=>({value:i,label:Bt(i)}))]})}),G("td",{children:s&&o.operator&&G(Rr,{resourceType:e.resourceType,searchParam:s,defaultValue:o.value,onChange:f})}),We("td",{children:[o.code&&o.operator&&G(Mt,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&G(Mt,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as ph,Grid as vn,Modal as xh}from"@mantine/core";import{useState as Ih}from"react";import{jsx as zo,jsxs as gh}from"react/jsx-runtime";function ti(e){let[o,t]=Ih(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return zo(xh,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:zo(W,{onSubmit:r,children:gh(vn,{children:[zo(vn.Col,{span:10,children:zo(Rr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),zo(vn.Col,{span:2,children:zo(ph,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as k}from"@mantine/core";import{Operator as oe}from"@medplum/core";import{Fragment as ai,jsx as x,jsxs as Wo}from"react/jsx-runtime";function ri(e){if(!e.searchParams)return null;function o(n,f){a(xn(e.search,n.code,f))}function t(n){a(Cr(e.search,n.code))}function r(n,f){e.onPrompt(n,{code:n.code,operator:f,value:""})}function a(n){e.onChange(n)}return e.searchParams.length===1?x(hh,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):x(k.Dropdown,{children:e.searchParams.map(n=>x(k.Item,{children:Re(n.code)},n.code))})}function hh(e){switch(e.searchParam.type){case"date":return x(vh,{...e});case"number":case"quantity":return x(yh,{...e});case"reference":return x(Ch,{...e});case"string":case"token":case"uri":return x(Sh,{...e});default:return Wo(ai,{children:["Unknown search param type: ",e.searchParam.type]})}}function vh(e){let{searchParam:o}=e,t=o.code;return Wo(k.Dropdown,{children:[x(k.Item,{icon:x(it,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),x(k.Item,{icon:x(ut,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),x(k.Divider,{}),x(k.Item,{icon:x(Po,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Equals..."}),x(k.Item,{icon:x(bo,{size:14}),onClick:()=>e.onPrompt(o,oe.NOT_EQUALS),children:"Does not equal..."}),x(k.Divider,{}),x(k.Item,{icon:x(zt,{size:14}),onClick:()=>e.onPrompt(o,oe.ENDS_BEFORE),children:"Before..."}),x(k.Item,{icon:x(Qt,{size:14}),onClick:()=>e.onPrompt(o,oe.STARTS_AFTER),children:"After..."}),x(k.Item,{icon:x(la,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Between..."}),x(k.Divider,{}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Ns(e.search,t)),children:"Tomorrow"}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Ls(e.search,t)),children:"Today"}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Es(e.search,t)),children:"Yesterday"}),x(k.Divider,{}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(qs(e.search,t)),children:"Next Month"}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Vs(e.search,t)),children:"This Month"}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Hs(e.search,t)),children:"Last Month"}),x(k.Divider,{}),x(k.Item,{icon:x(Ne,{size:14}),onClick:()=>e.onChange(Gs(e.search,t)),children:"Year to date"}),x(br,{...e})]})}function yh(e){let{searchParam:o}=e;return Wo(k.Dropdown,{children:[x(k.Item,{icon:x(it,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),x(k.Item,{icon:x(ut,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),x(k.Divider,{}),x(k.Item,{icon:x(Po,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Equals..."}),x(k.Item,{icon:x(bo,{size:14}),onClick:()=>e.onPrompt(o,oe.NOT_EQUALS),children:"Does not equal..."}),x(k.Divider,{}),x(k.Item,{icon:x(Qt,{size:14}),onClick:()=>e.onPrompt(o,oe.GREATER_THAN),children:"Greater than..."}),x(k.Item,{icon:x(Do,{size:14}),onClick:()=>e.onPrompt(o,oe.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),x(k.Item,{icon:x(zt,{size:14}),onClick:()=>e.onPrompt(o,oe.LESS_THAN),children:"Less than..."}),x(k.Item,{icon:x(Do,{size:14}),onClick:()=>e.onPrompt(o,oe.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),x(br,{...e})]})}function Ch(e){let{searchParam:o}=e;return Wo(k.Dropdown,{children:[x(k.Item,{icon:x(Po,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Equals..."}),x(k.Item,{icon:x(bo,{size:14}),onClick:()=>e.onPrompt(o,oe.NOT),children:"Does not equal..."}),x(br,{...e})]})}function Sh(e){let{searchParam:o}=e;return Wo(k.Dropdown,{children:[x(k.Item,{icon:x(it,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),x(k.Item,{icon:x(ut,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),x(k.Divider,{}),x(k.Item,{icon:x(Po,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Equals..."}),x(k.Item,{icon:x(bo,{size:14}),onClick:()=>e.onPrompt(o,oe.NOT),children:"Does not equal..."}),x(k.Divider,{}),x(k.Item,{icon:x(ia,{size:14}),onClick:()=>e.onPrompt(o,oe.CONTAINS),children:"Contains..."}),x(k.Item,{icon:x(sa,{size:14}),onClick:()=>e.onPrompt(o,oe.EQUALS),children:"Does not contain..."}),x(br,{...e})]})}function br(e){let{searchParam:o}=e,t=o.code;return Wo(ai,{children:[x(k.Divider,{}),x(k.Item,{icon:x(na,{size:14}),onClick:()=>e.onChange(pn(e.search,t)),children:"Missing"}),x(k.Item,{icon:x(aa,{size:14}),onClick:()=>e.onChange(pn(e.search,t,!1)),children:"Not missing"}),x(k.Divider,{}),x(k.Item,{icon:x(Aa,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Rh,getSearchParameter as bh,getSearchParameterDetails as Ph,getSearchParameters as Dh}from"@medplum/core";function ni(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(Th(o,r));return t}function Th(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=Rh(e,o),r=bh(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=Dh(e),n;if(a){let f=new RegExp(`${e}\\.${o.replaceAll("[x]","")}([^\\w-]|$)`);n=Object.values(a).filter(s=>!!s.expression&&f.test(s?.expression)),n.length===0&&(n=void 0)}return{name:o,elementDefinition:t,searchParams:n}}if(r){let a=Ph(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as zh,jsx as B,jsxs as ge}from"react/jsx-runtime";var Sn=class extends Event{constructor(t){super("change");this.definition=t}},Rn=class extends Event{constructor(t){super("load");this.response=t}},xo=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},Nh=Bh(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 Hh(e){let{classes:o}=Nh(),t=S(),[r,a]=Cn(!1),[n,f]=Cn(),{search:s,onLoad:l}=e,[i,u]=Cn({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),d=Lh(i);d.current=i;let c=s.total??"accurate",m=li(C=>{f(void 0),t.search(s.resourceType,Oh({...s,total:c,fields:void 0}),C).then(H=>{u({...d.current,searchResponse:H}),l&&l(new Rn(H))}).catch(H=>{u({...d.current,searchResponse:void 0}),f(H)})},[t,s,c,l]),g=li(()=>{u({...d.current,searchResponse:void 0}),m({cache:"reload"})},[m]);si(()=>{m()},[m]);function I(C,H){C.stopPropagation();let j=C.target.checked,Z={...d.current.selected};j?Z[H]=!0:delete Z[H],u({...d.current,selected:Z})}function v(C){C.stopPropagation();let Le=C.target.checked,j={},Z=d.current.searchResponse;Le&&Z?.entry&&Z.entry.forEach(he=>{he.resource?.id&&(j[he.resource.id]=!0)}),u({...d.current,selected:j})}function P(){let C=d.current;if(!C.searchResponse?.entry||C.searchResponse.entry.length===0)return!1;for(let H of C.searchResponse.entry)if(H.resource?.id&&!C.selected[H.resource.id])return!1;return!0}function b(C){e.onChange&&e.onChange(new Sn(C))}function T(C,H){if(Xt(C.target)||C.button===2)return;O(C);let Le=C.button===1||C.ctrlKey||C.metaKey;!Le&&e.onClick&&e.onClick(new xo(H,C)),Le&&e.onAuxClick&&e.onAuxClick(new xo(H,C))}function q(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(si(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return B(Pr,{style:{width:"100%",height:"100%"},children:B(Ah,{})});let y=e.checkboxesEnabled,M=ni(s),_=s.resourceType,Y=i.searchResponse,no=Y?.entry?.map(C=>C.resource),re="subtle",h="gray",L=16,ke=window.innerWidth<768;return ge("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&ge(Dr,{position:"apart",mb:"xl",children:[ge(Dr,{spacing:2,children:[B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(da,{size:L}),onClick:()=>u({...d.current,fieldEditorVisible:!0}),children:"Fields"}),B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(ha,{size:L}),onClick:()=>u({...d.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(ga,{size:L}),onClick:e.onNew,children:"New..."}),!ke&&q()&&B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(Ba,{size:L}),onClick:e.onExport?e.onExport:()=>u({...d.current,exportDialogVisible:!0}),children:"Export..."}),!ke&&e.onDelete&&B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(ct,{size:L}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!ke&&e.onBulk&&B(Xo,{compact:!0,variant:re,color:h,leftIcon:B(fa,{size:L}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),ge(Dr,{spacing:2,children:[Y&&ge(yn,{size:"xs",color:"dimmed",children:[Uh(s,Y.total),"-",Qh(s,Y.total)," of"," ",`${c==="estimate"?"~":""}${Y.total?.toLocaleString()}`]}),B(kh,{title:"Refresh",onClick:g,children:B(Pa,{size:"1.125rem"})})]})]}),ge(Fh,{className:o.table,children:[ge("thead",{children:[ge("tr",{children:[y&&B("th",{children:B("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:P(),onChange:C=>v(C)})}),M.map(C=>B("th",{children:ge(fi,{shadow:"md",width:240,position:"bottom-end",children:[B(fi.Target,{children:B(wh,{className:o.control,children:ge(Dr,{position:"apart",noWrap:!0,children:[B(yn,{weight:500,size:"sm",children:Re(C.name)}),B(Pr,{className:o.icon,children:B(oa,{size:14,stroke:1.5})})]})})}),B(ri,{search:e.search,searchParams:C.searchParams,onPrompt:(H,Le)=>{u({...d.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:Le})},onChange:H=>{b(H)}})]})},C.name))]}),!e.hideFilters&&ge("tr",{children:[y&&B("th",{}),M.map(C=>B("th",{children:C.searchParams&&B(Vh,{resourceType:_,searchParams:C.searchParams,filters:e.search.filters})},C.name))]})]}),B("tbody",{children:no?.map(C=>C&&ge("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>T(H,C),onAuxClick:H=>T(H,C),children:[y&&B("td",{children:B("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${C.id}`,checked:!!i.selected[C.id],onChange:H=>I(H,C.id)})}),M.map(H=>B("td",{children:Xs(C,H)},H.name))]},C.id))})]}),no?.length===0&&B(Ye,{children:B(Pr,{style:{height:150},children:B(yn,{size:"xl",color:"dimmed",children:"No results"})})}),Y?.total!==void 0&&Y.total>0&&B(Pr,{m:"md",p:"md",children:B(Mh,{value:qh(s),total:Gh(s,Y.total),onChange:C=>b(Us(s,C)),getControlProps:C=>{switch(C){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&B("div",{"data-testid":"search-error",children:B("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),B($s,{search:e.search,visible:d.current.fieldEditorVisible,onOk:C=>{b(C),u({...d.current,fieldEditorVisible:!1})},onCancel:()=>{u({...d.current,fieldEditorVisible:!1})}}),B(oi,{search:e.search,visible:d.current.filterEditorVisible,onOk:C=>{b(C),u({...d.current,filterEditorVisible:!1})},onCancel:()=>{u({...d.current,filterEditorVisible:!1})}}),B(Fs,{visible:d.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...d.current,exportDialogVisible:!1})}}),B(ti,{visible:d.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?Re(i.filterDialogSearchParam.code):"",resourceType:_,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:C=>{b(Uo(e.search,C.code,C.operator,C.value)),u({...d.current,filterDialogVisible:!1})},onCancel:()=>{u({...d.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var rE=Eh(Hh);function Vh(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?B("span",{children:"no filters"}):B(zh,{children:o.map(t=>ge("div",{children:[Bt(t.operator),"\xA0",B(Sr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function qh(e){return Math.floor((e.offset??0)/(e.count??bn))+1}function Gh(e,o){let t=e.count??bn;return Math.ceil(o/t)}function Uh(e,o){return Math.min(o,(e.offset??0)+1)}function Qh(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??bn))}import{jsx as me,jsxs as kr}from"react/jsx-runtime";function Kh(e){let o=S(),[t,r]=Tr(!1),[a,n]=Tr(),{query:f,fields:s}=e,[l,i]=Tr(),[u,d]=Tr({}),c=ui();c.current=l;let m=ui({});m.current=u,ii(()=>{n(void 0),o.graphql(f).then(i).catch(T=>n($h(T)))},[o,f]);function g(T,q){T.stopPropagation();let M=T.target.checked,_={...m.current};M?_[q]=!0:delete _[q],d(_)}function I(T){T.stopPropagation();let y=T.target.checked,M={},_=c.current?.data.ResourceList;y&&_&&_.forEach(Y=>{Y.id&&(M[Y.id]=!0)}),d(M)}function v(){let T=c.current?.data.ResourceList;if(!T||T.length===0)return!1;for(let q of T)if(q.id&&!m.current[q.id])return!1;return!0}function P(T,q){Xt(T.target)||(O(T),T.button!==1&&e.onClick&&e.onClick(new xo(q,T)),T.button===1&&e.onAuxClick&&e.onAuxClick(new xo(q,T)))}if(ii(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return me(Xh,{});let b=e.checkboxesEnabled;return kr("div",{onContextMenu:T=>O(T),"data-testid":"search-control",children:[kr(Jh,{children:[me("thead",{children:kr("tr",{children:[b&&me("th",{children:me("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:v(),onChange:T=>I(T)})}),s.map(T=>me("th",{children:T.name},T.name))]})}),me("tbody",{children:l?.data.ResourceList.map(T=>T&&kr("tr",{"data-testid":"search-control-row",onClick:q=>P(q,T),onAuxClick:q=>P(q,T),children:[b&&me("td",{children:me("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${T.id}`,checked:!!u[T.id],onChange:q=>g(q,T.id)})}),s.map(q=>me("td",{children:me(Bs,{propertyType:q.propertyType,path:q.fhirPath,resource:T})},q.name))]},T.id))})]}),l?.data.ResourceList.length===0&&me("div",{"data-testid":"empty-search",children:"No results"}),a&&me("div",{"data-testid":"search-error",children:me("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&me(Wh,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var xE=_h(Kh);import{jsx as Jo,jsxs as Zh}from"react/jsx-runtime";function to(e){return Zh("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Jo("title",{children:"Medplum Logo"}),Jo("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Jo("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"}),Jo("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"}),Jo("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Jo("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as rv,SimpleGrid as av}from"@mantine/core";import{Box as ci,Flex as Pn,Group as Yh,Paper as jh,RingProgress as mi,Text as Io,Title as Dn}from"@mantine/core";import{formatCodeableConcept as di}from"@medplum/core";import{Fragment as gi,jsx as K,jsxs as Ft}from"react/jsx-runtime";function pi(e){let{group:o}=e;return K(jh,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:Ft(Yh,{children:[o.measureScore&&K(ov,{group:o}),!o.measureScore&&K(ev,{group:o})]})})}function xi(e){let{measure:o}=e;return Ft(gi,{children:[K(Io,{fz:"md",fw:500,mb:8,children:o.title}),K(Io,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function ev(e){let{group:o}=e,t=o.population,r=t?.find(l=>di(l.code)==="numerator"),a=t?.find(l=>di(l.code)==="denominator"),n=r?.count,f=a?.count;if(f===0)return Ft(ci,{children:[K(Dn,{order:3,children:"Not Applicable"}),K(Io,{children:`Denominator: ${f}`})]});if(n===void 0||f===void 0)return Ft(ci,{children:[K(Dn,{order:3,children:"Insufficient Data"}),K(Io,{children:`Numerator: ${n}`}),K(Io,{children:`Denominator: ${f}`})]});let s=n/f*100;return K(mi,{size:120,thickness:12,roundCaps:!0,sections:[{value:s,color:Ii(s)}],label:K(Pn,{justify:"center",children:Ft(Io,{fw:700,fz:18,children:[n," / ",f]})})})}function ov(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return K(gi,{children:t==="%"?K(mi,{size:120,thickness:12,roundCaps:!0,sections:[{value:tv(o),color:Ii(o?.measureScore?.value??0)}],label:K(Pn,{justify:"center",children:K(Io,{fw:700,fz:18,children:K(Ze,{value:o.measureScore})})})}):K(Pn,{h:120,align:"center",children:K(Dn,{order:3,children:K(Ze,{value:o.measureScore})})})})}function tv(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function Ii(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as Tn,jsxs as nv}from"react/jsx-runtime";function kE(e){let o=U(e.measureReport),[t]=sf("Measure",{url:o?.measure});return o?nv(rv,{children:[t&&Tn(xi,{measure:t}),Tn(av,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>Tn(pi,{group:r},r.id??a))})]}):null}import{Alert as fv}from"@mantine/core";import{operationOutcomeIssueToString as lv}from"@medplum/core";import{jsx as kn}from"react/jsx-runtime";function $o(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:kn(fv,{icon:kn(so,{size:16}),color:"red",children:o.map(t=>kn("div",{"data-testid":"text-field-error",children:lv(t)},t.details?.text))})}import{createReference as Br}from"@medplum/core";import{useCallback as sv}from"react";import{jsx as iv}from"react/jsx-runtime";function GE(e){let o=sv((t,r,a)=>{let n=`${r}/${a}`,f=100;return Promise.allSettled([t.readHistory("Patient",a),t.search("Communication",{subject:n,_count:f}),t.search("Device",{patient:n,_count:f}),t.search("DeviceRequest",{patient:n,_count:f}),t.search("DiagnosticReport",{subject:n,_count:f}),t.search("Media",{subject:n,_count:f}),t.search("ServiceRequest",{subject:n,_count:f}),t.search("Task",{subject:n,_count:f})])},[]);return iv(oo,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Br(t),sender:Br(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Br(t),operator:Br(r),issued:new Date().toISOString(),content:a})})}import{Anchor as vi,Button as uv,createStyles as cv,NativeSelect as dv,Stack as mv,TextInput as An}from"@mantine/core";import{getReferenceString as pv}from"@medplum/core";import{useEffect as hi,useRef as yi,useState as wt}from"react";import{jsx as Q,jsxs as _o}from"react/jsx-runtime";var Ci=cv(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 f1(e){let o=S(),t=U(e.value),[r,a]=wt(!1),[n,f]=wt(),[s,l]=wt(),[i,u]=wt();function d(){l(void 0)}function c(){f(void 0)}let m=yi();if(m.current=i,hi(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),hi(()=>(u(yv(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 g(I,v){u({...m.current,[I]:v})}return Q("div",{children:_o(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[Q(An,{label:"Plan Title",defaultValue:i.title,onChange:I=>g("title",I.currentTarget.value)}),Q(Si,{actions:i.action||[],selectedKey:n,setSelectedKey:f,hoverKey:s,setHoverKey:l,onChange:I=>g("action",I)}),Q(uv,{type:"submit",children:"Save"})]})})}function Si(e){let{classes:o}=Ci(),t=yi();t.current=e.actions;function r(f){e.onChange(t.current.map(s=>s.id===f.id?f:s))}function a(f){e.onChange([...t.current,f]),e.setSelectedKey(f.id)}function n(f){e.onChange(t.current.filter(s=>s!==f))}return _o("div",{className:o.section,children:[e.actions.map(f=>Q("div",{children:Q(xv,{action:f,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(f)})},f.id)),Q("div",{className:o.bottomActions,children:Q(vi,{href:"#",onClick:f=>{O(f),a({id:bi()})},children:"Add action"})})]})}function xv(e){let{classes:o,cx:t}=Ci(),{action:r}=e,a=vv(r),n=e.selectedKey===e.action.id,f=e.hoverKey===e.action.id;function s(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function l(u){O(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:f&&!n});return _o("div",{"data-testid":r.id,className:i,onClick:s,onMouseOver:l,onFocus:l,children:[n?Q(gv,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):Q(Iv,{action:r,actionType:a}),Q("div",{className:o.bottomActions,children:Q(vi,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Mn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function Iv(e){let{action:o,actionType:t}=e,[r,a]=Ri(o);return _o("div",{children:[_o("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&Q("div",{children:Q(mo,{value:{reference:o.definitionCanonical}})}),r&&Q("div",{children:Q(ae,{property:Mn,propertyType:a,value:r})})]})}function gv(e){let{action:o}=e,[t,r]=wt(e.actionType);function a(n,f){e.onChange({...o,[n]:f})}return _o(mv,{spacing:"xl",children:[Q(An,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),Q(An,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),Q(dv,{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&&Q(Si,{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 Q(Ar,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return Q(Ar,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return Q(Ar,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return Q(Ar,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),Q(Ie,{title:"Timing",description:"When the action should take place.",children:Q(hv,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function Ar(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return Q(sr,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:pv(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function hv(e){let o=e.action,t="timing",[r,a]=Ri(o);return Q(qe,{property:Mn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,f)=>{e.onChange(It(o,t,f??t,Mn,n))}})}function vv(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function Ri(e){return Ae({type:"PlanDefinitionAction",value:e},"timing")}var Bn=1;function bi(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Bn=Math.max(Bn,o+1))}return e}return"id-"+Bn++}function yv(e){return{...e,action:Pi(e.action)}}function Pi(e){if(e)return e.map(o=>({...o,id:bi(o.id),action:Pi(o.action)}))}import{Anchor as be,Box as Ln,Button as _v,createStyles as Kv,Group as Zv,NativeSelect as Yv,Space as jv,Textarea as ey,TextInput as Nn,Title as oy}from"@mantine/core";import{getElementDefinition as ty,isResource as ry}from"@medplum/core";import{useEffect as Gi,useRef as ay,useState as Nr}from"react";import{Checkbox as wv,Group as Ov,MultiSelect as Ev,NativeSelect as Lv,Radio as Ei,Textarea as Nv,TextInput as Ko}from"@mantine/core";import{capitalize as On,deepEquals as Hv,formatCodeableConcept as Vv,formatCoding as Lr,getElementDefinition as qv,getTypedPropertyValue as ro,stringify as Li}from"@medplum/core";import{useContext as Gv}from"react";import{deepClone as Cv,evalFhirPathTyped as Sv,formatCoding as Rv,getExtension as Mr,getTypedPropertyValue as Fn,getReferenceString as bv,stringify as Pv,splitN as Dv}from"@medplum/core";var Fr=(P=>(P.group="group",P.display="display",P.question="question",P.boolean="boolean",P.decimal="decimal",P.integer="integer",P.date="date",P.dateTime="dateTime",P.time="time",P.string="string",P.text="text",P.url="url",P.choice="choice",P.openChoice="open-choice",P.attachment="attachment",P.reference="reference",P.quantity="quantity",P))(Fr||{});function Di(e){return e.type==="choice"||e.type==="open-choice"}function Ti(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=Bi(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:f}=kv(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!f)return!1}return t!=="any"}function ki(e,o,t){return e.map(r=>{let a=t.answerOption?.find(f=>Rv(f.valueCoding)===r||f[o]===r),n=Fn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Bi(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Bi(t.item,o);if(r)return r}}}function Tv(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=Sv(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function kv(e,o,t){let r=o||[],a=Fn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,f=!0;for(let s of r){let l=Fn({type:"QuestionnaireResponseItemAnswer",value:s},"value[x]"),{operator:i}=e;if(Tv(l,a,i)?n=!0:f=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:f}}function wr(e){let o=Mr(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 Or(e,o){let t=Cv(e),r=Mr(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 Ai(e,o,t){let r=Mr(e,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceFilter");if(!r?.valueString)return;let a=r.valueString;o?.reference&&(a=a.replaceAll("$subj",o.reference)),t?.reference&&(a=a.replaceAll("$encounter",t.reference));let n={},f=a.split("&");for(let s of f){let[l,i]=Dv(s,"=",2);n[l]=i}return n}function Mi(e){return{resourceType:"QuestionnaireResponse",questionnaire:bv(e),item:Fi(e.item)}}function Fi(e){return e?.map(wn)??[]}function wn(e){return{id:Av(),linkId:e.linkId,text:e.text,item:Fi(e.item),answer:e.initial?.map(Mv)??[]}}var Bv=1;function Av(){return"id-"+Bv++}function Mv(e){return{...e}}function wi(e){return e.value.display||e.value.reference||Pv(e.value)}function Oi(e){let o=e?.item?.[0];return o&&Mr(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as Fv}from"react";var Er=Fv({});import{jsx as z}from"react/jsx-runtime";function Ot(e){let o=Gv(Er),t=e.item,r=e.response;function a(i){let u;Array.isArray(i)?u=i:e.index>=(e.response?.answer?.length??0)?u=(e.response?.answer??[]).concat([i]):u=(e.response?.answer??[]).map((c,m)=>m===e.index?i:c)??[],e.onChange({id:r?.id,linkId:r?.linkId,text:t.text,answer:u})}let n=t.type;if(!n)return null;let f=t.linkId;if(!f)return null;let s=t.initial&&t.initial.length>0?t.initial[0]:void 0,l=En(r,e.index)??ro({type:"QuestionnaireItemInitial",value:s},"value");switch(n){case"display":return z("p",{children:e.item.text},e.item.linkId);case"boolean":return z(rr,{title:e.item.text,htmlFor:e.item.linkId,children:z(wv,{id:e.item.linkId,name:e.item.linkId,defaultChecked:l?.value,onChange:i=>a({valueBoolean:i.currentTarget.checked})})},e.item.linkId);case"decimal":return z(Ko,{type:"number",step:"any",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDecimal:i.currentTarget.valueAsNumber})});case"integer":return z(Ko,{type:"number",step:1,id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueInteger:i.currentTarget.valueAsNumber})});case"date":return z(Ko,{type:"date",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDate:i.currentTarget.value})});case"dateTime":return z(De,{name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueDateTime:i})});case"time":return z(Ko,{type:"time",id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueTime:i.currentTarget.value})});case"string":case"url":return z(Ko,{id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"text":return z(Nv,{id:f,name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"attachment":return z(Ov,{py:4,children:z(Kt,{name:f,defaultValue:l?.value,onChange:i=>a({valueAttachment:i})})});case"reference":return z(Ho,{name:f,required:t.required,targetTypes:wr(t),searchCriteria:Ai(t,o.subject,o.encounter),defaultValue:l?.value,onChange:i=>a({valueReference:i})});case"quantity":return z(ye,{name:f,required:t.required,defaultValue:l?.value,onChange:i=>a({valueQuantity:i}),disableWheel:!0});case"choice":case"open-choice":return Jv(t)&&!t.answerValueSet?z(Uv,{name:f,item:t,initial:s,response:r,onChangeAnswer:i=>a(i)}):z(Qv,{name:f,item:t,initial:s,response:r,onChangeAnswer:i=>a(i)});default:return null}}function Uv(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return z(Vi,{});let n=ro({type:"QuestionnaireItemInitial",value:r},"value"),f=[""];for(let l of t.answerOption){let i=ro({type:"QuestionnaireItemAnswerOption",value:l},"value");f.push(Ni(i))}let s=En(a)??n;if(t.repeats){let{propertyName:l,data:i}=$v(e.item),u=Wv(a);return z(Ev,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[Ni(n)],onChange:d=>{let c=ki(d,l,t);e.onChangeAnswer(c)}})}return z(Lv,{id:o,name:o,onChange:l=>{let i=l.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],d=ro({type:"QuestionnaireItemAnswerOption",value:u},"value"),c="value"+On(d.type);e.onChangeAnswer({[c]:d.value})},defaultValue:Lr(s?.value)||s?.value,data:f})}function Qv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?z(Vi,{}):t.answerValueSet?z(nr,{name:o,binding:t.answerValueSet,onChange:f=>a({valueCoding:f})}):z(zv,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function zv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,f=qv("QuestionnaireItemAnswerOption","value[x]"),s=ro({type:"QuestionnaireItemInitial",value:r},"value"),l=[],i;if(t.answerOption)for(let c=0;c<t.answerOption.length;c++){let m=t.answerOption[c],g=`${o}-option-${c}`,I=ro({type:"QuestionnaireItemAnswerOption",value:m},"value");I?.value&&(s&&Li(I)===Li(s)&&(i=g),l.push([g,I]))}let u=En(n),d=Xv(l,u);return z(Ei.Group,{name:o,value:d??i,onChange:c=>{let m=l.find(g=>g[0]===c);if(m){let g=m[1],I="value"+On(g.type);a({[I]:g.value})}},children:l.map(([c,m])=>z(Ei,{id:c,value:c,py:4,label:z(ae,{property:f,propertyType:m.type,value:m.value})},c))})}function Vi(){return z(Ko,{disabled:!0,placeholder:"No Answers Defined"})}function qi(e){return ro({type:"QuestionnaireItemAnswer",value:e},"value")}function En(e,o=0){let t=e.answer;return qi(t?.[o]??{})}function Wv(e){let o=e.answer;return o?o.map(r=>qi(r)).map(r=>Lr(r?.value)||r?.value):[]}function Xv(e,o){return e.find(t=>Hv(t[1].value,o?.value))?.[0]}function Ni(e){if(e)return e.type==="CodeableConcept"?Vv(e.value):e.type==="Coding"?Lr(e.value):e.type==="Reference"?wi(e):e.value.toString()}function Jv(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function $v(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=ro({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+On(t.type),a=(e.answerOption??[]).map(n=>({value:Hi(n,r),label:Hi(n,r)}));return{propertyName:r,data:a}}function Hi(e,o){return Lr(e.valueCoding)||e[o]?.toString()}import{Fragment as Zo,jsx as F,jsxs as pe}from"react/jsx-runtime";var ny=Kv(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 z1(e){let o=S(),t=U(e.questionnaire),[r,a]=Nr(!1),[n,f]=Nr(),[s,l]=Nr(),[i,u]=Nr();function d(){u(void 0)}function c(){l(void 0)}Gi(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),Gi(()=>(f(iy(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",d),document.addEventListener("click",c),()=>{document.removeEventListener("mouseover",d),document.removeEventListener("click",c)}),[t]);let m=(g,I)=>{f(g),e.autoSave&&!I&&e.onSubmit&&e.onSubmit(g)};return!r||!n?null:F("div",{children:pe(W,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[F(Ui,{item:n,selectedKey:s,setSelectedKey:l,hoverKey:i,setHoverKey:u,onChange:m}),F(_v,{type:"submit",children:"Save"})]})})}function Ui(e){let{classes:o,cx:t}=ny(),r=e.item,a=e.item,n=ry(e.item),f=n||a.type==="group",s=a.linkId??"[untitled]",l=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=ay();u.current=e.item;function d(y){O(y),e.setSelectedKey(e.item.id)}function c(y){O(y),e.setHoverKey(e.item.id)}function m(y){let M=u.current;e.onChange({...M,item:M.item?.map(_=>_.id===y.id?y:_)})}function g(y,M){e.onChange({...e.item,item:[...e.item.item??[],y]},M)}function I(y){e.onChange({...e.item,item:e.item.item?.filter(M=>M!==y)})}function v(y,M){e.onChange({...u.current,[y]:M})}function P(y){e.onChange({...e.item,...y})}function b(y){e.onChange({...e.item,item:e.item.item?.map(M=>M===y?{...M,repeats:!M.repeats}:M)})}function T(y,M){let _=dy(e.item.item,y,M);e.onChange({...e.item,item:_})}let q=t(o.section,{[o.editing]:l,[o.hovering]:i&&!l});return pe("div",{"data-testid":a.linkId,className:q,onClick:d,onMouseOver:c,onFocus:c,children:[F("div",{className:o.questionBody,children:l?pe(Zo,{children:[n&&F(Nn,{size:"xl",defaultValue:r.title,onBlur:y=>v("title",y.currentTarget.value)}),!n&&F(ey,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:y=>v("text",y.currentTarget.value)}),a.type==="reference"&&F(sy,{item:a,onChange:P}),Di(a)&&F(fy,{item:a,onChange:y=>P(y)})]}):pe(Zo,{children:[r.title&&F(oy,{children:r.title}),a.text&&F("div",{children:a.text}),!f&&F(Ot,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((y,M)=>F("div",{children:F(Ui,{item:y,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:M===0,isLast:M===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>I(y),onRepeatable:b,onMoveUp:()=>T(M,-1),onMoveDown:()=>T(M,1)})},y.id)),!f&&F("div",{className:o.topActions,children:l?pe(Zo,{children:[F(Nn,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:y=>v("linkId",y.currentTarget.value)}),!f&&F(Yv,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:y=>v("type",y.currentTarget.value),data:[{value:"display",label:"Display"},{value:"boolean",label:"Boolean"},{value:"decimal",label:"Decimal"},{value:"integer",label:"Integer"},{value:"date",label:"Date"},{value:"dateTime",label:"Date/Time"},{value:"time",label:"Time"},{value:"string",label:"String"},{value:"text",label:"Text"},{value:"url",label:"URL"},{value:"choice",label:"Choice"},{value:"open-choice",label:"Open Choice"},{value:"attachment",label:"Attachment"},{value:"reference",label:"Reference"},{value:"quantity",label:"Quantity"}]})]}):F("div",{children:s})}),!n&&F(Ln,{className:o.movementActions,children:pe(Ln,{className:o.columnAlignment,children:[!e.isFirst&&F(be,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:F(ra,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&F(be,{href:"#",onClick:y=>{y.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:F(ta,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),pe("div",{className:o.bottomActions,children:[f&&pe(Zo,{children:[F(be,{href:"#",onClick:y=>{y.preventDefault(),g({id:go(),linkId:qn("q"),type:"string",text:"Question"})},children:"Add item"}),F(be,{href:"#",onClick:y=>{y.preventDefault(),g({id:go(),linkId:qn("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&F(be,{href:"#",onClick:y=>{y.preventDefault(),g(cy(),!0)},children:"Add Page"}),l&&!n&&pe(Zo,{children:[F(be,{href:"#",onClick:y=>{y.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),F(be,{href:"#",onClick:y=>{y.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function fy(e){let o=ty("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return pe("div",{children:[e.item.answerValueSet!==void 0?F(Nn,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):F(ly,{options:t,property:o,item:e.item,onChange:e.onChange}),pe(Ln,{display:"flex",children:[F(be,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:go()}]})},children:"Add choice"}),F(jv,{w:"lg"}),F(be,{href:"#",onClick:r=>{O(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function ly(e){return F("div",{children:e.options.map(o=>{let[t,r]=Ae({type:"QuestionnaireItemAnswerOption",value:o},"value");return pe("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[F("div",{children:F(qe,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let f=[...e.options],s=f.findIndex(l=>l.id===o.id);f[s]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:f})}},o.id)}),F("div",{children:F(be,{href:"#",onClick:a=>{O(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function sy(e){let o=wr(e.item)??[];return pe(Zo,{children:[o.map((t,r)=>pe(Zv,{children:[F(Oo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(Or(e.item,o.map(n=>n===t?a:n)))}}),F(be,{href:"#",onClick:a=>{O(a),e.onChange(Or(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),F(be,{href:"#",onClick:t=>{O(t),e.onChange(Or(e.item,[...o,""]))},children:"Add Resource Type"})]})}var Hn=1,Vn=1;function qn(e){return e+Hn++}function go(){return"id-"+Vn++}function iy(e){return{...e,id:e.id||go(),item:Qi(e.item)}}function Qi(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Vn=Math.max(Vn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(Hn=Math.max(Hn,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||go(),item:Qi(o.item),answerOption:uy(o.answerOption)}))}function uy(e){if(e)return e.map(o=>({...o,id:o.id||go()}))}function cy(){return{id:go(),linkId:qn("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 dy(e,o,t){let r=e??[],a=o+t;if(a<0||a>=r.length)return r;let n=[...r];return[n[o],n[a]]=[n[a],n[o]],n}import{Title as Dy}from"@mantine/core";import{createReference as Ty,getReferenceString as ky}from"@medplum/core";import{useEffect as _i,useState as Qn}from"react";import{Button as Un,Group as Sy,Stack as Ry,Stepper as Xi}from"@mantine/core";import{Anchor as my}from"@mantine/core";import{useState as py}from"react";import{jsx as Hr,jsxs as Iy}from"react/jsx-runtime";function Vr(e){let{item:o,response:t,onChange:r}=e,[a,n]=py(xy(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return Hr("p",{children:o.text},o.linkId);let f=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?Hr(Ot,{item:o,response:t,onChange:s=>r([s]),index:0},o.linkId):Iy(Ie,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((s,l)=>Hr(Ot,{item:o,response:t,onChange:i=>r([i]),index:l},`${o.linkId}-${l}`)),f&&Hr(my,{onClick:()=>n(s=>s+1),children:"Add Item"})]},e.item.linkId)}function xy(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}import{Anchor as gy,Stack as hy,Title as vy}from"@mantine/core";import{useState as yy}from"react";import{Fragment as Cy,jsx as ho,jsxs as Wi}from"react/jsx-runtime";function Gn(e){let[o,t]=yy(e.response);if(o.length===0)return null;function r(n,f){let s=o.map((l,i)=>i===f?n[0]:l);t(s),e.onChange(s)}function a(){let n=wn(e.item);t([...o,n])}return Wi(Cy,{children:[o.map((n,f)=>ho(zi,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:s=>r(s,f)},n.id)),e.item.repeats&&ho(gy,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function zi(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let s=o.item?.map(i=>n.find(d=>d.id===i.id)??i)?.concat(n.slice(1)),l={...o,item:s};r([l])}return e.checkForQuestionEnabled(e.item)?Wi("div",{children:[e.item.text&&ho(vy,{order:3,mb:"md",children:e.item.text}),ho(hy,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?ho(Gn,{item:n,response:o.item?.filter(f=>f.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):ho(zi,{item:n,checkForQuestionEnabled:t,response:o.item?.find(f=>f.linkId===n.linkId)??{},onChange:a},n.linkId):ho(Vr,{item:n,response:o.item?.find(f=>f.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as Py,jsx as Xe,jsxs as $i}from"react/jsx-runtime";function Ji(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:f,numberOfPages:s,renderPages:l,submitButtonText:i,checkForQuestionEnabled:u}=e,d=o.map(c=>{let m=t?.item?.filter(I=>I.linkId===c.linkId)??[],g=c.type==="group"?Xe(Gn,{item:c,response:m,onChange:a,checkForQuestionEnabled:u},c.linkId):Xe(Vr,{item:c,response:m?.[0],onChange:a,checkForQuestionEnabled:u},c.linkId);return l?Xe(Xi.Step,{label:c.text,children:g},c.linkId):g});return $i(Py,{children:[l&&Xe(Xi,{active:r??0,allowNextStepsSelect:!1,p:6,children:d}),!l&&Xe(Ry,{children:d}),Xe(by,{activePage:r??0,numberOfPages:s,nextStep:n,prevStep:f,submitButtonText:i})]})}function by(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return $i(Sy,{position:"right",mt:"xl",spacing:"xs",children:[o&&Xe(Un,{onClick:e.prevStep,children:"Back"}),t&&Xe(Un,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&Xe(Un,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as zn,jsxs as Ay}from"react/jsx-runtime";function Ki(e){let o=S(),t=o.getProfile(),[r,a]=Qn(!1),n=U(e.questionnaire),[f,s]=Qn(),[l,i]=Qn(0);_i(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),_i(()=>{s(n?Mi(n):void 0)},[n]);function u(I){let v=f?.item??[],b={resourceType:"QuestionnaireResponse",item:Zi(v,Array.isArray(I)?I:[I])};s(b)}function d(I){return Ti(I,f?.item??[])}if(!r||!n)return null;let c=Oi(n),m=()=>i(I=>I+1),g=()=>i(I=>I-1);return zn(Er.Provider,{value:{subject:e.subject,encounter:e.encounter},children:Ay(W,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&f&&e.onSubmit({...f,questionnaire:ky(n),subject:e.subject,source:Ty(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&zn(Dy,{children:n.title}),zn(Ji,{items:n.item??[],response:f,onChange:u,renderPages:c>1,activePage:l,numberOfPages:c,submitButtonText:e.submitButtonText,checkForQuestionEnabled:d,nextStep:m,prevStep:g})]})})}function By(e,o){let t=Zi(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 Zi(e,o){let t=[],r=new Set;for(let a of e){let n=a.id,f=o.find(s=>s.id===n);f?(t.push(By(a,f)),r.add(f.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}import{ActionIcon as qr,Button as My,createStyles as Fy,Divider as wy,Group as Et,NativeSelect as Wn,Stack as Gr,Text as Oy,TextInput as Ey}from"@mantine/core";import{formatRange as Yi,getCodeBySystem as Ly}from"@medplum/core";import{useEffect as Ny,useState as Xn}from"react";import{jsx as X,jsxs as Yo}from"react/jsx-runtime";var Hy=Fy(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"}})),Vy=["gender","age","gestationalAge","context","appliesTo","category"],qy={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function AL(e){e=Object.assign(qy,e);let o=e.definition,[t,r]=Xn([]),[a,n]=Xn(1),[f,s]=Xn(1);return Ny(()=>{let g=Qy(o,s);r(zy(g.qualifiedInterval||[],n))},[o]),Yo(W,{testid:"reference-range-editor",onSubmit:l,children:[X(Gr,{children:t.map(g=>X(Gy,{unit:Xy(o.quantitativeDetails?.unit),onChange:d,onAdd:c,onRemove:m,onRemoveGroup:u,intervalGroup:g},`group-${g.id}`))}),X(qr,{title:"Add Group",size:"sm",onClick:g=>{O(g),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(I=>I+1)},children:X(Ro,{})}),X(Et,{position:"right",children:X(My,{type:"submit",children:"Save"})})]});function l(){let g=t.flatMap(I=>I.intervals).filter(I=>!Jy(I));e.onSubmit({...o,qualifiedInterval:g})}function i(g){r(I=>[...I,g])}function u(g){r(I=>I.filter(v=>v.id!==g.id))}function d(g,I){r(v=>{v=[...v];let P=v.find(T=>T.id===g),b=P?.intervals.findIndex(T=>T.id===I.id);return b!==void 0&&P?.intervals[b]&&(P.intervals[b]=I),v})}function c(g,I){I.id===void 0&&(I.id=`id-${f}`,s(v=>v+1)),r(v=>{v=[...v];let P=v.findIndex(b=>b.id===g);if(P!==-1){let b={...v[P]};I={...I,...b.filters},b.intervals=[...b.intervals,I],v[P]=b}return v})}function m(g,I){r(v=>{v=[...v];let P=v.find(b=>b.id===g);return P&&(P.intervals=P.intervals.filter(b=>b.id!==I.id)),v})}}function Gy(e){let{intervalGroup:o,unit:t}=e,{classes:r}=Hy();return X(Ye,{"data-testid":o.id,className:r.section,children:Yo(Gr,{spacing:"lg",children:[X(Et,{position:"right",children:X(qr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{O(a),e.onRemoveGroup(o)},children:X(_e,{})},`remove-group-button-${o.id}`)}),X(Uy,{intervalGroup:o,onChange:e.onChange}),X(wy,{}),o.intervals.map(a=>Yo(Gr,{spacing:"xs",children:[Yo(Et,{children:[X(Ey,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{O(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),X(qr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{O(n),e.onRemove(o.id,a)},children:X(_e,{})},`remove-interval-${a.id}`)]}),X(ht,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),X(qr,{title:"Add Interval",size:"sm",onClick:a=>{O(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:X(Ro,{})})]})})}function Uy(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 Yo(Gr,{style:{maxWidth:"50%"},children:[X(Et,{children:X(Wn,{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})}}})}),Yo(Et,{spacing:"xs",children:[X(Oy,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),X("div",{id:`div-age-${o.id}`,children:X(ht,{name:`age-${o.id}`,defaultValue:o.filters.age,onChange:r=>{for(let a of o.intervals)t(o.id,{...a,age:r})}},`age-${o.id}`)})]}),X(Wn,{data:["","pre-puberty","follicular","midcycle","luteal","postmenopausal"],label:"Endocrine:",defaultValue:o.filters.context?.text||"",onChange:r=>{for(let a of o.intervals){let n=r.currentTarget.value;n===""?(n=void 0,t(o.id,{...a,context:void 0})):t(o.id,{...a,context:{text:n,coding:[{code:n,system:"http://terminology.hl7.org/CodeSystem/referencerange-meaning"}]}})}}}),X(Wn,{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 Qy(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 zy(e,o){let t=1,r={};for(let a of e){let n=Wy(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(Vy.map(f=>[f,a[f]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function Wy(e){return[`gender=${e.gender}`,`age=${Yi(e.age)}`,`gestationalAge=${Yi(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function Xy(e){return e&&(Ly(e,"http://unitsofmeasure.org")||e.text)}function Jy(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as ji,Grid as Ur,Text as $y}from"@mantine/core";import{formatDateTime as _y,getReferenceString as Ky}from"@medplum/core";import{Fragment as Zy,useEffect as Yy,useState as eu}from"react";import{jsx as Oe,jsxs as Lt}from"react/jsx-runtime";function qL(e){let o=S(),t=U(e.value),[r,a]=eu(!1),[n,f]=eu();if(Yy(()=>{t&&!r&&(o.executeBatch(s(t)).then(f).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Oe(Ur,{children:t.action?.map((i,u)=>{let d=i.resource&&l(i.resource),c=d?.input?.[0]?.valueReference,m=d?.output?.[0]?.valueReference;return Lt(Zy,{children:[Oe(Ur.Col,{span:1,p:"md",children:d?.status==="completed"?Oe(ua,{}):Oe(Ta,{color:"gray"})}),Lt(Ur.Col,{span:9,p:"xs",children:[Oe($y,{weight:500,children:i.title}),i.description&&Oe("div",{children:i.description}),Lt("div",{children:["Last edited by\xA0",Oe(Me,{value:d?.meta?.author}),"\xA0on\xA0",_y(d?.meta?.lastUpdated)]}),Lt("div",{children:["Status: ",Oe(cr,{status:d?.status||"unknown"})]})]}),Lt(Ur.Col,{span:2,p:"md",children:[c&&!m&&Oe(ji,{onClick:()=>e.onStart(d,c),children:"Start"}),c&&m&&Oe(ji,{onClick:()=>e.onEdit(d,c,m),children:"Edit"})]})]},`action-${u}`)})});function s(i){let u=[];if(i.action)for(let d of i.action)d.resource?.reference&&u.push({request:{method:"GET",url:d.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function l(i){for(let u of n?.entry)if(u.resource&&i.reference===Ky(u.resource))return u.resource}}import{createStyles as nC}from"@mantine/core";import{useEffect as fC,useState as lC}from"react";import{stringify as tC}from"@medplum/core";function Qr(e,o){let t=jy(e,o);return eC(t,e,o)}function jy(e,o){let t=e.length,r=o.length,a=t+r+1,n=1+2*a,f=n/2|0,s=new Array(n);s[f+1]={i:0,j:-1,prev:void 0,snake:!0};for(let l=0;l<a;l++){for(let i=-l;i<=l;i+=2){let u=f+i,d=u+1,c=u-1,m=s[d],g=s[c],I,v=0;i===-l||i!==l&&g.i<m.i?(v=m.i,I=m):(v=g.i+1,I=g),s[c]=void 0;let P=v-i,b={i:v,j:P,prev:oC(I),snake:!1};for(;v<t&&P<r&&e[v]===o[P];)v++,P++;if(v>b.i&&(b={i:v,j:P,prev:b,snake:!0}),s[u]=b,v>=t&&P>=r)return s[u]}s[f+l-1]=void 0}}function eC(e,o,t){let r=[],a=e;for(a.snake&&(a=a.prev);a?.prev&&a.prev.j>=0;){let n=a.i,f=a.j;a=a.prev;let s=a.i,l=a.j,i={position:s,lines:o.slice(s,n)},u={position:l,lines:t.slice(l,f)},d;i.lines.length===0&&u.lines.length>0?d="insert":i.lines.length>0&&u.lines.length===0?d="delete":d="change",r.push({original:i,revised:u,type:d}),a.snake&&(a=a.prev)}return r}function oC(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:tC(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 rC(t,o),aC(t),t}function rC(e,o){for(let t=1;t<o.length;t++){let r=Qr(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,f=a.original.lines,s=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,f.length),a.type==="insert"||a.type==="change")for(let l=0;l<a.revised.lines.length;l++)e.splice(n+l,0,{id:o[t].meta.versionId,meta:o[t].meta,value:s[l],span:1})}}}function aC(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 tu(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function ru(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return jo(t,"year");let r=Math.floor(o/2592e3);if(r>0)return jo(r,"month");let a=Math.floor(o/86400);if(a>0)return jo(a,"day");let n=Math.floor(o/3600);if(n>0)return jo(n,"hour");let f=Math.floor(o/60);return f>0?jo(f,"minute"):jo(o,"second")}function jo(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as iC,jsx as Te,jsxs as au}from"react/jsx-runtime";var sC=nC(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 o2(e){let{classes:o}=sC(),t=S(),[r,a]=lC(e.history);if(fC(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(a).catch(console.log)},[t,e.history,e.resourceType,e.id]),!r)return Te("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let f=ou(r);return Te("div",{className:o.container,children:Te("table",{className:o.root,children:Te("tbody",{children:f.map((s,l)=>au("tr",{className:s.span>0?o.startRow:o.normalRow,children:[s.span>0&&au(iC,{children:[Te("td",{className:o.author,rowSpan:s.span,children:Te(je,{value:s.meta.author,link:!0})}),Te("td",{className:o.dateTime,rowSpan:s.span,children:Te(ee,{to:tu(n,s.meta.versionId),children:ru(s.meta.lastUpdated)})})]}),Te("td",{className:o.lineNumber,children:l+1}),Te("td",{className:o.line,children:Te("pre",{className:o.pre,children:s.value})})]},"row-"+l))})})})}import{createStyles as uC}from"@mantine/core";import{stringify as nu}from"@medplum/core";import{Fragment as mC,jsx as et,jsxs as pC}from"react/jsx-runtime";var cC=uC(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function s2(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=nu(o,!0).match(/[^\r\n]+/g),a=nu(t,!0).match(/[^\r\n]+/g),n=Qr(r,a);return et("pre",{style:{color:"gray"},children:n.map((f,s)=>et(dC,{delta:f},"delta"+s))})}function dC(e){let{classes:o}=cC();return pC(mC,{children:["...",et("br",{}),e.delta.original.lines.length>0&&et("div",{className:o.removed,children:e.delta.original.lines.join(`
66
- `)}),e.delta.revised.lines.length>0&&et("div",{className:o.added,children:e.delta.revised.lines.join(`
67
- `)}),"...",et("br",{})]})}import{Button as fu,Group as xC,Stack as IC,TextInput as lu}from"@mantine/core";import{deepClone as gC}from"@medplum/core";import{useEffect as hC,useState as su}from"react";import{jsx as ao,jsxs as Jn}from"react/jsx-runtime";function h2(e){let o=S(),t=U(e.defaultValue),[r,a]=su(!1),[n,f]=su();return hC(()=>{t&&(f(gC(t)),o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log))},[o,t]),!r||!n?ao("div",{children:"Loading..."}):Jn("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(n)},children:[Jn(IC,{mb:"xl",children:[ao(Ie,{title:"Resource Type",htmlFor:"resourceType",outcome:e.outcome,children:ao(lu,{name:"resourceType",defaultValue:n.resourceType,disabled:!0})}),ao(Ie,{title:"ID",htmlFor:"id",outcome:e.outcome,children:ao(lu,{name:"id",defaultValue:n.id,disabled:!0})})]}),ao(Ct,{typeName:n.resourceType,defaultValue:n,outcome:e.outcome,onChange:f}),Jn(xC,{position:"right",mt:"xl",children:[ao(fu,{type:"submit",children:"OK"}),e.onDelete&&ao(fu,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(n)},children:"Delete"})]})]})}import{Table as vC}from"@mantine/core";import{formatDateTime as yC,normalizeErrorString as CC}from"@medplum/core";import{useEffect as SC,useState as RC}from"react";import{jsx as xe,jsxs as $n}from"react/jsx-runtime";function T2(e){let o=S(),[t,r]=RC(e.history);return SC(()=>{!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?$n(vC,{withBorder:!0,withColumnBorders:!0,children:[xe("thead",{children:$n("tr",{children:[xe("th",{children:"Author"}),xe("th",{children:"Date"}),xe("th",{children:"Version"})]})}),xe("tbody",{children:t.entry?.map((a,n)=>xe(bC,{entry:a},"entry-"+n))})]}):xe("div",{children:"Loading..."})}function bC(e){let{response:o,resource:t}=e.entry;return t?$n("tr",{children:[xe("td",{children:xe(je,{value:t.meta?.author,link:!0})}),xe("td",{children:yC(t.meta?.lastUpdated)}),xe("td",{children:xe(ee,{to:PC(t),children:t.meta?.versionId})})]}):xe("tr",{children:xe("td",{colSpan:3,children:CC(o?.outcome)})})}function PC(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as DC,createStyles as TC,Stack as kC,Text as BC}from"@mantine/core";import{getReferenceString as AC,isReference as MC}from"@medplum/core";import{useState as zr}from"react";import{jsx as ue,jsxs as ot}from"react/jsx-runtime";var FC=TC(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function V2(e){let{classes:o}=FC(),t=U(e.schedule),r=U(e.questionnaire),[a,n]=zr(ur()),[f,s]=zr(),[l,i]=zr(),[u,d]=zr(),[c]=uf("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",MC(e.schedule)?e.schedule.reference:AC(e.schedule)],["start","gt"+wC(a)],["start","lt"+OC(a)]]));if(!t||!c||!r)return null;let m=t.actor?.[0];return ot("div",{className:o.container,"data-testid":"scheduler",children:[ot("div",{className:o.info,children:[m&&ue(le,{value:m,size:"xl"}),m&&ue(BC,{size:"xl",weight:500,children:ue(Me,{value:m})}),ue("p",{children:"1 hour"}),f&&ue("p",{children:f.toLocaleDateString()}),l&&ue("p",{children:iu(new Date(l.start))})]}),ot("div",{className:o.selection,children:[!f&&ot("div",{children:[ue("h3",{children:"Select date"}),ue(Ql,{slots:c,onChangeMonth:n,onClick:s})]}),f&&!l&&ot("div",{children:[ue("h3",{children:"Select time"}),ue(kC,{children:c.map(g=>{let I=new Date(g.start);return I.getTime()>f.getTime()&&I.getTime()<f.getTime()+24*3600*1e3&&ue("div",{children:ue(DC,{variant:"outline",style:{width:150},onClick:()=>i(g),children:iu(I)})},g.id)})})]}),f&&l&&!u&&ue(Ki,{questionnaire:r,submitButtonText:"Next",onSubmit:d}),f&&l&&u&&ot("div",{children:[ue("h3",{children:"You're all set!"}),ue("p",{children:"Check your email for a calendar invite."})]})]})]})}function wC(e){return uu(e.getTime())}function OC(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 iu(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as Wr}from"@medplum/core";import{jsx as EC}from"react/jsx-runtime";function X2(e){return EC(oo,{value:e.serviceRequest,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory("ServiceRequest",r),o.search("Communication",{"based-on":a,_count:n}),o.search("DiagnosticReport",{"based-on":a,_count:n}),o.search("Media",{"based-on":a,_count:n}),o.search("DocumentReference",{related:a,_count:n}),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])},createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",basedOn:[Wr(o)],subject:o.subject,sender:Wr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[Wr(o)],subject:o.subject,operator:Wr(t),issued:new Date().toISOString(),content:r})})}import{normalizeOperationOutcome as rS}from"@medplum/core";import{useEffect as aS,useState as hu}from"react";import{Anchor as cu,Button as LC,Center as NC,Group as HC,Stack as VC,Text as qC,TextInput as GC,Title as UC}from"@mantine/core";import{normalizeOperationOutcome as QC}from"@medplum/core";import{useState as zC}from"react";import{jsx as vo,jsxs as Xr}from"react/jsx-runtime";function Jr(e){let o=S(),[t,r]=zC();return Xr(W,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(QC(n))}},children:[Xr(NC,{sx:{flexDirection:"column"},children:[vo(to,{size:32}),vo(UC,{children:"Create project"})]}),Xr(VC,{spacing:"xl",children:[vo(GC,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:ne(t,"firstName")}),Xr(qC,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",vo(cu,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",vo(cu,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),vo(HC,{position:"right",mt:"xl",noWrap:!0,children:vo(LC,{type:"submit",children:"Create project"})})]})}import{Anchor as Zr,Button as $C,Center as _C,Checkbox as KC,Divider as ZC,Group as pu,PasswordInput as YC,Stack as jC,Text as xu,TextInput as Kn}from"@mantine/core";import{normalizeOperationOutcome as Iu}from"@medplum/core";import{useEffect as eS,useState as oS}from"react";import{useEffect as WC,useRef as XC,useState as _n}from"react";function $r(e,o){let t=document.getElementsByTagName("head")[0],r=document.createElement("script");r.async=!0,r.src=e,r.onload=o??null,t.appendChild(r)}import{jsx as JC}from"react/jsx-runtime";function _r(e){let o=S(),{googleClientId:t,handleGoogleCredential:r}=e,a=XC(null),[n,f]=_n(typeof google<"u"),[s,l]=_n(!1),[i,u]=_n(!1);return WC(()=>{if(typeof google>"u"){$r("https://accounts.google.com/gsi/client",()=>f(!0));return}s||(google.accounts.id.initialize({client_id:t,callback:r}),l(!0)),a.current&&!i&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,s,n,a,i,r]),t?JC("div",{ref:a}):null}function Kr(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 du(e){typeof grecaptcha>"u"&&$r("https://www.google.com/recaptcha/api.js?render="+e)}function mu(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as tS,jsx as ce,jsxs as tt}from"react/jsx-runtime";function gu(e){let o=Kr(e.googleClientId),t=e.recaptchaSiteKey,r=S(),[a,n]=oS(),f=ar(a,void 0);return eS(()=>{t&&du(t)},[t]),tt(W,{style:{maxWidth:400},onSubmit:async s=>{try{let l="";t&&(l=await mu(t)),e.handleAuthResponse(await r.startNewUser({projectId:e.projectId,clientId:e.clientId,firstName:s.firstName,lastName:s.lastName,email:s.email,password:s.password,remember:s.remember==="true",recaptchaSiteKey:t,recaptchaToken:l}))}catch(l){n(Iu(l))}},children:[ce(_C,{sx:{flexDirection:"column"},children:e.children}),ce($o,{issues:f}),o&&tt(tS,{children:[ce(pu,{position:"center",p:"xl",style:{height:70},children:ce(_r,{googleClientId:o,handleGoogleCredential:async s=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:s.clientId,googleCredential:s.credential,createUser:!0}))}catch(l){n(Iu(l))}}})}),ce(ZC,{label:"or",labelPosition:"center",my:"lg"})]}),tt(jC,{spacing:"xl",children:[ce(Kn,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:ne(a,"firstName")}),ce(Kn,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:ne(a,"lastName")}),ce(Kn,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:ne(a,"email")}),ce(YC,{name:"password",label:"Password",autoComplete:"off",required:!0,error:ne(a,"password")}),tt(xu,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",ce(Zr,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",ce(Zr,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),tt(xu,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",ce(Zr,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",ce(Zr,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),tt(pu,{position:"apart",mt:"xl",noWrap:!0,children:[ce(KC,{name:"remember",label:"Remember me",size:"xs"}),ce($C,{type:"submit",children:"Create account"})]})]})}import{jsx as Zn,jsxs as nS}from"react/jsx-runtime";function NN(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:f}=e,s=S(),[l,i]=hu(),[u,d]=hu();aS(()=>{o==="patient"&&l&&s.startNewPatient({login:l,projectId:t}).then(m=>s.processCode(m.code)).then(()=>f()).catch(m=>d(rS(m)))},[s,o,t,l,f]);function c(m){m.code?s.processCode(m.code).then(()=>f()).catch(console.log):m.login&&i(m.login)}return nS(hr,{width:450,children:[u&&Zn("pre",{children:JSON.stringify(u,null,2)}),!l&&Zn(gu,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:c,children:e.children}),l&&o==="project"&&Zn(Jr,{login:l,handleAuthResponse:c})]})}import{showNotification as Fu}from"@mantine/notifications";import{normalizeErrorString as wu}from"@medplum/core";import{useCallback as jn,useEffect as LS,useState as ef}from"react";import{Anchor as vu,Button as yu,Center as Cu,Checkbox as fS,Divider as lS,Group as Yn,PasswordInput as sS,Stack as iS,TextInput as uS}from"@mantine/core";import{normalizeOperationOutcome as cS}from"@medplum/core";import{useCallback as Yr,useState as Su}from"react";import{Fragment as pS,jsx as te,jsxs as Nt}from"react/jsx-runtime";function Ru(e){let[o,t]=Su();return o?te(mS,{email:o,...e}):te(dS,{setEmail:t,...e})}function dS(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...f}=e,s=S(),l=!e.disableGoogleAuth&&Kr(e.googleClientId),i=Yr(async c=>{if(!c.authorizeUrl)return!1;let m=JSON.stringify({...await s.ensureCodeChallenge(f),domain:c.domain}),g=new URL(c.authorizeUrl);return g.searchParams.set("state",m),window.location.assign(g.toString()),!0},[s,f]),u=Yr(async c=>{let m=await s.post("auth/method",{email:c.email});await i(m)||o(c.email)},[s,i,o]),d=Yr(async c=>{let m=await s.startGoogleLogin({...f,googleCredential:c.credential});await i(m)||r(m)},[s,f,i,r]);return Nt(W,{style:{maxWidth:400},onSubmit:u,children:[te(Cu,{sx:{flexDirection:"column"},children:a}),l&&Nt(pS,{children:[te(Yn,{position:"center",p:"xl",style:{height:70},children:te(_r,{googleClientId:l,handleGoogleCredential:d})}),!n&&te(lS,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&te(uS,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Nt(Yn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[te("div",{children:t&&te(vu,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&te(yu,{type:"submit",children:"Next"})]})]})}function mS(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=S(),[f,s]=Su(),l=ar(f,void 0),i=Yr(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(d=>s(cS(d)))},[n,a,t]);return Nt(W,{style:{maxWidth:400},onSubmit:i,children:[te(Cu,{sx:{flexDirection:"column"},children:r}),te($o,{issues:l}),te(iS,{spacing:"xl",children:te(sS,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:ne(f,"password")})}),Nt(Yn,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&te(vu,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),te(fS,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),te(yu,{type:"submit",children:"Sign in"})]})]})}import{Avatar as xS,Center as IS,Group as gS,Stack as hS,Text as bu,Title as vS,UnstyledButton as yS}from"@mantine/core";import{normalizeOperationOutcome as CS}from"@medplum/core";import{useState as SS}from"react";import{jsx as yo,jsxs as jr}from"react/jsx-runtime";function Pu(e){let o=S(),[t,r]=SS();return jr(hS,{children:[jr(IS,{sx:{flexDirection:"column"},children:[yo(to,{size:32}),yo(vS,{order:3,children:"Choose profile"})]}),yo($o,{outcome:t}),e.memberships.map(a=>yo(yS,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(CS(n)))},children:jr(gS,{children:[yo(xS,{radius:"xl"}),jr("div",{style:{flex:1},children:[yo(bu,{size:"sm",weight:500,children:a.profile?.display}),yo(bu,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as RS,Center as bS,Checkbox as PS,Group as DS,Stack as Du,Title as TS}from"@mantine/core";import{jsx as Co,jsxs as Tu}from"react/jsx-runtime";function ku(e){let o=S();return Co(W,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:Tu(Du,{children:[Tu(bS,{sx:{flexDirection:"column"},children:[Co(to,{size:32}),Co(TS,{children:"Choose scope"})]}),Co(Du,{children:(e.scope??"openid").split(" ").map(t=>Co(PS,{id:t,name:t,label:t,defaultChecked:!0},t))}),Co(DS,{position:"right",mt:"xl",children:Co(RS,{type:"submit",children:"Set scope"})})]})})}import{Alert as kS,Button as BS,Center as AS,Group as MS,Stack as Bu,TextInput as FS,Title as wS}from"@mantine/core";import{normalizeErrorString as OS}from"@medplum/core";import{useState as ES}from"react";import{jsx as Je,jsxs as Au}from"react/jsx-runtime";function Mu(e){let o=S(),[t,r]=ES();return Je(W,{style:{maxWidth:400},onSubmit:a=>{r(void 0),o.post("auth/mfa/verify",{login:e.login,token:a.token}).then(e.handleAuthResponse).catch(n=>r(OS(n)))},children:Au(Bu,{children:[Au(AS,{sx:{flexDirection:"column"},children:[Je(to,{size:32}),Je(wS,{children:"Enter MFA code"})]}),t&&Je(kS,{icon:Je(so,{size:16}),title:"Error",color:"red",children:t}),Je(Bu,{children:Je(FS,{name:"token",label:"MFA code",required:!0})}),Je(MS,{position:"right",mt:"xl",children:Je(BS,{type:"submit",children:"Submit code"})})]})})}import{jsx as So}from"react/jsx-runtime";function qH(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:f,...s}=e,l=S(),[i,u]=ef(),[d,c]=ef(!1),[m,g]=ef(),I=jn(b=>{f?f(b):l.processCode(b).then(()=>{r&&r()}).catch(T=>Fu({color:"red",message:wu(T)}))},[l,f,r]),v=jn(b=>{c(!!b.mfaRequired),b.login&&u(b.login),b.memberships&&g(b.memberships),b.code&&(t?g(void 0):I(b.code))},[t,I]),P=jn(b=>{I(b.code)},[I]);return LS(()=>{o&&!i&&l.get("auth/login/"+o).then(v).catch(b=>Fu({color:"red",message:wu(b)}))},[l,o,i,v]),So(hr,{width:450,children:i?d?So(Mu,{login:i,handleAuthResponse:v}):m?So(Pu,{login:i,memberships:m,handleAuthResponse:v}):e.projectId==="new"?So(Jr,{login:i,handleAuthResponse:v}):e.chooseScopes?So(ku,{login:i,scope:e.scope,handleAuthResponse:P}):So("div",{children:"Success"}):So(Ru,{onForgotPassword:a,onRegister:n,handleAuthResponse:v,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...s,children:e.children})})}export{cf as AddressDisplay,xf as AddressInput,If as AnnotationInput,UT as AppShell,Mo as AsyncAutocomplete,Qf as AttachmentArrayDisplay,Wf as AttachmentArrayInput,Eo as AttachmentButton,Be as AttachmentDisplay,Kt as AttachmentInput,xt as BackboneElementDisplay,Ct as BackboneElementInput,Ql as CalendarInput,rr as CheckboxFormSection,$t as CodeInput,Lo as CodeableConceptDisplay,nl as CodeableConceptInput,_f as CodingDisplay,nr as CodingInput,Kf as ContactDetailDisplay,sl as ContactDetailInput,jt as ContactPointDisplay,fr as ContactPointInput,Ye as Container,De as DateTimeInput,uO as DefaultResourceTimeline,Jf as DescriptionList,$f as DescriptionListEntry,$a as DiagnosticReportDisplay,hr as Document,Ex as ElementDefinitionInputSelector,Vl as ElementDefinitionTypeInput,SO as EncounterTimeline,To as ErrorBoundary,Kh as FhirPathTable,W as Form,Ie as FormSection,Nf as Header,Wt as HumanNameDisplay,ml as HumanNameInput,Zf as IdentifierDisplay,Il as IdentifierInput,Ma as Loading,to as Logo,kE as MeasureReportDisplay,ee as MedplumLink,GS as MedplumProvider,xE as MemoizedFhirPathTable,rE as MemoizedSearchControl,Yf as MoneyDisplay,gl as MoneyInput,Uf as Navbar,CI as ObservationTable,$o as OperationOutcomeAlert,Vo as Panel,GE as PatientTimeline,f1 as PlanDefinitionBuilder,Ze as QuantityDisplay,ye as QuantityInput,z1 as QuestionnaireBuilder,Ki as QuestionnaireForm,Fr as QuestionnaireItemType,er as RangeDisplay,ht as RangeInput,mo as ReferenceDisplay,Ho as ReferenceInput,AL as ReferenceRangeEditor,Gy as ReferenceRangeGroupEditor,NN as RegisterForm,qL as RequestGroupDisplay,rl as ResourceArrayDisplay,Fl as ResourceArrayInput,le as ResourceAvatar,je as ResourceBadge,o2 as ResourceBlame,s2 as ResourceDiff,h2 as ResourceForm,T2 as ResourceHistoryTable,sr as ResourceInput,Me as ResourceName,ae as ResourcePropertyDisplay,qe as ResourcePropertyInput,fn as ResourceTable,oo as ResourceTimeline,V2 as Scheduler,Sn as SearchChangeEvent,xo as SearchClickEvent,Hh as SearchControl,$s as SearchFieldEditor,oi as SearchFilterEditor,Rn as SearchLoadEvent,X2 as ServiceRequestTimeline,qH as SignInForm,cr as StatusBadge,vs as Timeline,eo as TimelineItem,Nl as TimingInput,mn as addDateFilterBetween,VO as addField,Uo as addFilter,Hs as addLastMonthFilter,pn as addMissingFilter,qs as addNextMonthFilter,Vs as addThisMonthFilter,Ls as addTodayFilter,Ns as addTomorrowFilter,Gs as addYearToDateFilter,Es as addYesterdayFilter,Re as buildFieldNameString,Mi as buildInitialResponse,wn as buildInitialResponseItem,HO as clearFilters,Cr as clearFiltersOnField,ul as convertIsoToLocal,cl as convertLocalToIso,$r as createScriptTag,Os as deleteFilter,wi as formatReferenceString,ne as getErrorsForInput,ni as getFieldDefinitions,ar as getIssuesForExpression,ki as getNewMultiSelectValues,Oi as getNumberOfPages,Bt as getOpString,Ai as getQuestionnaireItemReferenceFilter,wr as getQuestionnaireItemReferenceTargetTypes,mu as getRecaptcha,Ws as getSearchOperators,Qs as getSortField,du as initRecaptcha,Di as isChoiceQuestion,Ti as isQuestionEnabled,zs as isSortDescending,Hf as parseForm,ff as reactContext,Xs as renderValue,kt as setFilters,Vg as setOffset,Us as setPage,Or as setQuestionnaireItemReferenceTargetTypes,xn as setSort,Ss as sortByDateAndPriority,qO as toggleSort,S as useMedplum,nt as useMedplumContext,$e as useMedplumNavigate,qt as useMedplumProfile,U as useResource,XS as useSearch,sf as useSearchOne,uf as useSearchResources};
64
+ }`.replace(/\s+/g," ")}function Pd(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),Dd(Td(t),o).slice(0,5)}function Td(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 Dd(e,o){return e.sort((t,r)=>Ll(r,o)-Ll(t,o))}function Ll(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,Nl(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,Nl(Id(r),o));return t}function Nl(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as $,jsxs as Ze}from"react/jsx-runtime";var Od=Bd(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 Ql(e){let o=st(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:f}=Od(),[s,i]=wd(!1);return $(Ad,{height:60,p:8,style:{zIndex:101},children:Ze($t,{position:"apart",children:[Ze($t,{spacing:"xs",children:[$(Gl,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&$(ql,{pathname:e.pathname,searchParams:e.searchParams})]}),Ze(Ge,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:s,onClose:()=>i(!1),children:[$(Ge.Target,{children:$(Gl,{className:f(l.user,{[l.userActive]:s}),onClick:()=>i(u=>!u),children:Ze($t,{spacing:7,children:[$(fe,{value:r,radius:"xl",size:24}),$(xt,{size:"sm",className:l.userName,children:Fd(r?.name?.[0])}),$(Ia,{size:12,stroke:1.5})]})})}),Ze(Ge.Dropdown,{children:[Ze(Md,{align:"center",p:"xl",children:[$(fe,{size:"xl",radius:100,value:o.profile}),$(Xt,{value:o.profile?.name?.[0]}),$(xt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&$(Ge.Divider,{}),n.map(u=>u.profile.reference!==Ul(o.profile)&&$(Ge.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:Ze($t,{children:[$(kd,{radius:"xl"}),Ze("div",{style:{flex:1},children:[$(xt,{size:"sm",weight:500,children:u.profile.display}),$(xt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),$(Ge.Divider,{}),$(Ge.Item,{icon:$(wa,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),$(Ge.Item,{icon:$(ko,{size:14,stroke:1.5}),onClick:()=>a(`/${Ul(r)}`),children:"Account settings"}),$(Ge.Item,{icon:$(Pa,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),$(xt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as lm,createStyles as fm,Navbar as Ha,ScrollArea as sm,Space as im,Text as um}from"@mantine/core";import{Fragment as cm,useState as dm}from"react";import{Button as Vd,Group as Hd,Modal as qd,NativeSelect as Gd,Stack as Ud,TextInput as Qd}from"@mantine/core";import{showNotification as Wl}from"@mantine/notifications";import{deepClone as zd,normalizeErrorString as Wd}from"@medplum/core";function zl(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Ed(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Ld(o,t);return o}function Ed(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Ld(e,o){e[o.name]=o.value}import{jsx as Nd}from"react/jsx-runtime";function X(e){return Nd("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=zl(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as mo,jsxs as Jd}from"react/jsx-runtime";function Xl(e){let o=P(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,f=`${e.pathname}?${e.searchParams.toString()}`,s=zd(t);s.menu?.find(({title:u})=>u===n)?.link?.push({name:l,target:f}),o.updateResource(s).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),Wl({color:"green",message:"Success"}),e.onOk()}).catch(u=>{Wl({color:"red",message:Wd(u)})})}return mo(qd,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:mo(X,{onSubmit:r,children:Jd(Ud,{children:[mo(Xd,{config:t}),mo(Qd,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),mo(Hd,{position:"right",children:mo(Vd,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Xd(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return mo(Gd,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as rm,useState as am}from"react";import{useState as jd}from"react";import{useCallback as $d}from"react";import{jsx as Yd}from"react/jsx-runtime";function Va(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function _d(e){return typeof e.display=="string"?e.display:Va(e)}function Kd(e){return{value:Va(e),label:_d(e),resource:e}}function Zd(e){return{code:e,display:e}}function Eo(e){let o=P(),{binding:t,creatable:r,clearable:a,...n}=e,l=$d(async(f,s)=>{if(!t)return[];let u=(await o.searchValueSet(t,f,{signal:s})).expansion?.contains,c=[];for(let d of u)d.code&&!c.some(m=>m.code===d.code)&&c.push(d);return c},[o,t]);return Yd(wo,{...n,creatable:r??!0,clearable:a??!0,toKey:Va,toOption:Kd,loadOptions:l,onCreate:Zd,getCreateLabel:r===!1?void 0:f=>`+ Create ${f}`})}import{jsx as tm}from"react/jsx-runtime";function _t(e){let[o,t]=jd(e.defaultValue);function r(a){let n=a[0],l=om(n);t(l),e.onChange&&e.onChange(l)}return tm(Eo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:em(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function em(e){return e?{code:e}:void 0}function om(e){return e?.code}import{jsx as nm}from"react/jsx-runtime";function Lo(e){let[o,t]=am(e.defaultValue),r=e.onChange,a=rm(n=>{t(n),r&&r(n)},[r]);return nm(_t,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as gm,jsx as Te,jsxs as It}from"react/jsx-runtime";var Jl=fm(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 $l(e){let{classes:o}=Jl(),t=_e(),r=xm(e.pathname,e.searchParams,e.menus),[a,n]=dm(!1);function l(s,i){s.stopPropagation(),s.preventDefault(),t(i),window.innerWidth<768&&e.closeNavbar()}function f(s){s&&t(`/${s}`)}return It(gm,{children:[Te(Ha,{width:{sm:250},p:"xs",children:It(sm,{children:[!e.resourceTypeSearchDisabled&&Te(Ha.Section,{mb:"sm",children:Te(Lo,{name:"resourceType",placeholder:"Resource Type",onChange:s=>f(s)},window.location.pathname)}),It(Ha.Section,{grow:!0,children:[e.menus?.map(s=>It(cm,{children:[Te(um,{className:o.menuTitle,children:s.title}),s.links?.map(i=>It(mm,{to:i.href,active:i.href===r?.href,onClick:u=>l(u,i.href),children:[Te(pm,{to:i.href,icon:i.icon}),Te("span",{children:i.label})]},i.href))]},`menu-${s.title}`)),e.displayAddBookmark&&Te(lm,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Te(Ba,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Te(Xl,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function mm(e){let{classes:o,cx:t}=Jl();return Te(oe,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function pm(e){return e.icon?e.icon:Te(im,{w:30})}function xm(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 f=Im(e,o,l.href);f>a&&(a=f,r=l)}return r}function Im(e,o,t){let r=new URL(t,"https://example.com");if(e!==r.pathname)return 0;let a=["_count","_offset"];for(let[l,f]of r.searchParams.entries())if(!a.includes(l)&&o.get(l)!==f)return 0;let n=1;for(let[l,f]of o.entries())a.includes(l)||r.searchParams.get(l)===f&&n++;return n}import{jsx as po}from"react/jsx-runtime";function Fk(e){let o=ym(),[t,r]=bm(localStorage.navbarOpen==="true"),a=P(),n=Gt();Cm(()=>{function i(){vm({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 f(){l(!1)}function s(){l(!t)}return a.isLoading()?po(La,{}):po(hm,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&po(Ql,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:s}),navbar:n&&t?po($l,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:po(Bo,{children:po(Sm,{fallback:po(La,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as Rm}from"@mantine/core";import{jsx as xo,jsxs as Tm}from"react/jsx-runtime";function we(e){let{contentType:o,url:t,title:r}=e.value??{};return t?Tm("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&xo("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&xo("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:xo("source",{type:o,src:t})}),o==="application/pdf"&&xo("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:xo("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),xo("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:xo(Rm,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Pm(r),children:r||"Download"})})]}):null}function Pm(e){return e?.includes(".")?e:void 0}import{jsx as qa}from"react/jsx-runtime";function _l(e){return qa("div",{children:e.values?.map((o,t)=>qa("div",{children:qa(we,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as Kl}from"@mantine/core";import{useRef as Fm,useState as wm}from"react";import{useRef as Dm}from"react";import{normalizeOperationOutcome as km}from"@medplum/core";import{Fragment as Am,jsx as Bm,jsxs as Mm}from"react/jsx-runtime";function No(e){let o=P(),t=Dm(null);function r(l){w(l),t.current?.click()}function a(l){w(l);let f=l.target.files;f&&Array.from(f).forEach(n)}function n(l){if(!l||!l.name)return;e.onUploadStart&&e.onUploadStart();let s=l.name,i=l.type||"application/octet-stream";o.createBinary(l,s,i,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:s})}).catch(u=>{e.onUploadError&&e.onUploadError(km(u))})}return Mm(Am,{children:[Bm("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as ye,jsxs as gt}from"react/jsx-runtime";function Zl(e){let[o,t]=wm(e.defaultValue??[]),r=Fm();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return gt("table",{style:{width:"100%"},children:[gt("colgroup",{children:[ye("col",{width:"97%"}),ye("col",{width:"3%"})]}),gt("tbody",{children:[o.map((n,l)=>gt("tr",{children:[ye("td",{children:ye(we,{value:n,maxWidth:200})}),ye("td",{children:ye(Kl,{title:"Remove",size:"sm",onClick:f=>{w(f);let s=o.slice();s.splice(l,1),a(s)},children:ye(Fe,{})})})]},`${l}-${o.length}`)),gt("tr",{children:[ye("td",{}),ye("td",{children:ye(No,{onUpload:n=>{a([...r.current,n])},children:n=>ye(Kl,{...n,title:"Add",size:"sm",color:"green",children:ye(ct,{size:16})})})})]})]})]})}import{Button as Yl}from"@mantine/core";import{useState as Om}from"react";import{Fragment as Em,jsx as Kt,jsxs as Lm}from"react/jsx-runtime";function Zt(e){let[o,t]=Om(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?Lm(Em,{children:[Kt(we,{value:o,maxWidth:200}),Kt(Yl,{onClick:a=>{w(a),r(void 0)},children:"Remove"})]}):Kt(No,{onUpload:r,children:a=>Kt(Yl,{...a,children:"Upload..."})})}import{getPathDisplayName as bp,tryGetDataType as Rp}from"@medplum/core";var Yt=["meta","implicitRules","contained","extension","modifierExtension"],jt=["language","text"];import{createStyles as Nm}from"@mantine/core";import{Fragment as Hm,jsx as Ga,jsxs as qm}from"react/jsx-runtime";var Vm=Nm(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 jl(e){let{children:o,compact:t}=e,{classes:r,cx:a}=Vm();return Ga("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function ef(e){return qm(Hm,{children:[Ga("dt",{children:e.term}),Ga("dd",{children:e.children})]})}import{ActionIcon as dp,Box as mp,CopyButton as pp,Tooltip as xp}from"@mantine/core";import{PropertyType as L,formatDateTime as Ip,formatPeriod as gp,formatTiming as hp,isEmpty as yp}from"@medplum/core";import{formatCodeableConcept as Gm}from"@medplum/core";import{Fragment as Um,jsx as Qm}from"react/jsx-runtime";function Vo(e){return Qm(Um,{children:Gm(e.value)})}import{formatCoding as zm}from"@medplum/core";import{Fragment as Wm,jsx as Xm}from"react/jsx-runtime";function of(e){return Xm(Wm,{children:zm(e.value)})}import{Fragment as Jm,jsx as $m}from"react/jsx-runtime";function er(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("]")),$m(Jm,{children:t.join("").trim()})}import{Fragment as Km,jsx as _m,jsxs as Zm}from"react/jsx-runtime";function tf(e){let o=e.value;return o?Zm(Km,{children:[o.name,o.name&&": ",o.telecom?.map(t=>_m(er,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as Ym}from"react/jsx-runtime";function rf(e){return Ym("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as jm}from"@medplum/core";import{Fragment as ep,jsx as op}from"react/jsx-runtime";function af(e){return op(ep,{children:jm(e.value)})}import{formatQuantity as tp}from"@medplum/core";import{Fragment as rp,jsx as ap}from"react/jsx-runtime";function Ye(e){return ap(rp,{children:tp(e.value)})}import{formatRange as np}from"@medplum/core";import{Fragment as lp,jsx as fp}from"react/jsx-runtime";function or(e){return fp(lp,{children:np(e.value)})}import{Fragment as sp,jsx as nf,jsxs as ip}from"react/jsx-runtime";function lf(e){let o=e.value;return o?ip(sp,{children:[nf(Ye,{value:o.numerator}),"\xA0/\xA0",nf(Ye,{value:o.denominator})]}):null}import{stringify as up}from"@medplum/core";import{Fragment as cp,jsx as ff}from"react/jsx-runtime";function Io(e){if(!e.value)return null;let o=e.value.display||e.value.reference||up(e.value);return e.link!==!1&&e.value.reference?ff(oe,{to:e.value,children:o}):ff(cp,{children:o})}import{Fragment as sf,jsx as tr}from"react/jsx-runtime";function uf(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?tr(sf,{children:t.map((a,n)=>tr("div",{children:tr(ne,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):tr(sf,{})}import{Fragment as Ho,jsx as q,jsxs as vp}from"react/jsx-runtime";function ne(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return vp(mp,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!yp(r)&&q(pp,{value:r,timeout:2e3,children:({copied:n,copy:l})=>q(xp,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:q(dp,{color:n?"teal":"gray",onClick:l,children:n?q(ut,{size:"1rem"}):q(ha,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===L.Attachment?q(_l,{values:r,maxWidth:e.maxWidth}):q(uf,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case L.boolean:return q(Ho,{children:r===void 0?"":(!!r).toString()});case L.SystemString:case L.string:return q("div",{style:{whiteSpace:"pre-wrap"},children:r});case L.code:case L.date:case L.decimal:case L.id:case L.integer:case L.positiveInt:case L.unsignedInt:case L.uri:case L.url:return q(Ho,{children:r});case L.canonical:return q(Io,{value:{reference:r},link:e.link});case L.dateTime:case L.instant:return q(Ho,{children:Ip(r)});case L.markdown:return q("pre",{children:r});case L.Address:return q(gl,{value:r});case L.Annotation:return q(Ho,{children:r?.text});case L.Attachment:return q(we,{value:r,maxWidth:e.maxWidth});case L.CodeableConcept:return q(Vo,{value:r});case L.Coding:return q(of,{value:r});case L.ContactDetail:return q(tf,{value:r});case L.ContactPoint:return q(er,{value:r});case L.HumanName:return q(Xt,{value:r});case L.Identifier:return q(rf,{value:r});case L.Money:return q(af,{value:r});case L.Period:return q(Ho,{children:gp(r)});case L.Quantity:case L.Duration:return q(Ye,{value:r});case L.Range:return q(or,{value:r});case L.Ratio:return q(lf,{value:r});case L.Reference:return q(Io,{value:r,link:e.link});case L.Timing:return q(Ho,{children:hp(r)});case L.Dosage:case L.UsageContext:return q(ht,{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 q(ht,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as Sp,getTypedPropertyValueWithSchema as Cp}from"@medplum/core";function je(e,o){let t=Sp(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}function cf(e,o,t){let r=Cp(e,o,t);return r?Array.isArray(r)?[r.map(a=>a.value),r[0].type]:[r.value,r.type]:[void 0,"undefined"]}import{jsx as rr,jsxs as Pp}from"react/jsx-runtime";function ht(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=Rp(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?rr("div",{children:t.name}):rr(jl,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,f]=n;if(Yt.includes(l)||jt.includes(l)&&f.path.split(".").length===2)return null;let[s,i]=je(o,l);return e.ignoreMissingValues&&(!s||Array.isArray(s)&&s.length===0)?null:rr(ef,{term:bp(l),children:rr(ne,{property:f,propertyType:i,value:s,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):Pp("div",{children:[r,"\xA0not implemented"]})}import{tryGetDataType as DI}from"@medplum/core";import{useContext as kI,useMemo as is,useState as BI}from"react";import{Stack as RI}from"@mantine/core";import{getPathDisplayName as fs}from"@medplum/core";import{useMemo as PI,useState as TI}from"react";import{Group as kp,Input as Bp}from"@mantine/core";import{useContext as Ap}from"react";import Tp from"react";function Dp(e,o){let t=e.lastIndexOf(o);if(t===-1)return["",e];let r=e.substring(0,t),a=e.substring(t+o.length);return[r,a]}var De=Tp.createContext({profileUrl:void 0,debugMode:!1,getModifiedNestedElement:()=>{}});function df(e,o,t){let r=Object.create(null);function a(l){return r[l]}let n=e?.elements;if(n){let l=new Set;for(let[f,s]of Object.entries(n)){let[i,u]=Dp(f,".");l.has(i)&&(r[e.type+"."+f]=s),l.add(f)}}return{debugMode:t??!1,profileUrl:o,getModifiedNestedElement:a}}import{jsx as Ua,jsxs as Mp}from"react/jsx-runtime";function ar(e){let{debugMode:o}=Ap(De),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Mp(kp,{noWrap:!0,"data-testid":e.testId,children:[Ua("div",{children:e.children}),Ua("div",{children:Ua(Bp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as Fp}from"@mantine/core";import{useContext as wp}from"react";function G(e,o){return e?.issue?.filter(t=>mf(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
65
+ `)}function nr(e,o){return e?.issue?.filter(t=>mf(t.expression?.[0],o))}function mf(e,o){if(e===o)return!0;if(!e||!o)return!1;let t=e.indexOf(".");if(t>=0&&e.substring(t+1)===o)return!0;let r=o.indexOf(".");return r>=0&&o.substring(r+1)===e}import{jsx as Op}from"react/jsx-runtime";function se(e){let{debugMode:o}=wp(De),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Op(Fp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,error:G(e.outcome,e.htmlFor),"data-testid":e.testId,children:e.children})}import{capitalize as Ep,isEmpty as pf}from"@medplum/core";function yt(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let f=o.replace("[x]",Ep(l.code));f in e&&delete e[f]}return e[t]=a,e}function JA(e){return!!e&&!pf(e.url)&&!pf(e.name)}import{Checkbox as II,Group as gI,NativeSelect as hI,Textarea as yI,TextInput as Za}from"@mantine/core";import{capitalize as ls,PropertyType as O}from"@medplum/core";import{useState as vI}from"react";import{useState as Lp}from"react";import{jsx as Hp}from"react/jsx-runtime";function xf(e){let[o,t]=Lp(e.defaultValue);function r(a){let n=Vp(a);t(n),e.onChange&&e.onChange(n)}return Hp(Eo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Np(o),maxSelectedValues:1,onChange:r})}function Np(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Vp(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as qp}from"react";import{jsx as Qp}from"react/jsx-runtime";function lr(e){let[o,t]=qp(e.defaultValue);function r(a){let n=a[0],l=n&&Up(n);t(l),e.onChange&&e.onChange(l)}return Qp(Eo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Gp(o),maxSelectedValues:1,onChange:r})}function Gp(e){return{system:e.system,code:e.code,display:e.display}}function Up(e){return{system:e.system,code:e.code,display:e.display}}import{Group as Zp,TextInput as Yp}from"@mantine/core";import{useRef as jp,useState as ex}from"react";import{Group as zp,NativeSelect as If,TextInput as Wp}from"@mantine/core";import{useContext as Xp,useMemo as Jp,useRef as $p,useState as _p}from"react";import{jsx as Qa,jsxs as Kp}from"react/jsx-runtime";function fr(e){let{path:o,outcome:t}=e,{getModifiedNestedElement:r}=Xp(De),[a,n]=_p(e.defaultValue),l=$p();l.current=a;let[f,s,i]=Jp(()=>["system","use","value"].map(x=>r(o+"."+x)),[r,o]);function u(x){x&&Object.keys(x).length===0&&(x=void 0),n(x),e.onChange&&e.onChange(x)}function c(x){let p={...l.current,system:x};x||delete p.system,u(p)}function d(x){let p={...l.current,use:x};x||delete p.use,u(p)}function m(x){let p={...l.current,value:x};x||delete p.value,u(p)}return Kp(zp,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[Qa(If,{"data-testid":"system",defaultValue:a?.system,required:(f?.min??0)>0,onChange:x=>c(x.currentTarget.value),data:["","email","phone","fax","pager","sms","other"],error:G(t,o+".system")}),Qa(If,{"data-testid":"use",defaultValue:a?.use,required:(s?.min??0)>0,onChange:x=>d(x.currentTarget.value),data:["","home","work","temp","old","mobile"],error:G(t,o+".use")}),Qa(Wp,{placeholder:"Value",defaultValue:a?.value,required:(i?.min??0)>0,onChange:x=>m(x.currentTarget.value),error:G(t,o+".value")})]})}import{jsx as gf,jsxs as ox}from"react/jsx-runtime";function hf(e){let[o,t]=ex(e.defaultValue),r=jp();r.current=o;function a(f){t(f),e.onChange&&e.onChange(f)}function n(f){let s={...r.current,name:f};f||delete s.name,a(s)}function l(f){let s={...r.current,telecom:f&&[f]};f||delete s.telecom,a(s)}return ox(Zp,{spacing:"xs",grow:!0,noWrap:!0,children:[gf(Yp,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:f=>n(f.currentTarget.value)}),gf(fr,{name:e.name+"-telecom",path:e.path+".telecom",defaultValue:o?.telecom?.[0],onChange:l,outcome:e.outcome})]})}import{TextInput as tx}from"@mantine/core";import{isValidDate as yf}from"@medplum/core";function vf(e){if(!e)return"";let o=new Date(e);return yf(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function Sf(e){if(!e)return"";let o=new Date(e);return yf(o)?o.toISOString():""}import{jsx as ax}from"react/jsx-runtime";function ke(e){return ax(tx,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:rx(),defaultValue:vf(e.defaultValue),autoFocus:e.autoFocus,error:G(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(Sf(t))}}})}function rx(){return"datetime-local"}import{JsonInput as nx}from"@mantine/core";import{stringify as lx,tryGetProfile as fx}from"@medplum/core";import{useEffect as sx,useMemo as ix,useState as Cf}from"react";import{jsx as za,jsxs as bf}from"react/jsx-runtime";function Rf(e){let{propertyType:o}=e,t=P(),[r,a]=Cf(!1),[n,l]=Cf(),f=ix(()=>{if(!(!o.profile||o.profile.length===0))return o.profile[0]},[o]);sx(()=>{f&&(a(!0),t.requestProfileSchema(f).then(()=>{let i=fx(f);a(!1),l(i)}).catch(i=>{a(!1),console.warn(i)}))},[t,f]);function s(i){e.onChange&&(console.log("Extension",i),e.onChange(i))}return f?r?bf("div",{children:["Loading ",f,"..."]}):n?za(qo,{profileUrl:f,typeName:n.name,defaultValue:e.defaultValue,onChange:s}):bf("div",{children:["StructureDefinition for ",f," not found"]}):za(ux,{...e})}function ux(e){return za(nx,{id:e.name,name:e.name,"data-testid":"extension-json-input",defaultValue:lx(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as cx,NativeSelect as dx,TextInput as sr}from"@mantine/core";import{useState as mx}from"react";import{jsx as vt,jsxs as px}from"react/jsx-runtime";function Pf(e){let{outcome:o,path:t}=e,[r,a]=mx(e.defaultValue);function n(c){a(c),e.onChange&&e.onChange(c)}function l(c){n({...r,use:c||void 0})}function f(c){n({...r,prefix:c?c.split(" "):void 0})}function s(c){n({...r,given:c?c.split(" "):void 0})}function i(c){n({...r,family:c||void 0})}function u(c){n({...r,suffix:c?c.split(" "):void 0})}return px(cx,{spacing:"xs",grow:!0,noWrap:!0,children:[vt(dx,{defaultValue:r?.use,name:e.name+"-use","data-testid":"use",onChange:c=>l(c.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"],error:G(o,t+".use")}),vt(sr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:r?.prefix?.join(" "),onChange:c=>f(c.currentTarget.value),error:G(o,t+".prefix")}),vt(sr,{placeholder:"Given",name:e.name+"-given",defaultValue:r?.given?.join(" "),onChange:c=>s(c.currentTarget.value),error:G(o,t+".given")}),vt(sr,{name:e.name+"-family",placeholder:"Family",defaultValue:r?.family,onChange:c=>i(c.currentTarget.value),error:G(o,t+".family")}),vt(sr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:r?.suffix?.join(" "),onChange:c=>u(c.currentTarget.value),error:G(o,t+".suffix")})]})}import{Group as xx,TextInput as Tf}from"@mantine/core";import{useContext as Ix,useMemo as gx,useState as hx}from"react";import{jsx as Df,jsxs as yx}from"react/jsx-runtime";function kf(e){let{path:o,outcome:t}=e,[r,a]=hx(e.defaultValue),{getModifiedNestedElement:n}=Ix(De),[l,f]=gx(()=>["system","value"].map(i=>n(o+"."+i)),[n,o]);function s(i){a(i),e.onChange&&e.onChange(i)}return yx(xx,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[Df(Tf,{placeholder:"System",required:(l?.min??0)>0,defaultValue:r?.system,onChange:i=>s({...r,system:i.currentTarget.value}),error:G(t,o+".system")}),Df(Tf,{placeholder:"Value",required:(f?.min??0)>0,defaultValue:r?.value,onChange:i=>s({...r,value:i.currentTarget.value}),error:G(t,o+".value")})]})}import{NativeSelect as vx,TextInput as Sx}from"@mantine/core";import{useCallback as Wa,useState as Cx}from"react";import{jsx as Xa}from"react/jsx-runtime";var bx=["USD","EUR","CAD","GBP","AUD"];function Bf(e){let{onChange:o}=e,[t,r]=Cx(e.defaultValue),a=Wa(s=>{r(s),o&&o(s)},[o]),n=Wa(s=>{a({...t,currency:s.currentTarget.value})},[t,a]),l=Wa(s=>{a({...t,value:s.currentTarget.valueAsNumber})},[t,a]),f=Xa(vx,{defaultValue:t?.currency,data:bx,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return Xa(Sx,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:Xa(ya,{size:14}),rightSection:f,rightSectionWidth:92,onChange:l})}import{Group as Rx}from"@mantine/core";import{useState as Px}from"react";import{jsx as Af,jsxs as Tx}from"react/jsx-runtime";function Mf(e){let[o,t]=Px(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Tx(Rx,{spacing:"xs",grow:!0,noWrap:!0,children:[Af(ke,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),Af(ke,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as Dx,NativeSelect as kx,TextInput as Ff}from"@mantine/core";import{useState as Bx}from"react";import{jsx as Ja,jsxs as Mx}from"react/jsx-runtime";function ve(e){let[o,t]=Bx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Mx(Dx,{spacing:"xs",grow:!0,noWrap:!0,children:[Ja(kx,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),Ja(Ff,{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:Ax(a.currentTarget.value)})}}),Ja(Ff,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function Ax(e){if(e)return parseFloat(e)}import{Group as Fx}from"@mantine/core";import{useState as wx}from"react";import{jsx as wf,jsxs as Ox}from"react/jsx-runtime";function St(e){let[o,t]=wx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Ox(Fx,{spacing:"xs",grow:!0,noWrap:!0,children:[wf(ve,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),wf(ve,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as Ex}from"@mantine/core";import{useState as Lx}from"react";import{jsx as Of,jsxs as Nx}from"react/jsx-runtime";function Ef(e){let[o,t]=Lx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Nx(Ex,{spacing:"xs",grow:!0,noWrap:!0,children:[Of(ve,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Of(ve,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as Jx,NativeSelect as $x}from"@mantine/core";import{createReference as _x}from"@medplum/core";import{useState as qf}from"react";import{Group as Vx,Text as Lf}from"@mantine/core";import{getDisplayString as Hx,getReferenceString as Hf}from"@medplum/core";import{forwardRef as qx,useCallback as Nf,useState as Gx}from"react";import{jsx as Ct,jsxs as Vf}from"react/jsx-runtime";var Ux={Observation:"code",User:"email:contains"},Qx=["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 zx(e){return{value:Hf(e),label:Hx(e),resource:e}}function ir(e){let o=P(),{resourceType:t,searchCriteria:r}=e,[a,n]=Gx(),l=Q(e.defaultValue,n),f=e.onChange,s=Nf(async(u,c)=>{let d=Xx(t),m=new URLSearchParams({[d]:u,_count:"10",...r});return await o.searchResources(t,m,{signal:c})},[o,t,r]),i=Nf(u=>{f&&f(u[0])},[f]);return e.defaultValue&&!a&&!l?null:Ct(wo,{name:e.name,required:e.required,itemComponent:Wx,defaultValue:l,placeholder:e.placeholder,maxSelectedValues:1,toKey:Hf,toOption:zx,loadOptions:s,onChange:i,clearable:!0})}var Wx=qx(({label:e,resource:o,...t},r)=>Ct("div",{ref:r,...t,children:Vf(Vx,{noWrap:!0,children:[Ct(fe,{value:o}),Vf("div",{children:[Ct(Lf,{children:e}),Ct(Lf,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function Xx(e){return Ux[e]??(Qx.includes(e)?"name":"_id")}import{jsx as $a,jsxs as Yx}from"react/jsx-runtime";function Go(e){let o=Kx(e.targetTypes),t=Zx(e.defaultValue,o),[r,a]=qf(e.defaultValue),[n,l]=qf(t);function f(s){a(s),e.onChange&&e.onChange(s)}return Yx(Jx,{spacing:"xs",grow:!0,noWrap:!0,children:[o&&o.length>1&&$a($x,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:n,autoFocus:e.autoFocus,onChange:s=>l(s.currentTarget.value),data:o}),!o&&$a(Lo,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:n,onChange:l,name:e.name+"-resourceType",placeholder:"Resource Type"}),$a(ir,{resourceType:n,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:e.searchCriteria,onChange:s=>{f(s?_x(s):void 0)}})]})}function Kx(e){if(!(!e||e.length===0||e.length===1&&e[0]==="Resource"))return e}function Zx(e,o){let t=e?.reference?.split("/")[0];if(t)return t;if(o&&o.length>0)return o[0]}import{ActionIcon as Jf,Group as $f,Stack as tI}from"@mantine/core";import{arrayify as rI,getElementDefinitionFromElements as _f,getTypedPropertyValueWithSchema as Kf,isEmpty as _a,matchDiscriminant as aI,tryGetProfile as nI}from"@medplum/core";import{useEffect as lI,useState as dr}from"react";import{ActionIcon as Gf,Group as Uf,Stack as Qf}from"@mantine/core";import{getPropertyDisplayName as jx,isEmpty as eI}from"@medplum/core";import{useState as oI}from"react";import{jsx as Se,jsxs as zf}from"react/jsx-runtime";function Wf(e){let{slice:o,property:t}=e,[r,a]=oI(()=>e.defaultValue.map(s=>s??{}));function n(s){a(s),e.onChange&&e.onChange(s)}let l=o.min>0,f=Object.keys(o.elements).length>0?void 0:{marginTop:"1rem",marginLeft:"1rem"};return Se(se,{title:jx(o.name),description:o.definition,withAsterisk:l,fhirPath:`${t.path}:${o.name}`,testId:e.testId,children:zf(Qf,{style:f,children:[r.map((s,i)=>zf(Uf,{noWrap:!0,children:[Se("div",{style:{flexGrow:1},children:Se(Qf,{children:eI(o.elements)?Se(ur,{elementDefinitionType:o.type[0],name:o.name,defaultValue:s,onChange:u=>{let c=[...r];c[i]=u,n(c)},outcome:void 0,min:o.min,max:o.max,binding:void 0,path:o.path}):Se(cr,{type:o.type[0].code,elements:o.elements,defaultValue:s,outcome:e.outcome,onChange:u=>{let c=[...r];c[i]=u,n(c)},testId:e.testId&&`${e.testId}-elements-${i}`})})}),r.length>o.min&&Se("div",{children:Se(Gf,{title:"Remove",size:"sm","data-testid":e.testId&&`${e.testId}-remove-${i}`,onClick:u=>{w(u);let c=[...r];c.splice(i,1),n(c)},children:Se(Fe,{})})})]},`${i}-${r.length}`)),r.length<o.max&&Se(Uf,{noWrap:!0,style:{justifyContent:"flex-end"},children:Se("div",{children:Se(Gf,{title:"Add",size:"sm",color:"green","data-testid":e.testId&&`${e.testId}-add`,onClick:s=>{w(s);let i=[...r,void 0];n(i)},children:Se(Ke,{})})})})]})})}function Xf(e){return e.type!==void 0&&e.type.length>0}import{jsx as Be,jsxs as Yf}from"react/jsx-runtime";function fI(e,o,t){if(e)for(let r of o){let a;if(r.typeSchema?a={type:r.typeSchema.name,value:e}:a={type:r.type[0].code,value:e},t.every(n=>{let l,f=r.elements;if(!_a(r.elements)){let s=_f(r.elements,n.path);s&&(l=Kf(a.value,n.path,s))}if(!l&&r.typeSchema&&!_a(r.typeSchema?.elements)){f=r.typeSchema.elements;let s=_f(r.typeSchema.elements,n.path);s&&(l=Kf(a.value,n.path,s))}if(l)return rI(l)?.some(s=>aI(s,n,r,f))}))return r.name}}function Zf(e,o,t){if(!t||t.slices.length===0)return[e];let r=new Array(o.length+1);for(let a=0;a<r.length;a++)r[a]=[];for(let a of e){let n=fI(a,o,t.discriminator),l=n?o.findIndex(f=>f.name===n):-1;l===-1&&(l=o.length),r[l].push(a)}for(let a=0;a<o.length;a++)r[a].length===0&&r[a].push(void 0);return r}function jf(e){let{property:o}=e,t=P(),[r,a]=dr(!0),[n,l]=dr([]),[f]=dr(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[s,i]=dr([[]]),u=o.type[0]?.code;lI(()=>{if(!o.slicing){let y=[];l(y);let b=Zf(f,y,o.slicing);i(b),a(!1);return}let p=[],h=[],S=[];for(let y of o.slicing.slices){if(!Xf(y))continue;let b=y.type[0],E;_a(y.elements)&&b.profile&&(E=b.profile[0]),p.push(y),h.push(E),E?S.push(t.requestProfileSchema(E)):S.push(Promise.resolve())}Promise.all(S).then(()=>{for(let b=0;b<p.length;b++){let E=p[b],C=h[b];if(C){let M=nI(C);E.typeSchema=M}}l(p);let y=Zf(f,p,o.slicing);i(y),a(!1)}).catch(y=>{console.error(y),a(!1)})},[t,o.slicing,u,f]);function c(p,h){let S=[...s];if(S[h]=p,i(S),e.onChange){let y=S.flat().filter(b=>b!==void 0);e.onChange(y)}}if(r)return Be("div",{children:"Loading..."});let d=n.length,m=s[d],x=!(e.hideNonSliceValues??(u==="Extension"&&n.length>0));return Yf(tI,{style:e.indent?{marginTop:"1rem",marginLeft:"1rem"}:void 0,children:[n.map((p,h)=>Be(Wf,{slice:p,property:o,defaultValue:s[h],onChange:S=>{c(S,h)},testId:`slice-${p.name}`},p.name)),x&&m.map((p,h)=>Yf($f,{noWrap:!0,style:{flexGrow:1},children:[Be("div",{style:{flexGrow:1},children:Be(eo,{arrayElement:!0,property:e.property,name:e.name+"."+h,defaultValue:p,onChange:S=>{let y=[...m];y[h]=S,c(y,d)},defaultPropertyType:void 0,outcome:e.outcome})}),Be("div",{children:Be(Jf,{title:"Remove",size:"sm","data-testid":`nonsliced-remove-${h}`,onClick:S=>{w(S);let y=[...m];y.splice(h,1),c(y,d)},children:Be(Fe,{})})})]},`${h}-${m.length}`)),x&&s.flat().length<o.max&&Be($f,{noWrap:!0,style:{justifyContent:"flex-end"},children:Be("div",{children:Be(Jf,{title:"Add",size:"sm",color:"green","data-testid":"nonsliced-add",onClick:p=>{w(p);let h=[...m];h.push(void 0),c(h,d)},children:Be(Ke,{})})})})]})}import{Button as ts,Chip as es,Group as mr,Modal as sI,NativeSelect as iI,Stack as uI,Switch as cI,TextInput as dI}from"@mantine/core";import{formatTiming as mI}from"@medplum/core";import{useRef as rs,useState as Ka}from"react";import{Fragment as ns,jsx as le,jsxs as bt}from"react/jsx-runtime";var pI=["sun","mon","tue","wed","thu","fri","sat"];function as(e){let[o,t]=Ka(e.defaultValue),[r,a]=Ka(!1),n=rs();return n.current=o,bt(ns,{children:[bt(mr,{spacing:"xs",grow:!0,noWrap:!0,children:[le("span",{children:mI(n.current)||"No repeat"}),le(ts,{onClick:()=>a(!0),children:"Edit"})]}),le(xI,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var os={repeat:{period:1,periodUnit:"d"}};function xI(e){let[o,t]=Ka(e.defaultValue||os),r=rs();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 f(i){n({...r.current?.repeat,periodUnit:i})}function s(i){n({...r.current?.repeat,dayOfWeek:i})}return le(sI,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:bt(uI,{children:[le(se,{title:"Starts on",htmlFor:"timing-dialog-start",children:le(ke,{name:"timing-dialog-start",onChange:i=>a(i)})}),le(cI,{label:"Repeat",checked:!!o.repeat,onChange:i=>n(i.currentTarget.checked?os.repeat:void 0)}),o.repeat&&bt(ns,{children:[le(se,{title:"Repeat every",htmlFor:"timing-dialog-period",children:bt(mr,{spacing:"xs",grow:!0,noWrap:!0,children:[le(dI,{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)}),le(iI,{id:"timing-dialog-periodUnit",name:"timing-dialog-periodUnit",defaultValue:o.repeat.periodUnit,onChange:i=>f(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"&&le(se,{title:"Repeat on",children:le(es.Group,{multiple:!0,onChange:s,children:le(mr,{position:"apart",mt:"md",spacing:"xs",children:pI.map(i=>le(es,{value:i,size:"xs",radius:"xl",children:i.charAt(0).toUpperCase()},i))})})})]}),le(mr,{position:"right",children:le(ts,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as V,jsxs as bI}from"react/jsx-runtime";function eo(e){let{property:o,name:t,defaultValue:r,onChange:a}=e,n=e.defaultPropertyType&&e.defaultPropertyType!=="undefined"?e.defaultPropertyType:o.type[0].code,l=o.type;if(o.max>1&&!e.arrayElement){if(n===O.Attachment)return V(Zl,{name:t,defaultValue:r,onChange:a});let f=l[0]?.code!==O.Extension;return V(jf,{property:o,name:t,defaultValue:r,indent:f,onChange:a,outcome:e.outcome})}return l.length>1?V(SI,{elementDefinitionTypes:l,...e}):V(ur,{name:t,defaultValue:r,onChange:f=>{if(e.onChange){let s=e.name.replace("[x]",ls(l[0].code));e.onChange(f,s)}},outcome:e.outcome,elementDefinitionType:l[0],min:o.min,max:o.min,binding:o.binding,path:o.path})}function SI(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=vI(t);return bI(gI,{spacing:"xs",grow:!0,noWrap:!0,children:[V(hI,{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}))}),V(ur,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",ls(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path})]})}function ur(e){let{name:o,defaultValue:t,onChange:r,outcome:a,binding:n,path:l}=e,f=e.min!==void 0&&e.min>0,s=e.elementDefinitionType.code;if(!s)return V("div",{children:"Property type not specified "});let i={name:o,defaultValue:t,onChange:r,outcome:a,path:l};switch(s){case O.SystemString:case O.canonical:case O.string:case O.time:case O.uri:case O.url:return V(Za,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case O.date:return V(Za,{type:"date",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case O.dateTime:case O.instant:return V(ke,{name:o,defaultValue:t,onChange:r,outcome:a});case O.decimal:case O.integer:case O.positiveInt:case O.unsignedInt:return V(Za,{type:"number",step:s===O.decimal?"any":"1",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.valueAsNumber)}});case O.code:return V(_t,{...i,binding:n?.valueSet});case O.boolean:return V(II,{id:o,name:o,"data-testid":o,defaultChecked:!!t,onChange:u=>{r&&r(u.currentTarget.checked)}});case O.markdown:return V(yI,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)}});case O.Address:return V(Sl,{...i});case O.Annotation:return V(Cl,{...i});case O.Attachment:return V(Zt,{...i});case O.CodeableConcept:return V(xf,{binding:n?.valueSet,...i});case O.Coding:return V(lr,{binding:n?.valueSet,...i});case O.ContactDetail:return V(hf,{...i});case O.ContactPoint:return V(fr,{...i});case O.Extension:return V(Rf,{...i,propertyType:e.elementDefinitionType});case O.HumanName:return V(Pf,{...i});case O.Identifier:return V(kf,{...i});case O.Money:return V(Bf,{...i});case O.Period:return V(Mf,{...i});case O.Duration:case O.Quantity:return V(ve,{...i});case O.Range:return V(St,{...i});case O.Ratio:return V(Ef,{...i});case O.Reference:return V(Go,{...i,targetTypes:CI(e.elementDefinitionType)});case O.Timing:return V(as,{...i});case O.Dosage:case O.UsageContext:default:return V(qo,{typeName:s,defaultValue:t,onChange:r,outcome:a})}}function CI(e){return e?.targetProfile?.map(o=>o.split("/").pop())}import{jsx as pr}from"react/jsx-runtime";var ss=["extension","modifierExtension"];function cr(e){let{elements:o}=e,[t,r]=TI(e.defaultValue??{}),a=PI(()=>{let l=Object.create(null);for(let[f,s]of Object.entries(o))s.fixed&&(l[f]=s);return l},[o]);function n(l){for(let[f,s]of Object.entries(a))yt(l,f,f,s,s.fixed.value);r(l),e.onChange&&e.onChange(l)}return pr(RI,{style:{flexGrow:1},"data-testid":e.testId,children:Object.entries(o).map(([l,f])=>{if(!f.type||f.max===0||l==="url"&&f.fixed)return null;if(ss.includes(l)){if(!f.slicing||f.slicing.slices.length===0)return null}else{if(l==="id"||Yt.includes(l))return null;if(jt.includes(l)&&f.path.split(".").length===2)return null}if(l.includes("."))return null;let[s,i]=cf(t,l,f),u=f.min!==void 0&&f.min>0,c=pr(eo,{property:f,name:l,defaultValue:s,defaultPropertyType:i,onChange:(d,m)=>{n(yt({...t},l,m??l,f,d))},arrayElement:void 0,outcome:e.outcome},l);return e.type==="Extension"||ss.includes(l)?c:f.type.length===1&&f.type[0].code==="boolean"?pr(ar,{title:fs(l),description:f.description,htmlFor:l,fhirPath:f.path,withAsterisk:u,children:c},l):pr(se,{title:fs(l),description:f.description,withAsterisk:u,htmlFor:l,outcome:e.outcome,fhirPath:f.path,children:c},l)})})}import{jsx as us,jsxs as AI}from"react/jsx-runtime";function qo(e){let{typeName:o}=e,[t,r]=BI(e.defaultValue??{}),a=kI(De),n=e.profileUrl??a.profileUrl,l=is(()=>DI(o,n),[o,n]),f=is(()=>df(l,n),[l,n]);if(!l)return AI("div",{children:[o,"\xA0not implemented"]});function s(i){r(i),e.onChange&&e.onChange(i)}return us(De.Provider,{value:f,children:us(cr,{type:l.type,elements:l.elements,defaultValue:t,onChange:s,outcome:e.outcome})})}import{Button as Ya,createStyles as MI,Group as ds}from"@mantine/core";import{useMemo as FI,useState as wI}from"react";function cs(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function xr(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as ie,jsxs as Rt}from"react/jsx-runtime";var OI=MI(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 ms(e){let{classes:o}=OI(),{onChangeMonth:t,onClick:r}=e,[a,n]=wI(xr);function l(s){n(i=>{let u=new Date(i.getTime());return u.setMonth(i.getMonth()+s),t(u),u})}let f=FI(()=>EI(a,e.slots),[a,e.slots]);return Rt("div",{children:[Rt(ds,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[ie("p",{style:{flex:1},children:cs(a)}),Rt(ds,{position:"right",spacing:"xs",children:[ie(Ya,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),ie(Ya,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),Rt("table",{className:o.table,children:[ie("thead",{children:Rt("tr",{children:[ie("th",{children:"SUN"}),ie("th",{children:"MON"}),ie("th",{children:"TUE"}),ie("th",{children:"WED"}),ie("th",{children:"THU"}),ie("th",{children:"FRI"}),ie("th",{children:"SAT"})]})}),ie("tbody",{children:f.map((s,i)=>ie("tr",{children:s.map((u,c)=>ie("td",{children:u&&ie(Ya,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+c))},"week-"+i))})]})]})}function EI(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:LI(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 LI(e,o){for(let t of o){let r=new Date(t.start);if(r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate())return!0}return!1}import{Container as NI,createStyles as VI}from"@mantine/core";import{jsx as qI}from"react/jsx-runtime";var HI=VI(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function oo(e){let{children:o,...t}=e,{classes:r}=HI();return qI(NI,{className:r.root,...t,children:o})}import{ActionIcon as $s,Center as Zg,createStyles as Yg,Group as jg,Loader as eh,Menu as We,ScrollArea as oh,TextInput as th}from"@mantine/core";import{showNotification as rh,updateNotification as Sr}from"@mantine/notifications";import{getReferenceString as Dt,normalizeErrorString as _s}from"@medplum/core";import{useCallback as Cr,useEffect as ah,useRef as Ks,useState as Zs}from"react";import{createStyles as og,Group as gr,List as gs,Stack as hs,Text as Ce,Title as ys}from"@mantine/core";import{capitalize as tg,formatCodeableConcept as rg,formatDateTime as en,formatObservationValue as ag,isReference as ng}from"@medplum/core";import{useEffect as lg,useState as fg}from"react";import{Blockquote as GI,createStyles as UI,Stack as QI}from"@mantine/core";import{jsx as ps}from"react/jsx-runtime";var zI=UI(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function ja({value:e}){let{classes:o}=zI();return e?ps(QI,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&ps(GI,{classNames:{cite:o.noteCite,body:o.noteBody,root:o.noteRoot},cite:t.authorReference?.display||t.authorString,icon:null,children:t.text},`note-${t.text}`))}):null}import{Group as KI}from"@mantine/core";import{Text as WI}from"@mantine/core";import{getDisplayString as XI,isOk as JI,normalizeErrorString as $I}from"@medplum/core";import{useState as _I}from"react";import{jsx as xs}from"react/jsx-runtime";function Oe(e){let{value:o,link:t,...r}=e,[a,n]=_I(),l=Q(o,n),f;if(a&&!JI(a))f=`[${$I(a)}]`;else if(l)f=XI(l);else return null;return t?xs(oe,{to:o,...r,children:f}):xs(WI,{component:"span",...r,children:f})}import{jsx as Is,jsxs as ZI}from"react/jsx-runtime";function to(e){return ZI(KI,{spacing:"xs",children:[Is(fe,{size:24,radius:12,value:e.value,link:e.link}),Is(Oe,{value:e.value,link:e.link})]})}import{Badge as YI}from"@mantine/core";import{jsx as eg}from"react/jsx-runtime";var jI={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 Ir(e){return eg(YI,{color:jI[e.status],children:e.status})}import{Fragment as Pt,jsx as T,jsxs as ue}from"react/jsx-runtime";var vs=og(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}}));on.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function on(e){let o=P(),t=Q(e.value),[r,a]=fg();if(lg(()=>{t?.specimen&&Promise.allSettled(t.specimen.map(l=>o.readReference(l))).then(l=>l.filter(f=>f.status==="fulfilled").map(f=>f.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 ue(hs,{children:[T(ys,{children:"Diagnostic Report"}),T(sg,{value:t}),r&&!e.hideSpecimenInfo&&ig(r),t.result&&T(ug,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&T(ja,{value:n})]})}function sg({value:e}){return ue(gr,{mt:"md",spacing:30,children:[e.subject&&ue("div",{children:[T(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),T(Ce,{children:T(to,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>ue("div",{children:[T(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),T(Ce,{children:T(to,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>ue("div",{children:[T(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),T(Ce,{children:T(to,{value:o,link:!0})})]},o.reference)),e.issued&&ue("div",{children:[T(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),T(Ce,{children:en(e.issued)})]}),e.status&&ue("div",{children:[T(Ce,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),T(Ce,{children:tg(e.status)})]})]})}function ig(e){return ue(hs,{spacing:"xs",children:[T(ys,{order:2,size:"h6",children:"Specimens"}),T(gs,{type:"ordered",children:e?.map(o=>T(gs.Item,{ml:"sm",children:ue(gr,{spacing:20,children:[ue(gr,{spacing:5,children:[T(Ce,{fw:500,children:"Collected:"})," ",en(o.collection?.collectedDateTime)]}),ue(gr,{spacing:5,children:[T(Ce,{fw:500,children:"Received:"})," ",en(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function ug(e){let{classes:o}=vs();return ue("table",{className:o.table,children:[T("thead",{children:ue("tr",{children:[T("th",{children:"Test"}),T("th",{children:"Value"}),T("th",{children:"Reference Range"}),T("th",{children:"Interpretation"}),T("th",{children:"Category"}),T("th",{children:"Performer"}),T("th",{children:"Status"})]})}),T("tbody",{children:T(Ss,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function Ss(e){return T(Pt,{children:e.value?.map(o=>T(cg,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${ng(o)?o.reference:o.id}`))})}function cg(e){let{classes:o,cx:t}=vs(),r=Q(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=pg(r);return ue(Pt,{children:[ue("tr",{className:t({[o.criticalRow]:n}),children:[T("td",{rowSpan:a?2:1,children:T(oe,{to:r,children:T(Vo,{value:r.code})})}),T("td",{children:T(dg,{value:r})}),T("td",{children:T(mg,{value:r.referenceRange})}),T("td",{children:r.interpretation&&r.interpretation.length>0&&T(Vo,{value:r.interpretation[0]})}),T("td",{children:r.category&&r.category.length>0&&T(Pt,{children:r.category.map(l=>T("div",{children:T(Vo,{value:l})},`category-${rg(l)}`))})}),T("td",{children:r.performer?.map(l=>T(Io,{value:l},l.reference))}),T("td",{children:r.status&&T(Ir,{status:r.status})})]}),r.hasMember&&T(Ss,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&T("tr",{children:T("td",{colSpan:6,children:T(ja,{value:r.note})})})]})}function dg(e){let o=e.value;return T(Pt,{children:ag(o)})}function mg(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?T(Pt,{children:o.text}):T(or,{value:o}):null}function pg(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as xg,Paper as Ig,useComponentDefaultProps as gg}from"@mantine/core";import{jsx as vg}from"react/jsx-runtime";var hg=xg((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%"}}})),yg={shadow:"xs",radius:"md",withBorder:!0};function Uo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=gg("Panel",yg,e),{classes:f,cx:s}=hg({width:r,fill:a},{name:"Panel",unstyled:n});return vg(Ig,{className:s(f.paper,o),...l,children:t})}import{createStyles as Lg}from"@mantine/core";import{capitalize as Ng,evalFhirPathTyped as Ns,getSearchParameterDetails as Vg,toTypedValue as Vs}from"@medplum/core";var qs=cc(Ls(),1);import{useEffect as Hg,useState as qg}from"react";import{jsx as ze,jsxs as vr}from"react/jsx-runtime";var Gg=Lg(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 Gs(e){let{classes:o}=Gg(),t=P(),[r,a]=qg(!1);if(Hg(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,qs.createPatch)(e.original,e.revised),l=[Vs(e.original)],f=[Vs(e.revised)];return vr("table",{className:o.root,children:[ze("thead",{children:vr("tr",{children:[ze("th",{}),ze("th",{children:"Before"}),ze("th",{children:"After"})]})}),ze("tbody",{children:n.map(s=>{if(s.path.startsWith("/meta"))return null;let i=s.path,u=Ug(i),d=Vg(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],m=!!d?.isArray,x=s.op==="add"?void 0:Ns(u,l)?.[0],p=s.op==="remove"?void 0:Ns(u,f)?.[0];return vr("tr",{children:[vr("td",{children:[Ng(s.op)," ",u]}),ze("td",{className:o.removed,children:x&&ze(ne,{property:d,propertyType:x.type,value:Hs(x.value,m),ignoreMissingValues:!0})}),ze("td",{className:o.added,children:p&&ze(ne,{property:d,propertyType:p.type,value:Hs(p.value,m),ignoreMissingValues:!0})})]},`op-${s.op}-${s.path}`)})})]})}function Ug(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 Hs(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as Qg,useState as zg}from"react";import{jsx as Wg}from"react/jsx-runtime";function pn(e){let o=P(),t=Q(e.value),[r,a]=zg(!1);return Qg(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:Wg(ht,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as Xg,Group as Jg,Menu as Us,Text as xn}from"@mantine/core";import{formatDateTime as $g,getReferenceString as _g}from"@medplum/core";import{Fragment as Kg,jsx as be,jsxs as Qo}from"react/jsx-runtime";function Qs(e){return be(oo,{children:e.children})}function ro(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,f=e.dateTime??o.meta?.lastUpdated;return Qo(Uo,{"data-testid":"timeline-item",fill:!0,...n,children:[Qo(Jg,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[be(fe,{value:l,link:!0,size:"md"}),Qo("div",{style:{flex:1},children:[be(xn,{size:"sm",children:be(Oe,{color:"dark",weight:500,value:l,link:!0})}),Qo(xn,{size:"xs",children:[be(oe,{color:"dimmed",to:e.resource,children:$g(f)}),be(xn,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),be(oe,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&Qo(Us,{position:"bottom-end",shadow:"md",width:200,children:[be(Us.Target,{children:be(Xg,{radius:"xl","aria-label":`Actions for ${_g(e.resource)}`,children:be(va,{})})}),a]})]}),Qo(Bo,{children:[r&&be("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&be(Kg,{children:e.children})]})]})}function Xs(e,o){e.sort((t,r)=>{let a=zs(t,o),n=zs(r,o);return a>n?1:a<n?-1:Ws(t,o)-Ws(r,o)})}function zs(e,o){if(!Js(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Ws(e,o){if(!Js(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 Js(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as mh,jsx as D,jsxs as kt}from"react/jsx-runtime";var nh=Yg(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function ao(e){let o=P(),t=_e(),r=o.getProfile(),a=Ks(null),n=Q(e.value),[l,f]=Zs(),[s,i]=Zs([]),u=e.loadTimelineResources,c=Ks(s);c.current=s;let d=Cr(v=>{Xs(v,n),v.reverse(),i(v)},[n]),m=Cr(v=>{let N=[];for(let Me of v){if(Me.status!=="fulfilled")continue;let R=Me.value;if(R.type==="history"&&f(R),R.entry)for(let H of R.entry)N.push(H.resource)}d(N)},[d]),x=Cr(v=>d([...c.current,v]),[d]),p=Cr(()=>{let v,N;"resourceType"in e.value?(v=e.value.resourceType,N=e.value.id):[v,N]=e.value.reference?.split("/"),u(o,v,N).then(m).catch(console.log)},[o,e.value,u,m]);ah(()=>p(),[p]);function h(v){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,v)).then(N=>x(N)).catch(console.log)}function S(v){!n||!e.createMedia||o.createResource(e.createMedia(n,r,v)).then(N=>x(N)).then(()=>Sr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:D(ut,{size:16}),autoClose:2e3})).catch(N=>Sr({id:"upload-notification",color:"red",title:"Upload error",message:_s(N),icon:D(Qt,{size:16}),autoClose:2e3}))}function y(v,N){return o.updateResource({...v,priority:N})}function b(v){y(v,"stat").then(p).catch(console.log)}function E(v){y(v,"routine").then(p).catch(console.log)}function C(v){t(`/${v.resourceType}/${v.id}`)}function M(v){t(`/${v.resourceType}/${v.id}/edit`)}function K(v){t(`/${v.resourceType}/${v.id}/delete`)}function j(v){t(`/${v.resourceType}/${v.id}/_history/${v.meta?.versionId}`)}function Ve(){rh({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function so(v){Sr({id:"upload-notification",loading:!0,title:"Uploading...",message:dh(v),autoClose:!1,withCloseButton:!1})}function ae(v){Sr({id:"upload-notification",color:"red",title:"Upload error",message:_s(v),icon:D(Qt,{size:16}),autoClose:2e3})}return n?kt(Qs,{children:[e.createCommunication&&D(Uo,{children:D(X,{testid:"timeline-form",onSubmit:v=>{h(v.text);let N=a.current;N&&(N.value="",N.focus())},children:kt(jg,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[D(fe,{value:r}),D(th,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),D($s,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:D(Ta,{size:16})}),D(No,{onUpload:S,onUploadStart:Ve,onUploadProgress:so,onUploadError:ae,children:v=>D($s,{...v,radius:"xl",color:"blue",variant:"filled",children:D(ct,{size:16})})})]})})}),s.map(v=>{if(!v)return null;let N=`${v.resourceType}/${v.id}/${v.meta?.versionId}`;if(v.resourceType===n.resourceType&&v.id===n.id)return D(lh,{history:l,resource:v,onDetails:j},N);switch(v.resourceType){case"AuditEvent":return D(uh,{resource:v,onDetails:C},N);case"Communication":return D(sh,{resource:v,onPin:v.priority!=="stat"?b:void 0,onUnpin:v.priority==="stat"?E:void 0,onDetails:C,onEdit:M,onDelete:K},N);case"DiagnosticReport":return D(ch,{resource:v,onDetails:C,onEdit:M,onDelete:K},N);case"Media":return D(ih,{resource:v,onDetails:C,onEdit:M,onDelete:K},N);default:return D(ro,{resource:v,padding:!0,children:D(pn,{value:v,ignoreMissingValues:!0})},N)}})]}):D(Zg,{style:{width:"100%",height:"100%"},children:D(eh,{})})}function zo(e){return kt(We.Dropdown,{children:[D(We.Label,{children:"Resource"}),e.onPin&&D(We.Item,{icon:D(Da,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Dt(e.resource)}`,children:"Pin"}),e.onUnpin&&D(We.Item,{icon:D(ka,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Dt(e.resource)}`,children:"Unpin"}),e.onDetails&&D(We.Item,{icon:D(Ra,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Dt(e.resource)}`,children:"Details"}),e.onEdit&&D(We.Item,{icon:D(Sa,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Dt(e.resource)}`,children:"Edit"}),e.onDelete&&kt(mh,{children:[D(We.Divider,{}),D(We.Label,{children:"Danger zone"}),D(We.Item,{color:"red",icon:D(pt,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Dt(e.resource)}`,children:"Delete"})]})]})}function lh(e){let o=fh(e.history,e.resource);return o?D(ro,{resource:e.resource,padding:!0,popupMenuItems:D(zo,{...e}),children:D(Gs,{original:o,revised:e.resource})}):kt(ro,{resource:e.resource,padding:!0,popupMenuItems:D(zo,{...e}),children:[D("h3",{children:"Created"}),D(pn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function fh(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 sh(e){let{classes:o}=nh(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return D(ro,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:D(zo,{...e}),children:D("p",{children:e.resource.payload?.[0]?.contentString})})}function ih(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return D(ro,{resource:e.resource,padding:!!t,popupMenuItems:D(zo,{...e}),children:D(we,{value:e.resource.content})})}function uh(e){return D(ro,{resource:e.resource,padding:!0,popupMenuItems:D(zo,{...e}),children:D(oh,{children:D("pre",{children:e.resource.outcomeDesc})})})}function ch(e){return D(ro,{resource:e.resource,padding:!0,popupMenuItems:D(zo,{...e}),children:D(on,{value:e.resource})})}function dh(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${In(e.loaded)} / ${In(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${In(e.loaded)}`}function In(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as ph}from"react/jsx-runtime";function KE(e){return ph(ao,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as Ys}from"react/jsx-runtime";function br(e){let{children:o,...t}=e;return Ys(oo,{children:Ys(Uo,{...t,children:o})})}import{createReference as Rr}from"@medplum/core";import{jsx as xh}from"react/jsx-runtime";function s0(e){return xh(ao,{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:Rr(o),subject:o.subject,sender:Rr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:Rr(o),subject:o.subject,operator:Rr(t),issued:new Date().toISOString(),content:r})})}import{Button as Oy,Loader as Ey,Table as Ly}from"@mantine/core";import{normalizeOperationOutcome as Ny}from"@medplum/core";import{memo as Vy,useEffect as wi,useRef as Oi,useState as Fr}from"react";import{evalFhirPath as Ih}from"@medplum/core";import{jsx as gh}from"react/jsx-runtime";function js(e){let o;try{o=Ih(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 gh(ne,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as gy,Button as _o,Center as Ar,createStyles as hy,Group as Mr,Loader as yy,Menu as Ai,Pagination as vy,Table as Sy,Text as Dn,UnstyledButton as Cy}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as Mn,formatSearchQuery as by}from"@medplum/core";import{memo as Ry,useCallback as Mi,useEffect as Fi,useRef as Py,useState as kn}from"react";import{Box as hh,Button as yh,Modal as vh,Text as Sh}from"@mantine/core";import{jsx as Pr,jsxs as oi}from"react/jsx-runtime";function ti(e){return oi(vh,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[oi(hh,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&Pr(ei,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&Pr(ei,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),Pr(Sh,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function ei(e){return Pr(yh,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as Fh,Group as wh,Modal as Oh,MultiSelect as Eh,Stack as Lh}from"@mantine/core";import{getDataType as Nh,getSearchParameters as Vh,stringify as Hh}from"@medplum/core";import{useEffect as qh,useMemo as Gh,useRef as Uh,useState as gi}from"react";import{capitalize as Ch,DEFAULT_SEARCH_COUNT as bh,evalFhirPathTyped as Rh,formatDateTime as Ph,Operator as A}from"@medplum/core";import{Fragment as Mh,jsx as gn}from"react/jsx-runtime";var Th={string:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],fulltext:[A.EQUALS,A.NOT,A.CONTAINS,A.EXACT],token:[A.EQUALS,A.NOT],reference:[A.EQUALS,A.NOT],numeric:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],quantity:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS],date:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY],datetime:[A.EQUALS,A.NOT_EQUALS,A.GREATER_THAN,A.LESS_THAN,A.GREATER_THAN_OR_EQUALS,A.LESS_THAN_OR_EQUALS,A.STARTS_AFTER,A.ENDS_BEFORE,A.APPROXIMATELY]},Dh={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 Bt(e,o){return{...e,filters:o,offset:0,name:void 0}}function R0(e){return Bt(e,[])}function Tr(e,o){return Bt(e,(e.filters??[]).filter(t=>t.code!==o))}function Wo(e,o,t,r,a){a&&(e=Tr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Bt(e,n)}function P0(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 ai(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function ni(e,o){return hn(e,o,-1)}function li(e,o){return hn(e,o,0)}function fi(e,o){return hn(e,o,1)}function hn(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),vn(e,o,r,a)}function si(e,o){return yn(e,o,-1)}function ii(e,o){return yn(e,o,0)}function ui(e,o){return yn(e,o,1)}function yn(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),vn(e,o,r,a)}function ci(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),vn(e,o,t,new Date)}function vn(e,o,t,r){return e=Tr(e,o),e=ri(e,o,A.GREATER_THAN_OR_EQUALS,t),e=ri(e,o,A.LESS_THAN_OR_EQUALS,r),e}function ri(e,o,t,r){return Wo(e,o,t,r.toISOString())}function Sn(e,o,t=!0){return Wo(e,o,A.MISSING,t.toString())}function kh(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function di(e,o){let t=e.count??bh,r=(o-1)*t;return kh(e,r)}function Cn(e,o,t){return o===mi(e)&&t!==void 0&&t===pi(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function T0(e,o){let t=!1;return mi(e)===o&&(t=!pi(e)),Cn(e,o,t)}function mi(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function pi(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function xi(e){return Th[e.type]}function At(e){return Dh[e]??""}function Re(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(Ch).join(" "))}function Ii(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?Ph(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?Bh(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?Ah(e,o.searchParams[0]):null}function Bh(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=je({type:e.resourceType,value:e},t);return r?gn(ne,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function Ah(e,o){let t=Rh(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:gn(Mh,{children:t.map((r,a)=>gn(ne,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as Mt,jsxs as zh}from"react/jsx-runtime";function hi(e){let o=Uh(!1),[t,r]=gi({search:JSON.parse(Hh(e.search))}),[a,n]=gi(!1);qh(()=>{r({search:e.search})},[e.search]);let l=Gh(()=>{if(!e.visible)return[];let s=e.search.resourceType,i=Nh(s),u=Vh(s);return Qh(i,u).sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:Re(c)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function f(s){r({search:{...t.search,fields:s}})}return Mt(Oh,{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:Mt("div",{"data-testid":"overlay-child"})},children:zh(Lh,{children:[Mt(Eh,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:l,value:t.search.fields??[],onChange:f,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),Mt(wh,{position:"right",children:Mt(Fh,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function Qh(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(Re(n));if(o)for(let n of Object.keys(o)){let l=Re(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as Ft,Group as Yh,Modal as jh,NativeSelect as Si}from"@mantine/core";import{getSearchParameters as ey,stringify as Ci}from"@medplum/core";import{useEffect as oy,useRef as Ri,useState as Pn}from"react";import{formatDateTime as Wh,getSearchParameterDetails as Xh,globalSchema as Jh,Operator as yi,SearchParameterType as $h}from"@medplum/core";import{Fragment as vi,jsx as bn}from"react/jsx-runtime";function Dr(e){let{resourceType:o,filter:t}=e,r=Jh.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===yi.EQUALS||t.operator===yi.NOT_EQUALS))return bn(Oe,{value:{reference:t.value}});let a=Xh(o,r);if(t.code==="_lastUpdated"||a.type===$h.DATETIME)return bn(vi,{children:Wh(t.value)})}return bn(vi,{children:t.value})}import{Checkbox as _h,TextInput as Rn}from"@mantine/core";import{getSearchParameterDetails as Kh,SearchParameterType as Xo}from"@medplum/core";import{jsx as go}from"react/jsx-runtime";function kr(e){let o=Kh(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case Xo.REFERENCE:return go(Go,{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 Xo.BOOLEAN:return go(_h,{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 Xo.DATE:return go(Rn,{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 Xo.DATETIME:return go(ke,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case Xo.NUMBER:return go(Rn,{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 Xo.QUANTITY:return go(ve,{name:t,defaultValue:Zh(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return go(Rn,{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 Zh(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as U,jsxs as Xe}from"react/jsx-runtime";function Pi(e){let[o,t]=Pn(JSON.parse(Ci(e.search))),[r,a]=Pn(-1),n=Ri(o);n.current=o,oy(()=>{t(JSON.parse(Ci(e.search)))},[e.search]);function l(u){t(Wo(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let f=e.search.resourceType,s=ey(f)??{},i=o.filters||[];return Xe(jh,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[U("div",{children:Xe("table",{children:[Xe("colgroup",{children:[U("col",{style:{width:200}}),U("col",{style:{width:200}}),U("col",{style:{width:380}}),U("col",{style:{width:120}})]}),U("thead",{children:Xe("tr",{children:[U("th",{children:"Field"}),U("th",{children:"Operation"}),U("th",{children:"Value"}),U("th",{children:"Actions"})]})}),Xe("tbody",{children:[i.map((u,c)=>c===r?U(bi,{resourceType:f,searchParams:s,defaultValue:u,okText:"Save",onOk:d=>{let m=[...i];m[c]=d,t(Bt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):U(ty,{resourceType:f,searchParams:s,filter:u,onEdit:()=>a(c),onDelete:()=>t(ai(n.current,c))},`filter-${u.code}-${u.operator}-${u.value}-display`)),U(bi,{resourceType:f,searchParams:s,okText:"Add",onOk:l})]})]})}),U(Yh,{position:"right",mt:"xl",children:U(Ft,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function ty(e){let{filter:o}=e;return Xe("tr",{children:[U("td",{children:Re(o.code)}),U("td",{children:At(o.operator)}),U("td",{children:U(Dr,{resourceType:e.resourceType,filter:o})}),Xe("td",{children:[U(Ft,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),U(Ft,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function bi(e){let[o,t]=Pn(e.defaultValue??{}),r=Ri(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 f=e.searchParams[o.code],s=f&&xi(f);return Xe("tr",{children:[U("td",{children:U(Si,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:i=>a(i.currentTarget.value),data:["",...Object.keys(e.searchParams).map(i=>({value:i,label:Re(i)}))]})}),U("td",{children:s&&U(Si,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:i=>n(i.currentTarget.value),data:["",...s.map(i=>({value:i,label:At(i)}))]})}),U("td",{children:f&&o.operator&&U(kr,{resourceType:e.resourceType,searchParam:f,defaultValue:o.value,onChange:l})}),Xe("td",{children:[o.code&&o.operator&&U(Ft,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&U(Ft,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as ry,Grid as Tn,Modal as ay}from"@mantine/core";import{useState as ny}from"react";import{jsx as Jo,jsxs as ly}from"react/jsx-runtime";function Ti(e){let[o,t]=ny(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return Jo(ay,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:Jo(X,{onSubmit:r,children:ly(Tn,{children:[Jo(Tn.Col,{span:10,children:Jo(kr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),Jo(Tn.Col,{span:2,children:Jo(ry,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as k}from"@mantine/core";import{Operator as te}from"@medplum/core";import{Fragment as ki,jsx as g,jsxs as $o}from"react/jsx-runtime";function Di(e){if(!e.searchParams)return null;function o(n,l){a(Cn(e.search,n.code,l))}function t(n){a(Tr(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?g(fy,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):g(k.Dropdown,{children:e.searchParams.map(n=>g(k.Item,{children:Re(n.code)},n.code))})}function fy(e){switch(e.searchParam.type){case"date":return g(sy,{...e});case"number":case"quantity":return g(iy,{...e});case"reference":return g(uy,{...e});case"string":case"token":case"uri":return g(cy,{...e});default:return $o(ki,{children:["Unknown search param type: ",e.searchParam.type]})}}function sy(e){let{searchParam:o}=e,t=o.code;return $o(k.Dropdown,{children:[g(k.Item,{icon:g(dt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),g(k.Item,{icon:g(mt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),g(k.Divider,{}),g(k.Item,{icon:g(Do,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Equals..."}),g(k.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,te.NOT_EQUALS),children:"Does not equal..."}),g(k.Divider,{}),g(k.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,te.ENDS_BEFORE),children:"Before..."}),g(k.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,te.STARTS_AFTER),children:"After..."}),g(k.Item,{icon:g(da,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Between..."}),g(k.Divider,{}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(fi(e.search,t)),children:"Tomorrow"}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(li(e.search,t)),children:"Today"}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(ni(e.search,t)),children:"Yesterday"}),g(k.Divider,{}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(ui(e.search,t)),children:"Next Month"}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(ii(e.search,t)),children:"This Month"}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(si(e.search,t)),children:"Last Month"}),g(k.Divider,{}),g(k.Item,{icon:g(qe,{size:14}),onClick:()=>e.onChange(ci(e.search,t)),children:"Year to date"}),g(Br,{...e})]})}function iy(e){let{searchParam:o}=e;return $o(k.Dropdown,{children:[g(k.Item,{icon:g(dt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),g(k.Item,{icon:g(mt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),g(k.Divider,{}),g(k.Item,{icon:g(Do,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Equals..."}),g(k.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,te.NOT_EQUALS),children:"Does not equal..."}),g(k.Divider,{}),g(k.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,te.GREATER_THAN),children:"Greater than..."}),g(k.Item,{icon:g(ko,{size:14}),onClick:()=>e.onPrompt(o,te.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),g(k.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,te.LESS_THAN),children:"Less than..."}),g(k.Item,{icon:g(ko,{size:14}),onClick:()=>e.onPrompt(o,te.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),g(Br,{...e})]})}function uy(e){let{searchParam:o}=e;return $o(k.Dropdown,{children:[g(k.Item,{icon:g(Do,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Equals..."}),g(k.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,te.NOT),children:"Does not equal..."}),g(Br,{...e})]})}function cy(e){let{searchParam:o}=e;return $o(k.Dropdown,{children:[g(k.Item,{icon:g(dt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),g(k.Item,{icon:g(mt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),g(k.Divider,{}),g(k.Item,{icon:g(Do,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Equals..."}),g(k.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,te.NOT),children:"Does not equal..."}),g(k.Divider,{}),g(k.Item,{icon:g(pa,{size:14}),onClick:()=>e.onPrompt(o,te.CONTAINS),children:"Contains..."}),g(k.Item,{icon:g(ma,{size:14}),onClick:()=>e.onPrompt(o,te.EQUALS),children:"Does not contain..."}),g(Br,{...e})]})}function Br(e){let{searchParam:o}=e,t=o.code;return $o(ki,{children:[g(k.Divider,{}),g(k.Item,{icon:g(ua,{size:14}),onClick:()=>e.onChange(Sn(e.search,t)),children:"Missing"}),g(k.Item,{icon:g(ia,{size:14}),onClick:()=>e.onChange(Sn(e.search,t,!1)),children:"Not missing"}),g(k.Divider,{}),g(k.Item,{icon:g(Ea,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as dy,getSearchParameter as my,getSearchParameterDetails as py,getSearchParameters as xy}from"@medplum/core";function Bi(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(Iy(o,r));return t}function Iy(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=dy(e,o),r=my(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=xy(e),n;if(a){let l=new RegExp(`${e}\\.${o.replaceAll("[x]","")}([^\\w-]|$)`);n=Object.values(a).filter(f=>!!f.expression&&l.test(f?.expression)),n.length===0&&(n=void 0)}return{name:o,elementDefinition:t,searchParams:n}}if(r){let a=py(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as wy,jsx as B,jsxs as ge}from"react/jsx-runtime";var Bn=class extends Event{constructor(t){super("change");this.definition=t}},An=class extends Event{constructor(t){super("load");this.response=t}},ho=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},Ty=hy(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 Dy(e){let{classes:o}=Ty(),t=P(),[r,a]=kn(!1),[n,l]=kn(),{search:f,onLoad:s}=e,[i,u]=kn({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),c=Py(i);c.current=i;let d=f.total??"accurate",m=Mi(R=>{l(void 0),t.search(f.resourceType,by({...f,total:d,fields:void 0}),R).then(H=>{u({...c.current,searchResponse:H}),s&&s(new An(H))}).catch(H=>{u({...c.current,searchResponse:void 0}),l(H)})},[t,f,d,s]),x=Mi(()=>{u({...c.current,searchResponse:void 0}),m({cache:"reload"})},[m]);Fi(()=>{m()},[m]);function p(R,H){R.stopPropagation();let ee=R.target.checked,Y={...c.current.selected};ee?Y[H]=!0:delete Y[H],u({...c.current,selected:Y})}function h(R){R.stopPropagation();let He=R.target.checked,ee={},Y=c.current.searchResponse;He&&Y?.entry&&Y.entry.forEach(he=>{he.resource?.id&&(ee[he.resource.id]=!0)}),u({...c.current,selected:ee})}function S(){let R=c.current;if(!R.searchResponse?.entry||R.searchResponse.entry.length===0)return!1;for(let H of R.searchResponse.entry)if(H.resource?.id&&!R.selected[H.resource.id])return!1;return!0}function y(R){e.onChange&&e.onChange(new Bn(R))}function b(R,H){if(Jt(R.target)||R.button===2)return;w(R);let He=R.button===1||R.ctrlKey||R.metaKey;!He&&e.onClick&&e.onClick(new ho(H,R)),He&&e.onAuxClick&&e.onAuxClick(new ho(H,R))}function E(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(Fi(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return B(Ar,{style:{width:"100%",height:"100%"},children:B(yy,{})});let C=e.checkboxesEnabled,M=Bi(f),K=f.resourceType,j=i.searchResponse,so=j?.entry?.map(R=>R.resource),ae="subtle",v="gray",N=16,Me=window.innerWidth<768;return ge("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&ge(Mr,{position:"apart",mb:"xl",children:[ge(Mr,{spacing:2,children:[B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(ga,{size:N}),onClick:()=>u({...c.current,fieldEditorVisible:!0}),children:"Fields"}),B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(ba,{size:N}),onClick:()=>u({...c.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(Ca,{size:N}),onClick:e.onNew,children:"New..."}),!Me&&E()&&B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(Oa,{size:N}),onClick:e.onExport?e.onExport:()=>u({...c.current,exportDialogVisible:!0}),children:"Export..."}),!Me&&e.onDelete&&B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(pt,{size:N}),onClick:()=>e.onDelete(Object.keys(i.selected)),children:"Delete..."}),!Me&&e.onBulk&&B(_o,{compact:!0,variant:ae,color:v,leftIcon:B(ca,{size:N}),onClick:()=>e.onBulk(Object.keys(i.selected)),children:"Bulk..."})]}),ge(Mr,{spacing:2,children:[j&&ge(Dn,{size:"xs",color:"dimmed",children:[My(f,j.total),"-",Fy(f,j.total)," of"," ",`${d==="estimate"?"~":""}${j.total?.toLocaleString()}`]}),B(gy,{title:"Refresh",onClick:x,children:B(Aa,{size:"1.125rem"})})]})]}),ge(Sy,{className:o.table,children:[ge("thead",{children:[ge("tr",{children:[C&&B("th",{children:B("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:S(),onChange:R=>h(R)})}),M.map(R=>B("th",{children:ge(Ai,{shadow:"md",width:240,position:"bottom-end",children:[B(Ai.Target,{children:B(Cy,{className:o.control,children:ge(Mr,{position:"apart",noWrap:!0,children:[B(Dn,{weight:500,size:"sm",children:Re(R.name)}),B(Ar,{className:o.icon,children:B(la,{size:14,stroke:1.5})})]})})}),B(Di,{search:e.search,searchParams:R.searchParams,onPrompt:(H,He)=>{u({...c.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:He})},onChange:H=>{y(H)}})]})},R.name))]}),!e.hideFilters&&ge("tr",{children:[C&&B("th",{}),M.map(R=>B("th",{children:R.searchParams&&B(ky,{resourceType:K,searchParams:R.searchParams,filters:e.search.filters})},R.name))]})]}),B("tbody",{children:so?.map(R=>R&&ge("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>b(H,R),onAuxClick:H=>b(H,R),children:[C&&B("td",{children:B("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${R.id}`,checked:!!i.selected[R.id],onChange:H=>p(H,R.id)})}),M.map(H=>B("td",{children:Ii(R,H)},H.name))]},R.id))})]}),so?.length===0&&B(oo,{children:B(Ar,{style:{height:150},children:B(Dn,{size:"xl",color:"dimmed",children:"No results"})})}),j?.total!==void 0&&j.total>0&&B(Ar,{m:"md",p:"md",children:B(vy,{value:By(f),total:Ay(f,j.total),onChange:R=>y(di(f,R)),getControlProps:R=>{switch(R){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&B("div",{"data-testid":"search-error",children:B("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),B(hi,{search:e.search,visible:c.current.fieldEditorVisible,onOk:R=>{y(R),u({...c.current,fieldEditorVisible:!1})},onCancel:()=>{u({...c.current,fieldEditorVisible:!1})}}),B(Pi,{search:e.search,visible:c.current.filterEditorVisible,onOk:R=>{y(R),u({...c.current,filterEditorVisible:!1})},onCancel:()=>{u({...c.current,filterEditorVisible:!1})}}),B(ti,{visible:c.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...c.current,exportDialogVisible:!1})}}),B(Ti,{visible:c.current.filterDialogVisible,title:i.filterDialogSearchParam?.code?Re(i.filterDialogSearchParam.code):"",resourceType:K,searchParam:i.filterDialogSearchParam,filter:i.filterDialogFilter,defaultValue:"",onOk:R=>{y(Wo(e.search,R.code,R.operator,R.value)),u({...c.current,filterDialogVisible:!1})},onCancel:()=>{u({...c.current,filterDialogVisible:!1})}},i.filterDialogSearchParam?.code)]})}var Q1=Ry(Dy);function ky(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?B("span",{children:"no filters"}):B(wy,{children:o.map(t=>ge("div",{children:[At(t.operator),"\xA0",B(Dr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function By(e){return Math.floor((e.offset??0)/(e.count??Mn))+1}function Ay(e,o){let t=e.count??Mn;return Math.ceil(o/t)}function My(e,o){return Math.min(o,(e.offset??0)+1)}function Fy(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??Mn))}import{jsx as pe,jsxs as wr}from"react/jsx-runtime";function Hy(e){let o=P(),[t,r]=Fr(!1),[a,n]=Fr(),{query:l,fields:f}=e,[s,i]=Fr(),[u,c]=Fr({}),d=Oi();d.current=s;let m=Oi({});m.current=u,wi(()=>{n(void 0),o.graphql(l).then(i).catch(b=>n(Ny(b)))},[o,l]);function x(b,E){b.stopPropagation();let M=b.target.checked,K={...m.current};M?K[E]=!0:delete K[E],c(K)}function p(b){b.stopPropagation();let C=b.target.checked,M={},K=d.current?.data.ResourceList;C&&K&&K.forEach(j=>{j.id&&(M[j.id]=!0)}),c(M)}function h(){let b=d.current?.data.ResourceList;if(!b||b.length===0)return!1;for(let E of b)if(E.id&&!m.current[E.id])return!1;return!0}function S(b,E){Jt(b.target)||(w(b),b.button!==1&&e.onClick&&e.onClick(new ho(E,b)),b.button===1&&e.onAuxClick&&e.onAuxClick(new ho(E,b)))}if(wi(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return pe(Ey,{});let y=e.checkboxesEnabled;return wr("div",{onContextMenu:b=>w(b),"data-testid":"search-control",children:[wr(Ly,{children:[pe("thead",{children:wr("tr",{children:[y&&pe("th",{children:pe("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:h(),onChange:b=>p(b)})}),f.map(b=>pe("th",{children:b.name},b.name))]})}),pe("tbody",{children:s?.data.ResourceList.map(b=>b&&wr("tr",{"data-testid":"search-control-row",onClick:E=>S(E,b),onAuxClick:E=>S(E,b),children:[y&&pe("td",{children:pe("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${b.id}`,checked:!!u[b.id],onChange:E=>x(E,b.id)})}),f.map(E=>pe("td",{children:pe(js,{propertyType:E.propertyType,path:E.fhirPath,resource:b})},E.name))]},b.id))})]}),s?.data.ResourceList.length===0&&pe("div",{"data-testid":"empty-search",children:"No results"}),a&&pe("div",{"data-testid":"search-error",children:pe("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&pe(Oy,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var oL=Vy(Hy);import{jsx as Ko,jsxs as qy}from"react/jsx-runtime";function no(e){return qy("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Ko("title",{children:"Medplum Logo"}),Ko("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Ko("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"}),Ko("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"}),Ko("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Ko("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as Xy,SimpleGrid as Jy}from"@mantine/core";import{Box as Ei,Flex as Fn,Group as Gy,Paper as Uy,RingProgress as Ni,Text as yo,Title as wn}from"@mantine/core";import{formatCodeableConcept as Li}from"@medplum/core";import{Fragment as Gi,jsx as Z,jsxs as wt}from"react/jsx-runtime";function Vi(e){let{group:o}=e;return Z(Uy,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:wt(Gy,{children:[o.measureScore&&Z(zy,{group:o}),!o.measureScore&&Z(Qy,{group:o})]})})}function Hi(e){let{measure:o}=e;return wt(Gi,{children:[Z(yo,{fz:"md",fw:500,mb:8,children:o.title}),Z(yo,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function Qy(e){let{group:o}=e,t=o.population,r=t?.find(s=>Li(s.code)==="numerator"),a=t?.find(s=>Li(s.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return wt(Ei,{children:[Z(wn,{order:3,children:"Not Applicable"}),Z(yo,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return wt(Ei,{children:[Z(wn,{order:3,children:"Insufficient Data"}),Z(yo,{children:`Numerator: ${n}`}),Z(yo,{children:`Denominator: ${l}`})]});let f=n/l*100;return Z(Ni,{size:120,thickness:12,roundCaps:!0,sections:[{value:f,color:qi(f)}],label:Z(Fn,{justify:"center",children:wt(yo,{fw:700,fz:18,children:[n," / ",l]})})})}function zy(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return Z(Gi,{children:t==="%"?Z(Ni,{size:120,thickness:12,roundCaps:!0,sections:[{value:Wy(o),color:qi(o?.measureScore?.value??0)}],label:Z(Fn,{justify:"center",children:Z(yo,{fw:700,fz:18,children:Z(Ye,{value:o.measureScore})})})}):Z(Fn,{h:120,align:"center",children:Z(wn,{order:3,children:Z(Ye,{value:o.measureScore})})})})}function Wy(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function qi(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as On,jsxs as $y}from"react/jsx-runtime";function pL(e){let o=Q(e.measureReport),[t]=xl("Measure",{url:o?.measure});return o?$y(Xy,{children:[t&&On(Hi,{measure:t}),On(Jy,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>On(Vi,{group:r},r.id??a))})]}):null}import{Alert as _y}from"@mantine/core";import{operationOutcomeIssueToString as Ky}from"@medplum/core";import{jsx as En}from"react/jsx-runtime";function Zo(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:En(_y,{icon:En(co,{size:16}),color:"red",children:o.map(t=>En("div",{"data-testid":"text-field-error",children:Ky(t)},t.details?.text))})}import{createReference as Or}from"@medplum/core";import{useCallback as Zy}from"react";import{jsx as Yy}from"react/jsx-runtime";function DL(e){let o=Zy((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 Yy(ao,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Or(t),sender:Or(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Or(t),operator:Or(r),issued:new Date().toISOString(),content:a})})}import{Anchor as Qi,Button as jy,createStyles as ev,NativeSelect as ov,Stack as tv,TextInput as Nn}from"@mantine/core";import{getReferenceString as rv}from"@medplum/core";import{useEffect as Ui,useRef as zi,useState as Ot}from"react";import{jsx as z,jsxs as Yo}from"react/jsx-runtime";var Wi=ev(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 XL(e){let o=P(),t=Q(e.value),[r,a]=Ot(!1),[n,l]=Ot(),[f,s]=Ot(),[i,u]=Ot();function c(){s(void 0)}function d(){l(void 0)}let m=zi();if(m.current=i,Ui(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),Ui(()=>(u(iv(t??{resourceType:"PlanDefinition"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]),!r||!i)return null;function x(p,h){u({...m.current,[p]:h})}return z("div",{children:Yo(X,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(i),children:[z(Nn,{label:"Plan Title",defaultValue:i.title,onChange:p=>x("title",p.currentTarget.value)}),z(Xi,{actions:i.action||[],selectedKey:n,setSelectedKey:l,hoverKey:f,setHoverKey:s,onChange:p=>x("action",p)}),z(jy,{type:"submit",children:"Save"})]})})}function Xi(e){let{classes:o}=Wi(),t=zi();t.current=e.actions;function r(l){e.onChange(t.current.map(f=>f.id===l.id?l:f))}function a(l){e.onChange([...t.current,l]),e.setSelectedKey(l.id)}function n(l){e.onChange(t.current.filter(f=>f!==l))}return Yo("div",{className:o.section,children:[e.actions.map(l=>z("div",{children:z(av,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),z("div",{className:o.bottomActions,children:z(Qi,{href:"#",onClick:l=>{w(l),a({id:$i()})},children:"Add action"})})]})}function av(e){let{classes:o,cx:t}=Wi(),{action:r}=e,a=sv(r),n=e.selectedKey===e.action.id,l=e.hoverKey===e.action.id;function f(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function s(u){w(u),e.setHoverKey(e.action.id)}let i=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return Yo("div",{"data-testid":r.id,className:i,onClick:f,onMouseOver:s,onFocus:s,children:[n?z(lv,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):z(nv,{action:r,actionType:a}),z("div",{className:o.bottomActions,children:z(Qi,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Vn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function nv(e){let{action:o,actionType:t}=e,[r,a]=Ji(o);return Yo("div",{children:[Yo("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&z("div",{children:z(Io,{value:{reference:o.definitionCanonical}})}),r&&z("div",{children:z(ne,{property:Vn,propertyType:a,value:r})})]})}function lv(e){let{action:o}=e,[t,r]=Ot(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return Yo(tv,{spacing:"xl",children:[z(Nn,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),z(Nn,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),z(ov,{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&&z(Xi,{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 z(Er,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return z(Er,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return z(Er,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return z(Er,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),z(se,{title:"Timing",description:"When the action should take place.",children:z(fv,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function Er(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return z(ir,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:rv(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function fv(e){let o=e.action,t="timing",[r,a]=Ji(o);return z(eo,{property:Vn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(yt(o,t,l??t,Vn,n))},outcome:void 0})}function sv(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function Ji(e){return je({type:"PlanDefinitionAction",value:e},"timing")}var Ln=1;function $i(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Ln=Math.max(Ln,o+1))}return e}return"id-"+Ln++}function iv(e){return{...e,action:_i(e.action)}}function _i(e){if(e)return e.map(o=>({...o,id:$i(o.id),action:_i(o.action)}))}import{Anchor as Pe,Box as Qn,Button as Vv,createStyles as Hv,Group as qv,NativeSelect as Gv,Space as Uv,Textarea as Qv,TextInput as zn,Title as zv}from"@mantine/core";import{getElementDefinition as Wv,isResource as Xv}from"@medplum/core";import{useEffect as cu,useRef as Jv,useState as Ur}from"react";import{Checkbox as Cv,Group as bv,MultiSelect as Rv,NativeSelect as Pv,Radio as nu,Textarea as Tv,TextInput as jo}from"@mantine/core";import{capitalize as Gn,deepEquals as Dv,formatCodeableConcept as kv,formatCoding as Gr,getElementDefinition as Bv,getTypedPropertyValue as lo,stringify as lu}from"@medplum/core";import{useContext as Av}from"react";import{deepClone as uv,evalFhirPathTyped as cv,formatCoding as dv,getExtension as Lr,getTypedPropertyValue as Hn,getReferenceString as mv,stringify as pv,splitN as xv}from"@medplum/core";var Nr=(S=>(S.group="group",S.display="display",S.question="question",S.boolean="boolean",S.decimal="decimal",S.integer="integer",S.date="date",S.dateTime="dateTime",S.time="time",S.string="string",S.text="text",S.url="url",S.choice="choice",S.openChoice="open-choice",S.attachment="attachment",S.reference="reference",S.quantity="quantity",S))(Nr||{});function Ki(e){return e.type==="choice"||e.type==="open-choice"}function Zi(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=ji(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=gv(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function Yi(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>dv(l.valueCoding)===r||l[o]===r),n=Hn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function ji(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=ji(t.item,o);if(r)return r}}}function Iv(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=cv(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function gv(e,o,t){let r=o||[],a=Hn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let f of r){let s=Hn({type:"QuestionnaireResponseItemAnswer",value:f},"value[x]"),{operator:i}=e;if(Iv(s,a,i)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function Vr(e){let o=Lr(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 Hr(e,o){let t=uv(e),r=Lr(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 eu(e,o,t){let r=Lr(e,"http://hl7.org/fhir/StructureDefinition/questionnaire-referenceFilter");if(!r?.valueString)return;let a=r.valueString;o?.reference&&(a=a.replaceAll("$subj",o.reference)),t?.reference&&(a=a.replaceAll("$encounter",t.reference));let n={},l=a.split("&");for(let f of l){let[s,i]=xv(f,"=",2);n[s]=i}return n}function ou(e){return{resourceType:"QuestionnaireResponse",questionnaire:mv(e),item:tu(e.item)}}function tu(e){return e?.map(qn)??[]}function qn(e){return{id:yv(),linkId:e.linkId,text:e.text,item:tu(e.item),answer:e.initial?.map(vv)??[]}}var hv=1;function yv(){return"id-"+hv++}function vv(e){return{...e}}function ru(e){return e.value.display||e.value.reference||pv(e.value)}function au(e){let o=e?.item?.[0];return o&&Lr(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as Sv}from"react";var qr=Sv({});import{jsx as W}from"react/jsx-runtime";function Et(e){let o=Av(qr),t=e.item,r=e.response;function a(i){let u;Array.isArray(i)?u=i:e.index>=(e.response?.answer?.length??0)?u=(e.response?.answer??[]).concat([i]):u=(e.response?.answer??[]).map((d,m)=>m===e.index?i:d)??[],e.onChange({id:r?.id,linkId:r?.linkId,text:t.text,answer:u})}let n=t.type;if(!n)return null;let l=t.linkId;if(!l)return null;let f=t.initial&&t.initial.length>0?t.initial[0]:void 0,s=Un(r,e.index)??lo({type:"QuestionnaireItemInitial",value:f},"value");switch(n){case"display":return W("p",{children:e.item.text},e.item.linkId);case"boolean":return W(ar,{title:e.item.text,htmlFor:e.item.linkId,children:W(Cv,{id:e.item.linkId,name:e.item.linkId,defaultChecked:s?.value,onChange:i=>a({valueBoolean:i.currentTarget.checked})})},e.item.linkId);case"decimal":return W(jo,{type:"number",step:"any",id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueDecimal:i.currentTarget.valueAsNumber})});case"integer":return W(jo,{type:"number",step:1,id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueInteger:i.currentTarget.valueAsNumber})});case"date":return W(jo,{type:"date",id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueDate:i.currentTarget.value})});case"dateTime":return W(ke,{name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueDateTime:i})});case"time":return W(jo,{type:"time",id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueTime:i.currentTarget.value})});case"string":case"url":return W(jo,{id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"text":return W(Tv,{id:l,name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueString:i.currentTarget.value})});case"attachment":return W(bv,{py:4,children:W(Zt,{name:l,defaultValue:s?.value,onChange:i=>a({valueAttachment:i})})});case"reference":return W(Go,{name:l,required:t.required,targetTypes:Vr(t),searchCriteria:eu(t,o.subject,o.encounter),defaultValue:s?.value,onChange:i=>a({valueReference:i})});case"quantity":return W(ve,{name:l,required:t.required,defaultValue:s?.value,onChange:i=>a({valueQuantity:i}),disableWheel:!0});case"choice":case"open-choice":return Lv(t)&&!t.answerValueSet?W(Mv,{name:l,item:t,initial:f,response:r,onChangeAnswer:i=>a(i)}):W(Fv,{name:l,item:t,initial:f,response:r,onChangeAnswer:i=>a(i)});default:return null}}function Mv(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return W(iu,{});let n=lo({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let s of t.answerOption){let i=lo({type:"QuestionnaireItemAnswerOption",value:s},"value");l.push(fu(i))}let f=Un(a)??n;if(t.repeats){let{propertyName:s,data:i}=Nv(e.item),u=Ov(a);return W(Rv,{data:i,placeholder:"Select items",searchable:!0,defaultValue:u||[fu(n)],onChange:c=>{let d=Yi(c,s,t);e.onChangeAnswer(d)}})}return W(Pv,{id:o,name:o,onChange:s=>{let i=s.currentTarget.selectedIndex;if(i===0){e.onChangeAnswer({});return}let u=t.answerOption[i-1],c=lo({type:"QuestionnaireItemAnswerOption",value:u},"value"),d="value"+Gn(c.type);e.onChangeAnswer({[d]:c.value})},defaultValue:Gr(f?.value)||f?.value,data:l})}function Fv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?W(iu,{}):t.answerValueSet?W(lr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):W(wv,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function wv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Bv("QuestionnaireItemAnswerOption","value[x]"),f=lo({type:"QuestionnaireItemInitial",value:r},"value"),s=[],i;if(t.answerOption)for(let d=0;d<t.answerOption.length;d++){let m=t.answerOption[d],x=`${o}-option-${d}`,p=lo({type:"QuestionnaireItemAnswerOption",value:m},"value");p?.value&&(f&&lu(p)===lu(f)&&(i=x),s.push([x,p]))}let u=Un(n),c=Ev(s,u);return W(nu.Group,{name:o,value:c??i,onChange:d=>{let m=s.find(x=>x[0]===d);if(m){let x=m[1],p="value"+Gn(x.type);a({[p]:x.value})}},children:s.map(([d,m])=>W(nu,{id:d,value:d,py:4,label:W(ne,{property:l,propertyType:m.type,value:m.value})},d))})}function iu(){return W(jo,{disabled:!0,placeholder:"No Answers Defined"})}function uu(e){return lo({type:"QuestionnaireItemAnswer",value:e},"value")}function Un(e,o=0){let t=e.answer;return uu(t?.[o]??{})}function Ov(e){let o=e.answer;return o?o.map(r=>uu(r)).map(r=>Gr(r?.value)||r?.value):[]}function Ev(e,o){return e.find(t=>Dv(t[1].value,o?.value))?.[0]}function fu(e){if(e)return e.type==="CodeableConcept"?kv(e.value):e.type==="Coding"?Gr(e.value):e.type==="Reference"?ru(e):e.value.toString()}function Lv(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Nv(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=lo({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+Gn(t.type),a=(e.answerOption??[]).map(n=>({value:su(n,r),label:su(n,r)}));return{propertyName:r,data:a}}function su(e,o){return Gr(e.valueCoding)||e[o]?.toString()}import{Fragment as et,jsx as F,jsxs as xe}from"react/jsx-runtime";var $v=Hv(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 A2(e){let o=P(),t=Q(e.questionnaire),[r,a]=Ur(!1),[n,l]=Ur(),[f,s]=Ur(),[i,u]=Ur();function c(){u(void 0)}function d(){s(void 0)}cu(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),cu(()=>(l(Yv(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]);let m=(x,p)=>{l(x),e.autoSave&&!p&&e.onSubmit&&e.onSubmit(x)};return!r||!n?null:F("div",{children:xe(X,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[F(du,{item:n,selectedKey:f,setSelectedKey:s,hoverKey:i,setHoverKey:u,onChange:m}),F(Vv,{type:"submit",children:"Save"})]})})}function du(e){let{classes:o,cx:t}=$v(),r=e.item,a=e.item,n=Xv(e.item),l=n||a.type==="group",f=a.linkId??"[untitled]",s=e.selectedKey===e.item.id,i=e.hoverKey===e.item.id,u=Jv();u.current=e.item;function c(C){w(C),e.setSelectedKey(e.item.id)}function d(C){w(C),e.setHoverKey(e.item.id)}function m(C){let M=u.current;e.onChange({...M,item:M.item?.map(K=>K.id===C.id?C:K)})}function x(C,M){e.onChange({...e.item,item:[...e.item.item??[],C]},M)}function p(C){e.onChange({...e.item,item:e.item.item?.filter(M=>M!==C)})}function h(C,M){e.onChange({...u.current,[C]:M})}function S(C){e.onChange({...e.item,...C})}function y(C){e.onChange({...e.item,item:e.item.item?.map(M=>M===C?{...M,repeats:!M.repeats}:M)})}function b(C,M){let K=oS(e.item.item,C,M);e.onChange({...e.item,item:K})}let E=t(o.section,{[o.editing]:s,[o.hovering]:i&&!s});return xe("div",{"data-testid":a.linkId,className:E,onClick:c,onMouseOver:d,onFocus:d,children:[F("div",{className:o.questionBody,children:s?xe(et,{children:[n&&F(zn,{size:"xl",defaultValue:r.title,onBlur:C=>h("title",C.currentTarget.value)}),!n&&F(Qv,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:C=>h("text",C.currentTarget.value)}),a.type==="reference"&&F(Zv,{item:a,onChange:S}),Ki(a)&&F(_v,{item:a,onChange:C=>S(C)})]}):xe(et,{children:[r.title&&F(zv,{children:r.title}),a.text&&F("div",{children:a.text}),!l&&F(Et,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((C,M)=>F("div",{children:F(du,{item:C,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:M===0,isLast:M===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>p(C),onRepeatable:y,onMoveUp:()=>b(M,-1),onMoveDown:()=>b(M,1)})},C.id)),!l&&F("div",{className:o.topActions,children:s?xe(et,{children:[F(zn,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:C=>h("linkId",C.currentTarget.value)}),!l&&F(Gv,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:C=>h("type",C.currentTarget.value),data:[{value:"display",label:"Display"},{value:"boolean",label:"Boolean"},{value:"decimal",label:"Decimal"},{value:"integer",label:"Integer"},{value:"date",label:"Date"},{value:"dateTime",label:"Date/Time"},{value:"time",label:"Time"},{value:"string",label:"String"},{value:"text",label:"Text"},{value:"url",label:"URL"},{value:"choice",label:"Choice"},{value:"open-choice",label:"Open Choice"},{value:"attachment",label:"Attachment"},{value:"reference",label:"Reference"},{value:"quantity",label:"Quantity"}]})]}):F("div",{children:f})}),!n&&F(Qn,{className:o.movementActions,children:xe(Qn,{className:o.columnAlignment,children:[!e.isFirst&&F(Pe,{href:"#",onClick:C=>{C.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:F(sa,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&F(Pe,{href:"#",onClick:C=>{C.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:F(fa,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),xe("div",{className:o.bottomActions,children:[l&&xe(et,{children:[F(Pe,{href:"#",onClick:C=>{C.preventDefault(),x({id:vo(),linkId:Jn("q"),type:"string",text:"Question"})},children:"Add item"}),F(Pe,{href:"#",onClick:C=>{C.preventDefault(),x({id:vo(),linkId:Jn("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&F(Pe,{href:"#",onClick:C=>{C.preventDefault(),x(eS(),!0)},children:"Add Page"}),s&&!n&&xe(et,{children:[F(Pe,{href:"#",onClick:C=>{C.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),F(Pe,{href:"#",onClick:C=>{C.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function _v(e){let o=Wv("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return xe("div",{children:[e.item.answerValueSet!==void 0?F(zn,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):F(Kv,{options:t,property:o,item:e.item,onChange:e.onChange}),xe(Qn,{display:"flex",children:[F(Pe,{href:"#",onClick:r=>{w(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:vo()}]})},children:"Add choice"}),F(Uv,{w:"lg"}),F(Pe,{href:"#",onClick:r=>{w(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Kv(e){return F("div",{children:e.options.map(o=>{let[t,r]=je({type:"QuestionnaireItemAnswerOption",value:o},"value");return xe("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[F("div",{children:F(eo,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let l=[...e.options],f=l.findIndex(s=>s.id===o.id);l[f]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:l})},outcome:void 0},o.id)}),F("div",{children:F(Pe,{href:"#",onClick:a=>{w(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Zv(e){let o=Vr(e.item)??[];return xe(et,{children:[o.map((t,r)=>xe(qv,{children:[F(Lo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(Hr(e.item,o.map(n=>n===t?a:n)))}}),F(Pe,{href:"#",onClick:a=>{w(a),e.onChange(Hr(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),F(Pe,{href:"#",onClick:t=>{w(t),e.onChange(Hr(e.item,[...o,""]))},children:"Add Resource Type"})]})}var Wn=1,Xn=1;function Jn(e){return e+Wn++}function vo(){return"id-"+Xn++}function Yv(e){return{...e,id:e.id||vo(),item:mu(e.item)}}function mu(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Xn=Math.max(Xn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(Wn=Math.max(Wn,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||vo(),item:mu(o.item),answerOption:jv(o.answerOption)}))}function jv(e){if(e)return e.map(o=>({...o,id:o.id||vo()}))}function eS(){return{id:vo(),linkId:Jn("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 oS(e,o,t){let r=e??[],a=o+t;if(a<0||a>=r.length)return r;let n=[...r];return[n[o],n[a]]=[n[a],n[o]],n}import{Title as xS}from"@mantine/core";import{createReference as IS,getReferenceString as gS}from"@medplum/core";import{useEffect as yu,useState as Kn}from"react";import{Button as _n,Group as cS,Stack as dS,Stepper as Iu}from"@mantine/core";import{Anchor as tS}from"@mantine/core";import{useState as rS}from"react";import{jsx as Qr,jsxs as nS}from"react/jsx-runtime";function zr(e){let{item:o,response:t,onChange:r}=e,[a,n]=rS(aS(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return Qr("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?Qr(Et,{item:o,response:t,onChange:f=>r([f]),index:0},o.linkId):nS(se,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((f,s)=>Qr(Et,{item:o,response:t,onChange:i=>r([i]),index:s},`${o.linkId}-${s}`)),l&&Qr(tS,{onClick:()=>n(f=>f+1),children:"Add Item"})]},e.item.linkId)}function aS(e,o){if(e.type==="choice"||e.type==="open-choice")return 1;let t=o.answer;return t?.length?t.length:1}import{Anchor as lS,Stack as fS,Title as sS}from"@mantine/core";import{useState as iS}from"react";import{Fragment as uS,jsx as So,jsxs as xu}from"react/jsx-runtime";function $n(e){let[o,t]=iS(e.response);if(o.length===0)return null;function r(n,l){let f=o.map((s,i)=>i===l?n[0]:s);t(f),e.onChange(f)}function a(){let n=qn(e.item);t([...o,n])}return xu(uS,{children:[o.map((n,l)=>So(pu,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:f=>r(f,l)},n.id)),e.item.repeats&&So(lS,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function pu(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let f=o.item?.map(i=>n.find(c=>c.id===i.id)??i)?.concat(n.slice(1)),s={...o,item:f};r([s])}return e.checkForQuestionEnabled(e.item)?xu("div",{children:[e.item.text&&So(sS,{order:3,mb:"md",children:e.item.text}),So(fS,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?So($n,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):So(pu,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):So(zr,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as pS,jsx as Je,jsxs as hu}from"react/jsx-runtime";function gu(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:l,numberOfPages:f,renderPages:s,submitButtonText:i,checkForQuestionEnabled:u}=e,c=o.map(d=>{let m=t?.item?.filter(p=>p.linkId===d.linkId)??[],x=d.type==="group"?Je($n,{item:d,response:m,onChange:a,checkForQuestionEnabled:u},d.linkId):Je(zr,{item:d,response:m?.[0],onChange:a,checkForQuestionEnabled:u},d.linkId);return s?Je(Iu.Step,{label:d.text,children:x},d.linkId):x});return hu(pS,{children:[s&&Je(Iu,{active:r??0,allowNextStepsSelect:!1,p:6,children:c}),!s&&Je(dS,{children:c}),Je(mS,{activePage:r??0,numberOfPages:f,nextStep:n,prevStep:l,submitButtonText:i})]})}function mS(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return hu(cS,{position:"right",mt:"xl",spacing:"xs",children:[o&&Je(_n,{onClick:e.prevStep,children:"Back"}),t&&Je(_n,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&Je(_n,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as Zn,jsxs as yS}from"react/jsx-runtime";function vu(e){let o=P(),t=o.getProfile(),[r,a]=Kn(!1),n=Q(e.questionnaire),[l,f]=Kn(),[s,i]=Kn(0);yu(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),yu(()=>{f(n?ou(n):void 0)},[n]);function u(p){let h=l?.item??[],y={resourceType:"QuestionnaireResponse",item:Su(h,Array.isArray(p)?p:[p])};f(y)}function c(p){return Zi(p,l?.item??[])}if(!r||!n)return null;let d=au(n),m=()=>i(p=>p+1),x=()=>i(p=>p-1);return Zn(qr.Provider,{value:{subject:e.subject,encounter:e.encounter},children:yS(X,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:gS(n),subject:e.subject,source:IS(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&Zn(xS,{children:n.title}),Zn(gu,{items:n.item??[],response:l,onChange:u,renderPages:d>1,activePage:s,numberOfPages:d,submitButtonText:e.submitButtonText,checkForQuestionEnabled:c,nextStep:m,prevStep:x})]})})}function hS(e,o){let t=Su(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 Su(e,o){let t=[],r=new Set;for(let a of e){let n=a.id,l=o.find(f=>f.id===n);l?(t.push(hS(a,l)),r.add(l.id)):t.push(a)}for(let a of o)r.has(a.id)||t.push(a);return t}import{ActionIcon as Wr,Button as vS,createStyles as SS,Divider as CS,Group as Lt,NativeSelect as Yn,Stack as Xr,Text as bS,TextInput as RS}from"@mantine/core";import{formatRange as Cu,getCodeBySystem as PS}from"@medplum/core";import{useEffect as TS,useState as jn}from"react";import{jsx as J,jsxs as ot}from"react/jsx-runtime";var DS=SS(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"}})),kS=["gender","age","gestationalAge","context","appliesTo","category"],BS={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function IN(e){e=Object.assign(BS,e);let o=e.definition,[t,r]=jn([]),[a,n]=jn(1),[l,f]=jn(1);return TS(()=>{let x=FS(o,f);r(wS(x.qualifiedInterval||[],n))},[o]),ot(X,{testid:"reference-range-editor",onSubmit:s,children:[J(Xr,{children:t.map(x=>J(AS,{unit:ES(o.quantitativeDetails?.unit),onChange:c,onAdd:d,onRemove:m,onRemoveGroup:u,intervalGroup:x},`group-${x.id}`))}),J(Wr,{title:"Add Group",size:"sm",onClick:x=>{w(x),i({id:`group-id-${a}`,filters:{},intervals:[]}),n(p=>p+1)},children:J(Ke,{})}),J(Lt,{position:"right",children:J(vS,{type:"submit",children:"Save"})})]});function s(){let x=t.flatMap(p=>p.intervals).filter(p=>!LS(p));e.onSubmit({...o,qualifiedInterval:x})}function i(x){r(p=>[...p,x])}function u(x){r(p=>p.filter(h=>h.id!==x.id))}function c(x,p){r(h=>{h=[...h];let S=h.find(b=>b.id===x),y=S?.intervals.findIndex(b=>b.id===p.id);return y!==void 0&&S?.intervals[y]&&(S.intervals[y]=p),h})}function d(x,p){p.id===void 0&&(p.id=`id-${l}`,f(h=>h+1)),r(h=>{h=[...h];let S=h.findIndex(y=>y.id===x);if(S!==-1){let y={...h[S]};p={...p,...y.filters},y.intervals=[...y.intervals,p],h[S]=y}return h})}function m(x,p){r(h=>{h=[...h];let S=h.find(y=>y.id===x);return S&&(S.intervals=S.intervals.filter(y=>y.id!==p.id)),h})}}function AS(e){let{intervalGroup:o,unit:t}=e,{classes:r}=DS();return J(oo,{"data-testid":o.id,className:r.section,children:ot(Xr,{spacing:"lg",children:[J(Lt,{position:"right",children:J(Wr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{w(a),e.onRemoveGroup(o)},children:J(Fe,{})},`remove-group-button-${o.id}`)}),J(MS,{intervalGroup:o,onChange:e.onChange}),J(CS,{}),o.intervals.map(a=>ot(Xr,{spacing:"xs",children:[ot(Lt,{children:[J(RS,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{w(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),J(Wr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{w(n),e.onRemove(o.id,a)},children:J(Fe,{})},`remove-interval-${a.id}`)]}),J(St,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),J(Wr,{title:"Add Interval",size:"sm",onClick:a=>{w(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:J(Ke,{})})]})})}function MS(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 ot(Xr,{style:{maxWidth:"50%"},children:[J(Lt,{children:J(Yn,{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})}}})}),ot(Lt,{spacing:"xs",children:[J(bS,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),J("div",{id:`div-age-${o.id}`,children:J(St,{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}`)})]}),J(Yn,{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"}]}})}}}),J(Yn,{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 FS(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 wS(e,o){let t=1,r={};for(let a of e){let n=OS(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(kS.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function OS(e){return[`gender=${e.gender}`,`age=${Cu(e.age)}`,`gestationalAge=${Cu(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function ES(e){return e&&(PS(e,"http://unitsofmeasure.org")||e.text)}function LS(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as bu,Grid as Jr,Text as NS}from"@mantine/core";import{formatDateTime as VS,getReferenceString as HS}from"@medplum/core";import{Fragment as qS,useEffect as GS,useState as Ru}from"react";import{jsx as Ne,jsxs as Nt}from"react/jsx-runtime";function TN(e){let o=P(),t=Q(e.value),[r,a]=Ru(!1),[n,l]=Ru();if(GS(()=>{t&&!r&&(o.executeBatch(f(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Ne(Jr,{children:t.action?.map((i,u)=>{let c=i.resource&&s(i.resource),d=c?.input?.[0]?.valueReference,m=c?.output?.[0]?.valueReference;return Nt(qS,{children:[Ne(Jr.Col,{span:1,p:"md",children:c?.status==="completed"?Ne(xa,{}):Ne(Fa,{color:"gray"})}),Nt(Jr.Col,{span:9,p:"xs",children:[Ne(NS,{weight:500,children:i.title}),i.description&&Ne("div",{children:i.description}),Nt("div",{children:["Last edited by\xA0",Ne(Oe,{value:c?.meta?.author}),"\xA0on\xA0",VS(c?.meta?.lastUpdated)]}),Nt("div",{children:["Status: ",Ne(Ir,{status:c?.status||"unknown"})]})]}),Nt(Jr.Col,{span:2,p:"md",children:[d&&!m&&Ne(bu,{onClick:()=>e.onStart(c,d),children:"Start"}),d&&m&&Ne(bu,{onClick:()=>e.onEdit(c,d,m),children:"Edit"})]})]},`action-${u}`)})});function f(i){let u=[];if(i.action)for(let c of i.action)c.resource?.reference&&u.push({request:{method:"GET",url:c.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function s(i){for(let u of n?.entry)if(u.resource&&i.reference===HS(u.resource))return u.resource}}import{createStyles as $S}from"@mantine/core";import{useEffect as _S,useState as KS}from"react";import{stringify as WS}from"@medplum/core";function $r(e,o){let t=US(e,o);return QS(t,e,o)}function US(e,o){let t=e.length,r=o.length,a=t+r+1,n=1+2*a,l=n/2|0,f=new Array(n);f[l+1]={i:0,j:-1,prev:void 0,snake:!0};for(let s=0;s<a;s++){for(let i=-s;i<=s;i+=2){let u=l+i,c=u+1,d=u-1,m=f[c],x=f[d],p,h=0;i===-s||i!==s&&x.i<m.i?(h=m.i,p=m):(h=x.i+1,p=x),f[d]=void 0;let S=h-i,y={i:h,j:S,prev:zS(p),snake:!1};for(;h<t&&S<r&&e[h]===o[S];)h++,S++;if(h>y.i&&(y={i:h,j:S,prev:y,snake:!0}),f[u]=y,h>=t&&S>=r)return f[u]}f[l+s-1]=void 0}}function QS(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 f=a.i,s=a.j,i={position:f,lines:o.slice(f,n)},u={position:s,lines:t.slice(s,l)},c;i.lines.length===0&&u.lines.length>0?c="insert":i.lines.length>0&&u.lines.length===0?c="delete":c="change",r.push({original:i,revised:u,type:c}),a.snake&&(a=a.prev)}return r}function zS(e){return e&&!e.snake&&e.prev?e.prev:e}function Pu(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:WS(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 XS(t,o),JS(t),t}function XS(e,o){for(let t=1;t<o.length;t++){let r=$r(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,l=a.original.lines,f=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,l.length),a.type==="insert"||a.type==="change")for(let s=0;s<a.revised.lines.length;s++)e.splice(n+s,0,{id:o[t].meta.versionId,meta:o[t].meta,value:f[s],span:1})}}}function JS(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 Tu(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Du(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return tt(t,"year");let r=Math.floor(o/2592e3);if(r>0)return tt(r,"month");let a=Math.floor(o/86400);if(a>0)return tt(a,"day");let n=Math.floor(o/3600);if(n>0)return tt(n,"hour");let l=Math.floor(o/60);return l>0?tt(l,"minute"):tt(o,"second")}function tt(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as YS,jsx as Ae,jsxs as ku}from"react/jsx-runtime";var ZS=$S(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 GN(e){let{classes:o}=ZS(),t=P(),[r,a]=KS(e.history);if(_S(()=>{!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 Ae("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Pu(r);return Ae("div",{className:o.container,children:Ae("table",{className:o.root,children:Ae("tbody",{children:l.map((f,s)=>ku("tr",{className:f.span>0?o.startRow:o.normalRow,children:[f.span>0&&ku(YS,{children:[Ae("td",{className:o.author,rowSpan:f.span,children:Ae(to,{value:f.meta.author,link:!0})}),Ae("td",{className:o.dateTime,rowSpan:f.span,children:Ae(oe,{to:Tu(n,f.meta.versionId),children:Du(f.meta.lastUpdated)})})]}),Ae("td",{className:o.lineNumber,children:s+1}),Ae("td",{className:o.line,children:Ae("pre",{className:o.pre,children:f.value})})]},"row-"+s))})})})}import{createStyles as jS}from"@mantine/core";import{stringify as Bu}from"@medplum/core";import{Fragment as tC,jsx as rt,jsxs as rC}from"react/jsx-runtime";var eC=jS(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function $N(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Bu(o,!0).match(/[^\r\n]+/g),a=Bu(t,!0).match(/[^\r\n]+/g),n=$r(r,a);return rt("pre",{style:{color:"gray"},children:n.map((l,f)=>rt(oC,{delta:l},"delta"+f))})}function oC(e){let{classes:o}=eC();return rC(tC,{children:["...",rt("br",{}),e.delta.original.lines.length>0&&rt("div",{className:o.removed,children:e.delta.original.lines.join(`
66
+ `)}),e.delta.revised.lines.length>0&&rt("div",{className:o.added,children:e.delta.revised.lines.join(`
67
+ `)}),"...",rt("br",{})]})}import{Button as Au,Group as aC,Stack as nC,TextInput as Mu}from"@mantine/core";import{deepClone as lC,tryGetProfile as fC}from"@medplum/core";import{useEffect as sC,useState as Fu}from"react";import{jsx as fo,jsxs as el}from"react/jsx-runtime";function aV(e){let{outcome:o}=e,t=P(),r=Q(e.defaultValue),[a,n]=Fu(),[l,f]=Fu();return sC(()=>{if(r)if(f(lC(r)),e.profileUrl){let s=e.profileUrl;t.requestProfileSchema(e.profileUrl).then(()=>{let i=fC(s);i?n(i.name):console.log(`Schema not found for ${s}`)}).catch(console.log)}else{let s=e.schemaName??r?.resourceType;t.requestSchema(s).then(()=>n(s)).catch(console.log)}},[t,r,e.schemaName,e.profileUrl]),!a||!l?fo("div",{children:"Loading..."}):el("form",{noValidate:!0,autoComplete:"off",onSubmit:s=>{s.preventDefault(),e.onSubmit&&e.onSubmit(l)},children:[el(nC,{mb:"xl",children:[fo(se,{title:"Resource Type",htmlFor:"resourceType",outcome:o,children:fo(Mu,{name:"resourceType",defaultValue:l.resourceType,disabled:!0})}),fo(se,{title:"ID",htmlFor:"id",outcome:o,children:fo(Mu,{name:"id",defaultValue:l.id,disabled:!0})})]}),fo(qo,{typeName:a,defaultValue:l,outcome:o,onChange:f,profileUrl:e.profileUrl}),el(aC,{position:"right",mt:"xl",children:[fo(Au,{type:"submit",children:"OK"}),e.onDelete&&fo(Au,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(l)},children:"Delete"})]})]})}import{Table as iC}from"@mantine/core";import{formatDateTime as uC,normalizeErrorString as cC}from"@medplum/core";import{useEffect as dC,useState as mC}from"react";import{jsx as Ie,jsxs as ol}from"react/jsx-runtime";function mV(e){let o=P(),[t,r]=mC(e.history);return dC(()=>{!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?ol(iC,{withBorder:!0,withColumnBorders:!0,children:[Ie("thead",{children:ol("tr",{children:[Ie("th",{children:"Author"}),Ie("th",{children:"Date"}),Ie("th",{children:"Version"})]})}),Ie("tbody",{children:t.entry?.map((a,n)=>Ie(pC,{entry:a},"entry-"+n))})]}):Ie("div",{children:"Loading..."})}function pC(e){let{response:o,resource:t}=e.entry;return t?ol("tr",{children:[Ie("td",{children:Ie(to,{value:t.meta?.author,link:!0})}),Ie("td",{children:uC(t.meta?.lastUpdated)}),Ie("td",{children:Ie(oe,{to:xC(t),children:t.meta?.versionId})})]}):Ie("tr",{children:Ie("td",{colSpan:3,children:cC(o?.outcome)})})}function xC(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as IC,createStyles as gC,Stack as hC,Text as yC}from"@mantine/core";import{getReferenceString as vC,isReference as SC}from"@medplum/core";import{useState as _r}from"react";import{jsx as ce,jsxs as at}from"react/jsx-runtime";var CC=gC(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function PV(e){let{classes:o}=CC(),t=Q(e.schedule),r=Q(e.questionnaire),[a,n]=_r(xr()),[l,f]=_r(),[s,i]=_r(),[u,c]=_r(),[d]=Il("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",SC(e.schedule)?e.schedule.reference:vC(e.schedule)],["start","gt"+bC(a)],["start","lt"+RC(a)]]));if(!t||!d||!r)return null;let m=t.actor?.[0];return at("div",{className:o.container,"data-testid":"scheduler",children:[at("div",{className:o.info,children:[m&&ce(fe,{value:m,size:"xl"}),m&&ce(yC,{size:"xl",weight:500,children:ce(Oe,{value:m})}),ce("p",{children:"1 hour"}),l&&ce("p",{children:l.toLocaleDateString()}),s&&ce("p",{children:wu(new Date(s.start))})]}),at("div",{className:o.selection,children:[!l&&at("div",{children:[ce("h3",{children:"Select date"}),ce(ms,{slots:d,onChangeMonth:n,onClick:f})]}),l&&!s&&at("div",{children:[ce("h3",{children:"Select time"}),ce(hC,{children:d.map(x=>{let p=new Date(x.start);return p.getTime()>l.getTime()&&p.getTime()<l.getTime()+24*3600*1e3&&ce("div",{children:ce(IC,{variant:"outline",style:{width:150},onClick:()=>i(x),children:wu(p)})},x.id)})})]}),l&&s&&!u&&ce(vu,{questionnaire:r,submitButtonText:"Next",onSubmit:c}),l&&s&&u&&at("div",{children:[ce("h3",{children:"You're all set!"}),ce("p",{children:"Check your email for a calendar invite."})]})]})]})}function bC(e){return Ou(e.getTime())}function RC(e){return Ou(e.getTime()+31*24*60*60*1e3)}function Ou(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function wu(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as Kr}from"@medplum/core";import{jsx as PC}from"react/jsx-runtime";function FV(e){return PC(ao,{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:[Kr(o)],subject:o.subject,sender:Kr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[Kr(o)],subject:o.subject,operator:Kr(t),issued:new Date().toISOString(),content:r})})}import{normalizeOperationOutcome as JC}from"@medplum/core";import{useEffect as $C,useState as Uu}from"react";import{Anchor as Eu,Button as TC,Center as DC,Group as kC,Stack as BC,Text as AC,TextInput as MC,Title as FC}from"@mantine/core";import{normalizeOperationOutcome as wC}from"@medplum/core";import{useState as OC}from"react";import{jsx as Co,jsxs as Zr}from"react/jsx-runtime";function Yr(e){let o=P(),[t,r]=OC();return Zr(X,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(wC(n))}},children:[Zr(DC,{sx:{flexDirection:"column"},children:[Co(no,{size:32}),Co(FC,{children:"Create project"})]}),Zr(BC,{spacing:"xl",children:[Co(MC,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:G(t,"firstName")}),Zr(AC,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",Co(Eu,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",Co(Eu,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),Co(kC,{position:"right",mt:"xl",noWrap:!0,children:Co(TC,{type:"submit",children:"Create project"})})]})}import{Anchor as ta,Button as VC,Center as HC,Checkbox as qC,Divider as GC,Group as Vu,PasswordInput as UC,Stack as QC,Text as Hu,TextInput as rl}from"@mantine/core";import{normalizeOperationOutcome as qu}from"@medplum/core";import{useEffect as zC,useState as WC}from"react";import{useEffect as EC,useRef as LC,useState as tl}from"react";function jr(e,o){let t=document.getElementsByTagName("head")[0],r=document.createElement("script");r.async=!0,r.src=e,r.onload=o??null,t.appendChild(r)}import{jsx as NC}from"react/jsx-runtime";function ea(e){let o=P(),{googleClientId:t,handleGoogleCredential:r}=e,a=LC(null),[n,l]=tl(typeof google<"u"),[f,s]=tl(!1),[i,u]=tl(!1);return EC(()=>{if(typeof google>"u"){jr("https://accounts.google.com/gsi/client",()=>l(!0));return}f||(google.accounts.id.initialize({client_id:t,callback:r}),s(!0)),a.current&&!i&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,f,n,a,i,r]),t?NC("div",{ref:a}):null}function oa(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 Lu(e){typeof grecaptcha>"u"&&jr("https://www.google.com/recaptcha/api.js?render="+e)}function Nu(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as XC,jsx as de,jsxs as nt}from"react/jsx-runtime";function Gu(e){let o=oa(e.googleClientId),t=e.recaptchaSiteKey,r=P(),[a,n]=WC(),l=nr(a,void 0);return zC(()=>{t&&Lu(t)},[t]),nt(X,{style:{maxWidth:400},onSubmit:async f=>{try{let s="";t&&(s=await Nu(t)),e.handleAuthResponse(await r.startNewUser({projectId:e.projectId,clientId:e.clientId,firstName:f.firstName,lastName:f.lastName,email:f.email,password:f.password,remember:f.remember==="true",recaptchaSiteKey:t,recaptchaToken:s}))}catch(s){n(qu(s))}},children:[de(HC,{sx:{flexDirection:"column"},children:e.children}),de(Zo,{issues:l}),o&&nt(XC,{children:[de(Vu,{position:"center",p:"xl",style:{height:70},children:de(ea,{googleClientId:o,handleGoogleCredential:async f=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:f.clientId,googleCredential:f.credential,createUser:!0}))}catch(s){n(qu(s))}}})}),de(GC,{label:"or",labelPosition:"center",my:"lg"})]}),nt(QC,{spacing:"xl",children:[de(rl,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:G(a,"firstName")}),de(rl,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:G(a,"lastName")}),de(rl,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:G(a,"email")}),de(UC,{name:"password",label:"Password",autoComplete:"off",required:!0,error:G(a,"password")}),nt(Hu,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",de(ta,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",de(ta,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),nt(Hu,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",de(ta,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",de(ta,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),nt(Vu,{position:"apart",mt:"xl",noWrap:!0,children:[de(qC,{name:"remember",label:"Remember me",size:"xs"}),de(VC,{type:"submit",children:"Create account"})]})]})}import{jsx as al,jsxs as _C}from"react/jsx-runtime";function bH(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,f=P(),[s,i]=Uu(),[u,c]=Uu();$C(()=>{o==="patient"&&s&&f.startNewPatient({login:s,projectId:t}).then(m=>f.processCode(m.code)).then(()=>l()).catch(m=>c(JC(m)))},[f,o,t,s,l]);function d(m){m.code?f.processCode(m.code).then(()=>l()).catch(console.log):m.login&&i(m.login)}return _C(br,{width:450,children:[u&&al("pre",{children:JSON.stringify(u,null,2)}),!s&&al(Gu,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:d,children:e.children}),s&&o==="project"&&al(Yr,{login:s,handleAuthResponse:d})]})}import{showNotification as tc}from"@mantine/notifications";import{normalizeErrorString as rc}from"@medplum/core";import{useCallback as ll,useEffect as Tb,useState as fl}from"react";import{Anchor as Qu,Button as zu,Center as Wu,Checkbox as KC,Divider as ZC,Group as nl,PasswordInput as YC,Stack as jC,TextInput as eb}from"@mantine/core";import{normalizeOperationOutcome as ob}from"@medplum/core";import{useCallback as ra,useState as Xu}from"react";import{Fragment as ab,jsx as re,jsxs as Vt}from"react/jsx-runtime";function Ju(e){let[o,t]=Xu();return o?re(rb,{email:o,...e}):re(tb,{setEmail:t,...e})}function tb(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,f=P(),s=!e.disableGoogleAuth&&oa(e.googleClientId),i=ra(async d=>{if(!d.authorizeUrl)return!1;let m=JSON.stringify({...await f.ensureCodeChallenge(l),domain:d.domain}),x=new URL(d.authorizeUrl);return x.searchParams.set("state",m),window.location.assign(x.toString()),!0},[f,l]),u=ra(async d=>{let m=await f.post("auth/method",{email:d.email});await i(m)||o(d.email)},[f,i,o]),c=ra(async d=>{let m=await f.startGoogleLogin({...l,googleCredential:d.credential});await i(m)||r(m)},[f,l,i,r]);return Vt(X,{style:{maxWidth:400},onSubmit:u,children:[re(Wu,{sx:{flexDirection:"column"},children:a}),s&&Vt(ab,{children:[re(nl,{position:"center",p:"xl",style:{height:70},children:re(ea,{googleClientId:s,handleGoogleCredential:c})}),!n&&re(ZC,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&re(eb,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Vt(nl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[re("div",{children:t&&re(Qu,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&re(zu,{type:"submit",children:"Next"})]})]})}function rb(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=P(),[l,f]=Xu(),s=nr(l,void 0),i=ra(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(c=>f(ob(c)))},[n,a,t]);return Vt(X,{style:{maxWidth:400},onSubmit:i,children:[re(Wu,{sx:{flexDirection:"column"},children:r}),re(Zo,{issues:s}),re(jC,{spacing:"xl",children:re(YC,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:G(l,"password")})}),Vt(nl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&re(Qu,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),re(KC,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),re(zu,{type:"submit",children:"Sign in"})]})]})}import{Avatar as nb,Center as lb,Group as fb,Stack as sb,Text as $u,Title as ib,UnstyledButton as ub}from"@mantine/core";import{normalizeOperationOutcome as cb}from"@medplum/core";import{useState as db}from"react";import{jsx as bo,jsxs as aa}from"react/jsx-runtime";function _u(e){let o=P(),[t,r]=db();return aa(sb,{children:[aa(lb,{sx:{flexDirection:"column"},children:[bo(no,{size:32}),bo(ib,{order:3,children:"Choose profile"})]}),bo(Zo,{outcome:t}),e.memberships.map(a=>bo(ub,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(cb(n)))},children:aa(fb,{children:[bo(nb,{radius:"xl"}),aa("div",{style:{flex:1},children:[bo($u,{size:"sm",weight:500,children:a.profile?.display}),bo($u,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as mb,Center as pb,Checkbox as xb,Group as Ib,Stack as Ku,Title as gb}from"@mantine/core";import{jsx as Ro,jsxs as Zu}from"react/jsx-runtime";function Yu(e){let o=P();return Ro(X,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:Zu(Ku,{children:[Zu(pb,{sx:{flexDirection:"column"},children:[Ro(no,{size:32}),Ro(gb,{children:"Choose scope"})]}),Ro(Ku,{children:(e.scope??"openid").split(" ").map(t=>Ro(xb,{id:t,name:t,label:t,defaultChecked:!0},t))}),Ro(Ib,{position:"right",mt:"xl",children:Ro(mb,{type:"submit",children:"Set scope"})})]})})}import{Alert as hb,Button as yb,Center as vb,Group as Sb,Stack as ju,TextInput as Cb,Title as bb}from"@mantine/core";import{normalizeErrorString as Rb}from"@medplum/core";import{useState as Pb}from"react";import{jsx as $e,jsxs as ec}from"react/jsx-runtime";function oc(e){let o=P(),[t,r]=Pb();return $e(X,{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(Rb(n)))},children:ec(ju,{children:[ec(vb,{sx:{flexDirection:"column"},children:[$e(no,{size:32}),$e(bb,{children:"Enter MFA code"})]}),t&&$e(hb,{icon:$e(co,{size:16}),title:"Error",color:"red",children:t}),$e(ju,{children:$e(Cb,{name:"token",label:"MFA code",required:!0})}),$e(Sb,{position:"right",mt:"xl",children:$e(yb,{type:"submit",children:"Submit code"})})]})})}import{jsx as Po}from"react/jsx-runtime";function Tq(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...f}=e,s=P(),[i,u]=fl(),[c,d]=fl(!1),[m,x]=fl(),p=ll(y=>{l?l(y):s.processCode(y).then(()=>{r&&r()}).catch(b=>tc({color:"red",message:rc(b)}))},[s,l,r]),h=ll(y=>{d(!!y.mfaRequired),y.login&&u(y.login),y.memberships&&x(y.memberships),y.code&&(t?x(void 0):p(y.code))},[t,p]),S=ll(y=>{p(y.code)},[p]);return Tb(()=>{o&&!i&&s.get("auth/login/"+o).then(h).catch(y=>tc({color:"red",message:rc(y)}))},[s,o,i,h]),Po(br,{width:450,children:i?c?Po(oc,{login:i,handleAuthResponse:h}):m?Po(_u,{login:i,memberships:m,handleAuthResponse:h}):e.projectId==="new"?Po(Yr,{login:i,handleAuthResponse:h}):e.chooseScopes?Po(Yu,{login:i,scope:e.scope,handleAuthResponse:S}):Po("div",{children:"Success"}):Po(Ju,{onForgotPassword:a,onRegister:n,handleAuthResponse:h,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...f,children:e.children})})}export{gl as AddressDisplay,Sl as AddressInput,Cl as AnnotationInput,Fk as AppShell,wo as AsyncAutocomplete,_l as AttachmentArrayDisplay,Zl as AttachmentArrayInput,No as AttachmentButton,we as AttachmentDisplay,Zt as AttachmentInput,ht as BackboneElementDisplay,qo as BackboneElementInput,ms as CalendarInput,ar as CheckboxFormSection,_t as CodeInput,Vo as CodeableConceptDisplay,xf as CodeableConceptInput,of as CodingDisplay,lr as CodingInput,tf as ContactDetailDisplay,hf as ContactDetailInput,er as ContactPointDisplay,fr as ContactPointInput,oo as Container,ke as DateTimeInput,KE as DefaultResourceTimeline,jl as DescriptionList,ef as DescriptionListEntry,on as DiagnosticReportDisplay,br as Document,SI as ElementDefinitionInputSelector,ur as ElementDefinitionTypeInput,s0 as EncounterTimeline,Bo as ErrorBoundary,Hy as FhirPathTable,X as Form,se as FormSection,Ql as Header,Xt as HumanNameDisplay,Pf as HumanNameInput,rf as IdentifierDisplay,kf as IdentifierInput,La as Loading,no as Logo,pL as MeasureReportDisplay,oe as MedplumLink,Mb as MedplumProvider,oL as MemoizedFhirPathTable,Q1 as MemoizedSearchControl,af as MoneyDisplay,Bf as MoneyInput,$l as Navbar,ug as ObservationTable,Zo as OperationOutcomeAlert,Uo as Panel,DL as PatientTimeline,XL as PlanDefinitionBuilder,Ye as QuantityDisplay,ve as QuantityInput,A2 as QuestionnaireBuilder,vu as QuestionnaireForm,Nr as QuestionnaireItemType,or as RangeDisplay,St as RangeInput,Io as ReferenceDisplay,Go as ReferenceInput,IN as ReferenceRangeEditor,AS as ReferenceRangeGroupEditor,bH as RegisterForm,TN as RequestGroupDisplay,uf as ResourceArrayDisplay,jf as ResourceArrayInput,fe as ResourceAvatar,to as ResourceBadge,GN as ResourceBlame,$N as ResourceDiff,aV as ResourceForm,mV as ResourceHistoryTable,ir as ResourceInput,Oe as ResourceName,ne as ResourcePropertyDisplay,eo as ResourcePropertyInput,pn as ResourceTable,ao as ResourceTimeline,PV as Scheduler,Bn as SearchChangeEvent,ho as SearchClickEvent,Dy as SearchControl,hi as SearchFieldEditor,Pi as SearchFilterEditor,An as SearchLoadEvent,FV as ServiceRequestTimeline,Tq as SignInForm,Ir as StatusBadge,Qs as Timeline,ro as TimelineItem,as as TimingInput,vn as addDateFilterBetween,P0 as addField,Wo as addFilter,si as addLastMonthFilter,Sn as addMissingFilter,ui as addNextMonthFilter,ii as addThisMonthFilter,li as addTodayFilter,fi as addTomorrowFilter,ci as addYearToDateFilter,ni as addYesterdayFilter,Re as buildFieldNameString,ou as buildInitialResponse,qn as buildInitialResponseItem,R0 as clearFilters,Tr as clearFiltersOnField,vf as convertIsoToLocal,Sf as convertLocalToIso,jr as createScriptTag,ai as deleteFilter,ru as formatReferenceString,G as getErrorsForInput,Bi as getFieldDefinitions,nr as getIssuesForExpression,Yi as getNewMultiSelectValues,au as getNumberOfPages,At as getOpString,eu as getQuestionnaireItemReferenceFilter,Vr as getQuestionnaireItemReferenceTargetTypes,Nu as getRecaptcha,xi as getSearchOperators,mi as getSortField,Lu as initRecaptcha,Ki as isChoiceQuestion,Zi as isQuestionEnabled,pi as isSortDescending,JA as isSupportedProfileStructureDefinition,zl as parseForm,ml as reactContext,Ii as renderValue,Bt as setFilters,kh as setOffset,di as setPage,yt as setPropertyValue,Hr as setQuestionnaireItemReferenceTargetTypes,Cn as setSort,Xs as sortByDateAndPriority,T0 as toggleSort,P as useMedplum,st as useMedplumContext,_e as useMedplumNavigate,Gt as useMedplumProfile,Q as useResource,Lb as useSearch,xl as useSearchOne,Il as useSearchResources};
68
68
  //# sourceMappingURL=index.mjs.map