@medplum/react 2.2.7 → 2.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/cjs/index.d.ts +5 -2
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/index.mjs.map +3 -3
- package/package.json +20 -20
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var cd=Object.create;var zl=Object.defineProperty;var dd=Object.getOwnPropertyDescriptor;var md=Object.getOwnPropertyNames;var pd=Object.getPrototypeOf,xd=Object.prototype.hasOwnProperty;var vt=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var Id=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of md(o))!xd.call(e,a)&&a!==t&&zl(e,a,{get:()=>o[a],enumerable:!(r=dd(o,a))||r.enumerable});return e};var gd=(e,o,t)=>(t=e!=null?cd(pd(e)):{},Id(o||!e||!e.__esModule?zl(t,"default",{value:e,enumerable:!0}):t,e));var wn=vt(Nr=>{"use strict";Object.defineProperty(Nr,"__esModule",{value:!0});Nr.Pointer=void 0;function ey(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function oy(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var ty=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(ey);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(oy).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}();Nr.Pointer=ty});var En=vt(Ke=>{"use strict";Object.defineProperty(Ke,"__esModule",{value:!0});Ke.clone=Ke.objectType=Ke.hasOwnProperty=void 0;Ke.hasOwnProperty=Object.prototype.hasOwnProperty;function ry(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ke.objectType=ry;function ay(e){return e!=null&&typeof e=="object"}function On(e){if(!ay(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=On(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var l in e)Ke.hasOwnProperty.call(e,l)&&(n[l]=On(e[l]));return n}Ke.clone=On});var Vn=vt(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.diffAny=ve.diffObjects=ve.diffArrays=ve.intersection=ve.subtract=ve.isDestructive=void 0;var Ut=En();function ny(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}ve.isDestructive=ny;function Nn(e,o){var t={};for(var r in e)Ut.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Ut.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}ve.subtract=Nn;function _s(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Ut.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)}ve.intersection=_s;function ly(e){return e.op==="add"}function fy(e){return e.op==="remove"}function Ln(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function Ks(e,o,t,r){r===void 0&&(r=Vr);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 p=[];if(u>0){var x=n(u-1,c),C={op:"remove",index:u-1};p.push(Ln(x,C))}if(c>0){var y=n(u,c-1),v={op:"add",index:u-1,value:o[c-1]};p.push(Ln(y,v))}if(u>0&&c>0){var b=n(u-1,c-1),P={op:"replace",index:u-1,original:e[u-1],value:o[c-1]};p.push(Ln(b,P))}var h=p.sort(function(B,W){return B.cost-W.cost})[0];m=h}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,i=n(l,f).operations,s=i.reduce(function(u,c){var d=u[0],m=u[1];if(ly(c)){var p=c.index+1+m,x=p<l+m?String(p):"-",C={op:c.op,path:t.add(x).toString(),value:c.value};return[d.concat(C),m+1]}else if(fy(c)){var C={op:c.op,path:t.add(String(c.index+m)).toString()};return[d.concat(C),m-1]}else{var y=t.add(String(c.index+m)),v=r(c.original,c.value,y);return[d.concat.apply(d,v),m]}},[[],0])[0];return s}ve.diffArrays=Ks;function Zs(e,o,t,r){r===void 0&&(r=Vr);var a=[];return Nn(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),Nn(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),_s([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}ve.diffObjects=Zs;function Vr(e,o,t,r){if(r===void 0&&(r=Vr),e===o)return[];var a=(0,Ut.objectType)(e),n=(0,Ut.objectType)(o);return a=="array"&&n=="array"?Ks(e,o,t,r):a=="object"&&n=="object"?Zs(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}ve.diffAny=Vr});var fi=vt(Z=>{"use strict";var Hn=Z&&Z.__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(Z,"__esModule",{value:!0});Z.apply=Z.InvalidOperationError=Z.test=Z.copy=Z.move=Z.replace=Z.remove=Z.add=Z.TestError=Z.MissingError=void 0;var Ze=wn(),qn=En(),sy=Vn(),Qe=function(e){Hn(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);Z.MissingError=Qe;var Ys=function(e){Hn(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);Z.TestError=Ys;function Gn(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 js(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function ei(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new Qe(o.path):(Gn(t.parent,t.key,(0,qn.clone)(o.value)),null)}Z.add=ei;function oi(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new Qe(o.path):(js(t.parent,t.key),null)}Z.remove=oi;function ti(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new Qe(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new Qe(o.path)}else if(t.value===void 0)return new Qe(o.path);return t.parent[t.key]=(0,qn.clone)(o.value),null}Z.replace=ti;function ri(e,o){var t=Ze.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Qe(o.from);var r=Ze.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Qe(o.path):(js(t.parent,t.key),Gn(r.parent,r.key,t.value),null)}Z.move=ri;function ai(e,o){var t=Ze.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Qe(o.from);var r=Ze.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Qe(o.path):(Gn(r.parent,r.key,(0,qn.clone)(t.value)),null)}Z.copy=ai;function ni(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return(0,sy.diffAny)(t.value,o.value,new Ze.Pointer).length?new Ys(t.value,o.value):null}Z.test=ni;var li=function(e){Hn(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);Z.InvalidOperationError=li;function iy(e,o){switch(o.op){case"add":return ei(e,o);case"remove":return oi(e,o);case"replace":return ti(e,o);case"move":return ri(e,o);case"copy":return ai(e,o);case"test":return ni(e,o)}return new li(o)}Z.apply=iy});var ii=vt(ze=>{"use strict";Object.defineProperty(ze,"__esModule",{value:!0});ze.createTests=ze.createPatch=ze.applyPatch=ze.Pointer=void 0;var Un=wn();Object.defineProperty(ze,"Pointer",{enumerable:!0,get:function(){return Un.Pointer}});var uy=fi(),Qn=Vn();function cy(e,o){return o.map(function(t){return(0,uy.apply)(e,t)})}ze.applyPatch=cy;function dy(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,Qn.diffAny)(t,r,a,o)}return o}function my(e,o,t){var r=new Un.Pointer;return(t?dy(t):Qn.diffAny)(e,o,r)}ze.createPatch=my;function si(e,o){var t=Un.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function py(e,o){var t=new Array;return o.filter(Qn.isDestructive).forEach(function(r){var a=si(e,r.path);if(a&&t.push(a),"from"in r){var n=si(e,r.from);n&&t.push(n)}}),t}ze.createTests=py});import{useEffect as Wl,useMemo as hd,useState as yd}from"react";import{createContext as vd,useContext as Sd}from"react";import{jsx as Cd}from"react/jsx-runtime";import{deepEquals as Rd,isReference as _l,isResource as Pd,normalizeOperationOutcome as Td}from"@medplum/core";import{useCallback as kd,useEffect as Xl,useState as Dd}from"react";import{allOk as Ad,normalizeOperationOutcome as Bd}from"@medplum/core";import{useEffect as Md,useState as ar}from"react";var $l=vd(void 0);function St(){return Sd($l)}function S(){return St().medplum}function no(){return St().navigate}function nr(){return St().profile}function CT(e){let o=e.medplum,t=e.navigate??bd,[r,a]=yd({profile:o.getProfile(),loading:!o.isInitialized});Wl(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),Wl(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=hd(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return Cd($l.Provider,{value:n,children:e.children})}function bd(e){window.location.assign(e)}function X(e,o){let t=S(),[r,a]=Dd(Jl(t,e)),n=kd(l=>{Rd(l,r)||a(l)},[r,a]);return Xl(()=>{n(Jl(t,e))},[t,e,n]),Xl(()=>{let l=!0;return _l(e)&&t.readReference(e).then(f=>{l&&n(f)}).catch(f=>{l&&(n(void 0),o&&o(Td(f)))}),()=>l=!1},[t,r,e,n,o]),r}function Jl(e,o){if(o){if(Pd(o))return o;if(_l(o))return e.getCachedReference(o)}}function kT(e,o){return Da("search",e,o)}function Kl(e,o){return Da("searchOne",e,o)}function Zl(e,o){return Da("searchResources",e,o)}function Da(e,o,t){let r=S(),[a,n]=ar(),[l,f]=ar(!1),[i,s]=ar(),[u,c]=ar();return Md(()=>{let d=r.fhirSearchUrl(o,t).toString();d!==a&&(n(d),r[e](o,t).then(m=>{f(!1),s(m),c(Ad)}).catch(m=>{f(!1),s(void 0),c(Bd(m))}))},[r,e,o,t,a,s]),[i,l,u]}import{formatAddress as Fd}from"@medplum/core";import{Fragment as wd,jsx as Od}from"react/jsx-runtime";function Yl(e){let o=e.value;return o?Od(wd,{children:Fd(o)}):null}import{Group as Ed,NativeSelect as jl,TextInput as Ct}from"@mantine/core";import{useRef as Ld,useState as Nd}from"react";import{jsx as ho,jsxs as Vd}from"react/jsx-runtime";function ef(e,o){return e.line&&e.line.length>o?e.line[o]:""}function of(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function tf(e){let[o,t]=Nd(e.defaultValue||{}),r=Ld();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(of(r.current||{},0,d))}function i(d){a(of(r.current||{},1,d))}function s(d){a({...r.current,city:d})}function u(d){a({...r.current,state:d})}function c(d){a({...r.current,postalCode:d})}return Vd(Ed,{spacing:"xs",grow:!0,noWrap:!0,children:[ho(jl,{"data-testid":"address-use",defaultValue:o.use,onChange:d=>n(d.currentTarget.value),data:["","home","work","temp","old","billing"]}),ho(jl,{"data-testid":"address-type",defaultValue:o.type,onChange:d=>l(d.currentTarget.value),data:["","postal","physical","both"]}),ho(Ct,{placeholder:"Line 1",defaultValue:ef(o,0),onChange:d=>f(d.currentTarget.value)}),ho(Ct,{placeholder:"Line 2",defaultValue:ef(o,1),onChange:d=>i(d.currentTarget.value)}),ho(Ct,{placeholder:"City",defaultValue:o.city,onChange:d=>s(d.currentTarget.value)}),ho(Ct,{placeholder:"State",defaultValue:o.state,onChange:d=>u(d.currentTarget.value)}),ho(Ct,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:d=>c(d.currentTarget.value)})]})}import{TextInput as Hd}from"@mantine/core";import{createReference as qd}from"@medplum/core";import{useRef as Gd,useState as Ud}from"react";import{jsx as Qd}from"react/jsx-runtime";function rf(e){let o=nr(),[t,r]=Ud(e.defaultValue||{}),a=Gd();a.current=t;function n(l){let f=l?{text:l,authorReference:o&&qd(o),time:new Date().toISOString()}:{};r(f),e.onChange&&e.onChange(f)}return Qd(Hd,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as Rp,useMantineTheme as Pp}from"@mantine/core";import{showNotification as Tp}from"@mantine/notifications";import{Suspense as kp,useEffect as Dp,useState as Ap}from"react";import{Alert as Kd}from"@mantine/core";import{normalizeErrorString as Zd}from"@medplum/core";import{forwardRef as zd,createElement as nf}from"react";import yo from"prop-types";var af={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 Wd=Object.defineProperty,Xd=Object.defineProperties,Jd=Object.getOwnPropertyDescriptors,lr=Object.getOwnPropertySymbols,sf=Object.prototype.hasOwnProperty,uf=Object.prototype.propertyIsEnumerable,lf=(e,o,t)=>o in e?Wd(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,ff=(e,o)=>{for(var t in o||(o={}))sf.call(o,t)&&lf(e,t,o[t]);if(lr)for(var t of lr(o))uf.call(o,t)&&lf(e,t,o[t]);return e},$d=(e,o)=>Xd(e,Jd(o)),_d=(e,o)=>{var t={};for(var r in e)sf.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&lr)for(var r of lr(e))o.indexOf(r)<0&&uf.call(e,r)&&(t[r]=e[r]);return t},I=(e,o,t)=>{let r=zd((a,n)=>{var l=a,{color:f="currentColor",size:i=24,stroke:s=2,children:u}=l,c=_d(l,["color","size","stroke","children"]);return nf("svg",ff($d(ff({ref:n},af),{width:i,height:i,stroke:f,strokeWidth:s,className:`tabler-icon tabler-icon-${e}`}),c),[...t.map(([d,m])=>nf(d,m)),...u||[]])});return r.propTypes={color:yo.string,size:yo.oneOfType([yo.string,yo.number]),stroke:yo.oneOfType([yo.string,yo.number])},r.displayName=`${o}`,r};var Aa=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 vo=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 Ba=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 Ma=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 Fa=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 wa=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 Oa=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 Ea=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 La=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 Na=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 $e=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 bt=I("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Va=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 Ha=I("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var lo=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 So=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 Rt=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 qa=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 Pt=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 Ga=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 Ua=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 Qa=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 Vo=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 Ho=I("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var fr=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 za=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 Wa=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 Xa=I("gender-female","IconGenderFemale",[["path",{d:"M12 9m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0",key:"svg-0"}],["path",{d:"M12 14v7",key:"svg-1"}],["path",{d:"M9 18h6",key:"svg-2"}]]);var Ja=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 $a=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 sr=I("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var ir=I("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var _a=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 Ka=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 Za=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 Ya=I("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var ja=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 en=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 qo=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 Tt=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 kt=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 on=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 tn=I("stethoscope","IconStethoscope",[["path",{d:"M6 4h-1a2 2 0 0 0 -2 2v3.5h0a5.5 5.5 0 0 0 11 0v-3.5a2 2 0 0 0 -2 -2h-1",key:"svg-0"}],["path",{d:"M8 15a6 6 0 1 0 12 0v-3",key:"svg-1"}],["path",{d:"M11 3v2",key:"svg-2"}],["path",{d:"M6 3v2",key:"svg-3"}],["path",{d:"M20 10m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-4"}]]);var rn=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 an=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 Dt=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 nn=I("user-square","IconUserSquare",[["path",{d:"M9 10a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-0"}],["path",{d:"M6 21v-1a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v1",key:"svg-1"}],["path",{d:"M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z",key:"svg-2"}]]);var ln=I("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Yd}from"react";import{jsx as cf}from"react/jsx-runtime";var Go=class extends Yd{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?cf(Kd,{icon:cf(vo,{size:16}),title:"Something went wrong",color:"red",children:Zd(this.state.error)}):this.props.children}};import{Center as jd,Loader as em}from"@mantine/core";import{jsx as df}from"react/jsx-runtime";function fn(){return df(jd,{style:{width:"100%",height:"100vh"},children:df(em,{})})}import{Avatar as Om,createStyles as Em,Group as dr,Header as Lm,Menu as _e,Stack as Nm,Text as Bt,UnstyledButton as bf}from"@mantine/core";import{formatHumanName as Vm,getReferenceString as Rf}from"@medplum/core";import{useState as Hm}from"react";import{formatHumanName as om}from"@medplum/core";import{Fragment as tm,jsx as rm}from"react/jsx-runtime";function ur(e){let o=e.value;return o?rm(tm,{children:om(o,e.options)}):null}import{Avatar as pf}from"@mantine/core";import{getDisplayString as dm,getImageSrc as mm}from"@medplum/core";import{Anchor as am}from"@mantine/core";import{isReference as nm,isResource as lm}from"@medplum/core";function M(e){e.preventDefault(),e.stopPropagation()}function cr(e){if(mf(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&mf(o[0]))return!0}return!1}function mf(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as cm}from"react/jsx-runtime";function le(e){let o=no(),{to:t,suffix:r,label:a,onClick:n,children:l,...f}=e,i=fm(t);return r&&(i+="/"+r),cm(am,{href:i,"aria-label":a,onClick:s=>{M(s),n?n(s):t&&o(i)},...f,children:l})}function fm(e){if(e){if(typeof e=="string")return sm(e);if(lm(e))return im(e);if(nm(e))return um(e)}return"#"}function sm(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function im(e){return`/${e.resourceType}/${e.id}`}function um(e){return`/${e.reference}`}import{jsx as sn}from"react/jsx-runtime";function fe(e){let o=X(e.value),t=o?dm(o):e.alt??"",r=(o&&mm(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?sn(le,{to:o,children:sn(pf,{src:r,alt:t,radius:a,...n})}):sn(pf,{src:r,alt:t,radius:a,...n})}import{createStyles as vm,Group as Sm,Text as If}from"@mantine/core";import{formatHumanName as Cm,getDisplayString as Sf,getReferenceString as bm,isUUID as Rm}from"@medplum/core";import{forwardRef as Pm,useCallback as gf}from"react";import{Loader as pm,MultiSelect as xm}from"@mantine/core";import{showNotification as Im}from"@mantine/notifications";import{normalizeErrorString as gm}from"@medplum/core";import{useCallback as Uo,useEffect as hm,useRef as Co,useState as At}from"react";import{jsx as xf}from"react/jsx-runtime";function Qo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:f,...i}=e,s=ym(o),u=Co(null),[c,d]=At(),[m,p]=At(),[x,C]=At(),[y,v]=At(s.map(r)),[b,P]=At([]),h=Co(),B=Co(),W=Co();W.current=c;let Y=Co();Y.current=m;let gt=Co();gt.current=x;let ke=Co();ke.current=b;let De=Uo(()=>{d(void 0);let ee=u.current?.value.trim()||"";if(ee===B.current&&a===h.current)return;B.current=ee,h.current=a;let ne=new AbortController;p(ne),a(ee,ne.signal).then(ue=>{ne.signal.aborted||(P(ue.map(r)),p(void 0),gt.current&&(ue.length>0&&n(ue.slice(0,1)),C(!1)))}).catch(ue=>{ne.signal.aborted||ue.message.includes("aborted")||Im({color:"red",message:gm(ue)})})},[a,n,r]),R=Uo(()=>{Y.current&&(Y.current.abort(),p(void 0)),W.current!==void 0&&window.clearTimeout(W.current);let ee=window.setTimeout(()=>De(),100);d(ee)},[De]),N=Uo(ee=>{let ne=[],ue=[];for(let ht of ee){let rr=ke.current?.find(ud=>ud.value===ht),yt=rr?.resource;!yt&&f!==!1&&l&&(yt=l(ht),rr=r(yt)),yt&&ne.push(yt),rr&&ue.push(rr)}n(ne),v(ue)},[f,n,l,r]),ao=Uo(ee=>{ee.key==="Enter"&&(!W.current&&!Y.current?(M(ee),ke.current&&ke.current.length>0&&(P(ke.current.slice(0,1)),N([ke.current[0].value]))):C(!0))},[N]),T=Uo(ee=>{let ne=r(l(ee));return P([...ke.current,ne]),ne},[l,P,r]),G=Uo((ee,ne)=>!ne,[]);return hm(()=>()=>{Y.current&&Y.current.abort()},[]),xf(xm,{...i,ref:u,defaultValue:s.map(t),searchable:!0,onKeyDown:ao,onSearchChange:R,data:[...y,...b],onFocus:De,onChange:N,onCreate:T,rightSectionWidth:40,rightSection:m?xf(pm,{size:16}):null,filter:G,creatable:!0,withinPortal:!0})}function ym(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as zo,jsxs as vf}from"react/jsx-runtime";var Tm=vm(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function km(e){return e.id}function Dm(e){return{value:e.id,label:Sf(e),resource:e}}function Cf(e){let{classes:o}=Tm(),t=no(),r=S(),a=gf(async(l,f)=>{let i=Bm(l),s={signal:f},u=await r.graphql(i,void 0,void 0,s);return Mm(u,l)},[r]),n=gf(l=>{l.length>0&&t(`/${bm(l[0])}`)},[t]);return zo(Qo,{size:"sm",radius:"md",className:o.searchInput,icon:zo(en,{size:16}),placeholder:"Search",itemComponent:Am,toKey:km,toOption:Dm,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var Am=Pm(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),zo("div",{ref:t,...o,children:vf(Sm,{noWrap:!0,children:[zo(fe,{value:e}),vf("div",{children:[zo(If,{children:Sf(e)}),zo(If,{size:"xs",color:"dimmed",children:r})]})]})})});function Bm(e){let o=JSON.stringify(e);return Rm(e)?`{
|
|
1
|
+
var cd=Object.create;var zl=Object.defineProperty;var dd=Object.getOwnPropertyDescriptor;var md=Object.getOwnPropertyNames;var pd=Object.getPrototypeOf,xd=Object.prototype.hasOwnProperty;var vt=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var Id=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of md(o))!xd.call(e,a)&&a!==t&&zl(e,a,{get:()=>o[a],enumerable:!(r=dd(o,a))||r.enumerable});return e};var gd=(e,o,t)=>(t=e!=null?cd(pd(e)):{},Id(o||!e||!e.__esModule?zl(t,"default",{value:e,enumerable:!0}):t,e));var wn=vt(Nr=>{"use strict";Object.defineProperty(Nr,"__esModule",{value:!0});Nr.Pointer=void 0;function ey(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function oy(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var ty=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(ey);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(oy).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}();Nr.Pointer=ty});var En=vt(Ke=>{"use strict";Object.defineProperty(Ke,"__esModule",{value:!0});Ke.clone=Ke.objectType=Ke.hasOwnProperty=void 0;Ke.hasOwnProperty=Object.prototype.hasOwnProperty;function ry(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ke.objectType=ry;function ay(e){return e!=null&&typeof e=="object"}function On(e){if(!ay(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=On(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var l in e)Ke.hasOwnProperty.call(e,l)&&(n[l]=On(e[l]));return n}Ke.clone=On});var Vn=vt(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.diffAny=ve.diffObjects=ve.diffArrays=ve.intersection=ve.subtract=ve.isDestructive=void 0;var Ut=En();function ny(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}ve.isDestructive=ny;function Nn(e,o){var t={};for(var r in e)Ut.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Ut.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}ve.subtract=Nn;function _s(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Ut.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)}ve.intersection=_s;function ly(e){return e.op==="add"}function fy(e){return e.op==="remove"}function Ln(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function Ks(e,o,t,r){r===void 0&&(r=Vr);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 p=[];if(u>0){var x=n(u-1,c),C={op:"remove",index:u-1};p.push(Ln(x,C))}if(c>0){var y=n(u,c-1),v={op:"add",index:u-1,value:o[c-1]};p.push(Ln(y,v))}if(u>0&&c>0){var b=n(u-1,c-1),P={op:"replace",index:u-1,original:e[u-1],value:o[c-1]};p.push(Ln(b,P))}var h=p.sort(function(A,W){return A.cost-W.cost})[0];m=h}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,i=n(l,f).operations,s=i.reduce(function(u,c){var d=u[0],m=u[1];if(ly(c)){var p=c.index+1+m,x=p<l+m?String(p):"-",C={op:c.op,path:t.add(x).toString(),value:c.value};return[d.concat(C),m+1]}else if(fy(c)){var C={op:c.op,path:t.add(String(c.index+m)).toString()};return[d.concat(C),m-1]}else{var y=t.add(String(c.index+m)),v=r(c.original,c.value,y);return[d.concat.apply(d,v),m]}},[[],0])[0];return s}ve.diffArrays=Ks;function Zs(e,o,t,r){r===void 0&&(r=Vr);var a=[];return Nn(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),Nn(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),_s([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}ve.diffObjects=Zs;function Vr(e,o,t,r){if(r===void 0&&(r=Vr),e===o)return[];var a=(0,Ut.objectType)(e),n=(0,Ut.objectType)(o);return a=="array"&&n=="array"?Ks(e,o,t,r):a=="object"&&n=="object"?Zs(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}ve.diffAny=Vr});var fi=vt(Z=>{"use strict";var Hn=Z&&Z.__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(Z,"__esModule",{value:!0});Z.apply=Z.InvalidOperationError=Z.test=Z.copy=Z.move=Z.replace=Z.remove=Z.add=Z.TestError=Z.MissingError=void 0;var Ze=wn(),qn=En(),sy=Vn(),Qe=function(e){Hn(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);Z.MissingError=Qe;var Ys=function(e){Hn(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);Z.TestError=Ys;function Gn(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 js(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function ei(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new Qe(o.path):(Gn(t.parent,t.key,(0,qn.clone)(o.value)),null)}Z.add=ei;function oi(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new Qe(o.path):(js(t.parent,t.key),null)}Z.remove=oi;function ti(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new Qe(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new Qe(o.path)}else if(t.value===void 0)return new Qe(o.path);return t.parent[t.key]=(0,qn.clone)(o.value),null}Z.replace=ti;function ri(e,o){var t=Ze.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Qe(o.from);var r=Ze.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Qe(o.path):(js(t.parent,t.key),Gn(r.parent,r.key,t.value),null)}Z.move=ri;function ai(e,o){var t=Ze.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new Qe(o.from);var r=Ze.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new Qe(o.path):(Gn(r.parent,r.key,(0,qn.clone)(t.value)),null)}Z.copy=ai;function ni(e,o){var t=Ze.Pointer.fromJSON(o.path).evaluate(e);return(0,sy.diffAny)(t.value,o.value,new Ze.Pointer).length?new Ys(t.value,o.value):null}Z.test=ni;var li=function(e){Hn(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);Z.InvalidOperationError=li;function iy(e,o){switch(o.op){case"add":return ei(e,o);case"remove":return oi(e,o);case"replace":return ti(e,o);case"move":return ri(e,o);case"copy":return ai(e,o);case"test":return ni(e,o)}return new li(o)}Z.apply=iy});var ii=vt(ze=>{"use strict";Object.defineProperty(ze,"__esModule",{value:!0});ze.createTests=ze.createPatch=ze.applyPatch=ze.Pointer=void 0;var Un=wn();Object.defineProperty(ze,"Pointer",{enumerable:!0,get:function(){return Un.Pointer}});var uy=fi(),Qn=Vn();function cy(e,o){return o.map(function(t){return(0,uy.apply)(e,t)})}ze.applyPatch=cy;function dy(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,Qn.diffAny)(t,r,a,o)}return o}function my(e,o,t){var r=new Un.Pointer;return(t?dy(t):Qn.diffAny)(e,o,r)}ze.createPatch=my;function si(e,o){var t=Un.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function py(e,o){var t=new Array;return o.filter(Qn.isDestructive).forEach(function(r){var a=si(e,r.path);if(a&&t.push(a),"from"in r){var n=si(e,r.from);n&&t.push(n)}}),t}ze.createTests=py});import{useEffect as Wl,useMemo as hd,useState as yd}from"react";import{createContext as vd,useContext as Sd}from"react";import{jsx as Cd}from"react/jsx-runtime";import{deepEquals as Rd,isReference as _l,isResource as Pd,normalizeOperationOutcome as Td}from"@medplum/core";import{useCallback as kd,useEffect as Xl,useState as Dd}from"react";import{allOk as Bd,normalizeOperationOutcome as Ad}from"@medplum/core";import{useEffect as Md,useState as ar}from"react";var $l=vd(void 0);function St(){return Sd($l)}function S(){return St().medplum}function no(){return St().navigate}function nr(){return St().profile}function CT(e){let o=e.medplum,t=e.navigate??bd,[r,a]=yd({profile:o.getProfile(),loading:!o.isInitialized});Wl(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),Wl(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=hd(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return Cd($l.Provider,{value:n,children:e.children})}function bd(e){window.location.assign(e)}function X(e,o){let t=S(),[r,a]=Dd(Jl(t,e)),n=kd(l=>{Rd(l,r)||a(l)},[r,a]);return Xl(()=>{n(Jl(t,e))},[t,e,n]),Xl(()=>{let l=!0;return _l(e)&&t.readReference(e).then(f=>{l&&n(f)}).catch(f=>{l&&(n(void 0),o&&o(Td(f)))}),()=>l=!1},[t,r,e,n,o]),r}function Jl(e,o){if(o){if(Pd(o))return o;if(_l(o))return e.getCachedReference(o)}}function kT(e,o){return Da("search",e,o)}function Kl(e,o){return Da("searchOne",e,o)}function Zl(e,o){return Da("searchResources",e,o)}function Da(e,o,t){let r=S(),[a,n]=ar(),[l,f]=ar(!1),[i,s]=ar(),[u,c]=ar();return Md(()=>{let d=r.fhirSearchUrl(o,t).toString();d!==a&&(n(d),r[e](o,t).then(m=>{f(!1),s(m),c(Bd)}).catch(m=>{f(!1),s(void 0),c(Ad(m))}))},[r,e,o,t,a,s]),[i,l,u]}import{formatAddress as Fd}from"@medplum/core";import{Fragment as wd,jsx as Od}from"react/jsx-runtime";function Yl(e){let o=e.value;return o?Od(wd,{children:Fd(o)}):null}import{Group as Ed,NativeSelect as jl,TextInput as Ct}from"@mantine/core";import{useRef as Ld,useState as Nd}from"react";import{jsx as ho,jsxs as Vd}from"react/jsx-runtime";function ef(e,o){return e.line&&e.line.length>o?e.line[o]:""}function of(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function tf(e){let[o,t]=Nd(e.defaultValue||{}),r=Ld();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(of(r.current||{},0,d))}function i(d){a(of(r.current||{},1,d))}function s(d){a({...r.current,city:d})}function u(d){a({...r.current,state:d})}function c(d){a({...r.current,postalCode:d})}return Vd(Ed,{spacing:"xs",grow:!0,noWrap:!0,children:[ho(jl,{"data-testid":"address-use",defaultValue:o.use,onChange:d=>n(d.currentTarget.value),data:["","home","work","temp","old","billing"]}),ho(jl,{"data-testid":"address-type",defaultValue:o.type,onChange:d=>l(d.currentTarget.value),data:["","postal","physical","both"]}),ho(Ct,{placeholder:"Line 1",defaultValue:ef(o,0),onChange:d=>f(d.currentTarget.value)}),ho(Ct,{placeholder:"Line 2",defaultValue:ef(o,1),onChange:d=>i(d.currentTarget.value)}),ho(Ct,{placeholder:"City",defaultValue:o.city,onChange:d=>s(d.currentTarget.value)}),ho(Ct,{placeholder:"State",defaultValue:o.state,onChange:d=>u(d.currentTarget.value)}),ho(Ct,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:d=>c(d.currentTarget.value)})]})}import{TextInput as Hd}from"@mantine/core";import{createReference as qd}from"@medplum/core";import{useRef as Gd,useState as Ud}from"react";import{jsx as Qd}from"react/jsx-runtime";function rf(e){let o=nr(),[t,r]=Ud(e.defaultValue||{}),a=Gd();a.current=t;function n(l){let f=l?{text:l,authorReference:o&&qd(o),time:new Date().toISOString()}:{};r(f),e.onChange&&e.onChange(f)}return Qd(Hd,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as Rp,useMantineTheme as Pp}from"@mantine/core";import{showNotification as Tp}from"@mantine/notifications";import{Suspense as kp,useEffect as Dp,useState as Bp}from"react";import{Alert as Kd}from"@mantine/core";import{normalizeErrorString as Zd}from"@medplum/core";import{forwardRef as zd,createElement as nf}from"react";import yo from"prop-types";var af={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 Wd=Object.defineProperty,Xd=Object.defineProperties,Jd=Object.getOwnPropertyDescriptors,lr=Object.getOwnPropertySymbols,sf=Object.prototype.hasOwnProperty,uf=Object.prototype.propertyIsEnumerable,lf=(e,o,t)=>o in e?Wd(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,ff=(e,o)=>{for(var t in o||(o={}))sf.call(o,t)&&lf(e,t,o[t]);if(lr)for(var t of lr(o))uf.call(o,t)&&lf(e,t,o[t]);return e},$d=(e,o)=>Xd(e,Jd(o)),_d=(e,o)=>{var t={};for(var r in e)sf.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&lr)for(var r of lr(e))o.indexOf(r)<0&&uf.call(e,r)&&(t[r]=e[r]);return t},I=(e,o,t)=>{let r=zd((a,n)=>{var l=a,{color:f="currentColor",size:i=24,stroke:s=2,children:u}=l,c=_d(l,["color","size","stroke","children"]);return nf("svg",ff($d(ff({ref:n},af),{width:i,height:i,stroke:f,strokeWidth:s,className:`tabler-icon tabler-icon-${e}`}),c),[...t.map(([d,m])=>nf(d,m)),...u||[]])});return r.propTypes={color:yo.string,size:yo.oneOfType([yo.string,yo.number]),stroke:yo.oneOfType([yo.string,yo.number])},r.displayName=`${o}`,r};var Ba=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 vo=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 Aa=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 Ma=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 Fa=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 wa=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 Oa=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 Ea=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 La=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 Na=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 $e=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 bt=I("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Va=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 Ha=I("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var lo=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 So=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 Rt=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 qa=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 Pt=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 Ga=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 Ua=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 Qa=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 Vo=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 Ho=I("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var fr=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 za=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 Wa=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 Xa=I("gender-female","IconGenderFemale",[["path",{d:"M12 9m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0",key:"svg-0"}],["path",{d:"M12 14v7",key:"svg-1"}],["path",{d:"M9 18h6",key:"svg-2"}]]);var Ja=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 $a=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 sr=I("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var ir=I("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var _a=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 Ka=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 Za=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 Ya=I("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var ja=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 en=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 qo=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 Tt=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 kt=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 on=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 tn=I("stethoscope","IconStethoscope",[["path",{d:"M6 4h-1a2 2 0 0 0 -2 2v3.5h0a5.5 5.5 0 0 0 11 0v-3.5a2 2 0 0 0 -2 -2h-1",key:"svg-0"}],["path",{d:"M8 15a6 6 0 1 0 12 0v-3",key:"svg-1"}],["path",{d:"M11 3v2",key:"svg-2"}],["path",{d:"M6 3v2",key:"svg-3"}],["path",{d:"M20 10m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-4"}]]);var rn=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 an=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 Dt=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 nn=I("user-square","IconUserSquare",[["path",{d:"M9 10a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-0"}],["path",{d:"M6 21v-1a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v1",key:"svg-1"}],["path",{d:"M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z",key:"svg-2"}]]);var ln=I("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Yd}from"react";import{jsx as cf}from"react/jsx-runtime";var Go=class extends Yd{constructor(o){super(o),this.state={lastLocation:window.location.toString()}}static getDerivedStateFromError(o){return{error:o,lastLocation:window.location.toString()}}componentDidUpdate(o,t){window.location.toString()!==this.state.lastLocation&&this.setState({lastLocation:window.location.toString(),error:void 0})}shouldComponentUpdate(o,t){return!!(this.props.children!==o.children||t.error&&!this.state.error||this.state.lastLocation!==window.location.toString())}componentDidCatch(o,t){console.error("Uncaught error:",o,t)}render(){return this.state.error?cf(Kd,{icon:cf(vo,{size:16}),title:"Something went wrong",color:"red",children:Zd(this.state.error)}):this.props.children}};import{Center as jd,Loader as em}from"@mantine/core";import{jsx as df}from"react/jsx-runtime";function fn(){return df(jd,{style:{width:"100%",height:"100vh"},children:df(em,{})})}import{Avatar as Om,createStyles as Em,Group as dr,Header as Lm,Menu as _e,Stack as Nm,Text as At,UnstyledButton as bf}from"@mantine/core";import{formatHumanName as Vm,getReferenceString as Rf}from"@medplum/core";import{useState as Hm}from"react";import{formatHumanName as om}from"@medplum/core";import{Fragment as tm,jsx as rm}from"react/jsx-runtime";function ur(e){let o=e.value;return o?rm(tm,{children:om(o,e.options)}):null}import{Avatar as pf}from"@mantine/core";import{getDisplayString as dm,getImageSrc as mm}from"@medplum/core";import{Anchor as am}from"@mantine/core";import{isReference as nm,isResource as lm}from"@medplum/core";function M(e){e.preventDefault(),e.stopPropagation()}function cr(e){if(mf(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&mf(o[0]))return!0}return!1}function mf(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as cm}from"react/jsx-runtime";function le(e){let o=no(),{to:t,suffix:r,label:a,onClick:n,children:l,...f}=e,i=fm(t);return r&&(i+="/"+r),cm(am,{href:i,"aria-label":a,onClick:s=>{M(s),n?n(s):t&&o(i)},...f,children:l})}function fm(e){if(e){if(typeof e=="string")return sm(e);if(lm(e))return im(e);if(nm(e))return um(e)}return"#"}function sm(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function im(e){return`/${e.resourceType}/${e.id}`}function um(e){return`/${e.reference}`}import{jsx as sn}from"react/jsx-runtime";function fe(e){let o=X(e.value),t=o?dm(o):e.alt??"",r=(o&&mm(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?sn(le,{to:o,children:sn(pf,{src:r,alt:t,radius:a,...n})}):sn(pf,{src:r,alt:t,radius:a,...n})}import{createStyles as vm,Group as Sm,Text as If}from"@mantine/core";import{formatHumanName as Cm,getDisplayString as Sf,getReferenceString as bm,isUUID as Rm}from"@medplum/core";import{forwardRef as Pm,useCallback as gf}from"react";import{Loader as pm,MultiSelect as xm}from"@mantine/core";import{showNotification as Im}from"@mantine/notifications";import{normalizeErrorString as gm}from"@medplum/core";import{useCallback as Uo,useEffect as hm,useRef as Co,useState as Bt}from"react";import{jsx as xf}from"react/jsx-runtime";function Qo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:f,...i}=e,s=ym(o),u=Co(null),[c,d]=Bt(),[m,p]=Bt(),[x,C]=Bt(),[y,v]=Bt(s.map(r)),[b,P]=Bt([]),h=Co(),A=Co(),W=Co();W.current=c;let Y=Co();Y.current=m;let gt=Co();gt.current=x;let ke=Co();ke.current=b;let De=Uo(()=>{d(void 0);let ee=u.current?.value.trim()||"";if(ee===A.current&&a===h.current)return;A.current=ee,h.current=a;let ne=new AbortController;p(ne),a(ee,ne.signal).then(ue=>{ne.signal.aborted||(P(ue.map(r)),p(void 0),gt.current&&(ue.length>0&&n(ue.slice(0,1)),C(!1)))}).catch(ue=>{ne.signal.aborted||ue.message.includes("aborted")||Im({color:"red",message:gm(ue)})})},[a,n,r]),R=Uo(()=>{Y.current&&(Y.current.abort(),p(void 0)),W.current!==void 0&&window.clearTimeout(W.current);let ee=window.setTimeout(()=>De(),100);d(ee)},[De]),N=Uo(ee=>{let ne=[],ue=[];for(let ht of ee){let rr=ke.current?.find(ud=>ud.value===ht),yt=rr?.resource;!yt&&f!==!1&&l&&(yt=l(ht),rr=r(yt)),yt&&ne.push(yt),rr&&ue.push(rr)}n(ne),v(ue)},[f,n,l,r]),ao=Uo(ee=>{ee.key==="Enter"&&(!W.current&&!Y.current?(M(ee),ke.current&&ke.current.length>0&&(P(ke.current.slice(0,1)),N([ke.current[0].value]))):C(!0))},[N]),T=Uo(ee=>{let ne=r(l(ee));return P([...ke.current,ne]),ne},[l,P,r]),G=Uo((ee,ne)=>!ne,[]);return hm(()=>()=>{Y.current&&Y.current.abort()},[]),xf(xm,{...i,ref:u,defaultValue:s.map(t),searchable:!0,onKeyDown:ao,onSearchChange:R,data:[...y,...b],onFocus:De,onChange:N,onCreate:T,rightSectionWidth:40,rightSection:m?xf(pm,{size:16}):null,filter:G,creatable:!0,withinPortal:!0})}function ym(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as zo,jsxs as vf}from"react/jsx-runtime";var Tm=vm(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function km(e){return e.id}function Dm(e){return{value:e.id,label:Sf(e),resource:e}}function Cf(e){let{classes:o}=Tm(),t=no(),r=S(),a=gf(async(l,f)=>{let i=Am(l),s={signal:f},u=await r.graphql(i,void 0,void 0,s);return Mm(u,l)},[r]),n=gf(l=>{l.length>0&&t(`/${bm(l[0])}`)},[t]);return zo(Qo,{size:"sm",radius:"md",className:o.searchInput,icon:zo(en,{size:16}),placeholder:"Search",itemComponent:Bm,toKey:km,toOption:Dm,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var Bm=Pm(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),zo("div",{ref:t,...o,children:vf(Sm,{noWrap:!0,children:[zo(fe,{value:e}),vf("div",{children:[zo(If,{children:Sf(e)}),zo(If,{size:"xs",color:"dimmed",children:r})]})]})})});function Am(e){let o=JSON.stringify(e);return Rm(e)?`{
|
|
2
2
|
Patients1: PatientList(_id: ${o}, _count: 1) {
|
|
3
3
|
resourceType
|
|
4
4
|
id
|
|
@@ -61,14 +61,14 @@ var cd=Object.create;var zl=Object.defineProperty;var dd=Object.getOwnPropertyDe
|
|
|
61
61
|
display
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
}`.replace(/\s+/g," ")}function Mm(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),wm(Fm(t),o).slice(0,5)}function Fm(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 wm(e,o){return e.sort((t,r)=>hf(r,o)-hf(t,o))}function hf(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,yf(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,yf(Cm(r),o));return t}function yf(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as K,jsxs as fo}from"react/jsx-runtime";var qm=Em(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 Pf(e){let o=St(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:f}=qm(),[i,s]=Hm(!1);return K(Lm,{height:60,p:8,style:{zIndex:101},children:fo(dr,{position:"apart",children:[fo(dr,{spacing:"xs",children:[K(bf,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&K(Cf,{pathname:e.pathname,searchParams:e.searchParams})]}),fo(_e,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:i,onClose:()=>s(!1),children:[K(_e.Target,{children:K(bf,{className:f(l.user,{[l.userActive]:i}),onClick:()=>s(u=>!u),children:fo(dr,{spacing:7,children:[K(fe,{value:r,radius:"xl",size:24}),K(Bt,{size:"sm",className:l.userName,children:Vm(r?.name?.[0])}),K(Ha,{size:12,stroke:1.5})]})})}),fo(_e.Dropdown,{children:[fo(Nm,{align:"center",p:"xl",children:[K(fe,{size:"xl",radius:100,value:o.profile}),K(ur,{value:o.profile?.name?.[0]}),K(Bt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&K(_e.Divider,{}),n.map(u=>u.profile.reference!==Rf(o.profile)&&K(_e.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:fo(dr,{children:[K(Om,{radius:"xl"}),fo("div",{style:{flex:1},children:[K(Bt,{size:"sm",weight:500,children:u.profile.display}),K(Bt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),K(_e.Divider,{}),K(_e.Item,{icon:K(rn,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),K(_e.Item,{icon:K(qo,{size:14,stroke:1.5}),onClick:()=>a(`/${Rf(r)}`),children:"Account settings"}),K(_e.Item,{icon:K($a,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),K(Bt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as dp,createStyles as mp,Navbar as cn,ScrollArea as pp,Space as xp,Text as Ip}from"@mantine/core";import{Fragment as gp,useState as hp}from"react";import{Button as zm,Group as Wm,Modal as Xm,NativeSelect as Jm,Stack as $m,TextInput as _m}from"@mantine/core";import{showNotification as kf}from"@mantine/notifications";import{deepClone as Km,normalizeErrorString as Zm}from"@medplum/core";function Tf(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Gm(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Um(o,t);return o}function Gm(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Um(e,o){e[o.name]=o.value}import{jsx as Qm}from"react/jsx-runtime";function H(e){return Qm("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=Tf(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as bo,jsxs as jm}from"react/jsx-runtime";function Df(e){let o=S(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,f=`${e.pathname}?${e.searchParams.toString()}`,i=Km(t);i.menu?.find(({title:u})=>u===n)?.link?.push({name:l,target:f}),o.updateResource(i).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),kf({color:"green",message:"Success"}),e.onOk()}).catch(u=>{kf({color:"red",message:Zm(u)})})}return bo(Xm,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:bo(H,{onSubmit:r,children:jm($m,{children:[bo(Ym,{config:t}),bo(_m,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),bo(Wm,{position:"right",children:bo(zm,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Ym(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return bo(Jm,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as ip,useState as up}from"react";import{useState as np}from"react";import{useCallback as ep}from"react";import{jsx as ap}from"react/jsx-runtime";function un(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function op(e){return typeof e.display=="string"?e.display:un(e)}function tp(e){return{value:un(e),label:op(e),resource:e}}function rp(e){return{code:e,display:e}}function Wo(e){let o=S(),{binding:t,creatable:r,clearable:a,expandParams:n,...l}=e,f=ep(async(i,s)=>{if(!t)return[];let c=(await o.valueSetExpand({...n,url:t,filter:i},{signal:s})).expansion?.contains,d=[];for(let m of c)m.code&&!d.some(p=>p.code===m.code)&&d.push(m);return d},[o,n,t]);return ap(Qo,{...l,creatable:r??!0,clearable:a??!0,toKey:un,toOption:tp,loadOptions:f,onCreate:rp,getCreateLabel:r===!1?void 0:i=>`+ Create ${i}`})}import{jsx as sp}from"react/jsx-runtime";function mr(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=np(o);function l(f){let i=f[0],s=fp(i);n(s),t&&t(s)}return sp(Wo,{defaultValue:lp(a),onChange:l,...r})}function lp(e){return e?{code:e}:void 0}function fp(e){return e?.code}import{jsx as cp}from"react/jsx-runtime";function Xo(e){let[o,t]=up(e.defaultValue),r=e.onChange,a=ip(n=>{t(n),r&&r(n)},[r]);return cp(mr,{"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 bp,jsx as Le,jsxs as Mt}from"react/jsx-runtime";var Af=mp(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 Bf(e){let{classes:o}=Af(),t=no(),r=Sp(e.pathname,e.searchParams,e.menus),[a,n]=hp(!1);function l(i,s){i.stopPropagation(),i.preventDefault(),t(s),window.innerWidth<768&&e.closeNavbar()}function f(i){i&&t(`/${i}`)}return Mt(bp,{children:[Le(cn,{width:{sm:250},p:"xs",children:Mt(pp,{children:[!e.resourceTypeSearchDisabled&&Le(cn.Section,{mb:"sm",children:Le(Xo,{name:"resourceType",placeholder:"Resource Type",onChange:i=>f(i)},window.location.pathname)}),Mt(cn.Section,{grow:!0,children:[e.menus?.map(i=>Mt(gp,{children:[Le(Ip,{className:o.menuTitle,children:i.title}),i.links?.map(s=>Mt(yp,{to:s.href,active:s.href===r?.href,onClick:u=>l(u,s.href),children:[Le(vp,{to:s.href,icon:s.icon}),Le("span",{children:s.label})]},s.href))]},`menu-${i.title}`)),e.displayAddBookmark&&Le(dp,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Le(Ya,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Le(Df,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function yp(e){let{classes:o,cx:t}=Af();return Le(le,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function vp(e){return e.icon?e.icon:Le(xp,{w:30})}function Sp(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=Cp(e,o,l.href);f>a&&(a=f,r=l)}return r}function Cp(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 Ro}from"react/jsx-runtime";function wM(e){let o=Pp(),[t,r]=Ap(localStorage.navbarOpen==="true"),a=S(),n=nr();Dp(()=>{function s(){Tp({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",s),()=>a.removeEventListener("offline",s)},[a]);function l(s){localStorage.navbarOpen=s.toString(),r(s)}function f(){l(!1)}function i(){l(!t)}return a.isLoading()?Ro(fn,{}):Ro(Rp,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&Ro(Pf,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:i}),navbar:n&&t?Ro(Bf,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:Ro(Go,{children:Ro(kp,{fallback:Ro(fn,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as Bp}from"@mantine/core";import{jsx as Po,jsxs as Fp}from"react/jsx-runtime";function Ge(e){let{contentType:o,url:t,title:r}=e.value??{};return t?Fp("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&Po("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&Po("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:Po("source",{type:o,src:t})}),o==="application/pdf"&&Po("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:Po("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),Po("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:Po(Bp,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Mp(r),children:r||"Download"})})]}):null}function Mp(e){return e?.includes(".")?e:void 0}import{jsx as dn}from"react/jsx-runtime";function Mf(e){return dn("div",{children:e.values?.map((o,t)=>dn("div",{children:dn(Ge,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as Ff}from"@mantine/core";import{useRef as Vp,useState as Hp}from"react";import{useRef as wp}from"react";import{normalizeOperationOutcome as Op}from"@medplum/core";import{Fragment as Lp,jsx as Ep,jsxs as Np}from"react/jsx-runtime";function Jo(e){let o=S(),t=wp(null);function r(l){M(l),t.current?.click()}function a(l){M(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 i=l.name,s=l.type||"application/octet-stream";o.createBinary(l,i,s,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:i})}).catch(u=>{e.onUploadError&&e.onUploadError(Op(u))})}return Np(Lp,{children:[Ep("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as Ae,jsxs as Ft}from"react/jsx-runtime";function wf(e){let[o,t]=Hp(e.defaultValue??[]),r=Vp();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return Ft("table",{style:{width:"100%"},children:[Ft("colgroup",{children:[Ae("col",{width:"97%"}),Ae("col",{width:"3%"})]}),Ft("tbody",{children:[o.map((n,l)=>Ft("tr",{children:[Ae("td",{children:Ae(Ge,{value:n,maxWidth:200})}),Ae("td",{children:Ae(Ff,{title:"Remove",size:"sm",onClick:f=>{M(f);let i=o.slice();i.splice(l,1),a(i)},children:Ae(lo,{})})})]},`${l}-${o.length}`)),Ft("tr",{children:[Ae("td",{}),Ae("td",{children:Ae(Jo,{onUpload:n=>{a([...r.current,n])},children:n=>Ae(Ff,{...n,title:"Add",size:"sm",color:"green",children:Ae(Rt,{size:16})})})})]})]})]})}import{Button as Of}from"@mantine/core";import{useState as qp}from"react";import{Fragment as Gp,jsx as pr,jsxs as Up}from"react/jsx-runtime";function xr(e){let[o,t]=qp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?Up(Gp,{children:[pr(Ge,{value:o,maxWidth:200}),pr(Of,{onClick:a=>{M(a),r(void 0)},children:"Remove"})]}):pr(Jo,{onUpload:r,children:a=>pr(Of,{...a,children:"Upload..."})})}import{getPathDisplayName as Ax,tryGetDataType as Bx}from"@medplum/core";var Ir=["meta","implicitRules","contained","extension","modifierExtension"],gr=["language","text"];import{createStyles as Qp}from"@mantine/core";import{Fragment as Wp,jsx as mn,jsxs as Xp}from"react/jsx-runtime";var zp=Qp(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 Ef(e){let{children:o,compact:t}=e,{classes:r,cx:a}=zp();return mn("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function Lf(e){return Xp(Wp,{children:[mn("dt",{children:e.term}),mn("dd",{children:e.children})]})}import{ActionIcon as hx,Box as yx,CopyButton as vx,Tooltip as Sx}from"@mantine/core";import{PropertyType as V,formatDateTime as Cx,formatPeriod as bx,formatTiming as Rx,isEmpty as Px}from"@medplum/core";import{formatCodeableConcept as Jp}from"@medplum/core";import{Fragment as $p,jsx as _p}from"react/jsx-runtime";function ye(e){return _p($p,{children:Jp(e.value)})}import{formatCoding as Kp}from"@medplum/core";import{Fragment as Zp,jsx as Yp}from"react/jsx-runtime";function Nf(e){return Yp(Zp,{children:Kp(e.value)})}import{Fragment as jp,jsx as ex}from"react/jsx-runtime";function hr(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("]")),ex(jp,{children:t.join("").trim()})}import{Fragment as tx,jsx as ox,jsxs as rx}from"react/jsx-runtime";function Vf(e){let o=e.value;return o?rx(tx,{children:[o.name,o.name&&": ",o.telecom?.map(t=>ox(hr,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as ax}from"react/jsx-runtime";function Hf(e){return ax("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as nx}from"@medplum/core";import{Fragment as lx,jsx as fx}from"react/jsx-runtime";function qf(e){return fx(lx,{children:nx(e.value)})}import{formatQuantity as sx}from"@medplum/core";import{Fragment as ix,jsx as ux}from"react/jsx-runtime";function ae(e){return ux(ix,{children:sx(e.value)})}import{formatRange as cx}from"@medplum/core";import{Fragment as dx,jsx as mx}from"react/jsx-runtime";function yr(e){return mx(dx,{children:cx(e.value)})}import{Fragment as px,jsx as Gf,jsxs as xx}from"react/jsx-runtime";function Uf(e){let o=e.value;return o?xx(px,{children:[Gf(ae,{value:o.numerator}),"\xA0/\xA0",Gf(ae,{value:o.denominator})]}):null}import{stringify as Ix}from"@medplum/core";import{Fragment as gx,jsx as Qf}from"react/jsx-runtime";function To(e){if(!e.value)return null;let o=e.value.display||e.value.reference||Ix(e.value);return e.link!==!1&&e.value.reference?Qf(le,{to:e.value,children:o}):Qf(gx,{children:o})}import{Fragment as zf,jsx as vr}from"react/jsx-runtime";function Wf(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?vr(zf,{children:t.map((a,n)=>vr("div",{children:vr(ce,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):vr(zf,{})}import{Fragment as $o,jsx as U,jsxs as Tx}from"react/jsx-runtime";function ce(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return Tx(yx,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!Px(r)&&U(vx,{value:r,timeout:2e3,children:({copied:n,copy:l})=>U(Sx,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:U(hx,{color:n?"teal":"gray",onClick:l,children:n?U(bt,{size:"1rem"}):U(Pt,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===V.Attachment?U(Mf,{values:r,maxWidth:e.maxWidth}):U(Wf,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case V.boolean:return U($o,{children:r===void 0?"":(!!r).toString()});case V.SystemString:case V.string:return U("div",{style:{whiteSpace:"pre-wrap"},children:r});case V.code:case V.date:case V.decimal:case V.id:case V.integer:case V.positiveInt:case V.unsignedInt:case V.uri:case V.url:return U($o,{children:r});case V.canonical:return U(To,{value:{reference:r},link:e.link});case V.dateTime:case V.instant:return U($o,{children:Cx(r)});case V.markdown:return U("pre",{children:r});case V.Address:return U(Yl,{value:r});case V.Annotation:return U($o,{children:r?.text});case V.Attachment:return U(Ge,{value:r,maxWidth:e.maxWidth});case V.CodeableConcept:return U(ye,{value:r});case V.Coding:return U(Nf,{value:r});case V.ContactDetail:return U(Vf,{value:r});case V.ContactPoint:return U(hr,{value:r});case V.HumanName:return U(ur,{value:r});case V.Identifier:return U(Hf,{value:r});case V.Money:return U(qf,{value:r});case V.Period:return U($o,{children:bx(r)});case V.Quantity:case V.Duration:return U(ae,{value:r});case V.Range:return U(yr,{value:r});case V.Ratio:return U(Uf,{value:r});case V.Reference:return U(To,{value:r,link:e.link});case V.Timing:return U($o,{children:Rx(r)});case V.Dosage:case V.UsageContext:return U(wt,{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 U(wt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as kx,getTypedPropertyValueWithSchema as Dx}from"@medplum/core";function so(e,o){let t=kx(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}function Xf(e,o,t){let r=Dx(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 Sr,jsxs as Mx}from"react/jsx-runtime";function wt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=Bx(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?Sr("div",{children:t.name}):Sr(Ef,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,f]=n;if(Ir.includes(l)||gr.includes(l)&&f.path.split(".").length===2)return null;let[i,s]=so(o,l);return e.ignoreMissingValues&&(!i||Array.isArray(i)&&i.length===0)?null:Sr(Lf,{term:Ax(l),children:Sr(ce,{property:f,propertyType:s,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):Mx("div",{children:[r,"\xA0not implemented"]})}import{tryGetDataType as lh}from"@medplum/core";import{useContext as fh,useMemo as Ls,useState as sh}from"react";import{Stack as oh}from"@mantine/core";import{getPathDisplayName as Es,isPopulated as th}from"@medplum/core";import{useMemo as rh,useState as ah}from"react";import{Group as Ox,Input as Ex}from"@mantine/core";import{useContext as Lx}from"react";import Fx from"react";function wx(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 Ne=Fx.createContext({profileUrl:void 0,debugMode:!1,getModifiedNestedElement:()=>{}});function Jf(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,i]of Object.entries(n)){let[s,u]=wx(f,".");l.has(s)&&(r[e.type+"."+f]=i),l.add(f)}}return{debugMode:t??!1,profileUrl:o,getModifiedNestedElement:a}}import{jsx as pn,jsxs as Nx}from"react/jsx-runtime";function Cr(e){let{debugMode:o}=Lx(Ne),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Nx(Ox,{noWrap:!0,"data-testid":e.testId,children:[pn("div",{children:e.children}),pn("div",{children:pn(Ex.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as Vx}from"@mantine/core";import{useContext as Hx}from"react";function Q(e,o){return e?.issue?.filter(t=>$f(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
-
`)}function br(e,o){return e?.issue?.filter(t=>$f(t.expression?.[0],o))}function $f(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 qx}from"react/jsx-runtime";function pe(e){let{debugMode:o}=Hx(Ne),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,qx(Vx.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,error:Q(e.outcome,e.htmlFor),"data-testid":e.testId,children:e.children})}import{capitalize as Gx,isEmpty as _f}from"@medplum/core";function Ot(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let f=o.replace("[x]",Gx(l.code));f in e&&delete e[f]}return e[t]=a,e}function $w(e){return!!e&&!_f(e.url)&&!_f(e.name)}import{Checkbox as Wg,Group as Xg,NativeSelect as Jg,Textarea as $g,TextInput as kn}from"@mantine/core";import{capitalize as Os,HTTP_HL7_ORG as _g,PropertyType as E}from"@medplum/core";import{useState as Kg}from"react";import{useState as Ux}from"react";import{jsx as Wx}from"react/jsx-runtime";function _o(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=Ux(o);function l(f){let i=zx(f);n(i),t&&t(i)}return Wx(Wo,{defaultValue:a&&Qx(a),onChange:l,...r})}function Qx(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function zx(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as Xx}from"react";import{jsx as _x}from"react/jsx-runtime";function Rr(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=Xx(o);function l(f){let i=f[0],s=i&&$x(i);n(s),t&&t(s)}return _x(Wo,{defaultValue:a&&Jx(a),maxSelectedValues:1,onChange:l,...r})}function Jx(e){return{system:e.system,code:e.code,display:e.display}}function $x(e){return{system:e.system,code:e.code,display:e.display}}import{Group as rI,TextInput as aI}from"@mantine/core";import{useRef as nI,useState as lI}from"react";import{Group as Kx,NativeSelect as Kf,TextInput as Zx}from"@mantine/core";import{useContext as Yx,useMemo as jx,useRef as eI,useState as oI}from"react";import{jsx as xn,jsxs as tI}from"react/jsx-runtime";function Pr(e){let{path:o,outcome:t}=e,{getModifiedNestedElement:r}=Yx(Ne),[a,n]=oI(e.defaultValue),l=eI();l.current=a;let[f,i,s]=jx(()=>["system","use","value"].map(p=>r(o+"."+p)),[r,o]);function u(p){p&&Object.keys(p).length===0&&(p=void 0),n(p),e.onChange&&e.onChange(p)}function c(p){let x={...l.current,system:p};p||delete x.system,u(x)}function d(p){let x={...l.current,use:p};p||delete x.use,u(x)}function m(p){let x={...l.current,value:p};p||delete x.value,u(x)}return tI(Kx,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[xn(Kf,{"data-testid":"system",defaultValue:a?.system,required:(f?.min??0)>0,onChange:p=>c(p.currentTarget.value),data:["","email","phone","fax","pager","sms","other"],error:Q(t,o+".system")}),xn(Kf,{"data-testid":"use",defaultValue:a?.use,required:(i?.min??0)>0,onChange:p=>d(p.currentTarget.value),data:["","home","work","temp","old","mobile"],error:Q(t,o+".use")}),xn(Zx,{placeholder:"Value",defaultValue:a?.value,required:(s?.min??0)>0,onChange:p=>m(p.currentTarget.value),error:Q(t,o+".value")})]})}import{jsx as Zf,jsxs as fI}from"react/jsx-runtime";function Yf(e){let[o,t]=lI(e.defaultValue),r=nI();r.current=o;function a(f){t(f),e.onChange&&e.onChange(f)}function n(f){let i={...r.current,name:f};f||delete i.name,a(i)}function l(f){let i={...r.current,telecom:f&&[f]};f||delete i.telecom,a(i)}return fI(rI,{spacing:"xs",grow:!0,noWrap:!0,children:[Zf(aI,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:f=>n(f.currentTarget.value)}),Zf(Pr,{name:e.name+"-telecom",path:e.path+".telecom",defaultValue:o?.telecom?.[0],onChange:l,outcome:e.outcome})]})}import{TextInput as sI}from"@mantine/core";import{isValidDate as jf}from"@medplum/core";function es(e){if(!e)return"";let o=new Date(e);return jf(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function os(e){if(!e)return"";let o=new Date(e);return jf(o)?o.toISOString():""}import{jsx as uI}from"react/jsx-runtime";function Ve(e){return uI(sI,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:iI(),defaultValue:es(e.defaultValue),autoFocus:e.autoFocus,error:Q(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(os(t))}}})}function iI(){return"datetime-local"}import{JsonInput as cI}from"@mantine/core";import{stringify as dI,tryGetProfile as mI}from"@medplum/core";import{useEffect as pI,useMemo as xI,useState as ts}from"react";import{jsx as In,jsxs as rs}from"react/jsx-runtime";function as(e){let{propertyType:o}=e,t=S(),[r,a]=ts(!1),[n,l]=ts(),f=xI(()=>{if(!(!o.profile||o.profile.length===0))return o.profile[0]},[o]);pI(()=>{f&&(a(!0),t.requestProfileSchema(f).then(()=>{let s=mI(f);a(!1),l(s)}).catch(s=>{a(!1),console.warn(s)}))},[t,f]);function i(s){e.onChange&&(console.log("Extension",s),e.onChange(s))}return f?r?rs("div",{children:["Loading ",f,"..."]}):n?In(Ko,{profileUrl:f,typeName:n.name,defaultValue:e.defaultValue,onChange:i}):rs("div",{children:["StructureDefinition for ",f," not found"]}):In(II,{...e})}function II(e){return In(cI,{id:e.name,name:e.name,"data-testid":"extension-json-input",defaultValue:dI(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as gI,NativeSelect as hI,TextInput as Tr}from"@mantine/core";import{useState as yI}from"react";import{jsx as Et,jsxs as vI}from"react/jsx-runtime";function ns(e){let{outcome:o,path:t}=e,[r,a]=yI(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 i(c){n({...r,given:c?c.split(" "):void 0})}function s(c){n({...r,family:c||void 0})}function u(c){n({...r,suffix:c?c.split(" "):void 0})}return vI(gI,{spacing:"xs",grow:!0,noWrap:!0,children:[Et(hI,{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:Q(o,t+".use")}),Et(Tr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:r?.prefix?.join(" "),onChange:c=>f(c.currentTarget.value),error:Q(o,t+".prefix")}),Et(Tr,{placeholder:"Given",name:e.name+"-given",defaultValue:r?.given?.join(" "),onChange:c=>i(c.currentTarget.value),error:Q(o,t+".given")}),Et(Tr,{name:e.name+"-family",placeholder:"Family",defaultValue:r?.family,onChange:c=>s(c.currentTarget.value),error:Q(o,t+".family")}),Et(Tr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:r?.suffix?.join(" "),onChange:c=>u(c.currentTarget.value),error:Q(o,t+".suffix")})]})}import{Group as SI,TextInput as ls}from"@mantine/core";import{useContext as CI,useMemo as bI,useState as RI}from"react";import{jsx as fs,jsxs as PI}from"react/jsx-runtime";function ss(e){let{path:o,outcome:t}=e,[r,a]=RI(e.defaultValue),{getModifiedNestedElement:n}=CI(Ne),[l,f]=bI(()=>["system","value"].map(s=>n(o+"."+s)),[n,o]);function i(s){a(s),e.onChange&&e.onChange(s)}return PI(SI,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[fs(ls,{placeholder:"System",required:(l?.min??0)>0,defaultValue:r?.system,onChange:s=>i({...r,system:s.currentTarget.value}),error:Q(t,o+".system")}),fs(ls,{placeholder:"Value",required:(f?.min??0)>0,defaultValue:r?.value,onChange:s=>i({...r,value:s.currentTarget.value}),error:Q(t,o+".value")})]})}import{NativeSelect as TI,TextInput as kI}from"@mantine/core";import{useCallback as gn,useState as DI}from"react";import{jsx as hn}from"react/jsx-runtime";var AI=["USD","EUR","CAD","GBP","AUD"];function is(e){let{onChange:o}=e,[t,r]=DI(e.defaultValue),a=gn(i=>{r(i),o&&o(i)},[o]),n=gn(i=>{a({...t,currency:i.currentTarget.value})},[t,a]),l=gn(i=>{a({...t,value:i.currentTarget.valueAsNumber})},[t,a]),f=hn(TI,{defaultValue:t?.currency,data:AI,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return hn(kI,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:hn(Ga,{size:14}),rightSection:f,rightSectionWidth:92,onChange:l})}import{Group as BI}from"@mantine/core";import{useState as MI}from"react";import{jsx as us,jsxs as FI}from"react/jsx-runtime";function cs(e){let[o,t]=MI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return FI(BI,{spacing:"xs",grow:!0,noWrap:!0,children:[us(Ve,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),us(Ve,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as wI,NativeSelect as OI,TextInput as ds}from"@mantine/core";import{useState as EI}from"react";import{jsx as yn,jsxs as NI}from"react/jsx-runtime";function Be(e){let[o,t]=EI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return NI(wI,{spacing:"xs",grow:!0,noWrap:!0,children:[yn(OI,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),yn(ds,{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:LI(a.currentTarget.value)})}}),yn(ds,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function LI(e){if(e)return parseFloat(e)}import{Group as VI}from"@mantine/core";import{useState as HI}from"react";import{jsx as ms,jsxs as qI}from"react/jsx-runtime";function Lt(e){let[o,t]=HI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return qI(VI,{spacing:"xs",grow:!0,noWrap:!0,children:[ms(Be,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),ms(Be,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as GI}from"@mantine/core";import{useState as UI}from"react";import{jsx as ps,jsxs as QI}from"react/jsx-runtime";function xs(e){let[o,t]=UI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return QI(GI,{spacing:"xs",grow:!0,noWrap:!0,children:[ps(Be,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),ps(Be,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as jI,NativeSelect as eg}from"@mantine/core";import{LRUCache as og,ReadablePromise as tg,createReference as rg,isEmpty as ag,isPopulated as ng,tryGetProfile as lg}from"@medplum/core";import{useCallback as fg,useEffect as sg,useMemo as vs,useRef as ig,useState as vn}from"react";import{Group as zI,Text as Is}from"@mantine/core";import{getDisplayString as WI,getReferenceString as ys}from"@medplum/core";import{forwardRef as XI,useCallback as gs,useState as JI}from"react";import{jsx as Nt,jsxs as hs}from"react/jsx-runtime";var $I={Observation:"code",User:"email:contains"},_I=["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 KI(e){return{value:ys(e),label:WI(e),resource:e}}function kr(e){let o=S(),{resourceType:t,searchCriteria:r}=e,[a,n]=JI(),l=X(e.defaultValue,n),f=e.onChange,i=gs(async(u,c)=>{let d=YI(t),m=new URLSearchParams({[d]:u??"",_count:"10",...r});return await o.searchResources(t,m,{signal:c})},[o,t,r]),s=gs(u=>{f&&f(u[0])},[f]);return e.defaultValue&&!a&&!l?null:Nt(Qo,{name:e.name,required:e.required,itemComponent:ZI,defaultValue:l,placeholder:e.placeholder,maxSelectedValues:1,toKey:ys,toOption:KI,loadOptions:i,onChange:s,clearable:!0})}var ZI=XI(({label:e,resource:o,...t},r)=>Nt("div",{ref:r,...t,children:hs(zI,{noWrap:!0,children:[Nt(fe,{value:o}),hs("div",{children:[Nt(Is,{children:e}),Nt(Is,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function YI(e){return $I[e]??(_I.includes(e)?"name":"_id")}import{jsx as Sn,jsxs as pg}from"react/jsx-runtime";function Zo(e){let{onChange:o}=e,t=S(),[r,a]=vn(e.defaultValue),[n,l]=vn(()=>ug(e.targetTypes)),[f,i]=vn(()=>cg(e.defaultValue,n)),s=ig(new og),u=vs(()=>f?.type==="profile"?{...e.searchCriteria,_profile:f.value}:e.searchCriteria,[e.searchCriteria,f]);sg(()=>{let m=!1,p=n?.map(x=>{if(!mg(x))return Promise.resolve(x);m=!0;let C=x.value,y=s.current.get(C);if(y)return y;let v=dg(t,x.value).then(P=>{let h={...x};return P?ng(P.type)?(h.resourceType=P.type,h.name=P.name,h.title=P.title):(console.error(`StructureDefinition.type missing for ${x.value}`),h.error="StructureDefinition.type missing"):(console.error(`StructureDefinition not found for ${x.value}`),h.error="StructureDefinition not found"),h}).catch(P=>(console.error(P),{...x,error:P})),b=new tg(v);return s.current.set(C,b),b});!p||!m||Promise.all(p).then(x=>{if(l(x),!f)return;let C=x.findIndex(y=>y.value===f.value||y.resourceType===f.resourceType);if(C===-1){console.debug(`defaultValue had unexpected resourceType: ${f.resourceType}`);return}i(x[C])}).catch(console.error)},[t,f,n]);let c=fg(m=>{let p=m?rg(m):void 0;a(p),o&&o(p)},[o]),d=vs(()=>n?n.map(m=>({value:m.value,label:m.type==="profile"?m.title??m.name??m.resourceType??m.value:m.value})):[],[n]);return pg(jI,{spacing:"xs",grow:!0,noWrap:!0,children:[n&&n.length>1&&Sn(eg,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:f?.resourceType,autoFocus:e.autoFocus,onChange:m=>{let p=m.currentTarget.value,x=n.find(C=>C.value===p);i(x)},data:d}),!n&&Sn(Xo,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:f?.resourceType,onChange:m=>{i(m?{type:"resourceType",value:m,resourceType:m}:void 0)},name:e.name+"-resourceType",placeholder:"Resource Type"}),Sn(kr,{resourceType:f?.resourceType,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:c})]})}function ug(e){if(!e||e.length===0||e.length===1&&e[0]==="Resource")return;let o=[];for(let t of e)t.includes("/")?o.push({type:"profile",value:t}):o.push({type:"resourceType",value:t,resourceType:t});return o}function cg(e,o){let t=e?.reference?.split("/")[0];if(t){let r=o?.find(a=>a.resourceType===t);return r||{type:"resourceType",value:t,resourceType:t}}if(o&&o.length>0)return o[0]}async function dg(e,o){let t=lg(o);if(t)return{type:t.type,name:t.name,title:t.title};let r=`{
|
|
64
|
+
}`.replace(/\s+/g," ")}function Mm(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),wm(Fm(t),o).slice(0,5)}function Fm(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 wm(e,o){return e.sort((t,r)=>hf(r,o)-hf(t,o))}function hf(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,yf(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,yf(Cm(r),o));return t}function yf(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as K,jsxs as fo}from"react/jsx-runtime";var qm=Em(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 Pf(e){let o=St(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:f}=qm(),[i,s]=Hm(!1);return K(Lm,{height:60,p:8,style:{zIndex:101},children:fo(dr,{position:"apart",children:[fo(dr,{spacing:"xs",children:[K(bf,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&K(Cf,{pathname:e.pathname,searchParams:e.searchParams})]}),fo(_e,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:i,onClose:()=>s(!1),children:[K(_e.Target,{children:K(bf,{className:f(l.user,{[l.userActive]:i}),onClick:()=>s(u=>!u),children:fo(dr,{spacing:7,children:[K(fe,{value:r,radius:"xl",size:24}),K(At,{size:"sm",className:l.userName,children:Vm(r?.name?.[0])}),K(Ha,{size:12,stroke:1.5})]})})}),fo(_e.Dropdown,{children:[fo(Nm,{align:"center",p:"xl",children:[K(fe,{size:"xl",radius:100,value:o.profile}),K(ur,{value:o.profile?.name?.[0]}),K(At,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&K(_e.Divider,{}),n.map(u=>u.profile.reference!==Rf(o.profile)&&K(_e.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:fo(dr,{children:[K(Om,{radius:"xl"}),fo("div",{style:{flex:1},children:[K(At,{size:"sm",weight:500,children:u.profile.display}),K(At,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),K(_e.Divider,{}),K(_e.Item,{icon:K(rn,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),K(_e.Item,{icon:K(qo,{size:14,stroke:1.5}),onClick:()=>a(`/${Rf(r)}`),children:"Account settings"}),K(_e.Item,{icon:K($a,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),K(At,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as dp,createStyles as mp,Navbar as cn,ScrollArea as pp,Space as xp,Text as Ip}from"@mantine/core";import{Fragment as gp,useState as hp}from"react";import{Button as zm,Group as Wm,Modal as Xm,NativeSelect as Jm,Stack as $m,TextInput as _m}from"@mantine/core";import{showNotification as kf}from"@mantine/notifications";import{deepClone as Km,normalizeErrorString as Zm}from"@medplum/core";function Tf(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Gm(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&Um(o,t);return o}function Gm(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function Um(e,o){e[o.name]=o.value}import{jsx as Qm}from"react/jsx-runtime";function H(e){return Qm("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=Tf(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as bo,jsxs as jm}from"react/jsx-runtime";function Df(e){let o=S(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,f=`${e.pathname}?${e.searchParams.toString()}`,i=Km(t);i.menu?.find(({title:u})=>u===n)?.link?.push({name:l,target:f}),o.updateResource(i).then(u=>{t.menu=u.menu,o.dispatchEvent({type:"change"}),kf({color:"green",message:"Success"}),e.onOk()}).catch(u=>{kf({color:"red",message:Zm(u)})})}return bo(Xm,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:bo(H,{onSubmit:r,children:jm($m,{children:[bo(Ym,{config:t}),bo(_m,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),bo(Wm,{position:"right",children:bo(zm,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Ym(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return bo(Jm,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",data:t,withAsterisk:!0})}import{useCallback as ip,useState as up}from"react";import{useState as np}from"react";import{useCallback as ep}from"react";import{jsx as ap}from"react/jsx-runtime";function un(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function op(e){return typeof e.display=="string"?e.display:un(e)}function tp(e){return{value:un(e),label:op(e),resource:e}}function rp(e){return{code:e,display:e}}function Wo(e){let o=S(),{binding:t,creatable:r,clearable:a,expandParams:n,...l}=e,f=ep(async(i,s)=>{if(!t)return[];let c=(await o.valueSetExpand({...n,url:t,filter:i},{signal:s})).expansion?.contains,d=[];for(let m of c)m.code&&!d.some(p=>p.code===m.code)&&d.push(m);return d},[o,n,t]);return ap(Qo,{...l,creatable:r??!0,clearable:a??!0,toKey:un,toOption:tp,loadOptions:f,onCreate:rp,getCreateLabel:r===!1?void 0:i=>`+ Create ${i}`})}import{jsx as sp}from"react/jsx-runtime";function mr(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=np(o);function l(f){let i=f[0],s=fp(i);n(s),t&&t(s)}return sp(Wo,{defaultValue:lp(a),onChange:l,...r})}function lp(e){return e?{code:e}:void 0}function fp(e){return e?.code}import{jsx as cp}from"react/jsx-runtime";function Xo(e){let[o,t]=up(e.defaultValue),r=e.onChange,a=ip(n=>{t(n),r&&r(n)},[r]);return cp(mr,{"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 bp,jsx as Le,jsxs as Mt}from"react/jsx-runtime";var Bf=mp(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 Af(e){let{classes:o}=Bf(),t=no(),r=Sp(e.pathname,e.searchParams,e.menus),[a,n]=hp(!1);function l(i,s){i.stopPropagation(),i.preventDefault(),t(s),window.innerWidth<768&&e.closeNavbar()}function f(i){i&&t(`/${i}`)}return Mt(bp,{children:[Le(cn,{width:{sm:250},p:"xs",children:Mt(pp,{children:[!e.resourceTypeSearchDisabled&&Le(cn.Section,{mb:"sm",children:Le(Xo,{name:"resourceType",placeholder:"Resource Type",onChange:i=>f(i)},window.location.pathname)}),Mt(cn.Section,{grow:!0,children:[e.menus?.map(i=>Mt(gp,{children:[Le(Ip,{className:o.menuTitle,children:i.title}),i.links?.map(s=>Mt(yp,{to:s.href,active:s.href===r?.href,onClick:u=>l(u,s.href),children:[Le(vp,{to:s.href,icon:s.icon}),Le("span",{children:s.label})]},s.href))]},`menu-${i.title}`)),e.displayAddBookmark&&Le(dp,{variant:"subtle",size:"xs",mt:"xl",leftIcon:Le(Ya,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&Le(Df,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function yp(e){let{classes:o,cx:t}=Bf();return Le(le,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function vp(e){return e.icon?e.icon:Le(xp,{w:30})}function Sp(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=Cp(e,o,l.href);f>a&&(a=f,r=l)}return r}function Cp(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 Ro}from"react/jsx-runtime";function wM(e){let o=Pp(),[t,r]=Bp(localStorage.navbarOpen==="true"),a=S(),n=nr();Dp(()=>{function s(){Tp({color:"red",message:"No connection to server",autoClose:!1})}return a.addEventListener("offline",s),()=>a.removeEventListener("offline",s)},[a]);function l(s){localStorage.navbarOpen=s.toString(),r(s)}function f(){l(!1)}function i(){l(!t)}return a.isLoading()?Ro(fn,{}):Ro(Rp,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&Ro(Pf,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:i}),navbar:n&&t?Ro(Af,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:Ro(Go,{children:Ro(kp,{fallback:Ro(fn,{}),children:e.children})})})}import{Anchor as Ap}from"@mantine/core";import{jsx as Po,jsxs as Fp}from"react/jsx-runtime";function Ge(e){let{contentType:o,url:t,title:r}=e.value??{};return t?Fp("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&Po("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&Po("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:Po("source",{type:o,src:t})}),o==="application/pdf"&&Po("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:Po("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),Po("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:Po(Ap,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Mp(r),children:r||"Download"})})]}):null}function Mp(e){return e?.includes(".")?e:void 0}import{jsx as dn}from"react/jsx-runtime";function Mf(e){return dn("div",{children:e.values?.map((o,t)=>dn("div",{children:dn(Ge,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as Ff}from"@mantine/core";import{useRef as Vp,useState as Hp}from"react";import{useRef as wp}from"react";import{normalizeOperationOutcome as Op}from"@medplum/core";import{Fragment as Lp,jsx as Ep,jsxs as Np}from"react/jsx-runtime";function Jo(e){let o=S(),t=wp(null);function r(l){M(l),t.current?.click()}function a(l){M(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 i=l.name,s=l.type||"application/octet-stream";o.createBinary(l,i,s,e.onUploadProgress).then(u=>{e.onUpload({contentType:u.contentType,url:u.url,title:i})}).catch(u=>{e.onUploadError&&e.onUploadError(Op(u))})}return Np(Lp,{children:[Ep("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as Be,jsxs as Ft}from"react/jsx-runtime";function wf(e){let[o,t]=Hp(e.defaultValue??[]),r=Vp();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return Ft("table",{style:{width:"100%"},children:[Ft("colgroup",{children:[Be("col",{width:"97%"}),Be("col",{width:"3%"})]}),Ft("tbody",{children:[o.map((n,l)=>Ft("tr",{children:[Be("td",{children:Be(Ge,{value:n,maxWidth:200})}),Be("td",{children:Be(Ff,{title:"Remove",size:"sm",onClick:f=>{M(f);let i=o.slice();i.splice(l,1),a(i)},children:Be(lo,{})})})]},`${l}-${o.length}`)),Ft("tr",{children:[Be("td",{}),Be("td",{children:Be(Jo,{onUpload:n=>{a([...r.current,n])},children:n=>Be(Ff,{...n,title:"Add",size:"sm",color:"green",children:Be(Rt,{size:16})})})})]})]})]})}import{Button as Of}from"@mantine/core";import{useState as qp}from"react";import{Fragment as Gp,jsx as pr,jsxs as Up}from"react/jsx-runtime";function xr(e){let[o,t]=qp(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?Up(Gp,{children:[pr(Ge,{value:o,maxWidth:200}),pr(Of,{onClick:a=>{M(a),r(void 0)},children:"Remove"})]}):pr(Jo,{onUpload:r,children:a=>pr(Of,{...a,children:"Upload..."})})}import{getPathDisplayName as Bx,tryGetDataType as Ax}from"@medplum/core";var Ir=["meta","implicitRules","contained","extension","modifierExtension"],gr=["language","text"];import{createStyles as Qp}from"@mantine/core";import{Fragment as Wp,jsx as mn,jsxs as Xp}from"react/jsx-runtime";var zp=Qp(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 Ef(e){let{children:o,compact:t}=e,{classes:r,cx:a}=zp();return mn("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function Lf(e){return Xp(Wp,{children:[mn("dt",{children:e.term}),mn("dd",{children:e.children})]})}import{ActionIcon as hx,Box as yx,CopyButton as vx,Tooltip as Sx}from"@mantine/core";import{PropertyType as V,formatDateTime as Cx,formatPeriod as bx,formatTiming as Rx,isEmpty as Px}from"@medplum/core";import{formatCodeableConcept as Jp}from"@medplum/core";import{Fragment as $p,jsx as _p}from"react/jsx-runtime";function ye(e){return _p($p,{children:Jp(e.value)})}import{formatCoding as Kp}from"@medplum/core";import{Fragment as Zp,jsx as Yp}from"react/jsx-runtime";function Nf(e){return Yp(Zp,{children:Kp(e.value)})}import{Fragment as jp,jsx as ex}from"react/jsx-runtime";function hr(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("]")),ex(jp,{children:t.join("").trim()})}import{Fragment as tx,jsx as ox,jsxs as rx}from"react/jsx-runtime";function Vf(e){let o=e.value;return o?rx(tx,{children:[o.name,o.name&&": ",o.telecom?.map(t=>ox(hr,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as ax}from"react/jsx-runtime";function Hf(e){return ax("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as nx}from"@medplum/core";import{Fragment as lx,jsx as fx}from"react/jsx-runtime";function qf(e){return fx(lx,{children:nx(e.value)})}import{formatQuantity as sx}from"@medplum/core";import{Fragment as ix,jsx as ux}from"react/jsx-runtime";function ae(e){return ux(ix,{children:sx(e.value)})}import{formatRange as cx}from"@medplum/core";import{Fragment as dx,jsx as mx}from"react/jsx-runtime";function yr(e){return mx(dx,{children:cx(e.value)})}import{Fragment as px,jsx as Gf,jsxs as xx}from"react/jsx-runtime";function Uf(e){let o=e.value;return o?xx(px,{children:[Gf(ae,{value:o.numerator}),"\xA0/\xA0",Gf(ae,{value:o.denominator})]}):null}import{stringify as Ix}from"@medplum/core";import{Fragment as gx,jsx as Qf}from"react/jsx-runtime";function To(e){if(!e.value)return null;let o=e.value.display||e.value.reference||Ix(e.value);return e.link!==!1&&e.value.reference?Qf(le,{to:e.value,children:o}):Qf(gx,{children:o})}import{Fragment as zf,jsx as vr}from"react/jsx-runtime";function Wf(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?vr(zf,{children:t.map((a,n)=>vr("div",{children:vr(ce,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):vr(zf,{})}import{Fragment as $o,jsx as U,jsxs as Tx}from"react/jsx-runtime";function ce(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return Tx(yx,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!Px(r)&&U(vx,{value:r,timeout:2e3,children:({copied:n,copy:l})=>U(Sx,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:U(hx,{color:n?"teal":"gray",onClick:l,children:n?U(bt,{size:"1rem"}):U(Pt,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===V.Attachment?U(Mf,{values:r,maxWidth:e.maxWidth}):U(Wf,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case V.boolean:return U($o,{children:r===void 0?"":(!!r).toString()});case V.SystemString:case V.string:return U("div",{style:{whiteSpace:"pre-wrap"},children:r});case V.code:case V.date:case V.decimal:case V.id:case V.integer:case V.positiveInt:case V.unsignedInt:case V.uri:case V.url:return U($o,{children:r});case V.canonical:return U(To,{value:{reference:r},link:e.link});case V.dateTime:case V.instant:return U($o,{children:Cx(r)});case V.markdown:return U("pre",{children:r});case V.Address:return U(Yl,{value:r});case V.Annotation:return U($o,{children:r?.text});case V.Attachment:return U(Ge,{value:r,maxWidth:e.maxWidth});case V.CodeableConcept:return U(ye,{value:r});case V.Coding:return U(Nf,{value:r});case V.ContactDetail:return U(Vf,{value:r});case V.ContactPoint:return U(hr,{value:r});case V.HumanName:return U(ur,{value:r});case V.Identifier:return U(Hf,{value:r});case V.Money:return U(qf,{value:r});case V.Period:return U($o,{children:bx(r)});case V.Quantity:case V.Duration:return U(ae,{value:r});case V.Range:return U(yr,{value:r});case V.Ratio:return U(Uf,{value:r});case V.Reference:return U(To,{value:r,link:e.link});case V.Timing:return U($o,{children:Rx(r)});case V.Dosage:case V.UsageContext:return U(wt,{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 U(wt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as kx,getTypedPropertyValueWithSchema as Dx}from"@medplum/core";function so(e,o){let t=kx(e,o);return t?Array.isArray(t)?[t.map(r=>r.value),t[0].type]:[t.value,t.type]:[void 0,"undefined"]}function Xf(e,o,t){let r=Dx(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 Sr,jsxs as Mx}from"react/jsx-runtime";function wt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=Ax(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?Sr("div",{children:t.name}):Sr(Ef,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,f]=n;if(Ir.includes(l)||gr.includes(l)&&f.path.split(".").length===2)return null;let[i,s]=so(o,l);return e.ignoreMissingValues&&(!i||Array.isArray(i)&&i.length===0)?null:Sr(Lf,{term:Bx(l),children:Sr(ce,{property:f,propertyType:s,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):Mx("div",{children:[r,"\xA0not implemented"]})}import{tryGetDataType as lh}from"@medplum/core";import{useContext as fh,useMemo as Ls,useState as sh}from"react";import{Stack as oh}from"@mantine/core";import{getPathDisplayName as Es,isPopulated as th}from"@medplum/core";import{useMemo as rh,useState as ah}from"react";import{Group as Ox,Input as Ex}from"@mantine/core";import{useContext as Lx}from"react";import Fx from"react";function wx(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 Ne=Fx.createContext({profileUrl:void 0,debugMode:!1,getModifiedNestedElement:()=>{}});function Jf(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,i]of Object.entries(n)){let[s,u]=wx(f,".");l.has(s)&&(r[e.type+"."+f]=i),l.add(f)}}return{debugMode:t??!1,profileUrl:o,getModifiedNestedElement:a}}import{jsx as pn,jsxs as Nx}from"react/jsx-runtime";function Cr(e){let{debugMode:o}=Lx(Ne),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Nx(Ox,{noWrap:!0,"data-testid":e.testId,children:[pn("div",{children:e.children}),pn("div",{children:pn(Ex.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as Vx}from"@mantine/core";import{useContext as Hx}from"react";function Q(e,o){return e?.issue?.filter(t=>$f(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
+
`)}function br(e,o){return e?.issue?.filter(t=>$f(t.expression?.[0],o))}function $f(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 qx}from"react/jsx-runtime";function pe(e){let{debugMode:o}=Hx(Ne),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,qx(Vx.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,error:Q(e.outcome,e.htmlFor),"data-testid":e.testId,children:e.children})}import{capitalize as Gx,isEmpty as _f}from"@medplum/core";function Ot(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let f=o.replace("[x]",Gx(l.code));f in e&&delete e[f]}return e[t]=a,e}function $w(e){return!!e&&!_f(e.url)&&!_f(e.name)}import{Checkbox as Wg,Group as Xg,NativeSelect as Jg,Textarea as $g,TextInput as kn}from"@mantine/core";import{capitalize as Os,HTTP_HL7_ORG as _g,PropertyType as E}from"@medplum/core";import{useState as Kg}from"react";import{useState as Ux}from"react";import{jsx as Wx}from"react/jsx-runtime";function _o(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=Ux(o);function l(f){let i=zx(f);n(i),t&&t(i)}return Wx(Wo,{defaultValue:a&&Qx(a),onChange:l,...r})}function Qx(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function zx(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as Xx}from"react";import{jsx as _x}from"react/jsx-runtime";function Rr(e){let{defaultValue:o,onChange:t,...r}=e,[a,n]=Xx(o);function l(f){let i=f[0],s=i&&$x(i);n(s),t&&t(s)}return _x(Wo,{defaultValue:a&&Jx(a),maxSelectedValues:1,onChange:l,...r})}function Jx(e){return{system:e.system,code:e.code,display:e.display}}function $x(e){return{system:e.system,code:e.code,display:e.display}}import{Group as rI,TextInput as aI}from"@mantine/core";import{useRef as nI,useState as lI}from"react";import{Group as Kx,NativeSelect as Kf,TextInput as Zx}from"@mantine/core";import{useContext as Yx,useMemo as jx,useRef as eI,useState as oI}from"react";import{jsx as xn,jsxs as tI}from"react/jsx-runtime";function Pr(e){let{path:o,outcome:t}=e,{getModifiedNestedElement:r}=Yx(Ne),[a,n]=oI(e.defaultValue),l=eI();l.current=a;let[f,i,s]=jx(()=>["system","use","value"].map(p=>r(o+"."+p)),[r,o]);function u(p){p&&Object.keys(p).length===0&&(p=void 0),n(p),e.onChange&&e.onChange(p)}function c(p){let x={...l.current,system:p};p||delete x.system,u(x)}function d(p){let x={...l.current,use:p};p||delete x.use,u(x)}function m(p){let x={...l.current,value:p};p||delete x.value,u(x)}return tI(Kx,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[xn(Kf,{"data-testid":"system",defaultValue:a?.system,required:(f?.min??0)>0,onChange:p=>c(p.currentTarget.value),data:["","email","phone","fax","pager","sms","other"],error:Q(t,o+".system")}),xn(Kf,{"data-testid":"use",defaultValue:a?.use,required:(i?.min??0)>0,onChange:p=>d(p.currentTarget.value),data:["","home","work","temp","old","mobile"],error:Q(t,o+".use")}),xn(Zx,{placeholder:"Value",defaultValue:a?.value,required:(s?.min??0)>0,onChange:p=>m(p.currentTarget.value),error:Q(t,o+".value")})]})}import{jsx as Zf,jsxs as fI}from"react/jsx-runtime";function Yf(e){let[o,t]=lI(e.defaultValue),r=nI();r.current=o;function a(f){t(f),e.onChange&&e.onChange(f)}function n(f){let i={...r.current,name:f};f||delete i.name,a(i)}function l(f){let i={...r.current,telecom:f&&[f]};f||delete i.telecom,a(i)}return fI(rI,{spacing:"xs",grow:!0,noWrap:!0,children:[Zf(aI,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:f=>n(f.currentTarget.value)}),Zf(Pr,{name:e.name+"-telecom",path:e.path+".telecom",defaultValue:o?.telecom?.[0],onChange:l,outcome:e.outcome})]})}import{TextInput as sI}from"@mantine/core";import{isValidDate as jf}from"@medplum/core";function es(e){if(!e)return"";let o=new Date(e);return jf(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function os(e){if(!e)return"";let o=new Date(e);return jf(o)?o.toISOString():""}import{jsx as uI}from"react/jsx-runtime";function Ve(e){return uI(sI,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:iI(),defaultValue:es(e.defaultValue),autoFocus:e.autoFocus,error:Q(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(os(t))}}})}function iI(){return"datetime-local"}import{JsonInput as cI}from"@mantine/core";import{stringify as dI,tryGetProfile as mI}from"@medplum/core";import{useEffect as pI,useMemo as xI,useState as ts}from"react";import{jsx as In,jsxs as rs}from"react/jsx-runtime";function as(e){let{propertyType:o}=e,t=S(),[r,a]=ts(!1),[n,l]=ts(),f=xI(()=>{if(!(!o.profile||o.profile.length===0))return o.profile[0]},[o]);pI(()=>{f&&(a(!0),t.requestProfileSchema(f).then(()=>{let s=mI(f);a(!1),l(s)}).catch(s=>{a(!1),console.warn(s)}))},[t,f]);function i(s){e.onChange&&(console.log("Extension",s),e.onChange(s))}return f?r?rs("div",{children:["Loading ",f,"..."]}):n?In(Ko,{profileUrl:f,typeName:n.name,defaultValue:e.defaultValue,onChange:i}):rs("div",{children:["StructureDefinition for ",f," not found"]}):In(II,{...e})}function II(e){return In(cI,{id:e.name,name:e.name,"data-testid":"extension-json-input",defaultValue:dI(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as gI,NativeSelect as hI,TextInput as Tr}from"@mantine/core";import{useState as yI}from"react";import{jsx as Et,jsxs as vI}from"react/jsx-runtime";function ns(e){let{outcome:o,path:t}=e,[r,a]=yI(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 i(c){n({...r,given:c?c.split(" "):void 0})}function s(c){n({...r,family:c||void 0})}function u(c){n({...r,suffix:c?c.split(" "):void 0})}return vI(gI,{spacing:"xs",grow:!0,noWrap:!0,children:[Et(hI,{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:Q(o,t+".use")}),Et(Tr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:r?.prefix?.join(" "),onChange:c=>f(c.currentTarget.value),error:Q(o,t+".prefix")}),Et(Tr,{placeholder:"Given",name:e.name+"-given",defaultValue:r?.given?.join(" "),onChange:c=>i(c.currentTarget.value),error:Q(o,t+".given")}),Et(Tr,{name:e.name+"-family",placeholder:"Family",defaultValue:r?.family,onChange:c=>s(c.currentTarget.value),error:Q(o,t+".family")}),Et(Tr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:r?.suffix?.join(" "),onChange:c=>u(c.currentTarget.value),error:Q(o,t+".suffix")})]})}import{Group as SI,TextInput as ls}from"@mantine/core";import{useContext as CI,useMemo as bI,useState as RI}from"react";import{jsx as fs,jsxs as PI}from"react/jsx-runtime";function ss(e){let{path:o,outcome:t}=e,[r,a]=RI(e.defaultValue),{getModifiedNestedElement:n}=CI(Ne),[l,f]=bI(()=>["system","value"].map(s=>n(o+"."+s)),[n,o]);function i(s){a(s),e.onChange&&e.onChange(s)}return PI(SI,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[fs(ls,{placeholder:"System",required:(l?.min??0)>0,defaultValue:r?.system,onChange:s=>i({...r,system:s.currentTarget.value}),error:Q(t,o+".system")}),fs(ls,{placeholder:"Value",required:(f?.min??0)>0,defaultValue:r?.value,onChange:s=>i({...r,value:s.currentTarget.value}),error:Q(t,o+".value")})]})}import{NativeSelect as TI,TextInput as kI}from"@mantine/core";import{useCallback as gn,useState as DI}from"react";import{jsx as hn}from"react/jsx-runtime";var BI=["USD","EUR","CAD","GBP","AUD"];function is(e){let{onChange:o}=e,[t,r]=DI(e.defaultValue),a=gn(i=>{r(i),o&&o(i)},[o]),n=gn(i=>{a({...t,currency:i.currentTarget.value})},[t,a]),l=gn(i=>{a({...t,value:i.currentTarget.valueAsNumber})},[t,a]),f=hn(TI,{defaultValue:t?.currency,data:BI,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return hn(kI,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:hn(Ga,{size:14}),rightSection:f,rightSectionWidth:92,onChange:l})}import{Group as AI}from"@mantine/core";import{useState as MI}from"react";import{jsx as us,jsxs as FI}from"react/jsx-runtime";function cs(e){let[o,t]=MI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return FI(AI,{spacing:"xs",grow:!0,noWrap:!0,children:[us(Ve,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),us(Ve,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as wI,NativeSelect as OI,TextInput as ds}from"@mantine/core";import{useState as EI}from"react";import{jsx as yn,jsxs as NI}from"react/jsx-runtime";function Ae(e){let[o,t]=EI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return NI(wI,{spacing:"xs",grow:!0,noWrap:!0,children:[yn(OI,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),yn(ds,{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:LI(a.currentTarget.value)})}}),yn(ds,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function LI(e){if(e)return parseFloat(e)}import{Group as VI}from"@mantine/core";import{useState as HI}from"react";import{jsx as ms,jsxs as qI}from"react/jsx-runtime";function Lt(e){let[o,t]=HI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return qI(VI,{spacing:"xs",grow:!0,noWrap:!0,children:[ms(Ae,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),ms(Ae,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as GI}from"@mantine/core";import{useState as UI}from"react";import{jsx as ps,jsxs as QI}from"react/jsx-runtime";function xs(e){let[o,t]=UI(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return QI(GI,{spacing:"xs",grow:!0,noWrap:!0,children:[ps(Ae,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),ps(Ae,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as jI,NativeSelect as eg}from"@mantine/core";import{LRUCache as og,ReadablePromise as tg,createReference as rg,isEmpty as ag,isPopulated as ng,tryGetProfile as lg}from"@medplum/core";import{useCallback as fg,useEffect as sg,useMemo as vs,useRef as ig,useState as vn}from"react";import{Group as zI,Text as Is}from"@mantine/core";import{getDisplayString as WI,getReferenceString as ys}from"@medplum/core";import{forwardRef as XI,useCallback as gs,useState as JI}from"react";import{jsx as Nt,jsxs as hs}from"react/jsx-runtime";var $I={Observation:"code",User:"email:contains"},_I=["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 KI(e){return{value:ys(e),label:WI(e),resource:e}}function kr(e){let o=S(),{resourceType:t,searchCriteria:r}=e,[a,n]=JI(),l=X(e.defaultValue,n),f=e.onChange,i=gs(async(u,c)=>{let d=YI(t),m=new URLSearchParams({[d]:u??"",_count:"10",...r});return await o.searchResources(t,m,{signal:c})},[o,t,r]),s=gs(u=>{f&&f(u[0])},[f]);return e.defaultValue&&!a&&!l?null:Nt(Qo,{name:e.name,required:e.required,itemComponent:ZI,defaultValue:l,placeholder:e.placeholder,maxSelectedValues:1,toKey:ys,toOption:KI,loadOptions:i,onChange:s,clearable:!0})}var ZI=XI(({label:e,resource:o,...t},r)=>Nt("div",{ref:r,...t,children:hs(zI,{noWrap:!0,children:[Nt(fe,{value:o}),hs("div",{children:[Nt(Is,{children:e}),Nt(Is,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function YI(e){return $I[e]??(_I.includes(e)?"name":"_id")}import{jsx as Sn,jsxs as pg}from"react/jsx-runtime";function Zo(e){let{onChange:o}=e,t=S(),[r,a]=vn(e.defaultValue),[n,l]=vn(()=>ug(e.targetTypes)),[f,i]=vn(()=>cg(e.defaultValue,n)),s=ig(new og),u=vs(()=>f?.type==="profile"?{...e.searchCriteria,_profile:f.value}:e.searchCriteria,[e.searchCriteria,f]);sg(()=>{let m=!1,p=n?.map(x=>{if(!mg(x))return Promise.resolve(x);m=!0;let C=x.value,y=s.current.get(C);if(y)return y;let v=dg(t,x.value).then(P=>{let h={...x};return P?ng(P.type)?(h.resourceType=P.type,h.name=P.name,h.title=P.title):(console.error(`StructureDefinition.type missing for ${x.value}`),h.error="StructureDefinition.type missing"):(console.error(`StructureDefinition not found for ${x.value}`),h.error="StructureDefinition not found"),h}).catch(P=>(console.error(P),{...x,error:P})),b=new tg(v);return s.current.set(C,b),b});!p||!m||Promise.all(p).then(x=>{if(l(x),!f)return;let C=x.findIndex(y=>y.value===f.value||y.resourceType===f.resourceType);if(C===-1){console.debug(`defaultValue had unexpected resourceType: ${f.resourceType}`);return}i(x[C])}).catch(console.error)},[t,f,n]);let c=fg(m=>{let p=m?rg(m):void 0;a(p),o&&o(p)},[o]),d=vs(()=>n?n.map(m=>({value:m.value,label:m.type==="profile"?m.title??m.name??m.resourceType??m.value:m.value})):[],[n]);return pg(jI,{spacing:"xs",grow:!0,noWrap:!0,children:[n&&n.length>1&&Sn(eg,{"data-autofocus":e.autoFocus,"data-testid":"reference-input-resource-type-select",defaultValue:f?.resourceType,autoFocus:e.autoFocus,onChange:m=>{let p=m.currentTarget.value,x=n.find(C=>C.value===p);i(x)},data:d}),!n&&Sn(Xo,{autoFocus:e.autoFocus,testId:"reference-input-resource-type-input",defaultValue:f?.resourceType,onChange:m=>{i(m?{type:"resourceType",value:m,resourceType:m}:void 0)},name:e.name+"-resourceType",placeholder:"Resource Type"}),Sn(kr,{resourceType:f?.resourceType,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:c})]})}function ug(e){if(!e||e.length===0||e.length===1&&e[0]==="Resource")return;let o=[];for(let t of e)t.includes("/")?o.push({type:"profile",value:t}):o.push({type:"resourceType",value:t,resourceType:t});return o}function cg(e,o){let t=e?.reference?.split("/")[0];if(t){let r=o?.find(a=>a.resourceType===t);return r||{type:"resourceType",value:t,resourceType:t}}if(o&&o.length>0)return o[0]}async function dg(e,o){let t=lg(o);if(t)return{type:t.type,name:t.name,title:t.title};let r=`{
|
|
66
66
|
StructureDefinitionList(url: "${o}", _sort: "_lastUpdated", _count: 1) {
|
|
67
67
|
type,
|
|
68
68
|
name,
|
|
69
69
|
title,
|
|
70
70
|
}
|
|
71
|
-
}`.replace(/\s+/g," ");return(await e.graphql(r)).data.StructureDefinitionList[0]}function mg(e){return e.type==="profile"&&!e?.error&&ag(e.resourceType)}import{ActionIcon as Cs,Button as Cg,Group as Dr,Stack as bn,createStyles as bg}from"@mantine/core";import{getPathDisplayName as Rg,getPropertyDisplayName as Pg,isEmpty as Rn,tryGetProfile as Tg}from"@medplum/core";import{useEffect as kg,useState as Vt}from"react";import{arrayify as xg,getElementDefinitionFromElements as Ig,getTypedPropertyValueWithSchema as gg,isPopulated as hg,matchDiscriminant as yg}from"@medplum/core";function vg(e,o,t){for(let r of[t.elements,t.typeSchema?.elements]){let a;if(hg(r)){let n=Ig(r,o.path);n&&(a=gg(e.value,o.path,n))}if(a)return xg(a)?.some(n=>yg(n,o,t,r))??!1}return!1}function Sg(e,o,t){if(e)for(let r of o){let a={value:e,type:r.typeSchema?.name??r.type[0].code};if(t.every(n=>vg(a,n,r)))return r.name}}function Cn(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=Sg(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 Ss(e){return e.type!==void 0&&e.type.length>0}import{jsx as oe,jsxs as Ar}from"react/jsx-runtime";var bs=bg(e=>({indented:{marginTop:"0.5rem",borderLeft:`3px solid ${e.colors.gray[4]}`,padding:"0.5rem 0 0.5rem 0.5rem"}}));function Rs(e){let{property:o}=e,t=S(),[r,a]=Vt(!0),[n,l]=Vt([]),[f]=Vt(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[i,s]=Vt([[]]),{classes:u}=bs(),c=o.type[0]?.code;kg(()=>{if(!o.slicing){let P=[];l(P);let h=Cn(f,P,o.slicing);s(h),a(!1);return}let y=[],v=[],b=[];for(let P of o.slicing.slices){if(!Ss(P))continue;let h=P.type[0],B;Rn(P.elements)&&h.profile&&(B=h.profile[0]),y.push(P),v.push(B),B?b.push(t.requestProfileSchema(B)):b.push(Promise.resolve())}Promise.all(b).then(()=>{for(let h=0;h<y.length;h++){let B=y[h],W=v[h];if(W){let Y=Tg(W);B.typeSchema=Y}}l(y);let P=Cn(f,y,o.slicing);s(P),a(!1)}).catch(P=>{console.error(P),a(!1)})},[t,o.slicing,c,f]);function d(y,v){let b=[...i];if(b[v]=y,s(b),e.onChange){let P=b.flat().filter(h=>h!==void 0);e.onChange(P)}}if(r)return oe("div",{children:"Loading..."});let m=n.length,p=i[m],x=!(e.hideNonSliceValues??(c==="Extension"&&n.length>0)),C=Rg(o.path);return Ar(bn,{className:e.indent?u.indented:void 0,children:[n.map((y,v)=>oe(Dg,{slice:y,property:o,defaultValue:i[v],onChange:b=>{d(b,v)},testId:`slice-${y.name}`},y.name)),x&&p.map((y,v)=>Ar(Dr,{noWrap:!0,style:{flexGrow:1},children:[oe("div",{style:{flexGrow:1},children:oe(io,{arrayElement:!0,property:e.property,name:e.name+"."+v,defaultValue:y,onChange:b=>{let P=[...p];P[v]=b,d(P,m)},defaultPropertyType:void 0,outcome:e.outcome})}),oe(Ts,{propertyDisplayName:C,testId:`nonsliced-remove-${v}`,onClick:b=>{M(b);let P=[...p];P.splice(v,1),d(P,m)}})]},`${v}-${p.length}`)),x&&i.flat().length<o.max&&oe(Dr,{noWrap:!0,style:{justifyContent:"flex-start"},children:oe(Ps,{propertyDisplayName:C,onClick:y=>{M(y);let v=[...p];v.push(void 0),d(v,m)},testId:"nonsliced-add"})})]})}function Dg(e){let{slice:o,property:t}=e,[r,a]=Vt(()=>e.defaultValue.map(u=>u??{})),{classes:n}=bs();function l(u){a(u),e.onChange&&e.onChange(u)}let f=o.min>0,i=Rn(o.elements),s=Pg(o.name);return oe(pe,{title:s,description:o.definition,withAsterisk:f,fhirPath:`${t.path}:${o.name}`,testId:e.testId,children:Ar(bn,{className:i?n.indented:void 0,children:[r.map((u,c)=>Ar(Dr,{noWrap:!0,children:[oe("div",{style:{flexGrow:1},children:oe(bn,{children:Rn(o.elements)?oe(Br,{elementDefinitionType:o.type[0],name:o.name,defaultValue:u,onChange:d=>{let m=[...r];m[c]=d,l(m)},outcome:void 0,min:o.min,max:o.max,binding:void 0,path:o.path}):oe(Mr,{type:o.type[0].code,elements:o.elements,defaultValue:u,outcome:e.outcome,onChange:d=>{let m=[...r];m[c]=d,l(m)},testId:e.testId&&`${e.testId}-elements-${c}`})})}),r.length>o.min&&oe(Ts,{propertyDisplayName:s,testId:e.testId&&`${e.testId}-remove-${c}`,onClick:d=>{M(d);let m=[...r];m.splice(c,1),l(m)}})]},`${c}-${r.length}`)),r.length<o.max&&oe(Dr,{noWrap:!0,style:{justifyContent:"flex-start"},children:oe(Ps,{propertyDisplayName:s,onClick:u=>{M(u);let c=[...r,void 0];l(c)},testId:e.testId&&`${e.testId}-add`})})]})})}function Ps({propertyDisplayName:e,onClick:o,testId:t}){let r=e?`Add ${e}`:"Add";return e?oe(Cg,{title:r,size:"sm",color:"green.6",variant:"subtle","data-testid":t,leftIcon:oe(So,{size:"1.25rem"}),onClick:o,children:r}):oe(Cs,{title:r,color:"green.6","data-testid":t,onClick:o,children:oe(So,{size:"1.25rem"})})}function Ts({propertyDisplayName:e,onClick:o,testId:t}){return oe(Cs,{title:e?`Remove ${e}`:"Remove",color:"red.5","data-testid":t,onClick:o,children:oe(lo,{size:"1.25rem"})})}import{ActionIcon as Ag,Flex as Bg,Textarea as Mg}from"@mantine/core";import{useClipboard as Fg}from"@mantine/hooks";import{showNotification as wg}from"@mantine/notifications";import{useRef as Og,useState as Eg}from"react";import{jsx as Pn,jsxs as Lg}from"react/jsx-runtime";function ks(e){let[o,t]=Eg(!1),r=Fg(),a=Og(null),n={...e.styles};return o||(n.input||(n.input={}),n.input.WebkitTextSecurity="disc"),Lg(Bg,{gap:"xs",children:[Pn(Mg,{...e,styles:{...n,root:{...n.root??{},flexGrow:1}},ref:a,autosize:!0,minRows:1,onFocus:()=>t(!0),onBlur:()=>t(!1)}),Pn(Ag,{title:"Copy secret",onClick:()=>{r.copy(a.current?.value),wg({color:"green",message:"Copied"})},children:Pn(Pt,{})})]})}import{Button as Bs,Chip as Ds,Group as Fr,Modal as Ng,NativeSelect as Vg,Stack as Hg,Switch as qg,TextInput as Gg}from"@mantine/core";import{formatTiming as Ug}from"@medplum/core";import{useRef as Ms,useState as Tn}from"react";import{Fragment as ws,jsx as de,jsxs as Ht}from"react/jsx-runtime";var Qg=["sun","mon","tue","wed","thu","fri","sat"];function Fs(e){let[o,t]=Tn(e.defaultValue),[r,a]=Tn(!1),n=Ms();return n.current=o,Ht(ws,{children:[Ht(Fr,{spacing:"xs",grow:!0,noWrap:!0,children:[de("span",{children:Ug(n.current)||"No repeat"}),de(Bs,{onClick:()=>a(!0),children:"Edit"})]}),de(zg,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var As={repeat:{period:1,periodUnit:"d"}};function zg(e){let[o,t]=Tn(e.defaultValue||As),r=Ms();r.current=o;function a(s){t({...r.current,event:[s]})}function n(s){t({...r.current,repeat:s})}function l(s){n({...r.current?.repeat,period:s})}function f(s){n({...r.current?.repeat,periodUnit:s})}function i(s){n({...r.current?.repeat,dayOfWeek:s})}return de(Ng,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:Ht(Hg,{children:[de(pe,{title:"Starts on",htmlFor:"timing-dialog-start",children:de(Ve,{name:"timing-dialog-start",onChange:s=>a(s)})}),de(qg,{label:"Repeat",checked:!!o.repeat,onChange:s=>n(s.currentTarget.checked?As.repeat:void 0)}),o.repeat&&Ht(ws,{children:[de(pe,{title:"Repeat every",htmlFor:"timing-dialog-period",children:Ht(Fr,{spacing:"xs",grow:!0,noWrap:!0,children:[de(Gg,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:s=>l(parseInt(s.currentTarget.value,10)||1)}),de(Vg,{id:"timing-dialog-periodUnit",name:"timing-dialog-periodUnit",defaultValue:o.repeat.periodUnit,onChange:s=>f(s.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"&&de(pe,{title:"Repeat on",children:de(Ds.Group,{multiple:!0,onChange:i,children:de(Fr,{position:"apart",mt:"md",spacing:"xs",children:Qg.map(s=>de(Ds,{value:s,size:"xs",radius:"xl",children:s.charAt(0).toUpperCase()},s))})})})]}),de(Fr,{position:"right",children:de(Bs,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as q,jsxs as eh}from"react/jsx-runtime";function io(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.isArray||o.max>1)&&!e.arrayElement){if(n===E.Attachment)return q(wf,{name:t,defaultValue:r,onChange:a});let f=l[0]?.code!==E.Extension;return q(Rs,{property:o,name:t,defaultValue:r,indent:f,onChange:a,outcome:e.outcome})}return l.length>1?q(Zg,{elementDefinitionTypes:l,...e}):q(Br,{name:t,defaultValue:r,onChange:f=>{if(e.onChange){let i=e.name.replace("[x]",Os(l[0].code));e.onChange(f,i)}},outcome:e.outcome,elementDefinitionType:l[0],min:o.min,max:o.min,binding:o.binding,path:o.path})}function Zg(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=Kg(t);return eh(Xg,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[q(Jg,{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}))}),q(Br,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",Os(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path})]})}function Br(e){let{name:o,defaultValue:t,onChange:r,outcome:a,binding:n,path:l}=e,f=e.min!==void 0&&e.min>0,i=e.elementDefinitionType.code;if(!i)return q("div",{children:"Property type not specified "});let s={name:o,defaultValue:t,onChange:r,outcome:a,path:l};switch(i){case E.SystemString:case E.canonical:case E.string:case E.time:case E.uri:case E.url:return e.path==="Project.secret.value[x]"?q(ks,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{e.onChange&&e.onChange(u.currentTarget.value)},error:Q(e.outcome,o)}):q(kn,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:Q(a,o)});case E.date:return q(kn,{type:"date",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:Q(a,o)});case E.dateTime:case E.instant:return q(Ve,{name:o,defaultValue:t,onChange:r,outcome:a});case E.decimal:case E.integer:case E.positiveInt:case E.unsignedInt:return q(kn,{type:"number",step:i===E.decimal?"any":"1",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.valueAsNumber)}});case E.code:return q(mr,{...s,binding:n?.valueSet});case E.boolean:return q(Wg,{id:o,name:o,"data-testid":o,defaultChecked:!!t,onChange:u=>{r&&r(u.currentTarget.checked)}});case E.base64Binary:case E.markdown:return q($g,{id:o,spellCheck:i!==E.base64Binary,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)}});case E.Address:return q(tf,{...s});case E.Annotation:return q(rf,{...s});case E.Attachment:return q(xr,{...s});case E.CodeableConcept:return q(_o,{binding:n?.valueSet,...s});case E.Coding:return q(Rr,{binding:n?.valueSet,...s});case E.ContactDetail:return q(Yf,{...s});case E.ContactPoint:return q(Pr,{...s});case E.Extension:return q(as,{...s,propertyType:e.elementDefinitionType});case E.HumanName:return q(ns,{...s});case E.Identifier:return q(ss,{...s});case E.Money:return q(is,{...s});case E.Period:return q(cs,{...s});case E.Duration:case E.Quantity:return q(Be,{...s});case E.Range:return q(Lt,{...s});case E.Ratio:return q(xs,{...s});case E.Reference:return q(Zo,{...s,targetTypes:jg(e.elementDefinitionType)});case E.Timing:return q(Fs,{...s});case E.Dosage:case E.UsageContext:default:return q(Ko,{typeName:i,defaultValue:t,onChange:r,outcome:a})}}var Yg=[`${_g}/fhir/StructureDefinition/`,"https://medplum.com/fhir/StructureDefinition/"];function jg(e){return e?.targetProfile?.map(o=>{let t=Yg.find(r=>o.startsWith(r));return t?o.slice(t.length):o})}import{jsx as wr}from"react/jsx-runtime";var Dn=new Set(["extension","modifierExtension"]),nh=new Set(["id",...Ir].filter(e=>!Dn.has(e)));function Mr(e){let{elements:o}=e,[t,r]=ah(e.defaultValue??{}),a=rh(()=>{let l=Object.create(null);for(let[f,i]of Object.entries(o))i.fixed&&(l[f]=i);return l},[o]);function n(l){for(let[f,i]of Object.entries(a))Ot(l,f,f,i,i.fixed.value);r(l),e.onChange&&e.onChange(l)}return wr(oh,{style:{flexGrow:1},"data-testid":e.testId,children:Object.entries(o).map(([l,f])=>{if(!f.type||f.max===0||l==="url"&&f.fixed||Dn.has(l)&&!th(f.slicing?.slices))return null;if(nh.has(l))return null;if(gr.includes(l)&&f.path.split(".").length===2||l.includes("."))return null;let[i,s]=Xf(t,l,f),u=f.min!==void 0&&f.min>0,c=wr(io,{property:f,name:l,defaultValue:i,defaultPropertyType:s,onChange:(d,m)=>{n(Ot({...t},l,m??l,f,d))},arrayElement:void 0,outcome:e.outcome},l);return e.type==="Extension"||Dn.has(l)?c:f.type.length===1&&f.type[0].code==="boolean"?wr(Cr,{title:Es(l),description:f.description,htmlFor:l,fhirPath:f.path,withAsterisk:u,children:c},l):wr(pe,{title:Es(l),description:f.description,withAsterisk:u,htmlFor:l,outcome:e.outcome,fhirPath:f.path,children:c},l)})})}import{jsx as Ns,jsxs as ih}from"react/jsx-runtime";function Ko(e){let{typeName:o}=e,[t,r]=sh(e.defaultValue??{}),a=fh(Ne),n=e.profileUrl??a.profileUrl,l=Ls(()=>lh(o,n),[o,n]),f=Ls(()=>Jf(l,n),[l,n]);if(!l)return ih("div",{children:[o,"\xA0not implemented"]});function i(s){r(s),e.onChange&&e.onChange(s)}return Ns(Ne.Provider,{value:f,children:Ns(Mr,{type:l.type,elements:l.elements,defaultValue:t,onChange:i,outcome:e.outcome})})}import{Button as An,createStyles as uh,Group as Hs}from"@mantine/core";import{useMemo as ch,useState as dh}from"react";function Vs(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function Or(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as xe,jsxs as qt}from"react/jsx-runtime";var mh=uh(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 qs(e){let{classes:o}=mh(),{onChangeMonth:t,onClick:r}=e,[a,n]=dh(Or);function l(i){n(s=>{let u=new Date(s.getTime());return u.setMonth(s.getMonth()+i),t(u),u})}let f=ch(()=>ph(a,e.slots),[a,e.slots]);return qt("div",{children:[qt(Hs,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[xe("p",{style:{flex:1},children:Vs(a)}),qt(Hs,{position:"right",spacing:"xs",children:[xe(An,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),xe(An,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),qt("table",{className:o.table,children:[xe("thead",{children:qt("tr",{children:[xe("th",{children:"SUN"}),xe("th",{children:"MON"}),xe("th",{children:"TUE"}),xe("th",{children:"WED"}),xe("th",{children:"THU"}),xe("th",{children:"FRI"}),xe("th",{children:"SAT"})]})}),xe("tbody",{children:f.map((i,s)=>xe("tr",{children:i.map((u,c)=>xe("td",{children:u&&xe(An,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+c))},"week-"+s))})]})]})}function ph(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:xh(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 xh(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 Ih,createStyles as gh}from"@mantine/core";import{jsx as yh}from"react/jsx-runtime";var hh=gh(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function uo(e){let{children:o,...t}=e,{classes:r}=hh();return yh(Ih,{className:r.root,...t,children:o})}import{ActionIcon as Si,Center as By,createStyles as My,Group as Fy,Loader as wy,Menu as je,ScrollArea as Oy,TextInput as Ey}from"@mantine/core";import{showNotification as Ly,updateNotification as qr}from"@mantine/notifications";import{getReferenceString as Qt,normalizeErrorString as Ci}from"@medplum/core";import{useCallback as Gr,useEffect as Ny,useRef as bi,useState as Ri}from"react";import{createStyles as Oh,Group as Lr,List as zs,Stack as Ws,Text as Me,Title as Xs}from"@mantine/core";import{capitalize as Eh,formatCodeableConcept as Lh,formatDateTime as Mn,formatObservationValue as Nh,isReference as Vh}from"@medplum/core";import{useEffect as Hh,useState as qh}from"react";import{Blockquote as vh,createStyles as Sh,Stack as Ch}from"@mantine/core";import{jsx as Gs}from"react/jsx-runtime";var bh=Sh(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function Bn({value:e}){let{classes:o}=bh();return e?Gs(Ch,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&Gs(vh,{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 Ah}from"@mantine/core";import{Text as Rh}from"@mantine/core";import{getDisplayString as Ph,isOk as Th,normalizeErrorString as kh}from"@medplum/core";import{useState as Dh}from"react";import{jsx as Us}from"react/jsx-runtime";function Ue(e){let{value:o,link:t,...r}=e,[a,n]=Dh(),l=X(o,n),f;if(a&&!Th(a))f=`[${kh(a)}]`;else if(l)f=Ph(l);else return null;return t?Us(le,{to:o,...r,children:f}):Us(Rh,{component:"span",...r,children:f})}import{jsx as Qs,jsxs as Bh}from"react/jsx-runtime";function co(e){return Bh(Ah,{spacing:"xs",children:[Qs(fe,{size:24,radius:12,value:e.value,link:e.link}),Qs(Ue,{value:e.value,link:e.link})]})}import{Badge as Mh}from"@mantine/core";import{jsx as wh}from"react/jsx-runtime";var Fh={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 Er(e){return wh(Mh,{color:Fh[e.status],children:e.status})}import{Fragment as Gt,jsx as k,jsxs as Ie}from"react/jsx-runtime";var Js=Oh(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}}));Fn.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function Fn(e){let o=S(),t=X(e.value),[r,a]=qh();if(Hh(()=>{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 Ie(Ws,{children:[k(Xs,{children:"Diagnostic Report"}),k(Gh,{value:t}),r&&!e.hideSpecimenInfo&&Uh(r),t.result&&k(Qh,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&k(Bn,{value:n})]})}function Gh({value:e}){return Ie(Lr,{mt:"md",spacing:30,children:[e.subject&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),k(Me,{children:k(co,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),k(Me,{children:k(co,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),k(Me,{children:k(co,{value:o,link:!0})})]},o.reference)),e.issued&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),k(Me,{children:Mn(e.issued)})]}),e.status&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),k(Me,{children:Eh(e.status)})]})]})}function Uh(e){return Ie(Ws,{spacing:"xs",children:[k(Xs,{order:2,size:"h6",children:"Specimens"}),k(zs,{type:"ordered",children:e?.map(o=>k(zs.Item,{ml:"sm",children:Ie(Lr,{spacing:20,children:[Ie(Lr,{spacing:5,children:[k(Me,{fw:500,children:"Collected:"})," ",Mn(o.collection?.collectedDateTime)]}),Ie(Lr,{spacing:5,children:[k(Me,{fw:500,children:"Received:"})," ",Mn(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Qh(e){let{classes:o}=Js();return Ie("table",{className:o.table,children:[k("thead",{children:Ie("tr",{children:[k("th",{children:"Test"}),k("th",{children:"Value"}),k("th",{children:"Reference Range"}),k("th",{children:"Interpretation"}),k("th",{children:"Category"}),k("th",{children:"Performer"}),k("th",{children:"Status"})]})}),k("tbody",{children:k($s,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function $s(e){return k(Gt,{children:e.value?.map(o=>k(zh,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${Vh(o)?o.reference:o.id}`))})}function zh(e){let{classes:o,cx:t}=Js(),r=X(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=Jh(r);return Ie(Gt,{children:[Ie("tr",{className:t({[o.criticalRow]:n}),children:[k("td",{rowSpan:a?2:1,children:k(le,{to:r,children:k(ye,{value:r.code})})}),k("td",{children:k(Wh,{value:r})}),k("td",{children:k(Xh,{value:r.referenceRange})}),k("td",{children:r.interpretation&&r.interpretation.length>0&&k(ye,{value:r.interpretation[0]})}),k("td",{children:r.category&&r.category.length>0&&k(Gt,{children:r.category.map(l=>k("div",{children:k(ye,{value:l})},`category-${Lh(l)}`))})}),k("td",{children:r.performer?.map(l=>k(To,{value:l},l.reference))}),k("td",{children:r.status&&k(Er,{status:r.status})})]}),r.hasMember&&k($s,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&k("tr",{children:k("td",{colSpan:6,children:k(Bn,{value:r.note})})})]})}function Wh(e){let o=e.value;return k(Gt,{children:Nh(o)})}function Xh(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?k(Gt,{children:o.text}):k(yr,{value:o}):null}function Jh(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as $h,Paper as _h,useComponentDefaultProps as Kh}from"@mantine/core";import{jsx as jh}from"react/jsx-runtime";var Zh=$h((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%"}}})),Yh={shadow:"xs",radius:"md",withBorder:!0};function Yo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Kh("Panel",Yh,e),{classes:f,cx:i}=Zh({width:r,fill:a},{name:"Panel",unstyled:n});return jh(_h,{className:i(f.paper,o),...l,children:t})}import{createStyles as xy}from"@mantine/core";import{capitalize as Iy,evalFhirPathTyped as ui,getSearchParameterDetails as gy,toTypedValue as ci}from"@medplum/core";var mi=gd(ii(),1);import{useEffect as hy,useState as yy}from"react";import{jsx as Ye,jsxs as Hr}from"react/jsx-runtime";var vy=xy(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 pi(e){let{classes:o}=vy(),t=S(),[r,a]=yy(!1);if(hy(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,mi.createPatch)(e.original,e.revised),l=[ci(e.original)],f=[ci(e.revised)];return Hr("table",{className:o.root,children:[Ye("thead",{children:Hr("tr",{children:[Ye("th",{}),Ye("th",{children:"Before"}),Ye("th",{children:"After"})]})}),Ye("tbody",{children:n.map(i=>{if(i.path.startsWith("/meta"))return null;let s=i.path,u=Sy(s),d=gy(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],m=!!d?.isArray,p=i.op==="add"?void 0:ui(u,l)?.[0],x=i.op==="remove"?void 0:ui(u,f)?.[0];return Hr("tr",{children:[Hr("td",{children:[Iy(i.op)," ",u]}),Ye("td",{className:o.removed,children:p&&Ye(ce,{property:d,propertyType:p.type,value:di(p.value,m),ignoreMissingValues:!0})}),Ye("td",{className:o.added,children:x&&Ye(ce,{property:d,propertyType:x.type,value:di(x.value,m),ignoreMissingValues:!0})})]},`op-${i.op}-${i.path}`)})})]})}function Sy(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 di(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as Cy,useState as by}from"react";import{jsx as Ry}from"react/jsx-runtime";function zn(e){let o=S(),t=X(e.value),[r,a]=by(!1);return Cy(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:Ry(wt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as Py,Group as Ty,Menu as xi,Text as Wn}from"@mantine/core";import{formatDateTime as ky,getReferenceString as Dy}from"@medplum/core";import{Fragment as Ay,jsx as Fe,jsxs as jo}from"react/jsx-runtime";function Ii(e){return Fe(uo,{children:e.children})}function mo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,f=e.dateTime??o.meta?.lastUpdated;return jo(Yo,{"data-testid":"timeline-item",fill:!0,...n,children:[jo(Ty,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Fe(fe,{value:l,link:!0,size:"md"}),jo("div",{style:{flex:1},children:[Fe(Wn,{size:"sm",children:Fe(Ue,{color:"dark",weight:500,value:l,link:!0})}),jo(Wn,{size:"xs",children:[Fe(le,{color:"dimmed",to:e.resource,children:ky(f)}),Fe(Wn,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Fe(le,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&jo(xi,{position:"bottom-end",shadow:"md",width:200,children:[Fe(xi.Target,{children:Fe(Py,{radius:"xl","aria-label":`Actions for ${Dy(e.resource)}`,children:Fe(Ua,{})})}),a]})]}),jo(Go,{children:[r&&Fe("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Fe(Ay,{children:e.children})]})]})}function yi(e,o){e.sort((t,r)=>{let a=gi(t,o),n=gi(r,o);return a>n?1:a<n?-1:hi(t,o)-hi(r,o)})}function gi(e,o){if(!vi(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function hi(e,o){if(!vi(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 vi(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as Xy,jsx as D,jsxs as zt}from"react/jsx-runtime";var Vy=My(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function po(e){let o=S(),t=no(),r=o.getProfile(),a=bi(null),n=X(e.value),[l,f]=Ri(),[i,s]=Ri([]),u=e.loadTimelineResources,c=bi(i);c.current=i;let d=Gr(R=>{yi(R,n),R.reverse(),s(R)},[n]),m=Gr(R=>{let N=[];for(let ao of R){if(ao.status!=="fulfilled")continue;let T=ao.value;if(T.type==="history"&&f(T),T.entry)for(let G of T.entry)N.push(G.resource)}d(N)},[d]),p=Gr(R=>d([...c.current,R]),[d]),x=Gr(()=>{let R,N;"resourceType"in e.value?(R=e.value.resourceType,N=e.value.id):[R,N]=e.value.reference?.split("/"),u(o,R,N).then(m).catch(console.log)},[o,e.value,u,m]);Ny(()=>x(),[x]);function C(R){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,R)).then(N=>p(N)).catch(console.log)}function y(R){!n||!e.createMedia||o.createResource(e.createMedia(n,r,R)).then(N=>p(N)).then(()=>qr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:D(bt,{size:16}),autoClose:2e3})).catch(N=>qr({id:"upload-notification",color:"red",title:"Upload error",message:Ci(N),icon:D(fr,{size:16}),autoClose:2e3}))}function v(R,N){return o.updateResource({...R,priority:N})}function b(R){v(R,"stat").then(x).catch(console.log)}function P(R){v(R,"routine").then(x).catch(console.log)}function h(R){t(`/${R.resourceType}/${R.id}`)}function B(R){t(`/${R.resourceType}/${R.id}/edit`)}function W(R){t(`/${R.resourceType}/${R.id}/delete`)}function Y(R){t(`/${R.resourceType}/${R.id}/_history/${R.meta?.versionId}`)}function gt(){Ly({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function ke(R){qr({id:"upload-notification",loading:!0,title:"Uploading...",message:Wy(R),autoClose:!1,withCloseButton:!1})}function De(R){qr({id:"upload-notification",color:"red",title:"Upload error",message:Ci(R),icon:D(fr,{size:16}),autoClose:2e3})}return n?zt(Ii,{children:[e.createCommunication&&D(Yo,{children:D(H,{testid:"timeline-form",onSubmit:R=>{C(R.text);let N=a.current;N&&(N.value="",N.focus())},children:zt(Fy,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[D(fe,{value:r}),D(Ey,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),D(Si,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:D(_a,{size:16})}),D(Jo,{onUpload:y,onUploadStart:gt,onUploadProgress:ke,onUploadError:De,children:R=>D(Si,{...R,radius:"xl",color:"blue",variant:"filled",children:D(Rt,{size:16})})})]})})}),i.map(R=>{if(!R)return null;let N=`${R.resourceType}/${R.id}/${R.meta?.versionId}`;if(R.resourceType===n.resourceType&&R.id===n.id)return D(Hy,{history:l,resource:R,onDetails:Y},N);switch(R.resourceType){case"AuditEvent":return D(Qy,{resource:R,onDetails:h},N);case"Communication":return D(Gy,{resource:R,onPin:R.priority!=="stat"?b:void 0,onUnpin:R.priority==="stat"?P:void 0,onDetails:h,onEdit:B,onDelete:W},N);case"DiagnosticReport":return D(zy,{resource:R,onDetails:h,onEdit:B,onDelete:W},N);case"Media":return D(Uy,{resource:R,onDetails:h,onEdit:B,onDelete:W},N);default:return D(mo,{resource:R,padding:!0,children:D(zn,{value:R,ignoreMissingValues:!0})},N)}})]}):D(By,{style:{width:"100%",height:"100%"},children:D(wy,{})})}function et(e){return zt(je.Dropdown,{children:[D(je.Label,{children:"Resource"}),e.onPin&&D(je.Item,{icon:D(Ka,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Qt(e.resource)}`,children:"Pin"}),e.onUnpin&&D(je.Item,{icon:D(Za,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Qt(e.resource)}`,children:"Unpin"}),e.onDetails&&D(je.Item,{icon:D(Ja,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Qt(e.resource)}`,children:"Details"}),e.onEdit&&D(je.Item,{icon:D(Qa,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Qt(e.resource)}`,children:"Edit"}),e.onDelete&&zt(Xy,{children:[D(je.Divider,{}),D(je.Label,{children:"Danger zone"}),D(je.Item,{color:"red",icon:D(Dt,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Qt(e.resource)}`,children:"Delete"})]})]})}function Hy(e){let o=qy(e.history,e.resource);return o?D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(pi,{original:o,revised:e.resource})}):zt(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:[D("h3",{children:"Created"}),D(zn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function qy(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 Gy(e){let{classes:o}=Vy(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return D(mo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:D(et,{...e}),children:D("p",{children:e.resource.payload?.[0]?.contentString})})}function Uy(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return D(mo,{resource:e.resource,padding:!!t,popupMenuItems:D(et,{...e}),children:D(Ge,{value:e.resource.content})})}function Qy(e){return D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(Oy,{children:D("pre",{children:e.resource.outcomeDesc})})})}function zy(e){return D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(Fn,{value:e.resource})})}function Wy(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Xn(e.loaded)} / ${Xn(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Xn(e.loaded)}`}function Xn(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 Jy}from"react/jsx-runtime";function t2(e){return Jy(po,{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 Pi}from"react/jsx-runtime";function Ur(e){let{children:o,...t}=e;return Pi(uo,{children:Pi(Yo,{...t,children:o})})}import{createReference as Qr}from"@medplum/core";import{jsx as $y}from"react/jsx-runtime";function p2(e){return $y(po,{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:Qr(o),subject:o.subject,sender:Qr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:Qr(o),subject:o.subject,operator:Qr(t),issued:new Date().toISOString(),content:r})})}import{Button as mS,Loader as pS,Table as xS}from"@mantine/core";import{normalizeOperationOutcome as IS}from"@medplum/core";import{memo as gS,useEffect as lu,useRef as fu,useState as Zr}from"react";import{evalFhirPath as _y}from"@medplum/core";import{jsx as Ky}from"react/jsx-runtime";function Ti(e){let o;try{o=_y(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 Ky(ce,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as Kv,Button as nt,Center as _r,createStyles as Zv,Group as Kr,Loader as Yv,Menu as ru,Pagination as jv,Table as eS,Text as rl,UnstyledButton as oS}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as fl,formatSearchQuery as tS}from"@medplum/core";import{memo as rS,useCallback as au,useEffect as nu,useRef as aS,useState as al}from"react";import{Box as Zy,Button as Yy,Modal as jy,Text as ev}from"@mantine/core";import{jsx as zr,jsxs as Di}from"react/jsx-runtime";function Ai(e){return Di(jy,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Di(Zy,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&zr(ki,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&zr(ki,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),zr(ev,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function ki(e){return zr(Yy,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as cv,Group as dv,Modal as mv,MultiSelect as pv,Stack as xv}from"@mantine/core";import{getDataType as Iv,getSearchParameters as gv,stringify as hv}from"@medplum/core";import{useEffect as yv,useMemo as vv,useRef as Sv,useState as zi}from"react";import{capitalize as ov,DEFAULT_SEARCH_COUNT as tv,evalFhirPathTyped as rv,formatDateTime as av,Operator as O}from"@medplum/core";import{Fragment as uv,jsx as Jn}from"react/jsx-runtime";var nv={string:[O.EQUALS,O.NOT,O.CONTAINS,O.EXACT],fulltext:[O.EQUALS,O.NOT,O.CONTAINS,O.EXACT],token:[O.EQUALS,O.NOT],reference:[O.EQUALS,O.NOT],numeric:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS],quantity:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS],date:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS,O.STARTS_AFTER,O.ENDS_BEFORE,O.APPROXIMATELY],datetime:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS,O.STARTS_AFTER,O.ENDS_BEFORE,O.APPROXIMATELY]},lv={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 Wt(e,o){return{...e,filters:o,offset:0,name:void 0}}function B2(e){return Wt(e,[])}function Wr(e,o){return Wt(e,(e.filters??[]).filter(t=>t.code!==o))}function ot(e,o,t,r,a){a&&(e=Wr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Wt(e,n)}function M2(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 Mi(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function Fi(e,o){return $n(e,o,-1)}function wi(e,o){return $n(e,o,0)}function Oi(e,o){return $n(e,o,1)}function $n(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),Kn(e,o,r,a)}function Ei(e,o){return _n(e,o,-1)}function Li(e,o){return _n(e,o,0)}function Ni(e,o){return _n(e,o,1)}function _n(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),Kn(e,o,r,a)}function Vi(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Kn(e,o,t,new Date)}function Kn(e,o,t,r){return e=Wr(e,o),e=Bi(e,o,O.GREATER_THAN_OR_EQUALS,t),e=Bi(e,o,O.LESS_THAN_OR_EQUALS,r),e}function Bi(e,o,t,r){return ot(e,o,t,r.toISOString())}function Zn(e,o,t=!0){return ot(e,o,O.MISSING,t.toString())}function fv(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function Hi(e,o){let t=e.count??tv,r=(o-1)*t;return fv(e,r)}function Yn(e,o,t){return o===qi(e)&&t!==void 0&&t===Gi(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function F2(e,o){let t=!1;return qi(e)===o&&(t=!Gi(e)),Yn(e,o,t)}function qi(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function Gi(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function Ui(e){return nv[e.type]}function Xt(e){return lv[e]??""}function we(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(ov).join(" "))}function Qi(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?av(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?sv(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?iv(e,o.searchParams[0]):null}function sv(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=so({type:e.resourceType,value:e},t);return r?Jn(ce,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function iv(e,o){let t=rv(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:Jn(uv,{children:t.map((r,a)=>Jn(ce,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as Jt,jsxs as bv}from"react/jsx-runtime";function Wi(e){let o=Sv(!1),[t,r]=zi({search:JSON.parse(hv(e.search))}),[a,n]=zi(!1);yv(()=>{r({search:e.search})},[e.search]);let l=vv(()=>{if(!e.visible)return[];let i=e.search.resourceType,s=Iv(i),u=gv(i);return Cv(s,u).sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:we(c)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function f(i){r({search:{...t.search,fields:i}})}return Jt(mv,{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:Jt("div",{"data-testid":"overlay-child"})},children:bv(xv,{children:[Jt(pv,{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}),Jt(dv,{position:"right",children:Jt(cv,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function Cv(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(we(n));if(o)for(let n of Object.keys(o)){let l=we(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as $t,Group as Mv,Modal as Fv,NativeSelect as $i}from"@mantine/core";import{getSearchParameters as wv,stringify as _i}from"@medplum/core";import{useEffect as Ov,useRef as Zi,useState as ol}from"react";import{formatDateTime as Rv,getSearchParameterDetails as Pv,globalSchema as Tv,Operator as Xi,SearchParameterType as kv}from"@medplum/core";import{Fragment as Ji,jsx as jn}from"react/jsx-runtime";function Xr(e){let{resourceType:o,filter:t}=e,r=Tv.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===Xi.EQUALS||t.operator===Xi.NOT_EQUALS))return jn(Ue,{value:{reference:t.value}});let a=Pv(o,r);if(t.code==="_lastUpdated"||a.type===kv.DATETIME)return jn(Ji,{children:Rv(t.value)})}return jn(Ji,{children:t.value})}import{Checkbox as Dv,TextInput as el}from"@mantine/core";import{getSearchParameterDetails as Av,SearchParameterType as tt}from"@medplum/core";import{jsx as ko}from"react/jsx-runtime";function Jr(e){let o=Av(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case tt.REFERENCE:return ko(Zo,{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 tt.BOOLEAN:return ko(Dv,{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 tt.DATE:return ko(el,{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 tt.DATETIME:return ko(Ve,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case tt.NUMBER:return ko(el,{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 tt.QUANTITY:return ko(Be,{name:t,defaultValue:Bv(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return ko(el,{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 Bv(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as z,jsxs as eo}from"react/jsx-runtime";function Yi(e){let[o,t]=ol(JSON.parse(_i(e.search))),[r,a]=ol(-1),n=Zi(o);n.current=o,Ov(()=>{t(JSON.parse(_i(e.search)))},[e.search]);function l(u){t(ot(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let f=e.search.resourceType,i=wv(f)??{},s=o.filters||[];return eo(Fv,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[z("div",{children:eo("table",{children:[eo("colgroup",{children:[z("col",{style:{width:200}}),z("col",{style:{width:200}}),z("col",{style:{width:380}}),z("col",{style:{width:120}})]}),z("thead",{children:eo("tr",{children:[z("th",{children:"Field"}),z("th",{children:"Operation"}),z("th",{children:"Value"}),z("th",{children:"Actions"})]})}),eo("tbody",{children:[s.map((u,c)=>c===r?z(Ki,{resourceType:f,searchParams:i,defaultValue:u,okText:"Save",onOk:d=>{let m=[...s];m[c]=d,t(Wt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):z(Ev,{resourceType:f,searchParams:i,filter:u,onEdit:()=>a(c),onDelete:()=>t(Mi(n.current,c))},`filter-${u.code}-${u.operator}-${u.value}-display`)),z(Ki,{resourceType:f,searchParams:i,okText:"Add",onOk:l})]})]})}),z(Mv,{position:"right",mt:"xl",children:z($t,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function Ev(e){let{filter:o}=e;return eo("tr",{children:[z("td",{children:we(o.code)}),z("td",{children:Xt(o.operator)}),z("td",{children:z(Xr,{resourceType:e.resourceType,filter:o})}),eo("td",{children:[z($t,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),z($t,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function Ki(e){let[o,t]=ol(e.defaultValue??{}),r=Zi(o);r.current=o;function a(s){t({...r.current,code:s})}function n(s){t({...r.current,operator:s})}function l(s){t({...r.current,value:s})}let f=e.searchParams[o.code],i=f&&Ui(f);return eo("tr",{children:[z("td",{children:z($i,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:s=>a(s.currentTarget.value),data:["",...Object.keys(e.searchParams).map(s=>({value:s,label:we(s)}))]})}),z("td",{children:i&&z($i,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:s=>n(s.currentTarget.value),data:["",...i.map(s=>({value:s,label:Xt(s)}))]})}),z("td",{children:f&&o.operator&&z(Jr,{resourceType:e.resourceType,searchParam:f,defaultValue:o.value,onChange:l})}),eo("td",{children:[o.code&&o.operator&&z($t,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&z($t,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as Lv,Grid as tl,Modal as Nv}from"@mantine/core";import{useState as Vv}from"react";import{jsx as rt,jsxs as Hv}from"react/jsx-runtime";function ji(e){let[o,t]=Vv(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return rt(Nv,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:rt(H,{onSubmit:r,children:Hv(tl,{children:[rt(tl.Col,{span:10,children:rt(Jr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),rt(tl.Col,{span:2,children:rt(Lv,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as A}from"@mantine/core";import{Operator as se}from"@medplum/core";import{Fragment as ou,jsx as g,jsxs as at}from"react/jsx-runtime";function eu(e){if(!e.searchParams)return null;function o(n,l){a(Yn(e.search,n.code,l))}function t(n){a(Wr(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(qv,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):g(A.Dropdown,{children:e.searchParams.map(n=>g(A.Item,{children:we(n.code)},n.code))})}function qv(e){switch(e.searchParam.type){case"date":return g(Gv,{...e});case"number":case"quantity":return g(Uv,{...e});case"reference":return g(Qv,{...e});case"string":case"token":case"uri":return g(zv,{...e});default:return at(ou,{children:["Unknown search param type: ",e.searchParam.type]})}}function Gv(e){let{searchParam:o}=e,t=o.code;return at(A.Dropdown,{children:[g(A.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),g(A.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),g(A.Divider,{}),g(A.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(A.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT_EQUALS),children:"Does not equal..."}),g(A.Divider,{}),g(A.Item,{icon:g(ir,{size:14}),onClick:()=>e.onPrompt(o,se.ENDS_BEFORE),children:"Before..."}),g(A.Item,{icon:g(sr,{size:14}),onClick:()=>e.onPrompt(o,se.STARTS_AFTER),children:"After..."}),g(A.Item,{icon:g(Ea,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Between..."}),g(A.Divider,{}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Oi(e.search,t)),children:"Tomorrow"}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(wi(e.search,t)),children:"Today"}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Fi(e.search,t)),children:"Yesterday"}),g(A.Divider,{}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Ni(e.search,t)),children:"Next Month"}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Li(e.search,t)),children:"This Month"}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Ei(e.search,t)),children:"Last Month"}),g(A.Divider,{}),g(A.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Vi(e.search,t)),children:"Year to date"}),g($r,{...e})]})}function Uv(e){let{searchParam:o}=e;return at(A.Dropdown,{children:[g(A.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),g(A.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),g(A.Divider,{}),g(A.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(A.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT_EQUALS),children:"Does not equal..."}),g(A.Divider,{}),g(A.Item,{icon:g(sr,{size:14}),onClick:()=>e.onPrompt(o,se.GREATER_THAN),children:"Greater than..."}),g(A.Item,{icon:g(qo,{size:14}),onClick:()=>e.onPrompt(o,se.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),g(A.Item,{icon:g(ir,{size:14}),onClick:()=>e.onPrompt(o,se.LESS_THAN),children:"Less than..."}),g(A.Item,{icon:g(qo,{size:14}),onClick:()=>e.onPrompt(o,se.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),g($r,{...e})]})}function Qv(e){let{searchParam:o}=e;return at(A.Dropdown,{children:[g(A.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(A.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT),children:"Does not equal..."}),g($r,{...e})]})}function zv(e){let{searchParam:o}=e;return at(A.Dropdown,{children:[g(A.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),g(A.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),g(A.Divider,{}),g(A.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(A.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT),children:"Does not equal..."}),g(A.Divider,{}),g(A.Item,{icon:g(Na,{size:14}),onClick:()=>e.onPrompt(o,se.CONTAINS),children:"Contains..."}),g(A.Item,{icon:g(La,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Does not contain..."}),g($r,{...e})]})}function $r(e){let{searchParam:o}=e,t=o.code;return at(ou,{children:[g(A.Divider,{}),g(A.Item,{icon:g(wa,{size:14}),onClick:()=>e.onChange(Zn(e.search,t)),children:"Missing"}),g(A.Item,{icon:g(Fa,{size:14}),onClick:()=>e.onChange(Zn(e.search,t,!1)),children:"Not missing"}),g(A.Divider,{}),g(A.Item,{icon:g(ln,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Wv,getSearchParameter as Xv,getSearchParameterDetails as Jv,getSearchParameters as $v}from"@medplum/core";function tu(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(_v(o,r));return t}function _v(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=Wv(e,o),r=Xv(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=$v(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=Jv(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as dS,jsx as F,jsxs as Pe}from"react/jsx-runtime";var nl=class extends Event{constructor(t){super("change");this.definition=t}},ll=class extends Event{constructor(t){super("load");this.response=t}},Do=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},nS=Zv(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 lS(e){let{classes:o}=nS(),t=S(),[r,a]=al(!1),[n,l]=al(),{search:f,onLoad:i}=e,[s,u]=al({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),c=aS(s);c.current=s;let d=f.total??"accurate",m=au(T=>{l(void 0),t.search(f.resourceType,tS({...f,total:d,fields:void 0}),T).then(G=>{u({...c.current,searchResponse:G}),i&&i(new ll(G))}).catch(G=>{u({...c.current,searchResponse:void 0}),l(G)})},[t,f,d,i]),p=au(()=>{u({...c.current,searchResponse:void 0}),m({cache:"reload"})},[m]);nu(()=>{m()},[m]);function x(T,G){T.stopPropagation();let ne=T.target.checked,ue={...c.current.selected};ne?ue[G]=!0:delete ue[G],u({...c.current,selected:ue})}function C(T){T.stopPropagation();let ee=T.target.checked,ne={},ue=c.current.searchResponse;ee&&ue?.entry&&ue.entry.forEach(ht=>{ht.resource?.id&&(ne[ht.resource.id]=!0)}),u({...c.current,selected:ne})}function y(){let T=c.current;if(!T.searchResponse?.entry||T.searchResponse.entry.length===0)return!1;for(let G of T.searchResponse.entry)if(G.resource?.id&&!T.selected[G.resource.id])return!1;return!0}function v(T){e.onChange&&e.onChange(new nl(T))}function b(T,G){if(cr(T.target)||T.button===2)return;M(T);let ee=T.button===1||T.ctrlKey||T.metaKey;!ee&&e.onClick&&e.onClick(new Do(G,T)),ee&&e.onAuxClick&&e.onAuxClick(new Do(G,T))}function P(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(nu(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return F(_r,{style:{width:"100%",height:"100%"},children:F(Yv,{})});let h=e.checkboxesEnabled,B=tu(f),W=f.resourceType,Y=s.searchResponse,ke=Y?.entry?.map(T=>T.resource),De="subtle",R="gray",N=16,ao=window.innerWidth<768;return Pe("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&Pe(Kr,{position:"apart",mb:"xl",children:[Pe(Kr,{spacing:2,children:[F(nt,{compact:!0,variant:De,color:R,leftIcon:F(qa,{size:N}),onClick:()=>u({...c.current,fieldEditorVisible:!0}),children:"Fields"}),F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Wa,{size:N}),onClick:()=>u({...c.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(za,{size:N}),onClick:e.onNew,children:"New..."}),!ao&&P()&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(an,{size:N}),onClick:e.onExport?e.onExport:()=>u({...c.current,exportDialogVisible:!0}),children:"Export..."}),!ao&&e.onDelete&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Dt,{size:N}),onClick:()=>e.onDelete(Object.keys(s.selected)),children:"Delete..."}),!ao&&e.onBulk&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Oa,{size:N}),onClick:()=>e.onBulk(Object.keys(s.selected)),children:"Bulk..."})]}),Pe(Kr,{spacing:2,children:[Y&&Pe(rl,{size:"xs",color:"dimmed",children:[uS(f,Y.total),"-",cS(f,Y.total)," of"," ",`${d==="estimate"?"~":""}${Y.total?.toLocaleString()}`]}),F(Kv,{title:"Refresh",onClick:p,children:F(ja,{size:"1.125rem"})})]})]}),Pe(eS,{className:o.table,children:[Pe("thead",{children:[Pe("tr",{children:[h&&F("th",{children:F("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:y(),onChange:T=>C(T)})}),B.map(T=>F("th",{children:Pe(ru,{shadow:"md",width:240,position:"bottom-end",children:[F(ru.Target,{children:F(oS,{className:o.control,children:Pe(Kr,{position:"apart",noWrap:!0,children:[F(rl,{weight:500,size:"sm",children:we(T.name)}),F(_r,{className:o.icon,children:F(Aa,{size:14,stroke:1.5})})]})})}),F(eu,{search:e.search,searchParams:T.searchParams,onPrompt:(G,ee)=>{u({...c.current,filterDialogVisible:!0,filterDialogSearchParam:G,filterDialogFilter:ee})},onChange:G=>{v(G)}})]})},T.name))]}),!e.hideFilters&&Pe("tr",{children:[h&&F("th",{}),B.map(T=>F("th",{children:T.searchParams&&F(fS,{resourceType:W,searchParams:T.searchParams,filters:e.search.filters})},T.name))]})]}),F("tbody",{children:ke?.map(T=>T&&Pe("tr",{className:o.tr,"data-testid":"search-control-row",onClick:G=>b(G,T),onAuxClick:G=>b(G,T),children:[h&&F("td",{children:F("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${T.id}`,checked:!!s.selected[T.id],onChange:G=>x(G,T.id)})}),B.map(G=>F("td",{children:Qi(T,G)},G.name))]},T.id))})]}),ke?.length===0&&F(uo,{children:F(_r,{style:{height:150},children:F(rl,{size:"xl",color:"dimmed",children:"No results"})})}),Y?.total!==void 0&&Y.total>0&&F(_r,{m:"md",p:"md",children:F(jv,{value:sS(f),total:iS(f,Y.total),onChange:T=>v(Hi(f,T)),getControlProps:T=>{switch(T){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&F("div",{"data-testid":"search-error",children:F("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),F(Wi,{search:e.search,visible:c.current.fieldEditorVisible,onOk:T=>{v(T),u({...c.current,fieldEditorVisible:!1})},onCancel:()=>{u({...c.current,fieldEditorVisible:!1})}}),F(Yi,{search:e.search,visible:c.current.filterEditorVisible,onOk:T=>{v(T),u({...c.current,filterEditorVisible:!1})},onCancel:()=>{u({...c.current,filterEditorVisible:!1})}}),F(Ai,{visible:c.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...c.current,exportDialogVisible:!1})}}),F(ji,{visible:c.current.filterDialogVisible,title:s.filterDialogSearchParam?.code?we(s.filterDialogSearchParam.code):"",resourceType:W,searchParam:s.filterDialogSearchParam,filter:s.filterDialogFilter,defaultValue:"",onOk:T=>{v(ot(e.search,T.code,T.operator,T.value)),u({...c.current,filterDialogVisible:!1})},onCancel:()=>{u({...c.current,filterDialogVisible:!1})}},s.filterDialogSearchParam?.code)]})}var _N=rS(lS);function fS(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?F("span",{children:"no filters"}):F(dS,{children:o.map(t=>Pe("div",{children:[Xt(t.operator),"\xA0",F(Xr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function sS(e){return Math.floor((e.offset??0)/(e.count??fl))+1}function iS(e,o){let t=e.count??fl;return Math.ceil(o/t)}function uS(e,o){return Math.min(o,(e.offset??0)+1)}function cS(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??fl))}import{jsx as Se,jsxs as Yr}from"react/jsx-runtime";function hS(e){let o=S(),[t,r]=Zr(!1),[a,n]=Zr(),{query:l,fields:f}=e,[i,s]=Zr(),[u,c]=Zr({}),d=fu();d.current=i;let m=fu({});m.current=u,lu(()=>{n(void 0),o.graphql(l).then(s).catch(b=>n(IS(b)))},[o,l]);function p(b,P){b.stopPropagation();let B=b.target.checked,W={...m.current};B?W[P]=!0:delete W[P],c(W)}function x(b){b.stopPropagation();let h=b.target.checked,B={},W=d.current?.data.ResourceList;h&&W&&W.forEach(Y=>{Y.id&&(B[Y.id]=!0)}),c(B)}function C(){let b=d.current?.data.ResourceList;if(!b||b.length===0)return!1;for(let P of b)if(P.id&&!m.current[P.id])return!1;return!0}function y(b,P){cr(b.target)||(M(b),b.button!==1&&e.onClick&&e.onClick(new Do(P,b)),b.button===1&&e.onAuxClick&&e.onAuxClick(new Do(P,b)))}if(lu(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return Se(pS,{});let v=e.checkboxesEnabled;return Yr("div",{onContextMenu:b=>M(b),"data-testid":"search-control",children:[Yr(xS,{children:[Se("thead",{children:Yr("tr",{children:[v&&Se("th",{children:Se("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:C(),onChange:b=>x(b)})}),f.map(b=>Se("th",{children:b.name},b.name))]})}),Se("tbody",{children:i?.data.ResourceList.map(b=>b&&Yr("tr",{"data-testid":"search-control-row",onClick:P=>y(P,b),onAuxClick:P=>y(P,b),children:[v&&Se("td",{children:Se("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${b.id}`,checked:!!u[b.id],onChange:P=>p(P,b.id)})}),f.map(P=>Se("td",{children:Se(Ti,{propertyType:P.propertyType,path:P.fhirPath,resource:b})},P.name))]},b.id))})]}),i?.data.ResourceList.length===0&&Se("div",{"data-testid":"empty-search",children:"No results"}),a&&Se("div",{"data-testid":"search-error",children:Se("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&Se(mS,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var fV=gS(hS);import{jsx as lt,jsxs as yS}from"react/jsx-runtime";function xo(e){return yS("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[lt("title",{children:"Medplum Logo"}),lt("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),lt("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"}),lt("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"}),lt("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),lt("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as PS,SimpleGrid as TS}from"@mantine/core";import{Box as su,Flex as sl,Group as vS,Paper as SS,RingProgress as uu,Text as Ao,Title as il}from"@mantine/core";import{formatCodeableConcept as iu}from"@medplum/core";import{Fragment as pu,jsx as re,jsxs as _t}from"react/jsx-runtime";function cu(e){let{group:o}=e;return re(SS,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:_t(vS,{children:[o.measureScore&&re(bS,{group:o}),!o.measureScore&&re(CS,{group:o})]})})}function du(e){let{measure:o}=e;return _t(pu,{children:[re(Ao,{fz:"md",fw:500,mb:8,children:o.title}),re(Ao,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function CS(e){let{group:o}=e,t=o.population,r=t?.find(i=>iu(i.code)==="numerator"),a=t?.find(i=>iu(i.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return _t(su,{children:[re(il,{order:3,children:"Not Applicable"}),re(Ao,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return _t(su,{children:[re(il,{order:3,children:"Insufficient Data"}),re(Ao,{children:`Numerator: ${n}`}),re(Ao,{children:`Denominator: ${l}`})]});let f=n/l*100;return re(uu,{size:120,thickness:12,roundCaps:!0,sections:[{value:f,color:mu(f)}],label:re(sl,{justify:"center",children:_t(Ao,{fw:700,fz:18,children:[n," / ",l]})})})}function bS(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return re(pu,{children:t==="%"?re(uu,{size:120,thickness:12,roundCaps:!0,sections:[{value:RS(o),color:mu(o?.measureScore?.value??0)}],label:re(sl,{justify:"center",children:re(Ao,{fw:700,fz:18,children:re(ae,{value:o.measureScore})})})}):re(sl,{h:120,align:"center",children:re(il,{order:3,children:re(ae,{value:o.measureScore})})})})}function RS(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function mu(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as ul,jsxs as kS}from"react/jsx-runtime";function vV(e){let o=X(e.measureReport),[t]=Kl("Measure",{url:o?.measure});return o?kS(PS,{children:[t&&ul(du,{measure:t}),ul(TS,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>ul(cu,{group:r},r.id??a))})]}):null}import{Alert as DS}from"@mantine/core";import{operationOutcomeIssueToString as AS}from"@medplum/core";import{jsx as cl}from"react/jsx-runtime";function ft(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:cl(DS,{icon:cl(vo,{size:16}),color:"red",children:o.map(t=>cl("div",{"data-testid":"text-field-error",children:AS(t)},t.details?.text))})}import{Anchor as Xu,Card as Ju,Divider as Kt,Flex as gl,Group as MC,Paper as FC,Stack as wC,Text as Zt}from"@mantine/core";import{calculateAgeString as OC,formatHumanName as EC,resolveId as LC}from"@medplum/core";import{useEffect as NC,useState as st}from"react";import{Anchor as BS,Badge as MS,Box as FS,Button as wS,Group as xu,Modal as OS,NativeSelect as ES,Stack as LS,Text as Iu,TextInput as gu}from"@mantine/core";import{useDisclosure as NS}from"@mantine/hooks";import{createReference as hu}from"@medplum/core";import{useCallback as VS,useState as yu}from"react";import{Fragment as HS,jsx as Ce,jsxs as dl}from"react/jsx-runtime";function vu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=yu(e.allergies),[l,{open:f,close:i}]=NS(!1),[s,u]=yu(),c=VS(d=>{o.createResource({resourceType:"AllergyIntolerance",patient:hu(t),encounter:r?hu(r):void 0,code:s,onsetDateTime:d.onset?d.onset:void 0,reaction:d.reaction?[{manifestation:[{text:d.reaction}]}]:void 0}).then(m=>{n([...a,m]),i()}).catch(console.error)},[o,t,r,a,i,s]);return dl(HS,{children:[dl(xu,{position:"apart",children:[Ce(Iu,{fz:"md",fw:700,children:"Allergies"}),Ce(BS,{href:"#",onClick:d=>{M(d),f()},children:"+ Add"})]}),a.length>0?Ce(FS,{children:a.map(d=>Ce(MS,{maw:"100%",children:Ce(ye,{value:d.code})},d.id))}):Ce(Iu,{children:"(none)"}),Ce(OS,{opened:l,onClose:i,title:"Add Allergy",children:Ce(H,{onSubmit:c,children:dl(LS,{children:[Ce(_o,{name:"allergy","data-autofocus":!0,binding:"http://hl7.org/fhir/us/core/ValueSet/us-core-allergy-substance",onChange:d=>u(d)}),Ce(gu,{name:"reaction",label:"Reaction"}),Ce(ES,{name:"status",label:"Status",data:["active"]}),Ce(gu,{name:"onset",label:"Onset",type:"date"}),Ce(xu,{position:"right",spacing:4,mt:"md",children:Ce(wS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as qS,Badge as GS,Box as US,Button as QS,Group as Su,Modal as zS,Radio as ml,Stack as WS,Text as Cu}from"@mantine/core";import{useDisclosure as XS}from"@mantine/hooks";import{createReference as bu}from"@medplum/core";import{useCallback as JS,useState as Ru}from"react";import{Fragment as $S,jsx as Te,jsxs as jr}from"react/jsx-runtime";function Pu(e){let o=S(),[t,r]=Ru(e.medicationRequests),[a,{open:n,close:l}]=XS(!1),[f,i]=Ru(),s=JS(u=>{let c=u.status;o.createResource({resourceType:"MedicationRequest",status:c,intent:"order",encounter:e.encounter?bu(e.encounter):void 0,medicationCodeableConcept:f,subject:bu(e.patient)}).then(d=>{r([d,...t]),l()}).catch(console.error)},[o,e.patient,e.encounter,t,l,f]);return jr($S,{children:[jr(Su,{position:"apart",children:[Te(Cu,{fz:"md",fw:700,children:"Medications"}),Te(qS,{href:"#",onClick:u=>{M(u),n()},children:"+ Add"})]}),t.length>0?Te(US,{children:t.map(u=>Te(GS,{mt:4,maw:"50%",color:u.status==="active"?"blue":"gray",children:Te(ye,{value:u.medicationCodeableConcept})},u.id))}):Te(Cu,{children:"(none)"}),Te(zS,{opened:a,onClose:l,title:"Add Medication Request",children:Te(H,{onSubmit:s,children:jr(WS,{h:275,children:[Te(_o,{name:"request","data-autofocus":!0,binding:"https://app.medplum.com/ValueSet/16d6f7b7-7eeb-4d0e-a83b-83be082aa10b",onChange:u=>i(u)}),jr(ml.Group,{mt:32,name:"status",label:"Request Status",required:!0,children:[Te(ml,{value:"active",label:"active",my:"xs"},"active"),Te(ml,{value:"stopped",label:"stopped",my:"xs"},"stopped")]}),Te(Su,{position:"right",spacing:4,mt:"md",children:Te(QS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as _S,Badge as KS,Button as ZS,Grid as pl,Group as Tu,Modal as YS,NativeSelect as jS,Stack as eC,Text as ku,Textarea as oC,TextInput as Du}from"@mantine/core";import{useDisclosure as tC}from"@mantine/hooks";import{createReference as Au}from"@medplum/core";import{Fragment as rC,useCallback as aC,useState as nC}from"react";import{Fragment as lC,jsx as me,jsxs as ea}from"react/jsx-runtime";function Bu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=nC(e.problems),[l,{open:f,close:i}]=tC(!1),s=aC(u=>{o.createResource({resourceType:"Condition",subject:Au(t),encounter:r?Au(r):void 0,code:{coding:[{code:u.problem,display:u.problem}]},onsetDateTime:u.onset?u.onset:void 0}).then(c=>{n([...a,c]),i()}).catch(console.error)},[o,t,r,a,i]);return ea(lC,{children:[ea(Tu,{position:"apart",children:[me(ku,{fz:"md",fw:700,children:"Problem List"}),me(_S,{href:"#",onClick:u=>{M(u),f()},children:"+ Add"})]}),a.length>0?me(pl,{gutter:"xs",children:a.map(u=>ea(rC,{children:[me(pl.Col,{span:2,children:u.onsetDateTime?.substring(0,4)}),me(pl.Col,{span:10,children:me(KS,{maw:"100%",children:me(ye,{value:u.code})},u.id)})]},u.id))}):me(ku,{children:"(none)"}),me(YS,{opened:l,onClose:i,title:"Add Problem",children:me(H,{onSubmit:s,children:ea(eC,{children:[me(Du,{name:"problem",label:"Problem","data-autofocus":!0,autoFocus:!0,required:!0}),me(Du,{name:"onset",label:"Dx Date",type:"date",required:!0}),me(jS,{name:"status",label:"Status",data:["active"]}),me(oC,{name:"notes",label:"Notes"}),me(Tu,{position:"right",spacing:4,mt:"md",children:me(ZS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as fC,Badge as sC,Box as iC,Button as uC,Group as Mu,Modal as cC,Radio as Fu,Stack as dC,Text as wu}from"@mantine/core";import{useDisclosure as mC}from"@mantine/hooks";import{HTTP_HL7_ORG as pC,LOINC as xC,SNOMED as Ou,createReference as Eu}from"@medplum/core";import{useCallback as IC,useState as gC}from"react";import{Fragment as hC,jsx as Oe,jsxs as xl}from"react/jsx-runtime";var Lu={266919005:"Never smoked tobacco",266927001:"Tobacco smoking consumption unknown","428041000124106":"Occasional tobacco smoker","428061000124105":"Light tobacco smoker","428071000124103":"Heavy tobacco smoker",449868002:"Smokes tobacco daily",77176002:"Smoker",8517006:"Ex-smoker"};function Nu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=gC(e.smokingStatus),[l,{open:f,close:i}]=mC(!1),s=IC(u=>{o.createResource({resourceType:"Observation",meta:{profile:[pC+"/fhir/us/core/StructureDefinition/us-core-smokingstatus"]},status:"final",category:[{coding:[{system:"http://terminology.hl7.org/CodeSystem/observation-category",code:"social-history",display:"Social History"}],text:"Social History"}],code:{coding:[{system:xC,code:"72166-2",display:"Tobacco smoking status"}],text:"Tobacco smoking status"},subject:Eu(t),encounter:r?Eu(r):void 0,effectiveDateTime:new Date().toISOString(),valueCodeableConcept:{coding:[{system:Ou,version:Ou+"/731000124108",code:u.smokingStatus}],text:Lu[u.smokingStatus]}}).then(c=>{n(c),i()}).catch(console.error)},[o,t,r,i]);return xl(hC,{children:[xl(Mu,{position:"apart",children:[Oe(wu,{fz:"md",fw:700,children:"Smoking Status"}),Oe(fC,{href:"#",onClick:u=>{M(u),f()},children:"+ Edit"})]}),a?.valueCodeableConcept?Oe(iC,{children:Oe(sC,{children:Oe(ye,{value:a.valueCodeableConcept})})}):Oe(wu,{children:"(none)"}),Oe(cC,{opened:l,onClose:i,title:"Set Smoking Status",children:Oe(H,{onSubmit:s,children:xl(dC,{children:[Oe(Fu.Group,{name:"smokingStatus",label:"Smoking Status",required:!0,children:Object.entries(Lu).map(([u,c])=>Oe(Fu,{value:u,label:c,my:"xs"},u))}),Oe(Mu,{position:"right",spacing:4,mt:"md",children:Oe(uC,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as SC,Button as CC,Grid as te,Group as Bo,Modal as bC,Stack as RC,Text as PC,Textarea as TC,TextInput as We}from"@mantine/core";import{useDisclosure as kC}from"@mantine/hooks";import{useCallback as DC,useState as AC}from"react";import{LOINC as yC,UCUM as vC,createReference as Vu}from"@medplum/core";function oo(e,o){return e.find(r=>r.code?.coding?.[0].code===o)?.valueQuantity}function Il(e,o,t){return e.find(n=>n.code?.coding?.[0].code===o)?.component?.find(n=>n.code?.coding?.[0].code===t)?.valueQuantity}function Hu(e,o,t,r,a){if(Uu(a.value))return{...Gu(e,o,t,r),valueQuantity:a}}function qu(e,o,t,r,a){let n=a.filter(l=>Uu(l.valueQuantity?.value));if(n.length!==0)return{...Gu(e,o,t,r),component:n}}function Gu(e,o,t,r){return{resourceType:"Observation",status:"preliminary",subject:Vu(e),encounter:o?Vu(o):void 0,effectiveDateTime:new Date().toISOString(),category:[{coding:[{system:"http://terminology.hl7.org/CodeSystem/observation-category",code:"vital-signs",display:"Vital Signs"}]}],code:oa(t,r)}}function oa(e,o){return{coding:[{code:e,display:o,system:yC}],text:o}}function ta(e,o){return{value:e,system:vC,unit:o,code:o}}function Uu(e){return e!==void 0&&!isNaN(e)&&isFinite(e)}import{Fragment as BC,jsx as w,jsxs as Xe}from"react/jsx-runtime";var He={bloodPressure:{code:"85354-9",title:"Blood Pressure",unit:"mm[Hg]"},heartRate:{code:"8867-4",title:"Heart Rate",unit:"/min"},bodyTemperature:{code:"8310-5",title:"Body Temperature",unit:"Cel"},respiratoryRate:{code:"9279-1",title:"Respiratory Rate",unit:"/min"},height:{code:"8302-2",title:"height",unit:"cm"},weight:{code:"29463-7",title:"weight",unit:"kg"},bmi:{code:"39156-5",title:"BMI",unit:"kg/m2"},oxygen:{code:"2708-6",title:"Oxygen",unit:"%"},headCircumference:{code:"9843-4",title:"Head Circumference",unit:"cm"}},Qu="8480-6",zu="8462-4";function Wu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=AC(e.vitals),[l,{open:f,close:i}]=kC(!1),s=DC(u=>{let c=Object.entries(He).map(([d,m])=>d==="bloodPressure"?qu(t,r,m.code,m.title,[{code:oa(Qu,"Systolic blood pressure"),valueQuantity:ta(parseFloat(u.systolic),"mm[Hg]")},{code:oa(zu,"Diastolic blood pressure"),valueQuantity:ta(parseFloat(u.diastolic),"mm[Hg]")}]):Hu(t,r,m.code,m.title,ta(parseFloat(u[d]),m.unit))).filter(Boolean);Promise.all(c.map(d=>o.createResource(d))).then(d=>n([...d,...a])).catch(console.error),i()},[o,t,r,a,i]);return Xe(BC,{children:[Xe(Bo,{position:"apart",children:[w(PC,{fz:"md",fw:700,children:"Vitals"}),w(SC,{href:"#",onClick:u=>{M(u),f()},children:"+ Add"})]}),Xe(te,{children:[w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BP Sys"}),w(te.Col,{span:3,children:w(ae,{value:Il(a,He.bloodPressure.code,Qu)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BP Dias"}),w(te.Col,{span:3,children:w(ae,{value:Il(a,He.bloodPressure.code,zu)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"HR"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.heartRate.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Temp"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.bodyTemperature.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"RR"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.respiratoryRate.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Height"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.height.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Weight"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.weight.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BMI"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.bmi.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"O2"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.oxygen.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"HC"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.headCircumference.code)})})]}),w(bC,{opened:l,onClose:i,title:"Add Vitals",children:Xe(H,{onSubmit:s,children:[Xe(RC,{children:[Xe(Bo,{grow:!0,children:[w(We,{name:"systolic",label:"BP Sys","data-autofocus":!0,autoFocus:!0}),w(We,{name:"diastolic",label:"BP Dias"})]}),Xe(Bo,{grow:!0,children:[w(We,{name:"heartRate",label:"HR"}),w(We,{name:"bodyTemperature",label:"Temp"})]}),Xe(Bo,{grow:!0,children:[w(We,{name:"respiratoryRate",label:"RR"}),w(We,{name:"height",label:"height"})]}),Xe(Bo,{grow:!0,children:[w(We,{name:"weight",label:"Wt"}),w(We,{name:"bmi",label:"BMI"})]}),Xe(Bo,{grow:!0,children:[w(We,{name:"oxygen",label:"O2"}),w(We,{name:"headCircumference",label:"HC"})]}),w(TC,{name:"notes",label:"Notes"})]}),w(Bo,{position:"right",spacing:4,mt:"md",children:w(CC,{type:"submit",children:"Save"})})]})})]})}import{jsx as j,jsxs as Mo}from"react/jsx-runtime";function qH(e){let o=S(),{patient:t,background:r,...a}=e,[n,l]=st(),[f,i]=st(),[s,u]=st(),[c,d]=st(),[m,p]=st(),[x,C]=st();return NC(()=>{let y=LC(t),v=`Patient/${y}`,b={_count:100,_sort:"-_lastUpdated"};Promise.all([o.readResource("Patient",y),o.searchResources("AllergyIntolerance",{patient:v,...b}),o.searchResources("Condition",{patient:v,...b}),o.searchResources("MedicationRequest",{subject:v,...b}),o.searchResources("Observation",{subject:v,...b})]).then(P=>{l(P[0]),i(P[1]),u(P[2]),C(P[3]);let h=P[4];d(h.find(B=>B.code?.coding?.[0].code==="72166-2")),p(h.filter(B=>B.category?.[0]?.coding?.[0].code==="vital-signs"))}).catch(console.error)},[o,t]),n?Mo(Ju,{...a,children:[j(Ju.Section,{h:100,style:{background:r}}),j(fe,{value:n,size:80,radius:80,mx:"auto",mt:-50,sx:{border:"2px solid white"}}),j(Zt,{ta:"center",fz:"lg",fw:500,children:EC(n.name?.[0])}),Mo(Zt,{ta:"center",fz:"xs",color:"dimmed",children:[n.birthDate," (",OC(n.birthDate),")"]}),j(FC,{withBorder:!0,p:"md",my:"md",children:Mo(MC,{grow:!0,children:[Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,maw:"33%",children:[j(nn,{size:24,color:"gray"}),j(Zt,{fz:"xs",align:"center",sx:{whiteSpace:"nowrap"},children:"Self"})]}),Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,children:[j(tn,{size:24,color:"gray"}),j(Zt,{fz:"xs",sx:{whiteSpace:"nowrap"},children:n?.generalPractitioner?.[0]?.display??"No provider"})]}),Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,children:[j(Xa,{size:24,color:"gray"}),j(Zt,{fz:"xs",sx:{whiteSpace:"nowrap"},children:n.gender})]})]})}),Mo(wC,{spacing:"xs",children:[j(Xu,{href:"#",children:"No upcoming appointments"}),j(Xu,{href:"#",children:"No documented visits"}),j(Kt,{}),j(vu,{patient:n,allergies:f}),j(Kt,{}),j(Bu,{patient:n,problems:s}),j(Kt,{}),j(Pu,{patient:n,medicationRequests:x}),j(Kt,{}),j(Nu,{patient:n,smokingStatus:c}),j(Kt,{}),j(Wu,{patient:n,vitals:m})]})]}):null}import{createReference as ra}from"@medplum/core";import{useCallback as VC}from"react";import{jsx as HC}from"react/jsx-runtime";function $H(e){let o=VC((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 HC(po,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:ra(t),sender:ra(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:ra(t),operator:ra(r),issued:new Date().toISOString(),content:a})})}import{Anchor as _u,Button as qC,createStyles as GC,NativeSelect as UC,Stack as QC,TextInput as yl}from"@mantine/core";import{getReferenceString as zC}from"@medplum/core";import{useEffect as $u,useRef as Ku,useState as Yt}from"react";import{jsx as J,jsxs as it}from"react/jsx-runtime";var Zu=GC(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 mq(e){let o=S(),t=X(e.value),[r,a]=Yt(!1),[n,l]=Yt(),[f,i]=Yt(),[s,u]=Yt();function c(){i(void 0)}function d(){l(void 0)}let m=Ku();if(m.current=s,$u(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),$u(()=>(u(KC(t??{resourceType:"PlanDefinition"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]),!r||!s)return null;function p(x,C){u({...m.current,[x]:C})}return J("div",{children:it(H,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(s),children:[J(yl,{label:"Plan Title",defaultValue:s.title,onChange:x=>p("title",x.currentTarget.value)}),J(Yu,{actions:s.action||[],selectedKey:n,setSelectedKey:l,hoverKey:f,setHoverKey:i,onChange:x=>p("action",x)}),J(qC,{type:"submit",children:"Save"})]})})}function Yu(e){let{classes:o}=Zu(),t=Ku();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 it("div",{className:o.section,children:[e.actions.map(l=>J("div",{children:J(WC,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),J("div",{className:o.bottomActions,children:J(_u,{href:"#",onClick:l=>{M(l),a({id:ec()})},children:"Add action"})})]})}function WC(e){let{classes:o,cx:t}=Zu(),{action:r}=e,a=_C(r),n=e.selectedKey===e.action.id,l=e.hoverKey===e.action.id;function f(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function i(u){M(u),e.setHoverKey(e.action.id)}let s=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return it("div",{"data-testid":r.id,className:s,onClick:f,onMouseOver:i,onFocus:i,children:[n?J(JC,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):J(XC,{action:r,actionType:a}),J("div",{className:o.bottomActions,children:J(_u,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var vl={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function XC(e){let{action:o,actionType:t}=e,[r,a]=ju(o);return it("div",{children:[it("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&J("div",{children:J(To,{value:{reference:o.definitionCanonical}})}),r&&J("div",{children:J(ce,{property:vl,propertyType:a,value:r})})]})}function JC(e){let{action:o}=e,[t,r]=Yt(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return it(QC,{spacing:"xl",children:[J(yl,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),J(yl,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),J(UC,{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&&J(Yu,{actions:o.action,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:n=>a("action",n)}),(()=>{switch(t){case"appointment":return J(aa,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return J(aa,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return J(aa,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return J(aa,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),J(pe,{title:"Timing",description:"When the action should take place.",children:J($C,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function aa(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return J(kr,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:zC(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function $C(e){let o=e.action,t="timing",[r,a]=ju(o);return J(io,{property:vl,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(Ot(o,t,l??t,vl,n))},outcome:void 0})}function _C(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function ju(e){return so({type:"PlanDefinitionAction",value:e},"timing")}var hl=1;function ec(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(hl=Math.max(hl,o+1))}return e}return"id-"+hl++}function KC(e){return{...e,action:oc(e.action)}}function oc(e){if(e)return e.map(o=>({...o,id:ec(o.id),action:oc(o.action)}))}import{Anchor as Ee,Box as Pl,Button as Pb,createStyles as Tb,Group as kb,NativeSelect as Db,Space as Ab,Textarea as Bb,TextInput as Tl,Title as Mb}from"@mantine/core";import{getElementDefinition as Fb,isResource as wb}from"@medplum/core";import{useEffect as gc,useRef as Ob,useState as ca}from"react";import{Checkbox as ib,Group as ub,MultiSelect as cb,NativeSelect as db,Radio as cc,Textarea as mb,TextInput as ut}from"@mantine/core";import{capitalize as bl,deepEquals as pb,formatCodeableConcept as xb,formatCoding as ua,getElementDefinition as Ib,getTypedPropertyValue as Io,stringify as dc}from"@medplum/core";import{useContext as gb}from"react";import{deepClone as ZC,evalFhirPathTyped as YC,formatCoding as jC,getExtension as na,getReferenceString as eb,getTypedPropertyValue as Sl,splitN as ob,stringify as tb}from"@medplum/core";var la=(y=>(y.group="group",y.display="display",y.question="question",y.boolean="boolean",y.decimal="decimal",y.integer="integer",y.date="date",y.dateTime="dateTime",y.time="time",y.string="string",y.text="text",y.url="url",y.choice="choice",y.openChoice="open-choice",y.attachment="attachment",y.reference="reference",y.quantity="quantity",y))(la||{});function tc(e){return e.type==="choice"||e.type==="open-choice"}function rc(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=nc(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=ab(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function ac(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>jC(l.valueCoding)===r||l[o]===r),n=Sl({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function nc(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=nc(t.item,o);if(r)return r}}}function rb(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=YC(`%actualAnswer ${r} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":o});return a}else return!1}function ab(e,o,t){let r=o||[],a=Sl({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let f of r){let i=Sl({type:"QuestionnaireResponseItemAnswer",value:f},"value[x]"),{operator:s}=e;if(rb(i,a,s)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function fa(e){let o=na(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 sa(e,o){let t=ZC(e),r=na(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 lc(e,o,t){let r=na(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[i,s]=ob(f,"=",2);n[i]=s}return n}function fc(e){return{resourceType:"QuestionnaireResponse",questionnaire:eb(e),item:sc(e.item)}}function sc(e){return e?.map(Cl)??[]}function Cl(e){return{id:lb(),linkId:e.linkId,text:e.text,item:sc(e.item),answer:e.initial?.map(fb)??[]}}var nb=1;function lb(){return"id-"+nb++}function fb(e){return{...e}}function ic(e){return e.value.display||e.value.reference||tb(e.value)}function uc(e){let o=e?.item?.[0];return o&&na(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as sb}from"react";var ia=sb({});import{jsx as $}from"react/jsx-runtime";function jt(e){let o=gb(ia),t=e.item,r=e.response;function a(s){let u;Array.isArray(s)?u=s:e.index>=(e.response?.answer?.length??0)?u=(e.response?.answer??[]).concat([s]):u=(e.response?.answer??[]).map((d,m)=>m===e.index?s: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,i=Rl(r,e.index)??Io({type:"QuestionnaireItemInitial",value:f},"value");switch(n){case"display":return $("p",{children:e.item.text},e.item.linkId);case"boolean":return $(Cr,{title:e.item.text,htmlFor:e.item.linkId,children:$(ib,{id:e.item.linkId,name:e.item.linkId,defaultChecked:i?.value,onChange:s=>a({valueBoolean:s.currentTarget.checked})})},e.item.linkId);case"decimal":return $(ut,{type:"number",step:"any",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDecimal:s.currentTarget.valueAsNumber})});case"integer":return $(ut,{type:"number",step:1,id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueInteger:s.currentTarget.valueAsNumber})});case"date":return $(ut,{type:"date",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDate:s.currentTarget.value})});case"dateTime":return $(Ve,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDateTime:s})});case"time":return $(ut,{type:"time",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueTime:s.currentTarget.value})});case"string":case"url":return $(ut,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"text":return $(mb,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"attachment":return $(ub,{py:4,children:$(xr,{name:l,defaultValue:i?.value,onChange:s=>a({valueAttachment:s})})});case"reference":return $(Zo,{name:l,required:t.required,targetTypes:fa(t),searchCriteria:lc(t,o.subject,o.encounter),defaultValue:i?.value,onChange:s=>a({valueReference:s})});case"quantity":return $(Be,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueQuantity:s}),disableWheel:!0});case"choice":case"open-choice":return bb(t)&&!t.answerValueSet?$(hb,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)}):$(yb,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)});default:return null}}function hb(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return $(xc,{});let n=Io({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let i of t.answerOption){let s=Io({type:"QuestionnaireItemAnswerOption",value:i},"value");l.push(mc(s))}let f=Rl(a)??n;if(t.repeats){let{propertyName:i,data:s}=Rb(e.item),u=Sb(a);return $(cb,{data:s,placeholder:"Select items",searchable:!0,defaultValue:u||[mc(n)],onChange:c=>{let d=ac(c,i,t);e.onChangeAnswer(d)}})}return $(db,{id:o,name:o,onChange:i=>{let s=i.currentTarget.selectedIndex;if(s===0){e.onChangeAnswer({});return}let u=t.answerOption[s-1],c=Io({type:"QuestionnaireItemAnswerOption",value:u},"value"),d="value"+bl(c.type);e.onChangeAnswer({[d]:c.value})},defaultValue:ua(f?.value)||f?.value,data:l})}function yb(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?$(xc,{}):t.answerValueSet?$(Rr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):$(vb,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function vb(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Ib("QuestionnaireItemAnswerOption","value[x]"),f=Io({type:"QuestionnaireItemInitial",value:r},"value"),i=[],s;if(t.answerOption)for(let d=0;d<t.answerOption.length;d++){let m=t.answerOption[d],p=`${o}-option-${d}`,x=Io({type:"QuestionnaireItemAnswerOption",value:m},"value");x?.value&&(f&&dc(x)===dc(f)&&(s=p),i.push([p,x]))}let u=Rl(n),c=Cb(i,u);return $(cc.Group,{name:o,value:c??s,onChange:d=>{let m=i.find(p=>p[0]===d);if(m){let p=m[1],x="value"+bl(p.type);a({[x]:p.value})}},children:i.map(([d,m])=>$(cc,{id:d,value:d,py:4,label:$(ce,{property:l,propertyType:m.type,value:m.value})},d))})}function xc(){return $(ut,{disabled:!0,placeholder:"No Answers Defined"})}function Ic(e){return Io({type:"QuestionnaireItemAnswer",value:e},"value")}function Rl(e,o=0){let t=e.answer;return Ic(t?.[o]??{})}function Sb(e){let o=e.answer;return o?o.map(r=>Ic(r)).map(r=>ua(r?.value)||r?.value):[]}function Cb(e,o){return e.find(t=>pb(t[1].value,o?.value))?.[0]}function mc(e){if(e)return e.type==="CodeableConcept"?xb(e.value):e.type==="Coding"?ua(e.value):e.type==="Reference"?ic(e):e.value.toString()}function bb(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Rb(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=Io({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+bl(t.type),a=(e.answerOption??[]).map(n=>({value:pc(n,r),label:pc(n,r)}));return{propertyName:r,data:a}}function pc(e,o){return ua(e.valueCoding)||e[o]?.toString()}import{Fragment as ct,jsx as L,jsxs as be}from"react/jsx-runtime";var Eb=Tb(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 Zq(e){let o=S(),t=X(e.questionnaire),[r,a]=ca(!1),[n,l]=ca(),[f,i]=ca(),[s,u]=ca();function c(){u(void 0)}function d(){i(void 0)}gc(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),gc(()=>(l(Hb(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]);let m=(p,x)=>{l(p),e.autoSave&&!x&&e.onSubmit&&e.onSubmit(p)};return!r||!n?null:L("div",{children:be(H,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[L(hc,{item:n,selectedKey:f,setSelectedKey:i,hoverKey:s,setHoverKey:u,onChange:m}),L(Pb,{type:"submit",children:"Save"})]})})}function hc(e){let{classes:o,cx:t}=Eb(),r=e.item,a=e.item,n=wb(e.item),l=n||a.type==="group",f=a.linkId??"[untitled]",i=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,u=Ob();u.current=e.item;function c(h){M(h),e.setSelectedKey(e.item.id)}function d(h){M(h),e.setHoverKey(e.item.id)}function m(h){let B=u.current;e.onChange({...B,item:B.item?.map(W=>W.id===h.id?h:W)})}function p(h,B){e.onChange({...e.item,item:[...e.item.item??[],h]},B)}function x(h){e.onChange({...e.item,item:e.item.item?.filter(B=>B!==h)})}function C(h,B){e.onChange({...u.current,[h]:B})}function y(h){e.onChange({...e.item,...h})}function v(h){e.onChange({...e.item,item:e.item.item?.map(B=>B===h?{...B,repeats:!B.repeats}:B)})}function b(h,B){let W=Ub(e.item.item,h,B);e.onChange({...e.item,item:W})}let P=t(o.section,{[o.editing]:i,[o.hovering]:s&&!i});return be("div",{"data-testid":a.linkId,className:P,onClick:c,onMouseOver:d,onFocus:d,children:[L("div",{className:o.questionBody,children:i?be(ct,{children:[n&&L(Tl,{size:"xl",defaultValue:r.title,onBlur:h=>C("title",h.currentTarget.value)}),!n&&L(Bb,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:h=>C("text",h.currentTarget.value)}),a.type==="reference"&&L(Vb,{item:a,onChange:y}),tc(a)&&L(Lb,{item:a,onChange:h=>y(h)})]}):be(ct,{children:[r.title&&L(Mb,{children:r.title}),a.text&&L("div",{children:a.text}),!l&&L(jt,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((h,B)=>L("div",{children:L(hc,{item:h,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:B===0,isLast:B===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>x(h),onRepeatable:v,onMoveUp:()=>b(B,-1),onMoveDown:()=>b(B,1)})},h.id)),!l&&L("div",{className:o.topActions,children:i?be(ct,{children:[L(Tl,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:h=>C("linkId",h.currentTarget.value)}),!l&&L(Db,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:h=>C("type",h.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"}]})]}):L("div",{children:f})}),!n&&L(Pl,{className:o.movementActions,children:be(Pl,{className:o.columnAlignment,children:[!e.isFirst&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:L(Ma,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:L(Ba,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),be("div",{className:o.bottomActions,children:[l&&be(ct,{children:[L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p({id:Fo(),linkId:Al("q"),type:"string",text:"Question"})},children:"Add item"}),L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p({id:Fo(),linkId:Al("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p(Gb(),!0)},children:"Add Page"}),i&&!n&&be(ct,{children:[L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function Lb(e){let o=Fb("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return be("div",{children:[e.item.answerValueSet!==void 0?L(Tl,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):L(Nb,{options:t,property:o,item:e.item,onChange:e.onChange}),be(Pl,{display:"flex",children:[L(Ee,{href:"#",onClick:r=>{M(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:Fo()}]})},children:"Add choice"}),L(Ab,{w:"lg"}),L(Ee,{href:"#",onClick:r=>{M(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Nb(e){return L("div",{children:e.options.map(o=>{let[t,r]=so({type:"QuestionnaireItemAnswerOption",value:o},"value");return be("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[L("div",{children:L(io,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let l=[...e.options],f=l.findIndex(i=>i.id===o.id);l[f]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:l})},outcome:void 0},o.id)}),L("div",{children:L(Ee,{href:"#",onClick:a=>{M(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Vb(e){let o=fa(e.item)??[];return be(ct,{children:[o.map((t,r)=>be(kb,{children:[L(Xo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(sa(e.item,o.map(n=>n===t?a:n)))}}),L(Ee,{href:"#",onClick:a=>{M(a),e.onChange(sa(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),L(Ee,{href:"#",onClick:t=>{M(t),e.onChange(sa(e.item,[...o,""]))},children:"Add Resource Type"})]})}var kl=1,Dl=1;function Al(e){return e+kl++}function Fo(){return"id-"+Dl++}function Hb(e){return{...e,id:e.id||Fo(),item:yc(e.item)}}function yc(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Dl=Math.max(Dl,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(kl=Math.max(kl,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||Fo(),item:yc(o.item),answerOption:qb(o.answerOption)}))}function qb(e){if(e)return e.map(o=>({...o,id:o.id||Fo()}))}function Gb(){return{id:Fo(),linkId:Al("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 Ub(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 tR}from"@mantine/core";import{createReference as rR,getReferenceString as aR}from"@medplum/core";import{useEffect as Pc,useState as Fl}from"react";import{Button as Ml,Group as Yb,Stack as jb,Stepper as Cc}from"@mantine/core";import{Anchor as Qb}from"@mantine/core";import{useState as zb}from"react";import{jsx as da,jsxs as Xb}from"react/jsx-runtime";function ma(e){let{item:o,response:t,onChange:r}=e,[a,n]=zb(Wb(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return da("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?da(jt,{item:o,response:t,onChange:f=>r([f]),index:0},o.linkId):Xb(pe,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((f,i)=>da(jt,{item:o,response:t,onChange:s=>r([s]),index:i},`${o.linkId}-${i}`)),l&&da(Qb,{onClick:()=>n(f=>f+1),children:"Add Item"})]},e.item.linkId)}function Wb(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 Jb,Stack as $b,Title as _b}from"@mantine/core";import{useState as Kb}from"react";import{Fragment as Zb,jsx as wo,jsxs as Sc}from"react/jsx-runtime";function Bl(e){let[o,t]=Kb(e.response);if(o.length===0)return null;function r(n,l){let f=o.map((i,s)=>s===l?n[0]:i);t(f),e.onChange(f)}function a(){let n=Cl(e.item);t([...o,n])}return Sc(Zb,{children:[o.map((n,l)=>wo(vc,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:f=>r(f,l)},n.id)),e.item.repeats&&wo(Jb,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function vc(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let f=o.item?.map(s=>n.find(c=>c.id===s.id)??s)?.concat(n.slice(1)),i={...o,item:f};r([i])}return e.checkForQuestionEnabled(e.item)?Sc("div",{children:[e.item.text&&wo(_b,{order:3,mb:"md",children:e.item.text}),wo($b,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?wo(Bl,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):wo(vc,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):wo(ma,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as oR,jsx as to,jsxs as Rc}from"react/jsx-runtime";function bc(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:l,numberOfPages:f,renderPages:i,submitButtonText:s,checkForQuestionEnabled:u}=e,c=o.map(d=>{let m=t?.item?.filter(x=>x.linkId===d.linkId)??[],p=d.type==="group"?to(Bl,{item:d,response:m,onChange:a,checkForQuestionEnabled:u},d.linkId):to(ma,{item:d,response:m?.[0],onChange:a,checkForQuestionEnabled:u},d.linkId);return i?to(Cc.Step,{label:d.text,children:p},d.linkId):p});return Rc(oR,{children:[i&&to(Cc,{active:r??0,allowNextStepsSelect:!1,p:6,children:c}),!i&&to(jb,{children:c}),to(eR,{activePage:r??0,numberOfPages:f,nextStep:n,prevStep:l,submitButtonText:s})]})}function eR(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return Rc(Yb,{position:"right",mt:"xl",spacing:"xs",children:[o&&to(Ml,{onClick:e.prevStep,children:"Back"}),t&&to(Ml,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&to(Ml,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as wl,jsxs as lR}from"react/jsx-runtime";function Tc(e){let o=S(),t=o.getProfile(),[r,a]=Fl(!1),n=X(e.questionnaire),[l,f]=Fl(),[i,s]=Fl(0);Pc(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),Pc(()=>{f(n?fc(n):void 0)},[n]);function u(x){let C=l?.item??[],v={resourceType:"QuestionnaireResponse",item:kc(C,Array.isArray(x)?x:[x])};f(v)}function c(x){return rc(x,l?.item??[])}if(!r||!n)return null;let d=uc(n),m=()=>s(x=>x+1),p=()=>s(x=>x-1);return wl(ia.Provider,{value:{subject:e.subject,encounter:e.encounter},children:lR(H,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:aR(n),subject:e.subject,source:rR(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&wl(tR,{children:n.title}),wl(bc,{items:n.item??[],response:l,onChange:u,renderPages:d>1,activePage:i,numberOfPages:d,submitButtonText:e.submitButtonText,checkForQuestionEnabled:c,nextStep:m,prevStep:p})]})})}function nR(e,o){let t=kc(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 kc(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(nR(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 pa,Button as fR,createStyles as sR,Divider as iR,Group as er,NativeSelect as Ol,Stack as xa,Text as uR,TextInput as cR}from"@mantine/core";import{formatRange as Dc,getCodeBySystem as dR}from"@medplum/core";import{useEffect as mR,useState as El}from"react";import{jsx as _,jsxs as dt}from"react/jsx-runtime";var pR=sR(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"}})),xR=["gender","age","gestationalAge","context","appliesTo","category"],IR={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function NG(e){e=Object.assign(IR,e);let o=e.definition,[t,r]=El([]),[a,n]=El(1),[l,f]=El(1);return mR(()=>{let p=yR(o,f);r(vR(p.qualifiedInterval||[],n))},[o]),dt(H,{testid:"reference-range-editor",onSubmit:i,children:[_(xa,{children:t.map(p=>_(gR,{unit:CR(o.quantitativeDetails?.unit),onChange:c,onAdd:d,onRemove:m,onRemoveGroup:u,intervalGroup:p},`group-${p.id}`))}),_(pa,{title:"Add Group",size:"sm",onClick:p=>{M(p),s({id:`group-id-${a}`,filters:{},intervals:[]}),n(x=>x+1)},children:_(So,{})}),_(er,{position:"right",children:_(fR,{type:"submit",children:"Save"})})]});function i(){let p=t.flatMap(x=>x.intervals).filter(x=>!bR(x));e.onSubmit({...o,qualifiedInterval:p})}function s(p){r(x=>[...x,p])}function u(p){r(x=>x.filter(C=>C.id!==p.id))}function c(p,x){r(C=>{C=[...C];let y=C.find(b=>b.id===p),v=y?.intervals.findIndex(b=>b.id===x.id);return v!==void 0&&y?.intervals[v]&&(y.intervals[v]=x),C})}function d(p,x){x.id===void 0&&(x.id=`id-${l}`,f(C=>C+1)),r(C=>{C=[...C];let y=C.findIndex(v=>v.id===p);if(y!==-1){let v={...C[y]};x={...x,...v.filters},v.intervals=[...v.intervals,x],C[y]=v}return C})}function m(p,x){r(C=>{C=[...C];let y=C.find(v=>v.id===p);return y&&(y.intervals=y.intervals.filter(v=>v.id!==x.id)),C})}}function gR(e){let{intervalGroup:o,unit:t}=e,{classes:r}=pR();return _(uo,{"data-testid":o.id,className:r.section,children:dt(xa,{spacing:"lg",children:[_(er,{position:"right",children:_(pa,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{M(a),e.onRemoveGroup(o)},children:_(lo,{})},`remove-group-button-${o.id}`)}),_(hR,{intervalGroup:o,onChange:e.onChange}),_(iR,{}),o.intervals.map(a=>dt(xa,{spacing:"xs",children:[dt(er,{children:[_(cR,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{M(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),_(pa,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{M(n),e.onRemove(o.id,a)},children:_(lo,{})},`remove-interval-${a.id}`)]}),_(Lt,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),_(pa,{title:"Add Interval",size:"sm",onClick:a=>{M(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:_(So,{})})]})})}function hR(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 dt(xa,{style:{maxWidth:"50%"},children:[_(er,{children:_(Ol,{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})}}})}),dt(er,{spacing:"xs",children:[_(uR,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),_("div",{id:`div-age-${o.id}`,children:_(Lt,{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}`)})]}),_(Ol,{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"}]}})}}}),_(Ol,{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 yR(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 vR(e,o){let t=1,r={};for(let a of e){let n=SR(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(xR.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function SR(e){return[`gender=${e.gender}`,`age=${Dc(e.age)}`,`gestationalAge=${Dc(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function CR(e){return e&&(dR(e,"http://unitsofmeasure.org")||e.text)}function bR(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as Ac,Grid as Ia,Text as RR}from"@mantine/core";import{formatDateTime as PR,getReferenceString as TR}from"@medplum/core";import{Fragment as kR,useEffect as DR,useState as Bc}from"react";import{jsx as Je,jsxs as or}from"react/jsx-runtime";function JG(e){let o=S(),t=X(e.value),[r,a]=Bc(!1),[n,l]=Bc();if(DR(()=>{t&&!r&&(o.executeBatch(f(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Je(Ia,{children:t.action?.map((s,u)=>{let c=s.resource&&i(s.resource),d=c?.input?.[0]?.valueReference,m=c?.output?.[0]?.valueReference;return or(kR,{children:[Je(Ia.Col,{span:1,p:"md",children:c?.status==="completed"?Je(Va,{}):Je(on,{color:"gray"})}),or(Ia.Col,{span:9,p:"xs",children:[Je(RR,{weight:500,children:s.title}),s.description&&Je("div",{children:s.description}),or("div",{children:["Last edited by\xA0",Je(Ue,{value:c?.meta?.author}),"\xA0on\xA0",PR(c?.meta?.lastUpdated)]}),or("div",{children:["Status: ",Je(Er,{status:c?.status||"unknown"})]})]}),or(Ia.Col,{span:2,p:"md",children:[d&&!m&&Je(Ac,{onClick:()=>e.onStart(c,d),children:"Start"}),d&&m&&Je(Ac,{onClick:()=>e.onEdit(c,d,m),children:"Edit"})]})]},`action-${u}`)})});function f(s){let u=[];if(s.action)for(let c of s.action)c.resource?.reference&&u.push({request:{method:"GET",url:c.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function i(s){for(let u of n?.entry)if(u.resource&&s.reference===TR(u.resource))return u.resource}}import{createStyles as ER}from"@mantine/core";import{useEffect as LR,useState as NR}from"react";import{stringify as FR}from"@medplum/core";function ga(e,o){let t=AR(e,o);return BR(t,e,o)}function AR(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 i=0;i<a;i++){for(let s=-i;s<=i;s+=2){let u=l+s,c=u+1,d=u-1,m=f[c],p=f[d],x,C=0;s===-i||s!==i&&p.i<m.i?(C=m.i,x=m):(C=p.i+1,x=p),f[d]=void 0;let y=C-s,v={i:C,j:y,prev:MR(x),snake:!1};for(;C<t&&y<r&&e[C]===o[y];)C++,y++;if(C>v.i&&(v={i:C,j:y,prev:v,snake:!0}),f[u]=v,C>=t&&y>=r)return f[u]}f[l+i-1]=void 0}}function BR(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,i=a.j,s={position:f,lines:o.slice(f,n)},u={position:i,lines:t.slice(i,l)},c;s.lines.length===0&&u.lines.length>0?c="insert":s.lines.length>0&&u.lines.length===0?c="delete":c="change",r.push({original:s,revised:u,type:c}),a.snake&&(a=a.prev)}return r}function MR(e){return e&&!e.snake&&e.prev?e.prev:e}function Mc(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:FR(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 wR(t,o),OR(t),t}function wR(e,o){for(let t=1;t<o.length;t++){let r=ga(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 i=0;i<a.revised.lines.length;i++)e.splice(n+i,0,{id:o[t].meta.versionId,meta:o[t].meta,value:f[i],span:1})}}}function OR(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 Fc(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function wc(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return mt(t,"year");let r=Math.floor(o/2592e3);if(r>0)return mt(r,"month");let a=Math.floor(o/86400);if(a>0)return mt(a,"day");let n=Math.floor(o/3600);if(n>0)return mt(n,"hour");let l=Math.floor(o/60);return l>0?mt(l,"minute"):mt(o,"second")}function mt(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as HR,jsx as qe,jsxs as Oc}from"react/jsx-runtime";var VR=ER(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 s4(e){let{classes:o}=VR(),t=S(),[r,a]=NR(e.history);if(LR(()=>{!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 qe("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Mc(r);return qe("div",{className:o.container,children:qe("table",{className:o.root,children:qe("tbody",{children:l.map((f,i)=>Oc("tr",{className:f.span>0?o.startRow:o.normalRow,children:[f.span>0&&Oc(HR,{children:[qe("td",{className:o.author,rowSpan:f.span,children:qe(co,{value:f.meta.author,link:!0})}),qe("td",{className:o.dateTime,rowSpan:f.span,children:qe(le,{to:Fc(n,f.meta.versionId),children:wc(f.meta.lastUpdated)})})]}),qe("td",{className:o.lineNumber,children:i+1}),qe("td",{className:o.line,children:qe("pre",{className:o.pre,children:f.value})})]},"row-"+i))})})})}import{createStyles as qR}from"@mantine/core";import{stringify as Ec}from"@medplum/core";import{Fragment as QR,jsx as pt,jsxs as zR}from"react/jsx-runtime";var GR=qR(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function x4(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Ec(o,!0).match(/[^\r\n]+/g),a=Ec(t,!0).match(/[^\r\n]+/g),n=ga(r,a);return pt("pre",{style:{color:"gray"},children:n.map((l,f)=>pt(UR,{delta:l},"delta"+f))})}function UR(e){let{classes:o}=GR();return zR(QR,{children:["...",pt("br",{}),e.delta.original.lines.length>0&&pt("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
71
|
+
}`.replace(/\s+/g," ");return(await e.graphql(r)).data.StructureDefinitionList[0]}function mg(e){return e.type==="profile"&&!e?.error&&ag(e.resourceType)}import{ActionIcon as Cs,Button as Cg,Group as Dr,Stack as bn,createStyles as bg}from"@mantine/core";import{getPathDisplayName as Rg,getPropertyDisplayName as Pg,isEmpty as Rn,tryGetProfile as Tg}from"@medplum/core";import{useEffect as kg,useState as Vt}from"react";import{arrayify as xg,getElementDefinitionFromElements as Ig,getTypedPropertyValueWithSchema as gg,isPopulated as hg,matchDiscriminant as yg}from"@medplum/core";function vg(e,o,t){for(let r of[t.elements,t.typeSchema?.elements]){let a;if(hg(r)){let n=Ig(r,o.path);n&&(a=gg(e.value,o.path,n))}if(a)return xg(a)?.some(n=>yg(n,o,t,r))??!1}return!1}function Sg(e,o,t){if(e)for(let r of o){let a={value:e,type:r.typeSchema?.name??r.type[0].code};if(t.every(n=>vg(a,n,r)))return r.name}}function Cn(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=Sg(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 Ss(e){return e.type!==void 0&&e.type.length>0}import{jsx as oe,jsxs as Br}from"react/jsx-runtime";var bs=bg(e=>({indented:{marginTop:"0.5rem",borderLeft:`3px solid ${e.colors.gray[4]}`,padding:"0.5rem 0 0.5rem 0.5rem"}}));function Rs(e){let{property:o}=e,t=S(),[r,a]=Vt(!0),[n,l]=Vt([]),[f]=Vt(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[i,s]=Vt([[]]),{classes:u}=bs(),c=o.type[0]?.code;kg(()=>{if(!o.slicing){let P=[];l(P);let h=Cn(f,P,o.slicing);s(h),a(!1);return}let y=[],v=[],b=[];for(let P of o.slicing.slices){if(!Ss(P))continue;let h=P.type[0],A;Rn(P.elements)&&h.profile&&(A=h.profile[0]),y.push(P),v.push(A),A?b.push(t.requestProfileSchema(A)):b.push(Promise.resolve())}Promise.all(b).then(()=>{for(let h=0;h<y.length;h++){let A=y[h],W=v[h];if(W){let Y=Tg(W);A.typeSchema=Y}}l(y);let P=Cn(f,y,o.slicing);s(P),a(!1)}).catch(P=>{console.error(P),a(!1)})},[t,o.slicing,c,f]);function d(y,v){let b=[...i];if(b[v]=y,s(b),e.onChange){let P=b.flat().filter(h=>h!==void 0);e.onChange(P)}}if(r)return oe("div",{children:"Loading..."});let m=n.length,p=i[m],x=!(e.hideNonSliceValues??(c==="Extension"&&n.length>0)),C=Rg(o.path);return Br(bn,{className:e.indent?u.indented:void 0,children:[n.map((y,v)=>oe(Dg,{slice:y,property:o,defaultValue:i[v],onChange:b=>{d(b,v)},testId:`slice-${y.name}`},y.name)),x&&p.map((y,v)=>Br(Dr,{noWrap:!0,style:{flexGrow:1},children:[oe("div",{style:{flexGrow:1},children:oe(io,{arrayElement:!0,property:e.property,name:e.name+"."+v,defaultValue:y,onChange:b=>{let P=[...p];P[v]=b,d(P,m)},defaultPropertyType:void 0,outcome:e.outcome})}),oe(Ts,{propertyDisplayName:C,testId:`nonsliced-remove-${v}`,onClick:b=>{M(b);let P=[...p];P.splice(v,1),d(P,m)}})]},`${v}-${p.length}`)),x&&i.flat().length<o.max&&oe(Dr,{noWrap:!0,style:{justifyContent:"flex-start"},children:oe(Ps,{propertyDisplayName:C,onClick:y=>{M(y);let v=[...p];v.push(void 0),d(v,m)},testId:"nonsliced-add"})})]})}function Dg(e){let{slice:o,property:t}=e,[r,a]=Vt(()=>e.defaultValue.map(u=>u??{})),{classes:n}=bs();function l(u){a(u),e.onChange&&e.onChange(u)}let f=o.min>0,i=Rn(o.elements),s=Pg(o.name);return oe(pe,{title:s,description:o.definition,withAsterisk:f,fhirPath:`${t.path}:${o.name}`,testId:e.testId,children:Br(bn,{className:i?n.indented:void 0,children:[r.map((u,c)=>Br(Dr,{noWrap:!0,children:[oe("div",{style:{flexGrow:1},children:oe(bn,{children:Rn(o.elements)?oe(Ar,{elementDefinitionType:o.type[0],name:o.name,defaultValue:u,onChange:d=>{let m=[...r];m[c]=d,l(m)},outcome:void 0,min:o.min,max:o.max,binding:void 0,path:o.path}):oe(Mr,{type:o.type[0].code,elements:o.elements,defaultValue:u,outcome:e.outcome,onChange:d=>{let m=[...r];m[c]=d,l(m)},testId:e.testId&&`${e.testId}-elements-${c}`})})}),r.length>o.min&&oe(Ts,{propertyDisplayName:s,testId:e.testId&&`${e.testId}-remove-${c}`,onClick:d=>{M(d);let m=[...r];m.splice(c,1),l(m)}})]},`${c}-${r.length}`)),r.length<o.max&&oe(Dr,{noWrap:!0,style:{justifyContent:"flex-start"},children:oe(Ps,{propertyDisplayName:s,onClick:u=>{M(u);let c=[...r,void 0];l(c)},testId:e.testId&&`${e.testId}-add`})})]})})}function Ps({propertyDisplayName:e,onClick:o,testId:t}){let r=e?`Add ${e}`:"Add";return e?oe(Cg,{title:r,size:"sm",color:"green.6",variant:"subtle","data-testid":t,leftIcon:oe(So,{size:"1.25rem"}),onClick:o,children:r}):oe(Cs,{title:r,color:"green.6","data-testid":t,onClick:o,children:oe(So,{size:"1.25rem"})})}function Ts({propertyDisplayName:e,onClick:o,testId:t}){return oe(Cs,{title:e?`Remove ${e}`:"Remove",color:"red.5","data-testid":t,onClick:o,children:oe(lo,{size:"1.25rem"})})}import{ActionIcon as Bg,Flex as Ag,Textarea as Mg}from"@mantine/core";import{useClipboard as Fg}from"@mantine/hooks";import{showNotification as wg}from"@mantine/notifications";import{useRef as Og,useState as Eg}from"react";import{jsx as Pn,jsxs as Lg}from"react/jsx-runtime";function ks(e){let[o,t]=Eg(!1),r=Fg(),a=Og(null),n={...e.styles};return o||(n.input||(n.input={}),n.input.WebkitTextSecurity="disc"),Lg(Ag,{gap:"xs",children:[Pn(Mg,{...e,styles:{...n,root:{...n.root??{},flexGrow:1}},ref:a,autosize:!0,minRows:1,onFocus:()=>t(!0),onBlur:()=>t(!1)}),Pn(Bg,{title:"Copy secret",onClick:()=>{r.copy(a.current?.value),wg({color:"green",message:"Copied"})},children:Pn(Pt,{})})]})}import{Button as As,Chip as Ds,Group as Fr,Modal as Ng,NativeSelect as Vg,Stack as Hg,Switch as qg,TextInput as Gg}from"@mantine/core";import{formatTiming as Ug}from"@medplum/core";import{useRef as Ms,useState as Tn}from"react";import{Fragment as ws,jsx as de,jsxs as Ht}from"react/jsx-runtime";var Qg=["sun","mon","tue","wed","thu","fri","sat"];function Fs(e){let[o,t]=Tn(e.defaultValue),[r,a]=Tn(!1),n=Ms();return n.current=o,Ht(ws,{children:[Ht(Fr,{spacing:"xs",grow:!0,noWrap:!0,children:[de("span",{children:Ug(n.current)||"No repeat"}),de(As,{onClick:()=>a(!0),children:"Edit"})]}),de(zg,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var Bs={repeat:{period:1,periodUnit:"d"}};function zg(e){let[o,t]=Tn(e.defaultValue||Bs),r=Ms();r.current=o;function a(s){t({...r.current,event:[s]})}function n(s){t({...r.current,repeat:s})}function l(s){n({...r.current?.repeat,period:s})}function f(s){n({...r.current?.repeat,periodUnit:s})}function i(s){n({...r.current?.repeat,dayOfWeek:s})}return de(Ng,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:Ht(Hg,{children:[de(pe,{title:"Starts on",htmlFor:"timing-dialog-start",children:de(Ve,{name:"timing-dialog-start",onChange:s=>a(s)})}),de(qg,{label:"Repeat",checked:!!o.repeat,onChange:s=>n(s.currentTarget.checked?Bs.repeat:void 0)}),o.repeat&&Ht(ws,{children:[de(pe,{title:"Repeat every",htmlFor:"timing-dialog-period",children:Ht(Fr,{spacing:"xs",grow:!0,noWrap:!0,children:[de(Gg,{type:"number",step:1,id:"timing-dialog-period",name:"timing-dialog-period",defaultValue:o.repeat.period||1,onChange:s=>l(parseInt(s.currentTarget.value,10)||1)}),de(Vg,{id:"timing-dialog-periodUnit",name:"timing-dialog-periodUnit",defaultValue:o.repeat.periodUnit,onChange:s=>f(s.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"&&de(pe,{title:"Repeat on",children:de(Ds.Group,{multiple:!0,onChange:i,children:de(Fr,{position:"apart",mt:"md",spacing:"xs",children:Qg.map(s=>de(Ds,{value:s,size:"xs",radius:"xl",children:s.charAt(0).toUpperCase()},s))})})})]}),de(Fr,{position:"right",children:de(As,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as q,jsxs as eh}from"react/jsx-runtime";function io(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.isArray||o.max>1)&&!e.arrayElement){if(n===E.Attachment)return q(wf,{name:t,defaultValue:r,onChange:a});let f=l[0]?.code!==E.Extension;return q(Rs,{property:o,name:t,defaultValue:r,indent:f,onChange:a,outcome:e.outcome})}return l.length>1?q(Zg,{elementDefinitionTypes:l,...e}):q(Ar,{name:t,defaultValue:r,onChange:f=>{if(e.onChange){let i=e.name.replace("[x]",Os(l[0].code));e.onChange(f,i)}},outcome:e.outcome,elementDefinitionType:l[0],min:o.min,max:o.min,binding:o.binding,path:o.path})}function Zg(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=Kg(t);return eh(Xg,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[q(Jg,{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}))}),q(Ar,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",Os(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path})]})}function Ar(e){let{name:o,defaultValue:t,onChange:r,outcome:a,binding:n,path:l}=e,f=e.min!==void 0&&e.min>0,i=e.elementDefinitionType.code;if(!i)return q("div",{children:"Property type not specified "});let s={name:o,defaultValue:t,onChange:r,outcome:a,path:l};switch(i){case E.SystemString:case E.canonical:case E.string:case E.time:case E.uri:case E.url:return e.path==="Project.secret.value[x]"?q(ks,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{e.onChange&&e.onChange(u.currentTarget.value)},error:Q(e.outcome,o)}):q(kn,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:Q(a,o)});case E.date:return q(kn,{type:"date",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:Q(a,o)});case E.dateTime:case E.instant:return q(Ve,{name:o,defaultValue:t,onChange:r,outcome:a});case E.decimal:case E.integer:case E.positiveInt:case E.unsignedInt:return q(kn,{type:"number",step:i===E.decimal?"any":"1",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.valueAsNumber)}});case E.code:return q(mr,{...s,binding:n?.valueSet});case E.boolean:return q(Wg,{id:o,name:o,"data-testid":o,defaultChecked:!!t,onChange:u=>{r&&r(u.currentTarget.checked)}});case E.base64Binary:case E.markdown:return q($g,{id:o,spellCheck:i!==E.base64Binary,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)}});case E.Address:return q(tf,{...s});case E.Annotation:return q(rf,{...s});case E.Attachment:return q(xr,{...s});case E.CodeableConcept:return q(_o,{binding:n?.valueSet,...s});case E.Coding:return q(Rr,{binding:n?.valueSet,...s});case E.ContactDetail:return q(Yf,{...s});case E.ContactPoint:return q(Pr,{...s});case E.Extension:return q(as,{...s,propertyType:e.elementDefinitionType});case E.HumanName:return q(ns,{...s});case E.Identifier:return q(ss,{...s});case E.Money:return q(is,{...s});case E.Period:return q(cs,{...s});case E.Duration:case E.Quantity:return q(Ae,{...s});case E.Range:return q(Lt,{...s});case E.Ratio:return q(xs,{...s});case E.Reference:return q(Zo,{...s,targetTypes:jg(e.elementDefinitionType)});case E.Timing:return q(Fs,{...s});case E.Dosage:case E.UsageContext:default:return q(Ko,{typeName:i,defaultValue:t,onChange:r,outcome:a})}}var Yg=[`${_g}/fhir/StructureDefinition/`,"https://medplum.com/fhir/StructureDefinition/"];function jg(e){return e?.targetProfile?.map(o=>{let t=Yg.find(r=>o.startsWith(r));return t?o.slice(t.length):o})}import{jsx as wr}from"react/jsx-runtime";var Dn=new Set(["extension","modifierExtension"]),nh=new Set(["id",...Ir].filter(e=>!Dn.has(e)));function Mr(e){let{elements:o}=e,[t,r]=ah(e.defaultValue??{}),a=rh(()=>{let l=Object.create(null);for(let[f,i]of Object.entries(o))i.fixed&&(l[f]=i);return l},[o]);function n(l){for(let[f,i]of Object.entries(a))Ot(l,f,f,i,i.fixed.value);r(l),e.onChange&&e.onChange(l)}return wr(oh,{style:{flexGrow:1},"data-testid":e.testId,children:Object.entries(o).map(([l,f])=>{if(!f.type||f.max===0||l==="url"&&f.fixed||Dn.has(l)&&!th(f.slicing?.slices))return null;if(nh.has(l))return null;if(gr.includes(l)&&f.path.split(".").length===2||l.includes("."))return null;let[i,s]=Xf(t,l,f),u=f.min!==void 0&&f.min>0,c=wr(io,{property:f,name:l,defaultValue:i,defaultPropertyType:s,onChange:(d,m)=>{n(Ot({...t},l,m??l,f,d))},arrayElement:void 0,outcome:e.outcome},l);return e.type==="Extension"||Dn.has(l)?c:f.type.length===1&&f.type[0].code==="boolean"?wr(Cr,{title:Es(l),description:f.description,htmlFor:l,fhirPath:f.path,withAsterisk:u,children:c},l):wr(pe,{title:Es(l),description:f.description,withAsterisk:u,htmlFor:l,outcome:e.outcome,fhirPath:f.path,children:c},l)})})}import{jsx as Ns,jsxs as ih}from"react/jsx-runtime";function Ko(e){let{typeName:o}=e,[t,r]=sh(e.defaultValue??{}),a=fh(Ne),n=e.profileUrl??a.profileUrl,l=Ls(()=>lh(o,n),[o,n]),f=Ls(()=>Jf(l,n),[l,n]);if(!l)return ih("div",{children:[o,"\xA0not implemented"]});function i(s){r(s),e.onChange&&e.onChange(s)}return Ns(Ne.Provider,{value:f,children:Ns(Mr,{type:l.type,elements:l.elements,defaultValue:t,onChange:i,outcome:e.outcome})})}import{Button as Bn,createStyles as uh,Group as Hs}from"@mantine/core";import{useMemo as ch,useState as dh}from"react";function Vs(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function Or(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as xe,jsxs as qt}from"react/jsx-runtime";var mh=uh(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 qs(e){let{classes:o}=mh(),{onChangeMonth:t,onClick:r}=e,[a,n]=dh(Or);function l(i){n(s=>{let u=new Date(s.getTime());return u.setMonth(s.getMonth()+i),t(u),u})}let f=ch(()=>ph(a,e.slots),[a,e.slots]);return qt("div",{children:[qt(Hs,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[xe("p",{style:{flex:1},children:Vs(a)}),qt(Hs,{position:"right",spacing:"xs",children:[xe(Bn,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),xe(Bn,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),qt("table",{className:o.table,children:[xe("thead",{children:qt("tr",{children:[xe("th",{children:"SUN"}),xe("th",{children:"MON"}),xe("th",{children:"TUE"}),xe("th",{children:"WED"}),xe("th",{children:"THU"}),xe("th",{children:"FRI"}),xe("th",{children:"SAT"})]})}),xe("tbody",{children:f.map((i,s)=>xe("tr",{children:i.map((u,c)=>xe("td",{children:u&&xe(Bn,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+c))},"week-"+s))})]})]})}function ph(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:xh(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 xh(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 Ih,createStyles as gh}from"@mantine/core";import{jsx as yh}from"react/jsx-runtime";var hh=gh(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function uo(e){let{children:o,...t}=e,{classes:r}=hh();return yh(Ih,{className:r.root,...t,children:o})}import{ActionIcon as Si,Center as Ay,createStyles as My,Group as Fy,Loader as wy,Menu as je,ScrollArea as Oy,TextInput as Ey}from"@mantine/core";import{showNotification as Ly,updateNotification as qr}from"@mantine/notifications";import{getReferenceString as Qt,normalizeErrorString as Ci}from"@medplum/core";import{useCallback as Gr,useEffect as Ny,useRef as bi,useState as Ri}from"react";import{createStyles as Oh,Group as Lr,List as zs,Stack as Ws,Text as Me,Title as Xs}from"@mantine/core";import{capitalize as Eh,formatCodeableConcept as Lh,formatDateTime as Mn,formatObservationValue as Nh,isReference as Vh}from"@medplum/core";import{useEffect as Hh,useState as qh}from"react";import{Blockquote as vh,createStyles as Sh,Stack as Ch}from"@mantine/core";import{jsx as Gs}from"react/jsx-runtime";var bh=Sh(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function An({value:e}){let{classes:o}=bh();return e?Gs(Ch,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&Gs(vh,{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 Bh}from"@mantine/core";import{Text as Rh}from"@mantine/core";import{getDisplayString as Ph,isOk as Th,normalizeErrorString as kh}from"@medplum/core";import{useState as Dh}from"react";import{jsx as Us}from"react/jsx-runtime";function Ue(e){let{value:o,link:t,...r}=e,[a,n]=Dh(),l=X(o,n),f;if(a&&!Th(a))f=`[${kh(a)}]`;else if(l)f=Ph(l);else return null;return t?Us(le,{to:o,...r,children:f}):Us(Rh,{component:"span",...r,children:f})}import{jsx as Qs,jsxs as Ah}from"react/jsx-runtime";function co(e){return Ah(Bh,{spacing:"xs",children:[Qs(fe,{size:24,radius:12,value:e.value,link:e.link}),Qs(Ue,{value:e.value,link:e.link})]})}import{Badge as Mh}from"@mantine/core";import{jsx as wh}from"react/jsx-runtime";var Fh={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 Er(e){return wh(Mh,{color:Fh[e.status],children:e.status})}import{Fragment as Gt,jsx as k,jsxs as Ie}from"react/jsx-runtime";var Js=Oh(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}}));Fn.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function Fn(e){let o=S(),t=X(e.value),[r,a]=qh();if(Hh(()=>{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 Ie(Ws,{children:[k(Xs,{children:"Diagnostic Report"}),k(Gh,{value:t}),r&&!e.hideSpecimenInfo&&Uh(r),t.result&&k(Qh,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&k(An,{value:n})]})}function Gh({value:e}){return Ie(Lr,{mt:"md",spacing:30,children:[e.subject&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),k(Me,{children:k(co,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),k(Me,{children:k(co,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),k(Me,{children:k(co,{value:o,link:!0})})]},o.reference)),e.issued&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),k(Me,{children:Mn(e.issued)})]}),e.status&&Ie("div",{children:[k(Me,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),k(Me,{children:Eh(e.status)})]})]})}function Uh(e){return Ie(Ws,{spacing:"xs",children:[k(Xs,{order:2,size:"h6",children:"Specimens"}),k(zs,{type:"ordered",children:e?.map(o=>k(zs.Item,{ml:"sm",children:Ie(Lr,{spacing:20,children:[Ie(Lr,{spacing:5,children:[k(Me,{fw:500,children:"Collected:"})," ",Mn(o.collection?.collectedDateTime)]}),Ie(Lr,{spacing:5,children:[k(Me,{fw:500,children:"Received:"})," ",Mn(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Qh(e){let{classes:o}=Js();return Ie("table",{className:o.table,children:[k("thead",{children:Ie("tr",{children:[k("th",{children:"Test"}),k("th",{children:"Value"}),k("th",{children:"Reference Range"}),k("th",{children:"Interpretation"}),k("th",{children:"Category"}),k("th",{children:"Performer"}),k("th",{children:"Status"})]})}),k("tbody",{children:k($s,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function $s(e){return k(Gt,{children:e.value?.map(o=>k(zh,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${Vh(o)?o.reference:o.id}`))})}function zh(e){let{classes:o,cx:t}=Js(),r=X(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=Jh(r);return Ie(Gt,{children:[Ie("tr",{className:t({[o.criticalRow]:n}),children:[k("td",{rowSpan:a?2:1,children:k(le,{to:r,children:k(ye,{value:r.code})})}),k("td",{children:k(Wh,{value:r})}),k("td",{children:k(Xh,{value:r.referenceRange})}),k("td",{children:r.interpretation&&r.interpretation.length>0&&k(ye,{value:r.interpretation[0]})}),k("td",{children:r.category&&r.category.length>0&&k(Gt,{children:r.category.map(l=>k("div",{children:k(ye,{value:l})},`category-${Lh(l)}`))})}),k("td",{children:r.performer?.map(l=>k(To,{value:l},l.reference))}),k("td",{children:r.status&&k(Er,{status:r.status})})]}),r.hasMember&&k($s,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&k("tr",{children:k("td",{colSpan:6,children:k(An,{value:r.note})})})]})}function Wh(e){let o=e.value;return k(Gt,{children:Nh(o)})}function Xh(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?k(Gt,{children:o.text}):k(yr,{value:o}):null}function Jh(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as $h,Paper as _h,useComponentDefaultProps as Kh}from"@mantine/core";import{jsx as jh}from"react/jsx-runtime";var Zh=$h((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%"}}})),Yh={shadow:"xs",radius:"md",withBorder:!0};function Yo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Kh("Panel",Yh,e),{classes:f,cx:i}=Zh({width:r,fill:a},{name:"Panel",unstyled:n});return jh(_h,{className:i(f.paper,o),...l,children:t})}import{createStyles as xy}from"@mantine/core";import{capitalize as Iy,evalFhirPathTyped as ui,getSearchParameterDetails as gy,toTypedValue as ci}from"@medplum/core";var mi=gd(ii(),1);import{useEffect as hy,useState as yy}from"react";import{jsx as Ye,jsxs as Hr}from"react/jsx-runtime";var vy=xy(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 pi(e){let{classes:o}=vy(),t=S(),[r,a]=yy(!1);if(hy(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,mi.createPatch)(e.original,e.revised),l=[ci(e.original)],f=[ci(e.revised)];return Hr("table",{className:o.root,children:[Ye("thead",{children:Hr("tr",{children:[Ye("th",{}),Ye("th",{children:"Before"}),Ye("th",{children:"After"})]})}),Ye("tbody",{children:n.map(i=>{if(i.path.startsWith("/meta"))return null;let s=i.path,u=Sy(s),d=gy(e.original.resourceType,{resourceType:"SearchParameter",base:[e.original.resourceType],code:e.original.resourceType+"."+u,expression:e.original.resourceType+"."+u})?.elementDefinitions?.[0],m=!!d?.isArray,p=i.op==="add"?void 0:ui(u,l)?.[0],x=i.op==="remove"?void 0:ui(u,f)?.[0];return Hr("tr",{children:[Hr("td",{children:[Iy(i.op)," ",u]}),Ye("td",{className:o.removed,children:p&&Ye(ce,{property:d,propertyType:p.type,value:di(p.value,m),ignoreMissingValues:!0})}),Ye("td",{className:o.added,children:x&&Ye(ce,{property:d,propertyType:x.type,value:di(x.value,m),ignoreMissingValues:!0})})]},`op-${i.op}-${i.path}`)})})]})}function Sy(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 di(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as Cy,useState as by}from"react";import{jsx as Ry}from"react/jsx-runtime";function zn(e){let o=S(),t=X(e.value),[r,a]=by(!1);return Cy(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:Ry(wt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as Py,Group as Ty,Menu as xi,Text as Wn}from"@mantine/core";import{formatDateTime as ky,getReferenceString as Dy}from"@medplum/core";import{Fragment as By,jsx as Fe,jsxs as jo}from"react/jsx-runtime";function Ii(e){return Fe(uo,{children:e.children})}function mo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,f=e.dateTime??o.meta?.lastUpdated;return jo(Yo,{"data-testid":"timeline-item",fill:!0,...n,children:[jo(Ty,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Fe(fe,{value:l,link:!0,size:"md"}),jo("div",{style:{flex:1},children:[Fe(Wn,{size:"sm",children:Fe(Ue,{color:"dark",weight:500,value:l,link:!0})}),jo(Wn,{size:"xs",children:[Fe(le,{color:"dimmed",to:e.resource,children:ky(f)}),Fe(Wn,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Fe(le,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&jo(xi,{position:"bottom-end",shadow:"md",width:200,children:[Fe(xi.Target,{children:Fe(Py,{radius:"xl","aria-label":`Actions for ${Dy(e.resource)}`,children:Fe(Ua,{})})}),a]})]}),jo(Go,{children:[r&&Fe("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Fe(By,{children:e.children})]})]})}function yi(e,o){e.sort((t,r)=>{let a=gi(t,o),n=gi(r,o);return a>n?1:a<n?-1:hi(t,o)-hi(r,o)})}function gi(e,o){if(!vi(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function hi(e,o){if(!vi(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 vi(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as Xy,jsx as D,jsxs as zt}from"react/jsx-runtime";var Vy=My(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function po(e){let o=S(),t=no(),r=o.getProfile(),a=bi(null),n=X(e.value),[l,f]=Ri(),[i,s]=Ri([]),u=e.loadTimelineResources,c=bi(i);c.current=i;let d=Gr(R=>{yi(R,n),R.reverse(),s(R)},[n]),m=Gr(R=>{let N=[];for(let ao of R){if(ao.status!=="fulfilled")continue;let T=ao.value;if(T.type==="history"&&f(T),T.entry)for(let G of T.entry)N.push(G.resource)}d(N)},[d]),p=Gr(R=>d([...c.current,R]),[d]),x=Gr(()=>{let R,N;"resourceType"in e.value?(R=e.value.resourceType,N=e.value.id):[R,N]=e.value.reference?.split("/"),u(o,R,N).then(m).catch(console.log)},[o,e.value,u,m]);Ny(()=>x(),[x]);function C(R){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,R)).then(N=>p(N)).catch(console.log)}function y(R){!n||!e.createMedia||o.createResource(e.createMedia(n,r,R)).then(N=>p(N)).then(()=>qr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:D(bt,{size:16}),autoClose:2e3})).catch(N=>qr({id:"upload-notification",color:"red",title:"Upload error",message:Ci(N),icon:D(fr,{size:16}),autoClose:2e3}))}function v(R,N){return o.updateResource({...R,priority:N})}function b(R){v(R,"stat").then(x).catch(console.log)}function P(R){v(R,"routine").then(x).catch(console.log)}function h(R){t(`/${R.resourceType}/${R.id}`)}function A(R){t(`/${R.resourceType}/${R.id}/edit`)}function W(R){t(`/${R.resourceType}/${R.id}/delete`)}function Y(R){t(`/${R.resourceType}/${R.id}/_history/${R.meta?.versionId}`)}function gt(){Ly({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function ke(R){qr({id:"upload-notification",loading:!0,title:"Uploading...",message:Wy(R),autoClose:!1,withCloseButton:!1})}function De(R){qr({id:"upload-notification",color:"red",title:"Upload error",message:Ci(R),icon:D(fr,{size:16}),autoClose:2e3})}return n?zt(Ii,{children:[e.createCommunication&&D(Yo,{children:D(H,{testid:"timeline-form",onSubmit:R=>{C(R.text);let N=a.current;N&&(N.value="",N.focus())},children:zt(Fy,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[D(fe,{value:r}),D(Ey,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),D(Si,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:D(_a,{size:16})}),D(Jo,{onUpload:y,onUploadStart:gt,onUploadProgress:ke,onUploadError:De,children:R=>D(Si,{...R,radius:"xl",color:"blue",variant:"filled",children:D(Rt,{size:16})})})]})})}),i.map(R=>{if(!R)return null;let N=`${R.resourceType}/${R.id}/${R.meta?.versionId}`;if(R.resourceType===n.resourceType&&R.id===n.id)return D(Hy,{history:l,resource:R,onDetails:Y},N);switch(R.resourceType){case"AuditEvent":return D(Qy,{resource:R,onDetails:h},N);case"Communication":return D(Gy,{resource:R,onPin:R.priority!=="stat"?b:void 0,onUnpin:R.priority==="stat"?P:void 0,onDetails:h,onEdit:A,onDelete:W},N);case"DiagnosticReport":return D(zy,{resource:R,onDetails:h,onEdit:A,onDelete:W},N);case"Media":return D(Uy,{resource:R,onDetails:h,onEdit:A,onDelete:W},N);default:return D(mo,{resource:R,padding:!0,children:D(zn,{value:R,ignoreMissingValues:!0})},N)}})]}):D(Ay,{style:{width:"100%",height:"100%"},children:D(wy,{})})}function et(e){return zt(je.Dropdown,{children:[D(je.Label,{children:"Resource"}),e.onPin&&D(je.Item,{icon:D(Ka,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Qt(e.resource)}`,children:"Pin"}),e.onUnpin&&D(je.Item,{icon:D(Za,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Qt(e.resource)}`,children:"Unpin"}),e.onDetails&&D(je.Item,{icon:D(Ja,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Qt(e.resource)}`,children:"Details"}),e.onEdit&&D(je.Item,{icon:D(Qa,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Qt(e.resource)}`,children:"Edit"}),e.onDelete&&zt(Xy,{children:[D(je.Divider,{}),D(je.Label,{children:"Danger zone"}),D(je.Item,{color:"red",icon:D(Dt,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Qt(e.resource)}`,children:"Delete"})]})]})}function Hy(e){let o=qy(e.history,e.resource);return o?D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(pi,{original:o,revised:e.resource})}):zt(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:[D("h3",{children:"Created"}),D(zn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function qy(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 Gy(e){let{classes:o}=Vy(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return D(mo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:D(et,{...e}),children:D("p",{children:e.resource.payload?.[0]?.contentString})})}function Uy(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return D(mo,{resource:e.resource,padding:!!t,popupMenuItems:D(et,{...e}),children:D(Ge,{value:e.resource.content})})}function Qy(e){return D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(Oy,{children:D("pre",{children:e.resource.outcomeDesc})})})}function zy(e){return D(mo,{resource:e.resource,padding:!0,popupMenuItems:D(et,{...e}),children:D(Fn,{value:e.resource})})}function Wy(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Xn(e.loaded)} / ${Xn(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Xn(e.loaded)}`}function Xn(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 Jy}from"react/jsx-runtime";function t2(e){return Jy(po,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:100})])}})}import{jsx as Pi}from"react/jsx-runtime";function Ur(e){let{children:o,...t}=e;return Pi(uo,{children:Pi(Yo,{...t,children:o})})}import{createReference as Qr}from"@medplum/core";import{jsx as $y}from"react/jsx-runtime";function p2(e){return $y(po,{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:Qr(o),subject:o.subject,sender:Qr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:Qr(o),subject:o.subject,operator:Qr(t),issued:new Date().toISOString(),content:r})})}import{Button as mS,Loader as pS,Table as xS}from"@mantine/core";import{normalizeOperationOutcome as IS}from"@medplum/core";import{memo as gS,useEffect as lu,useRef as fu,useState as Zr}from"react";import{evalFhirPath as _y}from"@medplum/core";import{jsx as Ky}from"react/jsx-runtime";function Ti(e){let o;try{o=_y(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 Ky(ce,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as Kv,Button as nt,Center as _r,createStyles as Zv,Group as Kr,Loader as Yv,Menu as ru,Pagination as jv,Table as eS,Text as rl,UnstyledButton as oS}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as fl,formatSearchQuery as tS}from"@medplum/core";import{memo as rS,useCallback as au,useEffect as nu,useRef as aS,useState as al}from"react";import{Box as Zy,Button as Yy,Modal as jy,Text as ev}from"@mantine/core";import{jsx as zr,jsxs as Di}from"react/jsx-runtime";function Bi(e){return Di(jy,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Di(Zy,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&zr(ki,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&zr(ki,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),zr(ev,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function ki(e){return zr(Yy,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as cv,Group as dv,Modal as mv,MultiSelect as pv,Stack as xv}from"@mantine/core";import{getDataType as Iv,getSearchParameters as gv,stringify as hv}from"@medplum/core";import{useEffect as yv,useMemo as vv,useRef as Sv,useState as zi}from"react";import{capitalize as ov,DEFAULT_SEARCH_COUNT as tv,evalFhirPathTyped as rv,formatDateTime as av,Operator as O}from"@medplum/core";import{Fragment as uv,jsx as Jn}from"react/jsx-runtime";var nv={string:[O.EQUALS,O.NOT,O.CONTAINS,O.EXACT],fulltext:[O.EQUALS,O.NOT,O.CONTAINS,O.EXACT],token:[O.EQUALS,O.NOT],reference:[O.EQUALS,O.NOT],numeric:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS],quantity:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS],date:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS,O.STARTS_AFTER,O.ENDS_BEFORE,O.APPROXIMATELY],datetime:[O.EQUALS,O.NOT_EQUALS,O.GREATER_THAN,O.LESS_THAN,O.GREATER_THAN_OR_EQUALS,O.LESS_THAN_OR_EQUALS,O.STARTS_AFTER,O.ENDS_BEFORE,O.APPROXIMATELY]},lv={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 Wt(e,o){return{...e,filters:o,offset:0,name:void 0}}function A2(e){return Wt(e,[])}function Wr(e,o){return Wt(e,(e.filters??[]).filter(t=>t.code!==o))}function ot(e,o,t,r,a){a&&(e=Wr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Wt(e,n)}function M2(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 Mi(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function Fi(e,o){return $n(e,o,-1)}function wi(e,o){return $n(e,o,0)}function Oi(e,o){return $n(e,o,1)}function $n(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),Kn(e,o,r,a)}function Ei(e,o){return _n(e,o,-1)}function Li(e,o){return _n(e,o,0)}function Ni(e,o){return _n(e,o,1)}function _n(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),Kn(e,o,r,a)}function Vi(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Kn(e,o,t,new Date)}function Kn(e,o,t,r){return e=Wr(e,o),e=Ai(e,o,O.GREATER_THAN_OR_EQUALS,t),e=Ai(e,o,O.LESS_THAN_OR_EQUALS,r),e}function Ai(e,o,t,r){return ot(e,o,t,r.toISOString())}function Zn(e,o,t=!0){return ot(e,o,O.MISSING,t.toString())}function fv(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function Hi(e,o){let t=e.count??tv,r=(o-1)*t;return fv(e,r)}function Yn(e,o,t){return o===qi(e)&&t!==void 0&&t===Gi(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function F2(e,o){let t=!1;return qi(e)===o&&(t=!Gi(e)),Yn(e,o,t)}function qi(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function Gi(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function Ui(e){return nv[e.type]}function Xt(e){return lv[e]??""}function we(e){let o=e;return o.includes(".")&&(o=o.split(".").pop()),o==="versionId"?"Version ID":(o=o.replace("[x]",""),o=o.replace(/([A-Z])/g," $1"),o=o.replace(/[-_]/g," "),o=o.replace(/\s+/g," "),o=o.trim(),o.toLowerCase()==="id"?"ID":o.split(/\s/).map(ov).join(" "))}function Qi(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?av(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?sv(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?iv(e,o.searchParams[0]):null}function sv(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=so({type:e.resourceType,value:e},t);return r?Jn(ce,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function iv(e,o){let t=rv(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:Jn(uv,{children:t.map((r,a)=>Jn(ce,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as Jt,jsxs as bv}from"react/jsx-runtime";function Wi(e){let o=Sv(!1),[t,r]=zi({search:JSON.parse(hv(e.search))}),[a,n]=zi(!1);yv(()=>{r({search:e.search})},[e.search]);let l=vv(()=>{if(!e.visible)return[];let i=e.search.resourceType,s=Iv(i),u=gv(i);return Cv(s,u).sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:we(c)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function f(i){r({search:{...t.search,fields:i}})}return Jt(mv,{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:Jt("div",{"data-testid":"overlay-child"})},children:bv(xv,{children:[Jt(pv,{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}),Jt(dv,{position:"right",children:Jt(cv,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function Cv(e,o){let t=[],r=new Set,a=new Set;for(let n of Object.keys(e.elements))t.push(n),r.add(n.toLowerCase()),a.add(we(n));if(o)for(let n of Object.keys(o)){let l=we(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as $t,Group as Mv,Modal as Fv,NativeSelect as $i}from"@mantine/core";import{getSearchParameters as wv,stringify as _i}from"@medplum/core";import{useEffect as Ov,useRef as Zi,useState as ol}from"react";import{formatDateTime as Rv,getSearchParameterDetails as Pv,globalSchema as Tv,Operator as Xi,SearchParameterType as kv}from"@medplum/core";import{Fragment as Ji,jsx as jn}from"react/jsx-runtime";function Xr(e){let{resourceType:o,filter:t}=e,r=Tv.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===Xi.EQUALS||t.operator===Xi.NOT_EQUALS))return jn(Ue,{value:{reference:t.value}});let a=Pv(o,r);if(t.code==="_lastUpdated"||a.type===kv.DATETIME)return jn(Ji,{children:Rv(t.value)})}return jn(Ji,{children:t.value})}import{Checkbox as Dv,TextInput as el}from"@mantine/core";import{getSearchParameterDetails as Bv,SearchParameterType as tt}from"@medplum/core";import{jsx as ko}from"react/jsx-runtime";function Jr(e){let o=Bv(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case tt.REFERENCE:return ko(Zo,{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 tt.BOOLEAN:return ko(Dv,{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 tt.DATE:return ko(el,{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 tt.DATETIME:return ko(Ve,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case tt.NUMBER:return ko(el,{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 tt.QUANTITY:return ko(Ae,{name:t,defaultValue:Av(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return ko(el,{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 Av(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as z,jsxs as eo}from"react/jsx-runtime";function Yi(e){let[o,t]=ol(JSON.parse(_i(e.search))),[r,a]=ol(-1),n=Zi(o);n.current=o,Ov(()=>{t(JSON.parse(_i(e.search)))},[e.search]);function l(u){t(ot(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let f=e.search.resourceType,i=wv(f)??{},s=o.filters||[];return eo(Fv,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[z("div",{children:eo("table",{children:[eo("colgroup",{children:[z("col",{style:{width:200}}),z("col",{style:{width:200}}),z("col",{style:{width:380}}),z("col",{style:{width:120}})]}),z("thead",{children:eo("tr",{children:[z("th",{children:"Field"}),z("th",{children:"Operation"}),z("th",{children:"Value"}),z("th",{children:"Actions"})]})}),eo("tbody",{children:[s.map((u,c)=>c===r?z(Ki,{resourceType:f,searchParams:i,defaultValue:u,okText:"Save",onOk:d=>{let m=[...s];m[c]=d,t(Wt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):z(Ev,{resourceType:f,searchParams:i,filter:u,onEdit:()=>a(c),onDelete:()=>t(Mi(n.current,c))},`filter-${u.code}-${u.operator}-${u.value}-display`)),z(Ki,{resourceType:f,searchParams:i,okText:"Add",onOk:l})]})]})}),z(Mv,{position:"right",mt:"xl",children:z($t,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function Ev(e){let{filter:o}=e;return eo("tr",{children:[z("td",{children:we(o.code)}),z("td",{children:Xt(o.operator)}),z("td",{children:z(Xr,{resourceType:e.resourceType,filter:o})}),eo("td",{children:[z($t,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),z($t,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function Ki(e){let[o,t]=ol(e.defaultValue??{}),r=Zi(o);r.current=o;function a(s){t({...r.current,code:s})}function n(s){t({...r.current,operator:s})}function l(s){t({...r.current,value:s})}let f=e.searchParams[o.code],i=f&&Ui(f);return eo("tr",{children:[z("td",{children:z($i,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:s=>a(s.currentTarget.value),data:["",...Object.keys(e.searchParams).map(s=>({value:s,label:we(s)}))]})}),z("td",{children:i&&z($i,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:s=>n(s.currentTarget.value),data:["",...i.map(s=>({value:s,label:Xt(s)}))]})}),z("td",{children:f&&o.operator&&z(Jr,{resourceType:e.resourceType,searchParam:f,defaultValue:o.value,onChange:l})}),eo("td",{children:[o.code&&o.operator&&z($t,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&z($t,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as Lv,Grid as tl,Modal as Nv}from"@mantine/core";import{useState as Vv}from"react";import{jsx as rt,jsxs as Hv}from"react/jsx-runtime";function ji(e){let[o,t]=Vv(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return rt(Nv,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:rt(H,{onSubmit:r,children:Hv(tl,{children:[rt(tl.Col,{span:10,children:rt(Jr,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),rt(tl.Col,{span:2,children:rt(Lv,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as B}from"@mantine/core";import{Operator as se}from"@medplum/core";import{Fragment as ou,jsx as g,jsxs as at}from"react/jsx-runtime";function eu(e){if(!e.searchParams)return null;function o(n,l){a(Yn(e.search,n.code,l))}function t(n){a(Wr(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(qv,{search:e.search,searchParam:e.searchParams[0],onSort:o,onPrompt:r,onChange:a,onClear:t}):g(B.Dropdown,{children:e.searchParams.map(n=>g(B.Item,{children:we(n.code)},n.code))})}function qv(e){switch(e.searchParam.type){case"date":return g(Gv,{...e});case"number":case"quantity":return g(Uv,{...e});case"reference":return g(Qv,{...e});case"string":case"token":case"uri":return g(zv,{...e});default:return at(ou,{children:["Unknown search param type: ",e.searchParam.type]})}}function Gv(e){let{searchParam:o}=e,t=o.code;return at(B.Dropdown,{children:[g(B.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),g(B.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),g(B.Divider,{}),g(B.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(ir,{size:14}),onClick:()=>e.onPrompt(o,se.ENDS_BEFORE),children:"Before..."}),g(B.Item,{icon:g(sr,{size:14}),onClick:()=>e.onPrompt(o,se.STARTS_AFTER),children:"After..."}),g(B.Item,{icon:g(Ea,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Between..."}),g(B.Divider,{}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Oi(e.search,t)),children:"Tomorrow"}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(wi(e.search,t)),children:"Today"}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Fi(e.search,t)),children:"Yesterday"}),g(B.Divider,{}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Ni(e.search,t)),children:"Next Month"}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Li(e.search,t)),children:"This Month"}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Ei(e.search,t)),children:"Last Month"}),g(B.Divider,{}),g(B.Item,{icon:g($e,{size:14}),onClick:()=>e.onChange(Vi(e.search,t)),children:"Year to date"}),g($r,{...e})]})}function Uv(e){let{searchParam:o}=e;return at(B.Dropdown,{children:[g(B.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),g(B.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),g(B.Divider,{}),g(B.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(sr,{size:14}),onClick:()=>e.onPrompt(o,se.GREATER_THAN),children:"Greater than..."}),g(B.Item,{icon:g(qo,{size:14}),onClick:()=>e.onPrompt(o,se.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),g(B.Item,{icon:g(ir,{size:14}),onClick:()=>e.onPrompt(o,se.LESS_THAN),children:"Less than..."}),g(B.Item,{icon:g(qo,{size:14}),onClick:()=>e.onPrompt(o,se.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),g($r,{...e})]})}function Qv(e){let{searchParam:o}=e;return at(B.Dropdown,{children:[g(B.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT),children:"Does not equal..."}),g($r,{...e})]})}function zv(e){let{searchParam:o}=e;return at(B.Dropdown,{children:[g(B.Item,{icon:g(Tt,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),g(B.Item,{icon:g(kt,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),g(B.Divider,{}),g(B.Item,{icon:g(Ho,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Vo,{size:14}),onClick:()=>e.onPrompt(o,se.NOT),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(Na,{size:14}),onClick:()=>e.onPrompt(o,se.CONTAINS),children:"Contains..."}),g(B.Item,{icon:g(La,{size:14}),onClick:()=>e.onPrompt(o,se.EQUALS),children:"Does not contain..."}),g($r,{...e})]})}function $r(e){let{searchParam:o}=e,t=o.code;return at(ou,{children:[g(B.Divider,{}),g(B.Item,{icon:g(wa,{size:14}),onClick:()=>e.onChange(Zn(e.search,t)),children:"Missing"}),g(B.Item,{icon:g(Fa,{size:14}),onClick:()=>e.onChange(Zn(e.search,t,!1)),children:"Not missing"}),g(B.Divider,{}),g(B.Item,{icon:g(ln,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Wv,getSearchParameter as Xv,getSearchParameterDetails as Jv,getSearchParameters as $v}from"@medplum/core";function tu(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(_v(o,r));return t}function _v(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=Wv(e,o),r=Xv(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=$v(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=Jv(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as dS,jsx as F,jsxs as Pe}from"react/jsx-runtime";var nl=class extends Event{constructor(o){super("change"),this.definition=o}},ll=class extends Event{constructor(o){super("load"),this.response=o}},Do=class extends Event{constructor(o,t){super("click"),this.resource=o,this.browserEvent=t}},nS=Zv(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 lS(e){let{classes:o}=nS(),t=S(),[r,a]=al(!1),[n,l]=al(),{search:f,onLoad:i}=e,[s,u]=al({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),c=aS(s);c.current=s;let d=f.total??"accurate",m=au(T=>{l(void 0),t.search(f.resourceType,tS({...f,total:d,fields:void 0}),T).then(G=>{u({...c.current,searchResponse:G}),i&&i(new ll(G))}).catch(G=>{u({...c.current,searchResponse:void 0}),l(G)})},[t,f,d,i]),p=au(()=>{u({...c.current,searchResponse:void 0}),m({cache:"reload"})},[m]);nu(()=>{m()},[m]);function x(T,G){T.stopPropagation();let ne=T.target.checked,ue={...c.current.selected};ne?ue[G]=!0:delete ue[G],u({...c.current,selected:ue})}function C(T){T.stopPropagation();let ee=T.target.checked,ne={},ue=c.current.searchResponse;ee&&ue?.entry&&ue.entry.forEach(ht=>{ht.resource?.id&&(ne[ht.resource.id]=!0)}),u({...c.current,selected:ne})}function y(){let T=c.current;if(!T.searchResponse?.entry||T.searchResponse.entry.length===0)return!1;for(let G of T.searchResponse.entry)if(G.resource?.id&&!T.selected[G.resource.id])return!1;return!0}function v(T){e.onChange&&e.onChange(new nl(T))}function b(T,G){if(cr(T.target)||T.button===2)return;M(T);let ee=T.button===1||T.ctrlKey||T.metaKey;!ee&&e.onClick&&e.onClick(new Do(G,T)),ee&&e.onAuxClick&&e.onAuxClick(new Do(G,T))}function P(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(nu(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return F(_r,{style:{width:"100%",height:"100%"},children:F(Yv,{})});let h=e.checkboxesEnabled,A=tu(f),W=f.resourceType,Y=s.searchResponse,ke=Y?.entry?.map(T=>T.resource),De="subtle",R="gray",N=16,ao=window.innerWidth<768;return Pe("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&Pe(Kr,{position:"apart",mb:"xl",children:[Pe(Kr,{spacing:2,children:[F(nt,{compact:!0,variant:De,color:R,leftIcon:F(qa,{size:N}),onClick:()=>u({...c.current,fieldEditorVisible:!0}),children:"Fields"}),F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Wa,{size:N}),onClick:()=>u({...c.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(za,{size:N}),onClick:e.onNew,children:"New..."}),!ao&&P()&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(an,{size:N}),onClick:e.onExport?e.onExport:()=>u({...c.current,exportDialogVisible:!0}),children:"Export..."}),!ao&&e.onDelete&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Dt,{size:N}),onClick:()=>e.onDelete(Object.keys(s.selected)),children:"Delete..."}),!ao&&e.onBulk&&F(nt,{compact:!0,variant:De,color:R,leftIcon:F(Oa,{size:N}),onClick:()=>e.onBulk(Object.keys(s.selected)),children:"Bulk..."})]}),Pe(Kr,{spacing:2,children:[Y&&Pe(rl,{size:"xs",color:"dimmed",children:[uS(f,Y.total),"-",cS(f,Y.total)," of"," ",`${d==="estimate"?"~":""}${Y.total?.toLocaleString()}`]}),F(Kv,{title:"Refresh",onClick:p,children:F(ja,{size:"1.125rem"})})]})]}),Pe(eS,{className:o.table,children:[Pe("thead",{children:[Pe("tr",{children:[h&&F("th",{children:F("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:y(),onChange:T=>C(T)})}),A.map(T=>F("th",{children:Pe(ru,{shadow:"md",width:240,position:"bottom-end",children:[F(ru.Target,{children:F(oS,{className:o.control,children:Pe(Kr,{position:"apart",noWrap:!0,children:[F(rl,{weight:500,size:"sm",children:we(T.name)}),F(_r,{className:o.icon,children:F(Ba,{size:14,stroke:1.5})})]})})}),F(eu,{search:e.search,searchParams:T.searchParams,onPrompt:(G,ee)=>{u({...c.current,filterDialogVisible:!0,filterDialogSearchParam:G,filterDialogFilter:ee})},onChange:G=>{v(G)}})]})},T.name))]}),!e.hideFilters&&Pe("tr",{children:[h&&F("th",{}),A.map(T=>F("th",{children:T.searchParams&&F(fS,{resourceType:W,searchParams:T.searchParams,filters:e.search.filters})},T.name))]})]}),F("tbody",{children:ke?.map(T=>T&&Pe("tr",{className:o.tr,"data-testid":"search-control-row",onClick:G=>b(G,T),onAuxClick:G=>b(G,T),children:[h&&F("td",{children:F("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${T.id}`,checked:!!s.selected[T.id],onChange:G=>x(G,T.id)})}),A.map(G=>F("td",{children:Qi(T,G)},G.name))]},T.id))})]}),ke?.length===0&&F(uo,{children:F(_r,{style:{height:150},children:F(rl,{size:"xl",color:"dimmed",children:"No results"})})}),Y?.total!==void 0&&Y.total>0&&F(_r,{m:"md",p:"md",children:F(jv,{value:sS(f),total:iS(f,Y.total),onChange:T=>v(Hi(f,T)),getControlProps:T=>{switch(T){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&F("div",{"data-testid":"search-error",children:F("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),F(Wi,{search:e.search,visible:c.current.fieldEditorVisible,onOk:T=>{v(T),u({...c.current,fieldEditorVisible:!1})},onCancel:()=>{u({...c.current,fieldEditorVisible:!1})}}),F(Yi,{search:e.search,visible:c.current.filterEditorVisible,onOk:T=>{v(T),u({...c.current,filterEditorVisible:!1})},onCancel:()=>{u({...c.current,filterEditorVisible:!1})}}),F(Bi,{visible:c.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...c.current,exportDialogVisible:!1})}}),F(ji,{visible:c.current.filterDialogVisible,title:s.filterDialogSearchParam?.code?we(s.filterDialogSearchParam.code):"",resourceType:W,searchParam:s.filterDialogSearchParam,filter:s.filterDialogFilter,defaultValue:"",onOk:T=>{v(ot(e.search,T.code,T.operator,T.value)),u({...c.current,filterDialogVisible:!1})},onCancel:()=>{u({...c.current,filterDialogVisible:!1})}},s.filterDialogSearchParam?.code)]})}var _N=rS(lS);function fS(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?F("span",{children:"no filters"}):F(dS,{children:o.map(t=>Pe("div",{children:[Xt(t.operator),"\xA0",F(Xr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function sS(e){return Math.floor((e.offset??0)/(e.count??fl))+1}function iS(e,o){let t=e.count??fl;return Math.ceil(o/t)}function uS(e,o){return Math.min(o,(e.offset??0)+1)}function cS(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??fl))}import{jsx as Se,jsxs as Yr}from"react/jsx-runtime";function hS(e){let o=S(),[t,r]=Zr(!1),[a,n]=Zr(),{query:l,fields:f}=e,[i,s]=Zr(),[u,c]=Zr({}),d=fu();d.current=i;let m=fu({});m.current=u,lu(()=>{n(void 0),o.graphql(l).then(s).catch(b=>n(IS(b)))},[o,l]);function p(b,P){b.stopPropagation();let A=b.target.checked,W={...m.current};A?W[P]=!0:delete W[P],c(W)}function x(b){b.stopPropagation();let h=b.target.checked,A={},W=d.current?.data.ResourceList;h&&W&&W.forEach(Y=>{Y.id&&(A[Y.id]=!0)}),c(A)}function C(){let b=d.current?.data.ResourceList;if(!b||b.length===0)return!1;for(let P of b)if(P.id&&!m.current[P.id])return!1;return!0}function y(b,P){cr(b.target)||(M(b),b.button!==1&&e.onClick&&e.onClick(new Do(P,b)),b.button===1&&e.onAuxClick&&e.onAuxClick(new Do(P,b)))}if(lu(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return Se(pS,{});let v=e.checkboxesEnabled;return Yr("div",{onContextMenu:b=>M(b),"data-testid":"search-control",children:[Yr(xS,{children:[Se("thead",{children:Yr("tr",{children:[v&&Se("th",{children:Se("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:C(),onChange:b=>x(b)})}),f.map(b=>Se("th",{children:b.name},b.name))]})}),Se("tbody",{children:i?.data.ResourceList.map(b=>b&&Yr("tr",{"data-testid":"search-control-row",onClick:P=>y(P,b),onAuxClick:P=>y(P,b),children:[v&&Se("td",{children:Se("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${b.id}`,checked:!!u[b.id],onChange:P=>p(P,b.id)})}),f.map(P=>Se("td",{children:Se(Ti,{propertyType:P.propertyType,path:P.fhirPath,resource:b})},P.name))]},b.id))})]}),i?.data.ResourceList.length===0&&Se("div",{"data-testid":"empty-search",children:"No results"}),a&&Se("div",{"data-testid":"search-error",children:Se("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&Se(mS,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var fV=gS(hS);import{jsx as lt,jsxs as yS}from"react/jsx-runtime";function xo(e){return yS("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[lt("title",{children:"Medplum Logo"}),lt("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),lt("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"}),lt("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"}),lt("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),lt("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as PS,SimpleGrid as TS}from"@mantine/core";import{Box as su,Flex as sl,Group as vS,Paper as SS,RingProgress as uu,Text as Bo,Title as il}from"@mantine/core";import{formatCodeableConcept as iu}from"@medplum/core";import{Fragment as pu,jsx as re,jsxs as _t}from"react/jsx-runtime";function cu(e){let{group:o}=e;return re(SS,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:_t(vS,{children:[o.measureScore&&re(bS,{group:o}),!o.measureScore&&re(CS,{group:o})]})})}function du(e){let{measure:o}=e;return _t(pu,{children:[re(Bo,{fz:"md",fw:500,mb:8,children:o.title}),re(Bo,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function CS(e){let{group:o}=e,t=o.population,r=t?.find(i=>iu(i.code)==="numerator"),a=t?.find(i=>iu(i.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return _t(su,{children:[re(il,{order:3,children:"Not Applicable"}),re(Bo,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return _t(su,{children:[re(il,{order:3,children:"Insufficient Data"}),re(Bo,{children:`Numerator: ${n}`}),re(Bo,{children:`Denominator: ${l}`})]});let f=n/l*100;return re(uu,{size:120,thickness:12,roundCaps:!0,sections:[{value:f,color:mu(f)}],label:re(sl,{justify:"center",children:_t(Bo,{fw:700,fz:18,children:[n," / ",l]})})})}function bS(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return re(pu,{children:t==="%"?re(uu,{size:120,thickness:12,roundCaps:!0,sections:[{value:RS(o),color:mu(o?.measureScore?.value??0)}],label:re(sl,{justify:"center",children:re(Bo,{fw:700,fz:18,children:re(ae,{value:o.measureScore})})})}):re(sl,{h:120,align:"center",children:re(il,{order:3,children:re(ae,{value:o.measureScore})})})})}function RS(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function mu(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as ul,jsxs as kS}from"react/jsx-runtime";function vV(e){let o=X(e.measureReport),[t]=Kl("Measure",{url:o?.measure});return o?kS(PS,{children:[t&&ul(du,{measure:t}),ul(TS,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>ul(cu,{group:r},r.id??a))})]}):null}import{Alert as DS}from"@mantine/core";import{operationOutcomeIssueToString as BS}from"@medplum/core";import{jsx as cl}from"react/jsx-runtime";function ft(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:cl(DS,{icon:cl(vo,{size:16}),color:"red",children:o.map(t=>cl("div",{"data-testid":"text-field-error",children:BS(t)},t.details?.text))})}import{Anchor as Xu,Card as Ju,Divider as Kt,Flex as gl,Group as MC,Paper as FC,Stack as wC,Text as Zt}from"@mantine/core";import{calculateAgeString as OC,formatHumanName as EC,resolveId as LC}from"@medplum/core";import{useEffect as NC,useState as st}from"react";import{Anchor as AS,Badge as MS,Box as FS,Button as wS,Group as xu,Modal as OS,NativeSelect as ES,Stack as LS,Text as Iu,TextInput as gu}from"@mantine/core";import{useDisclosure as NS}from"@mantine/hooks";import{createReference as hu}from"@medplum/core";import{useCallback as VS,useState as yu}from"react";import{Fragment as HS,jsx as Ce,jsxs as dl}from"react/jsx-runtime";function vu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=yu(e.allergies),[l,{open:f,close:i}]=NS(!1),[s,u]=yu(),c=VS(d=>{o.createResource({resourceType:"AllergyIntolerance",patient:hu(t),encounter:r?hu(r):void 0,code:s,onsetDateTime:d.onset?d.onset:void 0,reaction:d.reaction?[{manifestation:[{text:d.reaction}]}]:void 0}).then(m=>{n([...a,m]),i()}).catch(console.error)},[o,t,r,a,i,s]);return dl(HS,{children:[dl(xu,{position:"apart",children:[Ce(Iu,{fz:"md",fw:700,children:"Allergies"}),Ce(AS,{href:"#",onClick:d=>{M(d),f()},children:"+ Add"})]}),a.length>0?Ce(FS,{children:a.map(d=>Ce(MS,{maw:"100%",children:Ce(ye,{value:d.code})},d.id))}):Ce(Iu,{children:"(none)"}),Ce(OS,{opened:l,onClose:i,title:"Add Allergy",children:Ce(H,{onSubmit:c,children:dl(LS,{children:[Ce(_o,{name:"allergy","data-autofocus":!0,binding:"http://hl7.org/fhir/us/core/ValueSet/us-core-allergy-substance",onChange:d=>u(d)}),Ce(gu,{name:"reaction",label:"Reaction"}),Ce(ES,{name:"status",label:"Status",data:["active"]}),Ce(gu,{name:"onset",label:"Onset",type:"date"}),Ce(xu,{position:"right",spacing:4,mt:"md",children:Ce(wS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as qS,Badge as GS,Box as US,Button as QS,Group as Su,Modal as zS,Radio as ml,Stack as WS,Text as Cu}from"@mantine/core";import{useDisclosure as XS}from"@mantine/hooks";import{createReference as bu}from"@medplum/core";import{useCallback as JS,useState as Ru}from"react";import{Fragment as $S,jsx as Te,jsxs as jr}from"react/jsx-runtime";function Pu(e){let o=S(),[t,r]=Ru(e.medicationRequests),[a,{open:n,close:l}]=XS(!1),[f,i]=Ru(),s=JS(u=>{let c=u.status;o.createResource({resourceType:"MedicationRequest",status:c,intent:"order",encounter:e.encounter?bu(e.encounter):void 0,medicationCodeableConcept:f,subject:bu(e.patient)}).then(d=>{r([d,...t]),l()}).catch(console.error)},[o,e.patient,e.encounter,t,l,f]);return jr($S,{children:[jr(Su,{position:"apart",children:[Te(Cu,{fz:"md",fw:700,children:"Medications"}),Te(qS,{href:"#",onClick:u=>{M(u),n()},children:"+ Add"})]}),t.length>0?Te(US,{children:t.map(u=>Te(GS,{mt:4,maw:"50%",color:u.status==="active"?"blue":"gray",children:Te(ye,{value:u.medicationCodeableConcept})},u.id))}):Te(Cu,{children:"(none)"}),Te(zS,{opened:a,onClose:l,title:"Add Medication Request",children:Te(H,{onSubmit:s,children:jr(WS,{h:275,children:[Te(_o,{name:"request","data-autofocus":!0,binding:"https://app.medplum.com/ValueSet/16d6f7b7-7eeb-4d0e-a83b-83be082aa10b",onChange:u=>i(u)}),jr(ml.Group,{mt:32,name:"status",label:"Request Status",required:!0,children:[Te(ml,{value:"active",label:"active",my:"xs"},"active"),Te(ml,{value:"stopped",label:"stopped",my:"xs"},"stopped")]}),Te(Su,{position:"right",spacing:4,mt:"md",children:Te(QS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as _S,Badge as KS,Button as ZS,Grid as pl,Group as Tu,Modal as YS,NativeSelect as jS,Stack as eC,Text as ku,Textarea as oC,TextInput as Du}from"@mantine/core";import{useDisclosure as tC}from"@mantine/hooks";import{createReference as Bu}from"@medplum/core";import{Fragment as rC,useCallback as aC,useState as nC}from"react";import{Fragment as lC,jsx as me,jsxs as ea}from"react/jsx-runtime";function Au(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=nC(e.problems),[l,{open:f,close:i}]=tC(!1),s=aC(u=>{o.createResource({resourceType:"Condition",subject:Bu(t),encounter:r?Bu(r):void 0,code:{coding:[{code:u.problem,display:u.problem}]},onsetDateTime:u.onset?u.onset:void 0}).then(c=>{n([...a,c]),i()}).catch(console.error)},[o,t,r,a,i]);return ea(lC,{children:[ea(Tu,{position:"apart",children:[me(ku,{fz:"md",fw:700,children:"Problem List"}),me(_S,{href:"#",onClick:u=>{M(u),f()},children:"+ Add"})]}),a.length>0?me(pl,{gutter:"xs",children:a.map(u=>ea(rC,{children:[me(pl.Col,{span:2,children:u.onsetDateTime?.substring(0,4)}),me(pl.Col,{span:10,children:me(KS,{maw:"100%",children:me(ye,{value:u.code})},u.id)})]},u.id))}):me(ku,{children:"(none)"}),me(YS,{opened:l,onClose:i,title:"Add Problem",children:me(H,{onSubmit:s,children:ea(eC,{children:[me(Du,{name:"problem",label:"Problem","data-autofocus":!0,autoFocus:!0,required:!0}),me(Du,{name:"onset",label:"Dx Date",type:"date",required:!0}),me(jS,{name:"status",label:"Status",data:["active"]}),me(oC,{name:"notes",label:"Notes"}),me(Tu,{position:"right",spacing:4,mt:"md",children:me(ZS,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as fC,Badge as sC,Box as iC,Button as uC,Group as Mu,Modal as cC,Radio as Fu,Stack as dC,Text as wu}from"@mantine/core";import{useDisclosure as mC}from"@mantine/hooks";import{HTTP_HL7_ORG as pC,LOINC as xC,SNOMED as Ou,createReference as Eu}from"@medplum/core";import{useCallback as IC,useState as gC}from"react";import{Fragment as hC,jsx as Oe,jsxs as xl}from"react/jsx-runtime";var Lu={266919005:"Never smoked tobacco",266927001:"Tobacco smoking consumption unknown","428041000124106":"Occasional tobacco smoker","428061000124105":"Light tobacco smoker","428071000124103":"Heavy tobacco smoker",449868002:"Smokes tobacco daily",77176002:"Smoker",8517006:"Ex-smoker"};function Nu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=gC(e.smokingStatus),[l,{open:f,close:i}]=mC(!1),s=IC(u=>{o.createResource({resourceType:"Observation",meta:{profile:[pC+"/fhir/us/core/StructureDefinition/us-core-smokingstatus"]},status:"final",category:[{coding:[{system:"http://terminology.hl7.org/CodeSystem/observation-category",code:"social-history",display:"Social History"}],text:"Social History"}],code:{coding:[{system:xC,code:"72166-2",display:"Tobacco smoking status"}],text:"Tobacco smoking status"},subject:Eu(t),encounter:r?Eu(r):void 0,effectiveDateTime:new Date().toISOString(),valueCodeableConcept:{coding:[{system:Ou,version:Ou+"/731000124108",code:u.smokingStatus}],text:Lu[u.smokingStatus]}}).then(c=>{n(c),i()}).catch(console.error)},[o,t,r,i]);return xl(hC,{children:[xl(Mu,{position:"apart",children:[Oe(wu,{fz:"md",fw:700,children:"Smoking Status"}),Oe(fC,{href:"#",onClick:u=>{M(u),f()},children:"+ Edit"})]}),a?.valueCodeableConcept?Oe(iC,{children:Oe(sC,{children:Oe(ye,{value:a.valueCodeableConcept})})}):Oe(wu,{children:"(none)"}),Oe(cC,{opened:l,onClose:i,title:"Set Smoking Status",children:Oe(H,{onSubmit:s,children:xl(dC,{children:[Oe(Fu.Group,{name:"smokingStatus",label:"Smoking Status",required:!0,children:Object.entries(Lu).map(([u,c])=>Oe(Fu,{value:u,label:c,my:"xs"},u))}),Oe(Mu,{position:"right",spacing:4,mt:"md",children:Oe(uC,{type:"submit",children:"Save"})})]})})})]})}import{Anchor as SC,Button as CC,Grid as te,Group as Ao,Modal as bC,Stack as RC,Text as PC,Textarea as TC,TextInput as We}from"@mantine/core";import{useDisclosure as kC}from"@mantine/hooks";import{useCallback as DC,useState as BC}from"react";import{LOINC as yC,UCUM as vC,createReference as Vu}from"@medplum/core";function oo(e,o){return e.find(r=>r.code?.coding?.[0].code===o)?.valueQuantity}function Il(e,o,t){return e.find(n=>n.code?.coding?.[0].code===o)?.component?.find(n=>n.code?.coding?.[0].code===t)?.valueQuantity}function Hu(e,o,t,r,a){if(Uu(a.value))return{...Gu(e,o,t,r),valueQuantity:a}}function qu(e,o,t,r,a){let n=a.filter(l=>Uu(l.valueQuantity?.value));if(n.length!==0)return{...Gu(e,o,t,r),component:n}}function Gu(e,o,t,r){return{resourceType:"Observation",status:"preliminary",subject:Vu(e),encounter:o?Vu(o):void 0,effectiveDateTime:new Date().toISOString(),category:[{coding:[{system:"http://terminology.hl7.org/CodeSystem/observation-category",code:"vital-signs",display:"Vital Signs"}]}],code:oa(t,r)}}function oa(e,o){return{coding:[{code:e,display:o,system:yC}],text:o}}function ta(e,o){return{value:e,system:vC,unit:o,code:o}}function Uu(e){return e!==void 0&&!isNaN(e)&&isFinite(e)}import{Fragment as AC,jsx as w,jsxs as Xe}from"react/jsx-runtime";var He={bloodPressure:{code:"85354-9",title:"Blood Pressure",unit:"mm[Hg]"},heartRate:{code:"8867-4",title:"Heart Rate",unit:"/min"},bodyTemperature:{code:"8310-5",title:"Body Temperature",unit:"Cel"},respiratoryRate:{code:"9279-1",title:"Respiratory Rate",unit:"/min"},height:{code:"8302-2",title:"height",unit:"cm"},weight:{code:"29463-7",title:"weight",unit:"kg"},bmi:{code:"39156-5",title:"BMI",unit:"kg/m2"},oxygen:{code:"2708-6",title:"Oxygen",unit:"%"},headCircumference:{code:"9843-4",title:"Head Circumference",unit:"cm"}},Qu="8480-6",zu="8462-4";function Wu(e){let o=S(),{patient:t,encounter:r}=e,[a,n]=BC(e.vitals),[l,{open:f,close:i}]=kC(!1),s=DC(u=>{let c=Object.entries(He).map(([d,m])=>d==="bloodPressure"?qu(t,r,m.code,m.title,[{code:oa(Qu,"Systolic blood pressure"),valueQuantity:ta(parseFloat(u.systolic),"mm[Hg]")},{code:oa(zu,"Diastolic blood pressure"),valueQuantity:ta(parseFloat(u.diastolic),"mm[Hg]")}]):Hu(t,r,m.code,m.title,ta(parseFloat(u[d]),m.unit))).filter(Boolean);Promise.all(c.map(d=>o.createResource(d))).then(d=>n([...d,...a])).catch(console.error),i()},[o,t,r,a,i]);return Xe(AC,{children:[Xe(Ao,{position:"apart",children:[w(PC,{fz:"md",fw:700,children:"Vitals"}),w(SC,{href:"#",onClick:u=>{M(u),f()},children:"+ Add"})]}),Xe(te,{children:[w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BP Sys"}),w(te.Col,{span:3,children:w(ae,{value:Il(a,He.bloodPressure.code,Qu)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BP Dias"}),w(te.Col,{span:3,children:w(ae,{value:Il(a,He.bloodPressure.code,zu)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"HR"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.heartRate.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Temp"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.bodyTemperature.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"RR"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.respiratoryRate.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Height"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.height.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"Weight"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.weight.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"BMI"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.bmi.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"O2"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.oxygen.code)})}),w(te.Col,{span:3,ta:"right",c:"dimmed",children:"HC"}),w(te.Col,{span:3,children:w(ae,{value:oo(a,He.headCircumference.code)})})]}),w(bC,{opened:l,onClose:i,title:"Add Vitals",children:Xe(H,{onSubmit:s,children:[Xe(RC,{children:[Xe(Ao,{grow:!0,children:[w(We,{name:"systolic",label:"BP Sys","data-autofocus":!0,autoFocus:!0}),w(We,{name:"diastolic",label:"BP Dias"})]}),Xe(Ao,{grow:!0,children:[w(We,{name:"heartRate",label:"HR"}),w(We,{name:"bodyTemperature",label:"Temp"})]}),Xe(Ao,{grow:!0,children:[w(We,{name:"respiratoryRate",label:"RR"}),w(We,{name:"height",label:"height"})]}),Xe(Ao,{grow:!0,children:[w(We,{name:"weight",label:"Wt"}),w(We,{name:"bmi",label:"BMI"})]}),Xe(Ao,{grow:!0,children:[w(We,{name:"oxygen",label:"O2"}),w(We,{name:"headCircumference",label:"HC"})]}),w(TC,{name:"notes",label:"Notes"})]}),w(Ao,{position:"right",spacing:4,mt:"md",children:w(CC,{type:"submit",children:"Save"})})]})})]})}import{jsx as j,jsxs as Mo}from"react/jsx-runtime";function qH(e){let o=S(),{patient:t,background:r,...a}=e,[n,l]=st(),[f,i]=st(),[s,u]=st(),[c,d]=st(),[m,p]=st(),[x,C]=st();return NC(()=>{let y=LC(t),v=`Patient/${y}`,b={_count:100,_sort:"-_lastUpdated"};Promise.all([o.readResource("Patient",y),o.searchResources("AllergyIntolerance",{patient:v,...b}),o.searchResources("Condition",{patient:v,...b}),o.searchResources("MedicationRequest",{subject:v,...b}),o.searchResources("Observation",{subject:v,...b})]).then(P=>{l(P[0]),i(P[1]),u(P[2]),C(P[3]);let h=P[4];d(h.find(A=>A.code?.coding?.[0].code==="72166-2")),p(h.filter(A=>A.category?.[0]?.coding?.[0].code==="vital-signs"))}).catch(console.error)},[o,t]),n?Mo(Ju,{...a,children:[j(Ju.Section,{h:100,style:{background:r}}),j(fe,{value:n,size:80,radius:80,mx:"auto",mt:-50,sx:{border:"2px solid white"}}),j(Zt,{ta:"center",fz:"lg",fw:500,children:EC(n.name?.[0])}),Mo(Zt,{ta:"center",fz:"xs",color:"dimmed",children:[n.birthDate," (",OC(n.birthDate),")"]}),j(FC,{withBorder:!0,p:"md",my:"md",children:Mo(MC,{grow:!0,children:[Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,maw:"33%",children:[j(nn,{size:24,color:"gray"}),j(Zt,{fz:"xs",align:"center",sx:{whiteSpace:"nowrap"},children:"Self"})]}),Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,children:[j(tn,{size:24,color:"gray"}),j(Zt,{fz:"xs",sx:{whiteSpace:"nowrap"},children:n?.generalPractitioner?.[0]?.display??"No provider"})]}),Mo(gl,{justify:"center",align:"center",direction:"column",gap:0,children:[j(Xa,{size:24,color:"gray"}),j(Zt,{fz:"xs",sx:{whiteSpace:"nowrap"},children:n.gender})]})]})}),Mo(wC,{spacing:"xs",children:[j(Xu,{href:"#",children:"No upcoming appointments"}),j(Xu,{href:"#",children:"No documented visits"}),j(Kt,{}),j(vu,{patient:n,allergies:f}),j(Kt,{}),j(Au,{patient:n,problems:s}),j(Kt,{}),j(Pu,{patient:n,medicationRequests:x}),j(Kt,{}),j(Nu,{patient:n,smokingStatus:c}),j(Kt,{}),j(Wu,{patient:n,vitals:m})]})]}):null}import{createReference as ra}from"@medplum/core";import{useCallback as VC}from"react";import{jsx as HC}from"react/jsx-runtime";function $H(e){let o=VC((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 HC(po,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:ra(t),sender:ra(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:ra(t),operator:ra(r),issued:new Date().toISOString(),content:a})})}import{Anchor as _u,Button as qC,createStyles as GC,NativeSelect as UC,Stack as QC,TextInput as yl}from"@mantine/core";import{getReferenceString as zC}from"@medplum/core";import{useEffect as $u,useRef as Ku,useState as Yt}from"react";import{jsx as J,jsxs as it}from"react/jsx-runtime";var Zu=GC(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 mq(e){let o=S(),t=X(e.value),[r,a]=Yt(!1),[n,l]=Yt(),[f,i]=Yt(),[s,u]=Yt();function c(){i(void 0)}function d(){l(void 0)}let m=Ku();if(m.current=s,$u(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),$u(()=>(u(KC(t??{resourceType:"PlanDefinition"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]),!r||!s)return null;function p(x,C){u({...m.current,[x]:C})}return J("div",{children:it(H,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(s),children:[J(yl,{label:"Plan Title",defaultValue:s.title,onChange:x=>p("title",x.currentTarget.value)}),J(Yu,{actions:s.action||[],selectedKey:n,setSelectedKey:l,hoverKey:f,setHoverKey:i,onChange:x=>p("action",x)}),J(qC,{type:"submit",children:"Save"})]})})}function Yu(e){let{classes:o}=Zu(),t=Ku();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 it("div",{className:o.section,children:[e.actions.map(l=>J("div",{children:J(WC,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),J("div",{className:o.bottomActions,children:J(_u,{href:"#",onClick:l=>{M(l),a({id:ec()})},children:"Add action"})})]})}function WC(e){let{classes:o,cx:t}=Zu(),{action:r}=e,a=_C(r),n=e.selectedKey===e.action.id,l=e.hoverKey===e.action.id;function f(u){u.stopPropagation(),e.setSelectedKey(e.action.id)}function i(u){M(u),e.setHoverKey(e.action.id)}let s=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return it("div",{"data-testid":r.id,className:s,onClick:f,onMouseOver:i,onFocus:i,children:[n?J(JC,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):J(XC,{action:r,actionType:a}),J("div",{className:o.bottomActions,children:J(_u,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var vl={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function XC(e){let{action:o,actionType:t}=e,[r,a]=ju(o);return it("div",{children:[it("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&J("div",{children:J(To,{value:{reference:o.definitionCanonical}})}),r&&J("div",{children:J(ce,{property:vl,propertyType:a,value:r})})]})}function JC(e){let{action:o}=e,[t,r]=Yt(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return it(QC,{spacing:"xl",children:[J(yl,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),J(yl,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),J(UC,{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&&J(Yu,{actions:o.action,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:n=>a("action",n)}),(()=>{switch(t){case"appointment":return J(aa,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return J(aa,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return J(aa,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return J(aa,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),J(pe,{title:"Timing",description:"When the action should take place.",children:J($C,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function aa(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return J(kr,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:zC(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function $C(e){let o=e.action,t="timing",[r,a]=ju(o);return J(io,{property:vl,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(Ot(o,t,l??t,vl,n))},outcome:void 0})}function _C(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function ju(e){return so({type:"PlanDefinitionAction",value:e},"timing")}var hl=1;function ec(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(hl=Math.max(hl,o+1))}return e}return"id-"+hl++}function KC(e){return{...e,action:oc(e.action)}}function oc(e){if(e)return e.map(o=>({...o,id:ec(o.id),action:oc(o.action)}))}import{Anchor as Ee,Box as Pl,Button as Pb,createStyles as Tb,Group as kb,NativeSelect as Db,Space as Bb,Textarea as Ab,TextInput as Tl,Title as Mb}from"@mantine/core";import{getElementDefinition as Fb,isResource as wb}from"@medplum/core";import{useEffect as gc,useRef as Ob,useState as ca}from"react";import{Checkbox as ib,Group as ub,MultiSelect as cb,NativeSelect as db,Radio as cc,Textarea as mb,TextInput as ut}from"@mantine/core";import{capitalize as bl,deepEquals as pb,formatCodeableConcept as xb,formatCoding as ua,getElementDefinition as Ib,getTypedPropertyValue as Io,stringify as dc}from"@medplum/core";import{useContext as gb}from"react";import{deepClone as ZC,evalFhirPathTyped as YC,formatCoding as jC,getExtension as na,getReferenceString as eb,getTypedPropertyValue as Sl,splitN as ob,stringify as tb}from"@medplum/core";var la=(y=>(y.group="group",y.display="display",y.question="question",y.boolean="boolean",y.decimal="decimal",y.integer="integer",y.date="date",y.dateTime="dateTime",y.time="time",y.string="string",y.text="text",y.url="url",y.choice="choice",y.openChoice="open-choice",y.attachment="attachment",y.reference="reference",y.quantity="quantity",y))(la||{});function tc(e){return e.type==="choice"||e.type==="open-choice"}function rc(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=nc(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=ab(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function ac(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>jC(l.valueCoding)===r||l[o]===r),n=Sl({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function nc(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=nc(t.item,o);if(r)return r}}}function rb(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=YC(`%actualAnswer ${r} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":o});return a}else return!1}function ab(e,o,t){let r=o||[],a=Sl({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let f of r){let i=Sl({type:"QuestionnaireResponseItemAnswer",value:f},"value[x]"),{operator:s}=e;if(rb(i,a,s)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function fa(e){let o=na(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 sa(e,o){let t=ZC(e),r=na(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 lc(e,o,t){let r=na(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[i,s]=ob(f,"=",2);n[i]=s}return n}function fc(e){return{resourceType:"QuestionnaireResponse",questionnaire:eb(e),item:sc(e.item)}}function sc(e){return e?.map(Cl)??[]}function Cl(e){return{id:lb(),linkId:e.linkId,text:e.text,item:sc(e.item),answer:e.initial?.map(fb)??[]}}var nb=1;function lb(){return"id-"+nb++}function fb(e){return{...e}}function ic(e){return e.value.display||e.value.reference||tb(e.value)}function uc(e){let o=e?.item?.[0];return o&&na(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as sb}from"react";var ia=sb({});import{jsx as $}from"react/jsx-runtime";function jt(e){let o=gb(ia),t=e.item,r=e.response;function a(s){let u;Array.isArray(s)?u=s:e.index>=(e.response?.answer?.length??0)?u=(e.response?.answer??[]).concat([s]):u=(e.response?.answer??[]).map((d,m)=>m===e.index?s: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,i=Rl(r,e.index)??Io({type:"QuestionnaireItemInitial",value:f},"value");switch(n){case"display":return $("p",{children:e.item.text},e.item.linkId);case"boolean":return $(Cr,{title:e.item.text,htmlFor:e.item.linkId,children:$(ib,{id:e.item.linkId,name:e.item.linkId,defaultChecked:i?.value,onChange:s=>a({valueBoolean:s.currentTarget.checked})})},e.item.linkId);case"decimal":return $(ut,{type:"number",step:"any",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDecimal:s.currentTarget.valueAsNumber})});case"integer":return $(ut,{type:"number",step:1,id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueInteger:s.currentTarget.valueAsNumber})});case"date":return $(ut,{type:"date",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDate:s.currentTarget.value})});case"dateTime":return $(Ve,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDateTime:s})});case"time":return $(ut,{type:"time",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueTime:s.currentTarget.value})});case"string":case"url":return $(ut,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"text":return $(mb,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"attachment":return $(ub,{py:4,children:$(xr,{name:l,defaultValue:i?.value,onChange:s=>a({valueAttachment:s})})});case"reference":return $(Zo,{name:l,required:t.required,targetTypes:fa(t),searchCriteria:lc(t,o.subject,o.encounter),defaultValue:i?.value,onChange:s=>a({valueReference:s})});case"quantity":return $(Ae,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueQuantity:s}),disableWheel:!0});case"choice":case"open-choice":return bb(t)&&!t.answerValueSet?$(hb,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)}):$(yb,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)});default:return null}}function hb(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return $(xc,{});let n=Io({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let i of t.answerOption){let s=Io({type:"QuestionnaireItemAnswerOption",value:i},"value");l.push(mc(s))}let f=Rl(a)??n;if(t.repeats){let{propertyName:i,data:s}=Rb(e.item),u=Sb(a);return $(cb,{data:s,placeholder:"Select items",searchable:!0,defaultValue:u||[mc(n)],onChange:c=>{let d=ac(c,i,t);e.onChangeAnswer(d)}})}return $(db,{id:o,name:o,onChange:i=>{let s=i.currentTarget.selectedIndex;if(s===0){e.onChangeAnswer({});return}let u=t.answerOption[s-1],c=Io({type:"QuestionnaireItemAnswerOption",value:u},"value"),d="value"+bl(c.type);e.onChangeAnswer({[d]:c.value})},defaultValue:ua(f?.value)||f?.value,data:l})}function yb(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?$(xc,{}):t.answerValueSet?$(Rr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):$(vb,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function vb(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Ib("QuestionnaireItemAnswerOption","value[x]"),f=Io({type:"QuestionnaireItemInitial",value:r},"value"),i=[],s;if(t.answerOption)for(let d=0;d<t.answerOption.length;d++){let m=t.answerOption[d],p=`${o}-option-${d}`,x=Io({type:"QuestionnaireItemAnswerOption",value:m},"value");x?.value&&(f&&dc(x)===dc(f)&&(s=p),i.push([p,x]))}let u=Rl(n),c=Cb(i,u);return $(cc.Group,{name:o,value:c??s,onChange:d=>{let m=i.find(p=>p[0]===d);if(m){let p=m[1],x="value"+bl(p.type);a({[x]:p.value})}},children:i.map(([d,m])=>$(cc,{id:d,value:d,py:4,label:$(ce,{property:l,propertyType:m.type,value:m.value})},d))})}function xc(){return $(ut,{disabled:!0,placeholder:"No Answers Defined"})}function Ic(e){return Io({type:"QuestionnaireItemAnswer",value:e},"value")}function Rl(e,o=0){let t=e.answer;return Ic(t?.[o]??{})}function Sb(e){let o=e.answer;return o?o.map(r=>Ic(r)).map(r=>ua(r?.value)||r?.value):[]}function Cb(e,o){return e.find(t=>pb(t[1].value,o?.value))?.[0]}function mc(e){if(e)return e.type==="CodeableConcept"?xb(e.value):e.type==="Coding"?ua(e.value):e.type==="Reference"?ic(e):e.value.toString()}function bb(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Rb(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=Io({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+bl(t.type),a=(e.answerOption??[]).map(n=>({value:pc(n,r),label:pc(n,r)}));return{propertyName:r,data:a}}function pc(e,o){return ua(e.valueCoding)||e[o]?.toString()}import{Fragment as ct,jsx as L,jsxs as be}from"react/jsx-runtime";var Eb=Tb(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 Zq(e){let o=S(),t=X(e.questionnaire),[r,a]=ca(!1),[n,l]=ca(),[f,i]=ca(),[s,u]=ca();function c(){u(void 0)}function d(){i(void 0)}gc(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),gc(()=>(l(Hb(t??{resourceType:"Questionnaire"})),document.addEventListener("mouseover",c),document.addEventListener("click",d),()=>{document.removeEventListener("mouseover",c),document.removeEventListener("click",d)}),[t]);let m=(p,x)=>{l(p),e.autoSave&&!x&&e.onSubmit&&e.onSubmit(p)};return!r||!n?null:L("div",{children:be(H,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[L(hc,{item:n,selectedKey:f,setSelectedKey:i,hoverKey:s,setHoverKey:u,onChange:m}),L(Pb,{type:"submit",children:"Save"})]})})}function hc(e){let{classes:o,cx:t}=Eb(),r=e.item,a=e.item,n=wb(e.item),l=n||a.type==="group",f=a.linkId??"[untitled]",i=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,u=Ob();u.current=e.item;function c(h){M(h),e.setSelectedKey(e.item.id)}function d(h){M(h),e.setHoverKey(e.item.id)}function m(h){let A=u.current;e.onChange({...A,item:A.item?.map(W=>W.id===h.id?h:W)})}function p(h,A){e.onChange({...e.item,item:[...e.item.item??[],h]},A)}function x(h){e.onChange({...e.item,item:e.item.item?.filter(A=>A!==h)})}function C(h,A){e.onChange({...u.current,[h]:A})}function y(h){e.onChange({...e.item,...h})}function v(h){e.onChange({...e.item,item:e.item.item?.map(A=>A===h?{...A,repeats:!A.repeats}:A)})}function b(h,A){let W=Ub(e.item.item,h,A);e.onChange({...e.item,item:W})}let P=t(o.section,{[o.editing]:i,[o.hovering]:s&&!i});return be("div",{"data-testid":a.linkId,className:P,onClick:c,onMouseOver:d,onFocus:d,children:[L("div",{className:o.questionBody,children:i?be(ct,{children:[n&&L(Tl,{size:"xl",defaultValue:r.title,onBlur:h=>C("title",h.currentTarget.value)}),!n&&L(Ab,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:h=>C("text",h.currentTarget.value)}),a.type==="reference"&&L(Vb,{item:a,onChange:y}),tc(a)&&L(Lb,{item:a,onChange:h=>y(h)})]}):be(ct,{children:[r.title&&L(Mb,{children:r.title}),a.text&&L("div",{children:a.text}),!l&&L(jt,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((h,A)=>L("div",{children:L(hc,{item:h,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:A===0,isLast:A===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>x(h),onRepeatable:v,onMoveUp:()=>b(A,-1),onMoveDown:()=>b(A,1)})},h.id)),!l&&L("div",{className:o.topActions,children:i?be(ct,{children:[L(Tl,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:h=>C("linkId",h.currentTarget.value)}),!l&&L(Db,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:h=>C("type",h.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"}]})]}):L("div",{children:f})}),!n&&L(Pl,{className:o.movementActions,children:be(Pl,{className:o.columnAlignment,children:[!e.isFirst&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:L(Ma,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:L(Aa,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),be("div",{className:o.bottomActions,children:[l&&be(ct,{children:[L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p({id:Fo(),linkId:Bl("q"),type:"string",text:"Question"})},children:"Add item"}),L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p({id:Fo(),linkId:Bl("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&L(Ee,{href:"#",onClick:h=>{h.preventDefault(),p(Gb(),!0)},children:"Add Page"}),i&&!n&&be(ct,{children:[L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),L(Ee,{href:"#",onClick:h=>{h.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function Lb(e){let o=Fb("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return be("div",{children:[e.item.answerValueSet!==void 0?L(Tl,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):L(Nb,{options:t,property:o,item:e.item,onChange:e.onChange}),be(Pl,{display:"flex",children:[L(Ee,{href:"#",onClick:r=>{M(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:Fo()}]})},children:"Add choice"}),L(Bb,{w:"lg"}),L(Ee,{href:"#",onClick:r=>{M(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function Nb(e){return L("div",{children:e.options.map(o=>{let[t,r]=so({type:"QuestionnaireItemAnswerOption",value:o},"value");return be("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[L("div",{children:L(io,{name:"value[x]",property:e.property,defaultPropertyType:r,defaultValue:t,onChange:(a,n)=>{let l=[...e.options],f=l.findIndex(i=>i.id===o.id);l[f]={id:o.id,[n]:a},e.onChange({...e.item,answerOption:l})},outcome:void 0},o.id)}),L("div",{children:L(Ee,{href:"#",onClick:a=>{M(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function Vb(e){let o=fa(e.item)??[];return be(ct,{children:[o.map((t,r)=>be(kb,{children:[L(Xo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(sa(e.item,o.map(n=>n===t?a:n)))}}),L(Ee,{href:"#",onClick:a=>{M(a),e.onChange(sa(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),L(Ee,{href:"#",onClick:t=>{M(t),e.onChange(sa(e.item,[...o,""]))},children:"Add Resource Type"})]})}var kl=1,Dl=1;function Bl(e){return e+kl++}function Fo(){return"id-"+Dl++}function Hb(e){return{...e,id:e.id||Fo(),item:yc(e.item)}}function yc(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Dl=Math.max(Dl,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(kl=Math.max(kl,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||Fo(),item:yc(o.item),answerOption:qb(o.answerOption)}))}function qb(e){if(e)return e.map(o=>({...o,id:o.id||Fo()}))}function Gb(){return{id:Fo(),linkId:Bl("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 Ub(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 tR}from"@mantine/core";import{createReference as rR,getReferenceString as aR}from"@medplum/core";import{useEffect as Pc,useState as Fl}from"react";import{Button as Ml,Group as Yb,Stack as jb,Stepper as Cc}from"@mantine/core";import{Anchor as Qb}from"@mantine/core";import{useState as zb}from"react";import{jsx as da,jsxs as Xb}from"react/jsx-runtime";function ma(e){let{item:o,response:t,onChange:r}=e,[a,n]=zb(Wb(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return da("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?da(jt,{item:o,response:t,onChange:f=>r([f]),index:0},o.linkId):Xb(pe,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((f,i)=>da(jt,{item:o,response:t,onChange:s=>r([s]),index:i},`${o.linkId}-${i}`)),l&&da(Qb,{onClick:()=>n(f=>f+1),children:"Add Item"})]},e.item.linkId)}function Wb(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 Jb,Stack as $b,Title as _b}from"@mantine/core";import{useState as Kb}from"react";import{Fragment as Zb,jsx as wo,jsxs as Sc}from"react/jsx-runtime";function Al(e){let[o,t]=Kb(e.response);if(o.length===0)return null;function r(n,l){let f=o.map((i,s)=>s===l?n[0]:i);t(f),e.onChange(f)}function a(){let n=Cl(e.item);t([...o,n])}return Sc(Zb,{children:[o.map((n,l)=>wo(vc,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:f=>r(f,l)},n.id)),e.item.repeats&&wo(Jb,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function vc(e){let{response:o,checkForQuestionEnabled:t,onChange:r}=e;function a(n){let f=o.item?.map(s=>n.find(c=>c.id===s.id)??s)?.concat(n.slice(1)),i={...o,item:f};r([i])}return e.checkForQuestionEnabled(e.item)?Sc("div",{children:[e.item.text&&wo(_b,{order:3,mb:"md",children:e.item.text}),wo($b,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?wo(Al,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):wo(vc,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):wo(ma,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as oR,jsx as to,jsxs as Rc}from"react/jsx-runtime";function bc(e){let{items:o,response:t,activePage:r,onChange:a,nextStep:n,prevStep:l,numberOfPages:f,renderPages:i,submitButtonText:s,checkForQuestionEnabled:u}=e,c=o.map(d=>{let m=t?.item?.filter(x=>x.linkId===d.linkId)??[],p=d.type==="group"?to(Al,{item:d,response:m,onChange:a,checkForQuestionEnabled:u},d.linkId):to(ma,{item:d,response:m?.[0],onChange:a,checkForQuestionEnabled:u},d.linkId);return i?to(Cc.Step,{label:d.text,children:p},d.linkId):p});return Rc(oR,{children:[i&&to(Cc,{active:r??0,allowNextStepsSelect:!1,p:6,children:c}),!i&&to(jb,{children:c}),to(eR,{activePage:r??0,numberOfPages:f,nextStep:n,prevStep:l,submitButtonText:s})]})}function eR(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return Rc(Yb,{position:"right",mt:"xl",spacing:"xs",children:[o&&to(Ml,{onClick:e.prevStep,children:"Back"}),t&&to(Ml,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&to(Ml,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as wl,jsxs as lR}from"react/jsx-runtime";function Tc(e){let o=S(),t=o.getProfile(),[r,a]=Fl(!1),n=X(e.questionnaire),[l,f]=Fl(),[i,s]=Fl(0);Pc(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),Pc(()=>{f(n?fc(n):void 0)},[n]);function u(x){let C=l?.item??[],v={resourceType:"QuestionnaireResponse",item:kc(C,Array.isArray(x)?x:[x])};f(v)}function c(x){return rc(x,l?.item??[])}if(!r||!n)return null;let d=uc(n),m=()=>s(x=>x+1),p=()=>s(x=>x-1);return wl(ia.Provider,{value:{subject:e.subject,encounter:e.encounter},children:lR(H,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:aR(n),subject:e.subject,source:rR(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&wl(tR,{children:n.title}),wl(bc,{items:n.item??[],response:l,onChange:u,renderPages:d>1,activePage:i,numberOfPages:d,submitButtonText:e.submitButtonText,checkForQuestionEnabled:c,nextStep:m,prevStep:p})]})})}function nR(e,o){let t=kc(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 kc(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(nR(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 pa,Button as fR,createStyles as sR,Divider as iR,Group as er,NativeSelect as Ol,Stack as xa,Text as uR,TextInput as cR}from"@mantine/core";import{formatRange as Dc,getCodeBySystem as dR}from"@medplum/core";import{useEffect as mR,useState as El}from"react";import{jsx as _,jsxs as dt}from"react/jsx-runtime";var pR=sR(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"}})),xR=["gender","age","gestationalAge","context","appliesTo","category"],IR={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function NG(e){e=Object.assign(IR,e);let o=e.definition,[t,r]=El([]),[a,n]=El(1),[l,f]=El(1);return mR(()=>{let p=yR(o,f);r(vR(p.qualifiedInterval||[],n))},[o]),dt(H,{testid:"reference-range-editor",onSubmit:i,children:[_(xa,{children:t.map(p=>_(gR,{unit:CR(o.quantitativeDetails?.unit),onChange:c,onAdd:d,onRemove:m,onRemoveGroup:u,intervalGroup:p},`group-${p.id}`))}),_(pa,{title:"Add Group",size:"sm",onClick:p=>{M(p),s({id:`group-id-${a}`,filters:{},intervals:[]}),n(x=>x+1)},children:_(So,{})}),_(er,{position:"right",children:_(fR,{type:"submit",children:"Save"})})]});function i(){let p=t.flatMap(x=>x.intervals).filter(x=>!bR(x));e.onSubmit({...o,qualifiedInterval:p})}function s(p){r(x=>[...x,p])}function u(p){r(x=>x.filter(C=>C.id!==p.id))}function c(p,x){r(C=>{C=[...C];let y=C.find(b=>b.id===p),v=y?.intervals.findIndex(b=>b.id===x.id);return v!==void 0&&y?.intervals[v]&&(y.intervals[v]=x),C})}function d(p,x){x.id===void 0&&(x.id=`id-${l}`,f(C=>C+1)),r(C=>{C=[...C];let y=C.findIndex(v=>v.id===p);if(y!==-1){let v={...C[y]};x={...x,...v.filters},v.intervals=[...v.intervals,x],C[y]=v}return C})}function m(p,x){r(C=>{C=[...C];let y=C.find(v=>v.id===p);return y&&(y.intervals=y.intervals.filter(v=>v.id!==x.id)),C})}}function gR(e){let{intervalGroup:o,unit:t}=e,{classes:r}=pR();return _(uo,{"data-testid":o.id,className:r.section,children:dt(xa,{spacing:"lg",children:[_(er,{position:"right",children:_(pa,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{M(a),e.onRemoveGroup(o)},children:_(lo,{})},`remove-group-button-${o.id}`)}),_(hR,{intervalGroup:o,onChange:e.onChange}),_(iR,{}),o.intervals.map(a=>dt(xa,{spacing:"xs",children:[dt(er,{children:[_(cR,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{M(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),_(pa,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{M(n),e.onRemove(o.id,a)},children:_(lo,{})},`remove-interval-${a.id}`)]}),_(Lt,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),_(pa,{title:"Add Interval",size:"sm",onClick:a=>{M(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:_(So,{})})]})})}function hR(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 dt(xa,{style:{maxWidth:"50%"},children:[_(er,{children:_(Ol,{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})}}})}),dt(er,{spacing:"xs",children:[_(uR,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),_("div",{id:`div-age-${o.id}`,children:_(Lt,{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}`)})]}),_(Ol,{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"}]}})}}}),_(Ol,{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 yR(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 vR(e,o){let t=1,r={};for(let a of e){let n=SR(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(xR.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function SR(e){return[`gender=${e.gender}`,`age=${Dc(e.age)}`,`gestationalAge=${Dc(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function CR(e){return e&&(dR(e,"http://unitsofmeasure.org")||e.text)}function bR(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as Bc,Grid as Ia,Text as RR}from"@mantine/core";import{formatDateTime as PR,getReferenceString as TR}from"@medplum/core";import{Fragment as kR,useEffect as DR,useState as Ac}from"react";import{jsx as Je,jsxs as or}from"react/jsx-runtime";function JG(e){let o=S(),t=X(e.value),[r,a]=Ac(!1),[n,l]=Ac();if(DR(()=>{t&&!r&&(o.executeBatch(f(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Je(Ia,{children:t.action?.map((s,u)=>{let c=s.resource&&i(s.resource),d=c?.input?.[0]?.valueReference,m=c?.output?.[0]?.valueReference;return or(kR,{children:[Je(Ia.Col,{span:1,p:"md",children:c?.status==="completed"?Je(Va,{}):Je(on,{color:"gray"})}),or(Ia.Col,{span:9,p:"xs",children:[Je(RR,{weight:500,children:s.title}),s.description&&Je("div",{children:s.description}),or("div",{children:["Last edited by\xA0",Je(Ue,{value:c?.meta?.author}),"\xA0on\xA0",PR(c?.meta?.lastUpdated)]}),or("div",{children:["Status: ",Je(Er,{status:c?.status||"unknown"})]})]}),or(Ia.Col,{span:2,p:"md",children:[d&&!m&&Je(Bc,{onClick:()=>e.onStart(c,d),children:"Start"}),d&&m&&Je(Bc,{onClick:()=>e.onEdit(c,d,m),children:"Edit"})]})]},`action-${u}`)})});function f(s){let u=[];if(s.action)for(let c of s.action)c.resource?.reference&&u.push({request:{method:"GET",url:c.resource.reference}});return{resourceType:"Bundle",type:"batch",entry:u}}function i(s){for(let u of n?.entry)if(u.resource&&s.reference===TR(u.resource))return u.resource}}import{createStyles as ER}from"@mantine/core";import{useEffect as LR,useState as NR}from"react";import{stringify as FR}from"@medplum/core";function ga(e,o){let t=BR(e,o);return AR(t,e,o)}function BR(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 i=0;i<a;i++){for(let s=-i;s<=i;s+=2){let u=l+s,c=u+1,d=u-1,m=f[c],p=f[d],x,C=0;s===-i||s!==i&&p.i<m.i?(C=m.i,x=m):(C=p.i+1,x=p),f[d]=void 0;let y=C-s,v={i:C,j:y,prev:MR(x),snake:!1};for(;C<t&&y<r&&e[C]===o[y];)C++,y++;if(C>v.i&&(v={i:C,j:y,prev:v,snake:!0}),f[u]=v,C>=t&&y>=r)return f[u]}f[l+i-1]=void 0}}function AR(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,i=a.j,s={position:f,lines:o.slice(f,n)},u={position:i,lines:t.slice(i,l)},c;s.lines.length===0&&u.lines.length>0?c="insert":s.lines.length>0&&u.lines.length===0?c="delete":c="change",r.push({original:s,revised:u,type:c}),a.snake&&(a=a.prev)}return r}function MR(e){return e&&!e.snake&&e.prev?e.prev:e}function Mc(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:FR(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 wR(t,o),OR(t),t}function wR(e,o){for(let t=1;t<o.length;t++){let r=ga(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 i=0;i<a.revised.lines.length;i++)e.splice(n+i,0,{id:o[t].meta.versionId,meta:o[t].meta,value:f[i],span:1})}}}function OR(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 Fc(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function wc(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return mt(t,"year");let r=Math.floor(o/2592e3);if(r>0)return mt(r,"month");let a=Math.floor(o/86400);if(a>0)return mt(a,"day");let n=Math.floor(o/3600);if(n>0)return mt(n,"hour");let l=Math.floor(o/60);return l>0?mt(l,"minute"):mt(o,"second")}function mt(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as HR,jsx as qe,jsxs as Oc}from"react/jsx-runtime";var VR=ER(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 s4(e){let{classes:o}=VR(),t=S(),[r,a]=NR(e.history);if(LR(()=>{!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 qe("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Mc(r);return qe("div",{className:o.container,children:qe("table",{className:o.root,children:qe("tbody",{children:l.map((f,i)=>Oc("tr",{className:f.span>0?o.startRow:o.normalRow,children:[f.span>0&&Oc(HR,{children:[qe("td",{className:o.author,rowSpan:f.span,children:qe(co,{value:f.meta.author,link:!0})}),qe("td",{className:o.dateTime,rowSpan:f.span,children:qe(le,{to:Fc(n,f.meta.versionId),children:wc(f.meta.lastUpdated)})})]}),qe("td",{className:o.lineNumber,children:i+1}),qe("td",{className:o.line,children:qe("pre",{className:o.pre,children:f.value})})]},"row-"+i))})})})}import{createStyles as qR}from"@mantine/core";import{stringify as Ec}from"@medplum/core";import{Fragment as QR,jsx as pt,jsxs as zR}from"react/jsx-runtime";var GR=qR(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function x4(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Ec(o,!0).match(/[^\r\n]+/g),a=Ec(t,!0).match(/[^\r\n]+/g),n=ga(r,a);return pt("pre",{style:{color:"gray"},children:n.map((l,f)=>pt(UR,{delta:l},"delta"+f))})}function UR(e){let{classes:o}=GR();return zR(QR,{children:["...",pt("br",{}),e.delta.original.lines.length>0&&pt("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
72
72
|
`)}),e.delta.revised.lines.length>0&&pt("div",{className:o.added,children:e.delta.revised.lines.join(`
|
|
73
|
-
`)}),"...",pt("br",{})]})}import{Button as Lc,Group as WR,Stack as XR,TextInput as Nc}from"@mantine/core";import{deepClone as JR,tryGetProfile as $R}from"@medplum/core";import{useEffect as _R,useState as Vc}from"react";import{jsx as go,jsxs as Ll}from"react/jsx-runtime";function P4(e){let{outcome:o}=e,t=S(),r=X(e.defaultValue),[a,n]=Vc(),[l,f]=Vc();return _R(()=>{if(r)if(f(JR(r)),e.profileUrl){let i=e.profileUrl;t.requestProfileSchema(e.profileUrl).then(()=>{let s=$R(i);s?n(s.name):console.log(`Schema not found for ${i}`)}).catch(console.log)}else{let i=e.schemaName??r?.resourceType;t.requestSchema(i).then(()=>n(i)).catch(console.log)}},[t,r,e.schemaName,e.profileUrl]),!a||!l?go("div",{children:"Loading..."}):Ll("form",{noValidate:!0,autoComplete:"off",onSubmit:i=>{i.preventDefault(),e.onSubmit&&e.onSubmit(l)},children:[Ll(XR,{mb:"xl",children:[go(pe,{title:"Resource Type",htmlFor:"resourceType",outcome:o,children:go(Nc,{name:"resourceType",defaultValue:l.resourceType,disabled:!0})}),go(pe,{title:"ID",htmlFor:"id",outcome:o,children:go(Nc,{name:"id",defaultValue:l.id,disabled:!0})})]}),go(Ko,{typeName:a,defaultValue:l,outcome:o,onChange:f,profileUrl:e.profileUrl}),Ll(WR,{position:"right",mt:"xl",children:[go(Lc,{type:"submit",children:"OK"}),e.onDelete&&go(Lc,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(l)},children:"Delete"})]})]})}import{Table as KR}from"@mantine/core";import{formatDateTime as ZR,normalizeErrorString as YR}from"@medplum/core";import{useEffect as jR,useState as eP}from"react";import{jsx as Re,jsxs as Nl}from"react/jsx-runtime";function O4(e){let o=S(),[t,r]=eP(e.history);return jR(()=>{!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?Nl(KR,{withBorder:!0,withColumnBorders:!0,children:[Re("thead",{children:Nl("tr",{children:[Re("th",{children:"Author"}),Re("th",{children:"Date"}),Re("th",{children:"Version"})]})}),Re("tbody",{children:t.entry?.map((a,n)=>Re(oP,{entry:a},"entry-"+n))})]}):Re("div",{children:"Loading..."})}function oP(e){let{response:o,resource:t}=e.entry;return t?Nl("tr",{children:[Re("td",{children:Re(co,{value:t.meta?.author,link:!0})}),Re("td",{children:ZR(t.meta?.lastUpdated)}),Re("td",{children:Re(le,{to:tP(t),children:t.meta?.versionId})})]}):Re("tr",{children:Re("td",{colSpan:3,children:YR(o?.outcome)})})}function tP(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as rP,createStyles as aP,Stack as nP,Text as lP}from"@mantine/core";import{getReferenceString as fP,isReference as sP}from"@medplum/core";import{useState as ha}from"react";import{jsx as ge,jsxs as xt}from"react/jsx-runtime";var iP=aP(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function X4(e){let{classes:o}=iP(),t=X(e.schedule),r=X(e.questionnaire),[a,n]=ha(Or()),[l,f]=ha(),[i,s]=ha(),[u,c]=ha(),[d]=Zl("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",sP(e.schedule)?e.schedule.reference:fP(e.schedule)],["start","gt"+uP(a)],["start","lt"+cP(a)]]));if(!t||!d||!r)return null;let m=t.actor?.[0];return xt("div",{className:o.container,"data-testid":"scheduler",children:[xt("div",{className:o.info,children:[m&&ge(fe,{value:m,size:"xl"}),m&&ge(lP,{size:"xl",weight:500,children:ge(Ue,{value:m})}),ge("p",{children:"1 hour"}),l&&ge("p",{children:l.toLocaleDateString()}),i&&ge("p",{children:Hc(new Date(i.start))})]}),xt("div",{className:o.selection,children:[!l&&xt("div",{children:[ge("h3",{children:"Select date"}),ge(qs,{slots:d,onChangeMonth:n,onClick:f})]}),l&&!i&&xt("div",{children:[ge("h3",{children:"Select time"}),ge(nP,{children:d.map(p=>{let x=new Date(p.start);return x.getTime()>l.getTime()&&x.getTime()<l.getTime()+24*3600*1e3&&ge("div",{children:ge(rP,{variant:"outline",style:{width:150},onClick:()=>s(p),children:Hc(x)})},p.id)})})]}),l&&i&&!u&&ge(Tc,{questionnaire:r,submitButtonText:"Next",onSubmit:c}),l&&i&&u&&xt("div",{children:[ge("h3",{children:"You're all set!"}),ge("p",{children:"Check your email for a calendar invite."})]})]})]})}function uP(e){return qc(e.getTime())}function cP(e){return qc(e.getTime()+31*24*60*60*1e3)}function qc(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Hc(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as ya}from"@medplum/core";import{jsx as dP}from"react/jsx-runtime";function j4(e){return dP(po,{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:[ya(o)],subject:o.subject,sender:ya(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[ya(o)],subject:o.subject,operator:ya(t),issued:new Date().toISOString(),content:r})})}import{Anchor as mP}from"@mantine/core";import{showNotification as pP}from"@mantine/notifications";import{normalizeErrorString as xP}from"@medplum/core";import{jsx as IP}from"react/jsx-runtime";function fU(e){let o=S(),{client:t,patient:r,encounter:a,children:n,...l}=e;function f(){o.createResource({resourceType:"SmartAppLaunch",patient:r,encounter:a}).then(i=>{let s=new URL(t.launchUri);s.searchParams.set("iss",o.getBaseUrl()+"fhir/R4"),s.searchParams.set("launch",i.id),window.location.assign(s.toString())}).catch(i=>pP({color:"red",message:xP(i),autoClose:!1}))}return IP(mP,{onClick:()=>f(),...l,children:n})}import{normalizeOperationOutcome as VP}from"@medplum/core";import{useEffect as HP,useState as $c}from"react";import{Anchor as Gc,Button as gP,Center as hP,Group as yP,Stack as vP,Text as SP,TextInput as CP,Title as bP}from"@mantine/core";import{normalizeOperationOutcome as RP}from"@medplum/core";import{useState as PP}from"react";import{jsx as Oo,jsxs as va}from"react/jsx-runtime";function Sa(e){let o=S(),[t,r]=PP();return va(H,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(RP(n))}},children:[va(hP,{sx:{flexDirection:"column"},children:[Oo(xo,{size:32}),Oo(bP,{children:"Create project"})]}),va(vP,{spacing:"xl",children:[Oo(CP,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:Q(t,"firstName")}),va(SP,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",Oo(Gc,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",Oo(Gc,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),Oo(yP,{position:"right",mt:"xl",noWrap:!0,children:Oo(gP,{type:"submit",children:"Create project"})})]})}import{Anchor as Pa,Button as AP,Center as BP,Checkbox as MP,Divider as FP,Group as zc,PasswordInput as wP,Stack as OP,Text as Wc,TextInput as Hl}from"@mantine/core";import{normalizeOperationOutcome as Xc}from"@medplum/core";import{useEffect as EP,useState as LP}from"react";import{useEffect as TP,useRef as kP,useState as Vl}from"react";function Ca(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 DP}from"react/jsx-runtime";function ba(e){let o=S(),{googleClientId:t,handleGoogleCredential:r}=e,a=kP(null),[n,l]=Vl(typeof google<"u"),[f,i]=Vl(!1),[s,u]=Vl(!1);return TP(()=>{if(typeof google>"u"){Ca("https://accounts.google.com/gsi/client",()=>l(!0));return}f||(google.accounts.id.initialize({client_id:t,callback:r}),i(!0)),a.current&&!s&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,f,n,a,s,r]),t?DP("div",{ref:a}):null}function Ra(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 Uc(e){typeof grecaptcha>"u"&&Ca("https://www.google.com/recaptcha/api.js?render="+e)}function Qc(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as NP,jsx as he,jsxs as It}from"react/jsx-runtime";function Jc(e){let o=Ra(e.googleClientId),t=e.recaptchaSiteKey,r=S(),[a,n]=LP(),l=br(a,void 0);return EP(()=>{t&&Uc(t)},[t]),It(H,{style:{maxWidth:400},onSubmit:async f=>{try{let i="";t&&(i=await Qc(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:i}))}catch(i){n(Xc(i))}},children:[he(BP,{sx:{flexDirection:"column"},children:e.children}),he(ft,{issues:l}),o&&It(NP,{children:[he(zc,{position:"center",p:"xl",style:{height:70},children:he(ba,{googleClientId:o,handleGoogleCredential:async f=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:f.clientId,googleCredential:f.credential,createUser:!0}))}catch(i){n(Xc(i))}}})}),he(FP,{label:"or",labelPosition:"center",my:"lg"})]}),It(OP,{spacing:"xl",children:[he(Hl,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:Q(a,"firstName")}),he(Hl,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:Q(a,"lastName")}),he(Hl,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:Q(a,"email")}),he(wP,{name:"password",label:"Password",autoComplete:"off",required:!0,error:Q(a,"password")}),It(Wc,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",he(Pa,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",he(Pa,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),It(Wc,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",he(Pa,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",he(Pa,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),It(zc,{position:"apart",mt:"xl",noWrap:!0,children:[he(MP,{name:"remember",label:"Remember me",size:"xs"}),he(AP,{type:"submit",children:"Create account"})]})]})}import{jsx as ql,jsxs as qP}from"react/jsx-runtime";function YU(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,f=S(),[i,s]=$c(),[u,c]=$c();HP(()=>{o==="patient"&&i&&f.startNewPatient({login:i,projectId:t}).then(m=>f.processCode(m.code)).then(()=>l()).catch(m=>c(VP(m)))},[f,o,t,i,l]);function d(m){m.code?f.processCode(m.code).then(()=>l()).catch(console.log):m.login&&s(m.login)}return qP(Ur,{width:450,children:[u&&ql("pre",{children:JSON.stringify(u,null,2)}),!i&&ql(Jc,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:d,children:e.children}),i&&o==="project"&&ql(Sa,{login:i,handleAuthResponse:d})]})}import{showNotification as sd}from"@mantine/notifications";import{normalizeErrorString as id}from"@medplum/core";import{useCallback as Ul,useEffect as gT,useState as Ql}from"react";import{Anchor as _c,Button as Kc,Center as Zc,Checkbox as GP,Divider as UP,Group as Gl,PasswordInput as QP,Stack as zP,TextInput as WP}from"@mantine/core";import{normalizeOperationOutcome as XP}from"@medplum/core";import{useCallback as Ta,useState as Yc}from"react";import{Fragment as _P,jsx as ie,jsxs as tr}from"react/jsx-runtime";function jc(e){let[o,t]=Yc();return o?ie($P,{email:o,...e}):ie(JP,{setEmail:t,...e})}function JP(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,f=S(),i=!e.disableGoogleAuth&&Ra(e.googleClientId),s=Ta(async d=>{if(!d.authorizeUrl)return!1;let m=JSON.stringify({...await f.ensureCodeChallenge(l),domain:d.domain}),p=new URL(d.authorizeUrl);return p.searchParams.set("state",m),window.location.assign(p.toString()),!0},[f,l]),u=Ta(async d=>{let m=await f.post("auth/method",{email:d.email});await s(m)||o(d.email)},[f,s,o]),c=Ta(async d=>{let m=await f.startGoogleLogin({...l,googleCredential:d.credential});await s(m)||r(m)},[f,l,s,r]);return tr(H,{style:{maxWidth:400},onSubmit:u,children:[ie(Zc,{sx:{flexDirection:"column"},children:a}),i&&tr(_P,{children:[ie(Gl,{position:"center",p:"xl",style:{height:70},children:ie(ba,{googleClientId:i,handleGoogleCredential:c})}),!n&&ie(UP,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&ie(WP,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),tr(Gl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[ie("div",{children:t&&ie(_c,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&ie(Kc,{type:"submit",children:"Next"})]})]})}function $P(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=S(),[l,f]=Yc(),i=br(l,void 0),s=Ta(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(c=>f(XP(c)))},[n,a,t]);return tr(H,{style:{maxWidth:400},onSubmit:s,children:[ie(Zc,{sx:{flexDirection:"column"},children:r}),ie(ft,{issues:i}),ie(zP,{spacing:"xl",children:ie(QP,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:Q(l,"password")})}),tr(Gl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&ie(_c,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),ie(GP,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),ie(Kc,{type:"submit",children:"Sign in"})]})]})}import{Avatar as KP,Center as ZP,Group as YP,Stack as jP,Text as ed,Title as eT,UnstyledButton as oT}from"@mantine/core";import{normalizeOperationOutcome as tT}from"@medplum/core";import{useState as rT}from"react";import{jsx as Eo,jsxs as ka}from"react/jsx-runtime";function od(e){let o=S(),[t,r]=rT();return ka(jP,{children:[ka(ZP,{sx:{flexDirection:"column"},children:[Eo(xo,{size:32}),Eo(eT,{order:3,children:"Choose profile"})]}),Eo(ft,{outcome:t}),e.memberships.map(a=>Eo(oT,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(tT(n)))},children:ka(YP,{children:[Eo(KP,{radius:"xl"}),ka("div",{style:{flex:1},children:[Eo(ed,{size:"sm",weight:500,children:a.profile?.display}),Eo(ed,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as aT,Center as nT,Checkbox as lT,Group as fT,Stack as td,Title as sT}from"@mantine/core";import{jsx as Lo,jsxs as rd}from"react/jsx-runtime";function ad(e){let o=S();return Lo(H,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:rd(td,{children:[rd(nT,{sx:{flexDirection:"column"},children:[Lo(xo,{size:32}),Lo(sT,{children:"Choose scope"})]}),Lo(td,{children:(e.scope??"openid").split(" ").map(t=>Lo(lT,{id:t,name:t,label:t,defaultChecked:!0},t))}),Lo(fT,{position:"right",mt:"xl",children:Lo(aT,{type:"submit",children:"Set scope"})})]})})}import{Alert as iT,Button as uT,Center as cT,Group as dT,Stack as nd,TextInput as mT,Title as pT}from"@mantine/core";import{normalizeErrorString as xT}from"@medplum/core";import{useState as IT}from"react";import{jsx as ro,jsxs as ld}from"react/jsx-runtime";function fd(e){let o=S(),[t,r]=IT();return ro(H,{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(xT(n)))},children:ld(nd,{children:[ld(cT,{sx:{flexDirection:"column"},children:[ro(xo,{size:32}),ro(pT,{children:"Enter MFA code"})]}),t&&ro(iT,{icon:ro(vo,{size:16}),title:"Error",color:"red",children:t}),ro(nd,{children:ro(mT,{name:"token",label:"MFA code",required:!0})}),ro(dT,{position:"right",mt:"xl",children:ro(uT,{type:"submit",children:"Submit code"})})]})})}import{jsx as No}from"react/jsx-runtime";function oQ(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...f}=e,i=S(),[s,u]=Ql(),[c,d]=Ql(!1),[m,p]=Ql(),x=Ul(v=>{l?l(v):i.processCode(v).then(()=>{r&&r()}).catch(b=>sd({color:"red",message:id(b)}))},[i,l,r]),C=Ul(v=>{d(!!v.mfaRequired),v.login&&u(v.login),v.memberships&&p(v.memberships),v.code&&(t?p(void 0):x(v.code))},[t,x]),y=Ul(v=>{x(v.code)},[x]);return gT(()=>{o&&!s&&i.get("auth/login/"+o).then(C).catch(v=>sd({color:"red",message:id(v)}))},[i,o,s,C]),No(Ur,{width:450,children:s?c?No(fd,{login:s,handleAuthResponse:C}):m?No(od,{login:s,memberships:m,handleAuthResponse:C}):e.projectId==="new"?No(Sa,{login:s,handleAuthResponse:C}):e.chooseScopes?No(ad,{login:s,scope:e.scope,handleAuthResponse:y}):No("div",{children:"Success"}):No(jc,{onForgotPassword:a,onRegister:n,handleAuthResponse:C,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...f,children:e.children})})}export{Yl as AddressDisplay,tf as AddressInput,rf as AnnotationInput,wM as AppShell,Qo as AsyncAutocomplete,Mf as AttachmentArrayDisplay,wf as AttachmentArrayInput,Jo as AttachmentButton,Ge as AttachmentDisplay,xr as AttachmentInput,wt as BackboneElementDisplay,Ko as BackboneElementInput,qs as CalendarInput,Cr as CheckboxFormSection,mr as CodeInput,ye as CodeableConceptDisplay,_o as CodeableConceptInput,Nf as CodingDisplay,Rr as CodingInput,Vf as ContactDetailDisplay,Yf as ContactDetailInput,hr as ContactPointDisplay,Pr as ContactPointInput,uo as Container,Ve as DateTimeInput,t2 as DefaultResourceTimeline,Ef as DescriptionList,Lf as DescriptionListEntry,Fn as DiagnosticReportDisplay,Ur as Document,Zg as ElementDefinitionInputSelector,Br as ElementDefinitionTypeInput,p2 as EncounterTimeline,Go as ErrorBoundary,hS as FhirPathTable,H as Form,pe as FormSection,Pf as Header,ur as HumanNameDisplay,ns as HumanNameInput,Hf as IdentifierDisplay,ss as IdentifierInput,fn as Loading,xo as Logo,vV as MeasureReportDisplay,le as MedplumLink,CT as MedplumProvider,fV as MemoizedFhirPathTable,_N as MemoizedSearchControl,qf as MoneyDisplay,is as MoneyInput,Bf as Navbar,Qh as ObservationTable,ft as OperationOutcomeAlert,Yo as Panel,qH as PatientSummary,$H as PatientTimeline,mq as PlanDefinitionBuilder,ae as QuantityDisplay,Be as QuantityInput,Zq as QuestionnaireBuilder,Tc as QuestionnaireForm,la as QuestionnaireItemType,yr as RangeDisplay,Lt as RangeInput,To as ReferenceDisplay,Zo as ReferenceInput,NG as ReferenceRangeEditor,gR as ReferenceRangeGroupEditor,YU as RegisterForm,JG as RequestGroupDisplay,Wf as ResourceArrayDisplay,Rs as ResourceArrayInput,fe as ResourceAvatar,co as ResourceBadge,s4 as ResourceBlame,x4 as ResourceDiff,P4 as ResourceForm,O4 as ResourceHistoryTable,kr as ResourceInput,Ue as ResourceName,ce as ResourcePropertyDisplay,io as ResourcePropertyInput,zn as ResourceTable,po as ResourceTimeline,X4 as Scheduler,nl as SearchChangeEvent,Do as SearchClickEvent,lS as SearchControl,Wi as SearchFieldEditor,Yi as SearchFilterEditor,ll as SearchLoadEvent,j4 as ServiceRequestTimeline,oQ as SignInForm,fU as SmartAppLaunchLink,Er as StatusBadge,Ii as Timeline,mo as TimelineItem,Fs as TimingInput,Kn as addDateFilterBetween,M2 as addField,ot as addFilter,Ei as addLastMonthFilter,Zn as addMissingFilter,Ni as addNextMonthFilter,Li as addThisMonthFilter,wi as addTodayFilter,Oi as addTomorrowFilter,Vi as addYearToDateFilter,Fi as addYesterdayFilter,we as buildFieldNameString,fc as buildInitialResponse,Cl as buildInitialResponseItem,B2 as clearFilters,Wr as clearFiltersOnField,es as convertIsoToLocal,os as convertLocalToIso,Ca as createScriptTag,Mi as deleteFilter,ic as formatReferenceString,Q as getErrorsForInput,tu as getFieldDefinitions,br as getIssuesForExpression,ac as getNewMultiSelectValues,uc as getNumberOfPages,Xt as getOpString,lc as getQuestionnaireItemReferenceFilter,fa as getQuestionnaireItemReferenceTargetTypes,Qc as getRecaptcha,Ui as getSearchOperators,qi as getSortField,Uc as initRecaptcha,tc as isChoiceQuestion,rc as isQuestionEnabled,Gi as isSortDescending,$w as isSupportedProfileStructureDefinition,Tf as parseForm,$l as reactContext,Qi as renderValue,Wt as setFilters,fv as setOffset,Hi as setPage,Ot as setPropertyValue,sa as setQuestionnaireItemReferenceTargetTypes,Yn as setSort,yi as sortByDateAndPriority,F2 as toggleSort,S as useMedplum,St as useMedplumContext,no as useMedplumNavigate,nr as useMedplumProfile,X as useResource,kT as useSearch,Kl as useSearchOne,Zl as useSearchResources};
|
|
73
|
+
`)}),"...",pt("br",{})]})}import{Button as Lc,Group as WR,Stack as XR,TextInput as Nc}from"@mantine/core";import{deepClone as JR,tryGetProfile as $R}from"@medplum/core";import{useEffect as _R,useState as Vc}from"react";import{jsx as go,jsxs as Ll}from"react/jsx-runtime";function P4(e){let{outcome:o}=e,t=S(),r=X(e.defaultValue),[a,n]=Vc(),[l,f]=Vc();return _R(()=>{if(r)if(f(JR(r)),e.profileUrl){let i=e.profileUrl;t.requestProfileSchema(e.profileUrl).then(()=>{let s=$R(i);s?n(s.name):console.log(`Schema not found for ${i}`)}).catch(console.log)}else{let i=e.schemaName??r?.resourceType;t.requestSchema(i).then(()=>n(i)).catch(console.log)}},[t,r,e.schemaName,e.profileUrl]),!a||!l?go("div",{children:"Loading..."}):Ll("form",{noValidate:!0,autoComplete:"off",onSubmit:i=>{i.preventDefault(),e.onSubmit&&e.onSubmit(l)},children:[Ll(XR,{mb:"xl",children:[go(pe,{title:"Resource Type",htmlFor:"resourceType",outcome:o,children:go(Nc,{name:"resourceType",defaultValue:l.resourceType,disabled:!0})}),go(pe,{title:"ID",htmlFor:"id",outcome:o,children:go(Nc,{name:"id",defaultValue:l.id,disabled:!0})})]}),go(Ko,{typeName:a,defaultValue:l,outcome:o,onChange:f,profileUrl:e.profileUrl}),Ll(WR,{position:"right",mt:"xl",children:[go(Lc,{type:"submit",children:"OK"}),e.onDelete&&go(Lc,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(l)},children:"Delete"})]})]})}import{Table as KR}from"@mantine/core";import{formatDateTime as ZR,normalizeErrorString as YR}from"@medplum/core";import{useEffect as jR,useState as eP}from"react";import{jsx as Re,jsxs as Nl}from"react/jsx-runtime";function O4(e){let o=S(),[t,r]=eP(e.history);return jR(()=>{!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?Nl(KR,{withBorder:!0,withColumnBorders:!0,children:[Re("thead",{children:Nl("tr",{children:[Re("th",{children:"Author"}),Re("th",{children:"Date"}),Re("th",{children:"Version"})]})}),Re("tbody",{children:t.entry?.map((a,n)=>Re(oP,{entry:a},"entry-"+n))})]}):Re("div",{children:"Loading..."})}function oP(e){let{response:o,resource:t}=e.entry;return t?Nl("tr",{children:[Re("td",{children:Re(co,{value:t.meta?.author,link:!0})}),Re("td",{children:ZR(t.meta?.lastUpdated)}),Re("td",{children:Re(le,{to:tP(t),children:t.meta?.versionId})})]}):Re("tr",{children:Re("td",{colSpan:3,children:YR(o?.outcome)})})}function tP(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as rP,createStyles as aP,Stack as nP,Text as lP}from"@mantine/core";import{getReferenceString as fP,isReference as sP}from"@medplum/core";import{useState as ha}from"react";import{jsx as ge,jsxs as xt}from"react/jsx-runtime";var iP=aP(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function X4(e){let{classes:o}=iP(),t=X(e.schedule),r=X(e.questionnaire),[a,n]=ha(Or()),[l,f]=ha(),[i,s]=ha(),[u,c]=ha(),[d]=Zl("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",sP(e.schedule)?e.schedule.reference:fP(e.schedule)],["start","gt"+uP(a)],["start","lt"+cP(a)]]));if(!t||!d||!r)return null;let m=t.actor?.[0];return xt("div",{className:o.container,"data-testid":"scheduler",children:[xt("div",{className:o.info,children:[m&&ge(fe,{value:m,size:"xl"}),m&&ge(lP,{size:"xl",weight:500,children:ge(Ue,{value:m})}),ge("p",{children:"1 hour"}),l&&ge("p",{children:l.toLocaleDateString()}),i&&ge("p",{children:Hc(new Date(i.start))})]}),xt("div",{className:o.selection,children:[!l&&xt("div",{children:[ge("h3",{children:"Select date"}),ge(qs,{slots:d,onChangeMonth:n,onClick:f})]}),l&&!i&&xt("div",{children:[ge("h3",{children:"Select time"}),ge(nP,{children:d.map(p=>{let x=new Date(p.start);return x.getTime()>l.getTime()&&x.getTime()<l.getTime()+24*3600*1e3&&ge("div",{children:ge(rP,{variant:"outline",style:{width:150},onClick:()=>s(p),children:Hc(x)})},p.id)})})]}),l&&i&&!u&&ge(Tc,{questionnaire:r,submitButtonText:"Next",onSubmit:c}),l&&i&&u&&xt("div",{children:[ge("h3",{children:"You're all set!"}),ge("p",{children:"Check your email for a calendar invite."})]})]})]})}function uP(e){return qc(e.getTime())}function cP(e){return qc(e.getTime()+31*24*60*60*1e3)}function qc(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Hc(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as ya}from"@medplum/core";import{jsx as dP}from"react/jsx-runtime";function j4(e){return dP(po,{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:[ya(o)],subject:o.subject,sender:ya(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[ya(o)],subject:o.subject,operator:ya(t),issued:new Date().toISOString(),content:r})})}import{Anchor as mP}from"@mantine/core";import{showNotification as pP}from"@mantine/notifications";import{normalizeErrorString as xP}from"@medplum/core";import{jsx as IP}from"react/jsx-runtime";function fU(e){let o=S(),{client:t,patient:r,encounter:a,children:n,...l}=e;function f(){o.createResource({resourceType:"SmartAppLaunch",patient:r,encounter:a}).then(i=>{let s=new URL(t.launchUri);s.searchParams.set("iss",o.getBaseUrl()+"fhir/R4"),s.searchParams.set("launch",i.id),window.location.assign(s.toString())}).catch(i=>pP({color:"red",message:xP(i),autoClose:!1}))}return IP(mP,{onClick:()=>f(),...l,children:n})}import{normalizeOperationOutcome as VP}from"@medplum/core";import{useEffect as HP,useState as $c}from"react";import{Anchor as Gc,Button as gP,Center as hP,Group as yP,Stack as vP,Text as SP,TextInput as CP,Title as bP}from"@mantine/core";import{normalizeOperationOutcome as RP}from"@medplum/core";import{useState as PP}from"react";import{jsx as Oo,jsxs as va}from"react/jsx-runtime";function Sa(e){let o=S(),[t,r]=PP();return va(H,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(RP(n))}},children:[va(hP,{sx:{flexDirection:"column"},children:[Oo(xo,{size:32}),Oo(bP,{children:"Create project"})]}),va(vP,{spacing:"xl",children:[Oo(CP,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:Q(t,"firstName")}),va(SP,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",Oo(Gc,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",Oo(Gc,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),Oo(yP,{position:"right",mt:"xl",noWrap:!0,children:Oo(gP,{type:"submit",children:"Create project"})})]})}import{Anchor as Pa,Button as BP,Center as AP,Checkbox as MP,Divider as FP,Group as zc,PasswordInput as wP,Stack as OP,Text as Wc,TextInput as Hl}from"@mantine/core";import{normalizeOperationOutcome as Xc}from"@medplum/core";import{useEffect as EP,useState as LP}from"react";import{useEffect as TP,useRef as kP,useState as Vl}from"react";function Ca(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 DP}from"react/jsx-runtime";function ba(e){let o=S(),{googleClientId:t,handleGoogleCredential:r}=e,a=kP(null),[n,l]=Vl(typeof google<"u"),[f,i]=Vl(!1),[s,u]=Vl(!1);return TP(()=>{if(typeof google>"u"){Ca("https://accounts.google.com/gsi/client",()=>l(!0));return}f||(google.accounts.id.initialize({client_id:t,callback:r}),i(!0)),a.current&&!s&&(google.accounts.id.renderButton(a.current,{}),u(!0))},[o,t,f,n,a,s,r]),t?DP("div",{ref:a}):null}function Ra(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 Uc(e){typeof grecaptcha>"u"&&Ca("https://www.google.com/recaptcha/api.js?render="+e)}function Qc(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as NP,jsx as he,jsxs as It}from"react/jsx-runtime";function Jc(e){let o=Ra(e.googleClientId),t=e.recaptchaSiteKey,r=S(),[a,n]=LP(),l=br(a,void 0);return EP(()=>{t&&Uc(t)},[t]),It(H,{style:{maxWidth:400},onSubmit:async f=>{try{let i="";t&&(i=await Qc(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:i}))}catch(i){n(Xc(i))}},children:[he(AP,{sx:{flexDirection:"column"},children:e.children}),he(ft,{issues:l}),o&&It(NP,{children:[he(zc,{position:"center",p:"xl",style:{height:70},children:he(ba,{googleClientId:o,handleGoogleCredential:async f=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:f.clientId,googleCredential:f.credential,createUser:!0}))}catch(i){n(Xc(i))}}})}),he(FP,{label:"or",labelPosition:"center",my:"lg"})]}),It(OP,{spacing:"xl",children:[he(Hl,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:Q(a,"firstName")}),he(Hl,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:Q(a,"lastName")}),he(Hl,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:Q(a,"email")}),he(wP,{name:"password",label:"Password",autoComplete:"off",required:!0,error:Q(a,"password")}),It(Wc,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",he(Pa,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",he(Pa,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),It(Wc,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",he(Pa,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",he(Pa,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),It(zc,{position:"apart",mt:"xl",noWrap:!0,children:[he(MP,{name:"remember",label:"Remember me",size:"xs"}),he(BP,{type:"submit",children:"Create account"})]})]})}import{jsx as ql,jsxs as qP}from"react/jsx-runtime";function YU(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,f=S(),[i,s]=$c(),[u,c]=$c();HP(()=>{o==="patient"&&i&&f.startNewPatient({login:i,projectId:t}).then(m=>f.processCode(m.code)).then(()=>l()).catch(m=>c(VP(m)))},[f,o,t,i,l]);function d(m){m.code?f.processCode(m.code).then(()=>l()).catch(console.log):m.login&&s(m.login)}return qP(Ur,{width:450,children:[u&&ql("pre",{children:JSON.stringify(u,null,2)}),!i&&ql(Jc,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:d,children:e.children}),i&&o==="project"&&ql(Sa,{login:i,handleAuthResponse:d})]})}import{showNotification as sd}from"@mantine/notifications";import{normalizeErrorString as id}from"@medplum/core";import{useCallback as Ul,useEffect as gT,useState as Ql}from"react";import{Anchor as _c,Button as Kc,Center as Zc,Checkbox as GP,Divider as UP,Group as Gl,PasswordInput as QP,Stack as zP,TextInput as WP}from"@mantine/core";import{normalizeOperationOutcome as XP}from"@medplum/core";import{useCallback as Ta,useState as Yc}from"react";import{Fragment as _P,jsx as ie,jsxs as tr}from"react/jsx-runtime";function jc(e){let[o,t]=Yc();return o?ie($P,{email:o,...e}):ie(JP,{setEmail:t,...e})}function JP(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,f=S(),i=!e.disableGoogleAuth&&Ra(e.googleClientId),s=Ta(async d=>{if(!d.authorizeUrl)return!1;let m=JSON.stringify({...await f.ensureCodeChallenge(l),domain:d.domain}),p=new URL(d.authorizeUrl);return p.searchParams.set("state",m),window.location.assign(p.toString()),!0},[f,l]),u=Ta(async d=>{let m=await f.post("auth/method",{email:d.email});await s(m)||o(d.email)},[f,s,o]),c=Ta(async d=>{let m=await f.startGoogleLogin({...l,googleCredential:d.credential});await s(m)||r(m)},[f,l,s,r]);return tr(H,{style:{maxWidth:400},onSubmit:u,children:[ie(Zc,{sx:{flexDirection:"column"},children:a}),i&&tr(_P,{children:[ie(Gl,{position:"center",p:"xl",style:{height:70},children:ie(ba,{googleClientId:i,handleGoogleCredential:c})}),!n&&ie(UP,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&ie(WP,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),tr(Gl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[ie("div",{children:t&&ie(_c,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&ie(Kc,{type:"submit",children:"Next"})]})]})}function $P(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=S(),[l,f]=Yc(),i=br(l,void 0),s=Ta(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(c=>f(XP(c)))},[n,a,t]);return tr(H,{style:{maxWidth:400},onSubmit:s,children:[ie(Zc,{sx:{flexDirection:"column"},children:r}),ie(ft,{issues:i}),ie(zP,{spacing:"xl",children:ie(QP,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:Q(l,"password")})}),tr(Gl,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&ie(_c,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),ie(GP,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),ie(Kc,{type:"submit",children:"Sign in"})]})]})}import{Avatar as KP,Center as ZP,Group as YP,Stack as jP,Text as ed,Title as eT,UnstyledButton as oT}from"@mantine/core";import{normalizeOperationOutcome as tT}from"@medplum/core";import{useState as rT}from"react";import{jsx as Eo,jsxs as ka}from"react/jsx-runtime";function od(e){let o=S(),[t,r]=rT();return ka(jP,{children:[ka(ZP,{sx:{flexDirection:"column"},children:[Eo(xo,{size:32}),Eo(eT,{order:3,children:"Choose profile"})]}),Eo(ft,{outcome:t}),e.memberships.map(a=>Eo(oT,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(tT(n)))},children:ka(YP,{children:[Eo(KP,{radius:"xl"}),ka("div",{style:{flex:1},children:[Eo(ed,{size:"sm",weight:500,children:a.profile?.display}),Eo(ed,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as aT,Center as nT,Checkbox as lT,Group as fT,Stack as td,Title as sT}from"@mantine/core";import{jsx as Lo,jsxs as rd}from"react/jsx-runtime";function ad(e){let o=S();return Lo(H,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:rd(td,{children:[rd(nT,{sx:{flexDirection:"column"},children:[Lo(xo,{size:32}),Lo(sT,{children:"Choose scope"})]}),Lo(td,{children:(e.scope??"openid").split(" ").map(t=>Lo(lT,{id:t,name:t,label:t,defaultChecked:!0},t))}),Lo(fT,{position:"right",mt:"xl",children:Lo(aT,{type:"submit",children:"Set scope"})})]})})}import{Alert as iT,Button as uT,Center as cT,Group as dT,Stack as nd,TextInput as mT,Title as pT}from"@mantine/core";import{normalizeErrorString as xT}from"@medplum/core";import{useState as IT}from"react";import{jsx as ro,jsxs as ld}from"react/jsx-runtime";function fd(e){let o=S(),[t,r]=IT();return ro(H,{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(xT(n)))},children:ld(nd,{children:[ld(cT,{sx:{flexDirection:"column"},children:[ro(xo,{size:32}),ro(pT,{children:"Enter MFA code"})]}),t&&ro(iT,{icon:ro(vo,{size:16}),title:"Error",color:"red",children:t}),ro(nd,{children:ro(mT,{name:"token",label:"MFA code",required:!0})}),ro(dT,{position:"right",mt:"xl",children:ro(uT,{type:"submit",children:"Submit code"})})]})})}import{jsx as No}from"react/jsx-runtime";function oQ(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...f}=e,i=S(),[s,u]=Ql(),[c,d]=Ql(!1),[m,p]=Ql(),x=Ul(v=>{l?l(v):i.processCode(v).then(()=>{r&&r()}).catch(b=>sd({color:"red",message:id(b)}))},[i,l,r]),C=Ul(v=>{d(!!v.mfaRequired),v.login&&u(v.login),v.memberships&&p(v.memberships),v.code&&(t?p(void 0):x(v.code))},[t,x]),y=Ul(v=>{x(v.code)},[x]);return gT(()=>{o&&!s&&i.get("auth/login/"+o).then(C).catch(v=>sd({color:"red",message:id(v)}))},[i,o,s,C]),No(Ur,{width:450,children:s?c?No(fd,{login:s,handleAuthResponse:C}):m?No(od,{login:s,memberships:m,handleAuthResponse:C}):e.projectId==="new"?No(Sa,{login:s,handleAuthResponse:C}):e.chooseScopes?No(ad,{login:s,scope:e.scope,handleAuthResponse:y}):No("div",{children:"Success"}):No(jc,{onForgotPassword:a,onRegister:n,handleAuthResponse:C,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...f,children:e.children})})}export{Yl as AddressDisplay,tf as AddressInput,rf as AnnotationInput,wM as AppShell,Qo as AsyncAutocomplete,Mf as AttachmentArrayDisplay,wf as AttachmentArrayInput,Jo as AttachmentButton,Ge as AttachmentDisplay,xr as AttachmentInput,wt as BackboneElementDisplay,Ko as BackboneElementInput,qs as CalendarInput,Cr as CheckboxFormSection,mr as CodeInput,ye as CodeableConceptDisplay,_o as CodeableConceptInput,Nf as CodingDisplay,Rr as CodingInput,Vf as ContactDetailDisplay,Yf as ContactDetailInput,hr as ContactPointDisplay,Pr as ContactPointInput,uo as Container,Ve as DateTimeInput,t2 as DefaultResourceTimeline,Ef as DescriptionList,Lf as DescriptionListEntry,Fn as DiagnosticReportDisplay,Ur as Document,Zg as ElementDefinitionInputSelector,Ar as ElementDefinitionTypeInput,p2 as EncounterTimeline,Go as ErrorBoundary,hS as FhirPathTable,H as Form,pe as FormSection,Pf as Header,ur as HumanNameDisplay,ns as HumanNameInput,Hf as IdentifierDisplay,ss as IdentifierInput,fn as Loading,xo as Logo,vV as MeasureReportDisplay,le as MedplumLink,CT as MedplumProvider,fV as MemoizedFhirPathTable,_N as MemoizedSearchControl,qf as MoneyDisplay,is as MoneyInput,Af as Navbar,Qh as ObservationTable,ft as OperationOutcomeAlert,Yo as Panel,qH as PatientSummary,$H as PatientTimeline,mq as PlanDefinitionBuilder,ae as QuantityDisplay,Ae as QuantityInput,Zq as QuestionnaireBuilder,Tc as QuestionnaireForm,la as QuestionnaireItemType,yr as RangeDisplay,Lt as RangeInput,To as ReferenceDisplay,Zo as ReferenceInput,NG as ReferenceRangeEditor,gR as ReferenceRangeGroupEditor,YU as RegisterForm,JG as RequestGroupDisplay,Wf as ResourceArrayDisplay,Rs as ResourceArrayInput,fe as ResourceAvatar,co as ResourceBadge,s4 as ResourceBlame,x4 as ResourceDiff,P4 as ResourceForm,O4 as ResourceHistoryTable,kr as ResourceInput,Ue as ResourceName,ce as ResourcePropertyDisplay,io as ResourcePropertyInput,zn as ResourceTable,po as ResourceTimeline,X4 as Scheduler,nl as SearchChangeEvent,Do as SearchClickEvent,lS as SearchControl,Wi as SearchFieldEditor,Yi as SearchFilterEditor,ll as SearchLoadEvent,j4 as ServiceRequestTimeline,oQ as SignInForm,fU as SmartAppLaunchLink,Er as StatusBadge,Ii as Timeline,mo as TimelineItem,Fs as TimingInput,Kn as addDateFilterBetween,M2 as addField,ot as addFilter,Ei as addLastMonthFilter,Zn as addMissingFilter,Ni as addNextMonthFilter,Li as addThisMonthFilter,wi as addTodayFilter,Oi as addTomorrowFilter,Vi as addYearToDateFilter,Fi as addYesterdayFilter,we as buildFieldNameString,fc as buildInitialResponse,Cl as buildInitialResponseItem,A2 as clearFilters,Wr as clearFiltersOnField,es as convertIsoToLocal,os as convertLocalToIso,Ca as createScriptTag,Mi as deleteFilter,ic as formatReferenceString,Q as getErrorsForInput,tu as getFieldDefinitions,br as getIssuesForExpression,ac as getNewMultiSelectValues,uc as getNumberOfPages,Xt as getOpString,lc as getQuestionnaireItemReferenceFilter,fa as getQuestionnaireItemReferenceTargetTypes,Qc as getRecaptcha,Ui as getSearchOperators,qi as getSortField,Uc as initRecaptcha,tc as isChoiceQuestion,rc as isQuestionEnabled,Gi as isSortDescending,$w as isSupportedProfileStructureDefinition,Tf as parseForm,$l as reactContext,Qi as renderValue,Wt as setFilters,fv as setOffset,Hi as setPage,Ot as setPropertyValue,sa as setQuestionnaireItemReferenceTargetTypes,Yn as setSort,yi as sortByDateAndPriority,F2 as toggleSort,S as useMedplum,St as useMedplumContext,no as useMedplumNavigate,nr as useMedplumProfile,X as useResource,kT as useSearch,Kl as useSearchOne,Zl as useSearchResources};
|
|
74
74
|
//# sourceMappingURL=index.mjs.map
|