@medplum/react 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +5 -5
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/cjs/index.d.ts +11 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/index.mjs.map +4 -4
- package/package.json +3 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var tc=Object.create;var ml=Object.defineProperty;var rc=Object.getOwnPropertyDescriptor;var ac=Object.getOwnPropertyNames;var nc=Object.getPrototypeOf,lc=Object.prototype.hasOwnProperty;var nt=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var fc=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of ac(o))!lc.call(e,a)&&a!==t&&ml(e,a,{get:()=>o[a],enumerable:!(r=rc(o,a))||r.enumerable});return e};var sc=(e,o,t)=>(t=e!=null?tc(nc(e)):{},fc(o||!e||!e.__esModule?ml(t,"default",{value:e,enumerable:!0}):t,e));var fn=nt(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0});yr.Pointer=void 0;function Eg(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Lg(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Ng=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(Eg);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(Lg).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}();yr.Pointer=Ng});var un=nt(Ve=>{"use strict";Object.defineProperty(Ve,"__esModule",{value:!0});Ve.clone=Ve.objectType=Ve.hasOwnProperty=void 0;Ve.hasOwnProperty=Object.prototype.hasOwnProperty;function Vg(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ve.objectType=Vg;function Hg(e){return e!=null&&typeof e=="object"}function sn(e){if(!Hg(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=sn(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var l in e)Ve.hasOwnProperty.call(e,l)&&(n[l]=sn(e[l]));return n}Ve.clone=sn});var mn=nt(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.diffAny=pe.diffObjects=pe.diffArrays=pe.intersection=pe.subtract=pe.isDestructive=void 0;var Tt=un();function qg(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}pe.isDestructive=qg;function dn(e,o){var t={};for(var r in e)Tt.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Tt.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}pe.subtract=dn;function ys(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Tt.hasOwnProperty.call(a,n)&&a[n]!==void 0&&(t[n]=(t[n]||0)+1)}for(var n in t)t[n]<o&&delete t[n];return Object.keys(t)}pe.intersection=ys;function Gg(e){return e.op==="add"}function Ug(e){return e.op==="remove"}function cn(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function vs(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),S={op:"remove",index:u-1};p.push(cn(x,S))}if(c>0){var y=n(u,c-1),v={op:"add",index:u-1,value:o[c-1]};p.push(cn(y,v))}if(u>0&&c>0){var C=n(u-1,c-1),T={op:"replace",index:u-1,original:e[u-1],value:o[c-1]};p.push(cn(C,T))}var h=p.sort(function(M,Q){return M.cost-Q.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(Gg(c)){var p=c.index+1+m,x=p<l+m?String(p):"-",S={op:c.op,path:t.add(x).toString(),value:c.value};return[d.concat(S),m+1]}else if(Ug(c)){var S={op:c.op,path:t.add(String(c.index+m)).toString()};return[d.concat(S),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}pe.diffArrays=vs;function Ss(e,o,t,r){r===void 0&&(r=vr);var a=[];return dn(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),dn(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),ys([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}pe.diffObjects=Ss;function vr(e,o,t,r){if(r===void 0&&(r=vr),e===o)return[];var a=(0,Tt.objectType)(e),n=(0,Tt.objectType)(o);return a=="array"&&n=="array"?vs(e,o,t,r):a=="object"&&n=="object"?Ss(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}pe.diffAny=vr});var Ms=nt(K=>{"use strict";var pn=K&&K.__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(K,"__esModule",{value:!0});K.apply=K.InvalidOperationError=K.test=K.copy=K.move=K.replace=K.remove=K.add=K.TestError=K.MissingError=void 0;var He=fn(),xn=un(),Qg=mn(),we=function(e){pn(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);K.MissingError=we;var Cs=function(e){pn(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);K.TestError=Cs;function In(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 bs(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function Rs(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new we(o.path):(In(t.parent,t.key,(0,xn.clone)(o.value)),null)}K.add=Rs;function Ps(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new we(o.path):(bs(t.parent,t.key),null)}K.remove=Ps;function Ts(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new we(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new we(o.path)}else if(t.value===void 0)return new we(o.path);return t.parent[t.key]=(0,xn.clone)(o.value),null}K.replace=Ts;function Ds(e,o){var t=He.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new we(o.from);var r=He.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new we(o.path):(bs(t.parent,t.key),In(r.parent,r.key,t.value),null)}K.move=Ds;function ks(e,o){var t=He.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new we(o.from);var r=He.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new we(o.path):(In(r.parent,r.key,(0,xn.clone)(t.value)),null)}K.copy=ks;function Bs(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return(0,Qg.diffAny)(t.value,o.value,new He.Pointer).length?new Cs(t.value,o.value):null}K.test=Bs;var As=function(e){pn(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);K.InvalidOperationError=As;function zg(e,o){switch(o.op){case"add":return Rs(e,o);case"remove":return Ps(e,o);case"replace":return Ts(e,o);case"move":return Ds(e,o);case"copy":return ks(e,o);case"test":return Bs(e,o)}return new As(o)}K.apply=zg});var ws=nt(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});Oe.createTests=Oe.createPatch=Oe.applyPatch=Oe.Pointer=void 0;var gn=fn();Object.defineProperty(Oe,"Pointer",{enumerable:!0,get:function(){return gn.Pointer}});var Wg=Ms(),hn=mn();function Xg(e,o){return o.map(function(t){return(0,Wg.apply)(e,t)})}Oe.applyPatch=Xg;function Jg(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,hn.diffAny)(t,r,a,o)}return o}function $g(e,o,t){var r=new gn.Pointer;return(t?Jg(t):hn.diffAny)(e,o,r)}Oe.createPatch=$g;function Fs(e,o){var t=gn.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function _g(e,o){var t=new Array;return o.filter(hn.isDestructive).forEach(function(r){var a=Fs(e,r.path);if(a&&t.push(a),"from"in r){var n=Fs(e,r.from);n&&t.push(n)}}),t}Oe.createTests=_g});import{useEffect as pl,useMemo as ic,useState as uc}from"react";import{createContext as cc,useContext as dc}from"react";import{jsx as mc}from"react/jsx-runtime";import{deepEquals as xc,isReference as hl,isResource as Ic,normalizeOperationOutcome as gc}from"@medplum/core";import{useCallback as hc,useEffect as xl,useState as yc}from"react";import{allOk as vc,normalizeOperationOutcome as Sc}from"@medplum/core";import{useEffect as Cc,useState as qt}from"react";var gl=cc(void 0);function lt(){return dc(gl)}function R(){return lt().medplum}function Xe(){return lt().navigate}function Gt(){return lt().profile}function Wb(e){let o=e.medplum,t=e.navigate??pc,[r,a]=uc({profile:o.getProfile(),loading:!o.isInitialized});pl(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),pl(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=ic(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return mc(gl.Provider,{value:n,children:e.children})}function pc(e){window.location.assign(e)}function z(e,o){let t=R(),[r,a]=yc(Il(t,e)),n=hc(l=>{xc(l,r)||a(l)},[r,a]);return xl(()=>{n(Il(t,e))},[t,e,n]),xl(()=>{let l=!0;return hl(e)&&t.readReference(e).then(f=>{l&&n(f)}).catch(f=>{l&&(n(void 0),o&&o(gc(f)))}),()=>l=!1},[t,r,e,n,o]),r}function Il(e,o){if(o){if(Ic(o))return o;if(hl(o))return e.getCachedReference(o)}}function Kb(e,o){return la("search",e,o)}function yl(e,o){return la("searchOne",e,o)}function vl(e,o){return la("searchResources",e,o)}function la(e,o,t){let r=R(),[a,n]=qt(),[l,f]=qt(!1),[i,s]=qt(),[u,c]=qt();return Cc(()=>{let d=r.fhirSearchUrl(o,t).toString();d!==a&&(n(d),r[e](o,t).then(m=>{f(!1),s(m),c(vc)}).catch(m=>{f(!1),s(void 0),c(Sc(m))}))},[r,e,o,t,a,s]),[i,l,u]}import{formatAddress as bc}from"@medplum/core";import{Fragment as Rc,jsx as Pc}from"react/jsx-runtime";function Sl(e){let o=e.value;return o?Pc(Rc,{children:bc(o)}):null}import{Group as Tc,NativeSelect as Cl,TextInput as ft}from"@mantine/core";import{useRef as Dc,useState as kc}from"react";import{jsx as no,jsxs as Bc}from"react/jsx-runtime";function bl(e,o){return e.line&&e.line.length>o?e.line[o]:""}function Rl(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function Pl(e){let[o,t]=kc(e.defaultValue||{}),r=Dc();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(Rl(r.current||{},0,d))}function i(d){a(Rl(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 Bc(Tc,{spacing:"xs",grow:!0,noWrap:!0,children:[no(Cl,{"data-testid":"address-use",defaultValue:o.use,onChange:d=>n(d.currentTarget.value),data:["","home","work","temp","old","billing"]}),no(Cl,{"data-testid":"address-type",defaultValue:o.type,onChange:d=>l(d.currentTarget.value),data:["","postal","physical","both"]}),no(ft,{placeholder:"Line 1",defaultValue:bl(o,0),onChange:d=>f(d.currentTarget.value)}),no(ft,{placeholder:"Line 2",defaultValue:bl(o,1),onChange:d=>i(d.currentTarget.value)}),no(ft,{placeholder:"City",defaultValue:o.city,onChange:d=>s(d.currentTarget.value)}),no(ft,{placeholder:"State",defaultValue:o.state,onChange:d=>u(d.currentTarget.value)}),no(ft,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:d=>c(d.currentTarget.value)})]})}import{TextInput as Ac}from"@mantine/core";import{createReference as Mc}from"@medplum/core";import{useRef as Fc,useState as wc}from"react";import{jsx as Oc}from"react/jsx-runtime";function Tl(e){let o=Gt(),[t,r]=wc(e.defaultValue||{}),a=Fc();a.current=t;function n(l){let f=l?{text:l,authorReference:o&&Mc(o),time:new Date().toISOString()}:{};r(f),e.onChange&&e.onChange(f)}return Oc(Ac,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as xm,useMantineTheme as Im}from"@mantine/core";import{showNotification as gm}from"@mantine/notifications";import{Suspense as hm,useEffect as ym,useState as vm}from"react";import{Alert as Gc}from"@mantine/core";import{normalizeErrorString as Uc}from"@medplum/core";import{forwardRef as Ec,createElement as kl}from"react";import lo from"prop-types";var Dl={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 Lc=Object.defineProperty,Nc=Object.defineProperties,Vc=Object.getOwnPropertyDescriptors,Ut=Object.getOwnPropertySymbols,Ml=Object.prototype.hasOwnProperty,Fl=Object.prototype.propertyIsEnumerable,Bl=(e,o,t)=>o in e?Lc(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Al=(e,o)=>{for(var t in o||(o={}))Ml.call(o,t)&&Bl(e,t,o[t]);if(Ut)for(var t of Ut(o))Fl.call(o,t)&&Bl(e,t,o[t]);return e},Hc=(e,o)=>Nc(e,Vc(o)),qc=(e,o)=>{var t={};for(var r in e)Ml.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ut)for(var r of Ut(e))o.indexOf(r)<0&&Fl.call(e,r)&&(t[r]=e[r]);return t},I=(e,o,t)=>{let r=Ec((a,n)=>{var l=a,{color:f="currentColor",size:i=24,stroke:s=2,children:u}=l,c=qc(l,["color","size","stroke","children"]);return kl("svg",Al(Hc(Al({ref:n},Dl),{width:i,height:i,stroke:f,strokeWidth:s,className:`tabler-icon tabler-icon-${e}`}),c),[...t.map(([d,m])=>kl(d,m)),...u||[]])});return r.propTypes={color:lo.string,size:lo.oneOfType([lo.string,lo.number]),stroke:lo.oneOfType([lo.string,lo.number])},r.displayName=`${o}`,r};var fa=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 fo=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 sa=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 ia=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 ua=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 ca=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 da=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 ma=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 pa=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 xa=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 Le=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 st=I("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Ia=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 ga=I("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Je=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 it=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 ha=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 ya=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 va=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 Sa=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 Ca=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 Ro=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 Po=I("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Qt=I("file-alert","IconFileAlert",[["path",{d:"M14 3v4a1 1 0 0 0 1 1h4",key:"svg-0"}],["path",{d:"M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]]);var ba=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 Ra=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 Pa=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 Ta=I("logout","IconLogout",[["path",{d:"M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M9 12h12l-3 -3",key:"svg-1"}],["path",{d:"M18 15l3 -3",key:"svg-2"}]]);var zt=I("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Wt=I("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var Da=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 Ba=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 Aa=I("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var Ma=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 Fa=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 To=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 ut=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 ct=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 wa=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 Oa=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 Ea=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 La=I("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Qc}from"react";import{jsx as wl}from"react/jsx-runtime";var Do=class extends Qc{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?wl(Gc,{icon:wl(fo,{size:16}),title:"Something went wrong",color:"red",children:Uc(this.state.error)}):this.props.children}};import{Center as zc,Loader as Wc}from"@mantine/core";import{jsx as Ol}from"react/jsx-runtime";function Na(){return Ol(zc,{style:{width:"100%",height:"100vh"},children:Ol(Wc,{})})}import{Avatar as Pd,createStyles as Td,Group as $t,Header as Dd,Menu as Ne,Stack as kd,Text as pt,UnstyledButton as Wl}from"@mantine/core";import{formatHumanName as Bd,getReferenceString as Xl}from"@medplum/core";import{useState as Ad}from"react";import{formatHumanName as Xc}from"@medplum/core";import{Fragment as Jc,jsx as $c}from"react/jsx-runtime";function Xt(e){let o=e.value;return o?$c(Jc,{children:Xc(o,e.options)}):null}import{Avatar as Ll}from"@mantine/core";import{getDisplayString as rd,getImageSrc as ad}from"@medplum/core";import{Anchor as _c}from"@mantine/core";import{isReference as Kc,isResource as Zc}from"@medplum/core";function E(e){e.preventDefault(),e.stopPropagation()}function Jt(e){if(El(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&El(o[0]))return!0}return!1}function El(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as td}from"react/jsx-runtime";function te(e){let o=Xe(),{to:t,suffix:r,label:a,onClick:n,children:l,...f}=e,i=Yc(t);return r&&(i+="/"+r),td(_c,{href:i,"aria-label":a,onClick:s=>{E(s),n?n(s):t&&o(i)},...f,children:l})}function Yc(e){if(e){if(typeof e=="string")return jc(e);if(Zc(e))return ed(e);if(Kc(e))return od(e)}return"#"}function jc(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function ed(e){return`/${e.resourceType}/${e.id}`}function od(e){return`/${e.reference}`}import{jsx as Va}from"react/jsx-runtime";function se(e){let o=z(e.value),t=o?rd(o):e.alt??"",r=(o&&ad(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?Va(te,{to:o,children:Va(Ll,{src:r,alt:t,radius:a,...n})}):Va(Ll,{src:r,alt:t,radius:a,...n})}import{createStyles as cd,Group as dd,Text as Vl}from"@mantine/core";import{formatHumanName as md,getDisplayString as Ql,getReferenceString as pd,isUUID as xd}from"@medplum/core";import{forwardRef as Id,useCallback as Hl}from"react";import{Loader as nd,MultiSelect as ld}from"@mantine/core";import{showNotification as fd}from"@mantine/notifications";import{normalizeErrorString as sd}from"@medplum/core";import{useCallback as ko,useEffect as id,useRef as io,useState as mt}from"react";import{jsx as Nl}from"react/jsx-runtime";function Bo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:f,...i}=e,s=ud(o),u=io(null),[c,d]=mt(),[m,p]=mt(),[x,S]=mt(),[y,v]=mt(s.map(r)),[C,T]=mt([]),h=io(),M=io(),Q=io();Q.current=c;let Z=io();Z.current=m;let tt=io();tt.current=x;let ye=io();ye.current=C;let ve=ko(()=>{d(void 0);let Y=u.current?.value.trim()||"";if(Y===M.current&&a===h.current)return;M.current=Y,h.current=a;let oe=new AbortController;p(oe),a(Y,oe.signal).then(ne=>{oe.signal.aborted||(T(ne.map(r)),p(void 0),tt.current&&(ne.length>0&&n(ne.slice(0,1)),S(!1)))}).catch(ne=>{oe.signal.aborted||ne.message.includes("aborted")||fd({color:"red",message:sd(ne)})})},[a,n,r]),b=ko(()=>{Z.current&&(Z.current.abort(),p(void 0)),Q.current!==void 0&&window.clearTimeout(Q.current);let Y=window.setTimeout(()=>ve(),100);d(Y)},[ve]),L=ko(Y=>{let oe=[],ne=[];for(let rt of Y){let Ht=ye.current?.find(oc=>oc.value===rt),at=Ht?.resource;!at&&f!==!1&&l&&(at=l(rt),Ht=r(at)),at&&oe.push(at),Ht&&ne.push(Ht)}n(oe),v(ne)},[f,n,l,r]),We=ko(Y=>{Y.key==="Enter"&&(!Q.current&&!Z.current?(E(Y),ye.current&&ye.current.length>0&&(T(ye.current.slice(0,1)),L([ye.current[0].value]))):S(!0))},[L]),P=ko(Y=>{let oe=r(l(Y));return T([...ye.current,oe]),oe},[l,T,r]),H=ko((Y,oe)=>!oe,[]);return id(()=>()=>{Z.current&&Z.current.abort()},[]),Nl(ld,{...i,ref:u,defaultValue:s.map(t),searchable:!0,onKeyDown:We,onSearchChange:b,data:[...y,...C],onFocus:ve,onChange:L,onCreate:P,rightSectionWidth:40,rightSection:m?Nl(nd,{size:16}):null,filter:H,creatable:!0,withinPortal:!0})}function ud(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Ao,jsxs as Ul}from"react/jsx-runtime";var gd=cd(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function hd(e){return e.id}function yd(e){return{value:e.id,label:Ql(e),resource:e}}function zl(e){let{classes:o}=gd(),t=Xe(),r=R(),a=Hl(async(l,f)=>{let i=Sd(l),s={signal:f},u=await r.graphql(i,void 0,void 0,s);return Cd(u,l)},[r]),n=Hl(l=>{l.length>0&&t(`/${pd(l[0])}`)},[t]);return Ao(Bo,{size:"sm",radius:"md",className:o.searchInput,icon:Ao(Fa,{size:16}),placeholder:"Search",itemComponent:vd,toKey:hd,toOption:yd,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var vd=Id(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Ao("div",{ref:t,...o,children:Ul(dd,{noWrap:!0,children:[Ao(se,{value:e}),Ul("div",{children:[Ao(Vl,{children:Ql(e)}),Ao(Vl,{size:"xs",color:"dimmed",children:r})]})]})})});function Sd(e){let o=JSON.stringify(e);return xd(e)?`{
|
|
1
|
+
var tc=Object.create;var ml=Object.defineProperty;var rc=Object.getOwnPropertyDescriptor;var ac=Object.getOwnPropertyNames;var nc=Object.getPrototypeOf,lc=Object.prototype.hasOwnProperty;var nt=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var fc=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of ac(o))!lc.call(e,a)&&a!==t&&ml(e,a,{get:()=>o[a],enumerable:!(r=rc(o,a))||r.enumerable});return e};var sc=(e,o,t)=>(t=e!=null?tc(nc(e)):{},fc(o||!e||!e.__esModule?ml(t,"default",{value:e,enumerable:!0}):t,e));var fn=nt(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0});yr.Pointer=void 0;function Eg(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Lg(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Ng=function(){function e(o){o===void 0&&(o=[""]),this.tokens=o}return e.fromJSON=function(o){var t=o.split("/").map(Eg);if(t[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(o));return new e(t)},e.prototype.toString=function(){return this.tokens.map(Lg).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}();yr.Pointer=Ng});var un=nt(Ve=>{"use strict";Object.defineProperty(Ve,"__esModule",{value:!0});Ve.clone=Ve.objectType=Ve.hasOwnProperty=void 0;Ve.hasOwnProperty=Object.prototype.hasOwnProperty;function Vg(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ve.objectType=Vg;function Hg(e){return e!=null&&typeof e=="object"}function sn(e){if(!Hg(e))return e;if(e.constructor==Array){for(var o=e.length,t=new Array(o),r=0;r<o;r++)t[r]=sn(e[r]);return t}if(e.constructor==Date){var a=new Date(+e);return a}var n={};for(var l in e)Ve.hasOwnProperty.call(e,l)&&(n[l]=sn(e[l]));return n}Ve.clone=sn});var mn=nt(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.diffAny=pe.diffObjects=pe.diffArrays=pe.intersection=pe.subtract=pe.isDestructive=void 0;var Tt=un();function qg(e){var o=e.op;return o==="remove"||o==="replace"||o==="copy"||o==="move"}pe.isDestructive=qg;function dn(e,o){var t={};for(var r in e)Tt.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(t[r]=1);for(var a in o)Tt.hasOwnProperty.call(o,a)&&o[a]!==void 0&&delete t[a];return Object.keys(t)}pe.subtract=dn;function ys(e){for(var o=e.length,t={},r=0;r<o;r++){var a=e[r];for(var n in a)Tt.hasOwnProperty.call(a,n)&&a[n]!==void 0&&(t[n]=(t[n]||0)+1)}for(var n in t)t[n]<o&&delete t[n];return Object.keys(t)}pe.intersection=ys;function Gg(e){return e.op==="add"}function Ug(e){return e.op==="remove"}function cn(e,o){return{operations:e.operations.concat(o),cost:e.cost+1}}function vs(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),S={op:"remove",index:u-1};p.push(cn(x,S))}if(c>0){var y=n(u,c-1),v={op:"add",index:u-1,value:o[c-1]};p.push(cn(y,v))}if(u>0&&c>0){var C=n(u-1,c-1),T={op:"replace",index:u-1,original:e[u-1],value:o[c-1]};p.push(cn(C,T))}var h=p.sort(function(M,Q){return M.cost-Q.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(Gg(c)){var p=c.index+1+m,x=p<l+m?String(p):"-",S={op:c.op,path:t.add(x).toString(),value:c.value};return[d.concat(S),m+1]}else if(Ug(c)){var S={op:c.op,path:t.add(String(c.index+m)).toString()};return[d.concat(S),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}pe.diffArrays=vs;function Ss(e,o,t,r){r===void 0&&(r=vr);var a=[];return dn(e,o).forEach(function(n){a.push({op:"remove",path:t.add(n).toString()})}),dn(o,e).forEach(function(n){a.push({op:"add",path:t.add(n).toString(),value:o[n]})}),ys([e,o]).forEach(function(n){a.push.apply(a,r(e[n],o[n],t.add(n)))}),a}pe.diffObjects=Ss;function vr(e,o,t,r){if(r===void 0&&(r=vr),e===o)return[];var a=(0,Tt.objectType)(e),n=(0,Tt.objectType)(o);return a=="array"&&n=="array"?vs(e,o,t,r):a=="object"&&n=="object"?Ss(e,o,t,r):[{op:"replace",path:t.toString(),value:o}]}pe.diffAny=vr});var Ms=nt(K=>{"use strict";var pn=K&&K.__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(K,"__esModule",{value:!0});K.apply=K.InvalidOperationError=K.test=K.copy=K.move=K.replace=K.remove=K.add=K.TestError=K.MissingError=void 0;var He=fn(),xn=un(),Qg=mn(),we=function(e){pn(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);K.MissingError=we;var Cs=function(e){pn(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);K.TestError=Cs;function In(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 bs(e,o){if(Array.isArray(e)){var t=parseInt(o,10);e.splice(t,1)}else delete e[o]}function Rs(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return t.parent===void 0?new we(o.path):(In(t.parent,t.key,(0,xn.clone)(o.value)),null)}K.add=Rs;function Ps(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return t.value===void 0?new we(o.path):(bs(t.parent,t.key),null)}K.remove=Ps;function Ts(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);if(t.parent===null)return new we(o.path);if(Array.isArray(t.parent)){if(parseInt(t.key,10)>=t.parent.length)return new we(o.path)}else if(t.value===void 0)return new we(o.path);return t.parent[t.key]=(0,xn.clone)(o.value),null}K.replace=Ts;function Ds(e,o){var t=He.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new we(o.from);var r=He.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new we(o.path):(bs(t.parent,t.key),In(r.parent,r.key,t.value),null)}K.move=Ds;function ks(e,o){var t=He.Pointer.fromJSON(o.from).evaluate(e);if(t.value===void 0)return new we(o.from);var r=He.Pointer.fromJSON(o.path).evaluate(e);return r.parent===void 0?new we(o.path):(In(r.parent,r.key,(0,xn.clone)(t.value)),null)}K.copy=ks;function Bs(e,o){var t=He.Pointer.fromJSON(o.path).evaluate(e);return(0,Qg.diffAny)(t.value,o.value,new He.Pointer).length?new Cs(t.value,o.value):null}K.test=Bs;var As=function(e){pn(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);K.InvalidOperationError=As;function zg(e,o){switch(o.op){case"add":return Rs(e,o);case"remove":return Ps(e,o);case"replace":return Ts(e,o);case"move":return Ds(e,o);case"copy":return ks(e,o);case"test":return Bs(e,o)}return new As(o)}K.apply=zg});var ws=nt(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});Oe.createTests=Oe.createPatch=Oe.applyPatch=Oe.Pointer=void 0;var gn=fn();Object.defineProperty(Oe,"Pointer",{enumerable:!0,get:function(){return gn.Pointer}});var Wg=Ms(),hn=mn();function Xg(e,o){return o.map(function(t){return(0,Wg.apply)(e,t)})}Oe.applyPatch=Xg;function Jg(e){function o(t,r,a){var n=e(t,r,a);return Array.isArray(n)?n:(0,hn.diffAny)(t,r,a,o)}return o}function $g(e,o,t){var r=new gn.Pointer;return(t?Jg(t):hn.diffAny)(e,o,r)}Oe.createPatch=$g;function Fs(e,o){var t=gn.Pointer.fromJSON(o).evaluate(e);if(t!==void 0)return{op:"test",path:o,value:t.value}}function _g(e,o){var t=new Array;return o.filter(hn.isDestructive).forEach(function(r){var a=Fs(e,r.path);if(a&&t.push(a),"from"in r){var n=Fs(e,r.from);n&&t.push(n)}}),t}Oe.createTests=_g});import{useEffect as pl,useMemo as ic,useState as uc}from"react";import{createContext as cc,useContext as dc}from"react";import{jsx as mc}from"react/jsx-runtime";import{deepEquals as xc,isReference as hl,isResource as Ic,normalizeOperationOutcome as gc}from"@medplum/core";import{useCallback as hc,useEffect as xl,useState as yc}from"react";import{allOk as vc,normalizeOperationOutcome as Sc}from"@medplum/core";import{useEffect as Cc,useState as qt}from"react";var gl=cc(void 0);function lt(){return dc(gl)}function R(){return lt().medplum}function Xe(){return lt().navigate}function Gt(){return lt().profile}function _b(e){let o=e.medplum,t=e.navigate??pc,[r,a]=uc({profile:o.getProfile(),loading:!o.isInitialized});pl(()=>{o&&(o.isInitialized||(a(l=>({...l,loading:!0})),o.getInitPromise().then(()=>a(l=>({...l,loading:!1}))).catch(console.error)))},[o,o.isInitialized]),pl(()=>{function l(){a({...r,profile:o.getProfile()})}return o.addEventListener("change",l),()=>o.removeEventListener("change",l)},[o,r]);let n=ic(()=>({...r,medplum:o,navigate:t}),[r,o,t]);return mc(gl.Provider,{value:n,children:e.children})}function pc(e){window.location.assign(e)}function z(e,o){let t=R(),[r,a]=yc(Il(t,e)),n=hc(l=>{xc(l,r)||a(l)},[r,a]);return xl(()=>{n(Il(t,e))},[t,e,n]),xl(()=>{let l=!0;return hl(e)&&t.readReference(e).then(f=>{l&&n(f)}).catch(f=>{l&&(n(void 0),o&&o(gc(f)))}),()=>l=!1},[t,r,e,n,o]),r}function Il(e,o){if(o){if(Ic(o))return o;if(hl(o))return e.getCachedReference(o)}}function eR(e,o){return la("search",e,o)}function yl(e,o){return la("searchOne",e,o)}function vl(e,o){return la("searchResources",e,o)}function la(e,o,t){let r=R(),[a,n]=qt(),[l,f]=qt(!1),[i,s]=qt(),[u,c]=qt();return Cc(()=>{let d=r.fhirSearchUrl(o,t).toString();d!==a&&(n(d),r[e](o,t).then(m=>{f(!1),s(m),c(vc)}).catch(m=>{f(!1),s(void 0),c(Sc(m))}))},[r,e,o,t,a,s]),[i,l,u]}import{formatAddress as bc}from"@medplum/core";import{Fragment as Rc,jsx as Pc}from"react/jsx-runtime";function Sl(e){let o=e.value;return o?Pc(Rc,{children:bc(o)}):null}import{Group as Tc,NativeSelect as Cl,TextInput as ft}from"@mantine/core";import{useRef as Dc,useState as kc}from"react";import{jsx as no,jsxs as Bc}from"react/jsx-runtime";function bl(e,o){return e.line&&e.line.length>o?e.line[o]:""}function Rl(e,o,t){let r=e.line||[];for(;r.length<=o;)r.push("");return r[o]=t,{...e,line:r}}function Pl(e){let[o,t]=kc(e.defaultValue||{}),r=Dc();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(Rl(r.current||{},0,d))}function i(d){a(Rl(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 Bc(Tc,{spacing:"xs",grow:!0,noWrap:!0,children:[no(Cl,{"data-testid":"address-use",defaultValue:o.use,onChange:d=>n(d.currentTarget.value),data:["","home","work","temp","old","billing"]}),no(Cl,{"data-testid":"address-type",defaultValue:o.type,onChange:d=>l(d.currentTarget.value),data:["","postal","physical","both"]}),no(ft,{placeholder:"Line 1",defaultValue:bl(o,0),onChange:d=>f(d.currentTarget.value)}),no(ft,{placeholder:"Line 2",defaultValue:bl(o,1),onChange:d=>i(d.currentTarget.value)}),no(ft,{placeholder:"City",defaultValue:o.city,onChange:d=>s(d.currentTarget.value)}),no(ft,{placeholder:"State",defaultValue:o.state,onChange:d=>u(d.currentTarget.value)}),no(ft,{placeholder:"Postal Code",defaultValue:o.postalCode,onChange:d=>c(d.currentTarget.value)})]})}import{TextInput as Ac}from"@mantine/core";import{createReference as Mc}from"@medplum/core";import{useRef as Fc,useState as wc}from"react";import{jsx as Oc}from"react/jsx-runtime";function Tl(e){let o=Gt(),[t,r]=wc(e.defaultValue||{}),a=Fc();a.current=t;function n(l){let f=l?{text:l,authorReference:o&&Mc(o),time:new Date().toISOString()}:{};r(f),e.onChange&&e.onChange(f)}return Oc(Ac,{name:e.name,placeholder:"Annotation text",defaultValue:t.text,onChange:l=>n(l.currentTarget.value)})}import{AppShell as xm,useMantineTheme as Im}from"@mantine/core";import{showNotification as gm}from"@mantine/notifications";import{Suspense as hm,useEffect as ym,useState as vm}from"react";import{Alert as Gc}from"@mantine/core";import{normalizeErrorString as Uc}from"@medplum/core";import{forwardRef as Ec,createElement as kl}from"react";import lo from"prop-types";var Dl={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 Lc=Object.defineProperty,Nc=Object.defineProperties,Vc=Object.getOwnPropertyDescriptors,Ut=Object.getOwnPropertySymbols,Ml=Object.prototype.hasOwnProperty,Fl=Object.prototype.propertyIsEnumerable,Bl=(e,o,t)=>o in e?Lc(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,Al=(e,o)=>{for(var t in o||(o={}))Ml.call(o,t)&&Bl(e,t,o[t]);if(Ut)for(var t of Ut(o))Fl.call(o,t)&&Bl(e,t,o[t]);return e},Hc=(e,o)=>Nc(e,Vc(o)),qc=(e,o)=>{var t={};for(var r in e)Ml.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ut)for(var r of Ut(e))o.indexOf(r)<0&&Fl.call(e,r)&&(t[r]=e[r]);return t},I=(e,o,t)=>{let r=Ec((a,n)=>{var l=a,{color:f="currentColor",size:i=24,stroke:s=2,children:u}=l,c=qc(l,["color","size","stroke","children"]);return kl("svg",Al(Hc(Al({ref:n},Dl),{width:i,height:i,stroke:f,strokeWidth:s,className:`tabler-icon tabler-icon-${e}`}),c),[...t.map(([d,m])=>kl(d,m)),...u||[]])});return r.propTypes={color:lo.string,size:lo.oneOfType([lo.string,lo.number]),stroke:lo.oneOfType([lo.string,lo.number])},r.displayName=`${o}`,r};var fa=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 fo=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 sa=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 ia=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 ua=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 ca=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 da=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 ma=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 pa=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 xa=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 Le=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 st=I("check","IconCheck",[["path",{d:"M5 12l5 5l10 -10",key:"svg-0"}]]);var Ia=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 ga=I("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]);var Je=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 it=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 ha=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 ya=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 va=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 Sa=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 Ca=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 Ro=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 Po=I("equal","IconEqual",[["path",{d:"M5 10h14",key:"svg-0"}],["path",{d:"M5 14h14",key:"svg-1"}]]);var Qt=I("file-alert","IconFileAlert",[["path",{d:"M14 3v4a1 1 0 0 0 1 1h4",key:"svg-0"}],["path",{d:"M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z",key:"svg-1"}],["path",{d:"M12 17l.01 0",key:"svg-2"}],["path",{d:"M12 11l0 3",key:"svg-3"}]]);var ba=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 Ra=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 Pa=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 Ta=I("logout","IconLogout",[["path",{d:"M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M9 12h12l-3 -3",key:"svg-1"}],["path",{d:"M18 15l3 -3",key:"svg-2"}]]);var zt=I("math-greater","IconMathGreater",[["path",{d:"M5 18l14 -6l-14 -6",key:"svg-0"}]]);var Wt=I("math-lower","IconMathLower",[["path",{d:"M19 18l-14 -6l14 -6",key:"svg-0"}]]);var Da=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 Ba=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 Aa=I("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);var Ma=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 Fa=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 To=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 ut=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 ct=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 wa=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 Oa=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 Ea=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 La=I("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);import{Component as Qc}from"react";import{jsx as wl}from"react/jsx-runtime";var Do=class extends Qc{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?wl(Gc,{icon:wl(fo,{size:16}),title:"Something went wrong",color:"red",children:Uc(this.state.error)}):this.props.children}};import{Center as zc,Loader as Wc}from"@mantine/core";import{jsx as Ol}from"react/jsx-runtime";function Na(){return Ol(zc,{style:{width:"100%",height:"100vh"},children:Ol(Wc,{})})}import{Avatar as Pd,createStyles as Td,Group as $t,Header as Dd,Menu as Ne,Stack as kd,Text as pt,UnstyledButton as Wl}from"@mantine/core";import{formatHumanName as Bd,getReferenceString as Xl}from"@medplum/core";import{useState as Ad}from"react";import{formatHumanName as Xc}from"@medplum/core";import{Fragment as Jc,jsx as $c}from"react/jsx-runtime";function Xt(e){let o=e.value;return o?$c(Jc,{children:Xc(o,e.options)}):null}import{Avatar as Ll}from"@mantine/core";import{getDisplayString as rd,getImageSrc as ad}from"@medplum/core";import{Anchor as _c}from"@mantine/core";import{isReference as Kc,isResource as Zc}from"@medplum/core";function E(e){e.preventDefault(),e.stopPropagation()}function Jt(e){if(El(e))return!0;if(e instanceof HTMLTableCellElement){let o=e.children;if(o.length===1&&El(o[0]))return!0}return!1}function El(e){return e instanceof HTMLInputElement&&e.type==="checkbox"}import{jsx as td}from"react/jsx-runtime";function te(e){let o=Xe(),{to:t,suffix:r,label:a,onClick:n,children:l,...f}=e,i=Yc(t);return r&&(i+="/"+r),td(_c,{href:i,"aria-label":a,onClick:s=>{E(s),n?n(s):t&&o(i)},...f,children:l})}function Yc(e){if(e){if(typeof e=="string")return jc(e);if(Zc(e))return ed(e);if(Kc(e))return od(e)}return"#"}function jc(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?e:"/"+e}function ed(e){return`/${e.resourceType}/${e.id}`}function od(e){return`/${e.reference}`}import{jsx as Va}from"react/jsx-runtime";function se(e){let o=z(e.value),t=o?rd(o):e.alt??"",r=(o&&ad(o))??e.src,a=e.radius??"xl",n={...e};return delete n.value,delete n.link,e.link?Va(te,{to:o,children:Va(Ll,{src:r,alt:t,radius:a,...n})}):Va(Ll,{src:r,alt:t,radius:a,...n})}import{createStyles as cd,Group as dd,Text as Vl}from"@mantine/core";import{formatHumanName as md,getDisplayString as Ql,getReferenceString as pd,isUUID as xd}from"@medplum/core";import{forwardRef as Id,useCallback as Hl}from"react";import{Loader as nd,MultiSelect as ld}from"@mantine/core";import{showNotification as fd}from"@mantine/notifications";import{normalizeErrorString as sd}from"@medplum/core";import{useCallback as ko,useEffect as id,useRef as io,useState as mt}from"react";import{jsx as Nl}from"react/jsx-runtime";function Bo(e){let{defaultValue:o,toKey:t,toOption:r,loadOptions:a,onChange:n,onCreate:l,creatable:f,...i}=e,s=ud(o),u=io(null),[c,d]=mt(),[m,p]=mt(),[x,S]=mt(),[y,v]=mt(s.map(r)),[C,T]=mt([]),h=io(),M=io(),Q=io();Q.current=c;let Z=io();Z.current=m;let tt=io();tt.current=x;let ye=io();ye.current=C;let ve=ko(()=>{d(void 0);let Y=u.current?.value.trim()||"";if(Y===M.current&&a===h.current)return;M.current=Y,h.current=a;let oe=new AbortController;p(oe),a(Y,oe.signal).then(ne=>{oe.signal.aborted||(T(ne.map(r)),p(void 0),tt.current&&(ne.length>0&&n(ne.slice(0,1)),S(!1)))}).catch(ne=>{oe.signal.aborted||ne.message.includes("aborted")||fd({color:"red",message:sd(ne)})})},[a,n,r]),b=ko(()=>{Z.current&&(Z.current.abort(),p(void 0)),Q.current!==void 0&&window.clearTimeout(Q.current);let Y=window.setTimeout(()=>ve(),100);d(Y)},[ve]),L=ko(Y=>{let oe=[],ne=[];for(let rt of Y){let Ht=ye.current?.find(oc=>oc.value===rt),at=Ht?.resource;!at&&f!==!1&&l&&(at=l(rt),Ht=r(at)),at&&oe.push(at),Ht&&ne.push(Ht)}n(oe),v(ne)},[f,n,l,r]),We=ko(Y=>{Y.key==="Enter"&&(!Q.current&&!Z.current?(E(Y),ye.current&&ye.current.length>0&&(T(ye.current.slice(0,1)),L([ye.current[0].value]))):S(!0))},[L]),P=ko(Y=>{let oe=r(l(Y));return T([...ye.current,oe]),oe},[l,T,r]),H=ko((Y,oe)=>!oe,[]);return id(()=>()=>{Z.current&&Z.current.abort()},[]),Nl(ld,{...i,ref:u,defaultValue:s.map(t),searchable:!0,onKeyDown:We,onSearchChange:b,data:[...y,...C],onFocus:ve,onChange:L,onCreate:P,rightSectionWidth:40,rightSection:m?Nl(nd,{size:16}):null,filter:H,creatable:!0,withinPortal:!0})}function ud(e){return e?Array.isArray(e)?e:[e]:[]}import{jsx as Ao,jsxs as Ul}from"react/jsx-runtime";var gd=cd(()=>({searchInput:{input:{width:220,transition:"width 0.2s"},"input:focus":{width:400},"@media (max-width: 800px)":{input:{width:150},"input:focus":{width:150}}}}));function hd(e){return e.id}function yd(e){return{value:e.id,label:Ql(e),resource:e}}function zl(e){let{classes:o}=gd(),t=Xe(),r=R(),a=Hl(async(l,f)=>{let i=Sd(l),s={signal:f},u=await r.graphql(i,void 0,void 0,s);return Cd(u,l)},[r]),n=Hl(l=>{l.length>0&&t(`/${pd(l[0])}`)},[t]);return Ao(Bo,{size:"sm",radius:"md",className:o.searchInput,icon:Ao(Fa,{size:16}),placeholder:"Search",itemComponent:vd,toKey:hd,toOption:yd,onChange:n,loadOptions:a,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1},`${e.pathname}?${e.searchParams}`)}var vd=Id(({resource:e,...o},t)=>{let r;return e.resourceType==="Patient"?r=e.birthDate:e.resourceType==="ServiceRequest"&&(r=e.subject?.display),Ao("div",{ref:t,...o,children:Ul(dd,{noWrap:!0,children:[Ao(se,{value:e}),Ul("div",{children:[Ao(Vl,{children:Ql(e)}),Ao(Vl,{size:"xs",color:"dimmed",children:r})]})]})})});function Sd(e){let o=JSON.stringify(e);return xd(e)?`{
|
|
2
2
|
Patients1: PatientList(_id: ${o}, _count: 1) {
|
|
3
3
|
resourceType
|
|
4
4
|
id
|
|
@@ -61,14 +61,14 @@ var tc=Object.create;var ml=Object.defineProperty;var rc=Object.getOwnPropertyDe
|
|
|
61
61
|
display
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
}`.replace(/\s+/g," ")}function Cd(e,o){let t=[];return e.data.Patients1&&t.push(...e.data.Patients1),e.data.Patients2&&t.push(...e.data.Patients2),e.data.ServiceRequestList&&t.push(...e.data.ServiceRequestList),Rd(bd(t),o).slice(0,5)}function bd(e){let o=new Set,t=[];for(let r of e)o.has(r.id)||(o.add(r.id),t.push(r));return t}function Rd(e,o){return e.sort((t,r)=>ql(r,o)-ql(t,o))}function ql(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,Gl(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,Gl(md(r),o));return t}function Gl(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as _,jsxs as $e}from"react/jsx-runtime";var Md=Td(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 Jl(e){let o=lt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:f}=Md(),[i,s]=Ad(!1);return _(Dd,{height:60,p:8,style:{zIndex:101},children:$e($t,{position:"apart",children:[$e($t,{spacing:"xs",children:[_(Wl,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&_(zl,{pathname:e.pathname,searchParams:e.searchParams})]}),$e(Ne,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:i,onClose:()=>s(!1),children:[_(Ne.Target,{children:_(Wl,{className:f(l.user,{[l.userActive]:i}),onClick:()=>s(u=>!u),children:$e($t,{spacing:7,children:[_(se,{value:r,radius:"xl",size:24}),_(pt,{size:"sm",className:l.userName,children:Bd(r?.name?.[0])}),_(ga,{size:12,stroke:1.5})]})})}),$e(Ne.Dropdown,{children:[$e(kd,{align:"center",p:"xl",children:[_(se,{size:"xl",radius:100,value:o.profile}),_(Xt,{value:o.profile?.name?.[0]}),_(pt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&_(Ne.Divider,{}),n.map(u=>u.profile.reference!==Xl(o.profile)&&_(Ne.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:$e($t,{children:[_(Pd,{radius:"xl"}),$e("div",{style:{flex:1},children:[_(pt,{size:"sm",weight:500,children:u.profile.display}),_(pt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),_(Ne.Divider,{}),_(Ne.Item,{icon:_(Oa,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),_(Ne.Item,{icon:_(To,{size:14,stroke:1.5}),onClick:()=>a(`/${Xl(r)}`),children:"Account settings"}),_(Ne.Item,{icon:_(Ta,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),_(pt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as rm,createStyles as am,Navbar as qa,ScrollArea as nm,Space as lm,Text as fm}from"@mantine/core";import{Fragment as sm,useState as im}from"react";import{Button as Ed,Group as Ld,Modal as Nd,NativeSelect as Vd,Stack as Hd,TextInput as qd}from"@mantine/core";import{showNotification as _l}from"@mantine/notifications";import{deepClone as Gd,normalizeErrorString as Ud}from"@medplum/core";function $l(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Fd(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&wd(o,t);return o}function Fd(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function wd(e,o){e[o.name]=o.value}import{jsx as Od}from"react/jsx-runtime";function J(e){return Od("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=$l(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as uo,jsxs as zd}from"react/jsx-runtime";function Kl(e){let o=R(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,f=`${e.pathname}?${e.searchParams.toString()}`,i=Gd(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"}),_l({color:"green",message:"Success"}),e.onOk()}).catch(u=>{_l({color:"red",message:Ud(u)})})}return uo(Nd,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:uo(J,{onSubmit:r,children:zd(Hd,{children:[uo(Qd,{config:t}),uo(qd,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),uo(Ld,{position:"right",children:uo(Ed,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Qd(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return uo(Vd,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as em,useState as om}from"react";import{useState as Kd}from"react";import{useCallback as Wd}from"react";import{jsx as _d}from"react/jsx-runtime";function Ha(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Xd(e){return typeof e.display=="string"?e.display:Ha(e)}function Jd(e){return{value:Ha(e),label:Xd(e),resource:e}}function $d(e){return{code:e,display:e}}function Mo(e){let o=R(),{binding:t,creatable:r,clearable:a,...n}=e,l=Wd(async(f,i)=>{if(!t)return[];let u=(await o.searchValueSet(t,f,{signal:i})).expansion?.contains,c=[];for(let d of u)d.code&&!c.some(m=>m.code===d.code)&&c.push(d);return c},[o,t]);return _d(Bo,{...n,creatable:r??!0,clearable:a??!0,toKey:Ha,toOption:Jd,loadOptions:l,onCreate:$d,getCreateLabel:r===!1?void 0:f=>`+ Create ${f}`})}import{jsx as jd}from"react/jsx-runtime";function _t(e){let[o,t]=Kd(e.defaultValue);function r(a){let n=a[0],l=Yd(n);t(l),e.onChange&&e.onChange(l)}return jd(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Zd(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Zd(e){return e?{code:e}:void 0}function Yd(e){return e?.code}import{jsx as tm}from"react/jsx-runtime";function Fo(e){let[o,t]=om(e.defaultValue),r=e.onChange,a=em(n=>{t(n),r&&r(n)},[r]);return tm(_t,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as pm,jsx as De,jsxs as xt}from"react/jsx-runtime";var Zl=am(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 Yl(e){let{classes:o}=Zl(),t=Xe(),r=dm(e.pathname,e.searchParams,e.menus),[a,n]=im(!1);function l(i,s){i.stopPropagation(),i.preventDefault(),t(s),window.innerWidth<768&&e.closeNavbar()}function f(i){i&&t(`/${i}`)}return xt(pm,{children:[De(qa,{width:{sm:250},p:"xs",children:xt(nm,{children:[!e.resourceTypeSearchDisabled&&De(qa.Section,{mb:"sm",children:De(Fo,{name:"resourceType",placeholder:"Resource Type",onChange:i=>f(i)},window.location.pathname)}),xt(qa.Section,{grow:!0,children:[e.menus?.map(i=>xt(sm,{children:[De(fm,{className:o.menuTitle,children:i.title}),i.links?.map(s=>xt(um,{to:s.href,active:s.href===r?.href,onClick:u=>l(u,s.href),children:[De(cm,{to:s.href,icon:s.icon}),De("span",{children:s.label})]},s.href))]},`menu-${i.title}`)),e.displayAddBookmark&&De(rm,{variant:"subtle",size:"xs",mt:"xl",leftIcon:De(Aa,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&De(Kl,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function um(e){let{classes:o,cx:t}=Zl();return De(te,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function cm(e){return e.icon?e.icon:De(lm,{w:30})}function dm(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=mm(e,o,l.href);f>a&&(a=f,r=l)}return r}function mm(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 co}from"react/jsx-runtime";function Xk(e){let o=Im(),[t,r]=vm(localStorage.navbarOpen==="true"),a=R(),n=Gt();ym(()=>{function s(){gm({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()?co(Na,{}):co(xm,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&co(Jl,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:i}),navbar:n&&t?co(Yl,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:co(Do,{children:co(hm,{fallback:co(Na,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as Sm}from"@mantine/core";import{jsx as mo,jsxs as bm}from"react/jsx-runtime";function Me(e){let{contentType:o,url:t,title:r}=e.value??{};return t?bm("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&mo("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&mo("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:mo("source",{type:o,src:t})}),o==="application/pdf"&&mo("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:mo("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),mo("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:mo(Sm,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Cm(r),children:r||"Download"})})]}):null}function Cm(e){return e?.includes(".")?e:void 0}import{jsx as Ga}from"react/jsx-runtime";function jl(e){return Ga("div",{children:e.values?.map((o,t)=>Ga("div",{children:Ga(Me,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as ef}from"@mantine/core";import{useRef as Bm,useState as Am}from"react";import{useRef as Rm}from"react";import{normalizeOperationOutcome as Pm}from"@medplum/core";import{Fragment as Dm,jsx as Tm,jsxs as km}from"react/jsx-runtime";function wo(e){let o=R(),t=Rm(null);function r(l){E(l),t.current?.click()}function a(l){E(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(Pm(u))})}return km(Dm,{children:[Tm("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as Se,jsxs as It}from"react/jsx-runtime";function of(e){let[o,t]=Am(e.defaultValue??[]),r=Bm();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return It("table",{style:{width:"100%"},children:[It("colgroup",{children:[Se("col",{width:"97%"}),Se("col",{width:"3%"})]}),It("tbody",{children:[o.map((n,l)=>It("tr",{children:[Se("td",{children:Se(Me,{value:n,maxWidth:200})}),Se("td",{children:Se(ef,{title:"Remove",size:"sm",onClick:f=>{E(f);let i=o.slice();i.splice(l,1),a(i)},children:Se(Je,{})})})]},`${l}-${o.length}`)),It("tr",{children:[Se("td",{}),Se("td",{children:Se(wo,{onUpload:n=>{a([...r.current,n])},children:n=>Se(ef,{...n,title:"Add",size:"sm",color:"green",children:Se(it,{size:16})})})})]})]})]})}import{Button as tf}from"@mantine/core";import{useState as Mm}from"react";import{Fragment as Fm,jsx as Kt,jsxs as wm}from"react/jsx-runtime";function Zt(e){let[o,t]=Mm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?wm(Fm,{children:[Kt(Me,{value:o,maxWidth:200}),Kt(tf,{onClick:a=>{E(a),r(void 0)},children:"Remove"})]}):Kt(wo,{onUpload:r,children:a=>Kt(tf,{...a,children:"Upload..."})})}import{getPathDisplayName as vp,tryGetDataType as Sp}from"@medplum/core";var Yt=["meta","implicitRules","contained","extension","modifierExtension"],jt=["language","text"];import{createStyles as Om}from"@mantine/core";import{Fragment as Lm,jsx as Ua,jsxs as Nm}from"react/jsx-runtime";var Em=Om(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 rf(e){let{children:o,compact:t}=e,{classes:r,cx:a}=Em();return Ua("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function af(e){return Nm(Lm,{children:[Ua("dt",{children:e.term}),Ua("dd",{children:e.children})]})}import{ActionIcon as ip,Box as up,CopyButton as cp,Tooltip as dp}from"@mantine/core";import{PropertyType as N,formatDateTime as mp,formatPeriod as pp,formatTiming as xp,isEmpty as Ip}from"@medplum/core";import{formatCodeableConcept as Vm}from"@medplum/core";import{Fragment as Hm,jsx as qm}from"react/jsx-runtime";function Oo(e){return qm(Hm,{children:Vm(e.value)})}import{formatCoding as Gm}from"@medplum/core";import{Fragment as Um,jsx as Qm}from"react/jsx-runtime";function nf(e){return Qm(Um,{children:Gm(e.value)})}import{Fragment as zm,jsx as Wm}from"react/jsx-runtime";function er(e){let o=e.value;if(!o)return null;let t=[];return o.value&&t.push(o.value),(o.use||o.system)&&(t.push(" ["),o.use&&t.push(o.use),o.use&&o.system&&t.push(" "),o.system&&t.push(o.system),t.push("]")),Wm(zm,{children:t.join("").trim()})}import{Fragment as Jm,jsx as Xm,jsxs as $m}from"react/jsx-runtime";function lf(e){let o=e.value;return o?$m(Jm,{children:[o.name,o.name&&": ",o.telecom?.map(t=>Xm(er,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as _m}from"react/jsx-runtime";function ff(e){return _m("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as Km}from"@medplum/core";import{Fragment as Zm,jsx as Ym}from"react/jsx-runtime";function sf(e){return Ym(Zm,{children:Km(e.value)})}import{formatQuantity as jm}from"@medplum/core";import{Fragment as ep,jsx as op}from"react/jsx-runtime";function _e(e){return op(ep,{children:jm(e.value)})}import{formatRange as tp}from"@medplum/core";import{Fragment as rp,jsx as ap}from"react/jsx-runtime";function or(e){return ap(rp,{children:tp(e.value)})}import{Fragment as np,jsx as uf,jsxs as lp}from"react/jsx-runtime";function cf(e){let o=e.value;return o?lp(np,{children:[uf(_e,{value:o.numerator}),"\xA0/\xA0",uf(_e,{value:o.denominator})]}):null}import{stringify as fp}from"@medplum/core";import{Fragment as sp,jsx as df}from"react/jsx-runtime";function po(e){if(!e.value)return null;let o=e.value.display||e.value.reference||fp(e.value);return e.link!==!1&&e.value.reference?df(te,{to:e.value,children:o}):df(sp,{children:o})}import{Fragment as mf,jsx as tr}from"react/jsx-runtime";function pf(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?tr(mf,{children:t.map((a,n)=>tr("div",{children:tr(le,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):tr(mf,{})}import{Fragment as Eo,jsx as q,jsxs as gp}from"react/jsx-runtime";function le(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return gp(up,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!Ip(r)&&q(cp,{value:r,timeout:2e3,children:({copied:n,copy:l})=>q(dp,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:q(ip,{color:n?"teal":"gray",onClick:l,children:n?q(st,{size:"1rem"}):q(ya,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===N.Attachment?q(jl,{values:r,maxWidth:e.maxWidth}):q(pf,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case N.boolean:return q(Eo,{children:r===void 0?"":(!!r).toString()});case N.SystemString:case N.string:return q("div",{style:{whiteSpace:"pre-wrap"},children:r});case N.code:case N.date:case N.decimal:case N.id:case N.integer:case N.positiveInt:case N.unsignedInt:case N.uri:case N.url:return q(Eo,{children:r});case N.canonical:return q(po,{value:{reference:r},link:e.link});case N.dateTime:case N.instant:return q(Eo,{children:mp(r)});case N.markdown:return q("pre",{children:r});case N.Address:return q(Sl,{value:r});case N.Annotation:return q(Eo,{children:r?.text});case N.Attachment:return q(Me,{value:r,maxWidth:e.maxWidth});case N.CodeableConcept:return q(Oo,{value:r});case N.Coding:return q(nf,{value:r});case N.ContactDetail:return q(lf,{value:r});case N.ContactPoint:return q(er,{value:r});case N.HumanName:return q(Xt,{value:r});case N.Identifier:return q(ff,{value:r});case N.Money:return q(sf,{value:r});case N.Period:return q(Eo,{children:pp(r)});case N.Quantity:case N.Duration:return q(_e,{value:r});case N.Range:return q(or,{value:r});case N.Ratio:return q(cf,{value:r});case N.Reference:return q(po,{value:r,link:e.link});case N.Timing:return q(Eo,{children:xp(r)});case N.Dosage:case N.UsageContext:return q(gt,{value:{type:t,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});default:if(!o)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);return q(gt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as hp,getTypedPropertyValueWithSchema as yp}from"@medplum/core";function Ke(e,o){let t=hp(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=yp(e,o,t);return r?Array.isArray(r)?[r.map(a=>a.value),r[0].type]:[r.value,r.type]:[void 0,"undefined"]}import{jsx as rr,jsxs as Cp}from"react/jsx-runtime";function gt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=Sp(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?rr("div",{children:t.name}):rr(rf,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,f]=n;if(Yt.includes(l)||jt.includes(l)&&f.path.split(".").length===2)return null;let[i,s]=Ke(o,l);return e.ignoreMissingValues&&(!i||Array.isArray(i)&&i.length===0)?null:rr(af,{term:vp(l),children:rr(le,{property:f,propertyType:s,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):Cp("div",{children:[r,"\xA0not implemented"]})}import{tryGetDataType as GI}from"@medplum/core";import{useContext as UI,useMemo as ls,useState as QI}from"react";import{Stack as LI}from"@mantine/core";import{getPathDisplayName as ns,isPopulated as NI}from"@medplum/core";import{useMemo as VI,useState as HI}from"react";import{Group as Pp,Input as Tp}from"@mantine/core";import{useContext as Dp}from"react";import bp from"react";function Rp(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 ke=bp.createContext({profileUrl:void 0,debugMode:!1,getModifiedNestedElement:()=>{}});function If(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]=Rp(f,".");l.has(s)&&(r[e.type+"."+f]=i),l.add(f)}}return{debugMode:t??!1,profileUrl:o,getModifiedNestedElement:a}}import{jsx as Qa,jsxs as kp}from"react/jsx-runtime";function ar(e){let{debugMode:o}=Dp(ke),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,kp(Pp,{noWrap:!0,"data-testid":e.testId,children:[Qa("div",{children:e.children}),Qa("div",{children:Qa(Tp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as Bp}from"@mantine/core";import{useContext as Ap}from"react";function G(e,o){return e?.issue?.filter(t=>gf(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
-
`)}function nr(e,o){return e?.issue?.filter(t=>gf(t.expression?.[0],o))}function gf(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 Mp}from"react/jsx-runtime";function ie(e){let{debugMode:o}=Ap(ke),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Mp(Bp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,error:G(e.outcome,e.htmlFor),"data-testid":e.testId,children:e.children})}import{capitalize as Fp,isEmpty as hf}from"@medplum/core";function ht(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let f=o.replace("[x]",Fp(l.code));f in e&&delete e[f]}return e[t]=a,e}function fM(e){return!!e&&!hf(e.url)&&!hf(e.name)}import{Checkbox as kI,Group as BI,NativeSelect as AI,Textarea as MI,TextInput as on}from"@mantine/core";import{capitalize as as,PropertyType as w}from"@medplum/core";import{useState as FI}from"react";import{useState as wp}from"react";import{jsx as Lp}from"react/jsx-runtime";function yf(e){let[o,t]=wp(e.defaultValue);function r(a){let n=Ep(a);t(n),e.onChange&&e.onChange(n)}return Lp(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Op(o),maxSelectedValues:1,onChange:r})}function Op(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Ep(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as Np}from"react";import{jsx as qp}from"react/jsx-runtime";function lr(e){let[o,t]=Np(e.defaultValue);function r(a){let n=a[0],l=n&&Hp(n);t(l),e.onChange&&e.onChange(l)}return qp(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Vp(o),maxSelectedValues:1,onChange:r})}function Vp(e){return{system:e.system,code:e.code,display:e.display}}function Hp(e){return{system:e.system,code:e.code,display:e.display}}import{Group as $p,TextInput as _p}from"@mantine/core";import{useRef as Kp,useState as Zp}from"react";import{Group as Gp,NativeSelect as vf,TextInput as Up}from"@mantine/core";import{useContext as Qp,useMemo as zp,useRef as Wp,useState as Xp}from"react";import{jsx as za,jsxs as Jp}from"react/jsx-runtime";function fr(e){let{path:o,outcome:t}=e,{getModifiedNestedElement:r}=Qp(ke),[a,n]=Xp(e.defaultValue),l=Wp();l.current=a;let[f,i,s]=zp(()=>["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 Jp(Gp,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[za(vf,{"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:G(t,o+".system")}),za(vf,{"data-testid":"use",defaultValue:a?.use,required:(i?.min??0)>0,onChange:p=>d(p.currentTarget.value),data:["","home","work","temp","old","mobile"],error:G(t,o+".use")}),za(Up,{placeholder:"Value",defaultValue:a?.value,required:(s?.min??0)>0,onChange:p=>m(p.currentTarget.value),error:G(t,o+".value")})]})}import{jsx as Sf,jsxs as Yp}from"react/jsx-runtime";function Cf(e){let[o,t]=Zp(e.defaultValue),r=Kp();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 Yp($p,{spacing:"xs",grow:!0,noWrap:!0,children:[Sf(_p,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:f=>n(f.currentTarget.value)}),Sf(fr,{name:e.name+"-telecom",path:e.path+".telecom",defaultValue:o?.telecom?.[0],onChange:l,outcome:e.outcome})]})}import{TextInput as jp}from"@mantine/core";import{isValidDate as bf}from"@medplum/core";function Rf(e){if(!e)return"";let o=new Date(e);return bf(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function Pf(e){if(!e)return"";let o=new Date(e);return bf(o)?o.toISOString():""}import{jsx as ox}from"react/jsx-runtime";function Be(e){return ox(jp,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:ex(),defaultValue:Rf(e.defaultValue),autoFocus:e.autoFocus,error:G(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(Pf(t))}}})}function ex(){return"datetime-local"}import{JsonInput as tx}from"@mantine/core";import{stringify as rx,tryGetProfile as ax}from"@medplum/core";import{useEffect as nx,useMemo as lx,useState as Tf}from"react";import{jsx as Wa,jsxs as Df}from"react/jsx-runtime";function kf(e){let{propertyType:o}=e,t=R(),[r,a]=Tf(!1),[n,l]=Tf(),f=lx(()=>{if(!(!o.profile||o.profile.length===0))return o.profile[0]},[o]);nx(()=>{f&&(a(!0),t.requestProfileSchema(f).then(()=>{let s=ax(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?Df("div",{children:["Loading ",f,"..."]}):n?Wa(Lo,{profileUrl:f,typeName:n.name,defaultValue:e.defaultValue,onChange:i}):Df("div",{children:["StructureDefinition for ",f," not found"]}):Wa(fx,{...e})}function fx(e){return Wa(tx,{id:e.name,name:e.name,"data-testid":"extension-json-input",defaultValue:rx(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as sx,NativeSelect as ix,TextInput as sr}from"@mantine/core";import{useState as ux}from"react";import{jsx as yt,jsxs as cx}from"react/jsx-runtime";function Bf(e){let{outcome:o,path:t}=e,[r,a]=ux(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 cx(sx,{spacing:"xs",grow:!0,noWrap:!0,children:[yt(ix,{defaultValue:r?.use,name:e.name+"-use","data-testid":"use",onChange:c=>l(c.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"],error:G(o,t+".use")}),yt(sr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:r?.prefix?.join(" "),onChange:c=>f(c.currentTarget.value),error:G(o,t+".prefix")}),yt(sr,{placeholder:"Given",name:e.name+"-given",defaultValue:r?.given?.join(" "),onChange:c=>i(c.currentTarget.value),error:G(o,t+".given")}),yt(sr,{name:e.name+"-family",placeholder:"Family",defaultValue:r?.family,onChange:c=>s(c.currentTarget.value),error:G(o,t+".family")}),yt(sr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:r?.suffix?.join(" "),onChange:c=>u(c.currentTarget.value),error:G(o,t+".suffix")})]})}import{Group as dx,TextInput as Af}from"@mantine/core";import{useContext as mx,useMemo as px,useState as xx}from"react";import{jsx as Mf,jsxs as Ix}from"react/jsx-runtime";function Ff(e){let{path:o,outcome:t}=e,[r,a]=xx(e.defaultValue),{getModifiedNestedElement:n}=mx(ke),[l,f]=px(()=>["system","value"].map(s=>n(o+"."+s)),[n,o]);function i(s){a(s),e.onChange&&e.onChange(s)}return Ix(dx,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[Mf(Af,{placeholder:"System",required:(l?.min??0)>0,defaultValue:r?.system,onChange:s=>i({...r,system:s.currentTarget.value}),error:G(t,o+".system")}),Mf(Af,{placeholder:"Value",required:(f?.min??0)>0,defaultValue:r?.value,onChange:s=>i({...r,value:s.currentTarget.value}),error:G(t,o+".value")})]})}import{NativeSelect as gx,TextInput as hx}from"@mantine/core";import{useCallback as Xa,useState as yx}from"react";import{jsx as Ja}from"react/jsx-runtime";var vx=["USD","EUR","CAD","GBP","AUD"];function wf(e){let{onChange:o}=e,[t,r]=yx(e.defaultValue),a=Xa(i=>{r(i),o&&o(i)},[o]),n=Xa(i=>{a({...t,currency:i.currentTarget.value})},[t,a]),l=Xa(i=>{a({...t,value:i.currentTarget.valueAsNumber})},[t,a]),f=Ja(gx,{defaultValue:t?.currency,data:vx,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return Ja(hx,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:Ja(va,{size:14}),rightSection:f,rightSectionWidth:92,onChange:l})}import{Group as Sx}from"@mantine/core";import{useState as Cx}from"react";import{jsx as Of,jsxs as bx}from"react/jsx-runtime";function Ef(e){let[o,t]=Cx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return bx(Sx,{spacing:"xs",grow:!0,noWrap:!0,children:[Of(Be,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),Of(Be,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as Rx,NativeSelect as Px,TextInput as Lf}from"@mantine/core";import{useState as Tx}from"react";import{jsx as $a,jsxs as kx}from"react/jsx-runtime";function Ce(e){let[o,t]=Tx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return kx(Rx,{spacing:"xs",grow:!0,noWrap:!0,children:[$a(Px,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),$a(Lf,{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:Dx(a.currentTarget.value)})}}),$a(Lf,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function Dx(e){if(e)return parseFloat(e)}import{Group as Bx}from"@mantine/core";import{useState as Ax}from"react";import{jsx as Nf,jsxs as Mx}from"react/jsx-runtime";function vt(e){let[o,t]=Ax(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Mx(Bx,{spacing:"xs",grow:!0,noWrap:!0,children:[Nf(Ce,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),Nf(Ce,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as Fx}from"@mantine/core";import{useState as wx}from"react";import{jsx as Vf,jsxs as Ox}from"react/jsx-runtime";function Hf(e){let[o,t]=wx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Ox(Fx,{spacing:"xs",grow:!0,noWrap:!0,children:[Vf(Ce,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Vf(Ce,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as zx,NativeSelect as Wx}from"@mantine/core";import{LRUCache as Xx,ReadablePromise as Jx,createReference as $x,isEmpty as _x,isPopulated as Kx,tryGetProfile as Zx}from"@medplum/core";import{useCallback as Yx,useEffect as jx,useMemo as zf,useRef as eI,useState as _a}from"react";import{Group as Ex,Text as qf}from"@mantine/core";import{getDisplayString as Lx,getReferenceString as Qf}from"@medplum/core";import{forwardRef as Nx,useCallback as Gf,useState as Vx}from"react";import{jsx as St,jsxs as Uf}from"react/jsx-runtime";var Hx={Observation:"code",User:"email:contains"},qx=["AccessPolicy","Account","ActivityDefinition","Bot","CapabilityStatement","ClientApplication","CodeSystem","CompartmentDefinition","ConceptMap","EffectEvidenceSynthesis","Endpoint","EventDefinition","Evidence","EvidenceVariable","ExampleScenario","GraphDefinition","HealthcareService","ImplementationGuide","InsurancePlan","Library","Location","Measure","MedicinalProduct","MessageDefinition","NamingSystem","OperationDefinition","Organization","Patient","Person","PlanDefinition","Practitioner","Project","Questionnaire","RelatedPerson","ResearchDefinition","ResearchElementDefinition","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function Gx(e){return{value:Qf(e),label:Lx(e),resource:e}}function ir(e){let o=R(),{resourceType:t,searchCriteria:r}=e,[a,n]=Vx(),l=z(e.defaultValue,n),f=e.onChange,i=Gf(async(u,c)=>{let d=Qx(t),m=new URLSearchParams({[d]:u??"",_count:"10",...r});return await o.searchResources(t,m,{signal:c})},[o,t,r]),s=Gf(u=>{f&&f(u[0])},[f]);return e.defaultValue&&!a&&!l?null:St(Bo,{name:e.name,required:e.required,itemComponent:Ux,defaultValue:l,placeholder:e.placeholder,maxSelectedValues:1,toKey:Qf,toOption:Gx,loadOptions:i,onChange:s,clearable:!0})}var Ux=Nx(({label:e,resource:o,...t},r)=>St("div",{ref:r,...t,children:Uf(Ex,{noWrap:!0,children:[St(se,{value:o}),Uf("div",{children:[St(qf,{children:e}),St(qf,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function Qx(e){return Hx[e]??(qx.includes(e)?"name":"_id")}import{jsx as Ka,jsxs as nI}from"react/jsx-runtime";function No(e){let{onChange:o}=e,t=R(),[r,a]=_a(e.defaultValue),[n,l]=_a(()=>oI(e.targetTypes)),[f,i]=_a(()=>tI(e.defaultValue,n)),s=eI(new Xx),u=zf(()=>f?.type==="profile"?{...e.searchCriteria,_profile:f.value}:e.searchCriteria,[e.searchCriteria,f]);jx(()=>{let m=!1,p=n?.map(x=>{if(!aI(x))return Promise.resolve(x);m=!0;let S=x.value,y=s.current.get(S);if(y)return y;let v=rI(t,x.value).then(T=>{let h={...x};return T?Kx(T.type)?(h.resourceType=T.type,h.name=T.name,h.title=T.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(T=>(console.error(T),{...x,error:T})),C=new Jx(v);return s.current.set(S,C),C});!p||!m||Promise.all(p).then(x=>{if(l(x),!f)return;let S=x.findIndex(y=>y.value===f.value||y.resourceType===f.resourceType);if(S===-1){console.debug(`defaultValue had unexpected resourceType: ${f.resourceType}`);return}i(x[S])}).catch(console.error)},[t,f,n]);let c=Yx(m=>{let p=m?$x(m):void 0;a(p),o&&o(p)},[o]),d=zf(()=>n?n.map(m=>({value:m.value,label:m.type==="profile"?m.title??m.name??m.resourceType??m.value:m.value})):[],[n]);return nI(zx,{spacing:"xs",grow:!0,noWrap:!0,children:[n&&n.length>1&&Ka(Wx,{"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(S=>S.value===p);i(x)},data:d}),!n&&Ka(Fo,{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"}),Ka(ir,{resourceType:f?.resourceType,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:c})]})}function oI(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 tI(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 rI(e,o){let t=Zx(o);if(t)return{type:t.type,name:t.name,title:t.title};let r=`{
|
|
64
|
+
}`.replace(/\s+/g," ")}function Cd(e,o){let t=[];return e.data.Patients1&&t.push(...e.data.Patients1),e.data.Patients2&&t.push(...e.data.Patients2),e.data.ServiceRequestList&&t.push(...e.data.ServiceRequestList),Rd(bd(t),o).slice(0,5)}function bd(e){let o=new Set,t=[];for(let r of e)o.has(r.id)||(o.add(r.id),t.push(r));return t}function Rd(e,o){return e.sort((t,r)=>ql(r,o)-ql(t,o))}function ql(e,o){let t=0;if(e.identifier)for(let r of e.identifier)t=Math.max(t,Gl(r.value,o));if(e.resourceType==="Patient"&&e.name)for(let r of e.name)t=Math.max(t,Gl(md(r),o));return t}function Gl(e,o){if(!e)return 0;let t=e.toLowerCase().indexOf(o.toLowerCase());return t<0?0:100-t}import{jsx as _,jsxs as $e}from"react/jsx-runtime";var Md=Td(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 Jl(e){let o=lt(),{medplum:t,profile:r,navigate:a}=o,n=t.getLogins(),{classes:l,cx:f}=Md(),[i,s]=Ad(!1);return _(Dd,{height:60,p:8,style:{zIndex:101},children:$e($t,{position:"apart",children:[$e($t,{spacing:"xs",children:[_(Wl,{className:l.logoButton,onClick:e.navbarToggle,children:e.logo}),!e.headerSearchDisabled&&_(zl,{pathname:e.pathname,searchParams:e.searchParams})]}),$e(Ne,{width:260,shadow:"xl",position:"bottom-end",transitionProps:{transition:"pop-top-right"},opened:i,onClose:()=>s(!1),children:[_(Ne.Target,{children:_(Wl,{className:f(l.user,{[l.userActive]:i}),onClick:()=>s(u=>!u),children:$e($t,{spacing:7,children:[_(se,{value:r,radius:"xl",size:24}),_(pt,{size:"sm",className:l.userName,children:Bd(r?.name?.[0])}),_(ga,{size:12,stroke:1.5})]})})}),$e(Ne.Dropdown,{children:[$e(kd,{align:"center",p:"xl",children:[_(se,{size:"xl",radius:100,value:o.profile}),_(Xt,{value:o.profile?.name?.[0]}),_(pt,{color:"dimmed",size:"xs",children:t.getActiveLogin()?.project.display})]}),n.length>1&&_(Ne.Divider,{}),n.map(u=>u.profile.reference!==Xl(o.profile)&&_(Ne.Item,{onClick:()=>{t.setActiveLogin(u).then(()=>window.location.reload()).catch(console.log)},children:$e($t,{children:[_(Pd,{radius:"xl"}),$e("div",{style:{flex:1},children:[_(pt,{size:"sm",weight:500,children:u.profile.display}),_(pt,{color:"dimmed",size:"xs",children:u.project.display})]})]})},u.profile.reference)),_(Ne.Divider,{}),_(Ne.Item,{icon:_(Oa,{size:14,stroke:1.5}),onClick:()=>a("/signin"),children:"Add another account"}),_(Ne.Item,{icon:_(To,{size:14,stroke:1.5}),onClick:()=>a(`/${Xl(r)}`),children:"Account settings"}),_(Ne.Item,{icon:_(Ta,{size:14,stroke:1.5}),onClick:async()=>{await t.signOut(),a("/signin")},children:"Sign out"}),_(pt,{size:"xs",color:"dimmed",align:"center",children:e.version})]})]})]})})}import{Button as rm,createStyles as am,Navbar as qa,ScrollArea as nm,Space as lm,Text as fm}from"@mantine/core";import{Fragment as sm,useState as im}from"react";import{Button as Ed,Group as Ld,Modal as Nd,NativeSelect as Vd,Stack as Hd,TextInput as qd}from"@mantine/core";import{showNotification as _l}from"@mantine/notifications";import{deepClone as Gd,normalizeErrorString as Ud}from"@medplum/core";function $l(e){let o={};for(let t of Array.from(e.elements))t instanceof HTMLInputElement?Fd(o,t):t instanceof HTMLTextAreaElement?o[t.name]=t.value:t instanceof HTMLSelectElement&&wd(o,t);return o}function Fd(e,o){o.disabled||(o.type==="checkbox"||o.type==="radio")&&!o.checked||(e[o.name]=o.value)}function wd(e,o){e[o.name]=o.value}import{jsx as Od}from"react/jsx-runtime";function J(e){return Od("form",{style:e.style,"data-testid":e.testid,onSubmit:o=>{o.preventDefault();let t=$l(o.target);e.onSubmit&&e.onSubmit(t)},children:e.children})}import{jsx as uo,jsxs as zd}from"react/jsx-runtime";function Kl(e){let o=R(),t=o.getUserConfiguration();function r(a){let{menuname:n,bookmarkname:l}=a,f=`${e.pathname}?${e.searchParams.toString()}`,i=Gd(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"}),_l({color:"green",message:"Success"}),e.onOk()}).catch(u=>{_l({color:"red",message:Ud(u)})})}return uo(Nd,{title:"Add Bookmark",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:uo(J,{onSubmit:r,children:zd(Hd,{children:[uo(Qd,{config:t}),uo(qd,{label:"Bookmark Name",type:"text",name:"bookmarkname",placeholder:"Bookmark Name",withAsterisk:!0}),uo(Ld,{position:"right",children:uo(Ed,{mt:"sm",type:"submit",children:"OK"})})]})})})}function Qd(e){function o(r){return r?.menu?.map(a=>a.title)}let t=o(e.config);return uo(Vd,{name:"menuname",defaultValue:t[0],label:"Select Menu Option",placeholder:"Menu",data:t,withAsterisk:!0})}import{useCallback as em,useState as om}from"react";import{useState as Kd}from"react";import{useCallback as Wd}from"react";import{jsx as _d}from"react/jsx-runtime";function Ha(e){return typeof e.code=="string"?e.code:JSON.stringify(e)}function Xd(e){return typeof e.display=="string"?e.display:Ha(e)}function Jd(e){return{value:Ha(e),label:Xd(e),resource:e}}function $d(e){return{code:e,display:e}}function Mo(e){let o=R(),{binding:t,creatable:r,clearable:a,...n}=e,l=Wd(async(f,i)=>{if(!t)return[];let u=(await o.searchValueSet(t,f,{signal:i})).expansion?.contains,c=[];for(let d of u)d.code&&!c.some(m=>m.code===d.code)&&c.push(d);return c},[o,t]);return _d(Bo,{...n,creatable:r??!0,clearable:a??!0,toKey:Ha,toOption:Jd,loadOptions:l,onCreate:$d,getCreateLabel:r===!1?void 0:f=>`+ Create ${f}`})}import{jsx as jd}from"react/jsx-runtime";function _t(e){let[o,t]=Kd(e.defaultValue);function r(a){let n=a[0],l=Yd(n);t(l),e.onChange&&e.onChange(l)}return jd(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:Zd(o),onChange:r,creatable:e.creatable,maxSelectedValues:e.maxSelectedValues??1,clearSearchOnChange:e.clearSearchOnChange,clearable:e.clearable})}function Zd(e){return e?{code:e}:void 0}function Yd(e){return e?.code}import{jsx as tm}from"react/jsx-runtime";function Fo(e){let[o,t]=om(e.defaultValue),r=e.onChange,a=em(n=>{t(n),r&&r(n)},[r]);return tm(_t,{"data-autofocus":e.autoFocus,"data-testid":e.testId,defaultValue:o,onChange:a,name:e.name,placeholder:e.placeholder,binding:"https://medplum.com/fhir/ValueSet/resource-types",creatable:!1,maxSelectedValues:0,clearSearchOnChange:!0,clearable:!1})}import{Fragment as pm,jsx as De,jsxs as xt}from"react/jsx-runtime";var Zl=am(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 Yl(e){let{classes:o}=Zl(),t=Xe(),r=dm(e.pathname,e.searchParams,e.menus),[a,n]=im(!1);function l(i,s){i.stopPropagation(),i.preventDefault(),t(s),window.innerWidth<768&&e.closeNavbar()}function f(i){i&&t(`/${i}`)}return xt(pm,{children:[De(qa,{width:{sm:250},p:"xs",children:xt(nm,{children:[!e.resourceTypeSearchDisabled&&De(qa.Section,{mb:"sm",children:De(Fo,{name:"resourceType",placeholder:"Resource Type",onChange:i=>f(i)},window.location.pathname)}),xt(qa.Section,{grow:!0,children:[e.menus?.map(i=>xt(sm,{children:[De(fm,{className:o.menuTitle,children:i.title}),i.links?.map(s=>xt(um,{to:s.href,active:s.href===r?.href,onClick:u=>l(u,s.href),children:[De(cm,{to:s.href,icon:s.icon}),De("span",{children:s.label})]},s.href))]},`menu-${i.title}`)),e.displayAddBookmark&&De(rm,{variant:"subtle",size:"xs",mt:"xl",leftIcon:De(Aa,{size:"0.75rem"}),onClick:()=>n(!0),children:"Add Bookmark"})]})]})}),e.pathname&&e.searchParams&&De(Kl,{pathname:e.pathname,searchParams:e.searchParams,visible:a,onOk:()=>n(!1),onCancel:()=>n(!1)})]})}function um(e){let{classes:o,cx:t}=Zl();return De(te,{onClick:e.onClick,to:e.to,className:t(o.link,{[o.linkActive]:e.active}),children:e.children})}function cm(e){return e.icon?e.icon:De(lm,{w:30})}function dm(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=mm(e,o,l.href);f>a&&(a=f,r=l)}return r}function mm(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 co}from"react/jsx-runtime";function Kk(e){let o=Im(),[t,r]=vm(localStorage.navbarOpen==="true"),a=R(),n=Gt();ym(()=>{function s(){gm({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()?co(Na,{}):co(xm,{styles:{main:{background:o.colorScheme==="dark"?o.colors.dark[8]:o.colors.gray[0]}},padding:0,fixed:!0,header:n&&co(Jl,{pathname:e.pathname,searchParams:e.searchParams,headerSearchDisabled:e.headerSearchDisabled,logo:e.logo,version:e.version,navbarToggle:i}),navbar:n&&t?co(Yl,{pathname:e.pathname,searchParams:e.searchParams,menus:e.menus,closeNavbar:f,displayAddBookmark:e.displayAddBookmark,resourceTypeSearchDisabled:e.resourceTypeSearchDisabled}):void 0,children:co(Do,{children:co(hm,{fallback:co(Na,{}),children:e.children})},`${e.pathname}?${e.searchParams?.toString()}`)})}import{Anchor as Sm}from"@mantine/core";import{jsx as mo,jsxs as bm}from"react/jsx-runtime";function Me(e){let{contentType:o,url:t,title:r}=e.value??{};return t?bm("div",{"data-testid":"attachment-display",children:[o?.startsWith("image/")&&mo("img",{"data-testid":"attachment-image",style:{maxWidth:e.maxWidth},src:t,alt:r}),o?.startsWith("video/")&&mo("video",{"data-testid":"attachment-video",style:{maxWidth:e.maxWidth},controls:!0,children:mo("source",{type:o,src:t})}),o==="application/pdf"&&mo("div",{"data-testid":"attachment-pdf",style:{maxWidth:e.maxWidth,minHeight:400},children:mo("iframe",{width:"100%",height:"400",src:t+"#navpanes=0",allowFullScreen:!0,frameBorder:0,seamless:!0})}),mo("div",{"data-testid":"download-link",style:{padding:"2px 16px 16px 16px"},children:mo(Sm,{href:t,"data-testid":"attachment-details",target:"_blank",rel:"noopener noreferrer",download:Cm(r),children:r||"Download"})})]}):null}function Cm(e){return e?.includes(".")?e:void 0}import{jsx as Ga}from"react/jsx-runtime";function jl(e){return Ga("div",{children:e.values?.map((o,t)=>Ga("div",{children:Ga(Me,{value:o,maxWidth:e.maxWidth})},"attatchment-"+t))})}import{ActionIcon as ef}from"@mantine/core";import{useRef as Bm,useState as Am}from"react";import{useRef as Rm}from"react";import{normalizeOperationOutcome as Pm}from"@medplum/core";import{Fragment as Dm,jsx as Tm,jsxs as km}from"react/jsx-runtime";function wo(e){let o=R(),t=Rm(null);function r(l){E(l),t.current?.click()}function a(l){E(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(Pm(u))})}return km(Dm,{children:[Tm("input",{type:"file","data-testid":"upload-file-input",style:{display:"none"},ref:t,onChange:l=>a(l)}),e.children({onClick:r})]})}import{jsx as Se,jsxs as It}from"react/jsx-runtime";function of(e){let[o,t]=Am(e.defaultValue??[]),r=Bm();r.current=o;function a(n){t(n),e.onChange&&e.onChange(n)}return It("table",{style:{width:"100%"},children:[It("colgroup",{children:[Se("col",{width:"97%"}),Se("col",{width:"3%"})]}),It("tbody",{children:[o.map((n,l)=>It("tr",{children:[Se("td",{children:Se(Me,{value:n,maxWidth:200})}),Se("td",{children:Se(ef,{title:"Remove",size:"sm",onClick:f=>{E(f);let i=o.slice();i.splice(l,1),a(i)},children:Se(Je,{})})})]},`${l}-${o.length}`)),It("tr",{children:[Se("td",{}),Se("td",{children:Se(wo,{onUpload:n=>{a([...r.current,n])},children:n=>Se(ef,{...n,title:"Add",size:"sm",color:"green",children:Se(it,{size:16})})})})]})]})]})}import{Button as tf}from"@mantine/core";import{useState as Mm}from"react";import{Fragment as Fm,jsx as Kt,jsxs as wm}from"react/jsx-runtime";function Zt(e){let[o,t]=Mm(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return o?wm(Fm,{children:[Kt(Me,{value:o,maxWidth:200}),Kt(tf,{onClick:a=>{E(a),r(void 0)},children:"Remove"})]}):Kt(wo,{onUpload:r,children:a=>Kt(tf,{...a,children:"Upload..."})})}import{getPathDisplayName as vp,tryGetDataType as Sp}from"@medplum/core";var Yt=["meta","implicitRules","contained","extension","modifierExtension"],jt=["language","text"];import{createStyles as Om}from"@mantine/core";import{Fragment as Lm,jsx as Ua,jsxs as Nm}from"react/jsx-runtime";var Em=Om(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 rf(e){let{children:o,compact:t}=e,{classes:r,cx:a}=Em();return Ua("dl",{className:a(r.root,{[r.compact]:t}),children:o})}function af(e){return Nm(Lm,{children:[Ua("dt",{children:e.term}),Ua("dd",{children:e.children})]})}import{ActionIcon as ip,Box as up,CopyButton as cp,Tooltip as dp}from"@mantine/core";import{PropertyType as N,formatDateTime as mp,formatPeriod as pp,formatTiming as xp,isEmpty as Ip}from"@medplum/core";import{formatCodeableConcept as Vm}from"@medplum/core";import{Fragment as Hm,jsx as qm}from"react/jsx-runtime";function Oo(e){return qm(Hm,{children:Vm(e.value)})}import{formatCoding as Gm}from"@medplum/core";import{Fragment as Um,jsx as Qm}from"react/jsx-runtime";function nf(e){return Qm(Um,{children:Gm(e.value)})}import{Fragment as zm,jsx as Wm}from"react/jsx-runtime";function er(e){let o=e.value;if(!o)return null;let t=[];return o.value&&t.push(o.value),(o.use||o.system)&&(t.push(" ["),o.use&&t.push(o.use),o.use&&o.system&&t.push(" "),o.system&&t.push(o.system),t.push("]")),Wm(zm,{children:t.join("").trim()})}import{Fragment as Jm,jsx as Xm,jsxs as $m}from"react/jsx-runtime";function lf(e){let o=e.value;return o?$m(Jm,{children:[o.name,o.name&&": ",o.telecom?.map(t=>Xm(er,{value:t},`telecom-${o.name}-${t.value}`))]}):null}import{jsxs as _m}from"react/jsx-runtime";function ff(e){return _m("div",{children:[e.value?.system,": ",e.value?.value]})}import{formatMoney as Km}from"@medplum/core";import{Fragment as Zm,jsx as Ym}from"react/jsx-runtime";function sf(e){return Ym(Zm,{children:Km(e.value)})}import{formatQuantity as jm}from"@medplum/core";import{Fragment as ep,jsx as op}from"react/jsx-runtime";function _e(e){return op(ep,{children:jm(e.value)})}import{formatRange as tp}from"@medplum/core";import{Fragment as rp,jsx as ap}from"react/jsx-runtime";function or(e){return ap(rp,{children:tp(e.value)})}import{Fragment as np,jsx as uf,jsxs as lp}from"react/jsx-runtime";function cf(e){let o=e.value;return o?lp(np,{children:[uf(_e,{value:o.numerator}),"\xA0/\xA0",uf(_e,{value:o.denominator})]}):null}import{stringify as fp}from"@medplum/core";import{Fragment as sp,jsx as df}from"react/jsx-runtime";function po(e){if(!e.value)return null;let o=e.value.display||e.value.reference||fp(e.value);return e.link!==!1&&e.value.reference?df(te,{to:e.value,children:o}):df(sp,{children:o})}import{Fragment as mf,jsx as tr}from"react/jsx-runtime";function pf(e){let{property:o,values:t}=e,r=o.type[0].code;return e.values?tr(mf,{children:t.map((a,n)=>tr("div",{children:tr(le,{arrayElement:!0,property:o,propertyType:r,value:a,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},`${n}-${t.length}`))}):tr(mf,{})}import{Fragment as Eo,jsx as q,jsxs as gp}from"react/jsx-runtime";function le(e){let{property:o,propertyType:t,value:r}=e;if(o?.path?.endsWith(".id"))return gp(up,{component:"div",sx:{display:"flex",gap:3,alignItems:"center"},children:[r,!Ip(r)&&q(cp,{value:r,timeout:2e3,children:({copied:n,copy:l})=>q(dp,{label:n?"Copied":"Copy",withArrow:!0,position:"right",children:q(ip,{color:n?"teal":"gray",onClick:l,children:n?q(st,{size:"1rem"}):q(ya,{size:"1rem"})})})})]});if(o?.max&&o.max>1&&!e.arrayElement)return t===N.Attachment?q(jl,{values:r,maxWidth:e.maxWidth}):q(pf,{property:o,values:r,ignoreMissingValues:e.ignoreMissingValues,link:e.link});switch(t){case N.boolean:return q(Eo,{children:r===void 0?"":(!!r).toString()});case N.SystemString:case N.string:return q("div",{style:{whiteSpace:"pre-wrap"},children:r});case N.code:case N.date:case N.decimal:case N.id:case N.integer:case N.positiveInt:case N.unsignedInt:case N.uri:case N.url:return q(Eo,{children:r});case N.canonical:return q(po,{value:{reference:r},link:e.link});case N.dateTime:case N.instant:return q(Eo,{children:mp(r)});case N.markdown:return q("pre",{children:r});case N.Address:return q(Sl,{value:r});case N.Annotation:return q(Eo,{children:r?.text});case N.Attachment:return q(Me,{value:r,maxWidth:e.maxWidth});case N.CodeableConcept:return q(Oo,{value:r});case N.Coding:return q(nf,{value:r});case N.ContactDetail:return q(lf,{value:r});case N.ContactPoint:return q(er,{value:r});case N.HumanName:return q(Xt,{value:r});case N.Identifier:return q(ff,{value:r});case N.Money:return q(sf,{value:r});case N.Period:return q(Eo,{children:pp(r)});case N.Quantity:case N.Duration:return q(_e,{value:r});case N.Range:return q(or,{value:r});case N.Ratio:return q(cf,{value:r});case N.Reference:return q(po,{value:r,link:e.link});case N.Timing:return q(Eo,{children:xp(r)});case N.Dosage:case N.UsageContext:return q(gt,{value:{type:t,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues});default:if(!o)throw Error(`Displaying property of type ${e.propertyType} requires element schema`);return q(gt,{value:{type:o.type[0].code,value:r},compact:!0,ignoreMissingValues:e.ignoreMissingValues})}}import{getTypedPropertyValue as hp,getTypedPropertyValueWithSchema as yp}from"@medplum/core";function Ke(e,o){let t=hp(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=yp(e,o,t);return r?Array.isArray(r)?[r.map(a=>a.value),r[0].type]:[r.value,r.type]:[void 0,"undefined"]}import{jsx as rr,jsxs as Cp}from"react/jsx-runtime";function gt(e){let o=e.value,t=o.value;if(!t)return null;let r=o.type,a=Sp(r);return a?typeof t=="object"&&"name"in t&&Object.keys(t).length===1&&typeof t.name=="string"?rr("div",{children:t.name}):rr(rf,{compact:e.compact,children:Object.entries(a.elements).map(n=>{let[l,f]=n;if(Yt.includes(l)||jt.includes(l)&&f.path.split(".").length===2)return null;let[i,s]=Ke(o,l);return e.ignoreMissingValues&&(!i||Array.isArray(i)&&i.length===0)?null:rr(af,{term:vp(l),children:rr(le,{property:f,propertyType:s,value:i,ignoreMissingValues:e.ignoreMissingValues,link:e.link})},l)})}):Cp("div",{children:[r,"\xA0not implemented"]})}import{tryGetDataType as GI}from"@medplum/core";import{useContext as UI,useMemo as ls,useState as QI}from"react";import{Stack as LI}from"@mantine/core";import{getPathDisplayName as ns,isPopulated as NI}from"@medplum/core";import{useMemo as VI,useState as HI}from"react";import{Group as Pp,Input as Tp}from"@mantine/core";import{useContext as Dp}from"react";import bp from"react";function Rp(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 ke=bp.createContext({profileUrl:void 0,debugMode:!1,getModifiedNestedElement:()=>{}});function If(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]=Rp(f,".");l.has(s)&&(r[e.type+"."+f]=i),l.add(f)}}return{debugMode:t??!1,profileUrl:o,getModifiedNestedElement:a}}import{jsx as Qa,jsxs as kp}from"react/jsx-runtime";function ar(e){let{debugMode:o}=Dp(ke),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,kp(Pp,{noWrap:!0,"data-testid":e.testId,children:[Qa("div",{children:e.children}),Qa("div",{children:Qa(Tp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,children:null})})]})}import{Input as Bp}from"@mantine/core";import{useContext as Ap}from"react";function G(e,o){return e?.issue?.filter(t=>gf(t.expression?.[0],o))?.map(t=>t.details?.text)?.join(`
|
|
65
|
+
`)}function nr(e,o){return e?.issue?.filter(t=>gf(t.expression?.[0],o))}function gf(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 Mp}from"react/jsx-runtime";function ie(e){let{debugMode:o}=Ap(ke),t;return o&&e.fhirPath?t=`${e.title} - ${e.fhirPath}`:t=e.title,Mp(Bp.Wrapper,{id:e.htmlFor,label:t,description:e.description,withAsterisk:e.withAsterisk,error:G(e.outcome,e.htmlFor),"data-testid":e.testId,children:e.children})}import{capitalize as Fp,isEmpty as hf}from"@medplum/core";function ht(e,o,t,r,a){let n=r.type;if(n.length>1)for(let l of n){let f=o.replace("[x]",Fp(l.code));f in e&&delete e[f]}return e[t]=a,e}function cM(e){return!!e&&!hf(e.url)&&!hf(e.name)}import{Checkbox as kI,Group as BI,NativeSelect as AI,Textarea as MI,TextInput as on}from"@mantine/core";import{capitalize as as,PropertyType as w}from"@medplum/core";import{useState as FI}from"react";import{useState as wp}from"react";import{jsx as Lp}from"react/jsx-runtime";function yf(e){let[o,t]=wp(e.defaultValue);function r(a){let n=Ep(a);t(n),e.onChange&&e.onChange(n)}return Lp(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Op(o),maxSelectedValues:1,onChange:r})}function Op(e){return e.coding?.map(o=>({system:o.system,code:o.code,display:o.display}))}function Ep(e){if(e.length!==0)return{coding:e.map(o=>({system:o.system,code:o.code,display:o.display}))}}import{useState as Np}from"react";import{jsx as qp}from"react/jsx-runtime";function lr(e){let[o,t]=Np(e.defaultValue);function r(a){let n=a[0],l=n&&Hp(n);t(l),e.onChange&&e.onChange(l)}return qp(Mo,{binding:e.binding,name:e.name,placeholder:e.placeholder,defaultValue:o&&Vp(o),maxSelectedValues:1,onChange:r})}function Vp(e){return{system:e.system,code:e.code,display:e.display}}function Hp(e){return{system:e.system,code:e.code,display:e.display}}import{Group as $p,TextInput as _p}from"@mantine/core";import{useRef as Kp,useState as Zp}from"react";import{Group as Gp,NativeSelect as vf,TextInput as Up}from"@mantine/core";import{useContext as Qp,useMemo as zp,useRef as Wp,useState as Xp}from"react";import{jsx as za,jsxs as Jp}from"react/jsx-runtime";function fr(e){let{path:o,outcome:t}=e,{getModifiedNestedElement:r}=Qp(ke),[a,n]=Xp(e.defaultValue),l=Wp();l.current=a;let[f,i,s]=zp(()=>["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 Jp(Gp,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[za(vf,{"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:G(t,o+".system")}),za(vf,{"data-testid":"use",defaultValue:a?.use,required:(i?.min??0)>0,onChange:p=>d(p.currentTarget.value),data:["","home","work","temp","old","mobile"],error:G(t,o+".use")}),za(Up,{placeholder:"Value",defaultValue:a?.value,required:(s?.min??0)>0,onChange:p=>m(p.currentTarget.value),error:G(t,o+".value")})]})}import{jsx as Sf,jsxs as Yp}from"react/jsx-runtime";function Cf(e){let[o,t]=Zp(e.defaultValue),r=Kp();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 Yp($p,{spacing:"xs",grow:!0,noWrap:!0,children:[Sf(_p,{"data-testid":e.name+"-name",name:e.name+"-name",placeholder:"Name",style:{width:180},defaultValue:o?.name,onChange:f=>n(f.currentTarget.value)}),Sf(fr,{name:e.name+"-telecom",path:e.path+".telecom",defaultValue:o?.telecom?.[0],onChange:l,outcome:e.outcome})]})}import{TextInput as jp}from"@mantine/core";import{isValidDate as bf}from"@medplum/core";function Rf(e){if(!e)return"";let o=new Date(e);return bf(o)?o.toLocaleDateString("sv")+"T"+o.toLocaleTimeString("sv"):""}function Pf(e){if(!e)return"";let o=new Date(e);return bf(o)?o.toISOString():""}import{jsx as ox}from"react/jsx-runtime";function Be(e){return ox(jp,{id:e.name,name:e.name,"data-autofocus":e.autoFocus,"data-testid":e.name,placeholder:e.placeholder,required:e.required,type:ex(),defaultValue:Rf(e.defaultValue),autoFocus:e.autoFocus,error:G(e.outcome,e.name),onChange:o=>{if(e.onChange){let t=o.currentTarget.value;e.onChange(Pf(t))}}})}function ex(){return"datetime-local"}import{JsonInput as tx}from"@mantine/core";import{stringify as rx,tryGetProfile as ax}from"@medplum/core";import{useEffect as nx,useMemo as lx,useState as Tf}from"react";import{jsx as Wa,jsxs as Df}from"react/jsx-runtime";function kf(e){let{propertyType:o}=e,t=R(),[r,a]=Tf(!1),[n,l]=Tf(),f=lx(()=>{if(!(!o.profile||o.profile.length===0))return o.profile[0]},[o]);nx(()=>{f&&(a(!0),t.requestProfileSchema(f).then(()=>{let s=ax(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?Df("div",{children:["Loading ",f,"..."]}):n?Wa(Lo,{profileUrl:f,typeName:n.name,defaultValue:e.defaultValue,onChange:i}):Df("div",{children:["StructureDefinition for ",f," not found"]}):Wa(fx,{...e})}function fx(e){return Wa(tx,{id:e.name,name:e.name,"data-testid":"extension-json-input",defaultValue:rx(e.defaultValue),deserialize:JSON.parse,onChange:o=>{e.onChange&&e.onChange(JSON.parse(o))}})}import{Group as sx,NativeSelect as ix,TextInput as sr}from"@mantine/core";import{useState as ux}from"react";import{jsx as yt,jsxs as cx}from"react/jsx-runtime";function Bf(e){let{outcome:o,path:t}=e,[r,a]=ux(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 cx(sx,{spacing:"xs",grow:!0,noWrap:!0,children:[yt(ix,{defaultValue:r?.use,name:e.name+"-use","data-testid":"use",onChange:c=>l(c.currentTarget.value),data:["","temp","old","usual","official","nickname","anonymous","maiden"],error:G(o,t+".use")}),yt(sr,{placeholder:"Prefix",name:e.name+"-prefix",defaultValue:r?.prefix?.join(" "),onChange:c=>f(c.currentTarget.value),error:G(o,t+".prefix")}),yt(sr,{placeholder:"Given",name:e.name+"-given",defaultValue:r?.given?.join(" "),onChange:c=>i(c.currentTarget.value),error:G(o,t+".given")}),yt(sr,{name:e.name+"-family",placeholder:"Family",defaultValue:r?.family,onChange:c=>s(c.currentTarget.value),error:G(o,t+".family")}),yt(sr,{placeholder:"Suffix",name:e.name+"-suffix",defaultValue:r?.suffix?.join(" "),onChange:c=>u(c.currentTarget.value),error:G(o,t+".suffix")})]})}import{Group as dx,TextInput as Af}from"@mantine/core";import{useContext as mx,useMemo as px,useState as xx}from"react";import{jsx as Mf,jsxs as Ix}from"react/jsx-runtime";function Ff(e){let{path:o,outcome:t}=e,[r,a]=xx(e.defaultValue),{getModifiedNestedElement:n}=mx(ke),[l,f]=px(()=>["system","value"].map(s=>n(o+"."+s)),[n,o]);function i(s){a(s),e.onChange&&e.onChange(s)}return Ix(dx,{spacing:"xs",grow:!0,noWrap:!0,align:"flex-start",children:[Mf(Af,{placeholder:"System",required:(l?.min??0)>0,defaultValue:r?.system,onChange:s=>i({...r,system:s.currentTarget.value}),error:G(t,o+".system")}),Mf(Af,{placeholder:"Value",required:(f?.min??0)>0,defaultValue:r?.value,onChange:s=>i({...r,value:s.currentTarget.value}),error:G(t,o+".value")})]})}import{NativeSelect as gx,TextInput as hx}from"@mantine/core";import{useCallback as Xa,useState as yx}from"react";import{jsx as Ja}from"react/jsx-runtime";var vx=["USD","EUR","CAD","GBP","AUD"];function wf(e){let{onChange:o}=e,[t,r]=yx(e.defaultValue),a=Xa(i=>{r(i),o&&o(i)},[o]),n=Xa(i=>{a({...t,currency:i.currentTarget.value})},[t,a]),l=Xa(i=>{a({...t,value:i.currentTarget.valueAsNumber})},[t,a]),f=Ja(gx,{defaultValue:t?.currency,data:vx,styles:{input:{fontWeight:500,borderTopLeftRadius:0,borderBottomLeftRadius:0,width:92}},onChange:n});return Ja(hx,{type:"number",label:e.label,placeholder:e.placeholder??"Value",defaultValue:t?.value?.toString()??"USD",icon:Ja(va,{size:14}),rightSection:f,rightSectionWidth:92,onChange:l})}import{Group as Sx}from"@mantine/core";import{useState as Cx}from"react";import{jsx as Of,jsxs as bx}from"react/jsx-runtime";function Ef(e){let[o,t]=Cx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return bx(Sx,{spacing:"xs",grow:!0,noWrap:!0,children:[Of(Be,{name:e.name+".start",placeholder:"Start",defaultValue:o?.start,onChange:a=>r({...o,start:a})}),Of(Be,{name:e.name+".end",placeholder:"End",defaultValue:o?.end,onChange:a=>r({...o,end:a})})]})}import{Group as Rx,NativeSelect as Px,TextInput as Lf}from"@mantine/core";import{useState as Tx}from"react";import{jsx as $a,jsxs as kx}from"react/jsx-runtime";function Ce(e){let[o,t]=Tx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return kx(Rx,{spacing:"xs",grow:!0,noWrap:!0,children:[$a(Px,{style:{width:80},"data-testid":e.name+"-comparator",defaultValue:o?.comparator,data:["","<","<=",">=",">"],onChange:a=>r({...o,comparator:a.currentTarget.value})}),$a(Lf,{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:Dx(a.currentTarget.value)})}}),$a(Lf,{placeholder:"Unit","data-testid":e.name+"-unit",defaultValue:o?.unit,onChange:a=>r({...o,unit:a.currentTarget.value})})]})}function Dx(e){if(e)return parseFloat(e)}import{Group as Bx}from"@mantine/core";import{useState as Ax}from"react";import{jsx as Nf,jsxs as Mx}from"react/jsx-runtime";function vt(e){let[o,t]=Ax(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Mx(Bx,{spacing:"xs",grow:!0,noWrap:!0,children:[Nf(Ce,{name:e.name+"-low",defaultValue:o?.low,onChange:a=>r({...o,low:a})}),Nf(Ce,{name:e.name+"-high",defaultValue:o?.high,onChange:a=>r({...o,high:a})})]})}import{Group as Fx}from"@mantine/core";import{useState as wx}from"react";import{jsx as Vf,jsxs as Ox}from"react/jsx-runtime";function Hf(e){let[o,t]=wx(e.defaultValue);function r(a){t(a),e.onChange&&e.onChange(a)}return Ox(Fx,{spacing:"xs",grow:!0,noWrap:!0,children:[Vf(Ce,{name:e.name+"-numerator",defaultValue:o?.numerator,onChange:a=>r({...o,numerator:a})}),Vf(Ce,{name:e.name+"-denominator",defaultValue:o?.denominator,onChange:a=>r({...o,denominator:a})})]})}import{Group as zx,NativeSelect as Wx}from"@mantine/core";import{LRUCache as Xx,ReadablePromise as Jx,createReference as $x,isEmpty as _x,isPopulated as Kx,tryGetProfile as Zx}from"@medplum/core";import{useCallback as Yx,useEffect as jx,useMemo as zf,useRef as eI,useState as _a}from"react";import{Group as Ex,Text as qf}from"@mantine/core";import{getDisplayString as Lx,getReferenceString as Qf}from"@medplum/core";import{forwardRef as Nx,useCallback as Gf,useState as Vx}from"react";import{jsx as St,jsxs as Uf}from"react/jsx-runtime";var Hx={Observation:"code",User:"email:contains"},qx=["AccessPolicy","Account","ActivityDefinition","Bot","CapabilityStatement","ClientApplication","CodeSystem","CompartmentDefinition","ConceptMap","EffectEvidenceSynthesis","Endpoint","EventDefinition","Evidence","EvidenceVariable","ExampleScenario","GraphDefinition","HealthcareService","ImplementationGuide","InsurancePlan","Library","Location","Measure","MedicinalProduct","MessageDefinition","NamingSystem","OperationDefinition","Organization","Patient","Person","PlanDefinition","Practitioner","Project","Questionnaire","RelatedPerson","ResearchDefinition","ResearchElementDefinition","RiskEvidenceSynthesis","SearchParameter","StructureDefinition","StructureMap","TerminologyCapabilities","TestScript","UserConfiguration","ValueSet"];function Gx(e){return{value:Qf(e),label:Lx(e),resource:e}}function ir(e){let o=R(),{resourceType:t,searchCriteria:r}=e,[a,n]=Vx(),l=z(e.defaultValue,n),f=e.onChange,i=Gf(async(u,c)=>{let d=Qx(t),m=new URLSearchParams({[d]:u??"",_count:"10",...r});return await o.searchResources(t,m,{signal:c})},[o,t,r]),s=Gf(u=>{f&&f(u[0])},[f]);return e.defaultValue&&!a&&!l?null:St(Bo,{name:e.name,required:e.required,itemComponent:Ux,defaultValue:l,placeholder:e.placeholder,maxSelectedValues:1,toKey:Qf,toOption:Gx,loadOptions:i,onChange:s,clearable:!0})}var Ux=Nx(({label:e,resource:o,...t},r)=>St("div",{ref:r,...t,children:Uf(Ex,{noWrap:!0,children:[St(se,{value:o}),Uf("div",{children:[St(qf,{children:e}),St(qf,{size:"xs",color:"dimmed",children:o.birthDate})]})]})}));function Qx(e){return Hx[e]??(qx.includes(e)?"name":"_id")}import{jsx as Ka,jsxs as nI}from"react/jsx-runtime";function No(e){let{onChange:o}=e,t=R(),[r,a]=_a(e.defaultValue),[n,l]=_a(()=>oI(e.targetTypes)),[f,i]=_a(()=>tI(e.defaultValue,n)),s=eI(new Xx),u=zf(()=>f?.type==="profile"?{...e.searchCriteria,_profile:f.value}:e.searchCriteria,[e.searchCriteria,f]);jx(()=>{let m=!1,p=n?.map(x=>{if(!aI(x))return Promise.resolve(x);m=!0;let S=x.value,y=s.current.get(S);if(y)return y;let v=rI(t,x.value).then(T=>{let h={...x};return T?Kx(T.type)?(h.resourceType=T.type,h.name=T.name,h.title=T.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(T=>(console.error(T),{...x,error:T})),C=new Jx(v);return s.current.set(S,C),C});!p||!m||Promise.all(p).then(x=>{if(l(x),!f)return;let S=x.findIndex(y=>y.value===f.value||y.resourceType===f.resourceType);if(S===-1){console.debug(`defaultValue had unexpected resourceType: ${f.resourceType}`);return}i(x[S])}).catch(console.error)},[t,f,n]);let c=Yx(m=>{let p=m?$x(m):void 0;a(p),o&&o(p)},[o]),d=zf(()=>n?n.map(m=>({value:m.value,label:m.type==="profile"?m.title??m.name??m.resourceType??m.value:m.value})):[],[n]);return nI(zx,{spacing:"xs",grow:!0,noWrap:!0,children:[n&&n.length>1&&Ka(Wx,{"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(S=>S.value===p);i(x)},data:d}),!n&&Ka(Fo,{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"}),Ka(ir,{resourceType:f?.resourceType,name:e.name+"-id",required:e.required,placeholder:e.placeholder,defaultValue:r,searchCriteria:u,onChange:c})]})}function oI(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 tI(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 rI(e,o){let t=Zx(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 aI(e){return e.type==="profile"&&!e?.error&&_x(e.resourceType)}import{ActionIcon as Xf,Button as mI,Group as ur,Stack as Ya,createStyles as pI}from"@mantine/core";import{getPathDisplayName as xI,getPropertyDisplayName as II,isEmpty as ja,tryGetProfile as gI}from"@medplum/core";import{useEffect as hI,useState as Ct}from"react";import{arrayify as lI,getElementDefinitionFromElements as fI,getTypedPropertyValueWithSchema as sI,isPopulated as iI,matchDiscriminant as uI}from"@medplum/core";function cI(e,o,t){for(let r of[t.elements,t.typeSchema?.elements]){let a;if(iI(r)){let n=fI(r,o.path);n&&(a=sI(e.value,o.path,n))}if(a)return lI(a)?.some(n=>uI(n,o,t,r))??!1}return!1}function dI(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=>cI(a,n,r)))return r.name}}function Za(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=dI(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 Wf(e){return e.type!==void 0&&e.type.length>0}import{jsx as j,jsxs as cr}from"react/jsx-runtime";var Jf=pI(e=>({indented:{marginTop:"0.5rem",borderLeft:`3px solid ${e.colors.gray[4]}`,padding:"0.5rem 0 0.5rem 0.5rem"}}));function $f(e){let{property:o}=e,t=R(),[r,a]=Ct(!0),[n,l]=Ct([]),[f]=Ct(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[i,s]=Ct([[]]),{classes:u}=Jf(),c=o.type[0]?.code;hI(()=>{if(!o.slicing){let T=[];l(T);let h=Za(f,T,o.slicing);s(h),a(!1);return}let y=[],v=[],C=[];for(let T of o.slicing.slices){if(!Wf(T))continue;let h=T.type[0],M;ja(T.elements)&&h.profile&&(M=h.profile[0]),y.push(T),v.push(M),M?C.push(t.requestProfileSchema(M)):C.push(Promise.resolve())}Promise.all(C).then(()=>{for(let h=0;h<y.length;h++){let M=y[h],Q=v[h];if(Q){let Z=gI(Q);M.typeSchema=Z}}l(y);let T=Za(f,y,o.slicing);s(T),a(!1)}).catch(T=>{console.error(T),a(!1)})},[t,o.slicing,c,f]);function d(y,v){let C=[...i];if(C[v]=y,s(C),e.onChange){let T=C.flat().filter(h=>h!==void 0);e.onChange(T)}}if(r)return j("div",{children:"Loading..."});let m=n.length,p=i[m],x=!(e.hideNonSliceValues??(c==="Extension"&&n.length>0)),S=xI(o.path);return cr(Ya,{className:e.indent?u.indented:void 0,children:[n.map((y,v)=>j(yI,{slice:y,property:o,defaultValue:i[v],onChange:C=>{d(C,v)},testId:`slice-${y.name}`},y.name)),x&&p.map((y,v)=>cr(ur,{noWrap:!0,style:{flexGrow:1},children:[j("div",{style:{flexGrow:1},children:j(Ze,{arrayElement:!0,property:e.property,name:e.name+"."+v,defaultValue:y,onChange:C=>{let T=[...p];T[v]=C,d(T,m)},defaultPropertyType:void 0,outcome:e.outcome})}),j(Kf,{propertyDisplayName:S,testId:`nonsliced-remove-${v}`,onClick:C=>{E(C);let T=[...p];T.splice(v,1),d(T,m)}})]},`${v}-${p.length}`)),x&&i.flat().length<o.max&&j(ur,{noWrap:!0,style:{justifyContent:"flex-start"},children:j(_f,{propertyDisplayName:S,onClick:y=>{E(y);let v=[...p];v.push(void 0),d(v,m)},testId:"nonsliced-add"})})]})}function yI(e){let{slice:o,property:t}=e,[r,a]=Ct(()=>e.defaultValue.map(u=>u??{})),{classes:n}=Jf();function l(u){a(u),e.onChange&&e.onChange(u)}let f=o.min>0,i=ja(o.elements),s=II(o.name);return j(ie,{title:s,description:o.definition,withAsterisk:f,fhirPath:`${t.path}:${o.name}`,testId:e.testId,children:cr(Ya,{className:i?n.indented:void 0,children:[r.map((u,c)=>cr(ur,{noWrap:!0,children:[j("div",{style:{flexGrow:1},children:j(Ya,{children:ja(o.elements)?j(dr,{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}):j(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&&j(Kf,{propertyDisplayName:s,testId:e.testId&&`${e.testId}-remove-${c}`,onClick:d=>{E(d);let m=[...r];m.splice(c,1),l(m)}})]},`${c}-${r.length}`)),r.length<o.max&&j(ur,{noWrap:!0,style:{justifyContent:"flex-start"},children:j(_f,{propertyDisplayName:s,onClick:u=>{E(u);let c=[...r,void 0];l(c)},testId:e.testId&&`${e.testId}-add`})})]})})}function _f({propertyDisplayName:e,onClick:o,testId:t}){let r=e?`Add ${e}`:"Add";return e?j(mI,{title:r,size:"sm",color:"green.6",variant:"subtle","data-testid":t,leftIcon:j(so,{size:"1.25rem"}),onClick:o,children:r}):j(Xf,{title:r,color:"green.6","data-testid":t,onClick:o,children:j(so,{size:"1.25rem"})})}function Kf({propertyDisplayName:e,onClick:o,testId:t}){return j(Xf,{title:e?`Remove ${e}`:"Remove",color:"red.5","data-testid":t,onClick:o,children:j(Je,{size:"1.25rem"})})}import{Button as jf,Chip as Zf,Group as pr,Modal as vI,NativeSelect as SI,Stack as CI,Switch as bI,TextInput as RI}from"@mantine/core";import{formatTiming as PI}from"@medplum/core";import{useRef as es,useState as en}from"react";import{Fragment as ts,jsx as fe,jsxs as bt}from"react/jsx-runtime";var TI=["sun","mon","tue","wed","thu","fri","sat"];function os(e){let[o,t]=en(e.defaultValue),[r,a]=en(!1),n=es();return n.current=o,bt(ts,{children:[bt(pr,{spacing:"xs",grow:!0,noWrap:!0,children:[fe("span",{children:PI(n.current)||"No repeat"}),fe(jf,{onClick:()=>a(!0),children:"Edit"})]}),fe(DI,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var Yf={repeat:{period:1,periodUnit:"d"}};function DI(e){let[o,t]=en(e.defaultValue||Yf),r=es();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 fe(vI,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:bt(CI,{children:[fe(ie,{title:"Starts on",htmlFor:"timing-dialog-start",children:fe(Be,{name:"timing-dialog-start",onChange:s=>a(s)})}),fe(bI,{label:"Repeat",checked:!!o.repeat,onChange:s=>n(s.currentTarget.checked?Yf.repeat:void 0)}),o.repeat&&bt(ts,{children:[fe(ie,{title:"Repeat every",htmlFor:"timing-dialog-period",children:bt(pr,{spacing:"xs",grow:!0,noWrap:!0,children:[fe(RI,{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)}),fe(SI,{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"&&fe(ie,{title:"Repeat on",children:fe(Zf.Group,{multiple:!0,onChange:i,children:fe(pr,{position:"apart",mt:"md",spacing:"xs",children:TI.map(s=>fe(Zf,{value:s,size:"xs",radius:"xl",children:s.charAt(0).toUpperCase()},s))})})})]}),fe(pr,{position:"right",children:fe(jf,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as V,jsxs as EI}from"react/jsx-runtime";function Ze(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===w.Attachment)return V(of,{name:t,defaultValue:r,onChange:a});let f=l[0]?.code!==w.Extension;return V($f,{property:o,name:t,defaultValue:r,indent:f,onChange:a,outcome:e.outcome})}return l.length>1?V(wI,{elementDefinitionTypes:l,...e}):V(dr,{name:t,defaultValue:r,onChange:f=>{if(e.onChange){let i=e.name.replace("[x]",as(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 wI(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=FI(t);return EI(BI,{spacing:"xs",grow:!0,noWrap:!0,children:[V(AI,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(l=>l.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),V(dr,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",as(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path})]})}function dr(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 V("div",{children:"Property type not specified "});let s={name:o,defaultValue:t,onChange:r,outcome:a,path:l};switch(i){case w.SystemString:case w.canonical:case w.string:case w.time:case w.uri:case w.url:return V(on,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case w.date:return V(on,{type:"date",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case w.dateTime:case w.instant:return V(Be,{name:o,defaultValue:t,onChange:r,outcome:a});case w.decimal:case w.integer:case w.positiveInt:case w.unsignedInt:return V(on,{type:"number",step:i===w.decimal?"any":"1",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.valueAsNumber)}});case w.code:return V(_t,{...s,binding:n?.valueSet});case w.boolean:return V(kI,{id:o,name:o,"data-testid":o,defaultChecked:!!t,onChange:u=>{r&&r(u.currentTarget.checked)}});case w.base64Binary:case w.markdown:return V(MI,{id:o,spellCheck:i!==w.base64Binary,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)}});case w.Address:return V(Pl,{...s});case w.Annotation:return V(Tl,{...s});case w.Attachment:return V(Zt,{...s});case w.CodeableConcept:return V(yf,{binding:n?.valueSet,...s});case w.Coding:return V(lr,{binding:n?.valueSet,...s});case w.ContactDetail:return V(Cf,{...s});case w.ContactPoint:return V(fr,{...s});case w.Extension:return V(kf,{...s,propertyType:e.elementDefinitionType});case w.HumanName:return V(Bf,{...s});case w.Identifier:return V(Ff,{...s});case w.Money:return V(wf,{...s});case w.Period:return V(Ef,{...s});case w.Duration:case w.Quantity:return V(Ce,{...s});case w.Range:return V(vt,{...s});case w.Ratio:return V(Hf,{...s});case w.Reference:return V(No,{...s,targetTypes:OI(e.elementDefinitionType)});case w.Timing:return V(os,{...s});case w.Dosage:case w.UsageContext:default:return V(Lo,{typeName:i,defaultValue:t,onChange:r,outcome:a})}}var rs="http://hl7.org/fhir/StructureDefinition/";function OI(e){return e?.targetProfile?.map(o=>o.startsWith(rs)?o.slice(rs.length):o)}import{jsx as xr}from"react/jsx-runtime";var tn=new Set(["extension","modifierExtension"]),qI=new Set(["id",...Yt].filter(e=>!tn.has(e)));function mr(e){let{elements:o}=e,[t,r]=HI(e.defaultValue??{}),a=VI(()=>{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))ht(l,f,f,i,i.fixed.value);r(l),e.onChange&&e.onChange(l)}return xr(LI,{style:{flexGrow:1},"data-testid":e.testId,children:Object.entries(o).map(([l,f])=>{if(!f.type||f.max===0||l==="url"&&f.fixed||tn.has(l)&&!NI(f.slicing?.slices))return null;if(qI.has(l))return null;if(jt.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=xr(Ze,{property:f,name:l,defaultValue:i,defaultPropertyType:s,onChange:(d,m)=>{n(ht({...t},l,m??l,f,d))},arrayElement:void 0,outcome:e.outcome},l);return e.type==="Extension"||tn.has(l)?c:f.type.length===1&&f.type[0].code==="boolean"?xr(ar,{title:ns(l),description:f.description,htmlFor:l,fhirPath:f.path,withAsterisk:u,children:c},l):xr(ie,{title:ns(l),description:f.description,withAsterisk:u,htmlFor:l,outcome:e.outcome,fhirPath:f.path,children:c},l)})})}import{jsx as fs,jsxs as zI}from"react/jsx-runtime";function Lo(e){let{typeName:o}=e,[t,r]=QI(e.defaultValue??{}),a=UI(ke),n=e.profileUrl??a.profileUrl,l=ls(()=>GI(o,n),[o,n]),f=ls(()=>If(l,n),[l,n]);if(!l)return zI("div",{children:[o,"\xA0not implemented"]});function i(s){r(s),e.onChange&&e.onChange(s)}return fs(ke.Provider,{value:f,children:fs(mr,{type:l.type,elements:l.elements,defaultValue:t,onChange:i,outcome:e.outcome})})}import{Button as rn,createStyles as WI,Group as is}from"@mantine/core";import{useMemo as XI,useState as JI}from"react";function ss(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function Ir(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as ue,jsxs as Rt}from"react/jsx-runtime";var $I=WI(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 us(e){let{classes:o}=$I(),{onChangeMonth:t,onClick:r}=e,[a,n]=JI(Ir);function l(i){n(s=>{let u=new Date(s.getTime());return u.setMonth(s.getMonth()+i),t(u),u})}let f=XI(()=>_I(a,e.slots),[a,e.slots]);return Rt("div",{children:[Rt(is,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[ue("p",{style:{flex:1},children:ss(a)}),Rt(is,{position:"right",spacing:"xs",children:[ue(rn,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),ue(rn,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),Rt("table",{className:o.table,children:[ue("thead",{children:Rt("tr",{children:[ue("th",{children:"SUN"}),ue("th",{children:"MON"}),ue("th",{children:"TUE"}),ue("th",{children:"WED"}),ue("th",{children:"THU"}),ue("th",{children:"FRI"}),ue("th",{children:"SAT"})]})}),ue("tbody",{children:f.map((i,s)=>ue("tr",{children:i.map((u,c)=>ue("td",{children:u&&ue(rn,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+c))},"week-"+s))})]})]})}function _I(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:KI(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 KI(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 ZI,createStyles as YI}from"@mantine/core";import{jsx as eg}from"react/jsx-runtime";var jI=YI(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Ye(e){let{children:o,...t}=e,{classes:r}=jI();return eg(ZI,{className:r.root,...t,children:o})}import{ActionIcon as Ws,Center as ch,createStyles as dh,Group as mh,Loader as ph,Menu as Ge,ScrollArea as xh,TextInput as Ih}from"@mantine/core";import{showNotification as gh,updateNotification as Cr}from"@mantine/notifications";import{getReferenceString as Dt,normalizeErrorString as Xs}from"@medplum/core";import{useCallback as br,useEffect as hh,useRef as Js,useState as $s}from"react";import{createStyles as xg,Group as hr,List as ps,Stack as xs,Text as be,Title as Is}from"@mantine/core";import{capitalize as Ig,formatCodeableConcept as gg,formatDateTime as nn,formatObservationValue as hg,isReference as yg}from"@medplum/core";import{useEffect as vg,useState as Sg}from"react";import{Blockquote as og,createStyles as tg,Stack as rg}from"@mantine/core";import{jsx as cs}from"react/jsx-runtime";var ag=tg(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function an({value:e}){let{classes:o}=ag();return e?cs(rg,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&cs(og,{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 ug}from"@mantine/core";import{Text as ng}from"@mantine/core";import{getDisplayString as lg,isOk as fg,normalizeErrorString as sg}from"@medplum/core";import{useState as ig}from"react";import{jsx as ds}from"react/jsx-runtime";function Fe(e){let{value:o,link:t,...r}=e,[a,n]=ig(),l=z(o,n),f;if(a&&!fg(a))f=`[${sg(a)}]`;else if(l)f=lg(l);else return null;return t?ds(te,{to:o,...r,children:f}):ds(ng,{component:"span",...r,children:f})}import{jsx as ms,jsxs as cg}from"react/jsx-runtime";function je(e){return cg(ug,{spacing:"xs",children:[ms(se,{size:24,radius:12,value:e.value,link:e.link}),ms(Fe,{value:e.value,link:e.link})]})}import{Badge as dg}from"@mantine/core";import{jsx as pg}from"react/jsx-runtime";var mg={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 gr(e){return pg(dg,{color:mg[e.status],children:e.status})}import{Fragment as Pt,jsx as D,jsxs as ce}from"react/jsx-runtime";var gs=xg(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}}));ln.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function ln(e){let o=R(),t=z(e.value),[r,a]=Sg();if(vg(()=>{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 ce(xs,{children:[D(Is,{children:"Diagnostic Report"}),D(Cg,{value:t}),r&&!e.hideSpecimenInfo&&bg(r),t.result&&D(Rg,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&D(an,{value:n})]})}function Cg({value:e}){return ce(hr,{mt:"md",spacing:30,children:[e.subject&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),D(be,{children:D(je,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),D(be,{children:D(je,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),D(be,{children:D(je,{value:o,link:!0})})]},o.reference)),e.issued&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),D(be,{children:nn(e.issued)})]}),e.status&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),D(be,{children:Ig(e.status)})]})]})}function bg(e){return ce(xs,{spacing:"xs",children:[D(Is,{order:2,size:"h6",children:"Specimens"}),D(ps,{type:"ordered",children:e?.map(o=>D(ps.Item,{ml:"sm",children:ce(hr,{spacing:20,children:[ce(hr,{spacing:5,children:[D(be,{fw:500,children:"Collected:"})," ",nn(o.collection?.collectedDateTime)]}),ce(hr,{spacing:5,children:[D(be,{fw:500,children:"Received:"})," ",nn(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Rg(e){let{classes:o}=gs();return ce("table",{className:o.table,children:[D("thead",{children:ce("tr",{children:[D("th",{children:"Test"}),D("th",{children:"Value"}),D("th",{children:"Reference Range"}),D("th",{children:"Interpretation"}),D("th",{children:"Category"}),D("th",{children:"Performer"}),D("th",{children:"Status"})]})}),D("tbody",{children:D(hs,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function hs(e){return D(Pt,{children:e.value?.map(o=>D(Pg,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${yg(o)?o.reference:o.id}`))})}function Pg(e){let{classes:o,cx:t}=gs(),r=z(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=kg(r);return ce(Pt,{children:[ce("tr",{className:t({[o.criticalRow]:n}),children:[D("td",{rowSpan:a?2:1,children:D(te,{to:r,children:D(Oo,{value:r.code})})}),D("td",{children:D(Tg,{value:r})}),D("td",{children:D(Dg,{value:r.referenceRange})}),D("td",{children:r.interpretation&&r.interpretation.length>0&&D(Oo,{value:r.interpretation[0]})}),D("td",{children:r.category&&r.category.length>0&&D(Pt,{children:r.category.map(l=>D("div",{children:D(Oo,{value:l})},`category-${gg(l)}`))})}),D("td",{children:r.performer?.map(l=>D(po,{value:l},l.reference))}),D("td",{children:r.status&&D(gr,{status:r.status})})]}),r.hasMember&&D(hs,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&D("tr",{children:D("td",{colSpan:6,children:D(an,{value:r.note})})})]})}function Tg(e){let o=e.value;return D(Pt,{children:hg(o)})}function Dg(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?D(Pt,{children:o.text}):D(or,{value:o}):null}function kg(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as Bg,Paper as Ag,useComponentDefaultProps as Mg}from"@mantine/core";import{jsx as Og}from"react/jsx-runtime";var Fg=Bg((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%"}}})),wg={shadow:"xs",radius:"md",withBorder:!0};function Vo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Mg("Panel",wg,e),{classes:f,cx:i}=Fg({width:r,fill:a},{name:"Panel",unstyled:n});return Og(Ag,{className:i(f.paper,o),...l,children:t})}import{createStyles as Kg}from"@mantine/core";import{capitalize as Zg,evalFhirPathTyped as Os,getSearchParameterDetails as Yg,toTypedValue as Es}from"@medplum/core";var Ns=sc(ws(),1);import{useEffect as jg,useState as eh}from"react";import{jsx as qe,jsxs as Sr}from"react/jsx-runtime";var oh=Kg(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 Vs(e){let{classes:o}=oh(),t=R(),[r,a]=eh(!1);if(jg(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,Ns.createPatch)(e.original,e.revised),l=[Es(e.original)],f=[Es(e.revised)];return Sr("table",{className:o.root,children:[qe("thead",{children:Sr("tr",{children:[qe("th",{}),qe("th",{children:"Before"}),qe("th",{children:"After"})]})}),qe("tbody",{children:n.map(i=>{if(i.path.startsWith("/meta"))return null;let s=i.path,u=th(s),d=Yg(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:Os(u,l)?.[0],x=i.op==="remove"?void 0:Os(u,f)?.[0];return Sr("tr",{children:[Sr("td",{children:[Zg(i.op)," ",u]}),qe("td",{className:o.removed,children:p&&qe(le,{property:d,propertyType:p.type,value:Ls(p.value,m),ignoreMissingValues:!0})}),qe("td",{className:o.added,children:x&&qe(le,{property:d,propertyType:x.type,value:Ls(x.value,m),ignoreMissingValues:!0})})]},`op-${i.op}-${i.path}`)})})]})}function th(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 Ls(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as rh,useState as ah}from"react";import{jsx as nh}from"react/jsx-runtime";function yn(e){let o=R(),t=z(e.value),[r,a]=ah(!1);return rh(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:nh(gt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as lh,Group as fh,Menu as Hs,Text as vn}from"@mantine/core";import{formatDateTime as sh,getReferenceString as ih}from"@medplum/core";import{Fragment as uh,jsx as Re,jsxs as Ho}from"react/jsx-runtime";function qs(e){return Re(Ye,{children:e.children})}function eo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,f=e.dateTime??o.meta?.lastUpdated;return Ho(Vo,{"data-testid":"timeline-item",fill:!0,...n,children:[Ho(fh,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Re(se,{value:l,link:!0,size:"md"}),Ho("div",{style:{flex:1},children:[Re(vn,{size:"sm",children:Re(Fe,{color:"dark",weight:500,value:l,link:!0})}),Ho(vn,{size:"xs",children:[Re(te,{color:"dimmed",to:e.resource,children:sh(f)}),Re(vn,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Re(te,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&Ho(Hs,{position:"bottom-end",shadow:"md",width:200,children:[Re(Hs.Target,{children:Re(lh,{radius:"xl","aria-label":`Actions for ${ih(e.resource)}`,children:Re(Sa,{})})}),a]})]}),Ho(Do,{children:[r&&Re("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Re(uh,{children:e.children})]})]})}function Qs(e,o){e.sort((t,r)=>{let a=Gs(t,o),n=Gs(r,o);return a>n?1:a<n?-1:Us(t,o)-Us(r,o)})}function Gs(e,o){if(!zs(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Us(e,o){if(!zs(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 zs(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as Dh,jsx as k,jsxs as kt}from"react/jsx-runtime";var yh=dh(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function oo(e){let o=R(),t=Xe(),r=o.getProfile(),a=Js(null),n=z(e.value),[l,f]=$s(),[i,s]=$s([]),u=e.loadTimelineResources,c=Js(i);c.current=i;let d=br(b=>{Qs(b,n),b.reverse(),s(b)},[n]),m=br(b=>{let L=[];for(let We of b){if(We.status!=="fulfilled")continue;let P=We.value;if(P.type==="history"&&f(P),P.entry)for(let H of P.entry)L.push(H.resource)}d(L)},[d]),p=br(b=>d([...c.current,b]),[d]),x=br(()=>{let b,L;"resourceType"in e.value?(b=e.value.resourceType,L=e.value.id):[b,L]=e.value.reference?.split("/"),u(o,b,L).then(m).catch(console.log)},[o,e.value,u,m]);hh(()=>x(),[x]);function S(b){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,b)).then(L=>p(L)).catch(console.log)}function y(b){!n||!e.createMedia||o.createResource(e.createMedia(n,r,b)).then(L=>p(L)).then(()=>Cr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:k(st,{size:16}),autoClose:2e3})).catch(L=>Cr({id:"upload-notification",color:"red",title:"Upload error",message:Xs(L),icon:k(Qt,{size:16}),autoClose:2e3}))}function v(b,L){return o.updateResource({...b,priority:L})}function C(b){v(b,"stat").then(x).catch(console.log)}function T(b){v(b,"routine").then(x).catch(console.log)}function h(b){t(`/${b.resourceType}/${b.id}`)}function M(b){t(`/${b.resourceType}/${b.id}/edit`)}function Q(b){t(`/${b.resourceType}/${b.id}/delete`)}function Z(b){t(`/${b.resourceType}/${b.id}/_history/${b.meta?.versionId}`)}function tt(){gh({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function ye(b){Cr({id:"upload-notification",loading:!0,title:"Uploading...",message:Th(b),autoClose:!1,withCloseButton:!1})}function ve(b){Cr({id:"upload-notification",color:"red",title:"Upload error",message:Xs(b),icon:k(Qt,{size:16}),autoClose:2e3})}return n?kt(qs,{children:[e.createCommunication&&k(Vo,{children:k(J,{testid:"timeline-form",onSubmit:b=>{S(b.text);let L=a.current;L&&(L.value="",L.focus())},children:kt(mh,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[k(se,{value:r}),k(Ih,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),k(Ws,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:k(Da,{size:16})}),k(wo,{onUpload:y,onUploadStart:tt,onUploadProgress:ye,onUploadError:ve,children:b=>k(Ws,{...b,radius:"xl",color:"blue",variant:"filled",children:k(it,{size:16})})})]})})}),i.map(b=>{if(!b)return null;let L=`${b.resourceType}/${b.id}/${b.meta?.versionId}`;if(b.resourceType===n.resourceType&&b.id===n.id)return k(vh,{history:l,resource:b,onDetails:Z},L);switch(b.resourceType){case"AuditEvent":return k(Rh,{resource:b,onDetails:h},L);case"Communication":return k(Ch,{resource:b,onPin:b.priority!=="stat"?C:void 0,onUnpin:b.priority==="stat"?T:void 0,onDetails:h,onEdit:M,onDelete:Q},L);case"DiagnosticReport":return k(Ph,{resource:b,onDetails:h,onEdit:M,onDelete:Q},L);case"Media":return k(bh,{resource:b,onDetails:h,onEdit:M,onDelete:Q},L);default:return k(eo,{resource:b,padding:!0,children:k(yn,{value:b,ignoreMissingValues:!0})},L)}})]}):k(ch,{style:{width:"100%",height:"100%"},children:k(ph,{})})}function qo(e){return kt(Ge.Dropdown,{children:[k(Ge.Label,{children:"Resource"}),e.onPin&&k(Ge.Item,{icon:k(ka,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Dt(e.resource)}`,children:"Pin"}),e.onUnpin&&k(Ge.Item,{icon:k(Ba,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Dt(e.resource)}`,children:"Unpin"}),e.onDetails&&k(Ge.Item,{icon:k(Pa,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Dt(e.resource)}`,children:"Details"}),e.onEdit&&k(Ge.Item,{icon:k(Ca,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Dt(e.resource)}`,children:"Edit"}),e.onDelete&&kt(Dh,{children:[k(Ge.Divider,{}),k(Ge.Label,{children:"Danger zone"}),k(Ge.Item,{color:"red",icon:k(dt,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Dt(e.resource)}`,children:"Delete"})]})]})}function vh(e){let o=Sh(e.history,e.resource);return o?k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(Vs,{original:o,revised:e.resource})}):kt(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:[k("h3",{children:"Created"}),k(yn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function Sh(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 Ch(e){let{classes:o}=yh(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return k(eo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:k(qo,{...e}),children:k("p",{children:e.resource.payload?.[0]?.contentString})})}function bh(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return k(eo,{resource:e.resource,padding:!!t,popupMenuItems:k(qo,{...e}),children:k(Me,{value:e.resource.content})})}function Rh(e){return k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(xh,{children:k("pre",{children:e.resource.outcomeDesc})})})}function Ph(e){return k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(ln,{value:e.resource})})}function Th(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Sn(e.loaded)} / ${Sn(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Sn(e.loaded)}`}function Sn(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as kh}from"react/jsx-runtime";function r0(e){return kh(oo,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as _s}from"react/jsx-runtime";function Rr(e){let{children:o,...t}=e;return _s(Ye,{children:_s(Vo,{...t,children:o})})}import{createReference as Pr}from"@medplum/core";import{jsx as Bh}from"react/jsx-runtime";function x0(e){return Bh(oo,{value:e.encounter,loadTimelineResources:async(o,t,r)=>Promise.allSettled([o.readHistory("Encounter",r),o.search("Communication","encounter=Encounter/"+r),o.search("Media","encounter=Encounter/"+r)]),createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",encounter:Pr(o),subject:o.subject,sender:Pr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:Pr(o),subject:o.subject,operator:Pr(t),issued:new Date().toISOString(),content:r})})}import{Button as $y,Loader as _y,Table as Ky}from"@mantine/core";import{normalizeOperationOutcome as Zy}from"@medplum/core";import{memo as Yy,useEffect as Ai,useRef as Mi,useState as wr}from"react";import{evalFhirPath as Ah}from"@medplum/core";import{jsx as Mh}from"react/jsx-runtime";function Ks(e){let o;try{o=Ah(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 Mh(le,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as My,Button as Wo,Center as Mr,createStyles as Fy,Group as Fr,Loader as wy,Menu as Di,Pagination as Oy,Table as Ey,Text as Fn,UnstyledButton as Ly}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as Ln,formatSearchQuery as Ny}from"@medplum/core";import{memo as Vy,useCallback as ki,useEffect as Bi,useRef as Hy,useState as wn}from"react";import{Box as Fh,Button as wh,Modal as Oh,Text as Eh}from"@mantine/core";import{jsx as Tr,jsxs as Ys}from"react/jsx-runtime";function js(e){return Ys(Oh,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Ys(Fh,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&Tr(Zs,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&Tr(Zs,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),Tr(Eh,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function Zs(e){return Tr(wh,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as Xh,Group as Jh,Modal as $h,MultiSelect as _h,Stack as Kh}from"@mantine/core";import{getDataType as Zh,getSearchParameters as Yh,stringify as jh}from"@medplum/core";import{useEffect as ey,useMemo as oy,useRef as ty,useState as pi}from"react";import{capitalize as Lh,DEFAULT_SEARCH_COUNT as Nh,evalFhirPathTyped as Vh,formatDateTime as Hh,Operator as F}from"@medplum/core";import{Fragment as Wh,jsx as Cn}from"react/jsx-runtime";var qh={string:[F.EQUALS,F.NOT,F.CONTAINS,F.EXACT],fulltext:[F.EQUALS,F.NOT,F.CONTAINS,F.EXACT],token:[F.EQUALS,F.NOT],reference:[F.EQUALS,F.NOT],numeric:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS],quantity:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS],date:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS,F.STARTS_AFTER,F.ENDS_BEFORE,F.APPROXIMATELY],datetime:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS,F.STARTS_AFTER,F.ENDS_BEFORE,F.APPROXIMATELY]},Gh={eq:"equals",ne:"not equals",gt:"greater than",lt:"less than",ge:"greater than or equals",le:"less than or equals",sa:"starts after",eb:"ends before",ap:"approximately",contains:"contains",exact:"exact",text:"text",not:"not",above:"above",below:"below",in:"in","not-in":"not in","of-type":"of type",missing:"missing",identifier:"identifier",iterate:"iterate"};function Bt(e,o){return{...e,filters:o,offset:0,name:void 0}}function M0(e){return Bt(e,[])}function Dr(e,o){return Bt(e,(e.filters??[]).filter(t=>t.code!==o))}function Go(e,o,t,r,a){a&&(e=Dr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Bt(e,n)}function F0(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 oi(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function ti(e,o){return bn(e,o,-1)}function ri(e,o){return bn(e,o,0)}function ai(e,o){return bn(e,o,1)}function bn(e,o,t){let r=new Date;r.setDate(r.getDate()+t),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setDate(a.getDate()+1),a.setTime(a.getTime()-1),Pn(e,o,r,a)}function ni(e,o){return Rn(e,o,-1)}function li(e,o){return Rn(e,o,0)}function fi(e,o){return Rn(e,o,1)}function Rn(e,o,t){let r=new Date;r.setMonth(r.getMonth()+t),r.setDate(1),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setMonth(a.getMonth()+1),a.setDate(1),a.setHours(0,0,0,0),a.setTime(a.getTime()-1),Pn(e,o,r,a)}function si(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Pn(e,o,t,new Date)}function Pn(e,o,t,r){return e=Dr(e,o),e=ei(e,o,F.GREATER_THAN_OR_EQUALS,t),e=ei(e,o,F.LESS_THAN_OR_EQUALS,r),e}function ei(e,o,t,r){return Go(e,o,t,r.toISOString())}function Tn(e,o,t=!0){return Go(e,o,F.MISSING,t.toString())}function Uh(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function ii(e,o){let t=e.count??Nh,r=(o-1)*t;return Uh(e,r)}function Dn(e,o,t){return o===ui(e)&&t!==void 0&&t===ci(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function w0(e,o){let t=!1;return ui(e)===o&&(t=!ci(e)),Dn(e,o,t)}function ui(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function ci(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function di(e){return qh[e.type]}function At(e){return Gh[e]??""}function Pe(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(Lh).join(" "))}function mi(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?Hh(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?Qh(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?zh(e,o.searchParams[0]):null}function Qh(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=Ke({type:e.resourceType,value:e},t);return r?Cn(le,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function zh(e,o){let t=Vh(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:Cn(Wh,{children:t.map((r,a)=>Cn(le,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as Mt,jsxs as ay}from"react/jsx-runtime";function xi(e){let o=ty(!1),[t,r]=pi({search:JSON.parse(jh(e.search))}),[a,n]=pi(!1);ey(()=>{r({search:e.search})},[e.search]);let l=oy(()=>{if(!e.visible)return[];let i=e.search.resourceType,s=Zh(i),u=Yh(i);return ry(s,u).sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:Pe(c)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function f(i){r({search:{...t.search,fields:i}})}return Mt($h,{title:"Fields",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>{e.onCancel()},size:"auto",withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{o.current=a},onClick:()=>{o.current||e.onCancel(),o.current=!1},children:Mt("div",{"data-testid":"overlay-child"})},children:ay(Kh,{children:[Mt(_h,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:l,value:t.search.fields??[],onChange:f,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),Mt(Jh,{position:"right",children:Mt(Xh,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function ry(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(Pe(n));if(o)for(let n of Object.keys(o)){let l=Pe(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as Ft,Group as dy,Modal as my,NativeSelect as hi}from"@mantine/core";import{getSearchParameters as py,stringify as yi}from"@medplum/core";import{useEffect as xy,useRef as Si,useState as An}from"react";import{formatDateTime as ny,getSearchParameterDetails as ly,globalSchema as fy,Operator as Ii,SearchParameterType as sy}from"@medplum/core";import{Fragment as gi,jsx as kn}from"react/jsx-runtime";function kr(e){let{resourceType:o,filter:t}=e,r=fy.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===Ii.EQUALS||t.operator===Ii.NOT_EQUALS))return kn(Fe,{value:{reference:t.value}});let a=ly(o,r);if(t.code==="_lastUpdated"||a.type===sy.DATETIME)return kn(gi,{children:ny(t.value)})}return kn(gi,{children:t.value})}import{Checkbox as iy,TextInput as Bn}from"@mantine/core";import{getSearchParameterDetails as uy,SearchParameterType as Uo}from"@medplum/core";import{jsx as xo}from"react/jsx-runtime";function Br(e){let o=uy(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case Uo.REFERENCE:return xo(No,{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 Uo.BOOLEAN:return xo(iy,{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 Uo.DATE:return xo(Bn,{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 Uo.DATETIME:return xo(Be,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case Uo.NUMBER:return xo(Bn,{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 Uo.QUANTITY:return xo(Ce,{name:t,defaultValue:cy(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return xo(Bn,{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 cy(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as U,jsxs as Ue}from"react/jsx-runtime";function Ci(e){let[o,t]=An(JSON.parse(yi(e.search))),[r,a]=An(-1),n=Si(o);n.current=o,xy(()=>{t(JSON.parse(yi(e.search)))},[e.search]);function l(u){t(Go(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let f=e.search.resourceType,i=py(f)??{},s=o.filters||[];return Ue(my,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[U("div",{children:Ue("table",{children:[Ue("colgroup",{children:[U("col",{style:{width:200}}),U("col",{style:{width:200}}),U("col",{style:{width:380}}),U("col",{style:{width:120}})]}),U("thead",{children:Ue("tr",{children:[U("th",{children:"Field"}),U("th",{children:"Operation"}),U("th",{children:"Value"}),U("th",{children:"Actions"})]})}),Ue("tbody",{children:[s.map((u,c)=>c===r?U(vi,{resourceType:f,searchParams:i,defaultValue:u,okText:"Save",onOk:d=>{let m=[...s];m[c]=d,t(Bt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):U(Iy,{resourceType:f,searchParams:i,filter:u,onEdit:()=>a(c),onDelete:()=>t(oi(n.current,c))},`filter-${u.code}-${u.operator}-${u.value}-display`)),U(vi,{resourceType:f,searchParams:i,okText:"Add",onOk:l})]})]})}),U(dy,{position:"right",mt:"xl",children:U(Ft,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function Iy(e){let{filter:o}=e;return Ue("tr",{children:[U("td",{children:Pe(o.code)}),U("td",{children:At(o.operator)}),U("td",{children:U(kr,{resourceType:e.resourceType,filter:o})}),Ue("td",{children:[U(Ft,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),U(Ft,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function vi(e){let[o,t]=An(e.defaultValue??{}),r=Si(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&&di(f);return Ue("tr",{children:[U("td",{children:U(hi,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:s=>a(s.currentTarget.value),data:["",...Object.keys(e.searchParams).map(s=>({value:s,label:Pe(s)}))]})}),U("td",{children:i&&U(hi,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:s=>n(s.currentTarget.value),data:["",...i.map(s=>({value:s,label:At(s)}))]})}),U("td",{children:f&&o.operator&&U(Br,{resourceType:e.resourceType,searchParam:f,defaultValue:o.value,onChange:l})}),Ue("td",{children:[o.code&&o.operator&&U(Ft,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&U(Ft,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as gy,Grid as Mn,Modal as hy}from"@mantine/core";import{useState as yy}from"react";import{jsx as Qo,jsxs as vy}from"react/jsx-runtime";function bi(e){let[o,t]=yy(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return Qo(hy,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:Qo(J,{onSubmit:r,children:vy(Mn,{children:[Qo(Mn.Col,{span:10,children:Qo(Br,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),Qo(Mn.Col,{span:2,children:Qo(gy,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as B}from"@mantine/core";import{Operator as re}from"@medplum/core";import{Fragment as Pi,jsx as g,jsxs as zo}from"react/jsx-runtime";function Ri(e){if(!e.searchParams)return null;function o(n,l){a(Dn(e.search,n.code,l))}function t(n){a(Dr(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(Sy,{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:Pe(n.code)},n.code))})}function Sy(e){switch(e.searchParam.type){case"date":return g(Cy,{...e});case"number":case"quantity":return g(by,{...e});case"reference":return g(Ry,{...e});case"string":case"token":case"uri":return g(Py,{...e});default:return zo(Pi,{children:["Unknown search param type: ",e.searchParam.type]})}}function Cy(e){let{searchParam:o}=e,t=o.code;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,re.ENDS_BEFORE),children:"Before..."}),g(B.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,re.STARTS_AFTER),children:"After..."}),g(B.Item,{icon:g(ma,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Between..."}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ai(e.search,t)),children:"Tomorrow"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ri(e.search,t)),children:"Today"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ti(e.search,t)),children:"Yesterday"}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(fi(e.search,t)),children:"Next Month"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(li(e.search,t)),children:"This Month"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ni(e.search,t)),children:"Last Month"}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(si(e.search,t)),children:"Year to date"}),g(Ar,{...e})]})}function by(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,re.GREATER_THAN),children:"Greater than..."}),g(B.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,re.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),g(B.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,re.LESS_THAN),children:"Less than..."}),g(B.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,re.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),g(Ar,{...e})]})}function Ry(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT),children:"Does not equal..."}),g(Ar,{...e})]})}function Py(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(xa,{size:14}),onClick:()=>e.onPrompt(o,re.CONTAINS),children:"Contains..."}),g(B.Item,{icon:g(pa,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Does not contain..."}),g(Ar,{...e})]})}function Ar(e){let{searchParam:o}=e,t=o.code;return zo(Pi,{children:[g(B.Divider,{}),g(B.Item,{icon:g(ca,{size:14}),onClick:()=>e.onChange(Tn(e.search,t)),children:"Missing"}),g(B.Item,{icon:g(ua,{size:14}),onClick:()=>e.onChange(Tn(e.search,t,!1)),children:"Not missing"}),g(B.Divider,{}),g(B.Item,{icon:g(La,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Ty,getSearchParameter as Dy,getSearchParameterDetails as ky,getSearchParameters as By}from"@medplum/core";function Ti(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(Ay(o,r));return t}function Ay(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=Ty(e,o),r=Dy(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=By(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=ky(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as Jy,jsx as A,jsxs as he}from"react/jsx-runtime";var On=class extends Event{constructor(t){super("change");this.definition=t}},En=class extends Event{constructor(t){super("load");this.response=t}},Io=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},qy=Fy(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 Gy(e){let{classes:o}=qy(),t=R(),[r,a]=wn(!1),[n,l]=wn(),{search:f,onLoad:i}=e,[s,u]=wn({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),c=Hy(s);c.current=s;let d=f.total??"accurate",m=ki(P=>{l(void 0),t.search(f.resourceType,Ny({...f,total:d,fields:void 0}),P).then(H=>{u({...c.current,searchResponse:H}),i&&i(new En(H))}).catch(H=>{u({...c.current,searchResponse:void 0}),l(H)})},[t,f,d,i]),p=ki(()=>{u({...c.current,searchResponse:void 0}),m({cache:"reload"})},[m]);Bi(()=>{m()},[m]);function x(P,H){P.stopPropagation();let oe=P.target.checked,ne={...c.current.selected};oe?ne[H]=!0:delete ne[H],u({...c.current,selected:ne})}function S(P){P.stopPropagation();let Y=P.target.checked,oe={},ne=c.current.searchResponse;Y&&ne?.entry&&ne.entry.forEach(rt=>{rt.resource?.id&&(oe[rt.resource.id]=!0)}),u({...c.current,selected:oe})}function y(){let P=c.current;if(!P.searchResponse?.entry||P.searchResponse.entry.length===0)return!1;for(let H of P.searchResponse.entry)if(H.resource?.id&&!P.selected[H.resource.id])return!1;return!0}function v(P){e.onChange&&e.onChange(new On(P))}function C(P,H){if(Jt(P.target)||P.button===2)return;E(P);let Y=P.button===1||P.ctrlKey||P.metaKey;!Y&&e.onClick&&e.onClick(new Io(H,P)),Y&&e.onAuxClick&&e.onAuxClick(new Io(H,P))}function T(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(Bi(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return A(Mr,{style:{width:"100%",height:"100%"},children:A(wy,{})});let h=e.checkboxesEnabled,M=Ti(f),Q=f.resourceType,Z=s.searchResponse,ye=Z?.entry?.map(P=>P.resource),ve="subtle",b="gray",L=16,We=window.innerWidth<768;return he("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&he(Fr,{position:"apart",mb:"xl",children:[he(Fr,{spacing:2,children:[A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(ha,{size:L}),onClick:()=>u({...c.current,fieldEditorVisible:!0}),children:"Fields"}),A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(Ra,{size:L}),onClick:()=>u({...c.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(ba,{size:L}),onClick:e.onNew,children:"New..."}),!We&&T()&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(Ea,{size:L}),onClick:e.onExport?e.onExport:()=>u({...c.current,exportDialogVisible:!0}),children:"Export..."}),!We&&e.onDelete&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(dt,{size:L}),onClick:()=>e.onDelete(Object.keys(s.selected)),children:"Delete..."}),!We&&e.onBulk&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(da,{size:L}),onClick:()=>e.onBulk(Object.keys(s.selected)),children:"Bulk..."})]}),he(Fr,{spacing:2,children:[Z&&he(Fn,{size:"xs",color:"dimmed",children:[Wy(f,Z.total),"-",Xy(f,Z.total)," of"," ",`${d==="estimate"?"~":""}${Z.total?.toLocaleString()}`]}),A(My,{title:"Refresh",onClick:p,children:A(Ma,{size:"1.125rem"})})]})]}),he(Ey,{className:o.table,children:[he("thead",{children:[he("tr",{children:[h&&A("th",{children:A("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:y(),onChange:P=>S(P)})}),M.map(P=>A("th",{children:he(Di,{shadow:"md",width:240,position:"bottom-end",children:[A(Di.Target,{children:A(Ly,{className:o.control,children:he(Fr,{position:"apart",noWrap:!0,children:[A(Fn,{weight:500,size:"sm",children:Pe(P.name)}),A(Mr,{className:o.icon,children:A(fa,{size:14,stroke:1.5})})]})})}),A(Ri,{search:e.search,searchParams:P.searchParams,onPrompt:(H,Y)=>{u({...c.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:Y})},onChange:H=>{v(H)}})]})},P.name))]}),!e.hideFilters&&he("tr",{children:[h&&A("th",{}),M.map(P=>A("th",{children:P.searchParams&&A(Uy,{resourceType:Q,searchParams:P.searchParams,filters:e.search.filters})},P.name))]})]}),A("tbody",{children:ye?.map(P=>P&&he("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>C(H,P),onAuxClick:H=>C(H,P),children:[h&&A("td",{children:A("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${P.id}`,checked:!!s.selected[P.id],onChange:H=>x(H,P.id)})}),M.map(H=>A("td",{children:mi(P,H)},H.name))]},P.id))})]}),ye?.length===0&&A(Ye,{children:A(Mr,{style:{height:150},children:A(Fn,{size:"xl",color:"dimmed",children:"No results"})})}),Z?.total!==void 0&&Z.total>0&&A(Mr,{m:"md",p:"md",children:A(Oy,{value:Qy(f),total:zy(f,Z.total),onChange:P=>v(ii(f,P)),getControlProps:P=>{switch(P){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&A("div",{"data-testid":"search-error",children:A("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),A(xi,{search:e.search,visible:c.current.fieldEditorVisible,onOk:P=>{v(P),u({...c.current,fieldEditorVisible:!1})},onCancel:()=>{u({...c.current,fieldEditorVisible:!1})}}),A(Ci,{search:e.search,visible:c.current.filterEditorVisible,onOk:P=>{v(P),u({...c.current,filterEditorVisible:!1})},onCancel:()=>{u({...c.current,filterEditorVisible:!1})}}),A(js,{visible:c.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...c.current,exportDialogVisible:!1})}}),A(bi,{visible:c.current.filterDialogVisible,title:s.filterDialogSearchParam?.code?Pe(s.filterDialogSearchParam.code):"",resourceType:Q,searchParam:s.filterDialogSearchParam,filter:s.filterDialogFilter,defaultValue:"",onOk:P=>{v(Go(e.search,P.code,P.operator,P.value)),u({...c.current,filterDialogVisible:!1})},onCancel:()=>{u({...c.current,filterDialogVisible:!1})}},s.filterDialogSearchParam?.code)]})}var K1=Vy(Gy);function Uy(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?A("span",{children:"no filters"}):A(Jy,{children:o.map(t=>he("div",{children:[At(t.operator),"\xA0",A(kr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function Qy(e){return Math.floor((e.offset??0)/(e.count??Ln))+1}function zy(e,o){let t=e.count??Ln;return Math.ceil(o/t)}function Wy(e,o){return Math.min(o,(e.offset??0)+1)}function Xy(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??Ln))}import{jsx as xe,jsxs as Or}from"react/jsx-runtime";function jy(e){let o=R(),[t,r]=wr(!1),[a,n]=wr(),{query:l,fields:f}=e,[i,s]=wr(),[u,c]=wr({}),d=Mi();d.current=i;let m=Mi({});m.current=u,Ai(()=>{n(void 0),o.graphql(l).then(s).catch(C=>n(Zy(C)))},[o,l]);function p(C,T){C.stopPropagation();let M=C.target.checked,Q={...m.current};M?Q[T]=!0:delete Q[T],c(Q)}function x(C){C.stopPropagation();let h=C.target.checked,M={},Q=d.current?.data.ResourceList;h&&Q&&Q.forEach(Z=>{Z.id&&(M[Z.id]=!0)}),c(M)}function S(){let C=d.current?.data.ResourceList;if(!C||C.length===0)return!1;for(let T of C)if(T.id&&!m.current[T.id])return!1;return!0}function y(C,T){Jt(C.target)||(E(C),C.button!==1&&e.onClick&&e.onClick(new Io(T,C)),C.button===1&&e.onAuxClick&&e.onAuxClick(new Io(T,C)))}if(Ai(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return xe(_y,{});let v=e.checkboxesEnabled;return Or("div",{onContextMenu:C=>E(C),"data-testid":"search-control",children:[Or(Ky,{children:[xe("thead",{children:Or("tr",{children:[v&&xe("th",{children:xe("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:S(),onChange:C=>x(C)})}),f.map(C=>xe("th",{children:C.name},C.name))]})}),xe("tbody",{children:i?.data.ResourceList.map(C=>C&&Or("tr",{"data-testid":"search-control-row",onClick:T=>y(T,C),onAuxClick:T=>y(T,C),children:[v&&xe("td",{children:xe("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${C.id}`,checked:!!u[C.id],onChange:T=>p(T,C.id)})}),f.map(T=>xe("td",{children:xe(Ks,{propertyType:T.propertyType,path:T.fhirPath,resource:C})},T.name))]},C.id))})]}),i?.data.ResourceList.length===0&&xe("div",{"data-testid":"empty-search",children:"No results"}),a&&xe("div",{"data-testid":"search-error",children:xe("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&xe($y,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var sL=Yy(jy);import{jsx as Xo,jsxs as ev}from"react/jsx-runtime";function to(e){return ev("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Xo("title",{children:"Medplum Logo"}),Xo("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Xo("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"}),Xo("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"}),Xo("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Xo("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as lv,SimpleGrid as fv}from"@mantine/core";import{Box as Fi,Flex as Nn,Group as ov,Paper as tv,RingProgress as Oi,Text as go,Title as Vn}from"@mantine/core";import{formatCodeableConcept as wi}from"@medplum/core";import{Fragment as Vi,jsx as ee,jsxs as wt}from"react/jsx-runtime";function Ei(e){let{group:o}=e;return ee(tv,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:wt(ov,{children:[o.measureScore&&ee(av,{group:o}),!o.measureScore&&ee(rv,{group:o})]})})}function Li(e){let{measure:o}=e;return wt(Vi,{children:[ee(go,{fz:"md",fw:500,mb:8,children:o.title}),ee(go,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function rv(e){let{group:o}=e,t=o.population,r=t?.find(i=>wi(i.code)==="numerator"),a=t?.find(i=>wi(i.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return wt(Fi,{children:[ee(Vn,{order:3,children:"Not Applicable"}),ee(go,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return wt(Fi,{children:[ee(Vn,{order:3,children:"Insufficient Data"}),ee(go,{children:`Numerator: ${n}`}),ee(go,{children:`Denominator: ${l}`})]});let f=n/l*100;return ee(Oi,{size:120,thickness:12,roundCaps:!0,sections:[{value:f,color:Ni(f)}],label:ee(Nn,{justify:"center",children:wt(go,{fw:700,fz:18,children:[n," / ",l]})})})}function av(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return ee(Vi,{children:t==="%"?ee(Oi,{size:120,thickness:12,roundCaps:!0,sections:[{value:nv(o),color:Ni(o?.measureScore?.value??0)}],label:ee(Nn,{justify:"center",children:ee(go,{fw:700,fz:18,children:ee(_e,{value:o.measureScore})})})}):ee(Nn,{h:120,align:"center",children:ee(Vn,{order:3,children:ee(_e,{value:o.measureScore})})})})}function nv(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function Ni(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as Hn,jsxs as sv}from"react/jsx-runtime";function SL(e){let o=z(e.measureReport),[t]=yl("Measure",{url:o?.measure});return o?sv(lv,{children:[t&&Hn(Li,{measure:t}),Hn(fv,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>Hn(Ei,{group:r},r.id??a))})]}):null}import{Alert as iv}from"@mantine/core";import{operationOutcomeIssueToString as uv}from"@medplum/core";import{jsx as qn}from"react/jsx-runtime";function Jo(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:qn(iv,{icon:qn(fo,{size:16}),color:"red",children:o.map(t=>qn("div",{"data-testid":"text-field-error",children:uv(t)},t.details?.text))})}import{createReference as Er}from"@medplum/core";import{useCallback as cv}from"react";import{jsx as dv}from"react/jsx-runtime";function OL(e){let o=cv((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 dv(oo,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Er(t),sender:Er(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Er(t),operator:Er(r),issued:new Date().toISOString(),content:a})})}import{Anchor as qi,Button as mv,createStyles as pv,NativeSelect as xv,Stack as Iv,TextInput as Un}from"@mantine/core";import{getReferenceString as gv}from"@medplum/core";import{useEffect as Hi,useRef as Gi,useState as Ot}from"react";import{jsx as W,jsxs as $o}from"react/jsx-runtime";var Ui=pv(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 jL(e){let o=R(),t=z(e.value),[r,a]=Ot(!1),[n,l]=Ot(),[f,i]=Ot(),[s,u]=Ot();function c(){i(void 0)}function d(){l(void 0)}let m=Gi();if(m.current=s,Hi(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),Hi(()=>(u(bv(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,S){u({...m.current,[x]:S})}return W("div",{children:$o(J,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(s),children:[W(Un,{label:"Plan Title",defaultValue:s.title,onChange:x=>p("title",x.currentTarget.value)}),W(Qi,{actions:s.action||[],selectedKey:n,setSelectedKey:l,hoverKey:f,setHoverKey:i,onChange:x=>p("action",x)}),W(mv,{type:"submit",children:"Save"})]})})}function Qi(e){let{classes:o}=Ui(),t=Gi();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 $o("div",{className:o.section,children:[e.actions.map(l=>W("div",{children:W(hv,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),W("div",{className:o.bottomActions,children:W(qi,{href:"#",onClick:l=>{E(l),a({id:Wi()})},children:"Add action"})})]})}function hv(e){let{classes:o,cx:t}=Ui(),{action:r}=e,a=Cv(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){E(u),e.setHoverKey(e.action.id)}let s=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return $o("div",{"data-testid":r.id,className:s,onClick:f,onMouseOver:i,onFocus:i,children:[n?W(vv,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):W(yv,{action:r,actionType:a}),W("div",{className:o.bottomActions,children:W(qi,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Qn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function yv(e){let{action:o,actionType:t}=e,[r,a]=zi(o);return $o("div",{children:[$o("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&W("div",{children:W(po,{value:{reference:o.definitionCanonical}})}),r&&W("div",{children:W(le,{property:Qn,propertyType:a,value:r})})]})}function vv(e){let{action:o}=e,[t,r]=Ot(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return $o(Iv,{spacing:"xl",children:[W(Un,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),W(Un,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),W(xv,{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&&W(Qi,{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 W(Lr,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return W(Lr,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return W(Lr,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return W(Lr,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),W(ie,{title:"Timing",description:"When the action should take place.",children:W(Sv,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function Lr(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return W(ir,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:gv(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function Sv(e){let o=e.action,t="timing",[r,a]=zi(o);return W(Ze,{property:Qn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(ht(o,t,l??t,Qn,n))},outcome:void 0})}function Cv(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function zi(e){return Ke({type:"PlanDefinitionAction",value:e},"timing")}var Gn=1;function Wi(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Gn=Math.max(Gn,o+1))}return e}return"id-"+Gn++}function bv(e){return{...e,action:Xi(e.action)}}function Xi(e){if(e)return e.map(o=>({...o,id:Wi(o.id),action:Xi(o.action)}))}import{Anchor as Te,Box as $n,Button as Yv,createStyles as jv,Group as eS,NativeSelect as oS,Space as tS,Textarea as rS,TextInput as _n,Title as aS}from"@mantine/core";import{getElementDefinition as nS,isResource as lS}from"@medplum/core";import{useEffect as su,useRef as fS,useState as Qr}from"react";import{Checkbox as Lv,Group as Nv,MultiSelect as Vv,NativeSelect as Hv,Radio as tu,Textarea as qv,TextInput as _o}from"@mantine/core";import{capitalize as Xn,deepEquals as Gv,formatCodeableConcept as Uv,formatCoding as Ur,getElementDefinition as Qv,getTypedPropertyValue as ro,stringify as ru}from"@medplum/core";import{useContext as zv}from"react";import{deepClone as Rv,evalFhirPathTyped as Pv,formatCoding as Tv,getExtension as Nr,getTypedPropertyValue as zn,getReferenceString as Dv,stringify as kv,splitN as Bv}from"@medplum/core";var Vr=(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))(Vr||{});function Ji(e){return e.type==="choice"||e.type==="open-choice"}function $i(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=Ki(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=Mv(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function _i(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>Tv(l.valueCoding)===r||l[o]===r),n=zn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Ki(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Ki(t.item,o);if(r)return r}}}function Av(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=Pv(`%actualAnswer ${r} %expectedAnswer`,[e],{actualAnswer:e,expectedAnswer:o});return a}else return!1}function Mv(e,o,t){let r=o||[],a=zn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let f of r){let i=zn({type:"QuestionnaireResponseItemAnswer",value:f},"value[x]"),{operator:s}=e;if(Av(i,a,s)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function Hr(e){let o=Nr(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 qr(e,o){let t=Rv(e),r=Nr(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 Zi(e,o,t){let r=Nr(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]=Bv(f,"=",2);n[i]=s}return n}function Yi(e){return{resourceType:"QuestionnaireResponse",questionnaire:Dv(e),item:ji(e.item)}}function ji(e){return e?.map(Wn)??[]}function Wn(e){return{id:wv(),linkId:e.linkId,text:e.text,item:ji(e.item),answer:e.initial?.map(Ov)??[]}}var Fv=1;function wv(){return"id-"+Fv++}function Ov(e){return{...e}}function eu(e){return e.value.display||e.value.reference||kv(e.value)}function ou(e){let o=e?.item?.[0];return o&&Nr(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as Ev}from"react";var Gr=Ev({});import{jsx as X}from"react/jsx-runtime";function Et(e){let o=zv(Gr),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=Jn(r,e.index)??ro({type:"QuestionnaireItemInitial",value:f},"value");switch(n){case"display":return X("p",{children:e.item.text},e.item.linkId);case"boolean":return X(ar,{title:e.item.text,htmlFor:e.item.linkId,children:X(Lv,{id:e.item.linkId,name:e.item.linkId,defaultChecked:i?.value,onChange:s=>a({valueBoolean:s.currentTarget.checked})})},e.item.linkId);case"decimal":return X(_o,{type:"number",step:"any",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDecimal:s.currentTarget.valueAsNumber})});case"integer":return X(_o,{type:"number",step:1,id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueInteger:s.currentTarget.valueAsNumber})});case"date":return X(_o,{type:"date",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDate:s.currentTarget.value})});case"dateTime":return X(Be,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDateTime:s})});case"time":return X(_o,{type:"time",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueTime:s.currentTarget.value})});case"string":case"url":return X(_o,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"text":return X(qv,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"attachment":return X(Nv,{py:4,children:X(Zt,{name:l,defaultValue:i?.value,onChange:s=>a({valueAttachment:s})})});case"reference":return X(No,{name:l,required:t.required,targetTypes:Hr(t),searchCriteria:Zi(t,o.subject,o.encounter),defaultValue:i?.value,onChange:s=>a({valueReference:s})});case"quantity":return X(Ce,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueQuantity:s}),disableWheel:!0});case"choice":case"open-choice":return Kv(t)&&!t.answerValueSet?X(Wv,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)}):X(Xv,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)});default:return null}}function Wv(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return X(lu,{});let n=ro({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let i of t.answerOption){let s=ro({type:"QuestionnaireItemAnswerOption",value:i},"value");l.push(au(s))}let f=Jn(a)??n;if(t.repeats){let{propertyName:i,data:s}=Zv(e.item),u=$v(a);return X(Vv,{data:s,placeholder:"Select items",searchable:!0,defaultValue:u||[au(n)],onChange:c=>{let d=_i(c,i,t);e.onChangeAnswer(d)}})}return X(Hv,{id:o,name:o,onChange:i=>{let s=i.currentTarget.selectedIndex;if(s===0){e.onChangeAnswer({});return}let u=t.answerOption[s-1],c=ro({type:"QuestionnaireItemAnswerOption",value:u},"value"),d="value"+Xn(c.type);e.onChangeAnswer({[d]:c.value})},defaultValue:Ur(f?.value)||f?.value,data:l})}function Xv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?X(lu,{}):t.answerValueSet?X(lr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):X(Jv,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Jv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Qv("QuestionnaireItemAnswerOption","value[x]"),f=ro({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=ro({type:"QuestionnaireItemAnswerOption",value:m},"value");x?.value&&(f&&ru(x)===ru(f)&&(s=p),i.push([p,x]))}let u=Jn(n),c=_v(i,u);return X(tu.Group,{name:o,value:c??s,onChange:d=>{let m=i.find(p=>p[0]===d);if(m){let p=m[1],x="value"+Xn(p.type);a({[x]:p.value})}},children:i.map(([d,m])=>X(tu,{id:d,value:d,py:4,label:X(le,{property:l,propertyType:m.type,value:m.value})},d))})}function lu(){return X(_o,{disabled:!0,placeholder:"No Answers Defined"})}function fu(e){return ro({type:"QuestionnaireItemAnswer",value:e},"value")}function Jn(e,o=0){let t=e.answer;return fu(t?.[o]??{})}function $v(e){let o=e.answer;return o?o.map(r=>fu(r)).map(r=>Ur(r?.value)||r?.value):[]}function _v(e,o){return e.find(t=>Gv(t[1].value,o?.value))?.[0]}function au(e){if(e)return e.type==="CodeableConcept"?Uv(e.value):e.type==="Coding"?Ur(e.value):e.type==="Reference"?eu(e):e.value.toString()}function Kv(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Zv(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=ro({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+Xn(t.type),a=(e.answerOption??[]).map(n=>({value:nu(n,r),label:nu(n,r)}));return{propertyName:r,data:a}}function nu(e,o){return Ur(e.valueCoding)||e[o]?.toString()}import{Fragment as Ko,jsx as O,jsxs as Ie}from"react/jsx-runtime";var sS=jv(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 N2(e){let o=R(),t=z(e.questionnaire),[r,a]=Qr(!1),[n,l]=Qr(),[f,i]=Qr(),[s,u]=Qr();function c(){u(void 0)}function d(){i(void 0)}su(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),su(()=>(l(dS(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:O("div",{children:Ie(J,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[O(iu,{item:n,selectedKey:f,setSelectedKey:i,hoverKey:s,setHoverKey:u,onChange:m}),O(Yv,{type:"submit",children:"Save"})]})})}function iu(e){let{classes:o,cx:t}=sS(),r=e.item,a=e.item,n=lS(e.item),l=n||a.type==="group",f=a.linkId??"[untitled]",i=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,u=fS();u.current=e.item;function c(h){E(h),e.setSelectedKey(e.item.id)}function d(h){E(h),e.setHoverKey(e.item.id)}function m(h){let M=u.current;e.onChange({...M,item:M.item?.map(Q=>Q.id===h.id?h:Q)})}function p(h,M){e.onChange({...e.item,item:[...e.item.item??[],h]},M)}function x(h){e.onChange({...e.item,item:e.item.item?.filter(M=>M!==h)})}function S(h,M){e.onChange({...u.current,[h]:M})}function y(h){e.onChange({...e.item,...h})}function v(h){e.onChange({...e.item,item:e.item.item?.map(M=>M===h?{...M,repeats:!M.repeats}:M)})}function C(h,M){let Q=xS(e.item.item,h,M);e.onChange({...e.item,item:Q})}let T=t(o.section,{[o.editing]:i,[o.hovering]:s&&!i});return Ie("div",{"data-testid":a.linkId,className:T,onClick:c,onMouseOver:d,onFocus:d,children:[O("div",{className:o.questionBody,children:i?Ie(Ko,{children:[n&&O(_n,{size:"xl",defaultValue:r.title,onBlur:h=>S("title",h.currentTarget.value)}),!n&&O(rS,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:h=>S("text",h.currentTarget.value)}),a.type==="reference"&&O(cS,{item:a,onChange:y}),Ji(a)&&O(iS,{item:a,onChange:h=>y(h)})]}):Ie(Ko,{children:[r.title&&O(aS,{children:r.title}),a.text&&O("div",{children:a.text}),!l&&O(Et,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((h,M)=>O("div",{children:O(iu,{item:h,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:M===0,isLast:M===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>x(h),onRepeatable:v,onMoveUp:()=>C(M,-1),onMoveDown:()=>C(M,1)})},h.id)),!l&&O("div",{className:o.topActions,children:i?Ie(Ko,{children:[O(_n,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:h=>S("linkId",h.currentTarget.value)}),!l&&O(oS,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:h=>S("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"}]})]}):O("div",{children:f})}),!n&&O($n,{className:o.movementActions,children:Ie($n,{className:o.columnAlignment,children:[!e.isFirst&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:O(ia,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:O(sa,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),Ie("div",{className:o.bottomActions,children:[l&&Ie(Ko,{children:[O(Te,{href:"#",onClick:h=>{h.preventDefault(),p({id:ho(),linkId:Yn("q"),type:"string",text:"Question"})},children:"Add item"}),O(Te,{href:"#",onClick:h=>{h.preventDefault(),p({id:ho(),linkId:Yn("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),p(pS(),!0)},children:"Add Page"}),i&&!n&&Ie(Ko,{children:[O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function iS(e){let o=nS("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return Ie("div",{children:[e.item.answerValueSet!==void 0?O(_n,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):O(uS,{options:t,property:o,item:e.item,onChange:e.onChange}),Ie($n,{display:"flex",children:[O(Te,{href:"#",onClick:r=>{E(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:ho()}]})},children:"Add choice"}),O(tS,{w:"lg"}),O(Te,{href:"#",onClick:r=>{E(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function uS(e){return O("div",{children:e.options.map(o=>{let[t,r]=Ke({type:"QuestionnaireItemAnswerOption",value:o},"value");return Ie("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[O("div",{children:O(Ze,{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)}),O("div",{children:O(Te,{href:"#",onClick:a=>{E(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function cS(e){let o=Hr(e.item)??[];return Ie(Ko,{children:[o.map((t,r)=>Ie(eS,{children:[O(Fo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(qr(e.item,o.map(n=>n===t?a:n)))}}),O(Te,{href:"#",onClick:a=>{E(a),e.onChange(qr(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),O(Te,{href:"#",onClick:t=>{E(t),e.onChange(qr(e.item,[...o,""]))},children:"Add Resource Type"})]})}var Kn=1,Zn=1;function Yn(e){return e+Kn++}function ho(){return"id-"+Zn++}function dS(e){return{...e,id:e.id||ho(),item:uu(e.item)}}function uu(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Zn=Math.max(Zn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(Kn=Math.max(Kn,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||ho(),item:uu(o.item),answerOption:mS(o.answerOption)}))}function mS(e){if(e)return e.map(o=>({...o,id:o.id||ho()}))}function pS(){return{id:ho(),linkId:Yn("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 xS(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 BS}from"@mantine/core";import{createReference as AS,getReferenceString as MS}from"@medplum/core";import{useEffect as Iu,useState as ol}from"react";import{Button as el,Group as PS,Stack as TS,Stepper as mu}from"@mantine/core";import{Anchor as IS}from"@mantine/core";import{useState as gS}from"react";import{jsx as zr,jsxs as yS}from"react/jsx-runtime";function Wr(e){let{item:o,response:t,onChange:r}=e,[a,n]=gS(hS(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return zr("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?zr(Et,{item:o,response:t,onChange:f=>r([f]),index:0},o.linkId):yS(ie,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((f,i)=>zr(Et,{item:o,response:t,onChange:s=>r([s]),index:i},`${o.linkId}-${i}`)),l&&zr(IS,{onClick:()=>n(f=>f+1),children:"Add Item"})]},e.item.linkId)}function hS(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 vS,Stack as SS,Title as CS}from"@mantine/core";import{useState as bS}from"react";import{Fragment as RS,jsx as yo,jsxs as du}from"react/jsx-runtime";function jn(e){let[o,t]=bS(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=Wn(e.item);t([...o,n])}return du(RS,{children:[o.map((n,l)=>yo(cu,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:f=>r(f,l)},n.id)),e.item.repeats&&yo(vS,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function cu(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)?du("div",{children:[e.item.text&&yo(CS,{order:3,mb:"md",children:e.item.text}),yo(SS,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?yo(jn,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):yo(cu,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):yo(Wr,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as kS,jsx as Qe,jsxs as xu}from"react/jsx-runtime";function pu(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"?Qe(jn,{item:d,response:m,onChange:a,checkForQuestionEnabled:u},d.linkId):Qe(Wr,{item:d,response:m?.[0],onChange:a,checkForQuestionEnabled:u},d.linkId);return i?Qe(mu.Step,{label:d.text,children:p},d.linkId):p});return xu(kS,{children:[i&&Qe(mu,{active:r??0,allowNextStepsSelect:!1,p:6,children:c}),!i&&Qe(TS,{children:c}),Qe(DS,{activePage:r??0,numberOfPages:f,nextStep:n,prevStep:l,submitButtonText:s})]})}function DS(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return xu(PS,{position:"right",mt:"xl",spacing:"xs",children:[o&&Qe(el,{onClick:e.prevStep,children:"Back"}),t&&Qe(el,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&Qe(el,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as tl,jsxs as wS}from"react/jsx-runtime";function gu(e){let o=R(),t=o.getProfile(),[r,a]=ol(!1),n=z(e.questionnaire),[l,f]=ol(),[i,s]=ol(0);Iu(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),Iu(()=>{f(n?Yi(n):void 0)},[n]);function u(x){let S=l?.item??[],v={resourceType:"QuestionnaireResponse",item:hu(S,Array.isArray(x)?x:[x])};f(v)}function c(x){return $i(x,l?.item??[])}if(!r||!n)return null;let d=ou(n),m=()=>s(x=>x+1),p=()=>s(x=>x-1);return tl(Gr.Provider,{value:{subject:e.subject,encounter:e.encounter},children:wS(J,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:MS(n),subject:e.subject,source:AS(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&tl(BS,{children:n.title}),tl(pu,{items:n.item??[],response:l,onChange:u,renderPages:d>1,activePage:i,numberOfPages:d,submitButtonText:e.submitButtonText,checkForQuestionEnabled:c,nextStep:m,prevStep:p})]})})}function FS(e,o){let t=hu(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 hu(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(FS(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 Xr,Button as OS,createStyles as ES,Divider as LS,Group as Lt,NativeSelect as rl,Stack as Jr,Text as NS,TextInput as VS}from"@mantine/core";import{formatRange as yu,getCodeBySystem as HS}from"@medplum/core";import{useEffect as qS,useState as al}from"react";import{jsx as $,jsxs as Zo}from"react/jsx-runtime";var GS=ES(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"}})),US=["gender","age","gestationalAge","context","appliesTo","category"],QS={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function bN(e){e=Object.assign(QS,e);let o=e.definition,[t,r]=al([]),[a,n]=al(1),[l,f]=al(1);return qS(()=>{let p=XS(o,f);r(JS(p.qualifiedInterval||[],n))},[o]),Zo(J,{testid:"reference-range-editor",onSubmit:i,children:[$(Jr,{children:t.map(p=>$(zS,{unit:_S(o.quantitativeDetails?.unit),onChange:c,onAdd:d,onRemove:m,onRemoveGroup:u,intervalGroup:p},`group-${p.id}`))}),$(Xr,{title:"Add Group",size:"sm",onClick:p=>{E(p),s({id:`group-id-${a}`,filters:{},intervals:[]}),n(x=>x+1)},children:$(so,{})}),$(Lt,{position:"right",children:$(OS,{type:"submit",children:"Save"})})]});function i(){let p=t.flatMap(x=>x.intervals).filter(x=>!KS(x));e.onSubmit({...o,qualifiedInterval:p})}function s(p){r(x=>[...x,p])}function u(p){r(x=>x.filter(S=>S.id!==p.id))}function c(p,x){r(S=>{S=[...S];let y=S.find(C=>C.id===p),v=y?.intervals.findIndex(C=>C.id===x.id);return v!==void 0&&y?.intervals[v]&&(y.intervals[v]=x),S})}function d(p,x){x.id===void 0&&(x.id=`id-${l}`,f(S=>S+1)),r(S=>{S=[...S];let y=S.findIndex(v=>v.id===p);if(y!==-1){let v={...S[y]};x={...x,...v.filters},v.intervals=[...v.intervals,x],S[y]=v}return S})}function m(p,x){r(S=>{S=[...S];let y=S.find(v=>v.id===p);return y&&(y.intervals=y.intervals.filter(v=>v.id!==x.id)),S})}}function zS(e){let{intervalGroup:o,unit:t}=e,{classes:r}=GS();return $(Ye,{"data-testid":o.id,className:r.section,children:Zo(Jr,{spacing:"lg",children:[$(Lt,{position:"right",children:$(Xr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{E(a),e.onRemoveGroup(o)},children:$(Je,{})},`remove-group-button-${o.id}`)}),$(WS,{intervalGroup:o,onChange:e.onChange}),$(LS,{}),o.intervals.map(a=>Zo(Jr,{spacing:"xs",children:[Zo(Lt,{children:[$(VS,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{E(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),$(Xr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{E(n),e.onRemove(o.id,a)},children:$(Je,{})},`remove-interval-${a.id}`)]}),$(vt,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),$(Xr,{title:"Add Interval",size:"sm",onClick:a=>{E(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:$(so,{})})]})})}function WS(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 Zo(Jr,{style:{maxWidth:"50%"},children:[$(Lt,{children:$(rl,{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})}}})}),Zo(Lt,{spacing:"xs",children:[$(NS,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),$("div",{id:`div-age-${o.id}`,children:$(vt,{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}`)})]}),$(rl,{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"}]}})}}}),$(rl,{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 XS(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 JS(e,o){let t=1,r={};for(let a of e){let n=$S(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(US.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function $S(e){return[`gender=${e.gender}`,`age=${yu(e.age)}`,`gestationalAge=${yu(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function _S(e){return e&&(HS(e,"http://unitsofmeasure.org")||e.text)}function KS(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as vu,Grid as $r,Text as ZS}from"@mantine/core";import{formatDateTime as YS,getReferenceString as jS}from"@medplum/core";import{Fragment as eC,useEffect as oC,useState as Su}from"react";import{jsx as Ee,jsxs as Nt}from"react/jsx-runtime";function wN(e){let o=R(),t=z(e.value),[r,a]=Su(!1),[n,l]=Su();if(oC(()=>{t&&!r&&(o.executeBatch(f(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Ee($r,{children:t.action?.map((s,u)=>{let c=s.resource&&i(s.resource),d=c?.input?.[0]?.valueReference,m=c?.output?.[0]?.valueReference;return Nt(eC,{children:[Ee($r.Col,{span:1,p:"md",children:c?.status==="completed"?Ee(Ia,{}):Ee(wa,{color:"gray"})}),Nt($r.Col,{span:9,p:"xs",children:[Ee(ZS,{weight:500,children:s.title}),s.description&&Ee("div",{children:s.description}),Nt("div",{children:["Last edited by\xA0",Ee(Fe,{value:c?.meta?.author}),"\xA0on\xA0",YS(c?.meta?.lastUpdated)]}),Nt("div",{children:["Status: ",Ee(gr,{status:c?.status||"unknown"})]})]}),Nt($r.Col,{span:2,p:"md",children:[d&&!m&&Ee(vu,{onClick:()=>e.onStart(c,d),children:"Start"}),d&&m&&Ee(vu,{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===jS(u.resource))return u.resource}}import{createStyles as sC}from"@mantine/core";import{useEffect as iC,useState as uC}from"react";import{stringify as nC}from"@medplum/core";function _r(e,o){let t=tC(e,o);return rC(t,e,o)}function tC(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,S=0;s===-i||s!==i&&p.i<m.i?(S=m.i,x=m):(S=p.i+1,x=p),f[d]=void 0;let y=S-s,v={i:S,j:y,prev:aC(x),snake:!1};for(;S<t&&y<r&&e[S]===o[y];)S++,y++;if(S>v.i&&(v={i:S,j:y,prev:v,snake:!0}),f[u]=v,S>=t&&y>=r)return f[u]}f[l+i-1]=void 0}}function rC(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 aC(e){return e&&!e.snake&&e.prev?e.prev:e}function Cu(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:nC(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 lC(t,o),fC(t),t}function lC(e,o){for(let t=1;t<o.length;t++){let r=_r(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,l=a.original.lines,f=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,l.length),a.type==="insert"||a.type==="change")for(let 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 fC(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 bu(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Ru(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Yo(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Yo(r,"month");let a=Math.floor(o/86400);if(a>0)return Yo(a,"day");let n=Math.floor(o/3600);if(n>0)return Yo(n,"hour");let l=Math.floor(o/60);return l>0?Yo(l,"minute"):Yo(o,"second")}function Yo(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as dC,jsx as Ae,jsxs as Pu}from"react/jsx-runtime";var cC=sC(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 $N(e){let{classes:o}=cC(),t=R(),[r,a]=uC(e.history);if(iC(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(a).catch(console.log)},[t,e.history,e.resourceType,e.id]),!r)return Ae("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Cu(r);return Ae("div",{className:o.container,children:Ae("table",{className:o.root,children:Ae("tbody",{children:l.map((f,i)=>Pu("tr",{className:f.span>0?o.startRow:o.normalRow,children:[f.span>0&&Pu(dC,{children:[Ae("td",{className:o.author,rowSpan:f.span,children:Ae(je,{value:f.meta.author,link:!0})}),Ae("td",{className:o.dateTime,rowSpan:f.span,children:Ae(te,{to:bu(n,f.meta.versionId),children:Ru(f.meta.lastUpdated)})})]}),Ae("td",{className:o.lineNumber,children:i+1}),Ae("td",{className:o.line,children:Ae("pre",{className:o.pre,children:f.value})})]},"row-"+i))})})})}import{createStyles as mC}from"@mantine/core";import{stringify as Tu}from"@medplum/core";import{Fragment as IC,jsx as jo,jsxs as gC}from"react/jsx-runtime";var pC=mC(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function oV(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Tu(o,!0).match(/[^\r\n]+/g),a=Tu(t,!0).match(/[^\r\n]+/g),n=_r(r,a);return jo("pre",{style:{color:"gray"},children:n.map((l,f)=>jo(xC,{delta:l},"delta"+f))})}function xC(e){let{classes:o}=pC();return gC(IC,{children:["...",jo("br",{}),e.delta.original.lines.length>0&&jo("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
71
|
+
}`.replace(/\s+/g," ");return(await e.graphql(r)).data.StructureDefinitionList[0]}function aI(e){return e.type==="profile"&&!e?.error&&_x(e.resourceType)}import{ActionIcon as Xf,Button as mI,Group as ur,Stack as Ya,createStyles as pI}from"@mantine/core";import{getPathDisplayName as xI,getPropertyDisplayName as II,isEmpty as ja,tryGetProfile as gI}from"@medplum/core";import{useEffect as hI,useState as Ct}from"react";import{arrayify as lI,getElementDefinitionFromElements as fI,getTypedPropertyValueWithSchema as sI,isPopulated as iI,matchDiscriminant as uI}from"@medplum/core";function cI(e,o,t){for(let r of[t.elements,t.typeSchema?.elements]){let a;if(iI(r)){let n=fI(r,o.path);n&&(a=sI(e.value,o.path,n))}if(a)return lI(a)?.some(n=>uI(n,o,t,r))??!1}return!1}function dI(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=>cI(a,n,r)))return r.name}}function Za(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=dI(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 Wf(e){return e.type!==void 0&&e.type.length>0}import{jsx as j,jsxs as cr}from"react/jsx-runtime";var Jf=pI(e=>({indented:{marginTop:"0.5rem",borderLeft:`3px solid ${e.colors.gray[4]}`,padding:"0.5rem 0 0.5rem 0.5rem"}}));function $f(e){let{property:o}=e,t=R(),[r,a]=Ct(!0),[n,l]=Ct([]),[f]=Ct(()=>Array.isArray(e.defaultValue)?e.defaultValue:[]),[i,s]=Ct([[]]),{classes:u}=Jf(),c=o.type[0]?.code;hI(()=>{if(!o.slicing){let T=[];l(T);let h=Za(f,T,o.slicing);s(h),a(!1);return}let y=[],v=[],C=[];for(let T of o.slicing.slices){if(!Wf(T))continue;let h=T.type[0],M;ja(T.elements)&&h.profile&&(M=h.profile[0]),y.push(T),v.push(M),M?C.push(t.requestProfileSchema(M)):C.push(Promise.resolve())}Promise.all(C).then(()=>{for(let h=0;h<y.length;h++){let M=y[h],Q=v[h];if(Q){let Z=gI(Q);M.typeSchema=Z}}l(y);let T=Za(f,y,o.slicing);s(T),a(!1)}).catch(T=>{console.error(T),a(!1)})},[t,o.slicing,c,f]);function d(y,v){let C=[...i];if(C[v]=y,s(C),e.onChange){let T=C.flat().filter(h=>h!==void 0);e.onChange(T)}}if(r)return j("div",{children:"Loading..."});let m=n.length,p=i[m],x=!(e.hideNonSliceValues??(c==="Extension"&&n.length>0)),S=xI(o.path);return cr(Ya,{className:e.indent?u.indented:void 0,children:[n.map((y,v)=>j(yI,{slice:y,property:o,defaultValue:i[v],onChange:C=>{d(C,v)},testId:`slice-${y.name}`},y.name)),x&&p.map((y,v)=>cr(ur,{noWrap:!0,style:{flexGrow:1},children:[j("div",{style:{flexGrow:1},children:j(Ze,{arrayElement:!0,property:e.property,name:e.name+"."+v,defaultValue:y,onChange:C=>{let T=[...p];T[v]=C,d(T,m)},defaultPropertyType:void 0,outcome:e.outcome})}),j(Kf,{propertyDisplayName:S,testId:`nonsliced-remove-${v}`,onClick:C=>{E(C);let T=[...p];T.splice(v,1),d(T,m)}})]},`${v}-${p.length}`)),x&&i.flat().length<o.max&&j(ur,{noWrap:!0,style:{justifyContent:"flex-start"},children:j(_f,{propertyDisplayName:S,onClick:y=>{E(y);let v=[...p];v.push(void 0),d(v,m)},testId:"nonsliced-add"})})]})}function yI(e){let{slice:o,property:t}=e,[r,a]=Ct(()=>e.defaultValue.map(u=>u??{})),{classes:n}=Jf();function l(u){a(u),e.onChange&&e.onChange(u)}let f=o.min>0,i=ja(o.elements),s=II(o.name);return j(ie,{title:s,description:o.definition,withAsterisk:f,fhirPath:`${t.path}:${o.name}`,testId:e.testId,children:cr(Ya,{className:i?n.indented:void 0,children:[r.map((u,c)=>cr(ur,{noWrap:!0,children:[j("div",{style:{flexGrow:1},children:j(Ya,{children:ja(o.elements)?j(dr,{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}):j(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&&j(Kf,{propertyDisplayName:s,testId:e.testId&&`${e.testId}-remove-${c}`,onClick:d=>{E(d);let m=[...r];m.splice(c,1),l(m)}})]},`${c}-${r.length}`)),r.length<o.max&&j(ur,{noWrap:!0,style:{justifyContent:"flex-start"},children:j(_f,{propertyDisplayName:s,onClick:u=>{E(u);let c=[...r,void 0];l(c)},testId:e.testId&&`${e.testId}-add`})})]})})}function _f({propertyDisplayName:e,onClick:o,testId:t}){let r=e?`Add ${e}`:"Add";return e?j(mI,{title:r,size:"sm",color:"green.6",variant:"subtle","data-testid":t,leftIcon:j(so,{size:"1.25rem"}),onClick:o,children:r}):j(Xf,{title:r,color:"green.6","data-testid":t,onClick:o,children:j(so,{size:"1.25rem"})})}function Kf({propertyDisplayName:e,onClick:o,testId:t}){return j(Xf,{title:e?`Remove ${e}`:"Remove",color:"red.5","data-testid":t,onClick:o,children:j(Je,{size:"1.25rem"})})}import{Button as jf,Chip as Zf,Group as pr,Modal as vI,NativeSelect as SI,Stack as CI,Switch as bI,TextInput as RI}from"@mantine/core";import{formatTiming as PI}from"@medplum/core";import{useRef as es,useState as en}from"react";import{Fragment as ts,jsx as fe,jsxs as bt}from"react/jsx-runtime";var TI=["sun","mon","tue","wed","thu","fri","sat"];function os(e){let[o,t]=en(e.defaultValue),[r,a]=en(!1),n=es();return n.current=o,bt(ts,{children:[bt(pr,{spacing:"xs",grow:!0,noWrap:!0,children:[fe("span",{children:PI(n.current)||"No repeat"}),fe(jf,{onClick:()=>a(!0),children:"Edit"})]}),fe(DI,{visible:r,defaultValue:n.current,onOk:l=>{e.onChange&&e.onChange(l),t(l),a(!1)},onCancel:()=>a(!1)})]})}var Yf={repeat:{period:1,periodUnit:"d"}};function DI(e){let[o,t]=en(e.defaultValue||Yf),r=es();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 fe(vI,{title:"Timing",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>e.onCancel(),children:bt(CI,{children:[fe(ie,{title:"Starts on",htmlFor:"timing-dialog-start",children:fe(Be,{name:"timing-dialog-start",onChange:s=>a(s)})}),fe(bI,{label:"Repeat",checked:!!o.repeat,onChange:s=>n(s.currentTarget.checked?Yf.repeat:void 0)}),o.repeat&&bt(ts,{children:[fe(ie,{title:"Repeat every",htmlFor:"timing-dialog-period",children:bt(pr,{spacing:"xs",grow:!0,noWrap:!0,children:[fe(RI,{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)}),fe(SI,{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"&&fe(ie,{title:"Repeat on",children:fe(Zf.Group,{multiple:!0,onChange:i,children:fe(pr,{position:"apart",mt:"md",spacing:"xs",children:TI.map(s=>fe(Zf,{value:s,size:"xs",radius:"xl",children:s.charAt(0).toUpperCase()},s))})})})]}),fe(pr,{position:"right",children:fe(jf,{onClick:()=>e.onOk(o),children:"OK"})})]})})}import{jsx as V,jsxs as EI}from"react/jsx-runtime";function Ze(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===w.Attachment)return V(of,{name:t,defaultValue:r,onChange:a});let f=l[0]?.code!==w.Extension;return V($f,{property:o,name:t,defaultValue:r,indent:f,onChange:a,outcome:e.outcome})}return l.length>1?V(wI,{elementDefinitionTypes:l,...e}):V(dr,{name:t,defaultValue:r,onChange:f=>{if(e.onChange){let i=e.name.replace("[x]",as(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 wI(e){let o=e.elementDefinitionTypes,t;e.defaultPropertyType&&(t=o.find(n=>n.code===e.defaultPropertyType)),t||(t=o[0]);let[r,a]=FI(t);return EI(BI,{spacing:"xs",grow:!0,noWrap:!0,children:[V(AI,{style:{width:"200px"},defaultValue:r.code,onChange:n=>{a(o.find(l=>l.code===n.currentTarget.value))},data:o.map(n=>({value:n.code,label:n.code}))}),V(dr,{name:e.name,defaultValue:e.defaultValue,outcome:e.outcome,elementDefinitionType:r,onChange:n=>{e.onChange&&e.onChange(n,e.name.replace("[x]",as(r.code)))},min:e.property.min,max:e.property.max,binding:e.property.binding,path:e.property.path})]})}function dr(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 V("div",{children:"Property type not specified "});let s={name:o,defaultValue:t,onChange:r,outcome:a,path:l};switch(i){case w.SystemString:case w.canonical:case w.string:case w.time:case w.uri:case w.url:return V(on,{id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case w.date:return V(on,{type:"date",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)},error:G(a,o)});case w.dateTime:case w.instant:return V(Be,{name:o,defaultValue:t,onChange:r,outcome:a});case w.decimal:case w.integer:case w.positiveInt:case w.unsignedInt:return V(on,{type:"number",step:i===w.decimal?"any":"1",id:o,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.valueAsNumber)}});case w.code:return V(_t,{...s,binding:n?.valueSet});case w.boolean:return V(kI,{id:o,name:o,"data-testid":o,defaultChecked:!!t,onChange:u=>{r&&r(u.currentTarget.checked)}});case w.base64Binary:case w.markdown:return V(MI,{id:o,spellCheck:i!==w.base64Binary,name:o,"data-testid":o,defaultValue:t,required:f,onChange:u=>{r&&r(u.currentTarget.value)}});case w.Address:return V(Pl,{...s});case w.Annotation:return V(Tl,{...s});case w.Attachment:return V(Zt,{...s});case w.CodeableConcept:return V(yf,{binding:n?.valueSet,...s});case w.Coding:return V(lr,{binding:n?.valueSet,...s});case w.ContactDetail:return V(Cf,{...s});case w.ContactPoint:return V(fr,{...s});case w.Extension:return V(kf,{...s,propertyType:e.elementDefinitionType});case w.HumanName:return V(Bf,{...s});case w.Identifier:return V(Ff,{...s});case w.Money:return V(wf,{...s});case w.Period:return V(Ef,{...s});case w.Duration:case w.Quantity:return V(Ce,{...s});case w.Range:return V(vt,{...s});case w.Ratio:return V(Hf,{...s});case w.Reference:return V(No,{...s,targetTypes:OI(e.elementDefinitionType)});case w.Timing:return V(os,{...s});case w.Dosage:case w.UsageContext:default:return V(Lo,{typeName:i,defaultValue:t,onChange:r,outcome:a})}}var rs="http://hl7.org/fhir/StructureDefinition/";function OI(e){return e?.targetProfile?.map(o=>o.startsWith(rs)?o.slice(rs.length):o)}import{jsx as xr}from"react/jsx-runtime";var tn=new Set(["extension","modifierExtension"]),qI=new Set(["id",...Yt].filter(e=>!tn.has(e)));function mr(e){let{elements:o}=e,[t,r]=HI(e.defaultValue??{}),a=VI(()=>{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))ht(l,f,f,i,i.fixed.value);r(l),e.onChange&&e.onChange(l)}return xr(LI,{style:{flexGrow:1},"data-testid":e.testId,children:Object.entries(o).map(([l,f])=>{if(!f.type||f.max===0||l==="url"&&f.fixed||tn.has(l)&&!NI(f.slicing?.slices))return null;if(qI.has(l))return null;if(jt.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=xr(Ze,{property:f,name:l,defaultValue:i,defaultPropertyType:s,onChange:(d,m)=>{n(ht({...t},l,m??l,f,d))},arrayElement:void 0,outcome:e.outcome},l);return e.type==="Extension"||tn.has(l)?c:f.type.length===1&&f.type[0].code==="boolean"?xr(ar,{title:ns(l),description:f.description,htmlFor:l,fhirPath:f.path,withAsterisk:u,children:c},l):xr(ie,{title:ns(l),description:f.description,withAsterisk:u,htmlFor:l,outcome:e.outcome,fhirPath:f.path,children:c},l)})})}import{jsx as fs,jsxs as zI}from"react/jsx-runtime";function Lo(e){let{typeName:o}=e,[t,r]=QI(e.defaultValue??{}),a=UI(ke),n=e.profileUrl??a.profileUrl,l=ls(()=>GI(o,n),[o,n]),f=ls(()=>If(l,n),[l,n]);if(!l)return zI("div",{children:[o,"\xA0not implemented"]});function i(s){r(s),e.onChange&&e.onChange(s)}return fs(ke.Provider,{value:f,children:fs(mr,{type:l.type,elements:l.elements,defaultValue:t,onChange:i,outcome:e.outcome})})}import{Button as rn,createStyles as WI,Group as is}from"@mantine/core";import{useMemo as XI,useState as JI}from"react";function ss(e){return e.toLocaleString("default",{month:"long"})+" "+e.getFullYear()}function Ir(){let e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}import{jsx as ue,jsxs as Rt}from"react/jsx-runtime";var $I=WI(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 us(e){let{classes:o}=$I(),{onChangeMonth:t,onClick:r}=e,[a,n]=JI(Ir);function l(i){n(s=>{let u=new Date(s.getTime());return u.setMonth(s.getMonth()+i),t(u),u})}let f=XI(()=>_I(a,e.slots),[a,e.slots]);return Rt("div",{children:[Rt(is,{position:"apart",spacing:"xs",grow:!0,noWrap:!0,children:[ue("p",{style:{flex:1},children:ss(a)}),Rt(is,{position:"right",spacing:"xs",children:[ue(rn,{variant:"outline","aria-label":"Previous month",onClick:()=>l(-1),children:"<"}),ue(rn,{variant:"outline","aria-label":"Next month",onClick:()=>l(1),children:">"})]})]}),Rt("table",{className:o.table,children:[ue("thead",{children:Rt("tr",{children:[ue("th",{children:"SUN"}),ue("th",{children:"MON"}),ue("th",{children:"TUE"}),ue("th",{children:"WED"}),ue("th",{children:"THU"}),ue("th",{children:"FRI"}),ue("th",{children:"SAT"})]})}),ue("tbody",{children:f.map((i,s)=>ue("tr",{children:i.map((u,c)=>ue("td",{children:u&&ue(rn,{disabled:!u.available,onClick:()=>r(u.date),children:u.date.getDate()})},"day-"+c))},"week-"+s))})]})]})}function _I(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:KI(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 KI(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 ZI,createStyles as YI}from"@mantine/core";import{jsx as eg}from"react/jsx-runtime";var jI=YI(()=>({root:{"@media (max-width: 800px)":{paddingLeft:4,paddingRight:4}}}));function Ye(e){let{children:o,...t}=e,{classes:r}=jI();return eg(ZI,{className:r.root,...t,children:o})}import{ActionIcon as Ws,Center as ch,createStyles as dh,Group as mh,Loader as ph,Menu as Ge,ScrollArea as xh,TextInput as Ih}from"@mantine/core";import{showNotification as gh,updateNotification as Cr}from"@mantine/notifications";import{getReferenceString as Dt,normalizeErrorString as Xs}from"@medplum/core";import{useCallback as br,useEffect as hh,useRef as Js,useState as $s}from"react";import{createStyles as xg,Group as hr,List as ps,Stack as xs,Text as be,Title as Is}from"@mantine/core";import{capitalize as Ig,formatCodeableConcept as gg,formatDateTime as nn,formatObservationValue as hg,isReference as yg}from"@medplum/core";import{useEffect as vg,useState as Sg}from"react";import{Blockquote as og,createStyles as tg,Stack as rg}from"@mantine/core";import{jsx as cs}from"react/jsx-runtime";var ag=tg(e=>({noteBody:{fontSize:e.fontSizes.sm},noteCite:{fontSize:e.fontSizes.xs,marginBlockStart:3},noteRoot:{padding:5}}));function an({value:e}){let{classes:o}=ag();return e?cs(rg,{justify:"flex-start",spacing:"xs",children:e.map(t=>t.text&&cs(og,{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 ug}from"@mantine/core";import{Text as ng}from"@mantine/core";import{getDisplayString as lg,isOk as fg,normalizeErrorString as sg}from"@medplum/core";import{useState as ig}from"react";import{jsx as ds}from"react/jsx-runtime";function Fe(e){let{value:o,link:t,...r}=e,[a,n]=ig(),l=z(o,n),f;if(a&&!fg(a))f=`[${sg(a)}]`;else if(l)f=lg(l);else return null;return t?ds(te,{to:o,...r,children:f}):ds(ng,{component:"span",...r,children:f})}import{jsx as ms,jsxs as cg}from"react/jsx-runtime";function je(e){return cg(ug,{spacing:"xs",children:[ms(se,{size:24,radius:12,value:e.value,link:e.link}),ms(Fe,{value:e.value,link:e.link})]})}import{Badge as dg}from"@mantine/core";import{jsx as pg}from"react/jsx-runtime";var mg={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 gr(e){return pg(dg,{color:mg[e.status],children:e.status})}import{Fragment as Pt,jsx as D,jsxs as ce}from"react/jsx-runtime";var gs=xg(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}}));ln.defaultProps={hideObservationNotes:!1,hideSpecimenInfo:!1};function ln(e){let o=R(),t=z(e.value),[r,a]=Sg();if(vg(()=>{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 ce(xs,{children:[D(Is,{children:"Diagnostic Report"}),D(Cg,{value:t}),r&&!e.hideSpecimenInfo&&bg(r),t.result&&D(Rg,{hideObservationNotes:e.hideObservationNotes,value:t.result}),n.length>0&&D(an,{value:n})]})}function Cg({value:e}){return ce(hr,{mt:"md",spacing:30,children:[e.subject&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Subject"}),D(be,{children:D(je,{value:e.subject,link:!0})})]}),e.resultsInterpreter?.map(o=>ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Interpreter"}),D(be,{children:D(je,{value:o,link:!0})})]},o.reference)),e.performer?.map(o=>ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Performer"}),D(be,{children:D(je,{value:o,link:!0})})]},o.reference)),e.issued&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Issued"}),D(be,{children:nn(e.issued)})]}),e.status&&ce("div",{children:[D(be,{size:"xs",transform:"uppercase",color:"dimmed",children:"Status"}),D(be,{children:Ig(e.status)})]})]})}function bg(e){return ce(xs,{spacing:"xs",children:[D(Is,{order:2,size:"h6",children:"Specimens"}),D(ps,{type:"ordered",children:e?.map(o=>D(ps.Item,{ml:"sm",children:ce(hr,{spacing:20,children:[ce(hr,{spacing:5,children:[D(be,{fw:500,children:"Collected:"})," ",nn(o.collection?.collectedDateTime)]}),ce(hr,{spacing:5,children:[D(be,{fw:500,children:"Received:"})," ",nn(o.receivedTime)]})]})},`specimen-${o.id}`))})]})}function Rg(e){let{classes:o}=gs();return ce("table",{className:o.table,children:[D("thead",{children:ce("tr",{children:[D("th",{children:"Test"}),D("th",{children:"Value"}),D("th",{children:"Reference Range"}),D("th",{children:"Interpretation"}),D("th",{children:"Category"}),D("th",{children:"Performer"}),D("th",{children:"Status"})]})}),D("tbody",{children:D(hs,{value:e.value,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes})})]})}function hs(e){return D(Pt,{children:e.value?.map(o=>D(Pg,{value:o,ancestorIds:e.ancestorIds,hideObservationNotes:e.hideObservationNotes},`obs-${yg(o)?o.reference:o.id}`))})}function Pg(e){let{classes:o,cx:t}=gs(),r=z(e.value);if(!r||e.ancestorIds?.includes(r.id))return null;let a=!e.hideObservationNotes&&r.note,n=kg(r);return ce(Pt,{children:[ce("tr",{className:t({[o.criticalRow]:n}),children:[D("td",{rowSpan:a?2:1,children:D(te,{to:r,children:D(Oo,{value:r.code})})}),D("td",{children:D(Tg,{value:r})}),D("td",{children:D(Dg,{value:r.referenceRange})}),D("td",{children:r.interpretation&&r.interpretation.length>0&&D(Oo,{value:r.interpretation[0]})}),D("td",{children:r.category&&r.category.length>0&&D(Pt,{children:r.category.map(l=>D("div",{children:D(Oo,{value:l})},`category-${gg(l)}`))})}),D("td",{children:r.performer?.map(l=>D(po,{value:l},l.reference))}),D("td",{children:r.status&&D(gr,{status:r.status})})]}),r.hasMember&&D(hs,{value:r.hasMember,ancestorIds:e.ancestorIds?[...e.ancestorIds,r.id]:[r.id],hideObservationNotes:e.hideObservationNotes}),a&&D("tr",{children:D("td",{colSpan:6,children:D(an,{value:r.note})})})]})}function Tg(e){let o=e.value;return D(Pt,{children:hg(o)})}function Dg(e){let o=e.value&&e.value.length>0&&e.value[0];return o?o.text?D(Pt,{children:o.text}):D(or,{value:o}):null}function kg(e){let o=e.interpretation?.[0]?.coding?.[0]?.code;return o==="AA"||o==="LL"||o==="HH"||o==="A"}import{createStyles as Bg,Paper as Ag,useComponentDefaultProps as Mg}from"@mantine/core";import{jsx as Og}from"react/jsx-runtime";var Fg=Bg((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%"}}})),wg={shadow:"xs",radius:"md",withBorder:!0};function Vo(e){let{className:o,children:t,width:r,fill:a,unstyled:n,...l}=Mg("Panel",wg,e),{classes:f,cx:i}=Fg({width:r,fill:a},{name:"Panel",unstyled:n});return Og(Ag,{className:i(f.paper,o),...l,children:t})}import{createStyles as Kg}from"@mantine/core";import{capitalize as Zg,evalFhirPathTyped as Os,getSearchParameterDetails as Yg,toTypedValue as Es}from"@medplum/core";var Ns=sc(ws(),1);import{useEffect as jg,useState as eh}from"react";import{jsx as qe,jsxs as Sr}from"react/jsx-runtime";var oh=Kg(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 Vs(e){let{classes:o}=oh(),t=R(),[r,a]=eh(!1);if(jg(()=>{t.requestSchema(e.original.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.original.resourceType]),!r)return null;let n=(0,Ns.createPatch)(e.original,e.revised),l=[Es(e.original)],f=[Es(e.revised)];return Sr("table",{className:o.root,children:[qe("thead",{children:Sr("tr",{children:[qe("th",{}),qe("th",{children:"Before"}),qe("th",{children:"After"})]})}),qe("tbody",{children:n.map(i=>{if(i.path.startsWith("/meta"))return null;let s=i.path,u=th(s),d=Yg(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:Os(u,l)?.[0],x=i.op==="remove"?void 0:Os(u,f)?.[0];return Sr("tr",{children:[Sr("td",{children:[Zg(i.op)," ",u]}),qe("td",{className:o.removed,children:p&&qe(le,{property:d,propertyType:p.type,value:Ls(p.value,m),ignoreMissingValues:!0})}),qe("td",{className:o.added,children:x&&qe(le,{property:d,propertyType:x.type,value:Ls(x.value,m),ignoreMissingValues:!0})})]},`op-${i.op}-${i.path}`)})})]})}function th(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 Ls(e,o){return Array.isArray(e)&&!o?e[0]:!Array.isArray(e)&&o?[e]:e}import{useEffect as rh,useState as ah}from"react";import{jsx as nh}from"react/jsx-runtime";function yn(e){let o=R(),t=z(e.value),[r,a]=ah(!1);return rh(()=>{t&&o.requestSchema(t.resourceType).then(()=>a(!0)).catch(console.log)},[o,t]),!r||!t?null:nh(gt,{value:{type:t.resourceType,value:e.forceUseInput?e.value:t},ignoreMissingValues:e.ignoreMissingValues})}import{ActionIcon as lh,Group as fh,Menu as Hs,Text as vn}from"@mantine/core";import{formatDateTime as sh,getReferenceString as ih}from"@medplum/core";import{Fragment as uh,jsx as Re,jsxs as Ho}from"react/jsx-runtime";function qs(e){return Re(Ye,{children:e.children})}function eo(e){let{resource:o,profile:t,padding:r,popupMenuItems:a,...n}=e,l=t??o.meta?.author,f=e.dateTime??o.meta?.lastUpdated;return Ho(Vo,{"data-testid":"timeline-item",fill:!0,...n,children:[Ho(fh,{position:"apart",spacing:8,mx:"xs",my:"sm",children:[Re(se,{value:l,link:!0,size:"md"}),Ho("div",{style:{flex:1},children:[Re(vn,{size:"sm",children:Re(Fe,{color:"dark",weight:500,value:l,link:!0})}),Ho(vn,{size:"xs",children:[Re(te,{color:"dimmed",to:e.resource,children:sh(f)}),Re(vn,{component:"span",color:"dimmed",mx:8,children:"\xB7"}),Re(te,{color:"dimmed",to:e.resource,children:e.resource.resourceType})]})]}),a&&Ho(Hs,{position:"bottom-end",shadow:"md",width:200,children:[Re(Hs.Target,{children:Re(lh,{radius:"xl","aria-label":`Actions for ${ih(e.resource)}`,children:Re(Sa,{})})}),a]})]}),Ho(Do,{children:[r&&Re("div",{style:{padding:"0 16px 16px 16px"},children:e.children}),!r&&Re(uh,{children:e.children})]})]})}function Qs(e,o){e.sort((t,r)=>{let a=Gs(t,o),n=Gs(r,o);return a>n?1:a<n?-1:Us(t,o)-Us(r,o)})}function Gs(e,o){if(!zs(e,o)){let t=e.priority;if(typeof t=="string")return{stat:4,asap:3,urgent:2}[t]??0}return 0}function Us(e,o){if(!zs(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 zs(e,o){return!!o&&e.resourceType===o.resourceType&&e.id===o.id}import{Fragment as Dh,jsx as k,jsxs as kt}from"react/jsx-runtime";var yh=dh(e=>({pinnedComment:{backgroundColor:e.colors.blue[0]}}));function oo(e){let o=R(),t=Xe(),r=o.getProfile(),a=Js(null),n=z(e.value),[l,f]=$s(),[i,s]=$s([]),u=e.loadTimelineResources,c=Js(i);c.current=i;let d=br(b=>{Qs(b,n),b.reverse(),s(b)},[n]),m=br(b=>{let L=[];for(let We of b){if(We.status!=="fulfilled")continue;let P=We.value;if(P.type==="history"&&f(P),P.entry)for(let H of P.entry)L.push(H.resource)}d(L)},[d]),p=br(b=>d([...c.current,b]),[d]),x=br(()=>{let b,L;"resourceType"in e.value?(b=e.value.resourceType,L=e.value.id):[b,L]=e.value.reference?.split("/"),u(o,b,L).then(m).catch(console.log)},[o,e.value,u,m]);hh(()=>x(),[x]);function S(b){!n||!e.createCommunication||o.createResource(e.createCommunication(n,r,b)).then(L=>p(L)).catch(console.log)}function y(b){!n||!e.createMedia||o.createResource(e.createMedia(n,r,b)).then(L=>p(L)).then(()=>Cr({id:"upload-notification",color:"teal",title:"Upload complete",message:"",icon:k(st,{size:16}),autoClose:2e3})).catch(L=>Cr({id:"upload-notification",color:"red",title:"Upload error",message:Xs(L),icon:k(Qt,{size:16}),autoClose:2e3}))}function v(b,L){return o.updateResource({...b,priority:L})}function C(b){v(b,"stat").then(x).catch(console.log)}function T(b){v(b,"routine").then(x).catch(console.log)}function h(b){t(`/${b.resourceType}/${b.id}`)}function M(b){t(`/${b.resourceType}/${b.id}/edit`)}function Q(b){t(`/${b.resourceType}/${b.id}/delete`)}function Z(b){t(`/${b.resourceType}/${b.id}/_history/${b.meta?.versionId}`)}function tt(){gh({id:"upload-notification",loading:!0,title:"Initializing upload...",message:"Please wait...",autoClose:!1,withCloseButton:!1})}function ye(b){Cr({id:"upload-notification",loading:!0,title:"Uploading...",message:Th(b),autoClose:!1,withCloseButton:!1})}function ve(b){Cr({id:"upload-notification",color:"red",title:"Upload error",message:Xs(b),icon:k(Qt,{size:16}),autoClose:2e3})}return n?kt(qs,{children:[e.createCommunication&&k(Vo,{children:k(J,{testid:"timeline-form",onSubmit:b=>{S(b.text);let L=a.current;L&&(L.value="",L.focus())},children:kt(mh,{spacing:"xs",noWrap:!0,style:{width:"100%"},children:[k(se,{value:r}),k(Ih,{name:"text",ref:a,placeholder:"Add comment",style:{width:"100%",maxWidth:300}}),k(Ws,{type:"submit",radius:"xl",color:"blue",variant:"filled",children:k(Da,{size:16})}),k(wo,{onUpload:y,onUploadStart:tt,onUploadProgress:ye,onUploadError:ve,children:b=>k(Ws,{...b,radius:"xl",color:"blue",variant:"filled",children:k(it,{size:16})})})]})})}),i.map(b=>{if(!b)return null;let L=`${b.resourceType}/${b.id}/${b.meta?.versionId}`;if(b.resourceType===n.resourceType&&b.id===n.id)return k(vh,{history:l,resource:b,onDetails:Z},L);switch(b.resourceType){case"AuditEvent":return k(Rh,{resource:b,onDetails:h},L);case"Communication":return k(Ch,{resource:b,onPin:b.priority!=="stat"?C:void 0,onUnpin:b.priority==="stat"?T:void 0,onDetails:h,onEdit:M,onDelete:Q},L);case"DiagnosticReport":return k(Ph,{resource:b,onDetails:h,onEdit:M,onDelete:Q},L);case"Media":return k(bh,{resource:b,onDetails:h,onEdit:M,onDelete:Q},L);default:return k(eo,{resource:b,padding:!0,children:k(yn,{value:b,ignoreMissingValues:!0})},L)}})]}):k(ch,{style:{width:"100%",height:"100%"},children:k(ph,{})})}function qo(e){return kt(Ge.Dropdown,{children:[k(Ge.Label,{children:"Resource"}),e.onPin&&k(Ge.Item,{icon:k(ka,{size:14}),onClick:()=>e.onPin(e.resource),"aria-label":`Pin ${Dt(e.resource)}`,children:"Pin"}),e.onUnpin&&k(Ge.Item,{icon:k(Ba,{size:14}),onClick:()=>e.onUnpin(e.resource),"aria-label":`Unpin ${Dt(e.resource)}`,children:"Unpin"}),e.onDetails&&k(Ge.Item,{icon:k(Pa,{size:14}),onClick:()=>e.onDetails(e.resource),"aria-label":`Details ${Dt(e.resource)}`,children:"Details"}),e.onEdit&&k(Ge.Item,{icon:k(Ca,{size:14}),onClick:()=>e.onEdit(e.resource),"aria-label":`Edit ${Dt(e.resource)}`,children:"Edit"}),e.onDelete&&kt(Dh,{children:[k(Ge.Divider,{}),k(Ge.Label,{children:"Danger zone"}),k(Ge.Item,{color:"red",icon:k(dt,{size:14}),onClick:()=>e.onDelete(e.resource),"aria-label":`Delete ${Dt(e.resource)}`,children:"Delete"})]})]})}function vh(e){let o=Sh(e.history,e.resource);return o?k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(Vs,{original:o,revised:e.resource})}):kt(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:[k("h3",{children:"Created"}),k(yn,{value:e.resource,ignoreMissingValues:!0,forceUseInput:!0})]})}function Sh(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 Ch(e){let{classes:o}=yh(),r=!e.resource.priority||e.resource.priority==="routine"?void 0:o.pinnedComment;return k(eo,{resource:e.resource,profile:e.resource.sender,dateTime:e.resource.sent,padding:!0,className:r,popupMenuItems:k(qo,{...e}),children:k("p",{children:e.resource.payload?.[0]?.contentString})})}function bh(e){let o=e.resource.content?.contentType,t=o&&!o.startsWith("image/")&&!o.startsWith("video/")&&o!=="application/pdf";return k(eo,{resource:e.resource,padding:!!t,popupMenuItems:k(qo,{...e}),children:k(Me,{value:e.resource.content})})}function Rh(e){return k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(xh,{children:k("pre",{children:e.resource.outcomeDesc})})})}function Ph(e){return k(eo,{resource:e.resource,padding:!0,popupMenuItems:k(qo,{...e}),children:k(ln,{value:e.resource})})}function Th(e){if(e.lengthComputable){let o=100*e.loaded/e.total;return`Uploaded: ${Sn(e.loaded)} / ${Sn(e.total)} ${o.toFixed(2)}%`}return`Uploaded: ${Sn(e.loaded)}`}function Sn(e){if(e===0)return"0.00 B";let o=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,o)).toFixed(2)+" "+" KMGTP".charAt(o)+"B"}import{jsx as kh}from"react/jsx-runtime";function f0(e){return kh(oo,{value:e.resource,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory(t,r),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])}})}import{jsx as _s}from"react/jsx-runtime";function Rr(e){let{children:o,...t}=e;return _s(Ye,{children:_s(Vo,{...t,children:o})})}import{createReference as Pr}from"@medplum/core";import{jsx as Bh}from"react/jsx-runtime";function y0(e){return Bh(oo,{value:e.encounter,loadTimelineResources:async(o,t,r)=>Promise.allSettled([o.readHistory("Encounter",r),o.search("Communication","encounter=Encounter/"+r),o.search("Media","encounter=Encounter/"+r)]),createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",encounter:Pr(o),subject:o.subject,sender:Pr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",encounter:Pr(o),subject:o.subject,operator:Pr(t),issued:new Date().toISOString(),content:r})})}import{Button as $y,Loader as _y,Table as Ky}from"@mantine/core";import{normalizeOperationOutcome as Zy}from"@medplum/core";import{memo as Yy,useEffect as Ai,useRef as Mi,useState as wr}from"react";import{evalFhirPath as Ah}from"@medplum/core";import{jsx as Mh}from"react/jsx-runtime";function Ks(e){let o;try{o=Ah(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 Mh(le,{value:o[0]||"",propertyType:e.propertyType})}import{ActionIcon as My,Button as Wo,Center as Mr,createStyles as Fy,Group as Fr,Loader as wy,Menu as Di,Pagination as Oy,Table as Ey,Text as Fn,UnstyledButton as Ly}from"@mantine/core";import{DEFAULT_SEARCH_COUNT as Ln,formatSearchQuery as Ny}from"@medplum/core";import{memo as Vy,useCallback as ki,useEffect as Bi,useRef as Hy,useState as wn}from"react";import{Box as Fh,Button as wh,Modal as Oh,Text as Eh}from"@mantine/core";import{jsx as Tr,jsxs as Ys}from"react/jsx-runtime";function js(e){return Ys(Oh,{title:"Export",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:e.onCancel,children:[Ys(Fh,{display:"flex",sx:{justifyContent:"space-between"},children:[e.exportCsv&&Tr(Zs,{text:"CSV",exportLogic:e.exportCsv,onCancel:e.onCancel}),e.exportTransactionBundle&&Tr(Zs,{text:"Transaction Bundle",exportLogic:e.exportTransactionBundle,onCancel:e.onCancel})]}),Tr(Eh,{sx:{marginTop:"10px",marginLeft:"2px"},children:"Limited to 1000 records"})]})}function Zs(e){return Tr(wh,{onClick:()=>{e.exportLogic(),e.onCancel()},children:`Export as ${e.text}`})}import{Button as Xh,Group as Jh,Modal as $h,MultiSelect as _h,Stack as Kh}from"@mantine/core";import{getDataType as Zh,getSearchParameters as Yh,stringify as jh}from"@medplum/core";import{useEffect as ey,useMemo as oy,useRef as ty,useState as pi}from"react";import{capitalize as Lh,DEFAULT_SEARCH_COUNT as Nh,evalFhirPathTyped as Vh,formatDateTime as Hh,Operator as F}from"@medplum/core";import{Fragment as Wh,jsx as Cn}from"react/jsx-runtime";var qh={string:[F.EQUALS,F.NOT,F.CONTAINS,F.EXACT],fulltext:[F.EQUALS,F.NOT,F.CONTAINS,F.EXACT],token:[F.EQUALS,F.NOT],reference:[F.EQUALS,F.NOT],numeric:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS],quantity:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS],date:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS,F.STARTS_AFTER,F.ENDS_BEFORE,F.APPROXIMATELY],datetime:[F.EQUALS,F.NOT_EQUALS,F.GREATER_THAN,F.LESS_THAN,F.GREATER_THAN_OR_EQUALS,F.LESS_THAN_OR_EQUALS,F.STARTS_AFTER,F.ENDS_BEFORE,F.APPROXIMATELY]},Gh={eq:"equals",ne:"not equals",gt:"greater than",lt:"less than",ge:"greater than or equals",le:"less than or equals",sa:"starts after",eb:"ends before",ap:"approximately",contains:"contains",exact:"exact",text:"text",not:"not",above:"above",below:"below",in:"in","not-in":"not in","of-type":"of type",missing:"missing",identifier:"identifier",iterate:"iterate"};function Bt(e,o){return{...e,filters:o,offset:0,name:void 0}}function E0(e){return Bt(e,[])}function Dr(e,o){return Bt(e,(e.filters??[]).filter(t=>t.code!==o))}function Go(e,o,t,r,a){a&&(e=Dr(e,o));let n=[];return e.filters&&n.push(...e.filters),n.push({code:o,operator:t,value:r??""}),Bt(e,n)}function L0(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 oi(e,o){if(!e.filters)return e;let t=[...e.filters];return t.splice(o,1),{...e,filters:t,name:void 0}}function ti(e,o){return bn(e,o,-1)}function ri(e,o){return bn(e,o,0)}function ai(e,o){return bn(e,o,1)}function bn(e,o,t){let r=new Date;r.setDate(r.getDate()+t),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setDate(a.getDate()+1),a.setTime(a.getTime()-1),Pn(e,o,r,a)}function ni(e,o){return Rn(e,o,-1)}function li(e,o){return Rn(e,o,0)}function fi(e,o){return Rn(e,o,1)}function Rn(e,o,t){let r=new Date;r.setMonth(r.getMonth()+t),r.setDate(1),r.setHours(0,0,0,0);let a=new Date(r.getTime());return a.setMonth(a.getMonth()+1),a.setDate(1),a.setHours(0,0,0,0),a.setTime(a.getTime()-1),Pn(e,o,r,a)}function si(e,o){let t=new Date;return t.setMonth(0),t.setDate(1),t.setHours(0,0,0,0),Pn(e,o,t,new Date)}function Pn(e,o,t,r){return e=Dr(e,o),e=ei(e,o,F.GREATER_THAN_OR_EQUALS,t),e=ei(e,o,F.LESS_THAN_OR_EQUALS,r),e}function ei(e,o,t,r){return Go(e,o,t,r.toISOString())}function Tn(e,o,t=!0){return Go(e,o,F.MISSING,t.toString())}function Uh(e,o){return e.offset===o?e:{...e,offset:o,name:void 0}}function ii(e,o){let t=e.count??Nh,r=(o-1)*t;return Uh(e,r)}function Dn(e,o,t){return o===ui(e)&&t!==void 0&&t===ci(e)?e:{...e,sortRules:[{code:o,descending:!!t}],name:void 0}}function N0(e,o){let t=!1;return ui(e)===o&&(t=!ci(e)),Dn(e,o,t)}function ui(e){let o=e.sortRules;if(!o||o.length===0)return;let t=o[0].code;return t.startsWith("-")?t.substr(1):t}function ci(e){let o=e.sortRules;return!o||o.length===0?!1:!!o[0].descending}function di(e){return qh[e.type]}function At(e){return Gh[e]??""}function Pe(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(Lh).join(" "))}function mi(e,o){let t=o.name;return t==="id"?e.id:t==="meta.versionId"?e.meta?.versionId:t==="_lastUpdated"?Hh(e.meta?.lastUpdated):o.elementDefinition&&`${e.resourceType}.${o.name}`===o.elementDefinition.path?Qh(e,o.elementDefinition):o.searchParams&&o.searchParams.length===1&&o.name===o.searchParams[0].code?zh(e,o.searchParams[0]):null}function Qh(e,o){let t=o.path?.split(".")?.pop()?.replaceAll("[x]","")??"",[r,a]=Ke({type:e.resourceType,value:e},t);return r?Cn(le,{property:o,propertyType:a,value:r,maxWidth:200,ignoreMissingValues:!0,link:!1}):null}function zh(e,o){let t=Vh(o.expression,[{type:e.resourceType,value:e}]);return!t||t.length===0?null:Cn(Wh,{children:t.map((r,a)=>Cn(le,{propertyType:r.type,value:r.value,maxWidth:200,ignoreMissingValues:!0,link:!1},`${a}-${t.length}`))})}import{jsx as Mt,jsxs as ay}from"react/jsx-runtime";function xi(e){let o=ty(!1),[t,r]=pi({search:JSON.parse(jh(e.search))}),[a,n]=pi(!1);ey(()=>{r({search:e.search})},[e.search]);let l=oy(()=>{if(!e.visible)return[];let i=e.search.resourceType,s=Zh(i),u=Yh(i);return ry(s,u).sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:Pe(c)}))},[e.visible,e.search.resourceType]);if(!e.visible)return null;function f(i){r({search:{...t.search,fields:i}})}return Mt($h,{title:"Fields",closeButtonProps:{"aria-label":"Close"},opened:e.visible,onClose:()=>{e.onCancel()},size:"auto",withOverlay:!0,closeOnClickOutside:!1,overlayProps:{onMouseDownCapture:()=>{o.current=a},onClick:()=>{o.current||e.onCancel(),o.current=!1},children:Mt("div",{"data-testid":"overlay-child"})},children:ay(Kh,{children:[Mt(_h,{withinPortal:!0,style:{width:550},placeholder:"Select fields to display",data:l,value:t.search.fields??[],onChange:f,onDropdownOpen:()=>n(!0),onDropdownClose:()=>n(!1),maxDropdownHeight:"250px",dropdownPosition:"bottom",clearButtonProps:{"aria-label":"Clear selection"},clearable:!0,searchable:!0}),Mt(Jh,{position:"right",children:Mt(Xh,{onClick:()=>e.onOk(t.search),children:"OK"})})]})})}function ry(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(Pe(n));if(o)for(let n of Object.keys(o)){let l=Pe(n);!r.has(n)&&!a.has(l)&&(t.push(n),r.add(n),a.add(l))}return t}import{Button as Ft,Group as dy,Modal as my,NativeSelect as hi}from"@mantine/core";import{getSearchParameters as py,stringify as yi}from"@medplum/core";import{useEffect as xy,useRef as Si,useState as An}from"react";import{formatDateTime as ny,getSearchParameterDetails as ly,globalSchema as fy,Operator as Ii,SearchParameterType as sy}from"@medplum/core";import{Fragment as gi,jsx as kn}from"react/jsx-runtime";function kr(e){let{resourceType:o,filter:t}=e,r=fy.types[o].searchParams?.[t.code];if(r){if(r.type==="reference"&&(t.operator===Ii.EQUALS||t.operator===Ii.NOT_EQUALS))return kn(Fe,{value:{reference:t.value}});let a=ly(o,r);if(t.code==="_lastUpdated"||a.type===sy.DATETIME)return kn(gi,{children:ny(t.value)})}return kn(gi,{children:t.value})}import{Checkbox as iy,TextInput as Bn}from"@mantine/core";import{getSearchParameterDetails as uy,SearchParameterType as Uo}from"@medplum/core";import{jsx as xo}from"react/jsx-runtime";function Br(e){let o=uy(e.resourceType,e.searchParam),t="filter-value";switch(o.type){case Uo.REFERENCE:return xo(No,{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 Uo.BOOLEAN:return xo(iy,{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 Uo.DATE:return xo(Bn,{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 Uo.DATETIME:return xo(Be,{name:t,defaultValue:e.defaultValue,autoFocus:e.autoFocus,onChange:e.onChange});case Uo.NUMBER:return xo(Bn,{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 Uo.QUANTITY:return xo(Ce,{name:t,defaultValue:cy(e.defaultValue),autoFocus:e.autoFocus,onChange:r=>{r?e.onChange(`${r.value}`):e.onChange("")}});default:return xo(Bn,{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 cy(e){if(e){let[o,t,r]=e.split("|");if(o)return{value:parseFloat(o),system:t,unit:r}}}import{jsx as U,jsxs as Ue}from"react/jsx-runtime";function Ci(e){let[o,t]=An(JSON.parse(yi(e.search))),[r,a]=An(-1),n=Si(o);n.current=o,xy(()=>{t(JSON.parse(yi(e.search)))},[e.search]);function l(u){t(Go(n.current,u.code,u.operator,u.value))}if(!e.visible)return null;let f=e.search.resourceType,i=py(f)??{},s=o.filters||[];return Ue(my,{title:"Filters",closeButtonProps:{"aria-label":"Close"},size:900,opened:e.visible,onClose:e.onCancel,children:[U("div",{children:Ue("table",{children:[Ue("colgroup",{children:[U("col",{style:{width:200}}),U("col",{style:{width:200}}),U("col",{style:{width:380}}),U("col",{style:{width:120}})]}),U("thead",{children:Ue("tr",{children:[U("th",{children:"Field"}),U("th",{children:"Operation"}),U("th",{children:"Value"}),U("th",{children:"Actions"})]})}),Ue("tbody",{children:[s.map((u,c)=>c===r?U(vi,{resourceType:f,searchParams:i,defaultValue:u,okText:"Save",onOk:d=>{let m=[...s];m[c]=d,t(Bt(n.current,m)),a(-1)},onCancel:()=>a(-1)},`filter-${u.code}-${u.operator}-${u.value}-input`):U(Iy,{resourceType:f,searchParams:i,filter:u,onEdit:()=>a(c),onDelete:()=>t(oi(n.current,c))},`filter-${u.code}-${u.operator}-${u.value}-display`)),U(vi,{resourceType:f,searchParams:i,okText:"Add",onOk:l})]})]})}),U(dy,{position:"right",mt:"xl",children:U(Ft,{onClick:()=>e.onOk(n.current),children:"OK"})})]})}function Iy(e){let{filter:o}=e;return Ue("tr",{children:[U("td",{children:Pe(o.code)}),U("td",{children:At(o.operator)}),U("td",{children:U(kr,{resourceType:e.resourceType,filter:o})}),Ue("td",{children:[U(Ft,{compact:!0,variant:"outline",onClick:e.onEdit,children:"Edit"}),U(Ft,{compact:!0,variant:"outline",onClick:e.onDelete,children:"Delete"})]})]})}function vi(e){let[o,t]=An(e.defaultValue??{}),r=Si(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&&di(f);return Ue("tr",{children:[U("td",{children:U(hi,{"data-testid":"filter-field",defaultValue:r.current.code,onChange:s=>a(s.currentTarget.value),data:["",...Object.keys(e.searchParams).map(s=>({value:s,label:Pe(s)}))]})}),U("td",{children:i&&U(hi,{"data-testid":"filter-operation",defaultValue:o.operator,onChange:s=>n(s.currentTarget.value),data:["",...i.map(s=>({value:s,label:At(s)}))]})}),U("td",{children:f&&o.operator&&U(Br,{resourceType:e.resourceType,searchParam:f,defaultValue:o.value,onChange:l})}),Ue("td",{children:[o.code&&o.operator&&U(Ft,{compact:!0,variant:"outline",onClick:()=>{e.onOk(r.current),t({})},children:e.okText}),e.onCancel&&U(Ft,{compact:!0,variant:"outline",onClick:e.onCancel,children:"Cancel"})]})]})}import{Button as gy,Grid as Mn,Modal as hy}from"@mantine/core";import{useState as yy}from"react";import{jsx as Qo,jsxs as vy}from"react/jsx-runtime";function bi(e){let[o,t]=yy(e.defaultValue??"");if(!e.visible||!e.searchParam||!e.filter)return null;function r(){e.onOk({...e.filter,value:o})}return Qo(hy,{title:e.title,size:"xl",opened:e.visible,onClose:e.onCancel,children:Qo(J,{onSubmit:r,children:vy(Mn,{children:[Qo(Mn.Col,{span:10,children:Qo(Br,{resourceType:e.resourceType,searchParam:e.searchParam,defaultValue:o,autoFocus:!0,onChange:t})}),Qo(Mn.Col,{span:2,children:Qo(gy,{onClick:r,fullWidth:!0,children:"OK"})})]})})})}import{Menu as B}from"@mantine/core";import{Operator as re}from"@medplum/core";import{Fragment as Pi,jsx as g,jsxs as zo}from"react/jsx-runtime";function Ri(e){if(!e.searchParams)return null;function o(n,l){a(Dn(e.search,n.code,l))}function t(n){a(Dr(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(Sy,{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:Pe(n.code)},n.code))})}function Sy(e){switch(e.searchParam.type){case"date":return g(Cy,{...e});case"number":case"quantity":return g(by,{...e});case"reference":return g(Ry,{...e});case"string":case"token":case"uri":return g(Py,{...e});default:return zo(Pi,{children:["Unknown search param type: ",e.searchParam.type]})}}function Cy(e){let{searchParam:o}=e,t=o.code;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Oldest to Newest"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Newest to Oldest"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,re.ENDS_BEFORE),children:"Before..."}),g(B.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,re.STARTS_AFTER),children:"After..."}),g(B.Item,{icon:g(ma,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Between..."}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ai(e.search,t)),children:"Tomorrow"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ri(e.search,t)),children:"Today"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ti(e.search,t)),children:"Yesterday"}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(fi(e.search,t)),children:"Next Month"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(li(e.search,t)),children:"This Month"}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(ni(e.search,t)),children:"Last Month"}),g(B.Divider,{}),g(B.Item,{icon:g(Le,{size:14}),onClick:()=>e.onChange(si(e.search,t)),children:"Year to date"}),g(Ar,{...e})]})}function by(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort Smallest to Largest"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Largest to Smallest"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT_EQUALS),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(zt,{size:14}),onClick:()=>e.onPrompt(o,re.GREATER_THAN),children:"Greater than..."}),g(B.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,re.GREATER_THAN_OR_EQUALS),children:"Greater than or equal to..."}),g(B.Item,{icon:g(Wt,{size:14}),onClick:()=>e.onPrompt(o,re.LESS_THAN),children:"Less than..."}),g(B.Item,{icon:g(To,{size:14}),onClick:()=>e.onPrompt(o,re.LESS_THAN_OR_EQUALS),children:"Less than or equal to..."}),g(Ar,{...e})]})}function Ry(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT),children:"Does not equal..."}),g(Ar,{...e})]})}function Py(e){let{searchParam:o}=e;return zo(B.Dropdown,{children:[g(B.Item,{icon:g(ut,{size:14}),onClick:()=>e.onSort(o,!1),children:"Sort A to Z"}),g(B.Item,{icon:g(ct,{size:14}),onClick:()=>e.onSort(o,!0),children:"Sort Z to A"}),g(B.Divider,{}),g(B.Item,{icon:g(Po,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Equals..."}),g(B.Item,{icon:g(Ro,{size:14}),onClick:()=>e.onPrompt(o,re.NOT),children:"Does not equal..."}),g(B.Divider,{}),g(B.Item,{icon:g(xa,{size:14}),onClick:()=>e.onPrompt(o,re.CONTAINS),children:"Contains..."}),g(B.Item,{icon:g(pa,{size:14}),onClick:()=>e.onPrompt(o,re.EQUALS),children:"Does not contain..."}),g(Ar,{...e})]})}function Ar(e){let{searchParam:o}=e,t=o.code;return zo(Pi,{children:[g(B.Divider,{}),g(B.Item,{icon:g(ca,{size:14}),onClick:()=>e.onChange(Tn(e.search,t)),children:"Missing"}),g(B.Item,{icon:g(ua,{size:14}),onClick:()=>e.onChange(Tn(e.search,t,!1)),children:"Not missing"}),g(B.Divider,{}),g(B.Item,{icon:g(La,{size:14}),onClick:()=>e.onClear(o),children:"Clear filters"})]})}import{getElementDefinition as Ty,getSearchParameter as Dy,getSearchParameterDetails as ky,getSearchParameters as By}from"@medplum/core";function Ti(e){let o=e.resourceType,t=[];for(let r of e.fields||["id","_lastUpdated"])t.push(Ay(o,r));return t}function Ay(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=Ty(e,o),r=Dy(e,o.toLowerCase());if(t&&r)return{name:o,elementDefinition:t,searchParams:[r]};if(t){let a=By(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=ky(e,r);return{name:o,elementDefinition:a.elementDefinitions?.[0],searchParams:[r]}}return{name:o}}import{Fragment as Jy,jsx as A,jsxs as he}from"react/jsx-runtime";var On=class extends Event{constructor(t){super("change");this.definition=t}},En=class extends Event{constructor(t){super("load");this.response=t}},Io=class extends Event{constructor(t,r){super("click");this.resource=t,this.browserEvent=r}},qy=Fy(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 Gy(e){let{classes:o}=qy(),t=R(),[r,a]=wn(!1),[n,l]=wn(),{search:f,onLoad:i}=e,[s,u]=wn({selected:{},fieldEditorVisible:!1,filterEditorVisible:!1,exportDialogVisible:!1,filterDialogVisible:!1}),c=Hy(s);c.current=s;let d=f.total??"accurate",m=ki(P=>{l(void 0),t.search(f.resourceType,Ny({...f,total:d,fields:void 0}),P).then(H=>{u({...c.current,searchResponse:H}),i&&i(new En(H))}).catch(H=>{u({...c.current,searchResponse:void 0}),l(H)})},[t,f,d,i]),p=ki(()=>{u({...c.current,searchResponse:void 0}),m({cache:"reload"})},[m]);Bi(()=>{m()},[m]);function x(P,H){P.stopPropagation();let oe=P.target.checked,ne={...c.current.selected};oe?ne[H]=!0:delete ne[H],u({...c.current,selected:ne})}function S(P){P.stopPropagation();let Y=P.target.checked,oe={},ne=c.current.searchResponse;Y&&ne?.entry&&ne.entry.forEach(rt=>{rt.resource?.id&&(oe[rt.resource.id]=!0)}),u({...c.current,selected:oe})}function y(){let P=c.current;if(!P.searchResponse?.entry||P.searchResponse.entry.length===0)return!1;for(let H of P.searchResponse.entry)if(H.resource?.id&&!P.selected[H.resource.id])return!1;return!0}function v(P){e.onChange&&e.onChange(new On(P))}function C(P,H){if(Jt(P.target)||P.button===2)return;E(P);let Y=P.button===1||P.ctrlKey||P.metaKey;!Y&&e.onClick&&e.onClick(new Io(H,P)),Y&&e.onAuxClick&&e.onAuxClick(new Io(H,P))}function T(){return!!(e.onExport??e.onExportCsv??e.onExportTransactionBundle)}if(Bi(()=>{a(!1),t.requestSchema(e.search.resourceType).then(()=>a(!0)).catch(console.log)},[t,e.search.resourceType]),!r)return A(Mr,{style:{width:"100%",height:"100%"},children:A(wy,{})});let h=e.checkboxesEnabled,M=Ti(f),Q=f.resourceType,Z=s.searchResponse,ye=Z?.entry?.map(P=>P.resource),ve="subtle",b="gray",L=16,We=window.innerWidth<768;return he("div",{className:o.root,"data-testid":"search-control",children:[!e.hideToolbar&&he(Fr,{position:"apart",mb:"xl",children:[he(Fr,{spacing:2,children:[A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(ha,{size:L}),onClick:()=>u({...c.current,fieldEditorVisible:!0}),children:"Fields"}),A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(Ra,{size:L}),onClick:()=>u({...c.current,filterEditorVisible:!0}),children:"Filters"}),e.onNew&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(ba,{size:L}),onClick:e.onNew,children:"New..."}),!We&&T()&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(Ea,{size:L}),onClick:e.onExport?e.onExport:()=>u({...c.current,exportDialogVisible:!0}),children:"Export..."}),!We&&e.onDelete&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(dt,{size:L}),onClick:()=>e.onDelete(Object.keys(s.selected)),children:"Delete..."}),!We&&e.onBulk&&A(Wo,{compact:!0,variant:ve,color:b,leftIcon:A(da,{size:L}),onClick:()=>e.onBulk(Object.keys(s.selected)),children:"Bulk..."})]}),he(Fr,{spacing:2,children:[Z&&he(Fn,{size:"xs",color:"dimmed",children:[Wy(f,Z.total),"-",Xy(f,Z.total)," of"," ",`${d==="estimate"?"~":""}${Z.total?.toLocaleString()}`]}),A(My,{title:"Refresh",onClick:p,children:A(Ma,{size:"1.125rem"})})]})]}),he(Ey,{className:o.table,children:[he("thead",{children:[he("tr",{children:[h&&A("th",{children:A("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:y(),onChange:P=>S(P)})}),M.map(P=>A("th",{children:he(Di,{shadow:"md",width:240,position:"bottom-end",children:[A(Di.Target,{children:A(Ly,{className:o.control,children:he(Fr,{position:"apart",noWrap:!0,children:[A(Fn,{weight:500,size:"sm",children:Pe(P.name)}),A(Mr,{className:o.icon,children:A(fa,{size:14,stroke:1.5})})]})})}),A(Ri,{search:e.search,searchParams:P.searchParams,onPrompt:(H,Y)=>{u({...c.current,filterDialogVisible:!0,filterDialogSearchParam:H,filterDialogFilter:Y})},onChange:H=>{v(H)}})]})},P.name))]}),!e.hideFilters&&he("tr",{children:[h&&A("th",{}),M.map(P=>A("th",{children:P.searchParams&&A(Uy,{resourceType:Q,searchParams:P.searchParams,filters:e.search.filters})},P.name))]})]}),A("tbody",{children:ye?.map(P=>P&&he("tr",{className:o.tr,"data-testid":"search-control-row",onClick:H=>C(H,P),onAuxClick:H=>C(H,P),children:[h&&A("td",{children:A("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${P.id}`,checked:!!s.selected[P.id],onChange:H=>x(H,P.id)})}),M.map(H=>A("td",{children:mi(P,H)},H.name))]},P.id))})]}),ye?.length===0&&A(Ye,{children:A(Mr,{style:{height:150},children:A(Fn,{size:"xl",color:"dimmed",children:"No results"})})}),Z?.total!==void 0&&Z.total>0&&A(Mr,{m:"md",p:"md",children:A(Oy,{value:Qy(f),total:zy(f,Z.total),onChange:P=>v(ii(f,P)),getControlProps:P=>{switch(P){case"previous":return{"aria-label":"Previous page"};case"next":return{"aria-label":"Next page"};default:return{}}}})}),n&&A("div",{"data-testid":"search-error",children:A("pre",{style:{textAlign:"left"},children:JSON.stringify(n,void 0,2)})}),A(xi,{search:e.search,visible:c.current.fieldEditorVisible,onOk:P=>{v(P),u({...c.current,fieldEditorVisible:!1})},onCancel:()=>{u({...c.current,fieldEditorVisible:!1})}}),A(Ci,{search:e.search,visible:c.current.filterEditorVisible,onOk:P=>{v(P),u({...c.current,filterEditorVisible:!1})},onCancel:()=>{u({...c.current,filterEditorVisible:!1})}}),A(js,{visible:c.current.exportDialogVisible,exportCsv:e.onExportCsv,exportTransactionBundle:e.onExportTransactionBundle,onCancel:()=>{u({...c.current,exportDialogVisible:!1})}}),A(bi,{visible:c.current.filterDialogVisible,title:s.filterDialogSearchParam?.code?Pe(s.filterDialogSearchParam.code):"",resourceType:Q,searchParam:s.filterDialogSearchParam,filter:s.filterDialogFilter,defaultValue:"",onOk:P=>{v(Go(e.search,P.code,P.operator,P.value)),u({...c.current,filterDialogVisible:!1})},onCancel:()=>{u({...c.current,filterDialogVisible:!1})}},s.filterDialogSearchParam?.code)]})}var eL=Vy(Gy);function Uy(e){let o=(e.filters??[]).filter(t=>e.searchParams.find(r=>r.code===t.code));return o.length===0?A("span",{children:"no filters"}):A(Jy,{children:o.map(t=>he("div",{children:[At(t.operator),"\xA0",A(kr,{resourceType:e.resourceType,filter:t})]},`filter-${t.code}-${t.operator}-${t.value}`))})}function Qy(e){return Math.floor((e.offset??0)/(e.count??Ln))+1}function zy(e,o){let t=e.count??Ln;return Math.ceil(o/t)}function Wy(e,o){return Math.min(o,(e.offset??0)+1)}function Xy(e,o){return Math.min(o,((e.offset??0)+1)*(e.count??Ln))}import{jsx as xe,jsxs as Or}from"react/jsx-runtime";function jy(e){let o=R(),[t,r]=wr(!1),[a,n]=wr(),{query:l,fields:f}=e,[i,s]=wr(),[u,c]=wr({}),d=Mi();d.current=i;let m=Mi({});m.current=u,Ai(()=>{n(void 0),o.graphql(l).then(s).catch(C=>n(Zy(C)))},[o,l]);function p(C,T){C.stopPropagation();let M=C.target.checked,Q={...m.current};M?Q[T]=!0:delete Q[T],c(Q)}function x(C){C.stopPropagation();let h=C.target.checked,M={},Q=d.current?.data.ResourceList;h&&Q&&Q.forEach(Z=>{Z.id&&(M[Z.id]=!0)}),c(M)}function S(){let C=d.current?.data.ResourceList;if(!C||C.length===0)return!1;for(let T of C)if(T.id&&!m.current[T.id])return!1;return!0}function y(C,T){Jt(C.target)||(E(C),C.button!==1&&e.onClick&&e.onClick(new Io(T,C)),C.button===1&&e.onAuxClick&&e.onAuxClick(new Io(T,C)))}if(Ai(()=>{o.requestSchema(e.resourceType).then(()=>r(!0)).catch(console.log)},[o,e.resourceType]),!t)return xe(_y,{});let v=e.checkboxesEnabled;return Or("div",{onContextMenu:C=>E(C),"data-testid":"search-control",children:[Or(Ky,{children:[xe("thead",{children:Or("tr",{children:[v&&xe("th",{children:xe("input",{type:"checkbox",value:"checked","aria-label":"all-checkbox","data-testid":"all-checkbox",checked:S(),onChange:C=>x(C)})}),f.map(C=>xe("th",{children:C.name},C.name))]})}),xe("tbody",{children:i?.data.ResourceList.map(C=>C&&Or("tr",{"data-testid":"search-control-row",onClick:T=>y(T,C),onAuxClick:T=>y(T,C),children:[v&&xe("td",{children:xe("input",{type:"checkbox",value:"checked","data-testid":"row-checkbox","aria-label":`Checkbox for ${C.id}`,checked:!!u[C.id],onChange:T=>p(T,C.id)})}),f.map(T=>xe("td",{children:xe(Ks,{propertyType:T.propertyType,path:T.fhirPath,resource:C})},T.name))]},C.id))})]}),i?.data.ResourceList.length===0&&xe("div",{"data-testid":"empty-search",children:"No results"}),a&&xe("div",{"data-testid":"search-error",children:xe("pre",{style:{textAlign:"left"},children:JSON.stringify(a,void 0,2)})}),e.onBulk&&xe($y,{onClick:()=>e.onBulk(Object.keys(m.current)),children:"Bulk..."})]})}var dL=Yy(jy);import{jsx as Xo,jsxs as ev}from"react/jsx-runtime";function to(e){return ev("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 491 491",style:{width:e.size,height:e.size},children:[Xo("title",{children:"Medplum Logo"}),Xo("path",{fill:e.fill??"#ad7136",d:"M282 67c6-16 16-29 29-40L289 0c-22 17-37 41-43 68l17 23 19-24z"}),Xo("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"}),Xo("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"}),Xo("path",{fill:e.fill??"#40bc26",d:"M207 220a176 176 0 01-177 43A176 176 0 01251 43l1 5c17 59 2 125-45 172z"}),Xo("path",{fill:e.fill??"#33961e",d:"M252 48A421 421 0 0057 270l-27-7A176 176 0 01251 43l1 5z"})]})}import{Box as lv,SimpleGrid as fv}from"@mantine/core";import{Box as Fi,Flex as Nn,Group as ov,Paper as tv,RingProgress as Oi,Text as go,Title as Vn}from"@mantine/core";import{formatCodeableConcept as wi}from"@medplum/core";import{Fragment as Vi,jsx as ee,jsxs as wt}from"react/jsx-runtime";function Ei(e){let{group:o}=e;return ee(tv,{withBorder:!0,radius:"md",p:"xs",display:"flex",sx:{alignItems:"center",justifyContent:"center"},children:wt(ov,{children:[o.measureScore&&ee(av,{group:o}),!o.measureScore&&ee(rv,{group:o})]})})}function Li(e){let{measure:o}=e;return wt(Vi,{children:[ee(go,{fz:"md",fw:500,mb:8,children:o.title}),ee(go,{fz:"xs",c:"dimmed",mb:8,children:o.subtitle})]})}function rv(e){let{group:o}=e,t=o.population,r=t?.find(i=>wi(i.code)==="numerator"),a=t?.find(i=>wi(i.code)==="denominator"),n=r?.count,l=a?.count;if(l===0)return wt(Fi,{children:[ee(Vn,{order:3,children:"Not Applicable"}),ee(go,{children:`Denominator: ${l}`})]});if(n===void 0||l===void 0)return wt(Fi,{children:[ee(Vn,{order:3,children:"Insufficient Data"}),ee(go,{children:`Numerator: ${n}`}),ee(go,{children:`Denominator: ${l}`})]});let f=n/l*100;return ee(Oi,{size:120,thickness:12,roundCaps:!0,sections:[{value:f,color:Ni(f)}],label:ee(Nn,{justify:"center",children:wt(go,{fw:700,fz:18,children:[n," / ",l]})})})}function av(e){let{group:o}=e,t=o.measureScore?.unit??o.measureScore?.code;return ee(Vi,{children:t==="%"?ee(Oi,{size:120,thickness:12,roundCaps:!0,sections:[{value:nv(o),color:Ni(o?.measureScore?.value??0)}],label:ee(Nn,{justify:"center",children:ee(go,{fw:700,fz:18,children:ee(_e,{value:o.measureScore})})})}):ee(Nn,{h:120,align:"center",children:ee(Vn,{order:3,children:ee(_e,{value:o.measureScore})})})})}function nv(e){let o=e.measureScore?.value,t=e.measureScore?.unit;return o?o<=1&&t==="%"?o*100:o:0}function Ni(e){return e<=33?"red":e<=67?"yellow":"green"}import{jsx as Hn,jsxs as sv}from"react/jsx-runtime";function PL(e){let o=z(e.measureReport),[t]=yl("Measure",{url:o?.measure});return o?sv(lv,{children:[t&&Hn(Li,{measure:t}),Hn(fv,{cols:3,breakpoints:[{maxWidth:"48rem",cols:2,spacing:"md"},{maxWidth:"36rem",cols:1,spacing:"sm"}],spacing:"md",children:o.group?.map((r,a)=>Hn(Ei,{group:r},r.id??a))})]}):null}import{Alert as iv}from"@mantine/core";import{operationOutcomeIssueToString as uv}from"@medplum/core";import{jsx as qn}from"react/jsx-runtime";function Jo(e){let o=e.outcome?.issue||e.issues;return!o||o.length===0?null:qn(iv,{icon:qn(fo,{size:16}),color:"red",children:o.map(t=>qn("div",{"data-testid":"text-field-error",children:uv(t)},t.details?.text))})}import{createReference as Er}from"@medplum/core";import{useCallback as cv}from"react";import{jsx as dv}from"react/jsx-runtime";function VL(e){let o=cv((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 dv(oo,{value:e.patient,loadTimelineResources:o,createCommunication:(t,r,a)=>({resourceType:"Communication",status:"completed",subject:Er(t),sender:Er(r),sent:new Date().toISOString(),payload:[{contentString:a}]}),createMedia:(t,r,a)=>({resourceType:"Media",status:"completed",subject:Er(t),operator:Er(r),issued:new Date().toISOString(),content:a})})}import{Anchor as qi,Button as mv,createStyles as pv,NativeSelect as xv,Stack as Iv,TextInput as Un}from"@mantine/core";import{getReferenceString as gv}from"@medplum/core";import{useEffect as Hi,useRef as Gi,useState as Ot}from"react";import{jsx as W,jsxs as $o}from"react/jsx-runtime";var Ui=pv(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 r2(e){let o=R(),t=z(e.value),[r,a]=Ot(!1),[n,l]=Ot(),[f,i]=Ot(),[s,u]=Ot();function c(){i(void 0)}function d(){l(void 0)}let m=Gi();if(m.current=s,Hi(()=>{o.requestSchema("PlanDefinition").then(()=>a(!0)).catch(console.log)},[o]),Hi(()=>(u(bv(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,S){u({...m.current,[x]:S})}return W("div",{children:$o(J,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(s),children:[W(Un,{label:"Plan Title",defaultValue:s.title,onChange:x=>p("title",x.currentTarget.value)}),W(Qi,{actions:s.action||[],selectedKey:n,setSelectedKey:l,hoverKey:f,setHoverKey:i,onChange:x=>p("action",x)}),W(mv,{type:"submit",children:"Save"})]})})}function Qi(e){let{classes:o}=Ui(),t=Gi();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 $o("div",{className:o.section,children:[e.actions.map(l=>W("div",{children:W(hv,{action:l,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onChange:r,onRemove:()=>n(l)})},l.id)),W("div",{className:o.bottomActions,children:W(qi,{href:"#",onClick:l=>{E(l),a({id:Wi()})},children:"Add action"})})]})}function hv(e){let{classes:o,cx:t}=Ui(),{action:r}=e,a=Cv(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){E(u),e.setHoverKey(e.action.id)}let s=t(o.section,{[o.editing]:n,[o.hovering]:l&&!n});return $o("div",{"data-testid":r.id,className:s,onClick:f,onMouseOver:i,onFocus:i,children:[n?W(vv,{action:r,actionType:a,onChange:e.onChange,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,setHoverKey:e.setHoverKey,onRemove:e.onRemove}):W(yv,{action:r,actionType:a}),W("div",{className:o.bottomActions,children:W(qi,{href:"#",onClick:u=>{u.preventDefault(),e.onRemove()},children:"Remove"})})]})}var Qn={path:"PlanDefinition.action.timing[x]",min:0,max:1,description:"",isArray:!1,constraints:[],type:["dateTime","Period","Range","Timing"].map(e=>({code:e}))};function yv(e){let{action:o,actionType:t}=e,[r,a]=zi(o);return $o("div",{children:[$o("div",{children:[o.title||"Untitled"," ",t&&`(${t})`]}),o.definitionCanonical&&W("div",{children:W(po,{value:{reference:o.definitionCanonical}})}),r&&W("div",{children:W(le,{property:Qn,propertyType:a,value:r})})]})}function vv(e){let{action:o}=e,[t,r]=Ot(e.actionType);function a(n,l){e.onChange({...o,[n]:l})}return $o(Iv,{spacing:"xl",children:[W(Un,{name:`actionTitle-${o.id}`,label:"Title",defaultValue:o.title,onChange:n=>a("title",n.currentTarget.value)}),W(Un,{name:`actionDescription-${o.id}`,label:"Description",defaultValue:o.description,onChange:n=>a("description",n.currentTarget.value)}),W(xv,{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&&W(Qi,{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 W(Lr,{title:"Appointment",description:"The subject must schedule an appointment from the schedule.",resourceType:"Schedule",action:o,onChange:e.onChange});case"lab":return W(Lr,{title:"Lab",description:"The subject must complete the following lab panel.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});case"questionnaire":return W(Lr,{title:"Questionnaire",description:"The subject must complete the selected questionnaire.",resourceType:"Questionnaire",action:o,onChange:e.onChange});case"task":return W(Lr,{title:"Task",description:"The subject must complete the following task.",resourceType:"ActivityDefinition",action:o,onChange:e.onChange});default:return null}})(),W(ie,{title:"Timing",description:"When the action should take place.",children:W(Sv,{name:"timing-"+o.id,action:o,onChange:e.onChange})})]})}function Lr(e){let{id:o,definitionCanonical:t}=e.action,r=t?.startsWith(e.resourceType+"/")?{reference:t}:void 0;return W(ir,{name:o,resourceType:e.resourceType,defaultValue:r,loadOnFocus:!0,onChange:a=>{a?e.onChange({...e.action,definitionCanonical:gv(a)}):e.onChange({...e.action,definitionCanonical:void 0})}})}function Sv(e){let o=e.action,t="timing",[r,a]=zi(o);return W(Ze,{property:Qn,name:"timing[x]",defaultValue:r,defaultPropertyType:a,onChange:(n,l)=>{e.onChange(ht(o,t,l??t,Qn,n))},outcome:void 0})}function Cv(e){if(e.definitionCanonical?.startsWith("Schedule"))return"appointment";if(e.definitionCanonical?.startsWith("Questionnaire/"))return"questionnaire";if(e.definitionCanonical?.startsWith("ActivityDefinition/"))return"task"}function zi(e){return Ke({type:"PlanDefinitionAction",value:e},"timing")}var Gn=1;function Wi(e){if(e){if(e.startsWith("id-")){let o=parseInt(e.substring(3),10);isNaN(o)||(Gn=Math.max(Gn,o+1))}return e}return"id-"+Gn++}function bv(e){return{...e,action:Xi(e.action)}}function Xi(e){if(e)return e.map(o=>({...o,id:Wi(o.id),action:Xi(o.action)}))}import{Anchor as Te,Box as $n,Button as Yv,createStyles as jv,Group as eS,NativeSelect as oS,Space as tS,Textarea as rS,TextInput as _n,Title as aS}from"@mantine/core";import{getElementDefinition as nS,isResource as lS}from"@medplum/core";import{useEffect as su,useRef as fS,useState as Qr}from"react";import{Checkbox as Lv,Group as Nv,MultiSelect as Vv,NativeSelect as Hv,Radio as tu,Textarea as qv,TextInput as _o}from"@mantine/core";import{capitalize as Xn,deepEquals as Gv,formatCodeableConcept as Uv,formatCoding as Ur,getElementDefinition as Qv,getTypedPropertyValue as ro,stringify as ru}from"@medplum/core";import{useContext as zv}from"react";import{deepClone as Rv,evalFhirPathTyped as Pv,formatCoding as Tv,getExtension as Nr,getReferenceString as Dv,getTypedPropertyValue as zn,splitN as kv,stringify as Bv}from"@medplum/core";var Vr=(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))(Vr||{});function Ji(e){return e.type==="choice"||e.type==="open-choice"}function $i(e,o){if(!e.enableWhen)return!0;let t=e.enableBehavior??"any";for(let r of e.enableWhen){let a=Ki(o,r.question);if(r.operator==="exists"&&!r.answerBoolean&&!a?.length){if(t==="any")return!0;continue}let{anyMatch:n,allMatch:l}=Mv(r,a,t);if(t==="any"&&n)return!0;if(t==="all"&&!l)return!1}return t!=="any"}function _i(e,o,t){return e.map(r=>{let a=t.answerOption?.find(l=>Tv(l.valueCoding)===r||l[o]===r),n=zn({type:"QuestionnaireItemAnswerOption",value:a},"value");return{[o]:n?.value}})}function Ki(e,o){if(e)for(let t of e){if(t.linkId===o)return t.answer;if(t.item){let r=Ki(t.item,o);if(r)return r}}}function Av(e,o,t){if(t==="exists")return!!e===o.value;if(e){let r=t==="="||t==="!="?t?.replace("=","~"):t,[{value:a}]=Pv(`%actualAnswer ${r} %expectedAnswer`,[e],{"%actualAnswer":e,"%expectedAnswer":o});return a}else return!1}function Mv(e,o,t){let r=o||[],a=zn({type:"QuestionnaireItemEnableWhen",value:e},"answer[x]"),n=!1,l=!0;for(let f of r){let i=zn({type:"QuestionnaireResponseItemAnswer",value:f},"value[x]"),{operator:s}=e;if(Av(i,a,s)?n=!0:l=!1,t==="any"&&n)break}return{anyMatch:n,allMatch:l}}function Hr(e){let o=Nr(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 qr(e,o){let t=Rv(e),r=Nr(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 Zi(e,o,t){let r=Nr(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]=kv(f,"=",2);n[i]=s}return n}function Yi(e){return{resourceType:"QuestionnaireResponse",questionnaire:Dv(e),item:ji(e.item)}}function ji(e){return e?.map(Wn)??[]}function Wn(e){return{id:wv(),linkId:e.linkId,text:e.text,item:ji(e.item),answer:e.initial?.map(Ov)??[]}}var Fv=1;function wv(){return"id-"+Fv++}function Ov(e){return{...e}}function eu(e){return e.value.display||e.value.reference||Bv(e.value)}function ou(e){let o=e?.item?.[0];return o&&Nr(o,"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl")?.valueCodeableConcept?.coding?.[0]?.code==="page"?e.item.length:1}import{createContext as Ev}from"react";var Gr=Ev({});import{jsx as X}from"react/jsx-runtime";function Et(e){let o=zv(Gr),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=Jn(r,e.index)??ro({type:"QuestionnaireItemInitial",value:f},"value");switch(n){case"display":return X("p",{children:e.item.text},e.item.linkId);case"boolean":return X(ar,{title:e.item.text,htmlFor:e.item.linkId,children:X(Lv,{id:e.item.linkId,name:e.item.linkId,defaultChecked:i?.value,onChange:s=>a({valueBoolean:s.currentTarget.checked})})},e.item.linkId);case"decimal":return X(_o,{type:"number",step:"any",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDecimal:s.currentTarget.valueAsNumber})});case"integer":return X(_o,{type:"number",step:1,id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueInteger:s.currentTarget.valueAsNumber})});case"date":return X(_o,{type:"date",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDate:s.currentTarget.value})});case"dateTime":return X(Be,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueDateTime:s})});case"time":return X(_o,{type:"time",id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueTime:s.currentTarget.value})});case"string":case"url":return X(_o,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"text":return X(qv,{id:l,name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueString:s.currentTarget.value})});case"attachment":return X(Nv,{py:4,children:X(Zt,{name:l,defaultValue:i?.value,onChange:s=>a({valueAttachment:s})})});case"reference":return X(No,{name:l,required:t.required,targetTypes:Hr(t),searchCriteria:Zi(t,o.subject,o.encounter),defaultValue:i?.value,onChange:s=>a({valueReference:s})});case"quantity":return X(Ce,{name:l,required:t.required,defaultValue:i?.value,onChange:s=>a({valueQuantity:s}),disableWheel:!0});case"choice":case"open-choice":return Kv(t)&&!t.answerValueSet?X(Wv,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)}):X(Xv,{name:l,item:t,initial:f,response:r,onChangeAnswer:s=>a(s)});default:return null}}function Wv(e){let{name:o,item:t,initial:r,response:a}=e;if(!t.answerOption?.length)return X(lu,{});let n=ro({type:"QuestionnaireItemInitial",value:r},"value"),l=[""];for(let i of t.answerOption){let s=ro({type:"QuestionnaireItemAnswerOption",value:i},"value");l.push(au(s))}let f=Jn(a)??n;if(t.repeats){let{propertyName:i,data:s}=Zv(e.item),u=$v(a);return X(Vv,{data:s,placeholder:"Select items",searchable:!0,defaultValue:u||[au(n)],onChange:c=>{let d=_i(c,i,t);e.onChangeAnswer(d)}})}return X(Hv,{id:o,name:o,onChange:i=>{let s=i.currentTarget.selectedIndex;if(s===0){e.onChangeAnswer({});return}let u=t.answerOption[s-1],c=ro({type:"QuestionnaireItemAnswerOption",value:u},"value"),d="value"+Xn(c.type);e.onChangeAnswer({[d]:c.value})},defaultValue:Ur(f?.value)||f?.value,data:l})}function Xv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e;return!t.answerOption?.length&&!t.answerValueSet?X(lu,{}):t.answerValueSet?X(lr,{name:o,binding:t.answerValueSet,onChange:l=>a({valueCoding:l})}):X(Jv,{name:n?.id??o,item:t,initial:r,response:n,onChangeAnswer:a})}function Jv(e){let{name:o,item:t,initial:r,onChangeAnswer:a,response:n}=e,l=Qv("QuestionnaireItemAnswerOption","value[x]"),f=ro({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=ro({type:"QuestionnaireItemAnswerOption",value:m},"value");x?.value&&(f&&ru(x)===ru(f)&&(s=p),i.push([p,x]))}let u=Jn(n),c=_v(i,u);return X(tu.Group,{name:o,value:c??s,onChange:d=>{let m=i.find(p=>p[0]===d);if(m){let p=m[1],x="value"+Xn(p.type);a({[x]:p.value})}},children:i.map(([d,m])=>X(tu,{id:d,value:d,py:4,label:X(le,{property:l,propertyType:m.type,value:m.value})},d))})}function lu(){return X(_o,{disabled:!0,placeholder:"No Answers Defined"})}function fu(e){return ro({type:"QuestionnaireItemAnswer",value:e},"value")}function Jn(e,o=0){let t=e.answer;return fu(t?.[o]??{})}function $v(e){let o=e.answer;return o?o.map(r=>fu(r)).map(r=>Ur(r?.value)||r?.value):[]}function _v(e,o){return e.find(t=>Gv(t[1].value,o?.value))?.[0]}function au(e){if(e)return e.type==="CodeableConcept"?Uv(e.value):e.type==="Coding"?Ur(e.value):e.type==="Reference"?eu(e):e.value.toString()}function Kv(e){return!!e.extension?.some(o=>o.url==="http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl"&&o.valueCodeableConcept?.coding?.[0]?.code==="drop-down")}function Zv(e){if(e.answerOption?.length===0)return{propertyName:"",data:[]};let o=e.answerOption[0],t=ro({type:"QuestionnaireItemAnswerOption",value:o},"value"),r="value"+Xn(t.type),a=(e.answerOption??[]).map(n=>({value:nu(n,r),label:nu(n,r)}));return{propertyName:r,data:a}}function nu(e,o){return Ur(e.valueCoding)||e[o]?.toString()}import{Fragment as Ko,jsx as O,jsxs as Ie}from"react/jsx-runtime";var sS=jv(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 G2(e){let o=R(),t=z(e.questionnaire),[r,a]=Qr(!1),[n,l]=Qr(),[f,i]=Qr(),[s,u]=Qr();function c(){u(void 0)}function d(){i(void 0)}su(()=>{o.requestSchema("Questionnaire").then(()=>a(!0)).catch(console.log)},[o]),su(()=>(l(dS(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:O("div",{children:Ie(J,{testid:"questionnaire-form",onSubmit:()=>e.onSubmit(n),children:[O(iu,{item:n,selectedKey:f,setSelectedKey:i,hoverKey:s,setHoverKey:u,onChange:m}),O(Yv,{type:"submit",children:"Save"})]})})}function iu(e){let{classes:o,cx:t}=sS(),r=e.item,a=e.item,n=lS(e.item),l=n||a.type==="group",f=a.linkId??"[untitled]",i=e.selectedKey===e.item.id,s=e.hoverKey===e.item.id,u=fS();u.current=e.item;function c(h){E(h),e.setSelectedKey(e.item.id)}function d(h){E(h),e.setHoverKey(e.item.id)}function m(h){let M=u.current;e.onChange({...M,item:M.item?.map(Q=>Q.id===h.id?h:Q)})}function p(h,M){e.onChange({...e.item,item:[...e.item.item??[],h]},M)}function x(h){e.onChange({...e.item,item:e.item.item?.filter(M=>M!==h)})}function S(h,M){e.onChange({...u.current,[h]:M})}function y(h){e.onChange({...e.item,...h})}function v(h){e.onChange({...e.item,item:e.item.item?.map(M=>M===h?{...M,repeats:!M.repeats}:M)})}function C(h,M){let Q=xS(e.item.item,h,M);e.onChange({...e.item,item:Q})}let T=t(o.section,{[o.editing]:i,[o.hovering]:s&&!i});return Ie("div",{"data-testid":a.linkId,className:T,onClick:c,onMouseOver:d,onFocus:d,children:[O("div",{className:o.questionBody,children:i?Ie(Ko,{children:[n&&O(_n,{size:"xl",defaultValue:r.title,onBlur:h=>S("title",h.currentTarget.value)}),!n&&O(rS,{autosize:!0,minRows:2,defaultValue:a.text,onBlur:h=>S("text",h.currentTarget.value)}),a.type==="reference"&&O(cS,{item:a,onChange:y}),Ji(a)&&O(iS,{item:a,onChange:h=>y(h)})]}):Ie(Ko,{children:[r.title&&O(aS,{children:r.title}),a.text&&O("div",{children:a.text}),!l&&O(Et,{item:a,index:0,onChange:()=>{},response:{}})]})}),a.item?.map((h,M)=>O("div",{children:O(iu,{item:h,selectedKey:e.selectedKey,setSelectedKey:e.setSelectedKey,hoverKey:e.hoverKey,isFirst:M===0,isLast:M===(e.item.item??[]).length-1,setHoverKey:e.setHoverKey,onChange:m,onRemove:()=>x(h),onRepeatable:v,onMoveUp:()=>C(M,-1),onMoveDown:()=>C(M,1)})},h.id)),!l&&O("div",{className:o.topActions,children:i?Ie(Ko,{children:[O(_n,{size:"xs",className:o.linkIdInput,defaultValue:a.linkId,onBlur:h=>S("linkId",h.currentTarget.value)}),!l&&O(oS,{size:"xs",className:o.typeSelect,defaultValue:a.type,onChange:h=>S("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"}]})]}):O("div",{children:f})}),!n&&O($n,{className:o.movementActions,children:Ie($n,{className:o.columnAlignment,children:[!e.isFirst&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveUp&&e.onMoveUp()},children:O(ia,{"data-testid":"up-button",size:15,className:o.movementIcons})}),!e.isLast&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onMoveDown&&e.onMoveDown()},children:O(sa,{"data-testid":"down-button",size:15,className:o.movementIcons})})]})}),Ie("div",{className:o.bottomActions,children:[l&&Ie(Ko,{children:[O(Te,{href:"#",onClick:h=>{h.preventDefault(),p({id:ho(),linkId:Yn("q"),type:"string",text:"Question"})},children:"Add item"}),O(Te,{href:"#",onClick:h=>{h.preventDefault(),p({id:ho(),linkId:Yn("g"),type:"group",text:"Group"},!0)},children:"Add group"})]}),n&&O(Te,{href:"#",onClick:h=>{h.preventDefault(),p(pS(),!0)},children:"Add Page"}),i&&!n&&Ie(Ko,{children:[O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onRepeatable&&e.onRepeatable(a)},children:a.repeats?"Remove Repeatable":"Make Repeatable"}),O(Te,{href:"#",onClick:h=>{h.preventDefault(),e.onRemove&&e.onRemove()},children:"Remove"})]})]})]})}function iS(e){let o=nS("QuestionnaireItemAnswerOption","value[x]"),t=e.item.answerOption??[];return Ie("div",{children:[e.item.answerValueSet!==void 0?O(_n,{placeholder:"Enter Value Set",defaultValue:e.item.answerValueSet,onChange:r=>e.onChange({...e.item,answerValueSet:r.target.value})}):O(uS,{options:t,property:o,item:e.item,onChange:e.onChange}),Ie($n,{display:"flex",children:[O(Te,{href:"#",onClick:r=>{E(r),e.onChange({...e.item,answerValueSet:void 0,answerOption:[...t,{id:ho()}]})},children:"Add choice"}),O(tS,{w:"lg"}),O(Te,{href:"#",onClick:r=>{E(r),e.onChange({...e.item,answerOption:[],answerValueSet:""})},children:"Add value set"})]})]})}function uS(e){return O("div",{children:e.options.map(o=>{let[t,r]=Ke({type:"QuestionnaireItemAnswerOption",value:o},"value");return Ie("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",width:"80%"},children:[O("div",{children:O(Ze,{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)}),O("div",{children:O(Te,{href:"#",onClick:a=>{E(a),e.onChange({...e.item,answerOption:e.options.filter(n=>n.id!==o.id)})},children:"Remove"})})]},o.id)})})}function cS(e){let o=Hr(e.item)??[];return Ie(Ko,{children:[o.map((t,r)=>Ie(eS,{children:[O(Fo,{name:"resourceType",placeholder:"Resource Type",defaultValue:t,onChange:a=>{e.onChange(qr(e.item,o.map(n=>n===t?a:n)))}}),O(Te,{href:"#",onClick:a=>{E(a),e.onChange(qr(e.item,o.filter(n=>n!==t)))},children:"Remove"})]},`${t}-${r}`)),O(Te,{href:"#",onClick:t=>{E(t),e.onChange(qr(e.item,[...o,""]))},children:"Add Resource Type"})]})}var Kn=1,Zn=1;function Yn(e){return e+Kn++}function ho(){return"id-"+Zn++}function dS(e){return{...e,id:e.id||ho(),item:uu(e.item)}}function uu(e){if(e)return e.forEach(o=>{o.id?.match(/^id-\d+$/)&&(Zn=Math.max(Zn,parseInt(o.id.substring(3),10)+1)),o.linkId?.match(/^q\d+$/)&&(Kn=Math.max(Kn,parseInt(o.linkId.substring(1),10)+1))}),e.map(o=>({...o,id:o.id||ho(),item:uu(o.item),answerOption:mS(o.answerOption)}))}function mS(e){if(e)return e.map(o=>({...o,id:o.id||ho()}))}function pS(){return{id:ho(),linkId:Yn("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 xS(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 BS}from"@mantine/core";import{createReference as AS,getReferenceString as MS}from"@medplum/core";import{useEffect as Iu,useState as ol}from"react";import{Button as el,Group as PS,Stack as TS,Stepper as mu}from"@mantine/core";import{Anchor as IS}from"@mantine/core";import{useState as gS}from"react";import{jsx as zr,jsxs as yS}from"react/jsx-runtime";function Wr(e){let{item:o,response:t,onChange:r}=e,[a,n]=gS(hS(o,t??{}));if(!e.checkForQuestionEnabled(o)||!t)return null;if(o.type==="display")return zr("p",{children:o.text},o.linkId);let l=o?.repeats&&o.type!=="choice"&&o.type!=="open-choice";return o.type==="boolean"?zr(Et,{item:o,response:t,onChange:f=>r([f]),index:0},o.linkId):yS(ie,{htmlFor:e.item.linkId,title:e.item.text,withAsterisk:e.item.required,children:[[...Array(a)].map((f,i)=>zr(Et,{item:o,response:t,onChange:s=>r([s]),index:i},`${o.linkId}-${i}`)),l&&zr(IS,{onClick:()=>n(f=>f+1),children:"Add Item"})]},e.item.linkId)}function hS(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 vS,Stack as SS,Title as CS}from"@mantine/core";import{useState as bS}from"react";import{Fragment as RS,jsx as yo,jsxs as du}from"react/jsx-runtime";function jn(e){let[o,t]=bS(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=Wn(e.item);t([...o,n])}return du(RS,{children:[o.map((n,l)=>yo(cu,{item:e.item,response:n,checkForQuestionEnabled:e.checkForQuestionEnabled,onChange:f=>r(f,l)},n.id)),e.item.repeats&&yo(vS,{onClick:a,children:`Add Group: ${e.item.text}`})]})}function cu(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)?du("div",{children:[e.item.text&&yo(CS,{order:3,mb:"md",children:e.item.text}),yo(SS,{children:e.item.item?.map(n=>n.type==="group"?n.repeats?yo(jn,{item:n,response:o.item?.filter(l=>l.linkId===n.linkId)??[],checkForQuestionEnabled:t,onChange:a},n.linkId):yo(cu,{item:n,checkForQuestionEnabled:t,response:o.item?.find(l=>l.linkId===n.linkId)??{},onChange:a},n.linkId):yo(Wr,{item:n,response:o.item?.find(l=>l.linkId===n.linkId),onChange:a,checkForQuestionEnabled:t},n.linkId))})]},e.item.linkId):null}import{Fragment as kS,jsx as Qe,jsxs as xu}from"react/jsx-runtime";function pu(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"?Qe(jn,{item:d,response:m,onChange:a,checkForQuestionEnabled:u},d.linkId):Qe(Wr,{item:d,response:m?.[0],onChange:a,checkForQuestionEnabled:u},d.linkId);return i?Qe(mu.Step,{label:d.text,children:p},d.linkId):p});return xu(kS,{children:[i&&Qe(mu,{active:r??0,allowNextStepsSelect:!1,p:6,children:c}),!i&&Qe(TS,{children:c}),Qe(DS,{activePage:r??0,numberOfPages:f,nextStep:n,prevStep:l,submitButtonText:s})]})}function DS(e){let o=e.activePage>0,t=e.activePage<e.numberOfPages-1,r=e.activePage===e.numberOfPages-1;return xu(PS,{position:"right",mt:"xl",spacing:"xs",children:[o&&Qe(el,{onClick:e.prevStep,children:"Back"}),t&&Qe(el,{onClick:a=>{a.currentTarget.closest("form").reportValidity()&&e.nextStep()},children:"Next"}),r&&Qe(el,{type:"submit",children:e.submitButtonText??"Submit"})]})}import{jsx as tl,jsxs as wS}from"react/jsx-runtime";function gu(e){let o=R(),t=o.getProfile(),[r,a]=ol(!1),n=z(e.questionnaire),[l,f]=ol(),[i,s]=ol(0);Iu(()=>{o.requestSchema("Questionnaire").then(()=>o.requestSchema("QuestionnaireResponse")).then(()=>a(!0)).catch(console.log)},[o]),Iu(()=>{f(n?Yi(n):void 0)},[n]);function u(x){let S=l?.item??[],v={resourceType:"QuestionnaireResponse",item:hu(S,Array.isArray(x)?x:[x])};f(v)}function c(x){return $i(x,l?.item??[])}if(!r||!n)return null;let d=ou(n),m=()=>s(x=>x+1),p=()=>s(x=>x-1);return tl(Gr.Provider,{value:{subject:e.subject,encounter:e.encounter},children:wS(J,{testid:"questionnaire-form",onSubmit:()=>{e.onSubmit&&l&&e.onSubmit({...l,questionnaire:MS(n),subject:e.subject,source:AS(t),authored:new Date().toISOString(),status:"completed"})},children:[n.title&&tl(BS,{children:n.title}),tl(pu,{items:n.item??[],response:l,onChange:u,renderPages:d>1,activePage:i,numberOfPages:d,submitButtonText:e.submitButtonText,checkForQuestionEnabled:c,nextStep:m,prevStep:p})]})})}function FS(e,o){let t=hu(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 hu(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(FS(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 Xr,Button as OS,createStyles as ES,Divider as LS,Group as Lt,NativeSelect as rl,Stack as Jr,Text as NS,TextInput as VS}from"@mantine/core";import{formatRange as yu,getCodeBySystem as HS}from"@medplum/core";import{useEffect as qS,useState as al}from"react";import{jsx as $,jsxs as Zo}from"react/jsx-runtime";var GS=ES(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"}})),US=["gender","age","gestationalAge","context","appliesTo","category"],QS={definition:{resourceType:"ObservationDefinition"},onSubmit:()=>{}};function DN(e){e=Object.assign(QS,e);let o=e.definition,[t,r]=al([]),[a,n]=al(1),[l,f]=al(1);return qS(()=>{let p=XS(o,f);r(JS(p.qualifiedInterval||[],n))},[o]),Zo(J,{testid:"reference-range-editor",onSubmit:i,children:[$(Jr,{children:t.map(p=>$(zS,{unit:_S(o.quantitativeDetails?.unit),onChange:c,onAdd:d,onRemove:m,onRemoveGroup:u,intervalGroup:p},`group-${p.id}`))}),$(Xr,{title:"Add Group",size:"sm",onClick:p=>{E(p),s({id:`group-id-${a}`,filters:{},intervals:[]}),n(x=>x+1)},children:$(so,{})}),$(Lt,{position:"right",children:$(OS,{type:"submit",children:"Save"})})]});function i(){let p=t.flatMap(x=>x.intervals).filter(x=>!KS(x));e.onSubmit({...o,qualifiedInterval:p})}function s(p){r(x=>[...x,p])}function u(p){r(x=>x.filter(S=>S.id!==p.id))}function c(p,x){r(S=>{S=[...S];let y=S.find(C=>C.id===p),v=y?.intervals.findIndex(C=>C.id===x.id);return v!==void 0&&y?.intervals[v]&&(y.intervals[v]=x),S})}function d(p,x){x.id===void 0&&(x.id=`id-${l}`,f(S=>S+1)),r(S=>{S=[...S];let y=S.findIndex(v=>v.id===p);if(y!==-1){let v={...S[y]};x={...x,...v.filters},v.intervals=[...v.intervals,x],S[y]=v}return S})}function m(p,x){r(S=>{S=[...S];let y=S.find(v=>v.id===p);return y&&(y.intervals=y.intervals.filter(v=>v.id!==x.id)),S})}}function zS(e){let{intervalGroup:o,unit:t}=e,{classes:r}=GS();return $(Ye,{"data-testid":o.id,className:r.section,children:Zo(Jr,{spacing:"lg",children:[$(Lt,{position:"right",children:$(Xr,{title:"Remove Group","data-testid":`remove-group-button-${o.id}`,size:"sm",onClick:a=>{E(a),e.onRemoveGroup(o)},children:$(Je,{})},`remove-group-button-${o.id}`)}),$(WS,{intervalGroup:o,onChange:e.onChange}),$(LS,{}),o.intervals.map(a=>Zo(Jr,{spacing:"xs",children:[Zo(Lt,{children:[$(VS,{"data-testid":`condition-${a.id}`,defaultValue:a.condition,label:"Condition: ",size:"sm",onChange:n=>{E(n),e.onChange(o.id,{...a,condition:n.currentTarget.value.trim()})}},`condition-${a.id}`),$(Xr,{title:"Remove Interval",size:"sm","data-testid":`remove-interval-${a.id}`,onClick:n=>{E(n),e.onRemove(o.id,a)},children:$(Je,{})},`remove-interval-${a.id}`)]}),$(vt,{onChange:n=>{e.onChange(o.id,{...a,range:n})},name:`range-${a.id}`,defaultValue:a.range},`range-${a.id}`)]},`interval-${a.id}`)),$(Xr,{title:"Add Interval",size:"sm",onClick:a=>{E(a),e.onAdd(o.id,{range:{low:{unit:t},high:{unit:t}}})},children:$(so,{})})]})})}function WS(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 Zo(Jr,{style:{maxWidth:"50%"},children:[$(Lt,{children:$(rl,{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})}}})}),Zo(Lt,{spacing:"xs",children:[$(NS,{component:"label",htmlFor:`div-age-${o.id}`,children:"Age:"}),$("div",{id:`div-age-${o.id}`,children:$(vt,{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}`)})]}),$(rl,{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"}]}})}}}),$(rl,{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 XS(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 JS(e,o){let t=1,r={};for(let a of e){let n=$S(a);n in r||(r[n]={id:`group-id-${t++}`,filters:Object.fromEntries(US.map(l=>[l,a[l]])),intervals:[]}),r[n].intervals.push(a)}return o(t),Object.values(r)}function $S(e){return[`gender=${e.gender}`,`age=${yu(e.age)}`,`gestationalAge=${yu(e.gestationalAge)}`,`context=${e.context?.text}`,`appliesTo=${e.appliesTo?.map(t=>t.text).join("+")}`,`category=${e.category}`].join(":")}function _S(e){return e&&(HS(e,"http://unitsofmeasure.org")||e.text)}function KS(e){return e.range?.low?.value===void 0&&e.range?.high?.value===void 0}import{Button as vu,Grid as $r,Text as ZS}from"@mantine/core";import{formatDateTime as YS,getReferenceString as jS}from"@medplum/core";import{Fragment as eC,useEffect as oC,useState as Su}from"react";import{jsx as Ee,jsxs as Nt}from"react/jsx-runtime";function NN(e){let o=R(),t=z(e.value),[r,a]=Su(!1),[n,l]=Su();if(oC(()=>{t&&!r&&(o.executeBatch(f(t)).then(l).catch(console.log),a(!0))},[o,t,r]),!t||!n)return null;return Ee($r,{children:t.action?.map((s,u)=>{let c=s.resource&&i(s.resource),d=c?.input?.[0]?.valueReference,m=c?.output?.[0]?.valueReference;return Nt(eC,{children:[Ee($r.Col,{span:1,p:"md",children:c?.status==="completed"?Ee(Ia,{}):Ee(wa,{color:"gray"})}),Nt($r.Col,{span:9,p:"xs",children:[Ee(ZS,{weight:500,children:s.title}),s.description&&Ee("div",{children:s.description}),Nt("div",{children:["Last edited by\xA0",Ee(Fe,{value:c?.meta?.author}),"\xA0on\xA0",YS(c?.meta?.lastUpdated)]}),Nt("div",{children:["Status: ",Ee(gr,{status:c?.status||"unknown"})]})]}),Nt($r.Col,{span:2,p:"md",children:[d&&!m&&Ee(vu,{onClick:()=>e.onStart(c,d),children:"Start"}),d&&m&&Ee(vu,{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===jS(u.resource))return u.resource}}import{createStyles as sC}from"@mantine/core";import{useEffect as iC,useState as uC}from"react";import{stringify as nC}from"@medplum/core";function _r(e,o){let t=tC(e,o);return rC(t,e,o)}function tC(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,S=0;s===-i||s!==i&&p.i<m.i?(S=m.i,x=m):(S=p.i+1,x=p),f[d]=void 0;let y=S-s,v={i:S,j:y,prev:aC(x),snake:!1};for(;S<t&&y<r&&e[S]===o[y];)S++,y++;if(S>v.i&&(v={i:S,j:y,prev:v,snake:!0}),f[u]=v,S>=t&&y>=r)return f[u]}f[l+i-1]=void 0}}function rC(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 aC(e){return e&&!e.snake&&e.prev?e.prev:e}function Cu(e){let o=e.entry.filter(r=>!!r.resource).map(r=>({meta:r.resource?.meta,lines:nC(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 lC(t,o),fC(t),t}function lC(e,o){for(let t=1;t<o.length;t++){let r=_r(o[t-1].lines,o[t].lines);for(let a of r){let n=a.original.position,l=a.original.lines,f=a.revised.lines;if((a.type==="delete"||a.type==="change")&&e.splice(n,l.length),a.type==="insert"||a.type==="change")for(let 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 fC(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 bu(e,o){return`/${e.resourceType}/${e.id}/_history/${o}`}function Ru(e){let o=Math.floor((Date.now()-Date.parse(e))/1e3),t=Math.floor(o/31536e3);if(t>0)return Yo(t,"year");let r=Math.floor(o/2592e3);if(r>0)return Yo(r,"month");let a=Math.floor(o/86400);if(a>0)return Yo(a,"day");let n=Math.floor(o/3600);if(n>0)return Yo(n,"hour");let l=Math.floor(o/60);return l>0?Yo(l,"minute"):Yo(o,"second")}function Yo(e,o){return`${e} ${e===1?o:o+"s"} ago`}import{Fragment as dC,jsx as Ae,jsxs as Pu}from"react/jsx-runtime";var cC=sC(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 YN(e){let{classes:o}=cC(),t=R(),[r,a]=uC(e.history);if(iC(()=>{!e.history&&e.resourceType&&e.id&&t.readHistory(e.resourceType,e.id).then(a).catch(console.log)},[t,e.history,e.resourceType,e.id]),!r)return Ae("div",{children:"Loading..."});let n=r.entry?.[0]?.resource;if(!n)return null;let l=Cu(r);return Ae("div",{className:o.container,children:Ae("table",{className:o.root,children:Ae("tbody",{children:l.map((f,i)=>Pu("tr",{className:f.span>0?o.startRow:o.normalRow,children:[f.span>0&&Pu(dC,{children:[Ae("td",{className:o.author,rowSpan:f.span,children:Ae(je,{value:f.meta.author,link:!0})}),Ae("td",{className:o.dateTime,rowSpan:f.span,children:Ae(te,{to:bu(n,f.meta.versionId),children:Ru(f.meta.lastUpdated)})})]}),Ae("td",{className:o.lineNumber,children:i+1}),Ae("td",{className:o.line,children:Ae("pre",{className:o.pre,children:f.value})})]},"row-"+i))})})})}import{createStyles as mC}from"@mantine/core";import{stringify as Tu}from"@medplum/core";import{Fragment as IC,jsx as jo,jsxs as gC}from"react/jsx-runtime";var pC=mC(e=>({removed:{color:e.colors.red[7],textDecoration:"line-through"},added:{color:e.colors.green[7]}}));function nV(e){let o=e.original,t=e.revised;e.ignoreMeta&&(o={...o,meta:void 0},t={...t,meta:void 0});let r=Tu(o,!0).match(/[^\r\n]+/g),a=Tu(t,!0).match(/[^\r\n]+/g),n=_r(r,a);return jo("pre",{style:{color:"gray"},children:n.map((l,f)=>jo(xC,{delta:l},"delta"+f))})}function xC(e){let{classes:o}=pC();return gC(IC,{children:["...",jo("br",{}),e.delta.original.lines.length>0&&jo("div",{className:o.removed,children:e.delta.original.lines.join(`
|
|
72
72
|
`)}),e.delta.revised.lines.length>0&&jo("div",{className:o.added,children:e.delta.revised.lines.join(`
|
|
73
|
-
`)}),"...",jo("br",{})]})}import{Button as Du,Group as hC,Stack as yC,TextInput as ku}from"@mantine/core";import{deepClone as vC,tryGetProfile as SC}from"@medplum/core";import{useEffect as CC,useState as Bu}from"react";import{jsx as ao,jsxs as nl}from"react/jsx-runtime";function cV(e){let{outcome:o}=e,t=R(),r=z(e.defaultValue),[a,n]=Bu(),[l,f]=Bu();return CC(()=>{if(r)if(f(vC(r)),e.profileUrl){let i=e.profileUrl;t.requestProfileSchema(e.profileUrl).then(()=>{let s=SC(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?ao("div",{children:"Loading..."}):nl("form",{noValidate:!0,autoComplete:"off",onSubmit:i=>{i.preventDefault(),e.onSubmit&&e.onSubmit(l)},children:[nl(yC,{mb:"xl",children:[ao(ie,{title:"Resource Type",htmlFor:"resourceType",outcome:o,children:ao(ku,{name:"resourceType",defaultValue:l.resourceType,disabled:!0})}),ao(ie,{title:"ID",htmlFor:"id",outcome:o,children:ao(ku,{name:"id",defaultValue:l.id,disabled:!0})})]}),ao(Lo,{typeName:a,defaultValue:l,outcome:o,onChange:f,profileUrl:e.profileUrl}),nl(hC,{position:"right",mt:"xl",children:[ao(Du,{type:"submit",children:"OK"}),e.onDelete&&ao(Du,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(l)},children:"Delete"})]})]})}import{Table as bC}from"@mantine/core";import{formatDateTime as RC,normalizeErrorString as PC}from"@medplum/core";import{useEffect as TC,useState as DC}from"react";import{jsx as ge,jsxs as ll}from"react/jsx-runtime";function vV(e){let o=R(),[t,r]=DC(e.history);return TC(()=>{!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?ll(bC,{withBorder:!0,withColumnBorders:!0,children:[ge("thead",{children:ll("tr",{children:[ge("th",{children:"Author"}),ge("th",{children:"Date"}),ge("th",{children:"Version"})]})}),ge("tbody",{children:t.entry?.map((a,n)=>ge(kC,{entry:a},"entry-"+n))})]}):ge("div",{children:"Loading..."})}function kC(e){let{response:o,resource:t}=e.entry;return t?ll("tr",{children:[ge("td",{children:ge(je,{value:t.meta?.author,link:!0})}),ge("td",{children:RC(t.meta?.lastUpdated)}),ge("td",{children:ge(te,{to:BC(t),children:t.meta?.versionId})})]}):ge("tr",{children:ge("td",{colSpan:3,children:PC(o?.outcome)})})}function BC(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as AC,createStyles as MC,Stack as FC,Text as wC}from"@mantine/core";import{getReferenceString as OC,isReference as EC}from"@medplum/core";import{useState as Kr}from"react";import{jsx as de,jsxs as et}from"react/jsx-runtime";var LC=MC(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function FV(e){let{classes:o}=LC(),t=z(e.schedule),r=z(e.questionnaire),[a,n]=Kr(Ir()),[l,f]=Kr(),[i,s]=Kr(),[u,c]=Kr(),[d]=vl("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",EC(e.schedule)?e.schedule.reference:OC(e.schedule)],["start","gt"+NC(a)],["start","lt"+VC(a)]]));if(!t||!d||!r)return null;let m=t.actor?.[0];return et("div",{className:o.container,"data-testid":"scheduler",children:[et("div",{className:o.info,children:[m&&de(se,{value:m,size:"xl"}),m&&de(wC,{size:"xl",weight:500,children:de(Fe,{value:m})}),de("p",{children:"1 hour"}),l&&de("p",{children:l.toLocaleDateString()}),i&&de("p",{children:Au(new Date(i.start))})]}),et("div",{className:o.selection,children:[!l&&et("div",{children:[de("h3",{children:"Select date"}),de(us,{slots:d,onChangeMonth:n,onClick:f})]}),l&&!i&&et("div",{children:[de("h3",{children:"Select time"}),de(FC,{children:d.map(p=>{let x=new Date(p.start);return x.getTime()>l.getTime()&&x.getTime()<l.getTime()+24*3600*1e3&&de("div",{children:de(AC,{variant:"outline",style:{width:150},onClick:()=>s(p),children:Au(x)})},p.id)})})]}),l&&i&&!u&&de(gu,{questionnaire:r,submitButtonText:"Next",onSubmit:c}),l&&i&&u&&et("div",{children:[de("h3",{children:"You're all set!"}),de("p",{children:"Check your email for a calendar invite."})]})]})]})}function NC(e){return Mu(e.getTime())}function VC(e){return Mu(e.getTime()+31*24*60*60*1e3)}function Mu(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Au(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as Zr}from"@medplum/core";import{jsx as HC}from"react/jsx-runtime";function HV(e){return HC(oo,{value:e.serviceRequest,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory("ServiceRequest",r),o.search("Communication",{"based-on":a,_count:n}),o.search("DiagnosticReport",{"based-on":a,_count:n}),o.search("Media",{"based-on":a,_count:n}),o.search("DocumentReference",{related:a,_count:n}),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])},createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",basedOn:[Zr(o)],subject:o.subject,sender:Zr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[Zr(o)],subject:o.subject,operator:Zr(t),issued:new Date().toISOString(),content:r})})}import{normalizeOperationOutcome as fb}from"@medplum/core";import{useEffect as sb,useState as Hu}from"react";import{Anchor as Fu,Button as qC,Center as GC,Group as UC,Stack as QC,Text as zC,TextInput as WC,Title as XC}from"@mantine/core";import{normalizeOperationOutcome as JC}from"@medplum/core";import{useState as $C}from"react";import{jsx as vo,jsxs as Yr}from"react/jsx-runtime";function jr(e){let o=R(),[t,r]=$C();return Yr(J,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(JC(n))}},children:[Yr(GC,{sx:{flexDirection:"column"},children:[vo(to,{size:32}),vo(XC,{children:"Create project"})]}),Yr(QC,{spacing:"xl",children:[vo(WC,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:G(t,"firstName")}),Yr(zC,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",vo(Fu,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",vo(Fu,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),vo(UC,{position:"right",mt:"xl",noWrap:!0,children:vo(qC,{type:"submit",children:"Create project"})})]})}import{Anchor as ra,Button as YC,Center as jC,Checkbox as eb,Divider as ob,Group as Eu,PasswordInput as tb,Stack as rb,Text as Lu,TextInput as sl}from"@mantine/core";import{normalizeOperationOutcome as Nu}from"@medplum/core";import{useEffect as ab,useState as nb}from"react";import{useEffect as _C,useRef as KC,useState as fl}from"react";function ea(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 ZC}from"react/jsx-runtime";function oa(e){let o=R(),{googleClientId:t,handleGoogleCredential:r}=e,a=KC(null),[n,l]=fl(typeof google<"u"),[f,i]=fl(!1),[s,u]=fl(!1);return _C(()=>{if(typeof google>"u"){ea("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?ZC("div",{ref:a}):null}function ta(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 wu(e){typeof grecaptcha>"u"&&ea("https://www.google.com/recaptcha/api.js?render="+e)}function Ou(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as lb,jsx as me,jsxs as ot}from"react/jsx-runtime";function Vu(e){let o=ta(e.googleClientId),t=e.recaptchaSiteKey,r=R(),[a,n]=nb(),l=nr(a,void 0);return ab(()=>{t&&wu(t)},[t]),ot(J,{style:{maxWidth:400},onSubmit:async f=>{try{let i="";t&&(i=await Ou(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(Nu(i))}},children:[me(jC,{sx:{flexDirection:"column"},children:e.children}),me(Jo,{issues:l}),o&&ot(lb,{children:[me(Eu,{position:"center",p:"xl",style:{height:70},children:me(oa,{googleClientId:o,handleGoogleCredential:async f=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:f.clientId,googleCredential:f.credential,createUser:!0}))}catch(i){n(Nu(i))}}})}),me(ob,{label:"or",labelPosition:"center",my:"lg"})]}),ot(rb,{spacing:"xl",children:[me(sl,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:G(a,"firstName")}),me(sl,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:G(a,"lastName")}),me(sl,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:G(a,"email")}),me(tb,{name:"password",label:"Password",autoComplete:"off",required:!0,error:G(a,"password")}),ot(Lu,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",me(ra,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",me(ra,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),ot(Lu,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",me(ra,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",me(ra,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),ot(Eu,{position:"apart",mt:"xl",noWrap:!0,children:[me(eb,{name:"remember",label:"Remember me",size:"xs"}),me(YC,{type:"submit",children:"Create account"})]})]})}import{jsx as il,jsxs as ib}from"react/jsx-runtime";function AH(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,f=R(),[i,s]=Hu(),[u,c]=Hu();sb(()=>{o==="patient"&&i&&f.startNewPatient({login:i,projectId:t}).then(m=>f.processCode(m.code)).then(()=>l()).catch(m=>c(fb(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 ib(Rr,{width:450,children:[u&&il("pre",{children:JSON.stringify(u,null,2)}),!i&&il(Vu,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:d,children:e.children}),i&&o==="project"&&il(jr,{login:i,handleAuthResponse:d})]})}import{showNotification as ju}from"@mantine/notifications";import{normalizeErrorString as ec}from"@medplum/core";import{useCallback as cl,useEffect as qb,useState as dl}from"react";import{Anchor as qu,Button as Gu,Center as Uu,Checkbox as ub,Divider as cb,Group as ul,PasswordInput as db,Stack as mb,TextInput as pb}from"@mantine/core";import{normalizeOperationOutcome as xb}from"@medplum/core";import{useCallback as aa,useState as Qu}from"react";import{Fragment as hb,jsx as ae,jsxs as Vt}from"react/jsx-runtime";function zu(e){let[o,t]=Qu();return o?ae(gb,{email:o,...e}):ae(Ib,{setEmail:t,...e})}function Ib(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,f=R(),i=!e.disableGoogleAuth&&ta(e.googleClientId),s=aa(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=aa(async d=>{let m=await f.post("auth/method",{email:d.email});await s(m)||o(d.email)},[f,s,o]),c=aa(async d=>{let m=await f.startGoogleLogin({...l,googleCredential:d.credential});await s(m)||r(m)},[f,l,s,r]);return Vt(J,{style:{maxWidth:400},onSubmit:u,children:[ae(Uu,{sx:{flexDirection:"column"},children:a}),i&&Vt(hb,{children:[ae(ul,{position:"center",p:"xl",style:{height:70},children:ae(oa,{googleClientId:i,handleGoogleCredential:c})}),!n&&ae(cb,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&ae(pb,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Vt(ul,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[ae("div",{children:t&&ae(qu,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&ae(Gu,{type:"submit",children:"Next"})]})]})}function gb(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=R(),[l,f]=Qu(),i=nr(l,void 0),s=aa(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(c=>f(xb(c)))},[n,a,t]);return Vt(J,{style:{maxWidth:400},onSubmit:s,children:[ae(Uu,{sx:{flexDirection:"column"},children:r}),ae(Jo,{issues:i}),ae(mb,{spacing:"xl",children:ae(db,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:G(l,"password")})}),Vt(ul,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&ae(qu,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),ae(ub,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),ae(Gu,{type:"submit",children:"Sign in"})]})]})}import{Avatar as yb,Center as vb,Group as Sb,Stack as Cb,Text as Wu,Title as bb,UnstyledButton as Rb}from"@mantine/core";import{normalizeOperationOutcome as Pb}from"@medplum/core";import{useState as Tb}from"react";import{jsx as So,jsxs as na}from"react/jsx-runtime";function Xu(e){let o=R(),[t,r]=Tb();return na(Cb,{children:[na(vb,{sx:{flexDirection:"column"},children:[So(to,{size:32}),So(bb,{order:3,children:"Choose profile"})]}),So(Jo,{outcome:t}),e.memberships.map(a=>So(Rb,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(Pb(n)))},children:na(Sb,{children:[So(yb,{radius:"xl"}),na("div",{style:{flex:1},children:[So(Wu,{size:"sm",weight:500,children:a.profile?.display}),So(Wu,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as Db,Center as kb,Checkbox as Bb,Group as Ab,Stack as Ju,Title as Mb}from"@mantine/core";import{jsx as Co,jsxs as $u}from"react/jsx-runtime";function _u(e){let o=R();return Co(J,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:$u(Ju,{children:[$u(kb,{sx:{flexDirection:"column"},children:[Co(to,{size:32}),Co(Mb,{children:"Choose scope"})]}),Co(Ju,{children:(e.scope??"openid").split(" ").map(t=>Co(Bb,{id:t,name:t,label:t,defaultChecked:!0},t))}),Co(Ab,{position:"right",mt:"xl",children:Co(Db,{type:"submit",children:"Set scope"})})]})})}import{Alert as Fb,Button as wb,Center as Ob,Group as Eb,Stack as Ku,TextInput as Lb,Title as Nb}from"@mantine/core";import{normalizeErrorString as Vb}from"@medplum/core";import{useState as Hb}from"react";import{jsx as ze,jsxs as Zu}from"react/jsx-runtime";function Yu(e){let o=R(),[t,r]=Hb();return ze(J,{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(Vb(n)))},children:Zu(Ku,{children:[Zu(Ob,{sx:{flexDirection:"column"},children:[ze(to,{size:32}),ze(Nb,{children:"Enter MFA code"})]}),t&&ze(Fb,{icon:ze(fo,{size:16}),title:"Error",color:"red",children:t}),ze(Ku,{children:ze(Lb,{name:"token",label:"MFA code",required:!0})}),ze(Eb,{position:"right",mt:"xl",children:ze(wb,{type:"submit",children:"Submit code"})})]})})}import{jsx as bo}from"react/jsx-runtime";function wq(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...f}=e,i=R(),[s,u]=dl(),[c,d]=dl(!1),[m,p]=dl(),x=cl(v=>{l?l(v):i.processCode(v).then(()=>{r&&r()}).catch(C=>ju({color:"red",message:ec(C)}))},[i,l,r]),S=cl(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=cl(v=>{x(v.code)},[x]);return qb(()=>{o&&!s&&i.get("auth/login/"+o).then(S).catch(v=>ju({color:"red",message:ec(v)}))},[i,o,s,S]),bo(Rr,{width:450,children:s?c?bo(Yu,{login:s,handleAuthResponse:S}):m?bo(Xu,{login:s,memberships:m,handleAuthResponse:S}):e.projectId==="new"?bo(jr,{login:s,handleAuthResponse:S}):e.chooseScopes?bo(_u,{login:s,scope:e.scope,handleAuthResponse:y}):bo("div",{children:"Success"}):bo(zu,{onForgotPassword:a,onRegister:n,handleAuthResponse:S,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...f,children:e.children})})}export{Sl as AddressDisplay,Pl as AddressInput,Tl as AnnotationInput,Xk as AppShell,Bo as AsyncAutocomplete,jl as AttachmentArrayDisplay,of as AttachmentArrayInput,wo as AttachmentButton,Me as AttachmentDisplay,Zt as AttachmentInput,gt as BackboneElementDisplay,Lo as BackboneElementInput,us as CalendarInput,ar as CheckboxFormSection,_t as CodeInput,Oo as CodeableConceptDisplay,yf as CodeableConceptInput,nf as CodingDisplay,lr as CodingInput,lf as ContactDetailDisplay,Cf as ContactDetailInput,er as ContactPointDisplay,fr as ContactPointInput,Ye as Container,Be as DateTimeInput,r0 as DefaultResourceTimeline,rf as DescriptionList,af as DescriptionListEntry,ln as DiagnosticReportDisplay,Rr as Document,wI as ElementDefinitionInputSelector,dr as ElementDefinitionTypeInput,x0 as EncounterTimeline,Do as ErrorBoundary,jy as FhirPathTable,J as Form,ie as FormSection,Jl as Header,Xt as HumanNameDisplay,Bf as HumanNameInput,ff as IdentifierDisplay,Ff as IdentifierInput,Na as Loading,to as Logo,SL as MeasureReportDisplay,te as MedplumLink,Wb as MedplumProvider,sL as MemoizedFhirPathTable,K1 as MemoizedSearchControl,sf as MoneyDisplay,wf as MoneyInput,Yl as Navbar,Rg as ObservationTable,Jo as OperationOutcomeAlert,Vo as Panel,OL as PatientTimeline,jL as PlanDefinitionBuilder,_e as QuantityDisplay,Ce as QuantityInput,N2 as QuestionnaireBuilder,gu as QuestionnaireForm,Vr as QuestionnaireItemType,or as RangeDisplay,vt as RangeInput,po as ReferenceDisplay,No as ReferenceInput,bN as ReferenceRangeEditor,zS as ReferenceRangeGroupEditor,AH as RegisterForm,wN as RequestGroupDisplay,pf as ResourceArrayDisplay,$f as ResourceArrayInput,se as ResourceAvatar,je as ResourceBadge,$N as ResourceBlame,oV as ResourceDiff,cV as ResourceForm,vV as ResourceHistoryTable,ir as ResourceInput,Fe as ResourceName,le as ResourcePropertyDisplay,Ze as ResourcePropertyInput,yn as ResourceTable,oo as ResourceTimeline,FV as Scheduler,On as SearchChangeEvent,Io as SearchClickEvent,Gy as SearchControl,xi as SearchFieldEditor,Ci as SearchFilterEditor,En as SearchLoadEvent,HV as ServiceRequestTimeline,wq as SignInForm,gr as StatusBadge,qs as Timeline,eo as TimelineItem,os as TimingInput,Pn as addDateFilterBetween,F0 as addField,Go as addFilter,ni as addLastMonthFilter,Tn as addMissingFilter,fi as addNextMonthFilter,li as addThisMonthFilter,ri as addTodayFilter,ai as addTomorrowFilter,si as addYearToDateFilter,ti as addYesterdayFilter,Pe as buildFieldNameString,Yi as buildInitialResponse,Wn as buildInitialResponseItem,M0 as clearFilters,Dr as clearFiltersOnField,Rf as convertIsoToLocal,Pf as convertLocalToIso,ea as createScriptTag,oi as deleteFilter,eu as formatReferenceString,G as getErrorsForInput,Ti as getFieldDefinitions,nr as getIssuesForExpression,_i as getNewMultiSelectValues,ou as getNumberOfPages,At as getOpString,Zi as getQuestionnaireItemReferenceFilter,Hr as getQuestionnaireItemReferenceTargetTypes,Ou as getRecaptcha,di as getSearchOperators,ui as getSortField,wu as initRecaptcha,Ji as isChoiceQuestion,$i as isQuestionEnabled,ci as isSortDescending,fM as isSupportedProfileStructureDefinition,$l as parseForm,gl as reactContext,mi as renderValue,Bt as setFilters,Uh as setOffset,ii as setPage,ht as setPropertyValue,qr as setQuestionnaireItemReferenceTargetTypes,Dn as setSort,Qs as sortByDateAndPriority,w0 as toggleSort,R as useMedplum,lt as useMedplumContext,Xe as useMedplumNavigate,Gt as useMedplumProfile,z as useResource,Kb as useSearch,yl as useSearchOne,vl as useSearchResources};
|
|
73
|
+
`)}),"...",jo("br",{})]})}import{Button as Du,Group as hC,Stack as yC,TextInput as ku}from"@mantine/core";import{deepClone as vC,tryGetProfile as SC}from"@medplum/core";import{useEffect as CC,useState as Bu}from"react";import{jsx as ao,jsxs as nl}from"react/jsx-runtime";function xV(e){let{outcome:o}=e,t=R(),r=z(e.defaultValue),[a,n]=Bu(),[l,f]=Bu();return CC(()=>{if(r)if(f(vC(r)),e.profileUrl){let i=e.profileUrl;t.requestProfileSchema(e.profileUrl).then(()=>{let s=SC(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?ao("div",{children:"Loading..."}):nl("form",{noValidate:!0,autoComplete:"off",onSubmit:i=>{i.preventDefault(),e.onSubmit&&e.onSubmit(l)},children:[nl(yC,{mb:"xl",children:[ao(ie,{title:"Resource Type",htmlFor:"resourceType",outcome:o,children:ao(ku,{name:"resourceType",defaultValue:l.resourceType,disabled:!0})}),ao(ie,{title:"ID",htmlFor:"id",outcome:o,children:ao(ku,{name:"id",defaultValue:l.id,disabled:!0})})]}),ao(Lo,{typeName:a,defaultValue:l,outcome:o,onChange:f,profileUrl:e.profileUrl}),nl(hC,{position:"right",mt:"xl",children:[ao(Du,{type:"submit",children:"OK"}),e.onDelete&&ao(Du,{variant:"outline",color:"red",type:"button",onClick:()=>{e.onDelete(l)},children:"Delete"})]})]})}import{Table as bC}from"@mantine/core";import{formatDateTime as RC,normalizeErrorString as PC}from"@medplum/core";import{useEffect as TC,useState as DC}from"react";import{jsx as ge,jsxs as ll}from"react/jsx-runtime";function RV(e){let o=R(),[t,r]=DC(e.history);return TC(()=>{!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?ll(bC,{withBorder:!0,withColumnBorders:!0,children:[ge("thead",{children:ll("tr",{children:[ge("th",{children:"Author"}),ge("th",{children:"Date"}),ge("th",{children:"Version"})]})}),ge("tbody",{children:t.entry?.map((a,n)=>ge(kC,{entry:a},"entry-"+n))})]}):ge("div",{children:"Loading..."})}function kC(e){let{response:o,resource:t}=e.entry;return t?ll("tr",{children:[ge("td",{children:ge(je,{value:t.meta?.author,link:!0})}),ge("td",{children:RC(t.meta?.lastUpdated)}),ge("td",{children:ge(te,{to:BC(t),children:t.meta?.versionId})})]}):ge("tr",{children:ge("td",{colSpan:3,children:PC(o?.outcome)})})}function BC(e){return`/${e.resourceType}/${e.id}/_history/${e.meta?.versionId}`}import{Button as AC,createStyles as MC,Stack as FC,Text as wC}from"@mantine/core";import{getReferenceString as OC,isReference as EC}from"@medplum/core";import{useState as Kr}from"react";import{jsx as de,jsxs as et}from"react/jsx-runtime";var LC=MC(e=>({container:{display:"flex",minHeight:400},info:{minWidth:300,padding:20,borderRight:`1px solid ${e.colors.gray[3]}`},selection:{minWidth:300,padding:20}}));function LV(e){let{classes:o}=LC(),t=z(e.schedule),r=z(e.questionnaire),[a,n]=Kr(Ir()),[l,f]=Kr(),[i,s]=Kr(),[u,c]=Kr(),[d]=vl("Slot",new URLSearchParams([["_count",(30*24).toString()],["schedule",EC(e.schedule)?e.schedule.reference:OC(e.schedule)],["start","gt"+NC(a)],["start","lt"+VC(a)]]));if(!t||!d||!r)return null;let m=t.actor?.[0];return et("div",{className:o.container,"data-testid":"scheduler",children:[et("div",{className:o.info,children:[m&&de(se,{value:m,size:"xl"}),m&&de(wC,{size:"xl",weight:500,children:de(Fe,{value:m})}),de("p",{children:"1 hour"}),l&&de("p",{children:l.toLocaleDateString()}),i&&de("p",{children:Au(new Date(i.start))})]}),et("div",{className:o.selection,children:[!l&&et("div",{children:[de("h3",{children:"Select date"}),de(us,{slots:d,onChangeMonth:n,onClick:f})]}),l&&!i&&et("div",{children:[de("h3",{children:"Select time"}),de(FC,{children:d.map(p=>{let x=new Date(p.start);return x.getTime()>l.getTime()&&x.getTime()<l.getTime()+24*3600*1e3&&de("div",{children:de(AC,{variant:"outline",style:{width:150},onClick:()=>s(p),children:Au(x)})},p.id)})})]}),l&&i&&!u&&de(gu,{questionnaire:r,submitButtonText:"Next",onSubmit:c}),l&&i&&u&&et("div",{children:[de("h3",{children:"You're all set!"}),de("p",{children:"Check your email for a calendar invite."})]})]})]})}function NC(e){return Mu(e.getTime())}function VC(e){return Mu(e.getTime()+31*24*60*60*1e3)}function Mu(e){let o=new Date(Math.max(Date.now(),e));return o.setHours(0,0,0,0),o.toISOString()}function Au(e){return e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}import{createReference as Zr}from"@medplum/core";import{jsx as HC}from"react/jsx-runtime";function QV(e){return HC(oo,{value:e.serviceRequest,loadTimelineResources:async(o,t,r)=>{let a=`${t}/${r}`,n=100;return Promise.allSettled([o.readHistory("ServiceRequest",r),o.search("Communication",{"based-on":a,_count:n}),o.search("DiagnosticReport",{"based-on":a,_count:n}),o.search("Media",{"based-on":a,_count:n}),o.search("DocumentReference",{related:a,_count:n}),o.search("Task",{_filter:`based-on eq ${a} or focus eq ${a} or subject eq ${a}`,_count:n})])},createCommunication:(o,t,r)=>({resourceType:"Communication",status:"completed",basedOn:[Zr(o)],subject:o.subject,sender:Zr(t),sent:new Date().toISOString(),payload:[{contentString:r}]}),createMedia:(o,t,r)=>({resourceType:"Media",status:"completed",basedOn:[Zr(o)],subject:o.subject,operator:Zr(t),issued:new Date().toISOString(),content:r})})}import{Anchor as qC}from"@mantine/core";import{showNotification as GC}from"@mantine/notifications";import{normalizeErrorString as UC}from"@medplum/core";import{jsx as QC}from"react/jsx-runtime";function ZV(e){let o=R(),{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=>GC({color:"red",message:UC(i),autoClose:!1}))}return QC(qC,{onClick:()=>f(),...l,children:n})}import{normalizeOperationOutcome as cb}from"@medplum/core";import{useEffect as db,useState as Hu}from"react";import{Anchor as Fu,Button as zC,Center as WC,Group as XC,Stack as JC,Text as $C,TextInput as _C,Title as KC}from"@mantine/core";import{normalizeOperationOutcome as ZC}from"@medplum/core";import{useState as YC}from"react";import{jsx as vo,jsxs as Yr}from"react/jsx-runtime";function jr(e){let o=R(),[t,r]=YC();return Yr(J,{style:{maxWidth:400},onSubmit:async a=>{try{e.handleAuthResponse(await o.startNewProject({login:e.login,projectName:a.projectName}))}catch(n){r(ZC(n))}},children:[Yr(WC,{sx:{flexDirection:"column"},children:[vo(to,{size:32}),vo(KC,{children:"Create project"})]}),Yr(JC,{spacing:"xl",children:[vo(_C,{name:"projectName",label:"Project Name",placeholder:"My Project",required:!0,autoFocus:!0,error:G(t,"firstName")}),Yr($C,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",vo(Fu,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",vo(Fu,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]})]}),vo(XC,{position:"right",mt:"xl",noWrap:!0,children:vo(zC,{type:"submit",children:"Create project"})})]})}import{Anchor as ra,Button as tb,Center as rb,Checkbox as ab,Divider as nb,Group as Eu,PasswordInput as lb,Stack as fb,Text as Lu,TextInput as sl}from"@mantine/core";import{normalizeOperationOutcome as Nu}from"@medplum/core";import{useEffect as sb,useState as ib}from"react";import{useEffect as jC,useRef as eb,useState as fl}from"react";function ea(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 ob}from"react/jsx-runtime";function oa(e){let o=R(),{googleClientId:t,handleGoogleCredential:r}=e,a=eb(null),[n,l]=fl(typeof google<"u"),[f,i]=fl(!1),[s,u]=fl(!1);return jC(()=>{if(typeof google>"u"){ea("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?ob("div",{ref:a}):null}function ta(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 wu(e){typeof grecaptcha>"u"&&ea("https://www.google.com/recaptcha/api.js?render="+e)}function Ou(e){return new Promise((o,t)=>{grecaptcha.ready(async()=>{try{o(await grecaptcha.execute(e,{action:"submit"}))}catch(r){t(r)}})})}import{Fragment as ub,jsx as me,jsxs as ot}from"react/jsx-runtime";function Vu(e){let o=ta(e.googleClientId),t=e.recaptchaSiteKey,r=R(),[a,n]=ib(),l=nr(a,void 0);return sb(()=>{t&&wu(t)},[t]),ot(J,{style:{maxWidth:400},onSubmit:async f=>{try{let i="";t&&(i=await Ou(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(Nu(i))}},children:[me(rb,{sx:{flexDirection:"column"},children:e.children}),me(Jo,{issues:l}),o&&ot(ub,{children:[me(Eu,{position:"center",p:"xl",style:{height:70},children:me(oa,{googleClientId:o,handleGoogleCredential:async f=>{try{e.handleAuthResponse(await r.startGoogleLogin({googleClientId:f.clientId,googleCredential:f.credential,createUser:!0}))}catch(i){n(Nu(i))}}})}),me(nb,{label:"or",labelPosition:"center",my:"lg"})]}),ot(fb,{spacing:"xl",children:[me(sl,{name:"firstName",type:"text",label:"First name",placeholder:"First name",required:!0,autoFocus:!0,error:G(a,"firstName")}),me(sl,{name:"lastName",type:"text",label:"Last name",placeholder:"Last name",required:!0,error:G(a,"lastName")}),me(sl,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,error:G(a,"email")}),me(lb,{name:"password",label:"Password",autoComplete:"off",required:!0,error:G(a,"password")}),ot(Lu,{color:"dimmed",size:"xs",children:["By clicking submit you agree to the Medplum"," ",me(ra,{href:"https://www.medplum.com/privacy",children:"Privacy\xA0Policy"})," and ",me(ra,{href:"https://www.medplum.com/terms",children:"Terms\xA0of\xA0Service"}),"."]}),ot(Lu,{color:"dimmed",size:"xs",children:["This site is protected by reCAPTCHA and the Google"," ",me(ra,{href:"https://policies.google.com/privacy",children:"Privacy\xA0Policy"})," and ",me(ra,{href:"https://policies.google.com/terms",children:"Terms\xA0of\xA0Service"})," apply."]})]}),ot(Eu,{position:"apart",mt:"xl",noWrap:!0,children:[me(ab,{name:"remember",label:"Remember me",size:"xs"}),me(tb,{type:"submit",children:"Create account"})]})]})}import{jsx as il,jsxs as mb}from"react/jsx-runtime";function UH(e){let{type:o,projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,onSuccess:l}=e,f=R(),[i,s]=Hu(),[u,c]=Hu();db(()=>{o==="patient"&&i&&f.startNewPatient({login:i,projectId:t}).then(m=>f.processCode(m.code)).then(()=>l()).catch(m=>c(cb(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 mb(Rr,{width:450,children:[u&&il("pre",{children:JSON.stringify(u,null,2)}),!i&&il(Vu,{projectId:t,clientId:r,googleClientId:a,recaptchaSiteKey:n,handleAuthResponse:d,children:e.children}),i&&o==="project"&&il(jr,{login:i,handleAuthResponse:d})]})}import{showNotification as ju}from"@mantine/notifications";import{normalizeErrorString as ec}from"@medplum/core";import{useCallback as cl,useEffect as zb,useState as dl}from"react";import{Anchor as qu,Button as Gu,Center as Uu,Checkbox as pb,Divider as xb,Group as ul,PasswordInput as Ib,Stack as gb,TextInput as hb}from"@mantine/core";import{normalizeOperationOutcome as yb}from"@medplum/core";import{useCallback as aa,useState as Qu}from"react";import{Fragment as Cb,jsx as ae,jsxs as Vt}from"react/jsx-runtime";function zu(e){let[o,t]=Qu();return o?ae(Sb,{email:o,...e}):ae(vb,{setEmail:t,...e})}function vb(e){let{setEmail:o,onRegister:t,handleAuthResponse:r,children:a,disableEmailAuth:n,...l}=e,f=R(),i=!e.disableGoogleAuth&&ta(e.googleClientId),s=aa(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=aa(async d=>{let m=await f.post("auth/method",{email:d.email});await s(m)||o(d.email)},[f,s,o]),c=aa(async d=>{let m=await f.startGoogleLogin({...l,googleCredential:d.credential});await s(m)||r(m)},[f,l,s,r]);return Vt(J,{style:{maxWidth:400},onSubmit:u,children:[ae(Uu,{sx:{flexDirection:"column"},children:a}),i&&Vt(Cb,{children:[ae(ul,{position:"center",p:"xl",style:{height:70},children:ae(oa,{googleClientId:i,handleGoogleCredential:c})}),!n&&ae(xb,{label:"or",labelPosition:"center",my:"lg"})]}),!n&&ae(hb,{name:"email",type:"email",label:"Email",placeholder:"name@domain.com",required:!0,autoFocus:!0}),Vt(ul,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[ae("div",{children:t&&ae(qu,{component:"button",type:"button",color:"dimmed",onClick:t,size:"xs",children:"Register"})}),!n&&ae(Gu,{type:"submit",children:"Next"})]})]})}function Sb(e){let{onForgotPassword:o,handleAuthResponse:t,children:r,...a}=e,n=R(),[l,f]=Qu(),i=nr(l,void 0),s=aa(u=>{n.startLogin({...a,password:u.password,remember:u.remember==="on"}).then(t).catch(c=>f(yb(c)))},[n,a,t]);return Vt(J,{style:{maxWidth:400},onSubmit:s,children:[ae(Uu,{sx:{flexDirection:"column"},children:r}),ae(Jo,{issues:i}),ae(gb,{spacing:"xl",children:ae(Ib,{name:"password",label:"Password",autoComplete:"off",required:!0,autoFocus:!0,error:G(l,"password")})}),Vt(ul,{position:"apart",mt:"xl",spacing:0,noWrap:!0,children:[o&&ae(qu,{component:"button",type:"button",color:"dimmed",onClick:o,size:"xs",children:"Forgot password"}),ae(pb,{id:"remember",name:"remember",label:"Remember me",size:"xs",sx:{lineHeight:1}}),ae(Gu,{type:"submit",children:"Sign in"})]})]})}import{Avatar as bb,Center as Rb,Group as Pb,Stack as Tb,Text as Wu,Title as Db,UnstyledButton as kb}from"@mantine/core";import{normalizeOperationOutcome as Bb}from"@medplum/core";import{useState as Ab}from"react";import{jsx as So,jsxs as na}from"react/jsx-runtime";function Xu(e){let o=R(),[t,r]=Ab();return na(Tb,{children:[na(Rb,{sx:{flexDirection:"column"},children:[So(to,{size:32}),So(Db,{order:3,children:"Choose profile"})]}),So(Jo,{outcome:t}),e.memberships.map(a=>So(kb,{onClick:()=>{o.post("auth/profile",{login:e.login,profile:a.id}).then(e.handleAuthResponse).catch(n=>r(Bb(n)))},children:na(Pb,{children:[So(bb,{radius:"xl"}),na("div",{style:{flex:1},children:[So(Wu,{size:"sm",weight:500,children:a.profile?.display}),So(Wu,{color:"dimmed",size:"xs",children:a.project?.display})]})]})},a.id))]})}import{Button as Mb,Center as Fb,Checkbox as wb,Group as Ob,Stack as Ju,Title as Eb}from"@mantine/core";import{jsx as Co,jsxs as $u}from"react/jsx-runtime";function _u(e){let o=R();return Co(J,{style:{maxWidth:400},onSubmit:t=>{o.post("auth/scope",{login:e.login,scope:Object.keys(t).join(" ")}).then(e.handleAuthResponse).catch(console.log)},children:$u(Ju,{children:[$u(Fb,{sx:{flexDirection:"column"},children:[Co(to,{size:32}),Co(Eb,{children:"Choose scope"})]}),Co(Ju,{children:(e.scope??"openid").split(" ").map(t=>Co(wb,{id:t,name:t,label:t,defaultChecked:!0},t))}),Co(Ob,{position:"right",mt:"xl",children:Co(Mb,{type:"submit",children:"Set scope"})})]})})}import{Alert as Lb,Button as Nb,Center as Vb,Group as Hb,Stack as Ku,TextInput as qb,Title as Gb}from"@mantine/core";import{normalizeErrorString as Ub}from"@medplum/core";import{useState as Qb}from"react";import{jsx as ze,jsxs as Zu}from"react/jsx-runtime";function Yu(e){let o=R(),[t,r]=Qb();return ze(J,{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(Ub(n)))},children:Zu(Ku,{children:[Zu(Vb,{sx:{flexDirection:"column"},children:[ze(to,{size:32}),ze(Gb,{children:"Enter MFA code"})]}),t&&ze(Lb,{icon:ze(fo,{size:16}),title:"Error",color:"red",children:t}),ze(Ku,{children:ze(qb,{name:"token",label:"MFA code",required:!0})}),ze(Hb,{position:"right",mt:"xl",children:ze(Nb,{type:"submit",children:"Submit code"})})]})})}import{jsx as bo}from"react/jsx-runtime";function Wq(e){let{login:o,chooseScopes:t,onSuccess:r,onForgotPassword:a,onRegister:n,onCode:l,...f}=e,i=R(),[s,u]=dl(),[c,d]=dl(!1),[m,p]=dl(),x=cl(v=>{l?l(v):i.processCode(v).then(()=>{r&&r()}).catch(C=>ju({color:"red",message:ec(C)}))},[i,l,r]),S=cl(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=cl(v=>{x(v.code)},[x]);return zb(()=>{o&&!s&&i.get("auth/login/"+o).then(S).catch(v=>ju({color:"red",message:ec(v)}))},[i,o,s,S]),bo(Rr,{width:450,children:s?c?bo(Yu,{login:s,handleAuthResponse:S}):m?bo(Xu,{login:s,memberships:m,handleAuthResponse:S}):e.projectId==="new"?bo(jr,{login:s,handleAuthResponse:S}):e.chooseScopes?bo(_u,{login:s,scope:e.scope,handleAuthResponse:y}):bo("div",{children:"Success"}):bo(zu,{onForgotPassword:a,onRegister:n,handleAuthResponse:S,disableGoogleAuth:e.disableGoogleAuth,disableEmailAuth:e.disableEmailAuth,...f,children:e.children})})}export{Sl as AddressDisplay,Pl as AddressInput,Tl as AnnotationInput,Kk as AppShell,Bo as AsyncAutocomplete,jl as AttachmentArrayDisplay,of as AttachmentArrayInput,wo as AttachmentButton,Me as AttachmentDisplay,Zt as AttachmentInput,gt as BackboneElementDisplay,Lo as BackboneElementInput,us as CalendarInput,ar as CheckboxFormSection,_t as CodeInput,Oo as CodeableConceptDisplay,yf as CodeableConceptInput,nf as CodingDisplay,lr as CodingInput,lf as ContactDetailDisplay,Cf as ContactDetailInput,er as ContactPointDisplay,fr as ContactPointInput,Ye as Container,Be as DateTimeInput,f0 as DefaultResourceTimeline,rf as DescriptionList,af as DescriptionListEntry,ln as DiagnosticReportDisplay,Rr as Document,wI as ElementDefinitionInputSelector,dr as ElementDefinitionTypeInput,y0 as EncounterTimeline,Do as ErrorBoundary,jy as FhirPathTable,J as Form,ie as FormSection,Jl as Header,Xt as HumanNameDisplay,Bf as HumanNameInput,ff as IdentifierDisplay,Ff as IdentifierInput,Na as Loading,to as Logo,PL as MeasureReportDisplay,te as MedplumLink,_b as MedplumProvider,dL as MemoizedFhirPathTable,eL as MemoizedSearchControl,sf as MoneyDisplay,wf as MoneyInput,Yl as Navbar,Rg as ObservationTable,Jo as OperationOutcomeAlert,Vo as Panel,VL as PatientTimeline,r2 as PlanDefinitionBuilder,_e as QuantityDisplay,Ce as QuantityInput,G2 as QuestionnaireBuilder,gu as QuestionnaireForm,Vr as QuestionnaireItemType,or as RangeDisplay,vt as RangeInput,po as ReferenceDisplay,No as ReferenceInput,DN as ReferenceRangeEditor,zS as ReferenceRangeGroupEditor,UH as RegisterForm,NN as RequestGroupDisplay,pf as ResourceArrayDisplay,$f as ResourceArrayInput,se as ResourceAvatar,je as ResourceBadge,YN as ResourceBlame,nV as ResourceDiff,xV as ResourceForm,RV as ResourceHistoryTable,ir as ResourceInput,Fe as ResourceName,le as ResourcePropertyDisplay,Ze as ResourcePropertyInput,yn as ResourceTable,oo as ResourceTimeline,LV as Scheduler,On as SearchChangeEvent,Io as SearchClickEvent,Gy as SearchControl,xi as SearchFieldEditor,Ci as SearchFilterEditor,En as SearchLoadEvent,QV as ServiceRequestTimeline,Wq as SignInForm,ZV as SmartAppLaunchLink,gr as StatusBadge,qs as Timeline,eo as TimelineItem,os as TimingInput,Pn as addDateFilterBetween,L0 as addField,Go as addFilter,ni as addLastMonthFilter,Tn as addMissingFilter,fi as addNextMonthFilter,li as addThisMonthFilter,ri as addTodayFilter,ai as addTomorrowFilter,si as addYearToDateFilter,ti as addYesterdayFilter,Pe as buildFieldNameString,Yi as buildInitialResponse,Wn as buildInitialResponseItem,E0 as clearFilters,Dr as clearFiltersOnField,Rf as convertIsoToLocal,Pf as convertLocalToIso,ea as createScriptTag,oi as deleteFilter,eu as formatReferenceString,G as getErrorsForInput,Ti as getFieldDefinitions,nr as getIssuesForExpression,_i as getNewMultiSelectValues,ou as getNumberOfPages,At as getOpString,Zi as getQuestionnaireItemReferenceFilter,Hr as getQuestionnaireItemReferenceTargetTypes,Ou as getRecaptcha,di as getSearchOperators,ui as getSortField,wu as initRecaptcha,Ji as isChoiceQuestion,$i as isQuestionEnabled,ci as isSortDescending,cM as isSupportedProfileStructureDefinition,$l as parseForm,gl as reactContext,mi as renderValue,Bt as setFilters,Uh as setOffset,ii as setPage,ht as setPropertyValue,qr as setQuestionnaireItemReferenceTargetTypes,Dn as setSort,Qs as sortByDateAndPriority,N0 as toggleSort,R as useMedplum,lt as useMedplumContext,Xe as useMedplumNavigate,Gt as useMedplumProfile,z as useResource,eR as useSearch,yl as useSearchOne,vl as useSearchResources};
|
|
74
74
|
//# sourceMappingURL=index.mjs.map
|